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 1325 to 2.4 #1376

Open
wants to merge 2 commits into
base: 2.4
Choose a base branch
from
Open
Show file tree
Hide file tree
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 @@ -218,8 +218,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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """{
Expand Down
Loading