Skip to content

Commit

Permalink
Added comments based on PR feedback.
Browse files Browse the repository at this point in the history
Signed-off-by: AWSHurneyt <[email protected]>
  • Loading branch information
AWSHurneyt committed Mar 14, 2024
1 parent 4bd853c commit 235056c
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ object BucketLevelMonitorRunner : MonitorRunner() {
?.addAll(monitorCtx.alertService!!.convertToCompletedAlerts(keysToAlertsMap))
}

// The alertSampleDocs map structure is Map<TriggerId, Map<BucketKeysHash, List<Alert>>>
val alertSampleDocs = mutableMapOf<String, Map<String, List<Map<String, Any>>>>()
for (trigger in monitor.triggers) {
val alertsToUpdate = mutableSetOf<Alert>()
Expand Down Expand Up @@ -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,
Expand All @@ -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<BucketKeysHash, List<Alert>>
*/
@Suppress("UNCHECKED_CAST")
private suspend fun getSampleDocs(
client: Client,
Expand All @@ -558,7 +565,6 @@ object BucketLevelMonitorRunner : MonitorRunner() {
searchRequest: SearchRequest
): Map<String, List<Map<String, Any>>> {
val sampleDocumentsByBucket = mutableMapOf<String, List<Map<String, Any>>>()

val searchResponse: SearchResponse = client.suspendUntil { client.search(searchRequest, it) }
val aggs = searchResponse.convertToMap().getOrDefault("aggregations", mapOf<String, Any>()) as Map<String, Any>
val compositeAgg = aggs.getOrDefault("composite_agg", mapOf<String, Any>()) as Map<String, Any>
Expand Down

0 comments on commit 235056c

Please sign in to comment.