Skip to content

Commit f1c0f1d

Browse files
authored
adds audit state in Alert (#461)
Signed-off-by: Surya Sashank Nistala <[email protected]>
1 parent fcb853e commit f1c0f1d

File tree

2 files changed

+17
-2
lines changed
  • src
    • main/kotlin/org/opensearch/commons/alerting/model
    • test/kotlin/org/opensearch/commons/alerting

2 files changed

+17
-2
lines changed

src/main/kotlin/org/opensearch/commons/alerting/model/Alert.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,12 @@ data class Alert(
171171
)
172172

173173
enum class State {
174-
ACTIVE, ACKNOWLEDGED, COMPLETED, ERROR, DELETED
174+
ACTIVE, ACKNOWLEDGED, COMPLETED, ERROR, DELETED,
175+
// Alerts are created in audit state when they are generated by delegate monitors of a workflow.
176+
// since chained alerts can be configured and acknowledged, the underlying monitors' alerts are simply
177+
// for evaluating chained alert triggers and auditing purpose.
178+
// Audit state alerts will be created in the history index and do not need to be acknowledged by users.
179+
AUDIT
175180
}
176181

177182
@Throws(IOException::class)

src/test/kotlin/org/opensearch/commons/alerting/AlertTests.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import org.junit.jupiter.api.Assertions
44
import org.junit.jupiter.api.Assertions.assertEquals
55
import org.junit.jupiter.api.Test
66
import org.opensearch.commons.alerting.model.Alert
7-
import kotlin.test.assertTrue
7+
import java.time.Instant
8+
import java.time.temporal.ChronoUnit
89

910
class AlertTests {
1011
@Test
@@ -60,6 +61,15 @@ class AlertTests {
6061
Assertions.assertFalse(activeAlert.isAcknowledged(), "Alert is acknowledged")
6162
}
6263

64+
@Test
65+
fun `test alert in audit state`() {
66+
val auditAlert = Alert(
67+
randomQueryLevelMonitor(), randomQueryLevelTrigger(), Instant.now().truncatedTo(ChronoUnit.MILLIS),
68+
null, actionExecutionResults = listOf(randomActionExecutionResult())
69+
)
70+
Assertions.assertFalse(auditAlert.isAcknowledged(), "Alert should not be in acknowledged state")
71+
}
72+
6373
@Test
6474
fun `test chained alert`() {
6575
val workflow = randomWorkflow()

0 commit comments

Comments
 (0)