From 235056c334f7988783aa5eee8efcd00fdf86d7da Mon Sep 17 00:00:00 2001 From: AWSHurneyt Date: Wed, 13 Mar 2024 23:29:10 -0700 Subject: [PATCH] Added comments based on PR feedback. Signed-off-by: AWSHurneyt --- .../opensearch/alerting/BucketLevelMonitorRunner.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/BucketLevelMonitorRunner.kt b/alerting/src/main/kotlin/org/opensearch/alerting/BucketLevelMonitorRunner.kt index 193c3db06..4ef74127d 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/BucketLevelMonitorRunner.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/BucketLevelMonitorRunner.kt @@ -224,6 +224,7 @@ object BucketLevelMonitorRunner : MonitorRunner() { ?.addAll(monitorCtx.alertService!!.convertToCompletedAlerts(keysToAlertsMap)) } + // The alertSampleDocs map structure is Map>> val alertSampleDocs = mutableMapOf>>>() for (trigger in monitor.triggers) { val alertsToUpdate = mutableSetOf() @@ -539,7 +540,7 @@ object BucketLevelMonitorRunner : MonitorRunner() { return if (!bucketKey.isNullOrEmpty() && !sampleDocs.isNullOrEmpty()) { AlertContext(alert = alert, sampleDocs = sampleDocs) } else { - logger.warn( + logger.error( "Failed to retrieve sample documents for alert {} from trigger {} of monitor {} during execution {}.", alert.id, alert.triggerId, @@ -550,6 +551,12 @@ object BucketLevelMonitorRunner : MonitorRunner() { } } + /** + * Executes the monitor's query with the addition of 2 top_hits aggregations that are used to return the top 5, + * and bottom 5 documents for each bucket. + * + * @return Map> + */ @Suppress("UNCHECKED_CAST") private suspend fun getSampleDocs( client: Client, @@ -558,7 +565,6 @@ object BucketLevelMonitorRunner : MonitorRunner() { searchRequest: SearchRequest ): Map>> { val sampleDocumentsByBucket = mutableMapOf>>() - val searchResponse: SearchResponse = client.suspendUntil { client.search(searchRequest, it) } val aggs = searchResponse.convertToMap().getOrDefault("aggregations", mapOf()) as Map val compositeAgg = aggs.getOrDefault("composite_agg", mapOf()) as Map