Skip to content

Commit

Permalink
Fix merge conflicts
Browse files Browse the repository at this point in the history
Signed-off-by: Megha Goyal <[email protected]>
  • Loading branch information
goyamegh committed Mar 14, 2024
1 parent 7a61f08 commit a7534db
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 78 deletions.
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,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)
return DocLevelQuery(id = id, query = query, name = name, tags = tags, fields = listOf("*"))
}

fun randomDocLevelMonitorInput(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 = """
Expand Down Expand Up @@ -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," +
Expand Down

0 comments on commit a7534db

Please sign in to comment.