From 90e86949a52dd02c42f8344ad596b4b53cbf7741 Mon Sep 17 00:00:00 2001 From: Subhobrata Dey Date: Thu, 26 Sep 2024 02:40:19 +0000 Subject: [PATCH] move deletion of query index before its creation Signed-off-by: Subhobrata Dey --- .../alerting/DocumentLevelMonitorRunner.kt | 22 +++++++++---------- .../alerting/util/DocLevelMonitorQueries.kt | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/DocumentLevelMonitorRunner.kt b/alerting/src/main/kotlin/org/opensearch/alerting/DocumentLevelMonitorRunner.kt index 0164aa00e..6f339fdce 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/DocumentLevelMonitorRunner.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/DocumentLevelMonitorRunner.kt @@ -121,6 +121,17 @@ class DocumentLevelMonitorRunner : MonitorRunner() { throw IndexNotFoundException(docLevelMonitorInput.indices.joinToString(",")) } + if (monitor.deleteQueryIndexInEveryRun == true && + monitorCtx.docLevelMonitorQueries!!.docLevelQueryIndexExists(monitor.dataSources) + ) { + val ack = monitorCtx.docLevelMonitorQueries!!.deleteDocLevelQueryIndex(monitor.dataSources) + if (!ack) { + logger.error( + "Deletion of concrete queryIndex:${monitor.dataSources.queryIndex} is not ack'd! " + + "for monitor ${monitor.id}" + ) + } + } monitorCtx.docLevelMonitorQueries!!.initDocLevelQueryIndex(monitor.dataSources) monitorCtx.docLevelMonitorQueries!!.indexDocLevelQueries( monitor = monitor, @@ -388,17 +399,6 @@ class DocumentLevelMonitorRunner : MonitorRunner() { ) return monitorResult.copy(error = alertingException, inputResults = InputRunResults(emptyList(), alertingException)) } finally { - if (monitor.deleteQueryIndexInEveryRun == true && - monitorCtx.docLevelMonitorQueries!!.docLevelQueryIndexExists(monitor.dataSources) - ) { - val ack = monitorCtx.docLevelMonitorQueries!!.deleteDocLevelQueryIndex(monitor.dataSources) - if (!ack) { - logger.error( - "Deletion of concrete queryIndex:${monitor.dataSources.queryIndex} is not ack'd! " + - "for monitor ${monitor.id}" - ) - } - } val endTime = System.currentTimeMillis() totalTimeTakenStat = endTime - startTime logger.debug( diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/util/DocLevelMonitorQueries.kt b/alerting/src/main/kotlin/org/opensearch/alerting/util/DocLevelMonitorQueries.kt index d2be2c8c0..7ce3309db 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/util/DocLevelMonitorQueries.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/util/DocLevelMonitorQueries.kt @@ -456,7 +456,7 @@ class DocLevelMonitorQueries(private val client: Client, private val clusterServ } bulkResponse.forEach { bulkItemResponse -> if (bulkItemResponse.isFailed) { - log.debug(bulkItemResponse.failureMessage) + log.error(bulkItemResponse.failureMessage) } } }