Skip to content

Commit

Permalink
Fixing DataSources Parsing Errors (#678) (#681)
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]>
(cherry picked from commit f4b2e1b)

Signed-off-by: toepkerd <[email protected]>
  • Loading branch information
toepkerd authored Jun 12, 2024
1 parent bdf32b2 commit dd9fdf1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ 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 +103,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 +153,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 @@ -506,4 +506,23 @@ class XContentTests {

assertEquals("Round tripping alert doesn't work", actionExecutionResult, parsedActionExecutionResultString)
}

@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 dd9fdf1

Please sign in to comment.