From 2ac1b8969b1c3cbbb0942df73e765c40757078ca Mon Sep 17 00:00:00 2001 From: Subhobrata Dey Date: Thu, 27 Jun 2024 19:37:16 -0700 Subject: [PATCH] fix minor bug in remote monitor impl (#1587) 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 1fa3105ab..2363324ac 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);