Skip to content

Commit e46f3b6

Browse files
Merge branch 'opensearch-project:main' into ccr-libs
2 parents a3900cd + 20f9ef6 commit e46f3b6

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

src/main/kotlin/org/opensearch/commons/alerting/model/Monitor.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.opensearch.commons.alerting.model
22

33
import org.opensearch.common.CheckedFunction
4+
import org.opensearch.commons.alerting.model.remote.monitors.RemoteMonitorTrigger
45
import org.opensearch.commons.alerting.util.IndexUtils.Companion.MONITOR_MAX_INPUTS
56
import org.opensearch.commons.alerting.util.IndexUtils.Companion.MONITOR_MAX_TRIGGERS
67
import org.opensearch.commons.alerting.util.IndexUtils.Companion.NO_SCHEMA_VERSION
@@ -188,8 +189,10 @@ data class Monitor(
188189
inputs.forEach {
189190
if (it is SearchInput) {
190191
out.writeEnum(Input.Type.SEARCH_INPUT)
191-
} else {
192+
} else if (it is DocLevelMonitorInput) {
192193
out.writeEnum(Input.Type.DOCUMENT_LEVEL_INPUT)
194+
} else {
195+
out.writeEnum(Input.Type.REMOTE_DOC_LEVEL_MONITOR_INPUT)
193196
}
194197
it.writeTo(out)
195198
}
@@ -199,6 +202,7 @@ data class Monitor(
199202
when (it) {
200203
is BucketLevelTrigger -> out.writeEnum(Trigger.Type.BUCKET_LEVEL_TRIGGER)
201204
is DocumentLevelTrigger -> out.writeEnum(Trigger.Type.DOCUMENT_LEVEL_TRIGGER)
205+
is RemoteMonitorTrigger -> out.writeEnum(Trigger.Type.REMOTE_MONITOR_TRIGGER)
202206
else -> out.writeEnum(Trigger.Type.QUERY_LEVEL_TRIGGER)
203207
}
204208
it.writeTo(out)

src/test/kotlin/org/opensearch/commons/alerting/model/WriteableTests.kt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import org.opensearch.commons.alerting.randomThrottle
2929
import org.opensearch.commons.alerting.randomUser
3030
import org.opensearch.commons.alerting.randomUserEmpty
3131
import org.opensearch.commons.alerting.randomWorkflow
32+
import org.opensearch.commons.alerting.util.IndexUtils
3233
import org.opensearch.commons.authuser.User
3334
import org.opensearch.core.common.io.stream.StreamInput
3435
import org.opensearch.core.common.io.stream.StreamOutput
@@ -37,6 +38,7 @@ import org.opensearch.search.builder.SearchSourceBuilder
3738
import org.opensearch.test.OpenSearchTestCase
3839
import java.io.IOException
3940
import java.time.Instant
41+
import java.time.temporal.ChronoUnit
4042
import kotlin.test.assertTrue
4143

4244
class WriteableTests {
@@ -370,6 +372,47 @@ class WriteableTests {
370372
Assert.assertEquals("Round tripping DocLevelMonitorInput failed", newDocLevelMonitorInput, docLevelMonitorInput)
371373
}
372374

375+
@Test
376+
fun `test RemoteMonitor as stream`() {
377+
val myMonitorInput = MyMonitorInput(1, "hello", MyMonitorInput(2, "world", null))
378+
var myObjOut = BytesStreamOutput()
379+
myMonitorInput.writeTo(myObjOut)
380+
val docLevelMonitorInput = DocLevelMonitorInput(
381+
"test",
382+
listOf("test"),
383+
listOf(randomDocLevelQuery())
384+
)
385+
val remoteDocLevelMonitorInput = RemoteDocLevelMonitorInput(myObjOut.bytes(), docLevelMonitorInput)
386+
387+
val myMonitorTrigger = MyMonitorTrigger(1, "hello", MyMonitorTrigger(2, "world", null))
388+
myObjOut = BytesStreamOutput()
389+
myMonitorTrigger.writeTo(myObjOut)
390+
val remoteMonitorTrigger = RemoteMonitorTrigger("id", "name", "1", listOf(), myObjOut.bytes())
391+
392+
val monitor = Monitor(
393+
Monitor.NO_ID,
394+
Monitor.NO_VERSION,
395+
"hello",
396+
true,
397+
IntervalSchedule(1, ChronoUnit.MINUTES),
398+
Instant.now(),
399+
Instant.now(),
400+
"remote_doc_level_monitor",
401+
null,
402+
IndexUtils.NO_SCHEMA_VERSION,
403+
listOf(remoteDocLevelMonitorInput),
404+
listOf(remoteMonitorTrigger),
405+
mapOf()
406+
)
407+
408+
val out = BytesStreamOutput()
409+
monitor.writeTo(out)
410+
411+
val sin = StreamInput.wrap(out.bytes().toBytesRef().bytes)
412+
val newMonitor = Monitor(sin)
413+
Assert.assertEquals("Round tripping RemoteMonitor failed", monitor, newMonitor)
414+
}
415+
373416
@Test
374417
fun `test Comment object`() {
375418
val user = randomUser()

0 commit comments

Comments
 (0)