Skip to content

Commit

Permalink
Script: Undeprecate general cache
Browse files Browse the repository at this point in the history
General cache settings are no longer deprecated for 8.0
* `script.cache.max_size`
* `script.cache.expire`
* `script.max_compilations_rate`

Refs: elastic#62899
  • Loading branch information
stu-elastic committed Oct 18, 2021
1 parent 8239527 commit 24e5e7f
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,15 @@ public class ScriptService implements Closeable, ClusterStateApplier, ScriptComp
static final String USE_CONTEXT_RATE_KEY = "use-context";

public static final Setting<Integer> SCRIPT_GENERAL_CACHE_SIZE_SETTING =
Setting.intSetting("script.cache.max_size", 100, 0, Property.NodeScope, Property.Deprecated);
Setting.intSetting("script.cache.max_size", 100, 0, Property.NodeScope);
public static final Setting<TimeValue> SCRIPT_GENERAL_CACHE_EXPIRE_SETTING =
Setting.positiveTimeSetting("script.cache.expire", TimeValue.timeValueMillis(0), Property.NodeScope, Property.Deprecated);
Setting.positiveTimeSetting("script.cache.expire", TimeValue.timeValueMillis(0), Property.NodeScope);
public static final Setting<Integer> SCRIPT_MAX_SIZE_IN_BYTES =
Setting.intSetting("script.max_size_in_bytes", 65535, 0, Property.Dynamic, Property.NodeScope);
public static final Setting<ScriptCache.CompilationRate> SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING =
new Setting<>("script.max_compilations_rate", USE_CONTEXT_RATE_KEY,
(String value) -> value.equals(USE_CONTEXT_RATE_KEY) ? USE_CONTEXT_RATE_VALUE: new ScriptCache.CompilationRate(value),
Property.Dynamic, Property.NodeScope, Property.Deprecated);
Property.Dynamic, Property.NodeScope);

// Per-context settings
static final String CONTEXT_PREFIX = "script.context.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import org.elasticsearch.common.bytes.BytesArray;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.settings.ClusterSettings;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.xcontent.XContentFactory;
Expand Down Expand Up @@ -226,8 +225,6 @@ public void testCompilationStatsOnCacheHit() throws IOException {
scriptService.compile(script, context);
scriptService.compile(script, context);
assertEquals(1L, scriptService.stats().getCompilations());
assertSettingDeprecationsAndWarnings(new Setting<?>[]{SCRIPT_GENERAL_CACHE_SIZE_SETTING,
SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING});
}

