Skip to content

Commit

Permalink
Add targetIndexSettings validation with test
Browse files Browse the repository at this point in the history
Signed-off-by: Aleksandr Tuliakov <tulyakov93@gmail.com>
  • Loading branch information
MrChaos1993 committed Feb 18, 2025
1 parent 6eed372 commit e08fb88
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package org.opensearch.indexmanagement.rollup.model

import org.opensearch.common.settings.IndexScopedSettings
import org.opensearch.common.settings.Settings
import org.opensearch.commons.authuser.User
import org.opensearch.core.common.io.stream.StreamInput
Expand Down Expand Up @@ -89,6 +90,9 @@ data class Rollup(
}
}
require(sourceIndex != targetIndex) { "Your source and target index cannot be the same" }
if (targetIndexSettings != null) {
IndexScopedSettings(null, IndexScopedSettings.BUILT_IN_INDEX_SETTINGS).validate(targetIndexSettings, true)
}
require(dimensions.filter { it.type == Dimension.Type.DATE_HISTOGRAM }.size == 1) {
"Must specify precisely one date histogram dimension" // this covers empty dimensions case too
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

package org.opensearch.indexmanagement.rollup.model

import org.opensearch.common.settings.Settings
import org.opensearch.common.settings.SettingsException
import org.opensearch.indexmanagement.randomInstant
import org.opensearch.indexmanagement.randomSchedule
import org.opensearch.indexmanagement.rollup.randomDateHistogram
Expand Down Expand Up @@ -52,6 +54,16 @@ class RollupTests : OpenSearchTestCase() {
}
}

fun `test rollup requires correct target index settings`() {
assertFailsWith(SettingsException::class, "Unknown property was `index.codec1`") {
randomRollup().copy(targetIndexSettings = Settings.builder().put("index.codec1", "zlib").build())
}

val sb = Settings.builder()
sb.put("index.codec", "zlib")
randomRollup().copy(targetIndexSettings = sb.build())
}

fun `test rollup requires page size to be between 1 and 10k`() {
assertFailsWith(IllegalArgumentException::class, "Page size was negative") {
randomRollup().copy(pageSize = -1)
Expand Down

0 comments on commit e08fb88

Please sign in to comment.