From 5d655264a74a384636c5382db8cf557efc989ae3 Mon Sep 17 00:00:00 2001 From: Surya Sashank Nistala Date: Wed, 21 Jun 2023 13:46:29 -0700 Subject: [PATCH] adds audit state in Alert Signed-off-by: Surya Sashank Nistala --- .../org/opensearch/commons/alerting/model/Alert.kt | 7 ++++++- .../org/opensearch/commons/alerting/AlertTests.kt | 12 +++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/org/opensearch/commons/alerting/model/Alert.kt b/src/main/kotlin/org/opensearch/commons/alerting/model/Alert.kt index 0ff9d6b7..a873cb93 100644 --- a/src/main/kotlin/org/opensearch/commons/alerting/model/Alert.kt +++ b/src/main/kotlin/org/opensearch/commons/alerting/model/Alert.kt @@ -171,7 +171,12 @@ data class Alert( ) enum class State { - ACTIVE, ACKNOWLEDGED, COMPLETED, ERROR, DELETED + ACTIVE, ACKNOWLEDGED, COMPLETED, ERROR, DELETED, + // Alerts are created in audit state when they are generated by delegate monitors of a workflow. + // since chained alerts can be configured and acknowledged, the underlying monitors' alerts are simply + // for evaluating chained alert triggers and auditing purpose. + // Audit state alerts will be created in the history index and do not need to be acknowledged by users. + AUDIT } @Throws(IOException::class) diff --git a/src/test/kotlin/org/opensearch/commons/alerting/AlertTests.kt b/src/test/kotlin/org/opensearch/commons/alerting/AlertTests.kt index 29b32bb5..e6801b5a 100644 --- a/src/test/kotlin/org/opensearch/commons/alerting/AlertTests.kt +++ b/src/test/kotlin/org/opensearch/commons/alerting/AlertTests.kt @@ -4,7 +4,8 @@ import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test import org.opensearch.commons.alerting.model.Alert -import kotlin.test.assertTrue +import java.time.Instant +import java.time.temporal.ChronoUnit class AlertTests { @Test @@ -60,6 +61,15 @@ class AlertTests { Assertions.assertFalse(activeAlert.isAcknowledged(), "Alert is acknowledged") } + @Test + fun `test alert in audit state`() { + val auditAlert = Alert( + randomQueryLevelMonitor(), randomQueryLevelTrigger(), Instant.now().truncatedTo(ChronoUnit.MILLIS), + null, actionExecutionResults = listOf(randomActionExecutionResult()) + ) + Assertions.assertFalse(auditAlert.isAcknowledged(), "Alert shoudl not be in acknowledged state") + } + @Test fun `test chained alert`() { val workflow = randomWorkflow()