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

[Backport 2.x] Accept of list of monitor ids in findings and alerts request dtos (#277) #278

Merged
merged 1 commit into from
Oct 10, 2022
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 @@ -13,19 +13,22 @@ class GetAlertsRequest : ActionRequest {
val alertState: String
val monitorId: String?
val alertIndex: String?
val monitorIds: List<String>?

constructor(
table: Table,
severityLevel: String,
alertState: String,
monitorId: String?,
alertIndex: String?
alertIndex: String?,
monitorIds: List<String>? = null
) : super() {
this.table = table
this.severityLevel = severityLevel
this.alertState = alertState
this.monitorId = monitorId
this.alertIndex = alertIndex
this.monitorIds = monitorIds
}

@Throws(IOException::class)
Expand All @@ -34,7 +37,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? {
Expand All @@ -48,5 +52,6 @@ class GetAlertsRequest : ActionRequest {
out.writeString(alertState)
out.writeOptionalString(monitorId)
out.writeOptionalString(alertIndex)
out.writeOptionalStringCollection(monitorIds)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,30 @@ class GetFindingsRequest : ActionRequest {
val findingId: String?
val table: Table
val monitorId: String?
val monitorIds: List<String>?
val findingIndex: String?

constructor(
findingId: String?,
table: Table,
monitorId: String? = null,
findingIndexName: String? = null
findingIndexName: String? = null,
monitorIds: List<String>? = null
) : super() {
this.findingId = findingId
this.table = table
this.monitorId = monitorId
this.findingIndex = findingIndexName
this.monitorIds = monitorIds
}

@Throws(IOException::class)
constructor(sin: StreamInput) : this(
findingId = sin.readOptionalString(),
table = Table.readFrom(sin),
monitorId = sin.readOptionalString(),
findingIndexName = sin.readOptionalString()
findingIndexName = sin.readOptionalString(),
monitorIds = sin.readOptionalStringList()
)

override fun validate(): ActionRequestValidationException? {
Expand All @@ -43,5 +47,6 @@ class GetFindingsRequest : ActionRequest {
table.writeTo(out)
out.writeOptionalString(monitorId)
out.writeOptionalString(findingIndex)
out.writeOptionalStringCollection(monitorIds)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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
Expand Down