Skip to content

Commit

Permalink
add primary first preference in search request for fetching audit sta…
Browse files Browse the repository at this point in the history
…te alerts to evaluate chained alert trigger condition (#1114)

Signed-off-by: Surya Sashank Nistala <snistala@amazon.com>
  • Loading branch information
eirsep authored Sep 5, 2023
1 parent 7b9584c commit 0ce01cb
Showing 1 changed file with 2 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 0ce01cb

Please sign in to comment.