Skip to content

Added support for feature flags in opensearch.yml#4959

Merged
dreamer-89 merged 1 commit into
opensearch-project:mainfrom
ntantri:support-feature-flags-via-yaml
Jan 4, 2023
Merged

Added support for feature flags in opensearch.yml#4959
dreamer-89 merged 1 commit into
opensearch-project:mainfrom
ntantri:support-feature-flags-via-yaml

Conversation

@ntantri
Copy link
Copy Markdown
Contributor

@ntantri ntantri commented Oct 27, 2022

This change introduces a static store "settings"
in FeatureFlags.java file to enable the isEnabled method to fetch flag settings defined in opensearch.yml.

Description

This PR addresses issue #4102, wherein, it allows FeatureFlags to be fetched from opensearch.yml and not from the environment variable or system property.

Issues Resolved

[#4102]

Check List

  • New functionality includes testing.
    • All tests pass
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed per the DCO using --signoff
  • Commit changes are listed out in CHANGELOG.md file (See: Changelog)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@ntantri ntantri requested review from a team and reta as code owners October 27, 2022 20:54
@ntantri ntantri closed this Oct 27, 2022
@ntantri ntantri reopened this Oct 27, 2022
@ntantri ntantri marked this pull request as draft October 27, 2022 20:56
@ntantri ntantri force-pushed the support-feature-flags-via-yaml branch 3 times, most recently from e97ceb1 to c22e311 Compare October 27, 2022 21:06
@github-actions
Copy link
Copy Markdown
Contributor

Gradle Check (Jenkins) Run Completed with:

@ntantri ntantri force-pushed the support-feature-flags-via-yaml branch from c22e311 to e8cb508 Compare October 27, 2022 21:08
@github-actions
Copy link
Copy Markdown
Contributor

Gradle Check (Jenkins) Run Completed with:

@github-actions
Copy link
Copy Markdown
Contributor

Gradle Check (Jenkins) Run Completed with:

@github-actions
Copy link
Copy Markdown
Contributor

Gradle Check (Jenkins) Run Completed with:

@github-actions
Copy link
Copy Markdown
Contributor

Gradle Check (Jenkins) Run Completed with:

@github-actions
Copy link
Copy Markdown
Contributor

Gradle Check (Jenkins) Run Completed with:

@ntantri ntantri force-pushed the support-feature-flags-via-yaml branch from e8cb508 to 9543074 Compare November 3, 2022 00:17
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Nov 3, 2022

Gradle Check (Jenkins) Run Completed with:

@mch2
Copy link
Copy Markdown
Member

mch2 commented Nov 23, 2022

@tan31989 This looks like a great start! Are you looking for feedback on this draft or still iterating?

One bit of feedback - As an additional test, you can flip SegmentReplicationIT to use node settings at startup by removing the assumeFeatureFlag beforeClass method and pass the settings to startNode where internalCluster().startNode(); is invoked.

@ntantri
Copy link
Copy Markdown
Contributor Author

ntantri commented Nov 24, 2022

@mch2 thanks for the inputs. Apologies that it's taking too much time. I had some personal things to take care of.
I should be able to fix this asap and test it.

@ntantri ntantri force-pushed the support-feature-flags-via-yaml branch from 9543074 to d8247ca Compare November 25, 2022 00:55
@github-actions
Copy link
Copy Markdown
Contributor

Gradle Check (Jenkins) Run Completed with:

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Nov 25, 2022

Codecov Report

❌ Patch coverage is 63.63636% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.06%. Comparing base (28e9b11) to head (9aa0a93).
⚠️ Report is 4339 commits behind head on main.

Files with missing lines Patch % Lines
...a/org/opensearch/test/OpenSearchIntegTestCase.java 0.00% 5 Missing ⚠️
...pensearch/common/settings/FeatureFlagSettings.java 50.00% 2 Missing ⚠️
.../java/org/opensearch/common/util/FeatureFlags.java 88.88% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #4959      +/-   ##
============================================
+ Coverage     70.98%   71.06%   +0.07%     
- Complexity    58669    58762      +93     
============================================
  Files          4763     4764       +1     
  Lines        279945   279966      +21     
  Branches      40418    40421       +3     
============================================
+ Hits         198731   198966     +235     
+ Misses        64988    64856     -132     
+ Partials      16226    16144      -82     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ntantri
Copy link
Copy Markdown
Contributor Author

ntantri commented Nov 25, 2022

@mch2 was debugging the tests by adding the settings to internalCluster().startNode(settings), and apparently there are validations on these settings being passed.

java.lang.IllegalArgumentException: unknown setting [opensearch.experimental.feature.extensions.enabled] 
please check that any required plugins are installed, or check the breaking changes 
documentation for removed settings
	at __randomizedtesting.SeedInfo.seed([F366529BF2371B1C:722EBD885B6BAAE8]:0)
	at org.opensearch.common.settings.AbstractScopedSettings.validate(AbstractScopedSettings.java:591)

So, if we add these settings to opensearch.yaml, do we effectively get that ingested during the testing?

@dblock
Copy link
Copy Markdown
Member

dblock commented Nov 28, 2022

I think we have more American spelling of initialize vs. British initialise. I believe in computers we typically use initialize, care to rename here (and possibly elsewhere, maybe a separate PR)?

@mch2
Copy link
Copy Markdown
Member

mch2 commented Nov 29, 2022

@mch2 was debugging the tests by adding the settings to internalCluster().startNode(settings), and apparently there are validations on these settings being passed.

java.lang.IllegalArgumentException: unknown setting [opensearch.experimental.feature.extensions.enabled] 
please check that any required plugins are installed, or check the breaking changes 
documentation for removed settings
	at __randomizedtesting.SeedInfo.seed([F366529BF2371B1C:722EBD885B6BAAE8]:0)
	at org.opensearch.common.settings.AbstractScopedSettings.validate(AbstractScopedSettings.java:591)

So, if we add these settings to opensearch.yaml, do we effectively get that ingested during the testing?

@tan31989 This means that the flag itself is not registered yet as a setting, even though it is properly getting passed in your test.

In SettingsModule.java we loop over the existing featureFlags link, and if enabled register the settings that are specific to the feature behind the flag. Before this step happens, we will need to register settings for the flags themselves.

Example for just the segrep setting:

        registerSetting(FeatureFlags.REPLICATION_TYPE_ENABLED_SETTING);

        for (Map.Entry<String, List<Setting>> featureFlaggedSetting : IndexScopedSettings.FEATURE_FLAGGED_INDEX_SETTINGS.entrySet()) {
            if (FeatureFlags.isEnabled(featureFlaggedSetting.getKey())) {
                featureFlaggedSetting.getValue().forEach(feature -> registerSetting(feature));
            }
        }

And in FeatureFlags.java

    /**
     * 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";

    public static final Setting<Boolean> REPLICATION_TYPE_ENABLED_SETTING = Setting.boolSetting(
        REPLICATION_TYPE,
        false,
        Setting.Property.NodeScope,
        Setting.Property.Final
    );

After this is done for a particular flag it will register all its settings, which for segrep is the replication type setting.

With this code if you were to flip the flag off in your test, you'd see a similar error indicating the type setting is unknown, while the enabled setting still exists with a final value of false.

java.lang.IllegalArgumentException: unknown setting [index.replication.type] please check that any required plugins are installed, or check the breaking changes documentation for removed settings

@ntantri ntantri force-pushed the support-feature-flags-via-yaml branch from d8247ca to 32a2a31 Compare December 8, 2022 10:28
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Dec 8, 2022

Gradle Check (Jenkins) Run Completed with:

@ntantri ntantri force-pushed the support-feature-flags-via-yaml branch from 32a2a31 to 5ee23a4 Compare December 8, 2022 10:57
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Dec 8, 2022

Gradle Check (Jenkins) Run Completed with:

@ntantri ntantri force-pushed the support-feature-flags-via-yaml branch from 5ee23a4 to 5cc38c5 Compare December 9, 2022 05:50
@ntantri
Copy link
Copy Markdown
Contributor Author

ntantri commented Jan 4, 2023

Random tests keep failing 🤔
Like:

1 org.opensearch.snapshots.SegmentReplicationSnapshotIT.testSnapshotOnSegRep_RestoreOnSegRepDuringIngestion
1 org.opensearch.indices.replication.SegmentReplicationIT.testReplicationAfterPrimaryRefreshAndFlush

Should those be marked as flaky and raised a separate ticket to fix?

@mch2
Copy link
Copy Markdown
Member

mch2 commented Jan 4, 2023

Random tests keep failing 🤔

Like:


1 org.opensearch.snapshots.SegmentReplicationSnapshotIT.testSnapshotOnSegRep_RestoreOnSegRepDuringIngestion

1 org.opensearch.indices.replication.SegmentReplicationIT.testReplicationAfterPrimaryRefreshAndFlush

Should those be marked as flaky and raised a separate ticket to fix?

Yes let's mute and look at them separately as they are segrep specific. I don't want to block this pr on them.

@dreamer-89 dreamer-89 merged commit 241bd42 into opensearch-project:main Jan 4, 2023
@dreamer-89 dreamer-89 added the backport 2.x Backport to 2.x branch label Jan 4, 2023
@opensearch-trigger-bot
Copy link
Copy Markdown
Contributor

The backport to 2.x failed:

The process '/usr/bin/git' failed with exit code 128

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/backport-2.x 2.x
# Navigate to the new working tree
pushd ../.worktrees/backport-2.x
# Create a new branch
git switch --create backport/backport-4959-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 241bd42ab4d0bff0c6d232df0076d2568e326667
# Push it to GitHub
git push --set-upstream origin backport/backport-4959-to-2.x
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/backport-2.x

Then, create a pull request where the base branch is 2.x and the compare/head branch is backport/backport-4959-to-2.x.

@dreamer-89
Copy link
Copy Markdown
Member

@tan31989 : The PR to backport to 2.x failed, care to raise a manual backport PR

@mch2
Copy link
Copy Markdown
Member

mch2 commented Jan 4, 2023

@tan31989 Thank you for this change!

@mch2 mch2 mentioned this pull request Jan 4, 2023
6 tasks
ntantri added a commit to ntantri/OpenSearch that referenced this pull request Jan 5, 2023
…#4959)

This change introduces a static store "settings"
in FeatureFlags.java file to enable isEnabled method to
fetch flag settings defined in opensearch.yml.

Signed-off-by: Nagaraj Tantri <nagarajtantri@gmail.com>

(cherry picked from commit 241bd42)
ntantri added a commit to ntantri/OpenSearch that referenced this pull request Jan 5, 2023
…#4959)

This change introduces a static store "settings"
in FeatureFlags.java file to enable isEnabled method to
fetch flag settings defined in opensearch.yml.

Signed-off-by: Nagaraj Tantri <nagarajtantri@gmail.com>

(cherry picked from commit 241bd42)
ntantri added a commit to ntantri/OpenSearch that referenced this pull request Jan 5, 2023
…#4959)

This change introduces a static store "settings"
in FeatureFlags.java file to enable isEnabled method to
fetch flag settings defined in opensearch.yml.

Signed-off-by: Nagaraj Tantri <nagarajtantri@gmail.com>

(cherry picked from commit 241bd42)
ntantri added a commit to ntantri/OpenSearch that referenced this pull request Jan 5, 2023
…#4959)

This change introduces a static store "settings"
in FeatureFlags.java file to enable isEnabled method to
fetch flag settings defined in opensearch.yml.

Signed-off-by: Nagaraj Tantri <nagarajtantri@gmail.com>

(cherry picked from commit 241bd42)
@ntantri
Copy link
Copy Markdown
Contributor Author

ntantri commented Jan 5, 2023

Added a backport PR here #5707

ntantri added a commit to ntantri/OpenSearch that referenced this pull request Jan 5, 2023
…#4959)

This change introduces a static store "settings"
in FeatureFlags.java file to enable isEnabled method to
fetch flag settings defined in opensearch.yml.

Signed-off-by: Nagaraj Tantri <nagarajtantri@gmail.com>

(cherry picked from commit 241bd42)
ntantri added a commit to ntantri/OpenSearch that referenced this pull request Jan 7, 2023
…#4959)

This change introduces a static store "settings"
in FeatureFlags.java file to enable isEnabled method to
fetch flag settings defined in opensearch.yml.

Signed-off-by: Nagaraj Tantri <nagarajtantri@gmail.com>

(cherry picked from commit 241bd42)
ntantri added a commit to ntantri/OpenSearch that referenced this pull request Jan 8, 2023
…#4959)

This change introduces a static store "settings"
in FeatureFlags.java file to enable isEnabled method to
fetch flag settings defined in opensearch.yml.

Signed-off-by: Nagaraj Tantri <nagarajtantri@gmail.com>

(cherry picked from commit 241bd42)
ntantri added a commit to ntantri/OpenSearch that referenced this pull request Jan 8, 2023
…#4959)

This change introduces a static store "settings"
in FeatureFlags.java file to enable isEnabled method to
fetch flag settings defined in opensearch.yml.

Signed-off-by: Nagaraj Tantri <nagarajtantri@gmail.com>

(cherry picked from commit 241bd42)
ntantri added a commit to ntantri/OpenSearch that referenced this pull request Jan 8, 2023
…#4959)

This change introduces a static store "settings"
in FeatureFlags.java file to enable isEnabled method to
fetch flag settings defined in opensearch.yml.

Signed-off-by: Nagaraj Tantri <nagarajtantri@gmail.com>

(cherry picked from commit 241bd42)
ntantri added a commit to ntantri/OpenSearch that referenced this pull request Jan 8, 2023
…#4959)

This change introduces a static store "settings"
in FeatureFlags.java file to enable isEnabled method to
fetch flag settings defined in opensearch.yml.

Signed-off-by: Nagaraj Tantri <nagarajtantri@gmail.com>

(cherry picked from commit 241bd42)
ntantri added a commit to ntantri/OpenSearch that referenced this pull request Jan 8, 2023
…#4959)

This change introduces a static store "settings"
in FeatureFlags.java file to enable isEnabled method to
fetch flag settings defined in opensearch.yml.

Signed-off-by: Nagaraj Tantri <nagarajtantri@gmail.com>

(cherry picked from commit 241bd42)
ntantri added a commit to ntantri/OpenSearch that referenced this pull request Jan 8, 2023
…#4959)

This change introduces a static store "settings"
in FeatureFlags.java file to enable isEnabled method to
fetch flag settings defined in opensearch.yml.

Signed-off-by: Nagaraj Tantri <nagarajtantri@gmail.com>

(cherry picked from commit 241bd42)
ntantri added a commit to ntantri/OpenSearch that referenced this pull request Jan 8, 2023
…#4959)

This change introduces a static store "settings"
in FeatureFlags.java file to enable isEnabled method to
fetch flag settings defined in opensearch.yml.

Signed-off-by: Nagaraj Tantri <nagarajtantri@gmail.com>

(cherry picked from commit 241bd42)
ntantri added a commit to ntantri/OpenSearch that referenced this pull request Jan 19, 2023
…#4959)

This change introduces a static store "settings"
in FeatureFlags.java file to enable isEnabled method to
fetch flag settings defined in opensearch.yml.

Signed-off-by: Nagaraj Tantri <nagarajtantri@gmail.com>

(cherry picked from commit 241bd42)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport 2.x Backport to 2.x branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants