Skip to content

Commit 90a2da6

Browse files
raj-chaklezzago
authored andcommitted
fix percolator mapping error when having field name 'type' (opensearch-project#726)
Signed-off-by: Raj Chakravarthi <[email protected]>
1 parent 309c304 commit 90a2da6

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

alerting/src/main/kotlin/org/opensearch/alerting/util/DocLevelMonitorQueries.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ class DocLevelMonitorQueries(private val client: Client, private val clusterServ
108108
flattenPaths: MutableList<String>
109109
) {
110110
// If node contains "properties" property then it is internal(non-leaf) node
111+
log.debug("Node in traverse: $node")
111112
if (node.containsKey(PROPERTIES)) {
112113
return traverseMappingsAndUpdate(node.get(PROPERTIES) as MutableMap<String, Any>, currentPath, processLeafFn, flattenPaths)
113-
} else if (node.containsKey(TYPE) == false) {
114-
// If there is no "type" property, this is either internal(non-leaf) node or leaf node
114+
} else {
115115
// newNodes will hold list of updated leaf properties
116116
var newNodes = ArrayList<Triple<String, String, Any>>(node.size)
117117
node.entries.forEach {

alerting/src/test/kotlin/org/opensearch/alerting/MonitorDataSourcesIT.kt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,19 @@ package org.opensearch.alerting
77

88
import org.junit.Assert
99
import org.opensearch.action.admin.indices.create.CreateIndexRequest
10+
import org.opensearch.action.search.SearchRequest
1011
import org.opensearch.alerting.action.GetAlertsAction
1112
import org.opensearch.alerting.action.GetAlertsRequest
1213
import org.opensearch.alerting.core.ScheduledJobIndices
1314
import org.opensearch.alerting.core.model.DocLevelMonitorInput
1415
import org.opensearch.alerting.core.model.DocLevelQuery
16+
import org.opensearch.alerting.core.model.ScheduledJob.Companion.DOC_LEVEL_QUERIES_INDEX
1517
import org.opensearch.alerting.core.model.ScheduledJob.Companion.SCHEDULED_JOBS_INDEX
1618
import org.opensearch.alerting.model.Table
1719
import org.opensearch.alerting.transport.AlertingSingleNodeTestCase
1820
import org.opensearch.common.settings.Settings
21+
import org.opensearch.index.query.QueryBuilders
22+
import org.opensearch.search.builder.SearchSourceBuilder
1923
import java.time.ZonedDateTime
2024
import java.time.format.DateTimeFormatter
2125
import java.time.temporal.ChronoUnit.MILLIS
@@ -62,6 +66,36 @@ class MonitorDataSourcesIT : AlertingSingleNodeTestCase() {
6266
Assert.assertTrue(getAlertsResponse.alerts.size == 0)
6367
}
6468

69+
fun `test delete monitor deletes all queries and metadata too`() {
70+
val docQuery = DocLevelQuery(query = "test_field:\"us-west-2\"", name = "3")
71+
val docLevelInput = DocLevelMonitorInput("description", listOf(index), listOf(docQuery))
72+
val trigger = randomDocumentLevelTrigger(condition = ALWAYS_RUN)
73+
var monitor = randomDocumentLevelMonitor(
74+
inputs = listOf(docLevelInput),
75+
triggers = listOf(trigger)
76+
)
77+
val monitorResponse = createMonitor(monitor)
78+
val testTime = DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(ZonedDateTime.now().truncatedTo(MILLIS))
79+
val testDoc = """{
80+
"message" : "This is an error from IAD region",
81+
"test_strict_date_time" : "$testTime",
82+
"test_field" : "us-west-2"
83+
}"""
84+
assertFalse(monitorResponse?.id.isNullOrEmpty())
85+
monitor = monitorResponse!!.monitor
86+
indexDoc(index, "1", testDoc)
87+
val monitorId = monitorResponse.id
88+
val executeMonitorResponse = executeMonitor(monitor, monitorId, false)
89+
Assert.assertEquals(executeMonitorResponse!!.monitorRunResult.monitorName, monitor.name)
90+
Assert.assertEquals(executeMonitorResponse.monitorRunResult.triggerResults.size, 1)
91+
searchAlerts(monitorId)
92+
// Verify queries exist
93+
var searchResponse = client().search(
94+
SearchRequest(DOC_LEVEL_QUERIES_INDEX).source(SearchSourceBuilder().query(QueryBuilders.matchAllQuery()))
95+
).get()
96+
assertNotEquals(0, searchResponse.hits.hits.size)
97+
}
98+
6599
fun `test execute pre-existing monitor and update`() {
66100
val request = CreateIndexRequest(SCHEDULED_JOBS_INDEX).mapping(ScheduledJobIndices.scheduledJobMappings())
67101
.settings(Settings.builder().put("index.hidden", true).build())

0 commit comments

Comments
 (0)