Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature findings enhancemnt #596

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,42 @@
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?
val table: Table
val monitorId: String?
val monitorIds: List<String>?
AWSHurneyt marked this conversation as resolved.
Show resolved Hide resolved
val findingIndex: String?
val severity: String?
val detectionType: String?
AWSHurneyt marked this conversation as resolved.
Show resolved Hide resolved
val findingIds: List<String>?
val startTime: Instant?
val endTime: Instant?

constructor(
findingId: String?,
table: Table,
monitorId: String? = null,
findingIndexName: String? = null,
monitorIds: List<String>? = null
monitorIds: List<String>? = null,
severity: String? = null,
detectionType: String? = null,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar comment here; this parameter should be named either logType, or detectorType to align with the rest of the repo. The UI refers to it as the logType (source), so I think that would be the better option; but I'd suggest going with whichever is more common in the code.

findingIds: List<String>? = null,
startTime: Instant? = null,
endTime: Instant? = null

Check warning on line 33 in src/main/kotlin/org/opensearch/commons/alerting/action/GetFindingsRequest.kt

View check run for this annotation

Codecov / codecov/patch

src/main/kotlin/org/opensearch/commons/alerting/action/GetFindingsRequest.kt#L28-L33

Added lines #L28 - L33 were not covered by tests
) : 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)
Expand All @@ -34,7 +50,12 @@
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? {
Expand All @@ -48,5 +69,10 @@
out.writeOptionalString(monitorId)
out.writeOptionalString(findingIndex)
out.writeOptionalStringCollection(monitorIds)
out.writeOptionalString(severity)
out.writeOptionalString(detectionType)
out.writeOptionalStringCollection(findingIds)
out.writeOptionalInstant(startTime)
out.writeOptionalInstant(endTime)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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())
}
Expand Down
Loading