Skip to content

Commit

Permalink
Fixing DataSources Parsing Errors (#678)
Browse files Browse the repository at this point in the history
* attempt to fix DataSources breaking change

Signed-off-by: Dennis Toepker <[email protected]>

* adding default comments index values instead of passing null into constructor

Signed-off-by: Dennis Toepker <[email protected]>

---------

Signed-off-by: Dennis Toepker <[email protected]>
Co-authored-by: Dennis Toepker <[email protected]>
  • Loading branch information
toepkerd and toepkerd-zz authored Jun 11, 2024
1 parent 5c4e828 commit f4b2e1b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ data class DataSources(
val alertsHistoryIndexPattern: String? = "<.opendistro-alerting-alert-history-{now/d}-1>", // AlertIndices.ALERT_HISTORY_INDEX_PATTERN

/** Configures a custom index alias to store comments associated with alerts.*/
val commentsIndex: String? = ".opensearch-alerting-comments-history-write", // CommentsIndices.COMMENTS_HISTORY_WRITE_INDEX
val commentsIndex: String? = DEFAULT_COMMENTS_INDEX, // CommentsIndices.COMMENTS_HISTORY_WRITE_INDEX

/** Configures a custom index pattern for commentsIndex alias.*/
val commentsIndexPattern: String? = "<.opensearch-alerting-comments-history-{now/d}-1>", // CommentsIndices.COMMENTS_HISTORY_INDEX_PATTERN
val commentsIndexPattern: String? = DEFAULT_COMMENTS_INDEX_PATTERN, // CommentsIndices.COMMENTS_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. */
Expand Down Expand Up @@ -102,8 +102,8 @@ data class DataSources(
alertsIndex = alertsIndex,
alertsHistoryIndex = alertsHistoryIndex,
alertsHistoryIndexPattern = alertsHistoryIndexPattern,
commentsIndex = null,
commentsIndexPattern = null,
commentsIndex = DEFAULT_COMMENTS_INDEX,
commentsIndexPattern = DEFAULT_COMMENTS_INDEX_PATTERN,
queryIndexMappingsByType = queryIndexMappingsByType,
findingsEnabled = findingsEnabled
)
Expand Down Expand Up @@ -152,6 +152,9 @@ data class DataSources(
const val QUERY_INDEX_MAPPINGS_BY_TYPE = "query_index_mappings_by_type"
const val FINDINGS_ENABLED_FIELD = "findings_enabled"

const val DEFAULT_COMMENTS_INDEX = ".opensearch-alerting-comments-history-write"
const val DEFAULT_COMMENTS_INDEX_PATTERN = "<.opensearch-alerting-comments-history-{now/d}-1>"

@JvmStatic
@Throws(IOException::class)
@Suppress("UNCHECKED_CAST")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -574,4 +574,23 @@ class XContentTests {
val parsedDocLevelMonitorInput = parsedRemoteDocLevelMonitorInput.docLevelMonitorInput
assertEquals("Round tripping RemoteDocLevelMonitorInput doesn't work", docLevelMonitorInput, parsedDocLevelMonitorInput)
}

@Test
fun `test DataSources parsing`() {
val dataSources = DataSources(
ScheduledJob.DOC_LEVEL_QUERIES_INDEX,
".opensearch-alerting-finding-history-write",
"<.opensearch-alerting-finding-history-{now/d}-1>",
".opendistro-alerting-alerts",
".opendistro-alerting-alert-history-write",
"<.opendistro-alerting-alert-history-{now/d}-1>",
mapOf(),
false
)
Assertions.assertNotNull(dataSources)

val dataSourcesString = dataSources.toXContent(builder(), ToXContent.EMPTY_PARAMS).string()
val parsedDataSources = DataSources.parse(parser(dataSourcesString))
Assertions.assertEquals(dataSources, parsedDataSources, "Round tripping DataSources doesn't work")
}
}

0 comments on commit f4b2e1b

Please sign in to comment.