From 60fbe9c879ee0444d9bb48ac999a3ae2e7a3f407 Mon Sep 17 00:00:00 2001 From: Surya Sashank Nistala Date: Tue, 5 Sep 2023 11:48:01 -0700 Subject: [PATCH] add primary first preference in search request for fetching audit state alerts to evaluate chained alert trigger condition Signed-off-by: Surya Sashank Nistala --- .../alerting/workflow/CompositeWorkflowRunner.kt | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/workflow/CompositeWorkflowRunner.kt b/alerting/src/main/kotlin/org/opensearch/alerting/workflow/CompositeWorkflowRunner.kt index 7f9b32c92..0dbf7eac2 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/workflow/CompositeWorkflowRunner.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/workflow/CompositeWorkflowRunner.kt @@ -21,6 +21,7 @@ import org.opensearch.alerting.script.ChainedAlertTriggerExecutionContext import org.opensearch.alerting.util.AlertingException import org.opensearch.alerting.util.isDocLevelMonitor import org.opensearch.alerting.util.isQueryLevelMonitor +import org.opensearch.cluster.routing.Preference import org.opensearch.common.xcontent.LoggingDeprecationHandler import org.opensearch.common.xcontent.XContentHelper import org.opensearch.common.xcontent.XContentType @@ -226,11 +227,6 @@ object CompositeWorkflowRunner : WorkflowRunner() { ) } workflowRunResult.executionEndTime = Instant.now() - - val sr = SearchRequest(dataSources!!.alertsIndex) - sr.source().query(QueryBuilders.matchAllQuery()).size(10) - val searchResponse: SearchResponse = monitorCtx.client!!.suspendUntil { monitorCtx.client!!.search(sr, it) } - searchResponse.hits return workflowRunResult } @@ -340,6 +336,7 @@ object CompositeWorkflowRunner : WorkflowRunner() { try { val searchRequest = SearchRequest(getDelegateMonitorAlertIndex(dataSources, workflow, monitorCtx.alertIndices!!.isAlertHistoryEnabled())) + searchRequest.preference(Preference.PRIMARY_FIRST.type()) val queryBuilder = boolQuery() queryBuilder.must(QueryBuilders.termQuery("execution_id", executionId)) queryBuilder.must(QueryBuilders.termQuery("state", getDelegateMonitorAlertState(workflow).name))