Skip to content

Commit

Permalink
Fix getAlerts API for standard Alerting monitors (opensearch-project#870
Browse files Browse the repository at this point in the history
) (opensearch-project#875)

* Fix getAlerts API for standard Alerting monitors

Signed-off-by: Ashish Agrawal <[email protected]>
  • Loading branch information
lezzago authored Apr 18, 2023
1 parent 2ac70d2 commit 493139e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,10 @@ class TransportGetAlertsAction @Inject constructor(
}
}
}
return alertIndex
return if (alertIndex == AlertIndices.ALERT_INDEX)
AlertIndices.ALL_ALERT_INDEX_PATTERN
else
alertIndex
}

fun getAlerts(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -832,6 +832,34 @@ class MonitorRestApiIT : AlertingRestTestCase() {
)
}

fun `test delete trigger moves alerts then try to search alert by monitorId to find alert in history index`() {
client().updateSettings(ScheduledJobSettings.SWEEPER_ENABLED.key, true)
putAlertMappings()
val trigger = randomQueryLevelTrigger()
val monitor = createMonitor(randomQueryLevelMonitor(triggers = listOf(trigger)))
val alert = createAlert(randomAlert(monitor).copy(triggerId = trigger.id, state = Alert.State.ACTIVE))
refreshIndex("*")
val updatedMonitor = monitor.copy(triggers = emptyList())
val updateResponse = client().makeRequest(
"PUT", "$ALERTING_BASE_URI/${monitor.id}", emptyMap(),
updatedMonitor.toHttpEntity()
)
assertEquals("Update request not successful", RestStatus.OK, updateResponse.restStatus())

// Wait 5 seconds for event to be processed and alerts moved
Thread.sleep(5000)

val alerts = searchAlerts(monitor)
assertEquals("Active alert was not deleted", 0, alerts.size)

// Find alert by id and make sure it checks the history of alerts as well
val inputMap = HashMap<String, Any>()
inputMap["monitorId"] = monitor.id
val responseMap = getAlerts(inputMap).asMap()

assertEquals(1, responseMap["totalAlerts"])
}

fun `test delete trigger moves alerts`() {
client().updateSettings(ScheduledJobSettings.SWEEPER_ENABLED.key, true)
putAlertMappings()
Expand Down

0 comments on commit 493139e

Please sign in to comment.