public void testIndexedScriptCountedInCompilationStats() throws IOException {
Expand All @@ -249,8 +246,6 @@ public void testCacheEvictionCountedInCacheEvictionsStats() throws IOException {
assertEquals(2L, scriptService.cacheStats().getGeneralStats().getCompilations());
assertEquals(1L, scriptService.stats().getCacheEvictions());
assertEquals(1L, scriptService.cacheStats().getGeneralStats().getCacheEvictions());
assertSettingDeprecationsAndWarnings(new Setting<?>[]{SCRIPT_GENERAL_CACHE_SIZE_SETTING,
SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING});
}

public void testContextCacheStats() throws IOException {
Expand Down Expand Up @@ -408,7 +403,6 @@ public void testConflictContextSettings() throws IOException {
.put(ScriptService.SCRIPT_CACHE_SIZE_SETTING.getConcreteSettingForNamespace("field").getKey(), 123)
.put(ScriptService.SCRIPT_MAX_COMPILATIONS_RATE_SETTING.getConcreteSettingForNamespace("score").getKey(), "50/5m")
.build());
assertSettingDeprecationsAndWarnings(new Setting<?>[]{SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING});
}

public void testFallbackContextSettings() {
Expand All @@ -432,7 +426,6 @@ public void testFallbackContextSettings() {

assertEquals(cacheExpireFooParsed, ScriptService.SCRIPT_CACHE_EXPIRE_SETTING.getConcreteSettingForNamespace("foo").get(s));
assertEquals(cacheExpireBackupParsed, ScriptService.SCRIPT_CACHE_EXPIRE_SETTING.getConcreteSettingForNamespace("bar").get(s));
assertSettingDeprecationsAndWarnings(new Setting<?>[]{SCRIPT_GENERAL_CACHE_SIZE_SETTING, SCRIPT_GENERAL_CACHE_EXPIRE_SETTING});
}

public void testUseContextSettingValue() {
Expand All @@ -449,7 +442,6 @@ public void testUseContextSettingValue() {
});

assertEquals("parameter must contain a positive integer and a timevalue, i.e. 10/1m, but was [use-context]", illegal.getMessage());
assertSettingDeprecationsAndWarnings(new Setting<?>[]{SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING});
}

public void testCacheHolderGeneralConstructor() throws IOException {
Expand All @@ -463,7 +455,6 @@ public void testCacheHolderGeneralConstructor() throws IOException {
assertNotNull(holder.general);
assertNull(holder.contextCache);
assertEquals(holder.general.rate, new ScriptCache.CompilationRate(compilationRate));
assertSettingDeprecationsAndWarnings(new Setting<?>[]{SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING});
}

public void testCacheHolderContextConstructor() throws IOException {
Expand Down Expand Up @@ -503,7 +494,6 @@ public void testCompilationRateUnlimitedContextOnly() throws IOException {
ScriptService.UNLIMITED_COMPILATION_RATE_KEY)
.put(SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING.getKey(), ScriptService.USE_CONTEXT_RATE_KEY)
.build());
assertSettingDeprecationsAndWarnings(new Setting<?>[]{SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING});
}

public void testDisableCompilationRateSetting() throws IOException {
Expand Down Expand Up @@ -532,7 +522,6 @@ public void testDisableCompilationRateSetting() throws IOException {
buildScriptService(Settings.builder()
.put("script.disable_max_compilations_rate", true)
.build());
assertSettingDeprecationsAndWarnings(new Setting<?>[]{SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING});
}

public void testCacheHolderChangeSettings() throws IOException {
Expand Down Expand Up @@ -604,8 +593,6 @@ public void testCacheHolderChangeSettings() throws IOException {
Settings.builder().put(SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING.getKey(), bRate).build()
);
assertEquals(holder, scriptService.cacheHolder.get());

assertSettingDeprecationsAndWarnings(new Setting<?>[]{SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING});
}

public void testFallbackToContextDefaults() throws IOException {
Expand Down Expand Up @@ -649,8 +636,6 @@ public void testFallbackToContextDefaults() throws IOException {
assertEquals(ingest.maxCompilationRateDefault, holder.contextCache.get(name).get().rate.asTuple());
assertEquals(ingest.cacheSizeDefault, holder.contextCache.get(name).get().cacheSize);
assertEquals(ingest.cacheExpireDefault, holder.contextCache.get(name).get().cacheExpire);

assertSettingDeprecationsAndWarnings(new Setting<?>[]{SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING});
}

private void assertCompileRejected(String lang, String script, ScriptType scriptType, ScriptContext<?> scriptContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ private DeprecationChecks() {
NodeDeprecationChecks.checkThreadPoolListenerSize(settings),
NodeDeprecationChecks::checkClusterRemoteConnectSetting,
NodeDeprecationChecks::checkNodeLocalStorageSetting,
NodeDeprecationChecks::checkGeneralScriptSizeSetting,
NodeDeprecationChecks::checkGeneralScriptExpireSetting,
NodeDeprecationChecks::checkGeneralScriptCompileSettings,
(settings, pluginsAndModules, clusterState, licenseState) ->
NodeDeprecationChecks.checkNodeBasicLicenseFeatureEnabledSetting(settings, XPackSettings.ENRICH_ENABLED_SETTING),
(settings, pluginsAndModules, clusterState, licenseState) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,42 +311,6 @@ public static DeprecationIssue checkNodeBasicLicenseFeatureEnabledSetting(final
);
}

public static DeprecationIssue checkGeneralScriptSizeSetting(final Settings settings, final PluginsAndModules pluginsAndModules,
final ClusterState clusterState, final XPackLicenseState licenseState) {
return checkDeprecatedSetting(
settings,
pluginsAndModules,
ScriptService.SCRIPT_GENERAL_CACHE_SIZE_SETTING,
ScriptService.SCRIPT_CACHE_SIZE_SETTING,
"a script context",
"https://ela.st/es-deprecation-7-script-cache-size-setting"
);
}

public static DeprecationIssue checkGeneralScriptExpireSetting(final Settings settings, final PluginsAndModules pluginsAndModules,
final ClusterState clusterState, final XPackLicenseState licenseState) {
return checkDeprecatedSetting(
settings,
pluginsAndModules,
ScriptService.SCRIPT_GENERAL_CACHE_EXPIRE_SETTING,
ScriptService.SCRIPT_CACHE_EXPIRE_SETTING,
"a script context",
"https://ela.st/es-deprecation-7-script-cache-expire-setting"
);
}

public static DeprecationIssue checkGeneralScriptCompileSettings(final Settings settings, final PluginsAndModules pluginsAndModules,
final ClusterState clusterState, final XPackLicenseState licenseState) {
return checkDeprecatedSetting(
settings,
pluginsAndModules,
ScriptService.SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING,
ScriptService.SCRIPT_MAX_COMPILATIONS_RATE_SETTING,
"a script context",
"https://ela.st/es-deprecation-7-script-max-compilations-rate-setting"
);
}

public static DeprecationIssue checkLegacyRoleSettings(
final Setting<Boolean> legacyRoleSetting,
final Settings settings,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,54 +423,6 @@ public void testThreadPoolListenerSize() {
assertSettingDeprecationsAndWarnings(new String[]{"thread_pool.listener.size"});
}

public void testGeneralScriptSizeSetting() {
final int size = randomIntBetween(1, 4);
final Settings settings = Settings.builder().put("script.cache.max_size", size).build();
final PluginsAndModules pluginsAndModules = new PluginsAndModules(Collections.emptyList(), Collections.emptyList());
final XPackLicenseState licenseState = new XPackLicenseState(Settings.EMPTY, () -> 0);
final List<DeprecationIssue> issues = getDeprecationIssues(settings, pluginsAndModules, licenseState);
final DeprecationIssue expected = new DeprecationIssue(
DeprecationIssue.Level.CRITICAL,
"setting [script.cache.max_size] is deprecated in favor of grouped setting [script.context.*.cache_max_size]",
"https://ela.st/es-deprecation-7-script-cache-size-setting",
"the setting [script.cache.max_size] is currently set to [" + size + "], instead set [script.context.*.cache_max_size] " +
"to [" + size + "] where * is a script context", false, null);
assertThat(issues, hasItem(expected));
assertSettingDeprecationsAndWarnings(new Setting<?>[]{ScriptService.SCRIPT_GENERAL_CACHE_SIZE_SETTING});
}

public void testGeneralScriptExpireSetting() {
final String expire = randomIntBetween(1, 4) + "m";
final Settings settings = Settings.builder().put("script.cache.expire", expire).build();
final PluginsAndModules pluginsAndModules = new PluginsAndModules(Collections.emptyList(), Collections.emptyList());
final XPackLicenseState licenseState = new XPackLicenseState(Settings.EMPTY, () -> 0);
final List<DeprecationIssue> issues = getDeprecationIssues(settings, pluginsAndModules, licenseState);
final DeprecationIssue expected = new DeprecationIssue(
DeprecationIssue.Level.CRITICAL,
"setting [script.cache.expire] is deprecated in favor of grouped setting [script.context.*.cache_expire]",
"https://ela.st/es-deprecation-7-script-cache-expire-setting",
"the setting [script.cache.expire] is currently set to [" + expire + "], instead set [script.context.*.cache_expire] to " +
"[" + expire + "] where * is a script context", false, null);
assertThat(issues, hasItem(expected));
assertSettingDeprecationsAndWarnings(new Setting<?>[]{ScriptService.SCRIPT_GENERAL_CACHE_EXPIRE_SETTING});
}

public void testGeneralScriptCompileSettings() {
final String rate = randomIntBetween(1, 100) + "/" + randomIntBetween(1, 200) + "m";
final Settings settings = Settings.builder().put("script.max_compilations_rate", rate).build();
final PluginsAndModules pluginsAndModules = new PluginsAndModules(Collections.emptyList(), Collections.emptyList());
final XPackLicenseState licenseState = new XPackLicenseState(Settings.EMPTY, () -> 0);
final List<DeprecationIssue> issues = getDeprecationIssues(settings, pluginsAndModules, licenseState);
final DeprecationIssue expected = new DeprecationIssue(
DeprecationIssue.Level.CRITICAL,
"setting [script.max_compilations_rate] is deprecated in favor of grouped setting [script.context.*.max_compilations_rate]",
"https://ela.st/es-deprecation-7-script-max-compilations-rate-setting",
"the setting [script.max_compilations_rate] is currently set to [" + rate +
"], instead set [script.context.*.max_compilations_rate] to [" + rate + "] where * is a script context", false, null);
assertThat(issues, hasItem(expected));
assertSettingDeprecationsAndWarnings(new Setting<?>[]{ScriptService.SCRIPT_GENERAL_MAX_COMPILATIONS_RATE_SETTING});
}

public void testClusterRemoteConnectSetting() {
final boolean value = randomBoolean();
final Settings settings = Settings.builder().put(RemoteClusterService.ENABLE_REMOTE_CLUSTERS.getKey(), value).build();
Expand Down

0 comments on commit 24e5e7f

Please sign in to comment.