From e5ceb384df71856cdd094244fc39d0e1fb26d46b Mon Sep 17 00:00:00 2001 From: Surya Sashank Nistala Date: Mon, 10 Oct 2022 13:35:39 -0700 Subject: [PATCH 1/2] accept of list of monitor ids in findings and alerts request dtos Signed-off-by: Surya Sashank Nistala --- .../commons/alerting/action/GetAlertsRequest.kt | 10 ++++++++-- .../commons/alerting/action/GetFindingsRequest.kt | 10 ++++++++-- .../commons/alerting/action/GetAlertsRequestTests.kt | 5 ++++- .../commons/alerting/action/GetFindingsRequestTests.kt | 5 ++++- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/org/opensearch/commons/alerting/action/GetAlertsRequest.kt b/src/main/kotlin/org/opensearch/commons/alerting/action/GetAlertsRequest.kt index bdda4e93..5bbccbcc 100644 --- a/src/main/kotlin/org/opensearch/commons/alerting/action/GetAlertsRequest.kt +++ b/src/main/kotlin/org/opensearch/commons/alerting/action/GetAlertsRequest.kt @@ -6,6 +6,7 @@ import org.opensearch.common.io.stream.StreamInput import org.opensearch.common.io.stream.StreamOutput import org.opensearch.commons.alerting.model.Table import java.io.IOException +import java.util.Collections class GetAlertsRequest : ActionRequest { val table: Table @@ -13,19 +14,22 @@ class GetAlertsRequest : ActionRequest { val alertState: String val monitorId: String? val alertIndex: String? + val monitorIds: List? constructor( table: Table, severityLevel: String, alertState: String, monitorId: String?, - alertIndex: String? + alertIndex: String?, + monitorIds: List = Collections.emptyList() ) : super() { this.table = table this.severityLevel = severityLevel this.alertState = alertState this.monitorId = monitorId this.alertIndex = alertIndex + this.monitorIds = monitorIds } @Throws(IOException::class) @@ -34,7 +38,8 @@ class GetAlertsRequest : ActionRequest { severityLevel = sin.readString(), alertState = sin.readString(), monitorId = sin.readOptionalString(), - alertIndex = sin.readOptionalString() + alertIndex = sin.readOptionalString(), + monitorIds = sin.readOptionalStringList() ) override fun validate(): ActionRequestValidationException? { @@ -48,5 +53,6 @@ class GetAlertsRequest : ActionRequest { out.writeString(alertState) out.writeOptionalString(monitorId) out.writeOptionalString(alertIndex) + out.writeOptionalStringCollection(monitorIds) } } diff --git a/src/main/kotlin/org/opensearch/commons/alerting/action/GetFindingsRequest.kt b/src/main/kotlin/org/opensearch/commons/alerting/action/GetFindingsRequest.kt index 4f852a64..519fc674 100644 --- a/src/main/kotlin/org/opensearch/commons/alerting/action/GetFindingsRequest.kt +++ b/src/main/kotlin/org/opensearch/commons/alerting/action/GetFindingsRequest.kt @@ -6,23 +6,27 @@ import org.opensearch.common.io.stream.StreamInput import org.opensearch.common.io.stream.StreamOutput import org.opensearch.commons.alerting.model.Table import java.io.IOException +import java.util.Collections class GetFindingsRequest : ActionRequest { val findingId: String? val table: Table val monitorId: String? + val monitorIds: List? val findingIndex: String? constructor( findingId: String?, table: Table, monitorId: String? = null, - findingIndexName: String? = null + findingIndexName: String? = null, + monitorIds: List = Collections.emptyList() ) : super() { this.findingId = findingId this.table = table this.monitorId = monitorId this.findingIndex = findingIndexName + this.monitorIds = monitorIds } @Throws(IOException::class) @@ -30,7 +34,8 @@ class GetFindingsRequest : ActionRequest { findingId = sin.readOptionalString(), table = Table.readFrom(sin), monitorId = sin.readOptionalString(), - findingIndexName = sin.readOptionalString() + findingIndexName = sin.readOptionalString(), + monitorIds = sin.readOptionalStringList() ) override fun validate(): ActionRequestValidationException? { @@ -43,5 +48,6 @@ class GetFindingsRequest : ActionRequest { table.writeTo(out) out.writeOptionalString(monitorId) out.writeOptionalString(findingIndex) + out.writeOptionalStringCollection(monitorIds) } } diff --git a/src/test/kotlin/org/opensearch/commons/alerting/action/GetAlertsRequestTests.kt b/src/test/kotlin/org/opensearch/commons/alerting/action/GetAlertsRequestTests.kt index 3b2024a5..43c2f61c 100644 --- a/src/test/kotlin/org/opensearch/commons/alerting/action/GetAlertsRequestTests.kt +++ b/src/test/kotlin/org/opensearch/commons/alerting/action/GetAlertsRequestTests.kt @@ -3,6 +3,7 @@ package org.opensearch.commons.alerting.action import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertNotNull import org.junit.jupiter.api.Assertions.assertNull +import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Test import org.opensearch.common.io.stream.BytesStreamOutput import org.opensearch.common.io.stream.StreamInput @@ -15,7 +16,7 @@ internal class GetAlertsRequestTests { val table = Table("asc", "sortString", null, 1, 0, "") - val req = GetAlertsRequest(table, "1", "active", null, null) + val req = GetAlertsRequest(table, "1", "active", null, null, listOf("1", "2")) assertNotNull(req) val out = BytesStreamOutput() @@ -27,6 +28,8 @@ internal class GetAlertsRequestTests { assertEquals("active", newReq.alertState) assertNull(newReq.monitorId) assertEquals(table, newReq.table) + assertTrue(newReq.monitorIds!!.contains("1")) + assertTrue(newReq.monitorIds!!.contains("2")) } @Test diff --git a/src/test/kotlin/org/opensearch/commons/alerting/action/GetFindingsRequestTests.kt b/src/test/kotlin/org/opensearch/commons/alerting/action/GetFindingsRequestTests.kt index 54fab737..f83cb8de 100644 --- a/src/test/kotlin/org/opensearch/commons/alerting/action/GetFindingsRequestTests.kt +++ b/src/test/kotlin/org/opensearch/commons/alerting/action/GetFindingsRequestTests.kt @@ -3,6 +3,7 @@ package org.opensearch.commons.alerting.action import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertNotNull import org.junit.jupiter.api.Assertions.assertNull +import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Test import org.opensearch.common.io.stream.BytesStreamOutput import org.opensearch.common.io.stream.StreamInput @@ -15,7 +16,7 @@ internal class GetFindingsRequestTests { val table = Table("asc", "sortString", null, 1, 0, "") - val req = GetFindingsRequest("2121", table, "1", "finding_index_name") + val req = GetFindingsRequest("2121", table, "1", "finding_index_name", listOf("1", "2")) assertNotNull(req) val out = BytesStreamOutput() @@ -27,6 +28,8 @@ internal class GetFindingsRequestTests { assertEquals("2121", newReq.findingId) assertEquals("finding_index_name", newReq.findingIndex) assertEquals(table, newReq.table) + assertTrue(newReq.monitorIds!!.contains("1")) + assertTrue(newReq.monitorIds!!.contains("2")) } @Test From 92601a0f9185963697efd61e7589b96f9e7abd9e Mon Sep 17 00:00:00 2001 From: Surya Sashank Nistala Date: Mon, 10 Oct 2022 14:19:19 -0700 Subject: [PATCH 2/2] make monitorIds nullable in constructor Signed-off-by: Surya Sashank Nistala --- .../org/opensearch/commons/alerting/action/GetAlertsRequest.kt | 3 +-- .../opensearch/commons/alerting/action/GetFindingsRequest.kt | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/org/opensearch/commons/alerting/action/GetAlertsRequest.kt b/src/main/kotlin/org/opensearch/commons/alerting/action/GetAlertsRequest.kt index 5bbccbcc..5804ff08 100644 --- a/src/main/kotlin/org/opensearch/commons/alerting/action/GetAlertsRequest.kt +++ b/src/main/kotlin/org/opensearch/commons/alerting/action/GetAlertsRequest.kt @@ -6,7 +6,6 @@ import org.opensearch.common.io.stream.StreamInput import org.opensearch.common.io.stream.StreamOutput import org.opensearch.commons.alerting.model.Table import java.io.IOException -import java.util.Collections class GetAlertsRequest : ActionRequest { val table: Table @@ -22,7 +21,7 @@ class GetAlertsRequest : ActionRequest { alertState: String, monitorId: String?, alertIndex: String?, - monitorIds: List = Collections.emptyList() + monitorIds: List? = null ) : super() { this.table = table this.severityLevel = severityLevel diff --git a/src/main/kotlin/org/opensearch/commons/alerting/action/GetFindingsRequest.kt b/src/main/kotlin/org/opensearch/commons/alerting/action/GetFindingsRequest.kt index 519fc674..ae65ca26 100644 --- a/src/main/kotlin/org/opensearch/commons/alerting/action/GetFindingsRequest.kt +++ b/src/main/kotlin/org/opensearch/commons/alerting/action/GetFindingsRequest.kt @@ -6,7 +6,6 @@ import org.opensearch.common.io.stream.StreamInput import org.opensearch.common.io.stream.StreamOutput import org.opensearch.commons.alerting.model.Table import java.io.IOException -import java.util.Collections class GetFindingsRequest : ActionRequest { val findingId: String? @@ -20,7 +19,7 @@ class GetFindingsRequest : ActionRequest { table: Table, monitorId: String? = null, findingIndexName: String? = null, - monitorIds: List = Collections.emptyList() + monitorIds: List? = null ) : super() { this.findingId = findingId this.table = table