diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java index d9da43df6bd9d..f75d6e1413cd8 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/DeprecationChecks.java @@ -98,6 +98,7 @@ private DeprecationChecks() { NodeDeprecationChecks::checkImplicitlyDisabledSecurityOnBasicAndTrial, NodeDeprecationChecks::checkSearchRemoteSettings, NodeDeprecationChecks::checkMonitoringExporterPassword, + NodeDeprecationChecks::checkFractionalByteValueSettings, NodeDeprecationChecks::checkFrozenCacheLeniency, NodeDeprecationChecks::checkSslServerEnabled, NodeDeprecationChecks::checkSslCertConfiguration, diff --git a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java index 569e6db14db20..dd070df611920 100644 --- a/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java +++ b/x-pack/plugin/deprecation/src/main/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecks.java @@ -20,8 +20,8 @@ import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Setting.Property; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.ssl.SslConfigurationKeys; +import org.elasticsearch.common.unit.ByteSizeValue; import org.elasticsearch.common.util.concurrent.EsExecutors; import org.elasticsearch.common.util.set.Sets; import org.elasticsearch.core.TimeValue; @@ -36,9 +36,9 @@ import org.elasticsearch.script.ScriptService; import org.elasticsearch.threadpool.FixedExecutorBuilder; import org.elasticsearch.transport.RemoteClusterService; -import org.elasticsearch.xpack.core.DataTier; import org.elasticsearch.transport.SniffConnectionStrategy; import org.elasticsearch.transport.TransportService; +import org.elasticsearch.xpack.core.DataTier; import org.elasticsearch.xpack.core.XPackSettings; import org.elasticsearch.xpack.core.security.SecurityField; import org.elasticsearch.xpack.core.security.authc.RealmConfig; @@ -48,6 +48,7 @@ import java.util.ArrayList; import java.util.Comparator; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Locale; @@ -671,6 +672,33 @@ static DeprecationIssue checkClusterRoutingAllocationIncludeRelocationsSetting(f ); } + static DeprecationIssue checkFractionalByteValueSettings(final Settings settings, + final PluginsAndModules pluginsAndModules, + final ClusterState clusterState, + final XPackLicenseState licenseState) { + Map fractionalByteSettings = new HashMap<>(); + for (String key : settings.keySet()) { + try { + settings.getAsBytesSize(key, ByteSizeValue.ZERO); + String stringValue = settings.get(key); + if (stringValue.contains(".")) { + fractionalByteSettings.put(key, stringValue); + } + } catch (Exception ignoreThis) { + // We expect anything that is not a byte setting to throw an exception, but we don't care about those + } + } + if (fractionalByteSettings.isEmpty()) { + return null; + } + String url = "https://www.elastic.co/guide/en/elasticsearch/reference/master/logging.html#deprecation-logging"; + String message = "support for fractional byte size values is deprecated and will be removed in a future release"; + String details = "change the following settings to non-fractional values: [" + + fractionalByteSettings.entrySet().stream().map(fractionalByteSetting -> fractionalByteSetting.getKey() + "->" + + fractionalByteSetting.getValue()).collect(Collectors.joining(", ")) + "]"; + return new DeprecationIssue(DeprecationIssue.Level.WARNING, message, url, details, false, null); + } + static DeprecationIssue checkFrozenCacheLeniency(final Settings settings, final PluginsAndModules pluginsAndModules, final ClusterState clusterState, diff --git a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java index 1b2520309c826..f33e88a9c4a42 100644 --- a/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java +++ b/x-pack/plugin/deprecation/src/test/java/org/elasticsearch/xpack/deprecation/NodeDeprecationChecksTests.java @@ -963,6 +963,34 @@ public void testImplicitlyConfiguredSecurityOnGoldPlus() { assertThat(issues, empty()); } + public void testCheckFractionalByteValueSettings() { + String settingKey = "network.tcp.send_buffer_size"; + String unit = randomFrom(new String[]{"k", "kb", "m", "mb", "g", "gb", "t", "tb", "p", "pb"}); + float value = Math.abs(randomFloat()); + String settingValue = value + unit; + String unaffectedSettingKey = "some.other.setting"; + String unaffectedSettingValue = "54.32.43mb"; //Not an actual number, so we don't expect to see a deprecation log about it + final Settings nodeSettings = + Settings.builder().put(settingKey, settingValue).put(unaffectedSettingKey, unaffectedSettingValue).build(); + final XPackLicenseState licenseState = new XPackLicenseState(Settings.EMPTY, () -> 0); + final ClusterState clusterState = ClusterState.EMPTY_STATE; + final DeprecationIssue expectedIssue = new DeprecationIssue(DeprecationIssue.Level.WARNING, + "support for fractional byte size values is deprecated and will be removed in a future release", + "https://www.elastic.co/guide/en/elasticsearch/reference/master/logging.html#deprecation-logging", + String.format(Locale.ROOT, + "change the following settings to non-fractional values: [%s->%s]", + settingKey, + settingValue), + false, null + ); + assertThat( + NodeDeprecationChecks.checkFractionalByteValueSettings(nodeSettings, null, clusterState, licenseState), + equalTo(expectedIssue) + ); + assertWarnings(String.format(Locale.ROOT, "Fractional bytes values are deprecated. Use non-fractional bytes values instead: [%s] " + + "found for setting [%s]", settingValue, settingKey)); + } + public void testCheckFrozenCacheLeniency() { String cacheSizeSettingValue = "10gb"; String cacheSizeSettingKey = "xpack.searchable.snapshot.shared_cache.size";