Skip to content

Commit 6d25039

Browse files
committed
adding schemaVersion
Signed-off-by: Dennis Toepker <[email protected]>
1 parent 2f9be0a commit 6d25039

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/main/kotlin/org/opensearch/commons/alerting/model/MonitorV2.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import org.opensearch.core.xcontent.XContentParser
1010
import org.opensearch.core.xcontent.XContentParserUtils
1111
import java.io.IOException
1212
import java.time.Instant
13+
import org.opensearch.commons.alerting.util.IndexUtils.Companion.NO_SCHEMA_VERSION
1314

1415
interface MonitorV2 : ScheduledJob {
1516
override val id: String
@@ -19,6 +20,7 @@ interface MonitorV2 : ScheduledJob {
1920
override val schedule: Schedule
2021
override val lastUpdateTime: Instant // required for scheduled job maintenance
2122
override val enabledTime: Instant? // required for scheduled job maintenance
23+
val schemaVersion: Int // for updating monitors
2224
val triggers: List<TriggerV2>
2325

2426
fun asTemplateArg(): Map<String, Any?>

src/main/kotlin/org/opensearch/commons/alerting/model/PPLMonitor.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import org.opensearch.core.xcontent.XContentParser
2424
import org.opensearch.core.xcontent.XContentParserUtils
2525
import java.io.IOException
2626
import 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

2830
private 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

Comments
 (0)