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

Fixing DataSources Parsing Errors #678

Merged
merged 2 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
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 @@ -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")
}
}
Loading