From a898e683b3a2ec616b9140a38b658f3281f1057f Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 12 Jun 2025 22:30:14 +0000 Subject: [PATCH] now publishes a list of findings instead of an individual one (#1860) * now publishes a list of findings instead of an individual one Signed-off-by: Dennis Toepker * publish batch findings method Signed-off-by: Dennis Toepker * adding success and failure logs when publishing findings Signed-off-by: Dennis Toepker * reverting name change and replaced info with debug log Signed-off-by: Dennis Toepker * more logging polishing Signed-off-by: Dennis Toepker --------- Signed-off-by: Dennis Toepker Co-authored-by: Dennis Toepker (cherry picked from commit 381a82e82e7f4343bd61770529dfb8ffd90e9bd5) Signed-off-by: github-actions[bot] --- .../TransportDocLevelMonitorFanOutAction.kt | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportDocLevelMonitorFanOutAction.kt b/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportDocLevelMonitorFanOutAction.kt index 12d7daf0b..27d5ee774 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportDocLevelMonitorFanOutAction.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportDocLevelMonitorFanOutAction.kt @@ -75,6 +75,7 @@ import org.opensearch.commons.alerting.AlertingPluginInterface import org.opensearch.commons.alerting.action.DocLevelMonitorFanOutAction import org.opensearch.commons.alerting.action.DocLevelMonitorFanOutRequest import org.opensearch.commons.alerting.action.DocLevelMonitorFanOutResponse +import org.opensearch.commons.alerting.action.PublishBatchFindingsRequest import org.opensearch.commons.alerting.action.PublishFindingsRequest import org.opensearch.commons.alerting.action.SubscribeFindingsResponse import org.opensearch.commons.alerting.model.ActionExecutionResult @@ -613,9 +614,7 @@ class TransportDocLevelMonitorFanOutAction if (monitor.shouldCreateSingleAlertForFindings == null || monitor.shouldCreateSingleAlertForFindings == false) { try { - findings.forEach { finding -> - publishFinding(monitor, finding) - } + publishBatchFindings(monitor, findings) } catch (e: Exception) { // suppress exception log.error("Optional finding callback failed", e) @@ -663,6 +662,27 @@ class TransportDocLevelMonitorFanOutAction ) } + private fun publishBatchFindings( + monitor: Monitor, + findings: List + ) { + val publishBatchFindingsRequest = PublishBatchFindingsRequest(monitor.id, findings) + log.debug("publishing {} findings from node {}", findings.size, clusterService.localNode().id) + AlertingPluginInterface.publishBatchFindings( + client as NodeClient, + publishBatchFindingsRequest, + object : ActionListener { + override fun onResponse(response: SubscribeFindingsResponse) { + log.debug("findings published successfully") + } + + override fun onFailure(e: Exception) { + log.error("publishing findings failed", e) + } + } + ) + } + suspend fun runAction( action: Action, ctx: TriggerExecutionContext,