From dfa926306f5cfc6ba07344004f5881f6f51de7b8 Mon Sep 17 00:00:00 2001 From: Surya Sashank Nistala Date: Wed, 2 Nov 2022 15:05:09 -0700 Subject: [PATCH] Adds owner field in monitor model (#313) Signed-off-by: Surya Sashank Nistala Signed-off-by: Surya Sashank Nistala --- .../opensearch/commons/alerting/model/Monitor.kt | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) 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 9f3e22a4..a12e5ef7 100644 --- a/src/main/kotlin/org/opensearch/commons/alerting/model/Monitor.kt +++ b/src/main/kotlin/org/opensearch/commons/alerting/model/Monitor.kt @@ -40,7 +40,8 @@ data class Monitor( val inputs: List, val triggers: List, val uiMetadata: Map, - val dataSources: DataSources = DataSources() + val dataSources: DataSources = DataSources(), + val owner: String? = "alerting" ) : ScheduledJob { override val type = MONITOR_TYPE @@ -102,7 +103,8 @@ data class Monitor( DataSources(sin) } else { DataSources() - } + }, + owner = sin.readOptionalString() ) // This enum classifies different Monitors @@ -151,6 +153,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(OWNER_FIELD, owner) if (params.paramAsBoolean("with_type", false)) builder.endObject() return builder.endObject() } @@ -195,6 +198,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.writeOptionalString(owner) } companion object { @@ -214,6 +218,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 OWNER_FIELD = "owner" // This is defined here instead of in ScheduledJob to avoid having the ScheduledJob class know about all // the different subclasses and creating circular dependencies @@ -240,6 +245,7 @@ data class Monitor( val triggers: MutableList = mutableListOf() val inputs: MutableList = mutableListOf() var dataSources = DataSources() + var owner = "alerting" XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.currentToken(), xcp) while (xcp.nextToken() != XContentParser.Token.END_OBJECT) { @@ -287,6 +293,7 @@ data class Monitor( UI_METADATA_FIELD -> uiMetadata = xcp.map() DATA_SOURCES_FIELD -> dataSources = if (xcp.currentToken() == XContentParser.Token.VALUE_NULL) DataSources() else DataSources.parse(xcp) + OWNER_FIELD -> owner = if (xcp.currentToken() == XContentParser.Token.VALUE_NULL) owner else xcp.text() else -> { xcp.skipChildren() } @@ -312,7 +319,8 @@ data class Monitor( inputs.toList(), triggers.toList(), uiMetadata, - dataSources + dataSources, + owner ) }