Skip to content

Commit

Permalink
add integTest for multiple datastreams inside a single index pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
sbcd90 committed Dec 8, 2023
1 parent fc3892b commit 7bd3927
Showing 1 changed file with 86 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1395,6 +1395,92 @@ class DocumentMonitorRunnerIT : AlertingRestTestCase() {
deleteIndexAlias(aliasName)
}

fun `test document-level monitor when multiple datastreams contain docs across read-only indices that do match query`() {
val dataStreamName1 = "test-datastream1"
createDataStream(
dataStreamName1,
"""
"properties" : {
"test_strict_date_time" : { "type" : "date", "format" : "strict_date_time" },
"test_field" : { "type" : "keyword" },
"number" : { "type" : "keyword" }
}
""".trimIndent(),
false
)
val dataStreamName2 = "test-datastream2"
createDataStream(
dataStreamName2,
"""
"properties" : {
"test_strict_date_time" : { "type" : "date", "format" : "strict_date_time" },
"test_field" : { "type" : "keyword" },
"number" : { "type" : "keyword" }
}
""".trimIndent(),
false
)

val testTime = DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(ZonedDateTime.now().truncatedTo(MILLIS))
val testDoc = """{
"@timestamp": "$testTime",
"message" : "This is an error from IAD region",
"test_strict_date_time" : "$testTime",
"test_field" : "us-west-2"
}"""
indexDoc(dataStreamName2, "-1", testDoc)
rolloverDatastream(dataStreamName2)
indexDoc(dataStreamName2, "0", testDoc)

val docQuery = DocLevelQuery(query = "test_field:\"us-west-2\"", name = "3", fields = listOf())
val docLevelInput = DocLevelMonitorInput("description", listOf("test-datastream*"), listOf(docQuery))

val action = randomAction(template = randomTemplateScript("Hello {{ctx.monitor.name}}"), destinationId = createDestination().id)
val monitor = createMonitor(
randomDocumentLevelMonitor(
inputs = listOf(docLevelInput),
triggers = listOf(randomDocumentLevelTrigger(condition = ALWAYS_RUN, actions = listOf(action)))
)
)

indexDoc(dataStreamName1, "1", testDoc)
indexDoc(dataStreamName2, "1", testDoc)
var response = executeMonitor(monitor.id)
var output = entityAsMap(response)
var searchResult = (output.objectMap("input_results")["results"] as List<Map<String, Any>>).first()
@Suppress("UNCHECKED_CAST")
var matchingDocsToQuery = searchResult[docQuery.id] as List<String>
assertEquals("Incorrect search result", 2, matchingDocsToQuery.size)

indexDoc(dataStreamName1, "2", testDoc)
indexDoc(dataStreamName2, "2", testDoc)
rolloverDatastream(dataStreamName1)
rolloverDatastream(dataStreamName1)
rolloverDatastream(dataStreamName2)
indexDoc(dataStreamName1, "4", testDoc)
indexDoc(dataStreamName2, "4", testDoc)
rolloverDatastream(dataStreamName1)
response = executeMonitor(monitor.id)
output = entityAsMap(response)
searchResult = (output.objectMap("input_results")["results"] as List<Map<String, Any>>).first()
@Suppress("UNCHECKED_CAST")
matchingDocsToQuery = searchResult[docQuery.id] as List<String>
assertEquals("Incorrect search result", 4, matchingDocsToQuery.size)

indexDoc(dataStreamName1, "5", testDoc)
indexDoc(dataStreamName1, "6", testDoc)
indexDoc(dataStreamName2, "5", testDoc)
indexDoc(dataStreamName2, "6", testDoc)
response = executeMonitor(monitor.id)
output = entityAsMap(response)
searchResult = (output.objectMap("input_results")["results"] as List<Map<String, Any>>).first()
@Suppress("UNCHECKED_CAST")
matchingDocsToQuery = searchResult[docQuery.id] as List<String>
assertEquals("Incorrect search result", 4, matchingDocsToQuery.size)
deleteDataStream(dataStreamName1)
deleteDataStream(dataStreamName2)
}

fun `test document-level monitor ignoring old read-only indices for datastreams`() {
val dataStreamName = "test-datastream"
createDataStream(
Expand Down

0 comments on commit 7bd3927

Please sign in to comment.