diff options
author | Jason Tedor <jason@tedor.me> | 2017-06-28 22:18:46 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-28 22:18:46 -0400 |
commit | da59c178e2cd39ac141c8e738ad692b94813eecd (patch) | |
tree | 8bfca2838afcc1e312ddf9f2c6992dbf5df87d85 /core/src/main/java/org/elasticsearch | |
parent | 9714c77c842a616c3c97289ad43afe218d605c81 (diff) |
Emit settings deprecation logging at most once
When a setting is deprecated, if that setting is used repeatedly we
currently emit a deprecation warning every time the setting is used. In
cases like hitting settings endpoints over and over against a node with
a lot of deprecated settings, this can lead to excessive deprecation
warnings which can crush a node. This commit ensures that a given
setting only sees deprecation logging at most once.
Relates #25457
Diffstat (limited to 'core/src/main/java/org/elasticsearch')
-rw-r--r-- | core/src/main/java/org/elasticsearch/common/settings/Setting.java | 2 | ||||
-rw-r--r-- | core/src/main/java/org/elasticsearch/common/settings/Settings.java | 18 |
2 files changed, 18 insertions, 2 deletions
diff --git a/core/src/main/java/org/elasticsearch/common/settings/Setting.java b/core/src/main/java/org/elasticsearch/common/settings/Setting.java index d81204cfb2..241315144a 100644 --- a/core/src/main/java/org/elasticsearch/common/settings/Setting.java +++ b/core/src/main/java/org/elasticsearch/common/settings/Setting.java @@ -345,7 +345,7 @@ public class Setting<T> extends ToXContentToBytes { /** Logs a deprecation warning if the setting is deprecated and used. */ protected void checkDeprecation(Settings settings) { // They're using the setting, so we need to tell them to stop - if (this.isDeprecated() && this.exists(settings)) { + if (this.isDeprecated() && this.exists(settings) && settings.addDeprecatedSetting(this)) { // It would be convenient to show its replacement key, but replacement is often not so simple final DeprecationLogger deprecationLogger = new DeprecationLogger(Loggers.getLogger(getClass())); deprecationLogger.deprecated("[{}] setting was deprecated in Elasticsearch and will be removed in a future release! " + diff --git a/core/src/main/java/org/elasticsearch/common/settings/Settings.java b/core/src/main/java/org/elasticsearch/common/settings/Settings.java index 182ea6ccb1..8412f57fd8 100644 --- a/core/src/main/java/org/elasticsearch/common/settings/Settings.java +++ b/core/src/main/java/org/elasticsearch/common/settings/Settings.java @@ -55,7 +55,6 @@ import java.util.Dictionary; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; -import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; import java.util.Map; @@ -63,6 +62,7 @@ import java.util.NoSuchElementException; import java.util.Objects; import java.util.Set; import java.util.TreeMap; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; import java.util.function.Function; import java.util.function.Predicate; @@ -94,6 +94,22 @@ public final class Settings implements ToXContent { private final SetOnce<Set<String>> firstLevelNames = new SetOnce<>(); /** + * The set of deprecated settings tracked by this settings object. + */ + private final Set<String> deprecatedSettings = Collections.newSetFromMap(new ConcurrentHashMap<>()); + + /** + * Add the setting as a tracked deprecated setting. + * + * @param setting the deprecated setting to track + * @return true if the setting was not already tracked as a deprecated setting, otherwise false + */ + boolean addDeprecatedSetting(final Setting setting) { + assert setting.isDeprecated() && setting.exists(this) : setting.getKey(); + return deprecatedSettings.add(setting.getKey()); + } + + /** * Setting names found in this Settings for both string and secure settings. * This is constructed lazily in {@link #keySet()}. */ |