Skip to content

Commit 3bda78e

Browse files
committed
ResourceWatcher: Rename settings to prevent watcher clash
The ResourceWatcher used settings prefixed `watcher.`, which potentially could clash with the watcher plugin. In order to prevent confusion, the settings have been renamed to `resource.reload` prefixes. This also uses the deprecation logging infrastructure introduced in #11033 to log deprecated settings and their alternative at startup. Closes #11175
1 parent 57a94a1 commit 3bda78e

File tree

5 files changed

+49
-13
lines changed

5 files changed

+49
-13
lines changed

core/src/main/java/org/elasticsearch/common/component/AbstractComponent.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.elasticsearch.common.component;
2121

22+
import com.google.common.base.Strings;
2223
import org.elasticsearch.common.logging.DeprecationLogger;
2324
import org.elasticsearch.common.logging.ESLogger;
2425
import org.elasticsearch.common.logging.Loggers;
@@ -51,4 +52,22 @@ public AbstractComponent(Settings settings, Class customClass) {
5152
public final String nodeName() {
5253
return settings.get("name", "");
5354
}
55+
56+
/**
57+
* Checks for a deprecated setting and logs the correct alternative
58+
*/
59+
protected void logDeprecatedSetting(String settingName, String alternativeName) {
60+
if (!Strings.isNullOrEmpty(settings.get(settingName))) {
61+
deprecationLogger.deprecated("Setting [{}] is deprecated, use [{}] instead", settingName, alternativeName);
62+
}
63+
}
64+
65+
/**
66+
* Checks for a removed setting and logs the correct alternative
67+
*/
68+
protected void logRemovedSetting(String settingName, String alternativeName) {
69+
if (!Strings.isNullOrEmpty(settings.get(settingName))) {
70+
deprecationLogger.deprecated("Setting [{}] has been removed, use [{}] instead", settingName, alternativeName);
71+
}
72+
}
5473
}

core/src/main/java/org/elasticsearch/watcher/ResourceWatcherService.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@
3535
*
3636
* Other elasticsearch services can register their resource watchers with this service using {@link #add(ResourceWatcher)}
3737
* method. This service will call {@link org.elasticsearch.watcher.ResourceWatcher#checkAndNotify()} method of all
38-
* registered watcher periodically. The frequency of checks can be specified using {@code watcher.interval} setting, which
39-
* defaults to {@code 60s}. The service can be disabled by setting {@code watcher.enabled} setting to {@code false}.
38+
* registered watcher periodically. The frequency of checks can be specified using {@code resource.reload.interval} setting, which
39+
* defaults to {@code 60s}. The service can be disabled by setting {@code resource.reload.enabled} setting to {@code false}.
4040
*/
4141
public class ResourceWatcherService extends AbstractLifecycleComponent<ResourceWatcherService> {
4242

43-
public static enum Frequency {
43+
public enum Frequency {
4444

4545
/**
4646
* Defaults to 5 seconds
@@ -59,7 +59,7 @@ public static enum Frequency {
5959

6060
final TimeValue interval;
6161

62-
private Frequency(TimeValue interval) {
62+
Frequency(TimeValue interval) {
6363
this.interval = interval;
6464
}
6565
}
@@ -78,15 +78,21 @@ private Frequency(TimeValue interval) {
7878
@Inject
7979
public ResourceWatcherService(Settings settings, ThreadPool threadPool) {
8080
super(settings);
81-
this.enabled = settings.getAsBoolean("watcher.enabled", true);
81+
this.enabled = settings.getAsBoolean("resource.reload.enabled", true);
8282
this.threadPool = threadPool;
8383

84-
TimeValue interval = settings.getAsTime("watcher.interval.low", Frequency.LOW.interval);
84+
TimeValue interval = settings.getAsTime("resource.reload.interval.low", Frequency.LOW.interval);
8585
lowMonitor = new ResourceMonitor(interval, Frequency.LOW);
86-
interval = settings.getAsTime("watcher.interval.medium", settings.getAsTime("watcher.interval", Frequency.MEDIUM.interval));
86+
interval = settings.getAsTime("resource.reload.interval.medium", settings.getAsTime("resource.reload.interval", Frequency.MEDIUM.interval));
8787
mediumMonitor = new ResourceMonitor(interval, Frequency.MEDIUM);
88-
interval = settings.getAsTime("watcher.interval.high", Frequency.HIGH.interval);
88+
interval = settings.getAsTime("resource.reload.interval.high", Frequency.HIGH.interval);
8989
highMonitor = new ResourceMonitor(interval, Frequency.HIGH);
90+
91+
logRemovedSetting("watcher.enabled", "resource.reload.enabled");
92+
logRemovedSetting("watcher.interval", "resource.reload.interval");
93+
logRemovedSetting("watcher.interval.low", "resource.reload.interval.low");
94+
logRemovedSetting("watcher.interval.medium", "resource.reload.interval.medium");
95+
logRemovedSetting("watcher.interval.high", "resource.reload.interval.high");
9096
}
9197

9298
@Override

core/src/test/java/org/elasticsearch/watcher/ResourceWatcherServiceTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void testSettings() throws Exception {
4545

4646
// checking bwc
4747
settings = Settings.builder()
48-
.put("watcher.interval", "40s") // only applies to medium
48+
.put("resource.reload.interval", "40s") // only applies to medium
4949
.build();
5050
service = new ResourceWatcherService(settings, threadPool);
5151
assertThat(service.highMonitor.interval.millis(), is(timeValueSeconds(5).millis()));
@@ -54,9 +54,9 @@ public void testSettings() throws Exception {
5454

5555
// checking custom
5656
settings = Settings.builder()
57-
.put("watcher.interval.high", "10s")
58-
.put("watcher.interval.medium", "20s")
59-
.put("watcher.interval.low", "30s")
57+
.put("resource.reload.interval.high", "10s")
58+
.put("resource.reload.interval.medium", "20s")
59+
.put("resource.reload.interval.low", "30s")
6060
.build();
6161
service = new ResourceWatcherService(settings, threadPool);
6262
assertThat(service.highMonitor.interval.millis(), is(timeValueSeconds(10).millis()));

docs/reference/migration/migrate_2_0.asciidoc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,3 +685,14 @@ curl -XGET 'localhost:9200/test/_search?fields=_timestamp,foo'
685685
}
686686
}
687687
---------------
688+
689+
=== Settings for resource watcher have been renamed
690+
691+
The setting names for configuring the resource watcher have been renamed
692+
to prevent clashes with the watcher plugin
693+
694+
* `watcher.enabled` is now `resource.reload.enabled`
695+
* `watcher.interval` is now `resource.reload.interval`
696+
* `watcher.interval.low` is now `resource.reload.interval.low`
697+
* `watcher.interval.medium` is now `resource.reload.interval.medium`
698+
* `watcher.interval.high` is now `resource.reload.interval.high`

docs/reference/modules/scripting.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ appropriate language.
342342
The `config/scripts` directory is scanned periodically for changes.
343343
New and changed scripts are reloaded and deleted script are removed
344344
from preloaded scripts cache. The reload frequency can be specified
345-
using `watcher.interval` setting, which defaults to `60s`.
345+
using `resource.reload.interval` setting, which defaults to `60s`.
346346
To disable script reloading completely set `script.auto_reload_enabled`
347347
to `false`.
348348

0 commit comments

Comments
 (0)