Skip to content

Commit

Permalink
BWC for rollover skip, restricted index pattern (opensearch-project#371)
Browse files Browse the repository at this point in the history
* BWC for rollover skip, restricted index pattern

Signed-off-by: bowenlan-amzn <[email protected]>

* Remove VisibleForTesting

Signed-off-by: bowenlan-amzn <[email protected]>
  • Loading branch information
bowenlan-amzn authored May 23, 2022
1 parent c93dcd5 commit 948b2c1
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,7 @@ class IndexManagementPlugin : JobSchedulerExtension, NetworkPlugin, ActionPlugin
LegacyOpenDistroManagedIndexSettings.HISTORY_NUMBER_OF_REPLICAS,
LegacyOpenDistroManagedIndexSettings.POLICY_ID,
LegacyOpenDistroManagedIndexSettings.ROLLOVER_ALIAS,
LegacyOpenDistroManagedIndexSettings.ROLLOVER_SKIP,
LegacyOpenDistroManagedIndexSettings.INDEX_STATE_MANAGEMENT_ENABLED,
LegacyOpenDistroManagedIndexSettings.METADATA_SERVICE_ENABLED,
LegacyOpenDistroManagedIndexSettings.JOB_INTERVAL,
Expand All @@ -462,6 +463,7 @@ class IndexManagementPlugin : JobSchedulerExtension, NetworkPlugin, ActionPlugin
LegacyOpenDistroManagedIndexSettings.AUTO_MANAGE,
LegacyOpenDistroManagedIndexSettings.METADATA_SERVICE_STATUS,
LegacyOpenDistroManagedIndexSettings.TEMPLATE_MIGRATION_CONTROL,
LegacyOpenDistroManagedIndexSettings.RESTRICTED_INDEX_PATTERN,
LegacyOpenDistroRollupSettings.ROLLUP_INGEST_BACKOFF_COUNT,
LegacyOpenDistroRollupSettings.ROLLUP_INGEST_BACKOFF_MILLIS,
LegacyOpenDistroRollupSettings.ROLLUP_SEARCH_BACKOFF_COUNT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ fun IndexMetadata.getRolloverAlias(): String? {
}

fun IndexMetadata.getRolloverSkip(): Boolean {
if (this.settings.get(ManagedIndexSettings.ROLLOVER_SKIP.key).isNullOrBlank()) {
return this.settings.getAsBoolean(LegacyOpenDistroManagedIndexSettings.ROLLOVER_SKIP.key, false)
}
return this.settings.getAsBoolean(ManagedIndexSettings.ROLLOVER_SKIP.key, false)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ class LegacyOpenDistroManagedIndexSettings {
Setting.Property.Deprecated
)

val ROLLOVER_SKIP: Setting<Boolean> = Setting.boolSetting(
"index.opendistro.index_state_management.rollover_skip",
false,
Setting.Property.IndexScope,
Setting.Property.Dynamic,
Setting.Property.Deprecated
)

val AUTO_MANAGE: Setting<Boolean> = Setting.boolSetting(
"index.opendistro.index_state_management.auto_manage",
true,
Expand Down Expand Up @@ -191,5 +199,13 @@ class LegacyOpenDistroManagedIndexSettings {
Setting.Property.Dynamic,
Setting.Property.Deprecated
)

val RESTRICTED_INDEX_PATTERN = Setting.simpleString(
"opendistro.index_state_management.restricted_index_pattern",
ManagedIndexSettings.DEFAULT_RESTRICTED_PATTERN,
Setting.Property.NodeScope,
Setting.Property.Dynamic,
Setting.Property.Deprecated
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class ManagedIndexSettings {

val ROLLOVER_SKIP: Setting<Boolean> = Setting.boolSetting(
"index.plugins.index_state_management.rollover_skip",
false,
LegacyOpenDistroManagedIndexSettings.ROLLOVER_SKIP,
Setting.Property.IndexScope,
Setting.Property.Dynamic
)
Expand Down Expand Up @@ -194,7 +194,7 @@ class ManagedIndexSettings {

val RESTRICTED_INDEX_PATTERN = Setting.simpleString(
"plugins.index_state_management.restricted_index_pattern",
DEFAULT_RESTRICTED_PATTERN,
LegacyOpenDistroManagedIndexSettings.RESTRICTED_INDEX_PATTERN,
Setting.Property.NodeScope,
Setting.Property.Dynamic
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ShrinkActio
import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext
import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData
import org.opensearch.indices.InvalidIndexNameException
import org.opensearch.jobscheduler.repackage.com.cronutils.utils.VisibleForTesting
import org.opensearch.jobscheduler.spi.LockModel
import org.opensearch.jobscheduler.spi.utils.LockService
import org.opensearch.script.Script
Expand Down Expand Up @@ -262,7 +261,6 @@ class AttemptMoveShardsStep(private val action: ShrinkAction) : ShrinkStep(name,
/*
* Returns the list of node names for nodes with enough space to shrink to, in increasing order of space available
*/
@VisibleForTesting
@SuppressWarnings("NestedBlockDepth", "ComplexMethod")
private suspend fun findSuitableNodes(
stepContext: StepContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class IndexManagementSettingsTests : OpenSearchTestCase() {
LegacyOpenDistroManagedIndexSettings.HISTORY_NUMBER_OF_REPLICAS,
LegacyOpenDistroManagedIndexSettings.POLICY_ID,
LegacyOpenDistroManagedIndexSettings.ROLLOVER_ALIAS,
LegacyOpenDistroManagedIndexSettings.ROLLOVER_SKIP,
LegacyOpenDistroManagedIndexSettings.INDEX_STATE_MANAGEMENT_ENABLED,
LegacyOpenDistroManagedIndexSettings.METADATA_SERVICE_ENABLED,
LegacyOpenDistroManagedIndexSettings.JOB_INTERVAL,
Expand All @@ -46,6 +47,7 @@ class IndexManagementSettingsTests : OpenSearchTestCase() {
LegacyOpenDistroManagedIndexSettings.COORDINATOR_BACKOFF_MILLIS,
LegacyOpenDistroManagedIndexSettings.ALLOW_LIST,
LegacyOpenDistroManagedIndexSettings.SNAPSHOT_DENY_LIST,
LegacyOpenDistroManagedIndexSettings.RESTRICTED_INDEX_PATTERN,
LegacyOpenDistroRollupSettings.ROLLUP_INGEST_BACKOFF_COUNT,
LegacyOpenDistroRollupSettings.ROLLUP_INGEST_BACKOFF_MILLIS,
LegacyOpenDistroRollupSettings.ROLLUP_SEARCH_BACKOFF_COUNT,
Expand Down Expand Up @@ -110,6 +112,23 @@ class IndexManagementSettingsTests : OpenSearchTestCase() {
assertEquals(LegacyOpenDistroManagedIndexSettings.JOB_INTERVAL.get(settings), 5)
}

fun testIndexSettingLegacyFallback() {
var settings = Settings.builder()
.put("index.opendistro.index_state_management.rollover_skip", true)
.build()
assertEquals(ManagedIndexSettings.ROLLOVER_SKIP.get(settings), true)

settings = Settings.builder()
.put("index.opendistro.index_state_management.rollover_skip", true)
.put("index.plugins.index_state_management.rollover_skip", false)
.build()
assertEquals(ManagedIndexSettings.ROLLOVER_SKIP.get(settings), false)

assertSettingDeprecationsAndWarnings(
arrayOf(LegacyOpenDistroManagedIndexSettings.ROLLOVER_SKIP)
)
}

fun testSettingsGetValueWithLegacyFallback() {
val settings = Settings.builder()
.put("opendistro.index_state_management.enabled", false)
Expand All @@ -127,6 +146,7 @@ class IndexManagementSettingsTests : OpenSearchTestCase() {
.put("opendistro.index_state_management.history.number_of_replicas", 2)
.putList("opendistro.index_state_management.allow_list", listOf("1"))
.putList("opendistro.index_state_management.snapshot.deny_list", listOf("1"))
.put("opendistro.index_state_management.restricted_index_pattern", "blocked_index_pattern")
.put("opendistro.rollup.enabled", false)
.put("opendistro.rollup.search.enabled", false)
.put("opendistro.rollup.ingest.backoff_millis", "1ms")
Expand All @@ -151,6 +171,7 @@ class IndexManagementSettingsTests : OpenSearchTestCase() {
assertEquals(ManagedIndexSettings.HISTORY_NUMBER_OF_REPLICAS.get(settings), 2)
assertEquals(ManagedIndexSettings.ALLOW_LIST.get(settings), listOf("1"))
assertEquals(ManagedIndexSettings.SNAPSHOT_DENY_LIST.get(settings), listOf("1"))
assertEquals(ManagedIndexSettings.RESTRICTED_INDEX_PATTERN.get(settings), "blocked_index_pattern")
assertEquals(RollupSettings.ROLLUP_ENABLED.get(settings), false)
assertEquals(RollupSettings.ROLLUP_SEARCH_ENABLED.get(settings), false)
assertEquals(RollupSettings.ROLLUP_SEARCH_ALL_JOBS.get(settings), false)
Expand All @@ -177,6 +198,7 @@ class IndexManagementSettingsTests : OpenSearchTestCase() {
LegacyOpenDistroManagedIndexSettings.HISTORY_NUMBER_OF_REPLICAS,
LegacyOpenDistroManagedIndexSettings.ALLOW_LIST,
LegacyOpenDistroManagedIndexSettings.SNAPSHOT_DENY_LIST,
LegacyOpenDistroManagedIndexSettings.RESTRICTED_INDEX_PATTERN,
LegacyOpenDistroRollupSettings.ROLLUP_ENABLED,
LegacyOpenDistroRollupSettings.ROLLUP_SEARCH_ENABLED,
LegacyOpenDistroRollupSettings.ROLLUP_INGEST_BACKOFF_MILLIS,
Expand Down

0 comments on commit 948b2c1

Please sign in to comment.