Skip to content

Commit 4d4c1af

Browse files
changes to support dynamic deletion of doc-level monitor query indices (#734) (#739)
Signed-off-by: Subhobrata Dey <[email protected]>
1 parent 34ba26b commit 4d4c1af

File tree

1 file changed

+12
-0
lines changed
  • src/main/kotlin/org/opensearch/commons/alerting/model

1 file changed

+12
-0
lines changed

src/main/kotlin/org/opensearch/commons/alerting/model/Monitor.kt

+12
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ data class Monitor(
4242
val triggers: List<Trigger>,
4343
val uiMetadata: Map<String, Any>,
4444
val dataSources: DataSources = DataSources(),
45+
val deleteQueryIndexInEveryRun: Boolean? = false,
4546
val owner: String? = "alerting"
4647
) : ScheduledJob {
4748

@@ -110,6 +111,7 @@ data class Monitor(
110111
} else {
111112
DataSources()
112113
},
114+
deleteQueryIndexInEveryRun = sin.readOptionalBoolean(),
113115
owner = sin.readOptionalString()
114116
)
115117

@@ -169,6 +171,7 @@ data class Monitor(
169171
.optionalTimeField(LAST_UPDATE_TIME_FIELD, lastUpdateTime)
170172
if (uiMetadata.isNotEmpty()) builder.field(UI_METADATA_FIELD, uiMetadata)
171173
builder.field(DATA_SOURCES_FIELD, dataSources)
174+
builder.field(DELETE_QUERY_INDEX_IN_EVERY_RUN_FIELD, deleteQueryIndexInEveryRun)
172175
builder.field(OWNER_FIELD, owner)
173176
if (params.paramAsBoolean("with_type", false)) builder.endObject()
174177
return builder.endObject()
@@ -220,6 +223,7 @@ data class Monitor(
220223
out.writeMap(uiMetadata)
221224
out.writeBoolean(dataSources != null) // for backward compatibility with pre-existing monitors which don't have datasources field
222225
dataSources.writeTo(out)
226+
out.writeOptionalBoolean(deleteQueryIndexInEveryRun)
223227
out.writeOptionalString(owner)
224228
}
225229

@@ -240,6 +244,7 @@ data class Monitor(
240244
const val UI_METADATA_FIELD = "ui_metadata"
241245
const val DATA_SOURCES_FIELD = "data_sources"
242246
const val ENABLED_TIME_FIELD = "enabled_time"
247+
const val DELETE_QUERY_INDEX_IN_EVERY_RUN_FIELD = "delete_query_index_in_every_run"
243248
const val OWNER_FIELD = "owner"
244249
val MONITOR_TYPE_PATTERN = Pattern.compile("[a-zA-Z0-9_]{5,25}")
245250

@@ -268,6 +273,7 @@ data class Monitor(
268273
val triggers: MutableList<Trigger> = mutableListOf()
269274
val inputs: MutableList<Input> = mutableListOf()
270275
var dataSources = DataSources()
276+
var deleteQueryIndexInEveryRun = false
271277
var owner = "alerting"
272278

273279
XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.currentToken(), xcp)
@@ -321,6 +327,11 @@ data class Monitor(
321327
} else {
322328
DataSources.parse(xcp)
323329
}
330+
DELETE_QUERY_INDEX_IN_EVERY_RUN_FIELD -> deleteQueryIndexInEveryRun = if (xcp.currentToken() == XContentParser.Token.VALUE_NULL) {
331+
deleteQueryIndexInEveryRun
332+
} else {
333+
xcp.booleanValue()
334+
}
324335
OWNER_FIELD -> owner = if (xcp.currentToken() == XContentParser.Token.VALUE_NULL) owner else xcp.text()
325336
else -> {
326337
xcp.skipChildren()
@@ -348,6 +359,7 @@ data class Monitor(
348359
triggers.toList(),
349360
uiMetadata,
350361
dataSources,
362+
deleteQueryIndexInEveryRun,
351363
owner
352364
)
353365
}

0 commit comments

Comments
 (0)