Skip to content
Merged
Show file tree
Hide file tree
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
41 changes: 8 additions & 33 deletions src/main/kotlin/org/opensearch/commons/alerting/model/Alert.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.opensearch.commons.alerting.model

import org.opensearch.Version
import org.opensearch.common.lucene.uid.Versions
import org.opensearch.commons.alerting.alerts.AlertError
import org.opensearch.commons.alerting.util.IndexUtils.Companion.NO_SCHEMA_VERSION
Expand Down Expand Up @@ -44,8 +43,7 @@ data class Alert(
val aggregationResultBucket: AggregationResultBucket? = null,
val executionId: String? = null,
val associatedAlertIds: List<String>,
val clusters: List<String>? = null,
val target: Target? = null
val clusters: List<String>? = null
) : Writeable, ToXContent {

init {
Expand Down Expand Up @@ -127,8 +125,7 @@ data class Alert(
workflowId = workflowId ?: "",
workflowName = "",
associatedAlertIds = emptyList(),
clusters = clusters,
target = monitor.target
clusters = clusters
)

constructor(
Expand Down Expand Up @@ -167,8 +164,7 @@ data class Alert(
workflowId = workflowId ?: "",
workflowName = "",
associatedAlertIds = emptyList(),
clusters = clusters,
target = monitor.target
clusters = clusters
)

constructor(
Expand Down Expand Up @@ -208,8 +204,7 @@ data class Alert(
workflowId = workflowId ?: "",
workflowName = "",
associatedAlertIds = emptyList(),
clusters = clusters,
target = monitor.target
clusters = clusters
)

constructor(
Expand Down Expand Up @@ -251,8 +246,7 @@ data class Alert(
workflowId = workflowId ?: "",
workflowName = "",
associatedAlertIds = emptyList(),
clusters = clusters,
target = monitor.target
clusters = clusters
)

constructor(
Expand Down Expand Up @@ -291,8 +285,7 @@ data class Alert(
workflowId = workflowId ?: "",
executionId = executionId,
associatedAlertIds = emptyList(),
clusters = clusters,
target = monitor.target
clusters = clusters
)

enum class State {
Expand Down Expand Up @@ -336,12 +329,7 @@ data class Alert(
aggregationResultBucket = if (sin.readBoolean()) AggregationResultBucket(sin) else null,
executionId = sin.readOptionalString(),
associatedAlertIds = sin.readStringList(),
clusters = sin.readOptionalStringList(),
target = if (sin.version.onOrAfter(Version.V_3_6_0)) {
if (sin.readBoolean()) Target(sin) else null
} else {
null
}
clusters = sin.readOptionalStringList()
)

fun isAcknowledged(): Boolean = (state == State.ACKNOWLEDGED)
Expand Down Expand Up @@ -380,10 +368,6 @@ data class Alert(
out.writeOptionalString(executionId)
out.writeStringCollection(associatedAlertIds)
out.writeOptionalStringArray(clusters?.toTypedArray())
if (out.version.onOrAfter(Version.V_3_6_0)) {
out.writeBoolean(target != null)
target?.writeTo(out)
}
}

companion object {
Expand Down Expand Up @@ -415,7 +399,6 @@ data class Alert(
const val BUCKET_KEYS = AggregationResultBucket.BUCKET_KEYS
const val PARENTS_BUCKET_PATH = AggregationResultBucket.PARENTS_BUCKET_PATH
const val CLUSTERS_FIELD = "clusters"
const val TARGET_FIELD = "target"
const val NO_ID = ""
const val NO_VERSION = Versions.NOT_FOUND

Expand Down Expand Up @@ -447,7 +430,6 @@ data class Alert(
var aggAlertBucket: AggregationResultBucket? = null
val associatedAlertIds = mutableListOf<String>()
val clusters = mutableListOf<String>()
var target: Target? = null
ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.currentToken(), xcp)
while (xcp.nextToken() != XContentParser.Token.END_OBJECT) {
val fieldName = xcp.currentName()
Expand Down Expand Up @@ -523,11 +505,6 @@ data class Alert(
clusters.add(xcp.text())
}
}
TARGET_FIELD -> target = if (xcp.currentToken() == XContentParser.Token.VALUE_NULL) {
null
} else {
Target.parse(xcp)
}
}
}

Expand Down Expand Up @@ -557,8 +534,7 @@ data class Alert(
workflowId = workflowId,
workflowName = workflowName,
associatedAlertIds = associatedAlertIds,
clusters = if (clusters.size > 0) clusters else null,
target = target
clusters = if (clusters.size > 0) clusters else null
)
}

Expand Down Expand Up @@ -610,7 +586,6 @@ data class Alert(
aggregationResultBucket?.innerXContent(builder)

if (!clusters.isNullOrEmpty()) builder.field(CLUSTERS_FIELD, clusters.toTypedArray())
if (target != null) builder.field(TARGET_FIELD, target)

builder.endObject()
return builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ data class Monitor(
val dataSources: DataSources = DataSources(),
val deleteQueryIndexInEveryRun: Boolean? = false,
val shouldCreateSingleAlertForFindings: Boolean? = false,
val owner: String? = "alerting",
val target: Target? = null
val owner: String? = "alerting"
) : ScheduledJob {

override val type = MONITOR_TYPE
Expand Down Expand Up @@ -122,12 +121,7 @@ data class Monitor(
} else {
false
},
owner = sin.readOptionalString(),
target = if (sin.version.onOrAfter(Version.V_3_6_0)) {
if (sin.readBoolean()) Target(sin) else null
} else {
null
}
owner = sin.readOptionalString()
)

// This enum classifies different Monitors
Expand Down Expand Up @@ -189,7 +183,6 @@ data class Monitor(
builder.field(DELETE_QUERY_INDEX_IN_EVERY_RUN_FIELD, deleteQueryIndexInEveryRun)
builder.field(SHOULD_CREATE_SINGLE_ALERT_FOR_FINDINGS_FIELD, shouldCreateSingleAlertForFindings)
builder.field(OWNER_FIELD, owner)
if (target != null) builder.field(TARGET_FIELD, target)
if (params.paramAsBoolean("with_type", false)) builder.endObject()
return builder.endObject()
}
Expand Down Expand Up @@ -247,10 +240,6 @@ data class Monitor(
out.writeOptionalBoolean(shouldCreateSingleAlertForFindings)
}
out.writeOptionalString(owner)
if (out.version.onOrAfter(Version.V_3_6_0)) {
out.writeBoolean(target != null)
target?.writeTo(out)
}
}

companion object {
Expand All @@ -273,7 +262,6 @@ data class Monitor(
const val DELETE_QUERY_INDEX_IN_EVERY_RUN_FIELD = "delete_query_index_in_every_run"
const val SHOULD_CREATE_SINGLE_ALERT_FOR_FINDINGS_FIELD = "should_create_single_alert_for_findings"
const val OWNER_FIELD = "owner"
const val TARGET_FIELD = "target"
val MONITOR_TYPE_PATTERN = Pattern.compile("[a-zA-Z0-9_]{5,25}")

// This is defined here instead of in ScheduledJob to avoid having the ScheduledJob class know about all
Expand Down Expand Up @@ -304,7 +292,6 @@ data class Monitor(
var deleteQueryIndexInEveryRun = false
var delegateMonitor = false
var owner = "alerting"
var target: Target? = null

XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.currentToken(), xcp)
while (xcp.nextToken() != XContentParser.Token.END_OBJECT) {
Expand Down Expand Up @@ -368,11 +355,6 @@ data class Monitor(
xcp.booleanValue()
}
OWNER_FIELD -> owner = if (xcp.currentToken() == XContentParser.Token.VALUE_NULL) owner else xcp.text()
TARGET_FIELD -> target = if (xcp.currentToken() == XContentParser.Token.VALUE_NULL) {
target
} else {
Target.parse(xcp)
}
else -> {
xcp.skipChildren()
}
Expand Down Expand Up @@ -401,8 +383,7 @@ data class Monitor(
dataSources,
deleteQueryIndexInEveryRun,
delegateMonitor,
owner,
target
owner
)
}

Expand Down
77 changes: 0 additions & 77 deletions src/main/kotlin/org/opensearch/commons/alerting/model/Target.kt

This file was deleted.

This file was deleted.

Loading
Loading