Skip to content

Commit ee15812

Browse files
Backport #1325 to 2.11 (#1351) (#1363)
* Set docData to empty string if actual is null (#1325) (cherry picked from commit 008e076) * Remove not yet introduced parameter fields --------- (cherry picked from commit 6368979) Signed-off-by: Chase Engelbrecht <[email protected]> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent e7505da commit ee15812

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportGetFindingsAction.kt

+3-2
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,9 @@ class TransportGetFindingsSearchAction @Inject constructor(
221221
val documents: MutableMap<String, FindingDocument> = mutableMapOf()
222222
response.responses.forEach {
223223
val key = "${it.index}|${it.id}"
224-
val docData = if (it.isFailed) "" else it.response.sourceAsString
225-
val findingDocument = FindingDocument(it.index, it.id, !it.isFailed, docData)
224+
val isDocFound = !(it.isFailed || it.response.sourceAsString == null)
225+
val docData = if (isDocFound) it.response.sourceAsString else ""
226+
val findingDocument = FindingDocument(it.index, it.id, isDocFound, docData)
226227
documents[key] = findingDocument
227228
}
228229

alerting/src/test/kotlin/org/opensearch/alerting/resthandler/FindingsRestApiIT.kt

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

34+
fun `test find Finding where source docData is null`() {
35+
val testIndex = createTestIndex()
36+
val testDoc = """{
37+
"message" : "This is an error from IAD region",
38+
"test_field" : "us-west-2"
39+
}"""
40+
indexDoc(testIndex, "someId", testDoc)
41+
42+
val docQuery = DocLevelQuery(query = "test_field:\"us-west-2\"", name = "3")
43+
val docLevelInput = DocLevelMonitorInput("description", listOf(testIndex), listOf(docQuery))
44+
val trigger = randomDocumentLevelTrigger(condition = ALWAYS_RUN)
45+
val trueMonitor = createMonitor(randomDocumentLevelMonitor(inputs = listOf(docLevelInput), triggers = listOf(trigger)))
46+
executeMonitor(trueMonitor.id, mapOf(Pair("dryrun", "true")))
47+
48+
createFinding(matchingDocIds = listOf("someId"), index = testIndex)
49+
val responseBeforeDelete = searchFindings()
50+
assertEquals(1, responseBeforeDelete.totalFindings)
51+
assertEquals(1, responseBeforeDelete.findings[0].documents.size)
52+
assertTrue(responseBeforeDelete.findings[0].documents[0].found)
53+
54+
deleteDoc(testIndex, "someId")
55+
val responseAfterDelete = searchFindings()
56+
assertEquals(1, responseAfterDelete.totalFindings)
57+
assertEquals(1, responseAfterDelete.findings[0].documents.size)
58+
assertFalse(responseAfterDelete.findings[0].documents[0].found)
59+
}
60+
3461
fun `test find Finding where doc is retrieved`() {
3562
val testIndex = createTestIndex()
3663
val testDoc = """{

0 commit comments

Comments
 (0)