From 88fe8653db14b72c6b0c8d37e094b6f8774e390a Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Wed, 25 Sep 2024 17:19:14 -0700 Subject: [PATCH] changes to support dynamic deletion of doc-level monitor query indices (#734) (#737) Signed-off-by: Subhobrata Dey --- .../org/opensearch/commons/alerting/model/Monitor.kt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/main/kotlin/org/opensearch/commons/alerting/model/Monitor.kt b/src/main/kotlin/org/opensearch/commons/alerting/model/Monitor.kt index 322e4b30..cc043f63 100644 --- a/src/main/kotlin/org/opensearch/commons/alerting/model/Monitor.kt +++ b/src/main/kotlin/org/opensearch/commons/alerting/model/Monitor.kt @@ -42,6 +42,7 @@ data class Monitor( val triggers: List, val uiMetadata: Map, val dataSources: DataSources = DataSources(), + val deleteQueryIndexInEveryRun: Boolean? = false, val owner: String? = "alerting" ) : ScheduledJob { @@ -110,6 +111,7 @@ data class Monitor( } else { DataSources() }, + deleteQueryIndexInEveryRun = sin.readOptionalBoolean(), owner = sin.readOptionalString() ) @@ -159,6 +161,7 @@ data class Monitor( .optionalTimeField(LAST_UPDATE_TIME_FIELD, lastUpdateTime) if (uiMetadata.isNotEmpty()) builder.field(UI_METADATA_FIELD, uiMetadata) builder.field(DATA_SOURCES_FIELD, dataSources) + builder.field(DELETE_QUERY_INDEX_IN_EVERY_RUN_FIELD, deleteQueryIndexInEveryRun) builder.field(OWNER_FIELD, owner) if (params.paramAsBoolean("with_type", false)) builder.endObject() return builder.endObject() @@ -210,6 +213,7 @@ data class Monitor( out.writeMap(uiMetadata) out.writeBoolean(dataSources != null) // for backward compatibility with pre-existing monitors which don't have datasources field dataSources.writeTo(out) + out.writeOptionalBoolean(deleteQueryIndexInEveryRun) out.writeOptionalString(owner) } @@ -230,6 +234,7 @@ data class Monitor( const val UI_METADATA_FIELD = "ui_metadata" const val DATA_SOURCES_FIELD = "data_sources" const val ENABLED_TIME_FIELD = "enabled_time" + const val DELETE_QUERY_INDEX_IN_EVERY_RUN_FIELD = "delete_query_index_in_every_run" const val OWNER_FIELD = "owner" val MONITOR_TYPE_PATTERN = Pattern.compile("[a-zA-Z0-9_]{5,25}") @@ -258,6 +263,7 @@ data class Monitor( val triggers: MutableList = mutableListOf() val inputs: MutableList = mutableListOf() var dataSources = DataSources() + var deleteQueryIndexInEveryRun = false var owner = "alerting" XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.currentToken(), xcp) @@ -311,6 +317,11 @@ data class Monitor( } else { DataSources.parse(xcp) } + DELETE_QUERY_INDEX_IN_EVERY_RUN_FIELD -> deleteQueryIndexInEveryRun = if (xcp.currentToken() == XContentParser.Token.VALUE_NULL) { + deleteQueryIndexInEveryRun + } else { + xcp.booleanValue() + } OWNER_FIELD -> owner = if (xcp.currentToken() == XContentParser.Token.VALUE_NULL) owner else xcp.text() else -> { xcp.skipChildren() @@ -338,6 +349,7 @@ data class Monitor( triggers.toList(), uiMetadata, dataSources, + deleteQueryIndexInEveryRun, owner ) }