@@ -24,6 +24,8 @@ import org.opensearch.core.xcontent.XContentParser
2424import org.opensearch.core.xcontent.XContentParserUtils
2525import java.io.IOException
2626import java.time.Instant
27+ import org.opensearch.commons.alerting.model.Monitor.Companion.SCHEMA_VERSION_FIELD
28+ import org.opensearch.commons.alerting.util.IndexUtils.Companion.NO_SCHEMA_VERSION
2729
2830private val logger = LogManager .getLogger(PPLMonitor ::class .java)
2931
@@ -40,6 +42,7 @@ data class PPLMonitor(
4042 override val schedule : Schedule ,
4143 override val lastUpdateTime : Instant ,
4244 override val enabledTime : Instant ? ,
45+ override val schemaVersion : Int = NO_SCHEMA_VERSION ,
4346 override val triggers : List <TriggerV2 >,
4447 val queryLanguage : QueryLanguage = QueryLanguage .PPL , // default to PPL, SQL not currently supported
4548 val query : String
@@ -84,6 +87,7 @@ data class PPLMonitor(
8487 schedule = Schedule .readFrom(sin),
8588 lastUpdateTime = sin.readInstant(),
8689 enabledTime = sin.readOptionalInstant(),
90+ schemaVersion = sin.readInt(),
8791 triggers = sin.readList(TriggerV2 ::readFrom),
8892 queryLanguage = sin.readEnum(QueryLanguage ::class .java),
8993 query = sin.readString()
@@ -106,8 +110,9 @@ data class PPLMonitor(
106110 builder.field(NAME_FIELD , name)
107111 builder.field(SCHEDULE_FIELD , schedule)
108112 builder.field(ENABLED_FIELD , enabled)
109- builder.optionalTimeField(ENABLED_TIME_FIELD , enabledTime)
110113 builder.nonOptionalTimeField(LAST_UPDATE_TIME_FIELD , lastUpdateTime)
114+ builder.optionalTimeField(ENABLED_TIME_FIELD , enabledTime)
115+ builder.field(SCHEMA_VERSION_FIELD , schemaVersion)
111116 builder.field(TRIGGERS_FIELD , triggers.toTypedArray())
112117 builder.field(QUERY_LANGUAGE_FIELD , queryLanguage.value)
113118 builder.field(QUERY_FIELD , query)
@@ -137,6 +142,7 @@ data class PPLMonitor(
137142 }
138143 out .writeInstant(lastUpdateTime)
139144 out .writeOptionalInstant(enabledTime)
145+ out .writeInt(schemaVersion)
140146 out .writeVInt(triggers.size)
141147 triggers.forEach {
142148 out .writeEnum(TriggerV2 .TriggerV2Type .PPL_TRIGGER )
@@ -192,6 +198,7 @@ data class PPLMonitor(
192198 var schedule: Schedule ? = null
193199 var lastUpdateTime: Instant ? = null
194200 var enabledTime: Instant ? = null
201+ var schemaVersion = NO_SCHEMA_VERSION
195202 val triggers: MutableList <TriggerV2 > = mutableListOf ()
196203 var queryLanguage: QueryLanguage = QueryLanguage .PPL // default to PPL
197204 var query: String? = null
@@ -207,8 +214,9 @@ data class PPLMonitor(
207214 MONITOR_TYPE_FIELD -> monitorType = xcp.text()
208215 ENABLED_FIELD -> enabled = xcp.booleanValue()
209216 SCHEDULE_FIELD -> schedule = Schedule .parse(xcp)
210- ENABLED_TIME_FIELD -> enabledTime = xcp.instant()
211217 LAST_UPDATE_TIME_FIELD -> lastUpdateTime = xcp.instant()
218+ ENABLED_TIME_FIELD -> enabledTime = xcp.instant()
219+ SCHEMA_VERSION_FIELD -> schemaVersion = xcp.intValue()
212220 TRIGGERS_FIELD -> {
213221 XContentParserUtils .ensureExpectedToken(
214222 XContentParser .Token .START_ARRAY ,
@@ -274,6 +282,7 @@ data class PPLMonitor(
274282 schedule,
275283 lastUpdateTime,
276284 enabledTime,
285+ schemaVersion,
277286 triggers,
278287 queryLanguage,
279288 query
0 commit comments