From bc176a3d7387bc670dd4a6c685353636d2e68be5 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 17 Dec 2024 19:31:28 +0000 Subject: [PATCH] Monitor model changed to add an optional fanoutEnabled field (#758) * Monitor model changed to add an optional fanoutEnabled field Signed-off-by: Riya Saxena * Monitor model changed to add an optional fanoutEnabled field Signed-off-by: Riya Saxena * move fanoutEnabled to docLevel input Signed-off-by: Riya Saxena * move fanoutEnabled to docLevel input Signed-off-by: Riya Saxena * move fanoutEnabled to docLevel input Signed-off-by: Riya Saxena --------- Signed-off-by: Riya Saxena (cherry picked from commit cb9d38b1da03cc1f66e3482e2c665f03aa582376) Signed-off-by: github-actions[bot] --- .../alerting/model/DocLevelMonitorInput.kt | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 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..fd67007a 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