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

Change deprecation.skip_deprecated_settings to work with dynamic settings #81836

Merged
Show file tree
Hide file tree
Changes from all 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 @@ -11,6 +11,11 @@
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.common.regex.Regex;
import org.elasticsearch.common.settings.Settings;

import java.util.Collections;
import java.util.List;

/**
* A logger that logs deprecation notices. Logger should be initialized with a class or name which will be used
Expand All @@ -32,7 +37,7 @@ public class DeprecationLogger {
* More serious than WARN by 1, but less serious than ERROR
*/
public static Level CRITICAL = Level.forName("CRITICAL", Level.WARN.intLevel() - 1);

private static volatile List<String> skipTheseDeprecations = Collections.emptyList();
private final Logger logger;

/**
Expand All @@ -53,6 +58,19 @@ public static DeprecationLogger getLogger(String name) {
return new DeprecationLogger(name);
}

/**
* The DeprecationLogger uses the "deprecation.skip_deprecated_settings" setting to decide whether to log a deprecation for a setting.
* This is a node setting. This method initializes the DeprecationLogger class with the node settings for the node in order to read the
* "deprecation.skip_deprecated_settings" setting. This only needs to be called once per JVM. If it is not called, the default behavior
* is to assume that the "deprecation.skip_deprecated_settings" setting is not set.
* @param nodeSettings The settings for this node
*/
public static void initialize(Settings nodeSettings) {
skipTheseDeprecations = nodeSettings == null
? Collections.emptyList()
: nodeSettings.getAsList("deprecation.skip_deprecated_settings");
}

private DeprecationLogger(String parentLoggerName) {
this.logger = LogManager.getLogger(getLoggerName(parentLoggerName));
}
Expand Down Expand Up @@ -92,10 +110,12 @@ public DeprecationLogger warn(final DeprecationCategory category, final String k
}

private DeprecationLogger logDeprecation(Level level, DeprecationCategory category, String key, String msg, Object[] params) {
String opaqueId = HeaderWarning.getXOpaqueId();
String productOrigin = HeaderWarning.getProductOrigin();
ESLogMessage deprecationMessage = new DeprecatedMessage(category, key, opaqueId, productOrigin, msg, params);
logger.log(level, deprecationMessage);
if (Regex.simpleMatch(skipTheseDeprecations, key) == false) {
String opaqueId = HeaderWarning.getXOpaqueId();
String productOrigin = HeaderWarning.getProductOrigin();
ESLogMessage deprecationMessage = new DeprecatedMessage(category, key, opaqueId, productOrigin, msg, params);
logger.log(level, deprecationMessage);
}
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -588,15 +588,12 @@ void checkDeprecation(Settings settings) {
// It would be convenient to show its replacement key, but replacement is often not so simple
final String key = getKey();
DeprecationCategory category = this.isSecure(settings) ? DeprecationCategory.SECURITY : DeprecationCategory.SETTINGS;
List<String> skipTheseDeprecations = settings.getAsList("deprecation.skip_deprecated_settings");
if (Regex.simpleMatch(skipTheseDeprecations, key) == false) {
String message = "[{}] setting was deprecated in Elasticsearch and will be removed in a future release! "
+ "See the breaking changes documentation for the next major version.";
if (this.isDeprecatedWarningOnly()) {
Settings.DeprecationLoggerHolder.deprecationLogger.warn(category, key, message, key);
} else {
Settings.DeprecationLoggerHolder.deprecationLogger.critical(category, key, message, key);
}
String message = "[{}] setting was deprecated in Elasticsearch and will be removed in a future release! "
+ "See the breaking changes documentation for the next major version.";
if (this.isDeprecatedWarningOnly()) {
Settings.DeprecationLoggerHolder.deprecationLogger.warn(category, key, message, key);
} else {
Settings.DeprecationLoggerHolder.deprecationLogger.critical(category, key, message, key);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions server/src/main/java/org/elasticsearch/node/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,8 @@ protected Node(
final List<Closeable> resourcesToClose = new ArrayList<>(); // register everything we need to release in the case of an error
boolean success = false;
try {
// Pass the node settings to the DeprecationLogger class so that it can have the deprecation.skip_deprecated_settings setting:
DeprecationLogger.initialize(initialEnvironment.settings());
Settings tmpSettings = Settings.builder()
.put(initialEnvironment.settings())
.put(Client.CLIENT_TYPE_SETTING_S.getKey(), CLIENT_TYPE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.LogEvent;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.AbstractScopedSettings.SettingUpdater;
import org.elasticsearch.common.settings.Setting.Property;
Expand Down Expand Up @@ -1385,7 +1386,7 @@ public void testCheckForDeprecation() {
}

public void testCheckForDeprecationWithSkipSetting() {
final String settingName = "foo.bar";
final String settingName = "foo.bar.hide.this";
final String settingValue = "blat";
final Setting<String> setting = Setting.simpleString(settingName, settingValue);
final Settings settings = Settings.builder().put(settingName, settingValue).build();
Expand All @@ -1398,6 +1399,7 @@ public void testCheckForDeprecationWithSkipSetting() {
.put(settingName, settingValue)
.putList("deprecation.skip_deprecated_settings", settingName)
.build();
DeprecationLogger.initialize(settingsWithSkipDeprecationSetting);
deprecatedSetting.checkDeprecation(settingsWithSkipDeprecationSetting);
ensureNoWarnings();
}
Expand Down