From eb481a6784ca0782b0dcef7cdeb9d89769001246 Mon Sep 17 00:00:00 2001 From: Surya Sashank Nistala Date: Tue, 12 Sep 2023 18:40:57 -0700 Subject: [PATCH] add workflow null or empty check only when empty workflow id passed. change Rest get alert handler to add empty string singleton list for workflow ids when none is passed Signed-off-by: Surya Sashank Nistala --- .../opensearch/alerting/resthandler/RestGetAlertsAction.kt | 2 ++ .../opensearch/alerting/transport/TransportGetAlertsAction.kt | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/resthandler/RestGetAlertsAction.kt b/alerting/src/main/kotlin/org/opensearch/alerting/resthandler/RestGetAlertsAction.kt index cf83cec8c..aabcf8d6c 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/resthandler/RestGetAlertsAction.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/resthandler/RestGetAlertsAction.kt @@ -61,6 +61,8 @@ class RestGetAlertsAction : BaseRestHandler() { val workflowIds = mutableListOf() if (workflowId.isNullOrEmpty() == false) { workflowIds.add(workflowId) + } else { + workflowIds.add("") } val table = Table( sortOrder, 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 9308d8fb6..3d1beb13f 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportGetAlertsAction.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportGetAlertsAction.kt @@ -123,7 +123,9 @@ class TransportGetAlertsAction @Inject constructor( } } else if (getAlertsRequest.monitorIds.isNullOrEmpty() == false) { queryBuilder.filter(QueryBuilders.termsQuery("monitor_id", getAlertsRequest.monitorIds)) - if (getAlertsRequest.workflowIds.isNullOrEmpty()) { + if ( + getAlertsRequest.workflowIds != null && getAlertsRequest.workflowIds!!.size == 1 && getAlertsRequest.workflowIds!![0] == "" + ) { val noWorkflowIdQuery = QueryBuilders.boolQuery() .should(QueryBuilders.boolQuery().mustNot(QueryBuilders.existsQuery(Alert.WORKFLOW_ID_FIELD))) .should(QueryBuilders.termsQuery(Alert.WORKFLOW_ID_FIELD, ""))