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

Accept of list of monitor ids in findings and alerts request dtos #277

Merged
merged 2 commits into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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,30 @@ import org.opensearch.common.io.stream.StreamInput
import org.opensearch.common.io.stream.StreamOutput
import org.opensearch.commons.alerting.model.Table
import java.io.IOException
import java.util.Collections

class GetAlertsRequest : ActionRequest {
val table: Table
val severityLevel: String
val alertState: String
val monitorId: String?
val alertIndex: String?
val monitorIds: List<String>?
Copy link
Contributor

@qreshi qreshi Oct 10, 2022

Choose a reason for hiding this comment

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

If we've defined monitorIds as nullable here, we should also make it nullable in the constructor (or non-nullable for both so it's consistent)

Same goes for the GetFindingsRequest

Copy link
Member Author

Choose a reason for hiding this comment

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

ack. done


constructor(
table: Table,
severityLevel: String,
alertState: String,
monitorId: String?,
alertIndex: String?
alertIndex: String?,
monitorIds: List<String> = Collections.emptyList()
) : 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 +38,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 +53,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 @@ -6,31 +6,36 @@ import org.opensearch.common.io.stream.StreamInput
import org.opensearch.common.io.stream.StreamOutput
import org.opensearch.commons.alerting.model.Table
import java.io.IOException
import java.util.Collections

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> = Collections.emptyList()
) : 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 +48,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