From 8b45f724bf3373cd05ae59adaeb8f941cc87fe80 Mon Sep 17 00:00:00 2001 From: Surya Sashank Nistala Date: Tue, 1 Aug 2023 17:20:35 -0700 Subject: [PATCH] fix get alerts alertState query filter (#1064) Signed-off-by: Surya Sashank Nistala (cherry picked from commit 3ad13650d2caddefa871a13e16c01c485c09ee82) --- .../alerting/transport/TransportGetAlertsAction.kt | 3 +-- .../opensearch/alerting/resthandler/WorkflowRestApiIT.kt | 6 +++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportGetAlertsAction.kt b/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportGetAlertsAction.kt index e4d561044..ad99ddfa7 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportGetAlertsAction.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportGetAlertsAction.kt @@ -103,8 +103,7 @@ class TransportGetAlertsAction @Inject constructor( // and only be shown in "associated alerts" field under get workflow_alerts API. // But if the API is called with query_params: state=AUDIT,monitor_id=<123>,workflow_id=, this api // will return audit alerts generated by delegate monitor <123> in workflow - QueryBuilders.boolQuery() - .filter(QueryBuilders.boolQuery().mustNot(QueryBuilders.termsQuery(Alert.STATE_FIELD, Alert.State.AUDIT.name))) + queryBuilder.filter(QueryBuilders.boolQuery().mustNot(QueryBuilders.termsQuery(Alert.STATE_FIELD, Alert.State.AUDIT.name))) } else { queryBuilder.filter(QueryBuilders.termQuery("state", getAlertsRequest.alertState)) } diff --git a/alerting/src/test/kotlin/org/opensearch/alerting/resthandler/WorkflowRestApiIT.kt b/alerting/src/test/kotlin/org/opensearch/alerting/resthandler/WorkflowRestApiIT.kt index e7cc5eddb..8d9de4973 100644 --- a/alerting/src/test/kotlin/org/opensearch/alerting/resthandler/WorkflowRestApiIT.kt +++ b/alerting/src/test/kotlin/org/opensearch/alerting/resthandler/WorkflowRestApiIT.kt @@ -1113,11 +1113,11 @@ class WorkflowRestApiIT : AlertingRestTestCase() { val associatedAlerts = getWorkflowAlerts["associatedAlerts"] as List> assertEquals(associatedAlerts.size, 2) - val getAlertsRes = getAlerts(java.util.Map.of("workflowIds", listOf(workflowId))) + val getAlertsRes = getAlerts() val getAlertsMap = getAlertsRes.asMap() Assert.assertTrue(getAlertsMap.containsKey("alerts")) - val getAlertsAlerts = getWorkflowAlerts["alerts"] as List> - assertEquals(alerts.size, 1) + val getAlertsAlerts = (getAlertsMap["alerts"] as ArrayList>) + assertEquals(getAlertsAlerts.size, 1) Assert.assertEquals(getAlertsAlerts[0]["execution_id"], executionId) Assert.assertEquals(getAlertsAlerts[0]["workflow_id"], workflowId) Assert.assertEquals(getAlertsAlerts[0]["monitor_id"], "")