diff --git a/src/main/kotlin/org/opensearch/commons/alerting/model/DocLevelQuery.kt b/src/main/kotlin/org/opensearch/commons/alerting/model/DocLevelQuery.kt index 7c72b0ca..a962f546 100644 --- a/src/main/kotlin/org/opensearch/commons/alerting/model/DocLevelQuery.kt +++ b/src/main/kotlin/org/opensearch/commons/alerting/model/DocLevelQuery.kt @@ -1,12 +1,12 @@ package org.opensearch.commons.alerting.model +import org.opensearch.common.io.stream.StreamInput +import org.opensearch.common.io.stream.StreamOutput +import org.opensearch.common.xcontent.XContentParserUtils import org.opensearch.commons.notifications.model.BaseModel -import org.opensearch.core.common.io.stream.StreamInput -import org.opensearch.core.common.io.stream.StreamOutput import org.opensearch.core.xcontent.ToXContent import org.opensearch.core.xcontent.XContentBuilder import org.opensearch.core.xcontent.XContentParser -import org.opensearch.core.xcontent.XContentParserUtils import java.io.IOException import java.lang.IllegalArgumentException import java.util.UUID diff --git a/src/test/kotlin/org/opensearch/commons/alerting/TestHelpers.kt b/src/test/kotlin/org/opensearch/commons/alerting/TestHelpers.kt index 94c7d23a..86cca074 100644 --- a/src/test/kotlin/org/opensearch/commons/alerting/TestHelpers.kt +++ b/src/test/kotlin/org/opensearch/commons/alerting/TestHelpers.kt @@ -284,7 +284,7 @@ fun randomDocLevelQuery( name: String = "${RandomNumbers.randomIntBetween(Random(), 0, 5)}", tags: List = mutableListOf(0..RandomNumbers.randomIntBetween(Random(), 0, 10)).map { RandomStrings.randomAsciiLettersOfLength(Random(), 10) } ): DocLevelQuery { - return DocLevelQuery(id = id, query = query, name = name, tags = tags) + return DocLevelQuery(id = id, query = query, name = name, tags = tags, fields = listOf("*")) } fun randomDocLevelMonitorInput( diff --git a/src/test/kotlin/org/opensearch/commons/alerting/action/GetFindingsResponseTests.kt b/src/test/kotlin/org/opensearch/commons/alerting/action/GetFindingsResponseTests.kt index 7349078b..51802789 100644 --- a/src/test/kotlin/org/opensearch/commons/alerting/action/GetFindingsResponseTests.kt +++ b/src/test/kotlin/org/opensearch/commons/alerting/action/GetFindingsResponseTests.kt @@ -25,7 +25,7 @@ internal class GetFindingsResponseTests { "monitor_id1", "monitor_name1", "test_index1", - listOf(DocLevelQuery("1", "myQuery", "fieldA:valABC", List.of())), + listOf(DocLevelQuery("1", "myQuery", listOf(), "fieldA:valABC", List.of(), List.of("*"))), Instant.now() ) val findingDocument1 = FindingDocument("test_index1", "doc1", true, "document 1 payload") @@ -44,7 +44,7 @@ internal class GetFindingsResponseTests { "monitor_id2", "monitor_name2", "test_index2", - listOf(DocLevelQuery("1", "myQuery", "fieldA:valABC", List.of())), + listOf(DocLevelQuery("1", "myQuery", listOf(), "fieldA:valABC", List.of())), Instant.now() ) val findingDocument21 = FindingDocument("test_index2", "doc21", true, "document 21 payload") diff --git a/src/test/kotlin/org/opensearch/commons/alerting/model/WriteableTests.kt b/src/test/kotlin/org/opensearch/commons/alerting/model/WriteableTests.kt index e81e59bd..710f0eda 100644 --- a/src/test/kotlin/org/opensearch/commons/alerting/model/WriteableTests.kt +++ b/src/test/kotlin/org/opensearch/commons/alerting/model/WriteableTests.kt @@ -3,13 +3,13 @@ package org.opensearch.commons.alerting.model import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Test import org.opensearch.common.io.stream.BytesStreamOutput +import org.opensearch.common.io.stream.StreamInput import org.opensearch.commons.alerting.model.action.Action import org.opensearch.commons.alerting.model.action.ActionExecutionPolicy import org.opensearch.commons.alerting.model.action.Throttle 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 @@ -18,7 +18,6 @@ import org.opensearch.commons.alerting.randomThrottle import org.opensearch.commons.alerting.randomUser import org.opensearch.commons.alerting.randomUserEmpty import org.opensearch.commons.authuser.User -import org.opensearch.core.common.io.stream.StreamInput import org.opensearch.search.builder.SearchSourceBuilder import kotlin.test.assertTrue @@ -137,16 +136,6 @@ class WriteableTests { Assertions.assertEquals(dlq, newDlq, "Round tripping DocLevelQuery doesn't work") } - @Test - fun `test chained alert trigger as stream`() { - val trigger = randomChainedAlertTrigger() - val out = BytesStreamOutput() - trigger.writeTo(out) - val sin = StreamInput.wrap(out.bytes().toBytesRef().bytes) - val newTrigger = ChainedAlertTrigger.readFrom(sin) - Assertions.assertEquals(trigger, newTrigger, "Round tripping DocumentLevelTrigger doesn't work") - } - @Test fun `test searchinput as stream`() { val input = SearchInput(emptyList(), SearchSourceBuilder()) diff --git a/src/test/kotlin/org/opensearch/commons/alerting/model/XContentTests.kt b/src/test/kotlin/org/opensearch/commons/alerting/model/XContentTests.kt index 065191fb..2f3e3ea4 100644 --- a/src/test/kotlin/org/opensearch/commons/alerting/model/XContentTests.kt +++ b/src/test/kotlin/org/opensearch/commons/alerting/model/XContentTests.kt @@ -22,7 +22,6 @@ import org.opensearch.commons.alerting.randomQueryLevelTrigger import org.opensearch.commons.alerting.randomThrottle import org.opensearch.commons.alerting.randomUser import org.opensearch.commons.alerting.randomUserEmpty -import org.opensearch.commons.alerting.randomWorkflow import org.opensearch.commons.alerting.toJsonString import org.opensearch.commons.alerting.toJsonStringWithUser import org.opensearch.commons.alerting.util.string @@ -179,22 +178,6 @@ class XContentTests { Assertions.assertEquals(monitor, parsedMonitor, "Round tripping BucketLevelMonitor doesn't work") } - @Test - fun `test composite workflow parsing`() { - val workflow = randomWorkflow() - val monitorString = workflow.toJsonStringWithUser() - val parsedMonitor = Workflow.parse(parser(monitorString)) - Assertions.assertEquals(workflow, parsedMonitor, "Round tripping BucketLevelMonitor doesn't work") - } - - @Test - fun `test composite workflow parsing with auditDelegateMonitorAlerts flag disabled`() { - val workflow = randomWorkflow(auditDelegateMonitorAlerts = false) - val monitorString = workflow.toJsonStringWithUser() - val parsedMonitor = Workflow.parse(parser(monitorString)) - Assertions.assertEquals(workflow, parsedMonitor, "Round tripping BucketLevelMonitor doesn't work") - } - @Test fun `test query-level trigger parsing`() { val trigger = randomQueryLevelTrigger() @@ -264,32 +247,6 @@ class XContentTests { Assertions.assertNull(parsedMonitor.user) } - @Test - fun `test workflow parsing`() { - val workflow = randomWorkflow(monitorIds = listOf("1", "2", "3")) - val monitorString = workflow.toJsonString() - val parsedWorkflow = Workflow.parse(parser(monitorString)) - Assertions.assertEquals(workflow, parsedWorkflow, "Round tripping workflow failed") - } - - @Test - fun `test chainedMonitorFindings parsing`() { - val cmf1 = ChainedMonitorFindings(monitorId = "m1") - val cmf1String = cmf1.toJsonString() - Assertions.assertEquals( - ChainedMonitorFindings.parse(parser(cmf1String)), - cmf1, - "Round tripping chained monitor findings failed" - ) - val cmf2 = ChainedMonitorFindings(monitorIds = listOf("m1", "m2")) - val cmf2String = cmf2.toJsonString() - Assertions.assertEquals( - ChainedMonitorFindings.parse(parser(cmf2String)), - cmf2, - "Round tripping chained monitor findings failed" - ) - } - @Test fun `test old monitor format parsing`() { val monitorString = """ @@ -453,23 +410,6 @@ class XContentTests { assertEquals("Round tripping alert doesn't work", alert, parsedAlert) } - @Test - fun `test alert parsing with noop trigger`() { - val monitor = randomQueryLevelMonitor() - val alert = Alert( - id = "", - monitor = monitor, - trigger = NoOpTrigger(), - startTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), - errorMessage = "some error", - lastNotificationTime = Instant.now(), - workflowId = "", - executionId = "", - clusters = listOf() - ) - assertEquals("Round tripping alert doesn't work", alert.triggerName, "NoOp trigger") - } - @Test fun `test alert parsing without user`() { val alertStr = "{\"id\":\"\",\"version\":-1,\"monitor_id\":\"\",\"schema_version\":0,\"monitor_version\":1," +