Skip to content

Commit

Permalink
Merge branch 'opensearch-project:main' into 3.0-issue1401
Browse files Browse the repository at this point in the history
  • Loading branch information
AWSHurneyt authored Mar 13, 2024
2 parents b3c4f4b + ba84d04 commit b4e746a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 90 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @lezzago @AWSHurneyt @sbcd90 @eirsep @getsaurabh02 @praveensameneni @qreshi @bowenlan-amzn @rishabhmaurya @engechas @riysaxen-amzn
* @lezzago @AWSHurneyt @sbcd90 @eirsep @getsaurabh02 @praveensameneni @qreshi @bowenlan-amzn @rishabhmaurya @engechas @riysaxen-amzn @jowg-amazon
27 changes: 14 additions & 13 deletions MAINTAINERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@ This document contains a list of maintainers in this repo. See [opensearch-proje

## Current Maintainers

| Maintainer | GitHub ID | Affiliation |
|----------------------| ------------------------------------------------- |-------------|
| Ashish Agrawal | [lezzago](https://github.com/lezzago) | Amazon |
| Mohammad Qureshi | [qreshi](https://github.com/qreshi) | Amazon |
| Bowen Lan | [bowenlan-amzn](https://github.com/bowenlan-amzn) | Amazon |
| Saurabh Singh | [getsaurabh02](https://github.com/getsaurabh02) | Amazon |
| Rishabh Maurya | [rishabhmaurya](https://github.com/rishabhmaurya) | Amazon |
| Subhobrata DEY | [sbcd90](https://github.com/sbcd90) | Amazon |
| Surya Sashank Nistala | [eirsep](https://github.com/eirsep) | Amazon |
| Thomas Hurney | [AWSHurneyt](https://github.com/AWSHurneyt) | Amazon |
| Praveen Sameneni | [praveensameneni](https://github.com/praveensameneni) | Amazon |
| Chase Engelbrecht | [engechas](https://github.com/engechas) | Amazon |
| Riya Saxena | [riysaxen-amzn](https://github.com/riysaxen-amzn) | Amazon |
| Maintainer | GitHub ID | Affiliation |
|-----------------------|-------------------------------------------------------|-------------|
| Ashish Agrawal | [lezzago](https://github.com/lezzago) | Amazon |
| Mohammad Qureshi | [qreshi](https://github.com/qreshi) | Amazon |
| Bowen Lan | [bowenlan-amzn](https://github.com/bowenlan-amzn) | Amazon |
| Saurabh Singh | [getsaurabh02](https://github.com/getsaurabh02) | Amazon |
| Rishabh Maurya | [rishabhmaurya](https://github.com/rishabhmaurya) | Amazon |
| Subhobrata DEY | [sbcd90](https://github.com/sbcd90) | Amazon |
| Surya Sashank Nistala | [eirsep](https://github.com/eirsep) | Amazon |
| Thomas Hurney | [AWSHurneyt](https://github.com/AWSHurneyt) | Amazon |
| Praveen Sameneni | [praveensameneni](https://github.com/praveensameneni) | Amazon |
| Chase Engelbrecht | [engechas](https://github.com/engechas) | Amazon |
| Riya Saxena | [riysaxen-amzn](https://github.com/riysaxen-amzn) | Amazon |
| Joanne Wang | [jowg-amazon](https://github.com/jowg-amazon) | Amazon |

## Emeritus

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ class RestGetFindingsAction : BaseRestHandler() {
val size = request.paramAsInt("size", 20)
val startIndex = request.paramAsInt("startIndex", 0)
val searchString = request.param("searchString", "")
val severity: String? = request.param("severity", "ALL")
val detectionType: String? = request.param("detectionType", "rules")

val table = Table(
sortOrder,
Expand All @@ -59,9 +57,7 @@ class RestGetFindingsAction : BaseRestHandler() {

val getFindingsSearchRequest = GetFindingsRequest(
findingID,
table,
severity,
detectionType
table
)
return RestChannelConsumer {
channel ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import org.opensearch.commons.alerting.model.FindingWithDocs
import org.opensearch.commons.utils.recreateObject
import org.opensearch.core.action.ActionListener
import org.opensearch.core.common.Strings
import org.opensearch.core.common.io.stream.NamedWriteableRegistry
import org.opensearch.core.xcontent.NamedXContentRegistry
import org.opensearch.core.xcontent.XContentParser
import org.opensearch.core.xcontent.XContentParserUtils
Expand All @@ -62,7 +63,8 @@ class TransportGetFindingsSearchAction @Inject constructor(
clusterService: ClusterService,
actionFilters: ActionFilters,
val settings: Settings,
val xContentRegistry: NamedXContentRegistry
val xContentRegistry: NamedXContentRegistry,
val namedWriteableRegistry: NamedWriteableRegistry
) : HandledTransportAction<ActionRequest, GetFindingsResponse> (
AlertingActions.GET_FINDINGS_ACTION_NAME, transportService, actionFilters, ::GetFindingsRequest
),
Expand All @@ -80,11 +82,8 @@ class TransportGetFindingsSearchAction @Inject constructor(
actionListener: ActionListener<GetFindingsResponse>
) {
val getFindingsRequest = request as? GetFindingsRequest
?: recreateObject(request) { GetFindingsRequest(it) }
?: recreateObject(request, namedWriteableRegistry) { GetFindingsRequest(it) }
val tableProp = getFindingsRequest.table
val severity = getFindingsRequest.severity
val detectionType = getFindingsRequest.detectionType
val searchString = tableProp.searchString

val sortBuilder = SortBuilders
.fieldSort(tableProp.sortString)
Expand All @@ -101,79 +100,16 @@ class TransportGetFindingsSearchAction @Inject constructor(
.seqNoAndPrimaryTerm(true)
.version(true)

val queryBuilder = QueryBuilders.boolQuery()
val queryBuilder = getFindingsRequest.boolQueryBuilder ?: QueryBuilders.boolQuery()

if (!getFindingsRequest.findingId.isNullOrBlank())
queryBuilder.filter(QueryBuilders.termQuery("_id", getFindingsRequest.findingId))

if (!getFindingsRequest.findingIds.isNullOrEmpty()) {
queryBuilder.filter(QueryBuilders.termsQuery("id", getFindingsRequest.findingIds))
}

if (getFindingsRequest.monitorId != null) {
queryBuilder.filter(QueryBuilders.termQuery("monitor_id", getFindingsRequest.monitorId))
} else if (getFindingsRequest.monitorIds.isNullOrEmpty() == false) {
queryBuilder.filter(QueryBuilders.termsQuery("monitor_id", getFindingsRequest.monitorIds))
}

if (getFindingsRequest.startTime != null && getFindingsRequest.endTime != null) {
val startTime = getFindingsRequest.startTime!!.toEpochMilli()
val endTime = getFindingsRequest.endTime!!.toEpochMilli()
val timeRangeQuery = QueryBuilders.rangeQuery("timestamp")
.from(startTime) // Greater than or equal to start time
.to(endTime) // Less than or equal to end time
queryBuilder.filter(timeRangeQuery)
}

if (!detectionType.isNullOrBlank()) {
val nestedQueryBuilder = QueryBuilders.nestedQuery(
"queries",
when {
detectionType.equals("threat", ignoreCase = true) -> {
QueryBuilders.boolQuery().filter(
QueryBuilders.prefixQuery("queries.id", "threat_intel_")
)
}
else -> {
QueryBuilders.boolQuery().mustNot(
QueryBuilders.prefixQuery("queries.id", "threat_intel_")
)
}
},
ScoreMode.None
)

// Add the nestedQueryBuilder to the main queryBuilder
queryBuilder.must(nestedQueryBuilder)
}

if (!searchString.isNullOrBlank()) {
queryBuilder
.should(QueryBuilders.matchQuery("index", searchString))
.should(
QueryBuilders.nestedQuery(
"queries",
QueryBuilders.matchQuery("queries.tags", searchString),
ScoreMode.None
)
)
.should(QueryBuilders.regexpQuery("monitor_name", searchString + ".*"))
.minimumShouldMatch(1)
}

if (!severity.isNullOrBlank()) {
queryBuilder
.must(
QueryBuilders.nestedQuery(
"queries",
QueryBuilders.boolQuery().should(
QueryBuilders.matchQuery("queries.tags", severity)
),
ScoreMode.None
)
)
}

if (!tableProp.searchString.isNullOrBlank()) {
queryBuilder
.should(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2119,8 +2119,10 @@ class DocumentMonitorRunnerIT : AlertingRestTestCase() {

val findings = searchFindings(monitor)
assertEquals("Findings saved for test monitor", 2, findings.size)
assertTrue("Findings saved for test monitor", findings[0].relatedDocIds.contains("1"))
assertTrue("Findings saved for test monitor", findings[1].relatedDocIds.contains("5"))
val findings0 = findings[0].relatedDocIds.contains("1") || findings[0].relatedDocIds.contains("5")
val findings1 = findings[1].relatedDocIds.contains("5") || findings[1].relatedDocIds.contains("1")
assertTrue("Findings saved for test monitor", findings0)
assertTrue("Findings saved for test monitor", findings1)
}

fun `test document-level monitor when index alias contain docs that do match a NOT EQUALS query and EXISTS query`() {
Expand Down

0 comments on commit b4e746a

Please sign in to comment.