diff --git a/src/main/kotlin/org/opensearch/commons/alerting/model/DataSources.kt b/src/main/kotlin/org/opensearch/commons/alerting/model/DataSources.kt index 110cf36f..7757a0b3 100644 --- a/src/main/kotlin/org/opensearch/commons/alerting/model/DataSources.kt +++ b/src/main/kotlin/org/opensearch/commons/alerting/model/DataSources.kt @@ -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. */ @@ -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 ) @@ -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") diff --git a/src/test/kotlin/org/opensearch/commons/alerting/model/XContentTests.kt b/src/test/kotlin/org/opensearch/commons/alerting/model/XContentTests.kt index ffb76105..3ce1f041 100644 --- a/src/test/kotlin/org/opensearch/commons/alerting/model/XContentTests.kt +++ b/src/test/kotlin/org/opensearch/commons/alerting/model/XContentTests.kt @@ -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") + } }