Skip to content

Commit

Permalink
Merge branch 'opensearch-project:main' into 3.0-cross-cluster-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
AWSHurneyt authored Mar 20, 2024
2 parents 7f641df + 3f5421f commit 773d3d4
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# This should match the owning team set up in https://github.com/orgs/opensearch-project/teams @opensearch-project/common-utils
* @lezzago @qreshi @bowenlan-amzn @rishabhmaurya @tlfeng @getsaurabh02 @eirsep @sbcd90 @AWSHurneyt
* @lezzago @qreshi @bowenlan-amzn @rishabhmaurya @getsaurabh02 @eirsep @sbcd90 @AWSHurneyt @engechas @riysaxen-amzn @jowg-amazon

5 changes: 4 additions & 1 deletion MAINTAINERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ This document contains a list of maintainers in this repo. See [opensearch-proje
| Mohammad Qureshi | [qreshi](https://github.com/qreshi) | Amazon |
| Bowen Lan | [bowenlan-amzn](https://github.com/bowenlan-amzn) | Amazon |
| Rishabh Maurya | [rishabhmaurya](https://github.com/rishabhmaurya) | Amazon |
| Tianli Feng | [tlfeng](https://github.com/tlfeng) | Amazon |
| Saurabh Singh | [getsaurabh02](https://github.com/getsaurabh02) | Amazon |
| Surya Sashank Nistala | [eirsep](https://github.com/eirsep) | Amazon |
| Subhobrata Dey | [sbcd90](https://github.com/sbcd90) | Amazon |
| Thomas Hurney | [AWSHurneyt](https://github.com/AWSHurneyt) | 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 @@ -5,6 +5,7 @@ import org.opensearch.action.ActionRequestValidationException
import org.opensearch.commons.alerting.model.Table
import org.opensearch.core.common.io.stream.StreamInput
import org.opensearch.core.common.io.stream.StreamOutput
import org.opensearch.index.query.BoolQueryBuilder
import java.io.IOException

class GetFindingsRequest : ActionRequest {
Expand All @@ -13,19 +14,21 @@ class GetFindingsRequest : ActionRequest {
val monitorId: String?
val monitorIds: List<String>?
val findingIndex: String?

val boolQueryBuilder: BoolQueryBuilder?
constructor(
findingId: String?,
table: Table,
monitorId: String? = null,
findingIndexName: String? = null,
monitorIds: List<String>? = null
monitorIds: List<String>? = null,
boolQueryBuilder: BoolQueryBuilder? = null
) : super() {
this.findingId = findingId
this.table = table
this.monitorId = monitorId
this.findingIndex = findingIndexName
this.monitorIds = monitorIds
this.boolQueryBuilder = boolQueryBuilder
}

@Throws(IOException::class)
Expand All @@ -34,7 +37,8 @@ class GetFindingsRequest : ActionRequest {
table = Table.readFrom(sin),
monitorId = sin.readOptionalString(),
findingIndexName = sin.readOptionalString(),
monitorIds = sin.readOptionalStringList()
monitorIds = sin.readOptionalStringList(),
boolQueryBuilder = BoolQueryBuilder(sin)
)

override fun validate(): ActionRequestValidationException? {
Expand All @@ -48,5 +52,6 @@ class GetFindingsRequest : ActionRequest {
out.writeOptionalString(monitorId)
out.writeOptionalString(findingIndex)
out.writeOptionalStringCollection(monitorIds)
boolQueryBuilder?.writeTo(out)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ data class DocLevelQuery(
val name: String,
val fields: List<String>,
val query: String,
val tags: List<String> = mutableListOf()
val tags: List<String> = mutableListOf(),
val queryFieldNames: List<String> = mutableListOf()
) : BaseModel {

init {
Expand All @@ -33,7 +34,8 @@ data class DocLevelQuery(
sin.readString(), // name
sin.readStringList(), // fields
sin.readString(), // query
sin.readStringList() // tags
sin.readStringList(), // tags,
sin.readStringList() // fieldsBeingQueried
)

fun asTemplateArg(): Map<String, Any> {
Expand All @@ -42,7 +44,8 @@ data class DocLevelQuery(
NAME_FIELD to name,
FIELDS_FIELD to fields,
QUERY_FIELD to query,
TAGS_FIELD to tags
TAGS_FIELD to tags,
QUERY_FIELD_NAMES_FIELD to queryFieldNames
)
}

Expand All @@ -53,6 +56,7 @@ data class DocLevelQuery(
out.writeStringCollection(fields)
out.writeString(query)
out.writeStringCollection(tags)
out.writeStringCollection(queryFieldNames)
}

override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder {
Expand All @@ -62,6 +66,7 @@ data class DocLevelQuery(
.field(FIELDS_FIELD, fields.toTypedArray())
.field(QUERY_FIELD, query)
.field(TAGS_FIELD, tags.toTypedArray())
.field(QUERY_FIELD_NAMES_FIELD, queryFieldNames.toTypedArray())
.endObject()
return builder
}
Expand All @@ -72,6 +77,7 @@ data class DocLevelQuery(
const val FIELDS_FIELD = "fields"
const val QUERY_FIELD = "query"
const val TAGS_FIELD = "tags"
const val QUERY_FIELD_NAMES_FIELD = "query_field_names"
const val NO_ID = ""
val INVALID_CHARACTERS: List<String> = listOf(" ", "[", "]", "{", "}", "(", ")")

Expand All @@ -83,6 +89,7 @@ data class DocLevelQuery(
lateinit var name: String
val tags: MutableList<String> = mutableListOf()
val fields: MutableList<String> = mutableListOf()
val queryFieldNames: MutableList<String> = mutableListOf()

XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.currentToken(), xcp)
while (xcp.nextToken() != XContentParser.Token.END_OBJECT) {
Expand All @@ -95,6 +102,7 @@ data class DocLevelQuery(
name = xcp.text()
validateQuery(name)
}

QUERY_FIELD -> query = xcp.text()
TAGS_FIELD -> {
XContentParserUtils.ensureExpectedToken(
Expand All @@ -108,6 +116,7 @@ data class DocLevelQuery(
tags.add(tag)
}
}

FIELDS_FIELD -> {
XContentParserUtils.ensureExpectedToken(
XContentParser.Token.START_ARRAY,
Expand All @@ -119,6 +128,18 @@ data class DocLevelQuery(
fields.add(field)
}
}

QUERY_FIELD_NAMES_FIELD -> {
XContentParserUtils.ensureExpectedToken(
XContentParser.Token.START_ARRAY,
xcp.currentToken(),
xcp
)
while (xcp.nextToken() != XContentParser.Token.END_ARRAY) {
val field = xcp.text()
queryFieldNames.add(field)
}
}
}
}

Expand All @@ -127,7 +148,8 @@ data class DocLevelQuery(
name = name,
fields = fields,
query = query,
tags = tags
tags = tags,
queryFieldNames = queryFieldNames
)
}

Expand All @@ -148,4 +170,20 @@ data class DocLevelQuery(
}
}
}

// constructor for java plugins' convenience to optionally avoid passing empty list for 'fieldsBeingQueried' field
constructor(
id: String,
name: String,
fields: MutableList<String>,
query: String,
tags: MutableList<String>
) : this(
id = id,
name = name,
fields = fields,
query = query,
tags = tags,
queryFieldNames = emptyList()
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ import org.junit.jupiter.api.Test
import org.opensearch.common.io.stream.BytesStreamOutput
import org.opensearch.commons.alerting.model.Table
import org.opensearch.core.common.io.stream.StreamInput
import org.opensearch.index.query.QueryBuilders

internal class GetFindingsRequestTests {

@Test
fun `test get findings request`() {
val table = Table("asc", "sortString", null, 1, 0, "")

val req = GetFindingsRequest("2121", table, "1", "finding_index_name", listOf("1", "2"))
val boolQueryBuilder = QueryBuilders.boolQuery()
val req = GetFindingsRequest("2121", table, "1", "finding_index_name", listOf("1", "2"), boolQueryBuilder)
assertNotNull(req)

val out = BytesStreamOutput()
Expand All @@ -34,8 +35,8 @@ internal class GetFindingsRequestTests {
@Test
fun `test validate returns null`() {
val table = Table("asc", "sortString", null, 1, 0, "")

val req = GetFindingsRequest("2121", table, "1", "active")
val boolQueryBuilder = QueryBuilders.boolQuery()
val req = GetFindingsRequest("2121", table, "1", "active", listOf("1", "2"), boolQueryBuilder)
assertNotNull(req)
assertNull(req.validate())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import org.opensearch.commons.alerting.randomWorkflow
import org.opensearch.commons.authuser.User
import org.opensearch.core.common.io.stream.StreamInput
import org.opensearch.search.builder.SearchSourceBuilder
import kotlin.test.assertTrue

class WriteableTests {

Expand Down Expand Up @@ -132,6 +133,19 @@ class WriteableTests {
val sin = StreamInput.wrap(out.bytes().toBytesRef().bytes)
val newDlq = DocLevelQuery.readFrom(sin)
Assertions.assertEquals(dlq, newDlq, "Round tripping DocLevelQuery doesn't work")
assertTrue(newDlq.queryFieldNames.isEmpty())
}

@Test
fun `test doc-level query with query Field Names as stream`() {
val dlq = randomDocLevelQuery().copy(queryFieldNames = listOf("f1", "f2"))
val out = BytesStreamOutput()
dlq.writeTo(out)
val sin = StreamInput.wrap(out.bytes().toBytesRef().bytes)
val newDlq = DocLevelQuery.readFrom(sin)
assertTrue(newDlq.queryFieldNames.contains(dlq.queryFieldNames[0]))
assertTrue(newDlq.queryFieldNames.contains(dlq.queryFieldNames[1]))
Assertions.assertEquals(dlq, newDlq, "Round tripping DocLevelQuery doesn't work")
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,18 @@ class XContentTests {
)
}

@Test
fun `test doc level query toXcontent with query field names`() {
val dlq = DocLevelQuery("id", "name", listOf("f1", "f2"), "query", listOf("t1", "t2"), listOf("f1", "f2"))
val dlqString = dlq.toXContent(builder(), ToXContent.EMPTY_PARAMS).string()
val parsedDlq = DocLevelQuery.parse(parser(dlqString))
Assertions.assertEquals(
dlq,
parsedDlq,
"Round tripping Doc level query doesn't work"
)
}

@Test
fun `test alert parsing`() {
val alert = randomAlert()
Expand Down

0 comments on commit 773d3d4

Please sign in to comment.