From 5fd57e57c54e6dc900458783fcb25260e1e0599e Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sat, 9 Mar 2024 00:44:28 +0000 Subject: [PATCH] Feature findings enhancemnt (#596) * added support for param in Finding API Signed-off-by: Riya Saxena * added detectionType as param for Findings API enhancements Signed-off-by: Riya Saxena * adding addiional params findingIds, startTime and endTime Signed-off-by: Riya Saxena * fix klint errors Signed-off-by: Riya Saxena --------- Signed-off-by: Riya Saxena (cherry picked from commit 892c34fc1b048e43aeafdb16ad33be1a7f44651f) Signed-off-by: github-actions[bot] --- .../alerting/action/GetFindingsRequest.kt | 30 +++++++++++++++++-- .../action/GetFindingsRequestTests.kt | 12 +++++--- 2 files changed, 36 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 0004d4f1..8ad2ff82 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? @@ -13,19 +14,34 @@ class GetFindingsRequest : ActionRequest { val monitorId: String? val monitorIds: List? val findingIndex: String? + val severity: String? + val detectionType: String? + val findingIds: List? + val startTime: Instant? + val endTime: Instant? constructor( findingId: String?, table: Table, monitorId: String? = null, findingIndexName: String? = null, - monitorIds: List? = null + monitorIds: List? = null, + severity: String? = null, + detectionType: String? = null, + findingIds: List? = null, + startTime: Instant? = null, + endTime: Instant? = null ) : super() { this.findingId = findingId this.table = table this.monitorId = monitorId this.findingIndex = findingIndexName this.monitorIds = monitorIds + this.severity = severity + this.detectionType = detectionType + this.findingIds = findingIds + this.startTime = startTime + this.endTime = endTime } @Throws(IOException::class) @@ -34,7 +50,12 @@ class GetFindingsRequest : ActionRequest { table = Table.readFrom(sin), monitorId = sin.readOptionalString(), findingIndexName = sin.readOptionalString(), - monitorIds = sin.readOptionalStringList() + monitorIds = sin.readOptionalStringList(), + severity = sin.readOptionalString(), + detectionType = sin.readOptionalString(), + findingIds = sin.readOptionalStringList(), + startTime = sin.readOptionalInstant(), + endTime = sin.readOptionalInstant() ) override fun validate(): ActionRequestValidationException? { @@ -48,5 +69,10 @@ class GetFindingsRequest : ActionRequest { out.writeOptionalString(monitorId) out.writeOptionalString(findingIndex) 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 ddd56d15..67014d1b 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,14 @@ 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")) + 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() @@ -26,16 +26,20 @@ internal class GetFindingsRequestTests { assertEquals("1", newReq.monitorId) 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")) + 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") + 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()) }