Skip to content

Commit

Permalink
move fanoutEnabled to docLevel input
Browse files Browse the repository at this point in the history
Signed-off-by: Riya Saxena <[email protected]>
  • Loading branch information
riysaxen-amzn committed Dec 17, 2024
1 parent c865b09 commit ab7ce61
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@ import java.io.IOException
data class DocLevelMonitorInput(
val description: String = NO_DESCRIPTION,
val indices: List<String>,
val queries: List<DocLevelQuery>
val queries: List<DocLevelQuery>,
val fanoutEnabled: Boolean? = true
) : Input {

@Throws(IOException::class)
constructor(sin: StreamInput) : this(
sin.readString(), // description
sin.readStringList(), // indices
sin.readList(::DocLevelQuery) // docLevelQueries
sin.readList(::DocLevelQuery), // docLevelQueries
sin.readOptionalBoolean(), // fanoutEnabled
)

override fun asTemplateArg(): Map<String, Any> {
Expand All @@ -41,6 +43,7 @@ data class DocLevelMonitorInput(
out.writeString(description)
out.writeStringCollection(indices)
out.writeCollection(queries)
out.writeOptionalBoolean(fanoutEnabled)
}

override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder {
Expand All @@ -49,6 +52,7 @@ data class DocLevelMonitorInput(
.field(DESCRIPTION_FIELD, description)
.field(INDICES_FIELD, indices.toTypedArray())
.field(QUERIES_FIELD, queries.toTypedArray())
.field(FANOUT_FIELD, fanoutEnabled)
.endObject()
.endObject()
return builder
Expand All @@ -59,7 +63,7 @@ data class DocLevelMonitorInput(
const val INDICES_FIELD = "indices"
const val DOC_LEVEL_INPUT_FIELD = "doc_level_input"
const val QUERIES_FIELD = "queries"

const val FANOUT_FIELD = "fan_out_enabled"
const val NO_DESCRIPTION = ""

val XCONTENT_REGISTRY = NamedXContentRegistry.Entry(
Expand All @@ -74,6 +78,7 @@ data class DocLevelMonitorInput(
var description: String = NO_DESCRIPTION
val indices: MutableList<String> = mutableListOf()
val docLevelQueries: MutableList<DocLevelQuery> = mutableListOf()
var fanoutEnabled: Boolean? = true

XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.currentToken(), xcp)
while (xcp.nextToken() != XContentParser.Token.END_OBJECT) {
Expand Down Expand Up @@ -102,10 +107,15 @@ data class DocLevelMonitorInput(
docLevelQueries.add(DocLevelQuery.parse(xcp))
}
}
FANOUT_FIELD -> fanoutEnabled = if (xcp.currentToken() == XContentParser.Token.VALUE_NULL) {
fanoutEnabled
} else {
xcp.booleanValue()
}
}
}

return DocLevelMonitorInput(description = description, indices = indices, queries = docLevelQueries)
return DocLevelMonitorInput(description = description, indices = indices, queries = docLevelQueries, fanoutEnabled = fanoutEnabled)
}

@JvmStatic
Expand Down
12 changes: 0 additions & 12 deletions src/main/kotlin/org/opensearch/commons/alerting/model/Monitor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ data class Monitor(
val deleteQueryIndexInEveryRun: Boolean? = false,
val shouldCreateSingleAlertForFindings: Boolean? = false,
val owner: String? = "alerting",
val fanoutEnabled: Boolean? = true
) : ScheduledJob {

override val type = MONITOR_TYPE
Expand Down Expand Up @@ -115,7 +114,6 @@ data class Monitor(
},
deleteQueryIndexInEveryRun = sin.readOptionalBoolean(),
shouldCreateSingleAlertForFindings = sin.readOptionalBoolean(),
fanoutEnabled = sin.readOptionalBoolean(),
owner = sin.readOptionalString()
)

Expand Down Expand Up @@ -177,7 +175,6 @@ data class Monitor(
builder.field(DATA_SOURCES_FIELD, dataSources)
builder.field(DELETE_QUERY_INDEX_IN_EVERY_RUN_FIELD, deleteQueryIndexInEveryRun)
builder.field(SHOULD_CREATE_SINGLE_ALERT_FOR_FINDINGS_FIELD, shouldCreateSingleAlertForFindings)
builder.field(FAN_OUT_ENABLED_FIELD, fanoutEnabled)
builder.field(OWNER_FIELD, owner)
if (params.paramAsBoolean("with_type", false)) builder.endObject()
return builder.endObject()
Expand Down Expand Up @@ -231,7 +228,6 @@ data class Monitor(
dataSources.writeTo(out)
out.writeOptionalBoolean(deleteQueryIndexInEveryRun)
out.writeOptionalBoolean(shouldCreateSingleAlertForFindings)
out.writeOptionalBoolean(fanoutEnabled)
out.writeOptionalString(owner)
}

Expand All @@ -254,7 +250,6 @@ data class Monitor(
const val ENABLED_TIME_FIELD = "enabled_time"
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 FAN_OUT_ENABLED_FIELD = "fan_out_enabled"
const val OWNER_FIELD = "owner"
val MONITOR_TYPE_PATTERN = Pattern.compile("[a-zA-Z0-9_]{5,25}")

Expand Down Expand Up @@ -286,7 +281,6 @@ data class Monitor(
var deleteQueryIndexInEveryRun = false
var delegateMonitor = false
var owner = "alerting"
var fanoutEnabled = true

XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.currentToken(), xcp)
while (xcp.nextToken() != XContentParser.Token.END_OBJECT) {
Expand Down Expand Up @@ -349,11 +343,6 @@ data class Monitor(
} else {
xcp.booleanValue()
}
FAN_OUT_ENABLED_FIELD -> fanoutEnabled = if (xcp.currentToken() == XContentParser.Token.VALUE_NULL) {
fanoutEnabled
} else {
xcp.booleanValue()
}
OWNER_FIELD -> owner = if (xcp.currentToken() == XContentParser.Token.VALUE_NULL) owner else xcp.text()
else -> {
xcp.skipChildren()
Expand Down Expand Up @@ -384,7 +373,6 @@ data class Monitor(
deleteQueryIndexInEveryRun,
delegateMonitor,
owner,
fanoutEnabled
)
}

Expand Down

0 comments on commit ab7ce61

Please sign in to comment.