Skip to content

Commit

Permalink
GET _cluster/settings with include_defaults returns the expected fall…
Browse files Browse the repository at this point in the history
…back value if defined in elasticsearch.yml (elastic#110816)

* test: add unit test that reproduces elastic#110815

* fix: consider the fallback setting when getting the default value of a setting

* doc: add changelog entry
  • Loading branch information
scampi committed Jul 26, 2024
1 parent ce86f2f commit 9b1f07a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
6 changes: 6 additions & 0 deletions docs/changelog/110816.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 110816
summary: GET _cluster/settings with include_defaults returns the expected fallback value if defined in elasticsearch.yml
area: Infra/Settings
type: bug
issues:
- 110815
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ private T get(Settings settings, boolean validate) {
*/
public void diff(Settings.Builder builder, Settings source, Settings defaultSettings) {
if (exists(source) == false) {
if (exists(defaultSettings)) {
if (existsOrFallbackExists(defaultSettings)) {
// If the setting is only in the defaults, use the value from the defaults
builder.put(getKey(), getRaw(defaultSettings));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,26 @@ public void testDiff() throws IOException {
assertThat(diff.getAsInt("foo.bar", null), equalTo(1));
}

public void testDiffWithFallbackDefaultSetting() {
final String fallbackSettingName = "fallback";
final Setting<Integer> fallbackSetting = Setting.intSetting(fallbackSettingName, 1, Property.Dynamic, Property.NodeScope);

final String settingName = "setting.with.fallback";
final Setting<Integer> dependentSetting = new Setting<>(
settingName,
fallbackSetting,
(s) -> Setting.parseInt(s, 1, settingName),
value -> {},
Property.Dynamic,
Property.NodeScope
);

ClusterSettings settings = new ClusterSettings(Settings.EMPTY, new HashSet<>(Arrays.asList(fallbackSetting, dependentSetting)));

final Settings diff = settings.diff(Settings.EMPTY, Settings.builder().put(fallbackSettingName, 2).build());
assertThat(diff.getAsInt(settingName, null), equalTo(2));
}

public void testDiffWithDependentSettings() {
final String dependedSettingName = "this.setting.is.depended.on";
Setting<Integer> dependedSetting = Setting.intSetting(dependedSettingName, 1, Property.Dynamic, Property.NodeScope);
Expand Down

0 comments on commit 9b1f07a

Please sign in to comment.