Skip to content

Conversation

sbcd90
Copy link
Collaborator

@sbcd90 sbcd90 commented Jul 29, 2025

Description

contextualize findings with additional metadata fields

Related Issues

Resolves #[Issue number to be closed when this PR is merged]

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • Public documentation issue/PR created.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.


// Before the "|" is the doc id and after the "|" is the index
val docIndex = it.key.split("|")
val additionalFields = this.fetchDocForFinding(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Making a search call per doc is not going to scale.

We have the document in memory as part of the monitor execution. Can we add these additional fields when we fetch that document and then carry them forward from memory?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@engechas findings are sparse
IMO we should do a second search in bulk for all finding-generating docs

Copy link
Member

@eirsep eirsep left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what

return response.hits
}

private suspend fun fetchDocForFinding(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plz add debug and info logs
time taken for search request

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fetch all docs for findings in single call

}
}
val response: SearchResponse = client.suspendUntil { client.search(request, it) }
if (response.status() !== RestStatus.OK) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error log

.fetchSource(false)
)

if (fields.isNotEmpty()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this check should be preliminary to assert that if its empty this search is useless

}

val additionalFields: MutableMap<String, List<Any>> = mutableMapOf()
for (field in response.hits.hits[0].fields) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check for empty hits
this is a walking ArrayOutOfBoundsException.

assertEquals(found.get(), false)
}

fun `test execute monitor with dryrun with finding metadata enabled`() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why dry run
plz add more test cases

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add test where additional fields are invalid. additoinal fields list is empty.

val additionalFields = this.fetchDocForFinding(
docIndex[1],
docIndex[0],
monitor.metadataForFindings!!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need version check here for serde?
what happens in upgrade or blue green scenarios?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants