Skip to content

Commit

Permalink
Revert commits dcf288d and d92419d (#570)
Browse files Browse the repository at this point in the history
* Revert "add fields param in toxcontent() for doc level query (#549) (#555)"

This reverts commit dcf288d.

Signed-off-by: Surya Sashank Nistala <[email protected]>

* Revert "add 'fields' parameter in doc level query object. (#546) (#551)"

This reverts commit d92419d.

Signed-off-by: Surya Sashank Nistala <[email protected]>

---------

Signed-off-by: Surya Sashank Nistala <[email protected]>
  • Loading branch information
eirsep authored Nov 27, 2023
1 parent 92da659 commit 080ecfe
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import java.util.UUID
data class DocLevelQuery(
val id: String = UUID.randomUUID().toString(),
val name: String,
val fields: List<String>,
val query: String,
val tags: List<String> = mutableListOf()
) : BaseModel {
Expand All @@ -31,7 +30,6 @@ data class DocLevelQuery(
constructor(sin: StreamInput) : this(
sin.readString(), // id
sin.readString(), // name
sin.readStringList(), // fields
sin.readString(), // query
sin.readStringList() // tags
)
Expand All @@ -40,7 +38,6 @@ data class DocLevelQuery(
return mapOf(
QUERY_ID_FIELD to id,
NAME_FIELD to name,
FIELDS_FIELD to fields,
QUERY_FIELD to query,
TAGS_FIELD to tags
)
Expand All @@ -50,7 +47,6 @@ data class DocLevelQuery(
override fun writeTo(out: StreamOutput) {
out.writeString(id)
out.writeString(name)
out.writeStringCollection(fields)
out.writeString(query)
out.writeStringCollection(tags)
}
Expand All @@ -59,7 +55,6 @@ data class DocLevelQuery(
builder.startObject()
.field(QUERY_ID_FIELD, id)
.field(NAME_FIELD, name)
.field(FIELDS_FIELD, fields.toTypedArray())
.field(QUERY_FIELD, query)
.field(TAGS_FIELD, tags.toTypedArray())
.endObject()
Expand All @@ -69,7 +64,6 @@ data class DocLevelQuery(
companion object {
const val QUERY_ID_FIELD = "id"
const val NAME_FIELD = "name"
const val FIELDS_FIELD = "fields"
const val QUERY_FIELD = "query"
const val TAGS_FIELD = "tags"
const val NO_ID = ""
Expand All @@ -82,7 +76,6 @@ data class DocLevelQuery(
lateinit var query: String
lateinit var name: String
val tags: MutableList<String> = mutableListOf()
val fields: MutableList<String> = mutableListOf()

XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.currentToken(), xcp)
while (xcp.nextToken() != XContentParser.Token.END_OBJECT) {
Expand All @@ -108,24 +101,12 @@ data class DocLevelQuery(
tags.add(tag)
}
}
FIELDS_FIELD -> {
XContentParserUtils.ensureExpectedToken(
XContentParser.Token.START_ARRAY,
xcp.currentToken(),
xcp
)
while (xcp.nextToken() != XContentParser.Token.END_ARRAY) {
val field = xcp.text()
fields.add(field)
}
}
}
}

return DocLevelQuery(
id = id,
name = name,
fields = fields,
query = query,
tags = tags
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ fun randomDocLevelQuery(
name: String = "${RandomNumbers.randomIntBetween(Random(), 0, 5)}",
tags: List<String> = mutableListOf(0..RandomNumbers.randomIntBetween(Random(), 0, 10)).map { RandomStrings.randomAsciiLettersOfLength(Random(), 10) }
): DocLevelQuery {
return DocLevelQuery(id = id, query = query, name = name, tags = tags, fields = listOf("*"))
return DocLevelQuery(id = id, query = query, name = name, tags = tags)
}

fun randomDocLevelMonitorInput(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal class GetFindingsResponseTests {
"monitor_id1",
"monitor_name1",
"test_index1",
listOf(DocLevelQuery("1", "myQuery", listOf(), "fieldA:valABC", listOf())),
listOf(DocLevelQuery("1", "myQuery", "fieldA:valABC", listOf())),
Instant.now()
)
val findingDocument1 = FindingDocument("test_index1", "doc1", true, "document 1 payload")
Expand All @@ -43,7 +43,7 @@ internal class GetFindingsResponseTests {
"monitor_id2",
"monitor_name2",
"test_index2",
listOf(DocLevelQuery("1", "myQuery", listOf(), "fieldA:valABC", listOf())),
listOf(DocLevelQuery("1", "myQuery", "fieldA:valABC", listOf())),
Instant.now()
)
val findingDocument21 = FindingDocument("test_index2", "doc21", true, "document 21 payload")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import org.opensearch.commons.alerting.randomAction
import org.opensearch.commons.alerting.randomActionExecutionPolicy
import org.opensearch.commons.alerting.randomBucketLevelTrigger
import org.opensearch.commons.alerting.randomChainedAlertTrigger
import org.opensearch.commons.alerting.randomDocLevelQuery
import org.opensearch.commons.alerting.randomDocumentLevelTrigger
import org.opensearch.commons.alerting.randomQueryLevelMonitor
import org.opensearch.commons.alerting.randomQueryLevelTrigger
Expand Down Expand Up @@ -113,16 +112,6 @@ class WriteableTests {
Assertions.assertEquals(trigger, newTrigger, "Round tripping DocumentLevelTrigger doesn't work")
}

@Test
fun `test doc-level query as stream`() {
val dlq = randomDocLevelQuery()
val out = BytesStreamOutput()
dlq.writeTo(out)
val sin = StreamInput.wrap(out.bytes().toBytesRef().bytes)
val newDlq = DocLevelQuery.readFrom(sin)
Assertions.assertEquals(dlq, newDlq, "Round tripping DocLevelQuery doesn't work")
}

@Test
fun `test chained alert trigger as stream`() {
val trigger = randomChainedAlertTrigger()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,18 +417,6 @@ class XContentTests {
)
}

@Test
fun `test doc level query toXcontent`() {
val dlq = DocLevelQuery("id", "name", listOf("f1", "f2"), "query", listOf("t1", "t2"))
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 080ecfe

Please sign in to comment.