From 03acc539b5d98893ab5075b22cbc528d8488a31a Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Wed, 2 Aug 2023 13:49:36 -0700 Subject: [PATCH] fix get alerts alertState query filter (#1064) (#1066) Signed-off-by: Surya Sashank Nistala (cherry picked from commit 3ad13650d2caddefa871a13e16c01c485c09ee82) Co-authored-by: Surya Sashank Nistala --- .../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 13e1745a4..9f6b08819 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportGetAlertsAction.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportGetAlertsAction.kt @@ -104,8 +104,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 c3d103b09..6d1e34bad 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"], "")