From 61e24a8312e631b4e5340fef48fb632fc7b2fd6f Mon Sep 17 00:00:00 2001 From: Riya Saxena Date: Wed, 3 Apr 2024 18:46:58 -0700 Subject: [PATCH 1/3] fix merge conflicts --- .../kotlin/org/opensearch/alerting/BucketLevelMonitorRunner.kt | 2 +- .../org/opensearch/alerting/DocumentLevelMonitorRunner.kt | 3 +-- .../org/opensearch/alerting/MonitorRunnerExecutionContext.kt | 2 +- .../alerting/transport/TransportGetFindingsAction.kt | 2 +- .../main/kotlin/org/opensearch/alerting/util/AlertingUtils.kt | 2 +- 5 files changed, 5 insertions(+), 6 deletions(-) diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/BucketLevelMonitorRunner.kt b/alerting/src/main/kotlin/org/opensearch/alerting/BucketLevelMonitorRunner.kt index 3e35b2997..47fef3edb 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/BucketLevelMonitorRunner.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/BucketLevelMonitorRunner.kt @@ -30,8 +30,8 @@ import org.opensearch.alerting.util.getCancelAfterTimeInterval import org.opensearch.alerting.util.getCombinedTriggerRunResult import org.opensearch.alerting.util.printsSampleDocData import org.opensearch.alerting.workflow.WorkflowRunContext -import org.opensearch.common.unit.TimeValue import org.opensearch.client.Client +import org.opensearch.common.unit.TimeValue import org.opensearch.common.xcontent.LoggingDeprecationHandler import org.opensearch.common.xcontent.XContentType import org.opensearch.commons.alerting.model.Alert diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/DocumentLevelMonitorRunner.kt b/alerting/src/main/kotlin/org/opensearch/alerting/DocumentLevelMonitorRunner.kt index 3654a136a..cc654ad39 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/DocumentLevelMonitorRunner.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/DocumentLevelMonitorRunner.kt @@ -37,6 +37,7 @@ import org.opensearch.alerting.util.getCancelAfterTimeInterval import org.opensearch.alerting.util.parseSampleDocTags import org.opensearch.alerting.util.printsSampleDocData import org.opensearch.alerting.workflow.WorkflowRunContext +import org.opensearch.client.Client import org.opensearch.client.node.NodeClient import org.opensearch.cluster.metadata.IndexMetadata import org.opensearch.cluster.routing.Preference @@ -728,7 +729,6 @@ class DocumentLevelMonitorRunner : MonitorRunner() { return response.hits.hits[0].seqNo } - private fun getShardsCount(clusterService: ClusterService, index: String): Int { val allShards: List = clusterService!!.state().routingTable().allShards(index) return allShards.filter { it.primary() }.size @@ -912,7 +912,6 @@ class DocumentLevelMonitorRunner : MonitorRunner() { .size(monitorCtx.docLevelMonitorShardFetchSize) ) .preference(Preference.PRIMARY_FIRST.type()) - request.cancelAfterTimeInterval = TimeValue.timeValueMinutes( getCancelAfterTimeInterval() ) diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/MonitorRunnerExecutionContext.kt b/alerting/src/main/kotlin/org/opensearch/alerting/MonitorRunnerExecutionContext.kt index db7a1d6bc..eefad1b6b 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/MonitorRunnerExecutionContext.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/MonitorRunnerExecutionContext.kt @@ -53,7 +53,7 @@ data class MonitorRunnerExecutionContext( @Volatile var maxActionableAlertCount: Long = AlertingSettings.DEFAULT_MAX_ACTIONABLE_ALERT_COUNT, @Volatile var indexTimeout: TimeValue? = null, - @Volatile var cancelAfterTimeInterval: TimeValue? = null + @Volatile var cancelAfterTimeInterval: TimeValue? = null, @Volatile var findingsIndexBatchSize: Int = AlertingSettings.DEFAULT_FINDINGS_INDEXING_BATCH_SIZE, @Volatile var fetchOnlyQueryFieldNames: Boolean = true, @Volatile var percQueryMaxNumDocsInMemory: Int = AlertingSettings.DEFAULT_PERCOLATE_QUERY_NUM_DOCS_IN_MEMORY, diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportGetFindingsAction.kt b/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportGetFindingsAction.kt index d837dc57b..bd491e057 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportGetFindingsAction.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportGetFindingsAction.kt @@ -132,7 +132,7 @@ class TransportGetFindingsSearchAction @Inject constructor( ) } searchSourceBuilder.query(queryBuilder).trackTotalHits(true) - + log.info("This is alerting: {}", searchSourceBuilder.toString()) client.threadPool().threadContext.stashContext().use { scope.launch { try { diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/util/AlertingUtils.kt b/alerting/src/main/kotlin/org/opensearch/alerting/util/AlertingUtils.kt index 056d7d4ea..355945939 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/util/AlertingUtils.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/util/AlertingUtils.kt @@ -26,8 +26,8 @@ import org.opensearch.commons.alerting.model.action.Action import org.opensearch.commons.alerting.model.action.ActionExecutionPolicy import org.opensearch.commons.alerting.model.action.ActionExecutionScope import org.opensearch.commons.alerting.util.isBucketLevelMonitor -import kotlin.math.max import org.opensearch.script.Script +import kotlin.math.max private val logger = LogManager.getLogger("AlertingUtils") From d17b6eb70f42c7ae49484c19837b18e23da68da2 Mon Sep 17 00:00:00 2001 From: Riya Saxena Date: Wed, 3 Apr 2024 18:50:32 -0700 Subject: [PATCH 2/3] fix merge conflicts Signed-off-by: Riya Saxena --- .../alerting/DocumentLevelMonitorRunner.kt | 30 ------------------- 1 file changed, 30 deletions(-) diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/DocumentLevelMonitorRunner.kt b/alerting/src/main/kotlin/org/opensearch/alerting/DocumentLevelMonitorRunner.kt index cc654ad39..51a32b642 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/DocumentLevelMonitorRunner.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/DocumentLevelMonitorRunner.kt @@ -37,7 +37,6 @@ import org.opensearch.alerting.util.getCancelAfterTimeInterval import org.opensearch.alerting.util.parseSampleDocTags import org.opensearch.alerting.util.printsSampleDocData import org.opensearch.alerting.workflow.WorkflowRunContext -import org.opensearch.client.Client import org.opensearch.client.node.NodeClient import org.opensearch.cluster.metadata.IndexMetadata import org.opensearch.cluster.routing.Preference @@ -700,35 +699,6 @@ class DocumentLevelMonitorRunner : MonitorRunner() { return indexCreationDate > lastExecutionTime.toEpochMilli() } - /** - * Get the current max seq number of the shard. We find it by searching the last document - * in the primary shard. - */ - private suspend fun getMaxSeqNo(client: Client, index: String, shard: String): Long { - val request: SearchRequest = SearchRequest() - .indices(index) - .preference("_shards:$shard") - .source( - SearchSourceBuilder() - .version(true) - .sort("_seq_no", SortOrder.DESC) - .seqNoAndPrimaryTerm(true) - .query(QueryBuilders.matchAllQuery()) - .size(1) - ) - request.cancelAfterTimeInterval = TimeValue.timeValueMinutes(getCancelAfterTimeInterval()) - - val response: SearchResponse = client.suspendUntil { client.search(request, it) } - - if (response.status() !== RestStatus.OK) { - throw IOException("Failed to get max seq no for shard: $shard") - } - if (response.hits.hits.isEmpty()) - return -1L - - return response.hits.hits[0].seqNo - } - private fun getShardsCount(clusterService: ClusterService, index: String): Int { val allShards: List = clusterService!!.state().routingTable().allShards(index) return allShards.filter { it.primary() }.size From e778cf5d1b42cd78c5474826e0fc353d1914970a Mon Sep 17 00:00:00 2001 From: Riya Saxena Date: Wed, 3 Apr 2024 18:55:49 -0700 Subject: [PATCH 3/3] fix merge conflicts Signed-off-by: Riya Saxena --- .../opensearch/alerting/transport/TransportGetFindingsAction.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportGetFindingsAction.kt b/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportGetFindingsAction.kt index bd491e057..6835a9625 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportGetFindingsAction.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportGetFindingsAction.kt @@ -132,7 +132,6 @@ class TransportGetFindingsSearchAction @Inject constructor( ) } searchSourceBuilder.query(queryBuilder).trackTotalHits(true) - log.info("This is alerting: {}", searchSourceBuilder.toString()) client.threadPool().threadContext.stashContext().use { scope.launch { try {