Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CCI] [BUG] Fixing extension settings update consumers #7456

Merged
merged 8 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,13 @@ public synchronized Settings applySettings(Settings newSettings) {
* This is useful to add additional validation to settings at runtime compared to at startup time.
*/
public synchronized <T> void addSettingsUpdateConsumer(Setting<T> setting, Consumer<T> consumer, Consumer<T> validator) {
if (setting != get(setting.getKey())) {
dbwiddis marked this conversation as resolved.
Show resolved Hide resolved
if (!setting.equals(get(setting.getKey()))) {
dbwiddis marked this conversation as resolved.
Show resolved Hide resolved
throw new SettingsException("Setting is not registered for key [" + setting.getKey() + "]");
} else if (setting.getKey() == null) {
logger.error("not registered setting key");
} else {
addSettingsUpdater(setting.newUpdater(consumer, logger, validator));
}
addSettingsUpdater(setting.newUpdater(consumer, logger, validator));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.junit.Test;
import org.opensearch.Version;
import org.opensearch.cluster.metadata.IndexMetadata;
import org.opensearch.cluster.routing.allocation.decider.FilterAllocationDecider;
Expand Down Expand Up @@ -1462,4 +1463,17 @@ public List<String> getListValue(final List<String> value) {
);
}

@Test
dbwiddis marked this conversation as resolved.
Show resolved Hide resolved
public void testAddSettingsUpdateConsumer() {
Setting<Integer> testSetting = Setting.intSetting("foo.bar", 1, Property.Dynamic, Property.NodeScope);
Setting<Integer> testSetting2 = Setting.intSetting("foo.bar.baz", 1, Property.Dynamic, Property.NodeScope);
AbstractScopedSettings service = new ClusterSettings(Settings.EMPTY, new HashSet<>(Arrays.asList(testSetting, testSetting2)));
AtomicInteger consumer2 = new AtomicInteger();
service.addSettingsUpdateConsumer(testSetting2, consumer2::set, (s) -> assertTrue(s > 0));
Setting<Integer> wrongKeySetting = Setting.intSetting("foo.bar.wrong", 1, Property.Dynamic, Property.NodeScope);

expectThrows(SettingsException.class, () -> {
service.addSettingsUpdateConsumer(wrongKeySetting, consumer2::set, (i) -> { if (i == 42) throw new AssertionError("boom"); });
});
}
}