Skip to content

Commit 381a82e

Browse files
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 <[email protected]> * publish batch findings method Signed-off-by: Dennis Toepker <[email protected]> * adding success and failure logs when publishing findings Signed-off-by: Dennis Toepker <[email protected]> * reverting name change and replaced info with debug log Signed-off-by: Dennis Toepker <[email protected]> * more logging polishing Signed-off-by: Dennis Toepker <[email protected]> --------- Signed-off-by: Dennis Toepker <[email protected]> Co-authored-by: Dennis Toepker <[email protected]>
1 parent 9bf6d54 commit 381a82e

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportDocLevelMonitorFanOutAction.kt

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ import org.opensearch.commons.alerting.AlertingPluginInterface
7474
import org.opensearch.commons.alerting.action.DocLevelMonitorFanOutAction
7575
import org.opensearch.commons.alerting.action.DocLevelMonitorFanOutRequest
7676
import org.opensearch.commons.alerting.action.DocLevelMonitorFanOutResponse
77+
import org.opensearch.commons.alerting.action.PublishBatchFindingsRequest
7778
import org.opensearch.commons.alerting.action.PublishFindingsRequest
7879
import org.opensearch.commons.alerting.action.SubscribeFindingsResponse
7980
import org.opensearch.commons.alerting.model.ActionExecutionResult
@@ -614,9 +615,7 @@ class TransportDocLevelMonitorFanOutAction
614615

615616
if (monitor.shouldCreateSingleAlertForFindings == null || monitor.shouldCreateSingleAlertForFindings == false) {
616617
try {
617-
findings.forEach { finding ->
618-
publishFinding(monitor, finding)
619-
}
618+
publishBatchFindings(monitor, findings)
620619
} catch (e: Exception) {
621620
// suppress exception
622621
log.error("Optional finding callback failed", e)
@@ -664,6 +663,27 @@ class TransportDocLevelMonitorFanOutAction
664663
)
665664
}
666665

666+
private fun publishBatchFindings(
667+
monitor: Monitor,
668+
findings: List<Finding>
669+
) {
670+
val publishBatchFindingsRequest = PublishBatchFindingsRequest(monitor.id, findings)
671+
log.debug("publishing {} findings from node {}", findings.size, clusterService.localNode().id)
672+
AlertingPluginInterface.publishBatchFindings(
673+
client as NodeClient,
674+
publishBatchFindingsRequest,
675+
object : ActionListener<SubscribeFindingsResponse> {
676+
override fun onResponse(response: SubscribeFindingsResponse) {
677+
log.debug("findings published successfully")
678+
}
679+
680+
override fun onFailure(e: Exception) {
681+
log.error("publishing findings failed", e)
682+
}
683+
}
684+
)
685+
}
686+
667687
suspend fun runAction(
668688
action: Action,
669689
ctx: TriggerExecutionContext,

0 commit comments

Comments
 (0)