From 10d0bcc2bfb5f091f56e46a1055ea3862c953eb7 Mon Sep 17 00:00:00 2001 From: Riya Saxena Date: Tue, 30 Jan 2024 16:07:43 -0800 Subject: [PATCH 1/4] added support for param in Finding API Signed-off-by: Riya Saxena --- .../commons/alerting/action/GetFindingsRequest.kt | 9 +++++++-- .../commons/alerting/action/GetFindingsRequestTests.kt | 5 +++-- 2 files changed, 10 insertions(+), 4 deletions(-) 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 0004d4f1..6f1a90b0 100644 --- a/src/main/kotlin/org/opensearch/commons/alerting/action/GetFindingsRequest.kt +++ b/src/main/kotlin/org/opensearch/commons/alerting/action/GetFindingsRequest.kt @@ -13,19 +13,22 @@ class GetFindingsRequest : ActionRequest { val monitorId: String? val monitorIds: List? val findingIndex: String? + val severity: String? constructor( findingId: String?, table: Table, monitorId: String? = null, findingIndexName: String? = null, - monitorIds: List? = null + monitorIds: List? = null, + severity: String? = null ) : super() { this.findingId = findingId this.table = table this.monitorId = monitorId this.findingIndex = findingIndexName this.monitorIds = monitorIds + this.severity = severity } @Throws(IOException::class) @@ -34,7 +37,8 @@ class GetFindingsRequest : ActionRequest { table = Table.readFrom(sin), monitorId = sin.readOptionalString(), findingIndexName = sin.readOptionalString(), - monitorIds = sin.readOptionalStringList() + monitorIds = sin.readOptionalStringList(), + severity = sin.readOptionalString() ) override fun validate(): ActionRequestValidationException? { @@ -48,5 +52,6 @@ class GetFindingsRequest : ActionRequest { out.writeOptionalString(monitorId) out.writeOptionalString(findingIndex) out.writeOptionalStringCollection(monitorIds) + out.writeOptionalString(severity) } } 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 253f4708..151db224 100644 --- a/src/test/kotlin/org/opensearch/commons/alerting/action/GetFindingsRequestTests.kt +++ b/src/test/kotlin/org/opensearch/commons/alerting/action/GetFindingsRequestTests.kt @@ -16,7 +16,7 @@ internal class GetFindingsRequestTests { val table = Table("asc", "sortString", null, 1, 0, "") - val req = GetFindingsRequest("2121", table, "1", "finding_index_name", listOf("1", "2")) + val req = GetFindingsRequest("2121", table, "1", "finding_index_name", listOf("1", "2"), "severity") assertNotNull(req) val out = BytesStreamOutput() @@ -27,6 +27,7 @@ internal class GetFindingsRequestTests { assertEquals("1", newReq.monitorId) assertEquals("2121", newReq.findingId) assertEquals("finding_index_name", newReq.findingIndex) + assertEquals("severity", newReq.severity) assertEquals(table, newReq.table) assertTrue(newReq.monitorIds!!.contains("1")) assertTrue(newReq.monitorIds!!.contains("2")) @@ -36,7 +37,7 @@ internal class GetFindingsRequestTests { fun `test validate returns null`() { val table = Table("asc", "sortString", null, 1, 0, "") - val req = GetFindingsRequest("2121", table, "1", "active") + val req = GetFindingsRequest("2121", table, "1", "active", listOf("1", "2"), "severity") assertNotNull(req) assertNull(req.validate()) } From ca4fbbff8a1cd1f029bfbeb435ef7968eb7d68a2 Mon Sep 17 00:00:00 2001 From: Riya Saxena Date: Tue, 30 Jan 2024 18:52:45 -0800 Subject: [PATCH 2/4] added detectionType as param for Findings API enhancements Signed-off-by: Riya Saxena --- .../commons/alerting/action/GetFindingsRequest.kt | 9 +++++++-- .../commons/alerting/action/GetFindingsRequestTests.kt | 5 +++-- 2 files changed, 10 insertions(+), 4 deletions(-) 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 6f1a90b0..df302a13 100644 --- a/src/main/kotlin/org/opensearch/commons/alerting/action/GetFindingsRequest.kt +++ b/src/main/kotlin/org/opensearch/commons/alerting/action/GetFindingsRequest.kt @@ -14,6 +14,7 @@ class GetFindingsRequest : ActionRequest { val monitorIds: List? val findingIndex: String? val severity: String? + val detectionType: String? constructor( findingId: String?, @@ -21,7 +22,8 @@ class GetFindingsRequest : ActionRequest { monitorId: String? = null, findingIndexName: String? = null, monitorIds: List? = null, - severity: String? = null + severity: String? = null, + detectionType: String? = null ) : super() { this.findingId = findingId this.table = table @@ -29,6 +31,7 @@ class GetFindingsRequest : ActionRequest { this.findingIndex = findingIndexName this.monitorIds = monitorIds this.severity = severity + this.detectionType = detectionType } @Throws(IOException::class) @@ -38,7 +41,8 @@ class GetFindingsRequest : ActionRequest { monitorId = sin.readOptionalString(), findingIndexName = sin.readOptionalString(), monitorIds = sin.readOptionalStringList(), - severity = sin.readOptionalString() + severity = sin.readOptionalString(), + detectionType = sin.readOptionalString() ) override fun validate(): ActionRequestValidationException? { @@ -53,5 +57,6 @@ class GetFindingsRequest : ActionRequest { out.writeOptionalString(findingIndex) out.writeOptionalStringCollection(monitorIds) out.writeOptionalString(severity) + out.writeOptionalString(detectionType) } } 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 151db224..2288716f 100644 --- a/src/test/kotlin/org/opensearch/commons/alerting/action/GetFindingsRequestTests.kt +++ b/src/test/kotlin/org/opensearch/commons/alerting/action/GetFindingsRequestTests.kt @@ -16,7 +16,7 @@ internal class GetFindingsRequestTests { val table = Table("asc", "sortString", null, 1, 0, "") - val req = GetFindingsRequest("2121", table, "1", "finding_index_name", listOf("1", "2"), "severity") + val req = GetFindingsRequest("2121", table, "1", "finding_index_name", listOf("1", "2"), "severity", "detectionType") assertNotNull(req) val out = BytesStreamOutput() @@ -28,6 +28,7 @@ internal class GetFindingsRequestTests { assertEquals("2121", newReq.findingId) assertEquals("finding_index_name", newReq.findingIndex) assertEquals("severity", newReq.severity) + assertEquals("detectionType", newReq.detectionType) assertEquals(table, newReq.table) assertTrue(newReq.monitorIds!!.contains("1")) assertTrue(newReq.monitorIds!!.contains("2")) @@ -37,7 +38,7 @@ internal class GetFindingsRequestTests { fun `test validate returns null`() { val table = Table("asc", "sortString", null, 1, 0, "") - val req = GetFindingsRequest("2121", table, "1", "active", listOf("1", "2"), "severity") + val req = GetFindingsRequest("2121", table, "1", "active", listOf("1", "2"), "severity", "detectionType") assertNotNull(req) assertNull(req.validate()) } From 99e3114bf447d5628ce1dda2dbfb7a2835175334 Mon Sep 17 00:00:00 2001 From: Riya Saxena Date: Thu, 29 Feb 2024 09:16:36 -0800 Subject: [PATCH 3/4] adding addiional params findingIds, startTime and endTime Signed-off-by: Riya Saxena --- .../alerting/action/GetFindingsRequest.kt | 20 +++++++++++++++++-- .../action/GetFindingsRequestTests.kt | 9 +++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) 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 df302a13..79b3cef1 100644 --- a/src/main/kotlin/org/opensearch/commons/alerting/action/GetFindingsRequest.kt +++ b/src/main/kotlin/org/opensearch/commons/alerting/action/GetFindingsRequest.kt @@ -6,6 +6,7 @@ import org.opensearch.commons.alerting.model.Table import org.opensearch.core.common.io.stream.StreamInput import org.opensearch.core.common.io.stream.StreamOutput import java.io.IOException +import java.time.Instant class GetFindingsRequest : ActionRequest { val findingId: String? @@ -15,6 +16,9 @@ class GetFindingsRequest : ActionRequest { val findingIndex: String? val severity: String? val detectionType: String? + val findingIds: List? + val startTime: Instant? + val endTime: Instant? constructor( findingId: String?, @@ -23,7 +27,10 @@ class GetFindingsRequest : ActionRequest { findingIndexName: String? = null, monitorIds: List? = null, severity: String? = null, - detectionType: String? = null + detectionType: String? = null , + findingIds: List? = null, + startTime: Instant? = null, + endTime: Instant? = null ) : super() { this.findingId = findingId this.table = table @@ -32,6 +39,9 @@ class GetFindingsRequest : ActionRequest { this.monitorIds = monitorIds this.severity = severity this.detectionType = detectionType + this.findingIds = findingIds + this.startTime = startTime + this.endTime = endTime } @Throws(IOException::class) @@ -42,7 +52,10 @@ class GetFindingsRequest : ActionRequest { findingIndexName = sin.readOptionalString(), monitorIds = sin.readOptionalStringList(), severity = sin.readOptionalString(), - detectionType = sin.readOptionalString() + detectionType = sin.readOptionalString(), + findingIds = sin.readOptionalStringList(), + startTime = sin.readOptionalInstant(), + endTime = sin.readOptionalInstant() ) override fun validate(): ActionRequestValidationException? { @@ -58,5 +71,8 @@ class GetFindingsRequest : ActionRequest { out.writeOptionalStringCollection(monitorIds) out.writeOptionalString(severity) out.writeOptionalString(detectionType) + out.writeOptionalStringCollection(findingIds) + out.writeOptionalInstant(startTime) + out.writeOptionalInstant(endTime) } } 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 066f0eb2..b77d2609 100644 --- a/src/test/kotlin/org/opensearch/commons/alerting/action/GetFindingsRequestTests.kt +++ b/src/test/kotlin/org/opensearch/commons/alerting/action/GetFindingsRequestTests.kt @@ -8,14 +8,16 @@ import org.junit.jupiter.api.Test import org.opensearch.common.io.stream.BytesStreamOutput import org.opensearch.commons.alerting.model.Table import org.opensearch.core.common.io.stream.StreamInput +import java.time.Instant internal class GetFindingsRequestTests { + @Test fun `test get findings request`() { val table = Table("asc", "sortString", null, 1, 0, "") - val req = GetFindingsRequest("2121", table, "1", "finding_index_name", listOf("1", "2"), "severity", "detectionType") + val req = GetFindingsRequest("2121", table, "1", "finding_index_name", listOf("1", "2"), "severity", "detectionType", listOf("id1", "id2", ), Instant.now(), Instant.now().plusSeconds(30000)) assertNotNull(req) val out = BytesStreamOutput() @@ -31,13 +33,16 @@ internal class GetFindingsRequestTests { assertEquals(table, newReq.table) assertTrue(newReq.monitorIds!!.contains("1")) assertTrue(newReq.monitorIds!!.contains("2")) + assertTrue(newReq.findingIds!!.contains("id1")) + assertTrue(newReq.findingIds!!.contains("id2")) + assertTrue(newReq.startTime!! < newReq.endTime, "startTime less than endTime") } @Test fun `test validate returns null`() { val table = Table("asc", "sortString", null, 1, 0, "") - val req = GetFindingsRequest("2121", table, "1", "active", listOf("1", "2"), "severity", "detectionType") + val req = GetFindingsRequest("2121", table, "1", "active", listOf("1", "2"), "severity", "detectionType", listOf("id1", "id2", ), Instant.now(), Instant.now().plusSeconds(30000)) assertNotNull(req) assertNull(req.validate()) } From 577850a1ddfa3741ad5480f4bfe787ece0b5b4c2 Mon Sep 17 00:00:00 2001 From: Riya Saxena Date: Thu, 29 Feb 2024 12:16:14 -0800 Subject: [PATCH 4/4] fix klint errors Signed-off-by: Riya Saxena --- .../commons/alerting/action/GetFindingsRequest.kt | 2 +- .../commons/alerting/action/GetFindingsRequestTests.kt | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) 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 79b3cef1..8ad2ff82 100644 --- a/src/main/kotlin/org/opensearch/commons/alerting/action/GetFindingsRequest.kt +++ b/src/main/kotlin/org/opensearch/commons/alerting/action/GetFindingsRequest.kt @@ -27,7 +27,7 @@ class GetFindingsRequest : ActionRequest { findingIndexName: String? = null, monitorIds: List? = null, severity: String? = null, - detectionType: String? = null , + detectionType: String? = null, findingIds: List? = null, startTime: Instant? = null, endTime: Instant? = null 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 b77d2609..67014d1b 100644 --- a/src/test/kotlin/org/opensearch/commons/alerting/action/GetFindingsRequestTests.kt +++ b/src/test/kotlin/org/opensearch/commons/alerting/action/GetFindingsRequestTests.kt @@ -12,12 +12,10 @@ import java.time.Instant internal class GetFindingsRequestTests { - @Test fun `test get findings request`() { val table = Table("asc", "sortString", null, 1, 0, "") - - val req = GetFindingsRequest("2121", table, "1", "finding_index_name", listOf("1", "2"), "severity", "detectionType", listOf("id1", "id2", ), Instant.now(), Instant.now().plusSeconds(30000)) + val req = GetFindingsRequest("2121", table, "1", "finding_index_name", listOf("1", "2"), "severity", "detectionType", listOf("id1", "id2"), Instant.now(), Instant.now().plusSeconds(30000)) assertNotNull(req) val out = BytesStreamOutput() @@ -41,8 +39,7 @@ internal class GetFindingsRequestTests { @Test fun `test validate returns null`() { val table = Table("asc", "sortString", null, 1, 0, "") - - val req = GetFindingsRequest("2121", table, "1", "active", listOf("1", "2"), "severity", "detectionType", listOf("id1", "id2", ), Instant.now(), Instant.now().plusSeconds(30000)) + val req = GetFindingsRequest("2121", table, "1", "active", listOf("1", "2"), "severity", "detectionType", listOf("id1", "id2"), Instant.now(), Instant.now().plusSeconds(30000)) assertNotNull(req) assertNull(req.validate()) }