Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/main/kotlin/org/opensearch/commons/alerting/model/Monitor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ data class Monitor(
val inputs: List<Input>,
val triggers: List<Trigger>,
val uiMetadata: Map<String, Any>,
val dataSources: DataSources = DataSources()
val dataSources: DataSources = DataSources(),
val owner: String? = "alerting"
) : ScheduledJob {

override val type = MONITOR_TYPE
Expand Down Expand Up @@ -102,7 +103,8 @@ data class Monitor(
DataSources(sin)
} else {
DataSources()
}
},
owner = sin.readOptionalString()
)

// This enum classifies different Monitors
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -240,6 +245,7 @@ data class Monitor(
val triggers: MutableList<Trigger> = mutableListOf()
val inputs: MutableList<Input> = mutableListOf()
var dataSources = DataSources()
var owner = "alerting"

XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.currentToken(), xcp)
while (xcp.nextToken() != XContentParser.Token.END_OBJECT) {
Expand Down Expand Up @@ -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()
}
Expand All @@ -312,7 +319,8 @@ data class Monitor(
inputs.toList(),
triggers.toList(),
uiMetadata,
dataSources
dataSources,
owner
)
}

Expand Down