Skip to content

Commit 4ffebba

Browse files
Fix is doc level monitor check (#835) (#839)
(cherry picked from commit 97b8176) Signed-off-by: Surya Sashank Nistala <[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>
1 parent 3e28c92 commit 4ffebba

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,12 @@ class IndexMonitorRequest : ActionRequest {
6565
private fun hasDocLeveMonitorInput() = monitor.inputs.isNotEmpty() && monitor.inputs[0] is DocLevelMonitorInput
6666

6767
private fun isDocLevelMonitor() =
68-
monitor.monitorType.isNotBlank() && Monitor.MonitorType.valueOf(this.monitor.monitorType.uppercase(Locale.ROOT)) == Monitor.MonitorType.DOC_LEVEL_MONITOR
68+
monitor.monitorType.isNotBlank() && isMonitorOfStandardType(monitor.monitorType) && Monitor.MonitorType.valueOf(this.monitor.monitorType.uppercase(Locale.ROOT)) == Monitor.MonitorType.DOC_LEVEL_MONITOR
69+
70+
private fun isMonitorOfStandardType(monitorType: String): Boolean {
71+
val standardMonitorTypes = Monitor.MonitorType.values().map { it.value.uppercase(Locale.ROOT) }.toSet()
72+
return standardMonitorTypes.contains(monitorType.uppercase(Locale.ROOT))
73+
}
6974

7075
@Throws(IOException::class)
7176
override fun writeTo(out: StreamOutput) {

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,25 @@ class IndexMonitorRequestTests {
161161
)
162162
}
163163

164+
@Test
165+
fun `test remote monitor with wildcard index pattern`() {
166+
val monitor = randomDocumentLevelMonitor().copy(
167+
monitorType = "ti_doc_level_monitor",
168+
inputs = listOf(DocLevelMonitorInput(indices = listOf("valid, test*", "test*"), queries = emptyList()))
169+
)
170+
val req = IndexMonitorRequest(
171+
"1234",
172+
1L,
173+
2L,
174+
WriteRequest.RefreshPolicy.IMMEDIATE,
175+
RestRequest.Method.POST,
176+
monitor
177+
)
178+
179+
val validationException = req.validate()
180+
Assertions.assertNull(validationException)
181+
}
182+
164183
@Test
165184
fun `test doc level monitor with regex index pattern`() {
166185
val monitor = randomDocumentLevelMonitor().copy(

0 commit comments

Comments
 (0)