From f4cab16a02428712c6ec90492664fd92f86d782b Mon Sep 17 00:00:00 2001 From: Subhobrata Dey Date: Fri, 28 Jun 2024 02:10:13 +0000 Subject: [PATCH] fix minor bug in remote monitor impl Signed-off-by: Subhobrata Dey --- .../remote/monitors/RemoteDocumentLevelMonitorRunner.kt | 3 ++- .../java/org/opensearch/alerting/SampleRemoteMonitorIT.java | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/remote/monitors/RemoteDocumentLevelMonitorRunner.kt b/alerting/src/main/kotlin/org/opensearch/alerting/remote/monitors/RemoteDocumentLevelMonitorRunner.kt index 0e23f0fb1..aa0d186e6 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/remote/monitors/RemoteDocumentLevelMonitorRunner.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/remote/monitors/RemoteDocumentLevelMonitorRunner.kt @@ -84,6 +84,7 @@ class RemoteDocumentLevelMonitorRunner : MonitorRunner() { for (ind in runContextKeys) { if (!allConcreteIndices.contains(ind)) { updatedLastRunContext.remove(ind) + lastRunContext.remove(ind) } } @@ -161,7 +162,7 @@ class RemoteDocumentLevelMonitorRunner : MonitorRunner() { val docLevelMonitorFanOutResponses = monitorCtx.remoteMonitors[monitor.monitorType]!!.monitorRunner.doFanOut( monitorCtx.clusterService!!, monitor, - monitorMetadata.copy(lastRunContext = updatedLastRunContext), + monitorMetadata.copy(lastRunContext = lastRunContext), executionId, concreteIndices, workflowRunContext, diff --git a/sample-remote-monitor-plugin/src/test/java/org/opensearch/alerting/SampleRemoteMonitorIT.java b/sample-remote-monitor-plugin/src/test/java/org/opensearch/alerting/SampleRemoteMonitorIT.java index 25e45fd46..aeb2085e5 100644 --- a/sample-remote-monitor-plugin/src/test/java/org/opensearch/alerting/SampleRemoteMonitorIT.java +++ b/sample-remote-monitor-plugin/src/test/java/org/opensearch/alerting/SampleRemoteMonitorIT.java @@ -260,6 +260,9 @@ public void testSampleRemoteDocLevelMonitorWithAlias() throws IOException, Inter makeRequest(client(), "POST", String.format(Locale.ROOT, "%s/_rollover", indexAlias), Map.of(), new StringEntity("", ContentType.APPLICATION_JSON)); + response = makeRequest(client(), "POST", "/_plugins/_alerting/monitors/" + monitorId + "/_execute", Map.of(), null); + Assert.assertEquals("Unable to execute remote monitor", RestStatus.OK, RestStatus.fromCode(response.getStatusLine().getStatusCode())); + response = makeRequest(client(), "POST", "/_plugins/_alerting/monitors/" + monitorId + "/_execute", Map.of(), null); Assert.assertEquals("Unable to execute remote monitor", RestStatus.OK, RestStatus.fromCode(response.getStatusLine().getStatusCode())); AtomicBoolean found = new AtomicBoolean(false);