Skip to content

Commit a911dad

Browse files
committed
removing action execution results from alertV2 and other cleanup
1 parent d836b0a commit a911dad

File tree

5 files changed

+16
-27
lines changed

5 files changed

+16
-27
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import org.opensearch.core.xcontent.XContentParser
3535
import org.opensearch.core.xcontent.XContentParserUtils.ensureExpectedToken
3636
import java.io.IOException
3737
import java.time.Instant
38+
import org.opensearch.commons.alerting.util.nonOptionalTimeField
3839

3940
data class AlertV2(
4041
val id: String = NO_ID,
@@ -47,10 +48,10 @@ data class AlertV2(
4748
val triggerId: String,
4849
val triggerName: String,
4950
val queryResults: Map<String, Any>,
51+
val triggeredTime: Instant,
5052
val expirationTime: Instant?,
5153
val errorMessage: String? = null,
5254
val severity: String,
53-
val actionExecutionResults: List<ActionExecutionResult>,
5455
val executionId: String? = null
5556
) : Writeable, ToXContent {
5657
@Throws(IOException::class)
@@ -69,10 +70,10 @@ data class AlertV2(
6970
triggerId = sin.readString(),
7071
triggerName = sin.readString(),
7172
queryResults = sin.readMap()!!.toMap(),
73+
triggeredTime = sin.readInstant(),
7274
expirationTime = sin.readOptionalInstant(),
7375
errorMessage = sin.readOptionalString(),
7476
severity = sin.readString(),
75-
actionExecutionResults = sin.readList(::ActionExecutionResult),
7677
executionId = sin.readOptionalString()
7778
)
7879

@@ -89,10 +90,10 @@ data class AlertV2(
8990
out.writeString(triggerId)
9091
out.writeString(triggerName)
9192
out.writeMap(queryResults)
93+
out.writeInstant(triggeredTime)
9294
out.writeOptionalInstant(expirationTime)
9395
out.writeOptionalString(errorMessage)
9496
out.writeString(severity)
95-
out.writeCollection(actionExecutionResults)
9697
out.writeOptionalString(executionId)
9798
}
9899

@@ -110,7 +111,7 @@ data class AlertV2(
110111
.field(QUERY_RESULTS_FIELD, queryResults)
111112
.field(ERROR_MESSAGE_FIELD, errorMessage)
112113
.field(SEVERITY_FIELD, severity)
113-
.field(ACTION_EXECUTION_RESULTS_FIELD, actionExecutionResults.toTypedArray())
114+
.nonOptionalTimeField(TRIGGERED_TIME_FIELD, triggeredTime)
114115
.optionalTimeField(EXPIRATION_TIME_FIELD, expirationTime)
115116
.endObject()
116117

@@ -133,6 +134,7 @@ data class AlertV2(
133134
}
134135

135136
companion object {
137+
const val TRIGGERED_TIME_FIELD = "triggered_time"
136138
const val EXPIRATION_TIME_FIELD = "expiration_time"
137139
const val QUERY_RESULTS_FIELD = "query_results"
138140

@@ -149,6 +151,7 @@ data class AlertV2(
149151
lateinit var triggerName: String
150152
var queryResults: Map<String, Any> = mapOf()
151153
lateinit var severity: String
154+
var triggeredTime: Instant? = null
152155
var expirationTime: Instant? = null
153156
var errorMessage: String? = null
154157
var executionId: String? = null
@@ -173,6 +176,7 @@ data class AlertV2(
173176
TRIGGER_ID_FIELD -> triggerId = xcp.text()
174177
TRIGGER_NAME_FIELD -> triggerName = xcp.text()
175178
QUERY_RESULTS_FIELD -> queryResults = xcp.map()
179+
TRIGGERED_TIME_FIELD -> triggeredTime = xcp.instant()
176180
EXPIRATION_TIME_FIELD -> expirationTime = xcp.instant()
177181
ERROR_MESSAGE_FIELD -> errorMessage = xcp.textOrNull()
178182
EXECUTION_ID_FIELD -> executionId = xcp.textOrNull()
@@ -197,10 +201,10 @@ data class AlertV2(
197201
triggerId = requireNotNull(triggerId),
198202
triggerName = requireNotNull(triggerName),
199203
queryResults = requireNotNull(queryResults),
204+
triggeredTime = requireNotNull(triggeredTime),
200205
expirationTime = expirationTime,
201206
errorMessage = errorMessage,
202207
severity = severity,
203-
actionExecutionResults = actionExecutionResults,
204208
executionId = executionId
205209
)
206210
}

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,5 @@ interface MonitorV2RunResult<out TriggerV2Result : TriggerV2RunResult> : Writeab
6060
}
6161
}
6262
}
63-
64-
@Suppress("UNCHECKED_CAST")
65-
fun suppressWarning(map: MutableMap<String?, Any?>?): Map<String, TriggerV2RunResult> {
66-
return map as Map<String, TriggerV2RunResult>
67-
}
6863
}
6964
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ import java.time.Instant
3232
private val logger = LogManager.getLogger(PPLMonitor::class.java)
3333

3434
// TODO: probably change this to be called PPLSQLMonitor. A PPL Monitor and SQL Monitor
35-
// TODO: would have the exact same functionality, except the choice of language
36-
// TODO: when calling PPL/SQL plugin's execute API would be different.
37-
// TODO: we dont need 2 different monitor types for that, just a simple if check
38-
// TODO: for query language at monitor execution time
35+
// would have the exact same functionality, except the choice of language
36+
// when calling PPL/SQL plugin's execute API would be different.
37+
// we dont need 2 different monitor types for that, just a simple if check
38+
// for query language at monitor execution time
3939
data class PPLMonitor(
4040
override val id: String = NO_ID,
4141
override val version: Long = NO_VERSION,

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

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package org.opensearch.commons.alerting.model
22

3-
import org.opensearch.commons.alerting.alerts.AlertError
43
import org.opensearch.commons.alerting.model.MonitorV2RunResult.Companion.ERROR_FIELD
54
import org.opensearch.commons.alerting.model.MonitorV2RunResult.Companion.MONITOR_NAME_FIELD
65
import org.opensearch.commons.alerting.model.MonitorV2RunResult.Companion.PERIOD_END_FIELD
76
import org.opensearch.commons.alerting.model.MonitorV2RunResult.Companion.PERIOD_START_FIELD
87
import org.opensearch.commons.alerting.model.MonitorV2RunResult.Companion.TRIGGER_RESULTS_FIELD
9-
import org.opensearch.commons.alerting.model.MonitorV2RunResult.Companion.suppressWarning
108
import org.opensearch.commons.alerting.util.nonOptionalTimeField
119
import org.opensearch.core.common.io.stream.StreamInput
1210
import org.opensearch.core.common.io.stream.StreamOutput
@@ -31,8 +29,8 @@ data class PPLMonitorRunResult(
3129
sin.readException(), // error
3230
sin.readInstant(), // periodStart
3331
sin.readInstant(), // periodEnd
34-
suppressWarning(sin.readMap()) as Map<String, PPLTriggerRunResult>, // triggerResults
35-
sin.readMap() as Map<String, Map<String, Any?>> // pplQueryResults // TODO: if this works, delete suppressWarning call above
32+
sin.readMap() as Map<String, PPLTriggerRunResult>, // triggerResults
33+
sin.readMap() as Map<String, Map<String, Any?>> // pplQueryResults
3634
)
3735

3836
override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder {
@@ -57,15 +55,6 @@ data class PPLMonitorRunResult(
5755
out.writeMap(pplQueryResults)
5856
}
5957

60-
// TODO: does this need any PPLMonitor specific logic, or can this just be deleted
61-
override fun alertError(): AlertError? {
62-
if (error != null) {
63-
return AlertError(Instant.now(), "Failed running monitor:\n${error.userErrorMessage()}")
64-
}
65-
66-
return null
67-
}
68-
6958
companion object {
7059
const val PPL_QUERY_RESULTS_FIELD = "ppl_query_results"
7160
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ interface TriggerV2 : BaseModel {
2828

2929
enum class Severity(val value: String) {
3030
INFO("info"),
31+
ERROR("error"),
3132
LOW("low"),
3233
MEDIUM("medium"),
3334
HIGH("high"),

0 commit comments

Comments
 (0)