From ab7ce61c6a84624662083844578ba432b32c44e1 Mon Sep 17 00:00:00 2001 From: Riya Saxena Date: Tue, 17 Dec 2024 10:49:11 -0800 Subject: [PATCH] move fanoutEnabled to docLevel input Signed-off-by: Riya Saxena --- .../alerting/model/DocLevelMonitorInput.kt | 18 ++++++++++++++---- .../commons/alerting/model/Monitor.kt | 12 ------------ 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/main/kotlin/org/opensearch/commons/alerting/model/DocLevelMonitorInput.kt b/src/main/kotlin/org/opensearch/commons/alerting/model/DocLevelMonitorInput.kt index 3193ee57..d582f625 100644 --- a/src/main/kotlin/org/opensearch/commons/alerting/model/DocLevelMonitorInput.kt +++ b/src/main/kotlin/org/opensearch/commons/alerting/model/DocLevelMonitorInput.kt @@ -14,14 +14,16 @@ import java.io.IOException data class DocLevelMonitorInput( val description: String = NO_DESCRIPTION, val indices: List, - val queries: List + val queries: List, + val fanoutEnabled: Boolean? = true ) : Input { @Throws(IOException::class) constructor(sin: StreamInput) : this( sin.readString(), // description sin.readStringList(), // indices - sin.readList(::DocLevelQuery) // docLevelQueries + sin.readList(::DocLevelQuery), // docLevelQueries + sin.readOptionalBoolean(), // fanoutEnabled ) override fun asTemplateArg(): Map { @@ -41,6 +43,7 @@ data class DocLevelMonitorInput( out.writeString(description) out.writeStringCollection(indices) out.writeCollection(queries) + out.writeOptionalBoolean(fanoutEnabled) } override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder { @@ -49,6 +52,7 @@ data class DocLevelMonitorInput( .field(DESCRIPTION_FIELD, description) .field(INDICES_FIELD, indices.toTypedArray()) .field(QUERIES_FIELD, queries.toTypedArray()) + .field(FANOUT_FIELD, fanoutEnabled) .endObject() .endObject() return builder @@ -59,7 +63,7 @@ data class DocLevelMonitorInput( const val INDICES_FIELD = "indices" const val DOC_LEVEL_INPUT_FIELD = "doc_level_input" const val QUERIES_FIELD = "queries" - + const val FANOUT_FIELD = "fan_out_enabled" const val NO_DESCRIPTION = "" val XCONTENT_REGISTRY = NamedXContentRegistry.Entry( @@ -74,6 +78,7 @@ data class DocLevelMonitorInput( var description: String = NO_DESCRIPTION val indices: MutableList = mutableListOf() val docLevelQueries: MutableList = mutableListOf() + var fanoutEnabled: Boolean? = true XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.currentToken(), xcp) while (xcp.nextToken() != XContentParser.Token.END_OBJECT) { @@ -102,10 +107,15 @@ data class DocLevelMonitorInput( docLevelQueries.add(DocLevelQuery.parse(xcp)) } } + FANOUT_FIELD -> fanoutEnabled = if (xcp.currentToken() == XContentParser.Token.VALUE_NULL) { + fanoutEnabled + } else { + xcp.booleanValue() + } } } - return DocLevelMonitorInput(description = description, indices = indices, queries = docLevelQueries) + return DocLevelMonitorInput(description = description, indices = indices, queries = docLevelQueries, fanoutEnabled = fanoutEnabled) } @JvmStatic 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 02bac4b5..c8e5a7cf 100644 --- a/src/main/kotlin/org/opensearch/commons/alerting/model/Monitor.kt +++ b/src/main/kotlin/org/opensearch/commons/alerting/model/Monitor.kt @@ -45,7 +45,6 @@ data class Monitor( val deleteQueryIndexInEveryRun: Boolean? = false, val shouldCreateSingleAlertForFindings: Boolean? = false, val owner: String? = "alerting", - val fanoutEnabled: Boolean? = true ) : ScheduledJob { override val type = MONITOR_TYPE @@ -115,7 +114,6 @@ data class Monitor( }, deleteQueryIndexInEveryRun = sin.readOptionalBoolean(), shouldCreateSingleAlertForFindings = sin.readOptionalBoolean(), - fanoutEnabled = sin.readOptionalBoolean(), owner = sin.readOptionalString() ) @@ -177,7 +175,6 @@ data class Monitor( builder.field(DATA_SOURCES_FIELD, dataSources) builder.field(DELETE_QUERY_INDEX_IN_EVERY_RUN_FIELD, deleteQueryIndexInEveryRun) builder.field(SHOULD_CREATE_SINGLE_ALERT_FOR_FINDINGS_FIELD, shouldCreateSingleAlertForFindings) - builder.field(FAN_OUT_ENABLED_FIELD, fanoutEnabled) builder.field(OWNER_FIELD, owner) if (params.paramAsBoolean("with_type", false)) builder.endObject() return builder.endObject() @@ -231,7 +228,6 @@ data class Monitor( dataSources.writeTo(out) out.writeOptionalBoolean(deleteQueryIndexInEveryRun) out.writeOptionalBoolean(shouldCreateSingleAlertForFindings) - out.writeOptionalBoolean(fanoutEnabled) out.writeOptionalString(owner) } @@ -254,7 +250,6 @@ data class Monitor( const val ENABLED_TIME_FIELD = "enabled_time" const val DELETE_QUERY_INDEX_IN_EVERY_RUN_FIELD = "delete_query_index_in_every_run" const val SHOULD_CREATE_SINGLE_ALERT_FOR_FINDINGS_FIELD = "should_create_single_alert_for_findings" - const val FAN_OUT_ENABLED_FIELD = "fan_out_enabled" const val OWNER_FIELD = "owner" val MONITOR_TYPE_PATTERN = Pattern.compile("[a-zA-Z0-9_]{5,25}") @@ -286,7 +281,6 @@ data class Monitor( var deleteQueryIndexInEveryRun = false var delegateMonitor = false var owner = "alerting" - var fanoutEnabled = true XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.currentToken(), xcp) while (xcp.nextToken() != XContentParser.Token.END_OBJECT) { @@ -349,11 +343,6 @@ data class Monitor( } else { xcp.booleanValue() } - FAN_OUT_ENABLED_FIELD -> fanoutEnabled = if (xcp.currentToken() == XContentParser.Token.VALUE_NULL) { - fanoutEnabled - } else { - xcp.booleanValue() - } OWNER_FIELD -> owner = if (xcp.currentToken() == XContentParser.Token.VALUE_NULL) owner else xcp.text() else -> { xcp.skipChildren() @@ -384,7 +373,6 @@ data class Monitor( deleteQueryIndexInEveryRun, delegateMonitor, owner, - fanoutEnabled ) }