Skip to content

Commit 67fda10

Browse files
authored
add findings enabled flag and findings field in bucket level monitor alerts constructor (#305)
Signed-off-by: Surya Sashank Nistala <snistala@amazon.com> Signed-off-by: Surya Sashank Nistala <snistala@amazon.com>
1 parent 6a169f7 commit 67fda10

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,14 @@ data class Alert(
7474
errorMessage: String? = null,
7575
errorHistory: List<AlertError> = mutableListOf(),
7676
actionExecutionResults: List<ActionExecutionResult> = mutableListOf(),
77-
schemaVersion: Int = NO_SCHEMA_VERSION
77+
schemaVersion: Int = NO_SCHEMA_VERSION,
78+
findingIds: List<String> = emptyList()
7879
) : this(
7980
monitorId = monitor.id, monitorName = monitor.name, monitorVersion = monitor.version, monitorUser = monitor.user,
8081
triggerId = trigger.id, triggerName = trigger.name, state = state, startTime = startTime,
8182
lastNotificationTime = lastNotificationTime, errorMessage = errorMessage, errorHistory = errorHistory,
8283
severity = trigger.severity, actionExecutionResults = actionExecutionResults, schemaVersion = schemaVersion,
83-
aggregationResultBucket = null, findingIds = emptyList(), relatedDocIds = emptyList()
84+
aggregationResultBucket = null, findingIds = findingIds, relatedDocIds = emptyList()
8485
)
8586

8687
constructor(
@@ -93,13 +94,14 @@ data class Alert(
9394
errorHistory: List<AlertError> = mutableListOf(),
9495
actionExecutionResults: List<ActionExecutionResult> = mutableListOf(),
9596
schemaVersion: Int = NO_SCHEMA_VERSION,
96-
aggregationResultBucket: AggregationResultBucket
97+
aggregationResultBucket: AggregationResultBucket,
98+
findingIds: List<String> = emptyList()
9799
) : this(
98100
monitorId = monitor.id, monitorName = monitor.name, monitorVersion = monitor.version, monitorUser = monitor.user,
99101
triggerId = trigger.id, triggerName = trigger.name, state = state, startTime = startTime,
100102
lastNotificationTime = lastNotificationTime, errorMessage = errorMessage, errorHistory = errorHistory,
101103
severity = trigger.severity, actionExecutionResults = actionExecutionResults, schemaVersion = schemaVersion,
102-
aggregationResultBucket = aggregationResultBucket, findingIds = emptyList(), relatedDocIds = emptyList()
104+
aggregationResultBucket = aggregationResultBucket, findingIds = findingIds, relatedDocIds = emptyList()
103105
)
104106

105107
constructor(

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ data class DataSources(
3333

3434
/** Configures custom mappings by field type for query index.
3535
* Custom query index mappings are configurable, only if a custom query index is configured too. */
36-
val queryIndexMappingsByType: Map<String, Map<String, String>> = mapOf()
36+
val queryIndexMappingsByType: Map<String, Map<String, String>> = mapOf(),
37+
38+
/** Configures flag to enable or disable creating and storing findings. */
39+
val findingsEnabled: Boolean? = false
3740

3841
) : Writeable, ToXContentObject {
3942

@@ -71,7 +74,8 @@ data class DataSources(
7174
alertsIndex = sin.readString(),
7275
alertsHistoryIndex = sin.readOptionalString(),
7376
alertsHistoryIndexPattern = sin.readOptionalString(),
74-
queryIndexMappingsByType = sin.readMap() as Map<String, Map<String, String>>
77+
queryIndexMappingsByType = sin.readMap() as Map<String, Map<String, String>>,
78+
findingsEnabled = sin.readOptionalBoolean()
7579
)
7680

7781
@Suppress("UNCHECKED_CAST")
@@ -83,7 +87,8 @@ data class DataSources(
8387
ALERTS_INDEX_FIELD to alertsIndex,
8488
ALERTS_HISTORY_INDEX_FIELD to alertsHistoryIndex,
8589
ALERTS_HISTORY_INDEX_PATTERN_FIELD to alertsHistoryIndexPattern,
86-
QUERY_INDEX_MAPPINGS_BY_TYPE to queryIndexMappingsByType
90+
QUERY_INDEX_MAPPINGS_BY_TYPE to queryIndexMappingsByType,
91+
FINDINGS_ENABLED_FIELD to findingsEnabled,
8792
)
8893
}
8994

@@ -96,6 +101,7 @@ data class DataSources(
96101
builder.field(ALERTS_HISTORY_INDEX_FIELD, alertsHistoryIndex)
97102
builder.field(ALERTS_HISTORY_INDEX_PATTERN_FIELD, alertsHistoryIndexPattern)
98103
builder.field(QUERY_INDEX_MAPPINGS_BY_TYPE, queryIndexMappingsByType as Map<String, Any>)
104+
builder.field(FINDINGS_ENABLED_FIELD, findingsEnabled)
99105
builder.endObject()
100106
return builder
101107
}
@@ -108,6 +114,7 @@ data class DataSources(
108114
const val ALERTS_HISTORY_INDEX_FIELD = "alerts_history_index"
109115
const val ALERTS_HISTORY_INDEX_PATTERN_FIELD = "alerts_history_index_pattern"
110116
const val QUERY_INDEX_MAPPINGS_BY_TYPE = "query_index_mappings_by_type"
117+
const val FINDINGS_ENABLED_FIELD = "findings_enabled"
111118

112119
@JvmStatic
113120
@Throws(IOException::class)
@@ -120,6 +127,7 @@ data class DataSources(
120127
var alertsHistoryIndex = ""
121128
var alertsHistoryIndexPattern = ""
122129
var queryIndexMappingsByType: Map<String, Map<String, String>> = mapOf()
130+
var findingsEnabled = false
123131

124132
XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.currentToken(), xcp)
125133
while (xcp.nextToken() != XContentParser.Token.END_OBJECT) {
@@ -134,6 +142,7 @@ data class DataSources(
134142
ALERTS_HISTORY_INDEX_FIELD -> alertsHistoryIndex = xcp.text()
135143
ALERTS_HISTORY_INDEX_PATTERN_FIELD -> alertsHistoryIndexPattern = xcp.text()
136144
QUERY_INDEX_MAPPINGS_BY_TYPE -> queryIndexMappingsByType = xcp.map() as Map<String, Map<String, String>>
145+
FINDINGS_ENABLED_FIELD -> findingsEnabled = xcp.booleanValue()
137146
}
138147
}
139148
return DataSources(
@@ -143,7 +152,8 @@ data class DataSources(
143152
alertsIndex = alertsIndex,
144153
alertsHistoryIndex = alertsHistoryIndex,
145154
alertsHistoryIndexPattern = alertsHistoryIndexPattern,
146-
queryIndexMappingsByType = queryIndexMappingsByType
155+
queryIndexMappingsByType = queryIndexMappingsByType,
156+
findingsEnabled = findingsEnabled
147157
)
148158
}
149159
}
@@ -157,5 +167,6 @@ data class DataSources(
157167
out.writeOptionalString(alertsHistoryIndex)
158168
out.writeOptionalString(alertsHistoryIndexPattern)
159169
out.writeMap(queryIndexMappingsByType as Map<String, Any>)
170+
out.writeOptionalBoolean(findingsEnabled)
160171
}
161172
}

0 commit comments

Comments
 (0)