Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.x] DocLevel Monitor - generate findings when 0 triggers #895

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import org.opensearch.commons.alerting.model.Alert.State.ACTIVE
import org.opensearch.commons.alerting.model.Alert.State.COMPLETED
import org.opensearch.commons.alerting.model.Alert.State.ERROR
import org.opensearch.commons.alerting.model.DataSources
import org.opensearch.commons.alerting.model.DocLevelMonitorInput
import org.opensearch.commons.alerting.model.DocLevelQuery
import org.opensearch.commons.alerting.model.IntervalSchedule
import org.opensearch.commons.alerting.model.Monitor
import org.opensearch.commons.alerting.model.SearchInput
Expand Down Expand Up @@ -53,7 +55,6 @@ import java.time.temporal.ChronoUnit
import java.time.temporal.ChronoUnit.DAYS
import java.time.temporal.ChronoUnit.MILLIS
import java.time.temporal.ChronoUnit.MINUTES
import kotlin.collections.HashMap

class MonitorRunnerServiceIT : AlertingRestTestCase() {

Expand Down Expand Up @@ -195,6 +196,31 @@ class MonitorRunnerServiceIT : AlertingRestTestCase() {
Assert.assertEquals(404, exception?.response?.statusLine?.statusCode)
}

fun `test execute doclevel monitor without triggers success`() {
// use a non-existent monitoid to trigger a 404.
val index = "foo"
createIndex(index, Settings.EMPTY)
val docQuery = DocLevelQuery(query = "test_field:\"us-west-2\"", name = "1")
val docLevelInput = DocLevelMonitorInput("description", listOf(index), listOf(docQuery))
val monitor = createMonitor(
randomDocumentLevelMonitor(
inputs = listOf(docLevelInput),
triggers = listOf()
)
)
val doc = """
{ "test_field": "us-west-2" }
""".trimIndent()
indexDoc(index, "1", doc)

val response = executeMonitor(monitor.id)
var output = entityAsMap(response)
assertEquals(monitor.name, output["monitor_name"])
assertTrue("Unexpected monitor error message", (output["error"] as String?).isNullOrEmpty())
assertTrue(searchFindings(monitor).size == 1)
assertTrue(searchAlerts(monitor).isEmpty())
}

fun `test acknowledged alert does not suppress subsequent errors`() {
val destinationId = createDestination().id

Expand Down
Loading