-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds the replication type index setting, alongside a formal notion of…
… feature flags (#3037) (#3071) * This change formalizes the notion of feature flags, and adds a "replication type" setting that will differentiate between document and segment replication, gated by a feature flag. Since seg-rep is currently an incomplete implementation, the feature flag ensures that the setting is not visible to users without explicitly setting a system property. We can then continue to merge seg-rep related changes from the feature branch to `main` safely hidden behind the feature flag gate. Signed-off-by: Kartik Ganesh <[email protected]> * Update security policy for testing feature flags Signed-off-by: Nicholas Walter Knize <[email protected]> Co-authored-by: Nicholas Walter Knize <[email protected]> (cherry picked from commit ee7b731) Co-authored-by: Kartik Ganesh <[email protected]>
- Loading branch information
1 parent
ddeb94c
commit e5a70db
Showing
8 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
server/src/main/java/org/opensearch/common/util/FeatureFlags.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.common.util; | ||
|
||
/** | ||
* Utility class to manage feature flags. Feature flags are system properties that must be set on the JVM. | ||
* These are used to gate the visibility/availability of incomplete features. Fore more information, see | ||
* https://featureflags.io/feature-flag-introduction/ | ||
*/ | ||
public class FeatureFlags { | ||
|
||
/** | ||
* Gates the visibility of the index setting that allows changing of replication type. | ||
* Once the feature is ready for production release, this feature flag can be removed. | ||
*/ | ||
public static final String REPLICATION_TYPE = "opensearch.experimental.feature.replication_type.enabled"; | ||
|
||
/** | ||
* Used to test feature flags whose values are expected to be booleans. | ||
* This method returns true if the value is "true" (case-insensitive), | ||
* and false otherwise. | ||
*/ | ||
public static boolean isEnabled(String featureFlagName) { | ||
return "true".equalsIgnoreCase(System.getProperty(featureFlagName)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
server/src/main/java/org/opensearch/indices/replication/common/ReplicationType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.indices.replication.common; | ||
|
||
/** | ||
* Enumerates the types of replication strategies supported by OpenSearch. | ||
* For more information, see https://github.com/opensearch-project/OpenSearch/issues/1694 | ||
*/ | ||
public enum ReplicationType { | ||
|
||
DOCUMENT, | ||
SEGMENT; | ||
|
||
public static ReplicationType parseString(String replicationType) { | ||
try { | ||
return ReplicationType.valueOf(replicationType); | ||
} catch (IllegalArgumentException e) { | ||
throw new IllegalArgumentException("Could not parse ReplicationStrategy for [" + replicationType + "]"); | ||
} catch (NullPointerException npe) { | ||
// return a default value for null input | ||
return DOCUMENT; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
server/src/test/java/org/opensearch/common/util/FeatureFlagTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.common.util; | ||
|
||
import org.junit.BeforeClass; | ||
import org.opensearch.common.SuppressForbidden; | ||
import org.opensearch.test.OpenSearchTestCase; | ||
|
||
import java.security.AccessController; | ||
import java.security.PrivilegedAction; | ||
|
||
public class FeatureFlagTests extends OpenSearchTestCase { | ||
|
||
@SuppressForbidden(reason = "sets the feature flag") | ||
@BeforeClass | ||
public static void enableFeature() { | ||
AccessController.doPrivileged((PrivilegedAction<String>) () -> System.setProperty(FeatureFlags.REPLICATION_TYPE, "true")); | ||
} | ||
|
||
public void testReplicationTypeFeatureFlag() { | ||
String replicationTypeFlag = FeatureFlags.REPLICATION_TYPE; | ||
assertNotNull(System.getProperty(replicationTypeFlag)); | ||
assertTrue(FeatureFlags.isEnabled(replicationTypeFlag)); | ||
} | ||
|
||
public void testMissingFeatureFlag() { | ||
String testFlag = "missingFeatureFlag"; | ||
assertNull(System.getProperty(testFlag)); | ||
assertFalse(FeatureFlags.isEnabled(testFlag)); | ||
} | ||
|
||
public void testNonBooleanFeatureFlag() { | ||
String javaVersionProperty = "java.version"; | ||
assertNotNull(System.getProperty(javaVersionProperty)); | ||
assertFalse(FeatureFlags.isEnabled(javaVersionProperty)); | ||
} | ||
} |