Skip to content

Commit

Permalink
ResourceWatcher: Rename settings to prevent watcher clash
Browse files Browse the repository at this point in the history
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 elastic#11033 to log deprecated settings and their alternative at
startup.

Closes elastic#11175
  • Loading branch information
spinscale committed May 26, 2015
1 parent 045f01c commit 8552121
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docs/reference/modules/scripting.asciidoc
Expand Up @@ -342,7 +342,7 @@ appropriate language.
The `config/scripts` directory is scanned periodically for changes.
New and changed scripts are reloaded and deleted script are removed
from preloaded scripts cache. The reload frequency can be specified
using `watcher.interval` setting, which defaults to `60s`.
using `resource.reload.interval` setting, which defaults to `60s`.
To disable script reloading completely set `script.auto_reload_enabled`
to `false`.

Expand Down
Expand Up @@ -19,6 +19,7 @@

package org.elasticsearch.common.component;

import com.google.common.base.Strings;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;
Expand Down Expand Up @@ -51,4 +52,13 @@ public AbstractComponent(Settings settings, Class customClass) {
public final String nodeName() {
return settings.get("name", "");
}

/**
* Checks for a deprecated setting and logs the correct alternative
*/
protected void logDeprecatedSetting(String settingName, String alternativeName) {
if (!Strings.isNullOrEmpty(settings.get(settingName))) {
deprecationLogger.deprecated("Setting [{}] is deprecated, use [{}] instead", settingName, alternativeName);
}
}
}
Expand Up @@ -35,12 +35,12 @@
*
* Other elasticsearch services can register their resource watchers with this service using {@link #add(ResourceWatcher)}
* method. This service will call {@link org.elasticsearch.watcher.ResourceWatcher#checkAndNotify()} method of all
* registered watcher periodically. The frequency of checks can be specified using {@code watcher.interval} setting, which
* defaults to {@code 60s}. The service can be disabled by setting {@code watcher.enabled} setting to {@code false}.
* registered watcher periodically. The frequency of checks can be specified using {@code resource.reload.interval} setting, which
* defaults to {@code 60s}. The service can be disabled by setting {@code resource.reload.enabled} setting to {@code false}.
*/
public class ResourceWatcherService extends AbstractLifecycleComponent<ResourceWatcherService> {

public static enum Frequency {
public enum Frequency {

/**
* Defaults to 5 seconds
Expand All @@ -59,7 +59,7 @@ public static enum Frequency {

final TimeValue interval;

private Frequency(TimeValue interval) {
Frequency(TimeValue interval) {
this.interval = interval;
}
}
Expand All @@ -78,15 +78,21 @@ private Frequency(TimeValue interval) {
@Inject
public ResourceWatcherService(Settings settings, ThreadPool threadPool) {
super(settings);
this.enabled = settings.getAsBoolean("watcher.enabled", true);
this.enabled = settings.getAsBoolean("resource.reload.enabled", true);
this.threadPool = threadPool;

TimeValue interval = settings.getAsTime("watcher.interval.low", Frequency.LOW.interval);
TimeValue interval = settings.getAsTime("resource.reload.interval.low", Frequency.LOW.interval);
lowMonitor = new ResourceMonitor(interval, Frequency.LOW);
interval = settings.getAsTime("watcher.interval.medium", settings.getAsTime("watcher.interval", Frequency.MEDIUM.interval));
interval = settings.getAsTime("resource.reload.interval.medium", settings.getAsTime("resource.reload.interval", Frequency.MEDIUM.interval));
mediumMonitor = new ResourceMonitor(interval, Frequency.MEDIUM);
interval = settings.getAsTime("watcher.interval.high", Frequency.HIGH.interval);
interval = settings.getAsTime("resource.reload.interval.high", Frequency.HIGH.interval);
highMonitor = new ResourceMonitor(interval, Frequency.HIGH);

logDeprecatedSetting("watcher.enabled", "resource.reload.enabled");
logDeprecatedSetting("watcher.interval", "resource.reload.interval");
logDeprecatedSetting("watcher.interval.low", "resource.reload.interval.low");
logDeprecatedSetting("watcher.interval.medium", "resource.reload.interval.medium");
logDeprecatedSetting("watcher.interval.high", "resource.reload.interval.high");
}

@Override
Expand Down
Expand Up @@ -45,7 +45,7 @@ public void testSettings() throws Exception {

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

// checking custom
settings = Settings.builder()
.put("watcher.interval.high", "10s")
.put("watcher.interval.medium", "20s")
.put("watcher.interval.low", "30s")
.put("resource.reload.interval.high", "10s")
.put("resource.reload.interval.medium", "20s")
.put("resource.reload.interval.low", "30s")
.build();
service = new ResourceWatcherService(settings, threadPool);
assertThat(service.highMonitor.interval.millis(), is(timeValueSeconds(10).millis()));
Expand Down

0 comments on commit 8552121

Please sign in to comment.