@@ -516,6 +516,76 @@ class MonitorDataSourcesIT : AlertingSingleNodeTestCase() {
516
516
assertEquals(" Alerts from custom history index" , 1 , alerts.size)
517
517
}
518
518
519
+ fun `test search custom alerts history index after alert ack` () {
520
+ val docQuery = DocLevelQuery (query = " test_field:\" us-west-2\" " , name = " 3" )
521
+ val docLevelInput = DocLevelMonitorInput (" description" , listOf (index), listOf (docQuery))
522
+ val trigger1 = randomDocumentLevelTrigger(condition = ALWAYS_RUN )
523
+ val trigger2 = randomDocumentLevelTrigger(condition = ALWAYS_RUN )
524
+ val customAlertsIndex = " custom_alerts_index"
525
+ val customAlertsHistoryIndex = " custom_alerts_history_index"
526
+ val customAlertsHistoryIndexPattern = " <custom_alerts_history_index-{now/d}-1>"
527
+ var monitor = randomDocumentLevelMonitor(
528
+ inputs = listOf (docLevelInput),
529
+ triggers = listOf (trigger1, trigger2),
530
+ dataSources = DataSources (
531
+ alertsIndex = customAlertsIndex,
532
+ alertsHistoryIndex = customAlertsHistoryIndex,
533
+ alertsHistoryIndexPattern = customAlertsHistoryIndexPattern
534
+ )
535
+ )
536
+ val monitorResponse = createMonitor(monitor)
537
+ val testTime = DateTimeFormatter .ISO_OFFSET_DATE_TIME .format(ZonedDateTime .now().truncatedTo(MILLIS ))
538
+ val testDoc = """ {
539
+ "message" : "This is an error from IAD region",
540
+ "test_strict_date_time" : "$testTime ",
541
+ "test_field" : "us-west-2"
542
+ }"""
543
+ assertFalse(monitorResponse?.id.isNullOrEmpty())
544
+ monitor = monitorResponse!! .monitor
545
+ indexDoc(index, " 1" , testDoc)
546
+ val monitorId = monitorResponse.id
547
+ val executeMonitorResponse = executeMonitor(monitor, monitorId, false )
548
+ var alertsBefore = searchAlerts(monitorId, customAlertsIndex)
549
+ Assert .assertEquals(2 , alertsBefore.size)
550
+ Assert .assertEquals(executeMonitorResponse!! .monitorRunResult.monitorName, monitor.name)
551
+ Assert .assertEquals(executeMonitorResponse.monitorRunResult.triggerResults.size, 2 )
552
+
553
+ var alerts = listOf<Alert >()
554
+ OpenSearchTestCase .waitUntil({
555
+ alerts = searchAlerts(monitorId, customAlertsIndex)
556
+ if (alerts.size == 1 ) {
557
+ return @waitUntil true
558
+ }
559
+ return @waitUntil false
560
+ }, 30 , TimeUnit .SECONDS )
561
+ assertEquals(" Alerts from custom index" , 2 , alerts.size)
562
+
563
+ val ackReq = AcknowledgeAlertRequest (monitorId, alerts.map { it.id }.toMutableList(), WriteRequest .RefreshPolicy .IMMEDIATE )
564
+ client().execute(AlertingActions .ACKNOWLEDGE_ALERTS_ACTION_TYPE , ackReq).get()
565
+
566
+ // verify alerts moved from alert index to alert history index
567
+ alerts = listOf<Alert >()
568
+ OpenSearchTestCase .waitUntil({
569
+ alerts = searchAlerts(monitorId, customAlertsHistoryIndex)
570
+ if (alerts.size == 1 ) {
571
+ return @waitUntil true
572
+ }
573
+ return @waitUntil false
574
+ }, 30 , TimeUnit .SECONDS )
575
+ assertEquals(" Alerts from custom history index" , 2 , alerts.size)
576
+
577
+ // verify alerts deleted from alert index
578
+ alerts = listOf<Alert >()
579
+ OpenSearchTestCase .waitUntil({
580
+ alerts = searchAlerts(monitorId, customAlertsIndex)
581
+ if (alerts.size == 1 ) {
582
+ return @waitUntil true
583
+ }
584
+ return @waitUntil false
585
+ }, 30 , TimeUnit .SECONDS )
586
+ assertEquals(" Alerts from custom history index" , 0 , alerts.size)
587
+ }
588
+
519
589
fun `test get alerts by list of monitors containing both existent and non-existent ids` () {
520
590
val docQuery = DocLevelQuery (query = " test_field:\" us-west-2\" " , name = " 3" )
521
591
val docLevelInput = DocLevelMonitorInput (" description" , listOf (index), listOf (docQuery))
0 commit comments