Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: opensearch-project/alerting
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 71225fdcc529dc6ce1c0f6bd787c1f275a2eb7d7
Choose a base ref
..
head repository: opensearch-project/alerting
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 3be6dcf39edb982c35bcc6c68513ac032faf33bd
Choose a head ref
Original file line number Diff line number Diff line change
@@ -221,8 +221,9 @@ class TransportGetFindingsSearchAction @Inject constructor(
val documents: MutableMap<String, FindingDocument> = mutableMapOf()
response.responses.forEach {
val key = "${it.index}|${it.id}"
val docData = if (it.isFailed) "" else it.response.sourceAsString
val findingDocument = FindingDocument(it.index, it.id, !it.isFailed, docData)
val isDocFound = !(it.isFailed || it.response.sourceAsString == null)
val docData = if (isDocFound) it.response.sourceAsString else ""
val findingDocument = FindingDocument(it.index, it.id, isDocFound, docData)
documents[key] = findingDocument
}

Original file line number Diff line number Diff line change
@@ -31,6 +31,33 @@ class FindingsRestApiIT : AlertingRestTestCase() {
assertFalse(response.findings[0].documents[0].found)
}

fun `test find Finding where source docData is null`() {
val testIndex = createTestIndex()
val testDoc = """{
"message" : "This is an error from IAD region",
"test_field" : "us-west-2"
}"""
indexDoc(testIndex, "someId", testDoc)

val docQuery = DocLevelQuery(query = "test_field:\"us-west-2\"", name = "3")
val docLevelInput = DocLevelMonitorInput("description", listOf(testIndex), listOf(docQuery))
val trigger = randomDocumentLevelTrigger(condition = ALWAYS_RUN)
val trueMonitor = createMonitor(randomDocumentLevelMonitor(inputs = listOf(docLevelInput), triggers = listOf(trigger)))
executeMonitor(trueMonitor.id, mapOf(Pair("dryrun", "true")))

createFinding(matchingDocIds = listOf("someId"), index = testIndex)
val responseBeforeDelete = searchFindings()
assertEquals(1, responseBeforeDelete.totalFindings)
assertEquals(1, responseBeforeDelete.findings[0].documents.size)
assertTrue(responseBeforeDelete.findings[0].documents[0].found)

deleteDoc(testIndex, "someId")
val responseAfterDelete = searchFindings()
assertEquals(1, responseAfterDelete.totalFindings)
assertEquals(1, responseAfterDelete.findings[0].documents.size)
assertFalse(responseAfterDelete.findings[0].documents[0].found)
}

fun `test find Finding where doc is retrieved`() {
val testIndex = createTestIndex()
val testDoc = """{