Skip to content

Commit 3a434fb

Browse files
opensearch-trigger-bot[bot]github-actions[bot]
authored andcommitted
Feature findings enhancemnt (opensearch-project#596) (opensearch-project#606)
* added support for param in Finding API * added detectionType as param for Findings API enhancements * adding addiional params findingIds, startTime and endTime * fix klint errors --------- (cherry picked from commit 892c34f) Signed-off-by: Riya Saxena <[email protected]> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Signed-off-by: AWSHurneyt <[email protected]>
1 parent 0dc19ef commit 3a434fb

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

src/main/kotlin/org/opensearch/commons/alerting/action/GetFindingsRequest.kt

+28-2
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,42 @@ import org.opensearch.commons.alerting.model.Table
66
import org.opensearch.core.common.io.stream.StreamInput
77
import org.opensearch.core.common.io.stream.StreamOutput
88
import java.io.IOException
9+
import java.time.Instant
910

1011
class GetFindingsRequest : ActionRequest {
1112
val findingId: String?
1213
val table: Table
1314
val monitorId: String?
1415
val monitorIds: List<String>?
1516
val findingIndex: String?
17+
val severity: String?
18+
val detectionType: String?
19+
val findingIds: List<String>?
20+
val startTime: Instant?
21+
val endTime: Instant?
1622

1723
constructor(
1824
findingId: String?,
1925
table: Table,
2026
monitorId: String? = null,
2127
findingIndexName: String? = null,
22-
monitorIds: List<String>? = null
28+
monitorIds: List<String>? = null,
29+
severity: String? = null,
30+
detectionType: String? = null,
31+
findingIds: List<String>? = null,
32+
startTime: Instant? = null,
33+
endTime: Instant? = null
2334
) : super() {
2435
this.findingId = findingId
2536
this.table = table
2637
this.monitorId = monitorId
2738
this.findingIndex = findingIndexName
2839
this.monitorIds = monitorIds
40+
this.severity = severity
41+
this.detectionType = detectionType
42+
this.findingIds = findingIds
43+
this.startTime = startTime
44+
this.endTime = endTime
2945
}
3046

3147
@Throws(IOException::class)
@@ -34,7 +50,12 @@ class GetFindingsRequest : ActionRequest {
3450
table = Table.readFrom(sin),
3551
monitorId = sin.readOptionalString(),
3652
findingIndexName = sin.readOptionalString(),
37-
monitorIds = sin.readOptionalStringList()
53+
monitorIds = sin.readOptionalStringList(),
54+
severity = sin.readOptionalString(),
55+
detectionType = sin.readOptionalString(),
56+
findingIds = sin.readOptionalStringList(),
57+
startTime = sin.readOptionalInstant(),
58+
endTime = sin.readOptionalInstant()
3859
)
3960

4061
override fun validate(): ActionRequestValidationException? {
@@ -48,5 +69,10 @@ class GetFindingsRequest : ActionRequest {
4869
out.writeOptionalString(monitorId)
4970
out.writeOptionalString(findingIndex)
5071
out.writeOptionalStringCollection(monitorIds)
72+
out.writeOptionalString(severity)
73+
out.writeOptionalString(detectionType)
74+
out.writeOptionalStringCollection(findingIds)
75+
out.writeOptionalInstant(startTime)
76+
out.writeOptionalInstant(endTime)
5177
}
5278
}

src/test/kotlin/org/opensearch/commons/alerting/action/GetFindingsRequestTests.kt

+8-4
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ import org.junit.jupiter.api.Test
88
import org.opensearch.common.io.stream.BytesStreamOutput
99
import org.opensearch.commons.alerting.model.Table
1010
import org.opensearch.core.common.io.stream.StreamInput
11+
import java.time.Instant
1112

1213
internal class GetFindingsRequestTests {
1314

1415
@Test
1516
fun `test get findings request`() {
1617
val table = Table("asc", "sortString", null, 1, 0, "")
17-
18-
val req = GetFindingsRequest("2121", table, "1", "finding_index_name", listOf("1", "2"))
18+
val req = GetFindingsRequest("2121", table, "1", "finding_index_name", listOf("1", "2"), "severity", "detectionType", listOf("id1", "id2"), Instant.now(), Instant.now().plusSeconds(30000))
1919
assertNotNull(req)
2020

2121
val out = BytesStreamOutput()
@@ -26,16 +26,20 @@ internal class GetFindingsRequestTests {
2626
assertEquals("1", newReq.monitorId)
2727
assertEquals("2121", newReq.findingId)
2828
assertEquals("finding_index_name", newReq.findingIndex)
29+
assertEquals("severity", newReq.severity)
30+
assertEquals("detectionType", newReq.detectionType)
2931
assertEquals(table, newReq.table)
3032
assertTrue(newReq.monitorIds!!.contains("1"))
3133
assertTrue(newReq.monitorIds!!.contains("2"))
34+
assertTrue(newReq.findingIds!!.contains("id1"))
35+
assertTrue(newReq.findingIds!!.contains("id2"))
36+
assertTrue(newReq.startTime!! < newReq.endTime, "startTime less than endTime")
3237
}
3338

3439
@Test
3540
fun `test validate returns null`() {
3641
val table = Table("asc", "sortString", null, 1, 0, "")
37-
38-
val req = GetFindingsRequest("2121", table, "1", "active")
42+
val req = GetFindingsRequest("2121", table, "1", "active", listOf("1", "2"), "severity", "detectionType", listOf("id1", "id2"), Instant.now(), Instant.now().plusSeconds(30000))
3943
assertNotNull(req)
4044
assertNull(req.validate())
4145
}

0 commit comments

Comments
 (0)