Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added params to Datasources #290

Merged
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,19 @@ data class DataSources(
* If index is pre-existing, mapping is updated*/
val findingsIndex: String = ".opensearch-alerting-finding-history-write", // AlertIndices.FINDING_HISTORY_WRITE_INDEX

/** Configures a custom index pattern for findingsIndex alias.*/
val findingsIndexPattern: String? = "<.opensearch-alerting-finding-history-{now/d}-1>", // AlertIndices.FINDING_HISTORY_INDEX_PATTERN

/** Configures a custom index to store alerts for a monitor. Creates a new index if index with given name not present.
* If index is pre-existing, mapping is updated. */
val alertsIndex: String = ".opendistro-alerting-alerts", // AlertIndices.ALERT_INDEX

/** Configures a custom index alias to store historic alerts for a monitor.*/
val alertsHistoryIndex: String? = ".opendistro-alerting-alert-history-write", // AlertIndices.ALERT_HISTORY_WRITE_INDEX

/** Configures a custom index pattern for alertHistoryIndex alias.*/
val alertsHistoryIndexPattern: String? = "<.opendistro-alerting-alert-history-{now/d}-1>", // AlertIndices.ALERT_HISTORY_INDEX_PATTERN

/** Configures custom mappings by field type for query index.
* Custom query index mappings are configurable, only if a custom query index is configured too. */
val queryIndexMappingsByType: Map<String, Map<String, String>> = mapOf()
Expand Down Expand Up @@ -58,16 +67,22 @@ data class DataSources(
constructor(sin: StreamInput) : this(
queryIndex = sin.readString(),
findingsIndex = sin.readString(),
findingsIndexPattern = sin.readOptionalString(),
alertsIndex = sin.readString(),
alertsHistoryIndex = sin.readOptionalString(),
alertsHistoryIndexPattern = sin.readOptionalString(),
queryIndexMappingsByType = sin.readMap() as Map<String, Map<String, String>>
)

@Suppress("UNCHECKED_CAST")
fun asTemplateArg(): Map<String, Any> {
fun asTemplateArg(): Map<String, Any?> {
return mapOf(
QUERY_INDEX_FIELD to queryIndex,
FINDINGS_INDEX_FIELD to findingsIndex,
FINDINGS_INDEX_PATTERN_FIELD to findingsIndexPattern,
ALERTS_INDEX_FIELD to alertsIndex,
ALERTS_HISTORY_INDEX_FIELD to alertsHistoryIndex,
ALERTS_HISTORY_INDEX_PATTERN_FIELD to alertsHistoryIndexPattern,
QUERY_INDEX_MAPPINGS_BY_TYPE to queryIndexMappingsByType
)
}
Expand All @@ -76,7 +91,10 @@ data class DataSources(
builder.startObject()
builder.field(QUERY_INDEX_FIELD, queryIndex)
builder.field(FINDINGS_INDEX_FIELD, findingsIndex)
builder.field(FINDINGS_INDEX_PATTERN_FIELD, findingsIndexPattern)
builder.field(ALERTS_INDEX_FIELD, alertsIndex)
builder.field(ALERTS_HISTORY_INDEX_FIELD, alertsHistoryIndex)
builder.field(ALERTS_HISTORY_INDEX_PATTERN_FIELD, alertsHistoryIndexPattern)
builder.field(QUERY_INDEX_MAPPINGS_BY_TYPE, queryIndexMappingsByType as Map<String, Any>)
builder.endObject()
return builder
Expand All @@ -85,7 +103,10 @@ data class DataSources(
companion object {
const val QUERY_INDEX_FIELD = "query_index"
const val FINDINGS_INDEX_FIELD = "findings_index"
const val FINDINGS_INDEX_PATTERN_FIELD = "findings_index_pattern"
const val ALERTS_INDEX_FIELD = "alerts_index"
const val ALERTS_HISTORY_INDEX_FIELD = "alerts_history_index"
const val ALERTS_HISTORY_INDEX_PATTERN_FIELD = "alerts_history_index_pattern"
const val QUERY_INDEX_MAPPINGS_BY_TYPE = "query_index_mappings_by_type"

@JvmStatic
Expand All @@ -94,7 +115,10 @@ data class DataSources(
fun parse(xcp: XContentParser): DataSources {
var queryIndex = ""
var findingsIndex = ""
var findingsIndexPattern = ""
var alertsIndex = ""
var alertsHistoryIndex = ""
var alertsHistoryIndexPattern = ""
var queryIndexMappingsByType: Map<String, Map<String, String>> = mapOf()

XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.currentToken(), xcp)
Expand All @@ -105,14 +129,20 @@ data class DataSources(
when (fieldName) {
QUERY_INDEX_FIELD -> queryIndex = xcp.text()
FINDINGS_INDEX_FIELD -> findingsIndex = xcp.text()
FINDINGS_INDEX_PATTERN_FIELD -> findingsIndexPattern = xcp.text()
ALERTS_INDEX_FIELD -> alertsIndex = xcp.text()
ALERTS_HISTORY_INDEX_FIELD -> alertsHistoryIndex = xcp.text()
ALERTS_HISTORY_INDEX_PATTERN_FIELD -> alertsHistoryIndexPattern = xcp.text()
QUERY_INDEX_MAPPINGS_BY_TYPE -> queryIndexMappingsByType = xcp.map() as Map<String, Map<String, String>>
}
}
return DataSources(
queryIndex = queryIndex,
findingsIndex = findingsIndex,
findingsIndexPattern = findingsIndexPattern,
alertsIndex = alertsIndex,
alertsHistoryIndex = alertsHistoryIndex,
alertsHistoryIndexPattern = alertsHistoryIndexPattern,
queryIndexMappingsByType = queryIndexMappingsByType
)
}
Expand All @@ -122,7 +152,10 @@ data class DataSources(
override fun writeTo(out: StreamOutput) {
out.writeString(queryIndex)
out.writeString(findingsIndex)
out.writeOptionalString(findingsIndexPattern)
out.writeString(alertsIndex)
out.writeOptionalString(alertsHistoryIndex)
out.writeOptionalString(alertsHistoryIndexPattern)
out.writeMap(queryIndexMappingsByType as Map<String, Any>)
}
}