Remove static stuff in MarvelSettings
Original commit: elastic/x-pack-elasticsearch@e534397299
This commit is contained in:
parent
78d006dbcc
commit
72675e711d
|
@ -7,6 +7,7 @@ package org.elasticsearch.marvel;
|
||||||
|
|
||||||
import org.elasticsearch.client.Client;
|
import org.elasticsearch.client.Client;
|
||||||
import org.elasticsearch.cluster.ClusterModule;
|
import org.elasticsearch.cluster.ClusterModule;
|
||||||
|
import org.elasticsearch.cluster.settings.Validator;
|
||||||
import org.elasticsearch.common.component.LifecycleComponent;
|
import org.elasticsearch.common.component.LifecycleComponent;
|
||||||
import org.elasticsearch.common.inject.Module;
|
import org.elasticsearch.common.inject.Module;
|
||||||
import org.elasticsearch.common.logging.ESLogger;
|
import org.elasticsearch.common.logging.ESLogger;
|
||||||
|
@ -18,7 +19,6 @@ import org.elasticsearch.marvel.agent.exporter.ExporterModule;
|
||||||
import org.elasticsearch.marvel.agent.exporter.Exporters;
|
import org.elasticsearch.marvel.agent.exporter.Exporters;
|
||||||
import org.elasticsearch.marvel.agent.renderer.RendererModule;
|
import org.elasticsearch.marvel.agent.renderer.RendererModule;
|
||||||
import org.elasticsearch.marvel.agent.settings.MarvelModule;
|
import org.elasticsearch.marvel.agent.settings.MarvelModule;
|
||||||
import org.elasticsearch.marvel.agent.settings.MarvelSetting;
|
|
||||||
import org.elasticsearch.marvel.agent.settings.MarvelSettings;
|
import org.elasticsearch.marvel.agent.settings.MarvelSettings;
|
||||||
import org.elasticsearch.marvel.license.LicenseModule;
|
import org.elasticsearch.marvel.license.LicenseModule;
|
||||||
import org.elasticsearch.marvel.license.LicenseService;
|
import org.elasticsearch.marvel.license.LicenseService;
|
||||||
|
@ -32,6 +32,7 @@ import org.elasticsearch.tribe.TribeService;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class MarvelPlugin extends Plugin {
|
public class MarvelPlugin extends Plugin {
|
||||||
|
|
||||||
|
@ -110,9 +111,8 @@ public class MarvelPlugin extends Plugin {
|
||||||
|
|
||||||
public void onModule(ClusterModule module) {
|
public void onModule(ClusterModule module) {
|
||||||
Exporters.registerDynamicSettings(module);
|
Exporters.registerDynamicSettings(module);
|
||||||
// MarvelSettingsService
|
for (Map.Entry<String, Validator> setting : MarvelSettings.dynamicSettings().entrySet()) {
|
||||||
for (MarvelSetting setting : MarvelSettings.dynamicSettings()) {
|
module.registerClusterDynamicSetting(setting.getKey(), setting.getValue());
|
||||||
module.registerClusterDynamicSetting(setting.dynamicSettingName(), setting.dynamicValidator());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
package org.elasticsearch.marvel.agent.settings;
|
package org.elasticsearch.marvel.agent.settings;
|
||||||
|
|
||||||
import org.elasticsearch.ElasticsearchParseException;
|
import org.elasticsearch.ElasticsearchParseException;
|
||||||
import org.elasticsearch.cluster.settings.Validator;
|
|
||||||
import org.elasticsearch.common.Strings;
|
import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.unit.TimeValue;
|
import org.elasticsearch.common.unit.TimeValue;
|
||||||
|
@ -17,15 +16,15 @@ public abstract class MarvelSetting<V> {
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
private final String description;
|
private final String description;
|
||||||
private final boolean dynamic;
|
|
||||||
|
|
||||||
|
private final V defaultValue;
|
||||||
private volatile V value;
|
private volatile V value;
|
||||||
|
|
||||||
MarvelSetting(String name, String description, V defaultValue, boolean dynamic) {
|
MarvelSetting(String name, String description, V defaultValue) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
|
this.defaultValue = defaultValue;
|
||||||
this.value = defaultValue;
|
this.value = defaultValue;
|
||||||
this.dynamic = dynamic;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract boolean onRefresh(Settings settings);
|
abstract boolean onRefresh(Settings settings);
|
||||||
|
@ -42,6 +41,10 @@ public abstract class MarvelSetting<V> {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public V getDefaultValue() {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized void setValue(V value) {
|
public synchronized void setValue(V value) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
@ -50,47 +53,35 @@ public abstract class MarvelSetting<V> {
|
||||||
return getValue() != null ? getValue().toString() : "null";
|
return getValue() != null ? getValue().toString() : "null";
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isDynamic() {
|
|
||||||
return dynamic;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String dynamicSettingName() {
|
|
||||||
return getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Validator dynamicValidator() {
|
|
||||||
return Validator.EMPTY;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "marvel setting [" + getName() + " : " + getValueAsString() + "]";
|
return "marvel setting [" + getName() + " : " + getValueAsString() + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BooleanSetting booleanSetting(String name, Boolean defaultValue, String description, boolean dynamic) {
|
public static BooleanSetting booleanSetting(String name, Boolean defaultValue, String description) {
|
||||||
return new BooleanSetting(name, description, defaultValue, dynamic);
|
return new BooleanSetting(name, description, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static StringSetting stringSetting(String name, String defaultValue, String description, boolean dynamic) {
|
public static StringSetting stringSetting(String name, String defaultValue, String description) {
|
||||||
return new StringSetting(name, description, defaultValue, dynamic);
|
return new StringSetting(name, description, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static StringArraySetting arraySetting(String name, String[] defaultValue, String description, boolean dynamic) {
|
public static StringArraySetting arraySetting(String name, String[] defaultValue, String description) {
|
||||||
return new StringArraySetting(name, description, defaultValue, dynamic);
|
return new StringArraySetting(name, description, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TimeValueSetting timeSetting(String name, TimeValue defaultValue, String description, boolean dynamic) {
|
public static TimeValueSetting timeSetting(String name, TimeValue defaultValue, String description) {
|
||||||
return new TimeValueSetting(name, description, defaultValue, dynamic);
|
return new TimeValueSetting(name, description, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TimeoutValueSetting timeoutSetting(String name, TimeValue defaultTimeoutValue, String description, boolean dynamic) {
|
public static TimeoutValueSetting timeoutSetting(String name, TimeValue defaultTimeoutValue, String description) {
|
||||||
return new TimeoutValueSetting(name, description, defaultTimeoutValue, dynamic);
|
return new TimeoutValueSetting(name, description, defaultTimeoutValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
static class BooleanSetting extends MarvelSetting<Boolean> {
|
static class BooleanSetting extends MarvelSetting<Boolean> {
|
||||||
|
|
||||||
BooleanSetting(String name, String description, Boolean defaultValue, boolean dynamic) {
|
BooleanSetting(String name, String description, Boolean defaultValue) {
|
||||||
super(name, description, defaultValue, dynamic);
|
super(name, description, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -102,17 +93,12 @@ public abstract class MarvelSetting<V> {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Validator dynamicValidator() {
|
|
||||||
return Validator.BOOLEAN;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static class StringSetting extends MarvelSetting<String> {
|
static class StringSetting extends MarvelSetting<String> {
|
||||||
|
|
||||||
StringSetting(String name, String description, String defaultValue, boolean dynamic) {
|
StringSetting(String name, String description, String defaultValue) {
|
||||||
super(name, description, defaultValue, dynamic);
|
super(name, description, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -128,8 +114,8 @@ public abstract class MarvelSetting<V> {
|
||||||
|
|
||||||
static class StringArraySetting extends MarvelSetting<String[]> {
|
static class StringArraySetting extends MarvelSetting<String[]> {
|
||||||
|
|
||||||
StringArraySetting(String name, String description, String[] defaultValue, boolean dynamic) {
|
StringArraySetting(String name, String description, String[] defaultValue) {
|
||||||
super(name, description, defaultValue, dynamic);
|
super(name, description, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -142,12 +128,6 @@ public abstract class MarvelSetting<V> {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String dynamicSettingName() {
|
|
||||||
// array settings
|
|
||||||
return super.dynamicSettingName() + ".*";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getValueAsString() {
|
public String getValueAsString() {
|
||||||
return Strings.arrayToCommaDelimitedString(getValue());
|
return Strings.arrayToCommaDelimitedString(getValue());
|
||||||
|
@ -156,8 +136,8 @@ public abstract class MarvelSetting<V> {
|
||||||
|
|
||||||
static class TimeValueSetting extends MarvelSetting<TimeValue> {
|
static class TimeValueSetting extends MarvelSetting<TimeValue> {
|
||||||
|
|
||||||
TimeValueSetting(String name, String description, TimeValue defaultValue, boolean dynamic) {
|
TimeValueSetting(String name, String description, TimeValue defaultValue) {
|
||||||
super(name, description, defaultValue, dynamic);
|
super(name, description, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -184,22 +164,12 @@ public abstract class MarvelSetting<V> {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Validator dynamicValidator() {
|
|
||||||
return Validator.TIME;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static class TimeoutValueSetting extends TimeValueSetting {
|
static class TimeoutValueSetting extends TimeValueSetting {
|
||||||
|
|
||||||
TimeoutValueSetting(String name, String description, TimeValue defaultValue, boolean dynamic) {
|
TimeoutValueSetting(String name, String description, TimeValue defaultValue) {
|
||||||
super(name, description, defaultValue, dynamic);
|
super(name, description, defaultValue);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Validator dynamicValidator() {
|
|
||||||
return Validator.TIMEOUT;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
*/
|
*/
|
||||||
package org.elasticsearch.marvel.agent.settings;
|
package org.elasticsearch.marvel.agent.settings;
|
||||||
|
|
||||||
|
import org.elasticsearch.cluster.settings.Validator;
|
||||||
import org.elasticsearch.common.Strings;
|
import org.elasticsearch.common.Strings;
|
||||||
import org.elasticsearch.common.component.AbstractComponent;
|
import org.elasticsearch.common.component.AbstractComponent;
|
||||||
import org.elasticsearch.common.inject.Inject;
|
import org.elasticsearch.common.inject.Inject;
|
||||||
|
@ -13,7 +14,10 @@ import org.elasticsearch.common.unit.TimeValue;
|
||||||
import org.elasticsearch.marvel.MarvelPlugin;
|
import org.elasticsearch.marvel.MarvelPlugin;
|
||||||
import org.elasticsearch.node.settings.NodeSettingsService;
|
import org.elasticsearch.node.settings.NodeSettingsService;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.elasticsearch.marvel.agent.settings.MarvelSetting.*;
|
import static org.elasticsearch.marvel.agent.settings.MarvelSetting.*;
|
||||||
|
|
||||||
|
@ -37,60 +41,74 @@ public class MarvelSettings extends AbstractComponent implements NodeSettingsSer
|
||||||
public static final String COLLECTORS = PREFIX + "collectors";
|
public static final String COLLECTORS = PREFIX + "collectors";
|
||||||
public static final String LICENSE_GRACE_PERIOD = PREFIX + "license.grace.period";
|
public static final String LICENSE_GRACE_PERIOD = PREFIX + "license.grace.period";
|
||||||
|
|
||||||
private static Map<String, ? extends MarvelSetting> MARVEL_SETTINGS = Collections.EMPTY_MAP;
|
private Map<String, ? extends MarvelSetting> settings = Collections.EMPTY_MAP;
|
||||||
|
|
||||||
static {
|
|
||||||
Map<String, MarvelSetting> map = new HashMap<>();
|
|
||||||
map.put(INTERVAL, timeSetting(INTERVAL, TimeValue.timeValueSeconds(10),
|
|
||||||
"Sampling interval between two collections (default to 10s)", true));
|
|
||||||
map.put(STARTUP_DELAY, timeSetting(STARTUP_DELAY, null,
|
|
||||||
"Waiting time before the agent start to collect data (default to sampling interval)", false));
|
|
||||||
map.put(INDEX_STATS_TIMEOUT, timeoutSetting(INDEX_STATS_TIMEOUT, TimeValue.timeValueMinutes(10),
|
|
||||||
"Timeout value when collecting index statistics (default to 10m)", true));
|
|
||||||
map.put(INDICES_STATS_TIMEOUT, timeoutSetting(INDICES_STATS_TIMEOUT, TimeValue.timeValueMinutes(10),
|
|
||||||
"Timeout value when collecting total indices statistics (default to 10m)", true));
|
|
||||||
map.put(INDICES, arraySetting(INDICES, Strings.EMPTY_ARRAY,
|
|
||||||
"List of indices names whose stats will be exported (default to all indices)", true));
|
|
||||||
map.put(CLUSTER_STATE_TIMEOUT, timeoutSetting(CLUSTER_STATE_TIMEOUT, TimeValue.timeValueMinutes(10),
|
|
||||||
"Timeout value when collecting the cluster state (default to 10m)", true));
|
|
||||||
map.put(CLUSTER_STATS_TIMEOUT, timeoutSetting(CLUSTER_STATS_TIMEOUT, TimeValue.timeValueMinutes(10),
|
|
||||||
"Timeout value when collecting the cluster statistics (default to 10m)", true));
|
|
||||||
map.put(INDEX_RECOVERY_TIMEOUT, timeoutSetting(INDEX_RECOVERY_TIMEOUT, TimeValue.timeValueMinutes(10),
|
|
||||||
"Timeout value when collecting the recovery information (default to 10m)", true));
|
|
||||||
map.put(INDEX_RECOVERY_ACTIVE_ONLY, booleanSetting(INDEX_RECOVERY_ACTIVE_ONLY, Boolean.FALSE,
|
|
||||||
"Flag to indicate if only active recoveries should be collected (default to false: all recoveries are collected)", true));
|
|
||||||
map.put(COLLECTORS, arraySetting(COLLECTORS, Strings.EMPTY_ARRAY,
|
|
||||||
"List of collectors allowed to collect data (default to all)", false));
|
|
||||||
map.put(LICENSE_GRACE_PERIOD, timeSetting(LICENSE_GRACE_PERIOD, MAX_LICENSE_GRACE_PERIOD,
|
|
||||||
"Period during which the agent continues to collect data even if the license is expired (default to 7 days, cannot be greater than 7 days)", false));
|
|
||||||
MARVEL_SETTINGS = Collections.unmodifiableMap(map);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public MarvelSettings(Settings clusterSettings, NodeSettingsService nodeSettingsService) {
|
public MarvelSettings(Settings clusterSettings, NodeSettingsService nodeSettingsService) {
|
||||||
super(clusterSettings);
|
super(clusterSettings);
|
||||||
|
|
||||||
logger.trace("initializing marvel settings:");
|
logger.trace("initializing marvel settings");
|
||||||
updateSettings(clusterSettings, false);
|
this.settings = defaultSettings();
|
||||||
|
|
||||||
|
logger.trace("updating marvel settings with cluster settings");
|
||||||
|
updateSettings(clusterSettings);
|
||||||
|
|
||||||
logger.trace("registering the service as a node settings listener");
|
logger.trace("registering the service as a node settings listener");
|
||||||
nodeSettingsService.addListener(this);
|
nodeSettingsService.addListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Map<String, MarvelSetting> defaultSettings() {
|
||||||
|
Map<String, MarvelSetting> map = new HashMap<>();
|
||||||
|
map.put(INTERVAL, timeSetting(INTERVAL, TimeValue.timeValueSeconds(10),
|
||||||
|
"Sampling interval between two collections (default to 10s)"));
|
||||||
|
map.put(STARTUP_DELAY, timeSetting(STARTUP_DELAY, null,
|
||||||
|
"Waiting time before the agent start to collect data (default to sampling interval)"));
|
||||||
|
map.put(INDEX_STATS_TIMEOUT, timeoutSetting(INDEX_STATS_TIMEOUT, TimeValue.timeValueMinutes(10),
|
||||||
|
"Timeout value when collecting index statistics (default to 10m)"));
|
||||||
|
map.put(INDICES_STATS_TIMEOUT, timeoutSetting(INDICES_STATS_TIMEOUT, TimeValue.timeValueMinutes(10),
|
||||||
|
"Timeout value when collecting total indices statistics (default to 10m)"));
|
||||||
|
map.put(INDICES, arraySetting(INDICES, Strings.EMPTY_ARRAY,
|
||||||
|
"List of indices names whose stats will be exported (default to all indices)"));
|
||||||
|
map.put(CLUSTER_STATE_TIMEOUT, timeoutSetting(CLUSTER_STATE_TIMEOUT, TimeValue.timeValueMinutes(10),
|
||||||
|
"Timeout value when collecting the cluster state (default to 10m)"));
|
||||||
|
map.put(CLUSTER_STATS_TIMEOUT, timeoutSetting(CLUSTER_STATS_TIMEOUT, TimeValue.timeValueMinutes(10),
|
||||||
|
"Timeout value when collecting the cluster statistics (default to 10m)"));
|
||||||
|
map.put(INDEX_RECOVERY_TIMEOUT, timeoutSetting(INDEX_RECOVERY_TIMEOUT, TimeValue.timeValueMinutes(10),
|
||||||
|
"Timeout value when collecting the recovery information (default to 10m)"));
|
||||||
|
map.put(INDEX_RECOVERY_ACTIVE_ONLY, booleanSetting(INDEX_RECOVERY_ACTIVE_ONLY, Boolean.FALSE,
|
||||||
|
"Flag to indicate if only active recoveries should be collected (default to false: all recoveries are collected)"));
|
||||||
|
map.put(COLLECTORS, arraySetting(COLLECTORS, Strings.EMPTY_ARRAY,
|
||||||
|
"List of collectors allowed to collect data (default to all)"));
|
||||||
|
map.put(LICENSE_GRACE_PERIOD, timeSetting(LICENSE_GRACE_PERIOD, MAX_LICENSE_GRACE_PERIOD,
|
||||||
|
"Period during which the agent continues to collect data even if the license is expired (default to 7 days, cannot be greater than 7 days)"));
|
||||||
|
return Collections.unmodifiableMap(map);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<String, Validator> dynamicSettings() {
|
||||||
|
Map<String, Validator> dynamics = new HashMap<>();
|
||||||
|
dynamics.put(INTERVAL, Validator.TIME);
|
||||||
|
dynamics.put(INDEX_STATS_TIMEOUT, Validator.TIMEOUT);
|
||||||
|
dynamics.put(INDICES_STATS_TIMEOUT, Validator.TIMEOUT);
|
||||||
|
dynamics.put(INDICES + ".*", Validator.EMPTY);
|
||||||
|
dynamics.put(CLUSTER_STATE_TIMEOUT, Validator.TIMEOUT);
|
||||||
|
dynamics.put(CLUSTER_STATS_TIMEOUT, Validator.TIMEOUT);
|
||||||
|
dynamics.put(INDEX_RECOVERY_TIMEOUT, Validator.TIMEOUT);
|
||||||
|
dynamics.put(INDEX_RECOVERY_ACTIVE_ONLY, Validator.BOOLEAN);
|
||||||
|
return dynamics;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRefreshSettings(Settings clusterSettings) {
|
public void onRefreshSettings(Settings clusterSettings) {
|
||||||
if (clusterSettings.names() == null || clusterSettings.names().isEmpty()) {
|
if (clusterSettings.names() == null || clusterSettings.names().isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
updateSettings(clusterSettings, true);
|
updateSettings(clusterSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void updateSettings(Settings clusterSettings, boolean dynamicOnly) {
|
private void updateSettings(Settings clusterSettings) {
|
||||||
for (MarvelSetting setting : settings()) {
|
for (MarvelSetting setting : settings.values()) {
|
||||||
if (!dynamicOnly || setting.isDynamic()) {
|
if (setting.onRefresh(clusterSettings)) {
|
||||||
if (setting.onRefresh(clusterSettings)) {
|
logger.info("{} updated", setting);
|
||||||
logger.info("{} updated", setting);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -101,8 +119,8 @@ public class MarvelSettings extends AbstractComponent implements NodeSettingsSer
|
||||||
* @param name The given name
|
* @param name The given name
|
||||||
* @return The associated setting, null if not found
|
* @return The associated setting, null if not found
|
||||||
*/
|
*/
|
||||||
synchronized MarvelSetting getSetting(String name) {
|
MarvelSetting getSetting(String name) {
|
||||||
MarvelSetting setting = MARVEL_SETTINGS.get(name);
|
MarvelSetting setting = settings.get(name);
|
||||||
if (setting == null) {
|
if (setting == null) {
|
||||||
throw new IllegalArgumentException("no marvel setting initialized for [" + name + "]");
|
throw new IllegalArgumentException("no marvel setting initialized for [" + name + "]");
|
||||||
}
|
}
|
||||||
|
@ -123,18 +141,8 @@ public class MarvelSettings extends AbstractComponent implements NodeSettingsSer
|
||||||
return (T) setting.getValue();
|
return (T) setting.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Collection<? extends MarvelSetting> settings() {
|
Collection<? extends MarvelSetting> settings() {
|
||||||
return MARVEL_SETTINGS.values();
|
return settings.values();
|
||||||
}
|
|
||||||
|
|
||||||
public static synchronized Collection<MarvelSetting> dynamicSettings() {
|
|
||||||
List<MarvelSetting> list = new ArrayList<>();
|
|
||||||
for (MarvelSetting setting : settings()) {
|
|
||||||
if (setting.isDynamic()) {
|
|
||||||
list.add(setting);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public TimeValue interval() {
|
public TimeValue interval() {
|
||||||
|
|
|
@ -23,9 +23,8 @@ public class MarvelSettingTests extends ESTestCase {
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
defaultValue = randomBoolean();
|
defaultValue = randomBoolean();
|
||||||
}
|
}
|
||||||
boolean dynamic = randomBoolean();
|
|
||||||
|
|
||||||
MarvelSetting.BooleanSetting setting = MarvelSetting.booleanSetting(name, defaultValue, description, dynamic);
|
MarvelSetting.BooleanSetting setting = MarvelSetting.booleanSetting(name, defaultValue, description);
|
||||||
assertThat(setting.getName(), equalTo(name));
|
assertThat(setting.getName(), equalTo(name));
|
||||||
assertThat(setting.getDescription(), equalTo(description));
|
assertThat(setting.getDescription(), equalTo(description));
|
||||||
assertThat(setting.getValue(), equalTo(defaultValue));
|
assertThat(setting.getValue(), equalTo(defaultValue));
|
||||||
|
@ -43,11 +42,10 @@ public class MarvelSettingTests extends ESTestCase {
|
||||||
String description = randomAsciiOfLength(20);
|
String description = randomAsciiOfLength(20);
|
||||||
TimeValue defaultValue = null;
|
TimeValue defaultValue = null;
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
defaultValue = randomParsedTimeValue();
|
defaultValue = newRandomTimeValue();
|
||||||
}
|
}
|
||||||
boolean dynamic = randomBoolean();
|
|
||||||
|
|
||||||
MarvelSetting.TimeValueSetting setting = MarvelSetting.timeSetting(name, defaultValue, description, dynamic);
|
MarvelSetting.TimeValueSetting setting = MarvelSetting.timeSetting(name, defaultValue, description);
|
||||||
assertThat(setting.getName(), equalTo(name));
|
assertThat(setting.getName(), equalTo(name));
|
||||||
assertThat(setting.getDescription(), equalTo(description));
|
assertThat(setting.getDescription(), equalTo(description));
|
||||||
if (defaultValue == null) {
|
if (defaultValue == null) {
|
||||||
|
@ -59,11 +57,11 @@ public class MarvelSettingTests extends ESTestCase {
|
||||||
setting.onRefresh(settingsBuilder().put(name, 15000L).build());
|
setting.onRefresh(settingsBuilder().put(name, 15000L).build());
|
||||||
assertThat(setting.getValue().millis(), equalTo(15000L));
|
assertThat(setting.getValue().millis(), equalTo(15000L));
|
||||||
|
|
||||||
TimeValue updated = randomParsedTimeValue();
|
TimeValue updated = newRandomTimeValue();
|
||||||
setting.onRefresh(settingsBuilder().put(name, updated.toString()).build());
|
setting.onRefresh(settingsBuilder().put(name, updated.toString()).build());
|
||||||
assertThat(setting.getValue().millis(), equalTo(updated.millis()));
|
assertThat(setting.getValue().millis(), equalTo(updated.millis()));
|
||||||
|
|
||||||
updated = randomParsedTimeValue();
|
updated = newRandomTimeValue();
|
||||||
setting.onRefresh(settingsBuilder().put(name, updated.toString()).build());
|
setting.onRefresh(settingsBuilder().put(name, updated.toString()).build());
|
||||||
assertThat(setting.getValue().millis(), equalTo(updated.millis()));
|
assertThat(setting.getValue().millis(), equalTo(updated.millis()));
|
||||||
}
|
}
|
||||||
|
@ -76,9 +74,8 @@ public class MarvelSettingTests extends ESTestCase {
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
defaultValue = randomAsciiOfLength(15);
|
defaultValue = randomAsciiOfLength(15);
|
||||||
}
|
}
|
||||||
boolean dynamic = randomBoolean();
|
|
||||||
|
|
||||||
MarvelSetting.StringSetting setting = MarvelSetting.stringSetting(name, defaultValue, description, dynamic);
|
MarvelSetting.StringSetting setting = MarvelSetting.stringSetting(name, defaultValue, description);
|
||||||
assertThat(setting.getName(), equalTo(name));
|
assertThat(setting.getName(), equalTo(name));
|
||||||
assertThat(setting.getDescription(), equalTo(description));
|
assertThat(setting.getDescription(), equalTo(description));
|
||||||
if (defaultValue == null) {
|
if (defaultValue == null) {
|
||||||
|
@ -107,9 +104,8 @@ public class MarvelSettingTests extends ESTestCase {
|
||||||
if (randomBoolean()) {
|
if (randomBoolean()) {
|
||||||
defaultValue = randomStringArray();
|
defaultValue = randomStringArray();
|
||||||
}
|
}
|
||||||
boolean dynamic = randomBoolean();
|
|
||||||
|
|
||||||
MarvelSetting.StringArraySetting setting = MarvelSetting.arraySetting(name, defaultValue, description, dynamic);
|
MarvelSetting.StringArraySetting setting = MarvelSetting.arraySetting(name, defaultValue, description);
|
||||||
assertThat(setting.getName(), equalTo(name));
|
assertThat(setting.getName(), equalTo(name));
|
||||||
assertThat(setting.getDescription(), equalTo(description));
|
assertThat(setting.getDescription(), equalTo(description));
|
||||||
if (defaultValue == null) {
|
if (defaultValue == null) {
|
||||||
|
@ -130,7 +126,7 @@ public class MarvelSettingTests extends ESTestCase {
|
||||||
assertArrayEquals(setting.getValue(), updated);
|
assertArrayEquals(setting.getValue(), updated);
|
||||||
}
|
}
|
||||||
|
|
||||||
private TimeValue randomParsedTimeValue() {
|
private TimeValue newRandomTimeValue() {
|
||||||
return TimeValue.parseTimeValue(randomFrom("10ms", "1.5s", "1.5m", "1.5h", "1.5d", "1000d"), null, getClass().getSimpleName() + ".unit");
|
return TimeValue.parseTimeValue(randomFrom("10ms", "1.5s", "1.5m", "1.5h", "1.5d", "1000d"), null, getClass().getSimpleName() + ".unit");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,30 +8,24 @@ package org.elasticsearch.marvel.agent.settings;
|
||||||
import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequestBuilder;
|
import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequestBuilder;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
import org.elasticsearch.common.unit.TimeValue;
|
import org.elasticsearch.common.unit.TimeValue;
|
||||||
import org.elasticsearch.license.plugin.LicensePlugin;
|
|
||||||
import org.elasticsearch.marvel.MarvelPlugin;
|
|
||||||
import org.elasticsearch.marvel.test.MarvelIntegTestCase;
|
import org.elasticsearch.marvel.test.MarvelIntegTestCase;
|
||||||
import org.elasticsearch.node.Node;
|
import org.elasticsearch.node.Node;
|
||||||
import org.elasticsearch.plugins.Plugin;
|
|
||||||
import org.elasticsearch.test.ESIntegTestCase;
|
import org.elasticsearch.test.ESIntegTestCase;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
||||||
import static org.hamcrest.Matchers.*;
|
import static org.hamcrest.Matchers.*;
|
||||||
|
|
||||||
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 1)
|
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 1)
|
||||||
public class MarvelSettingsTests extends MarvelIntegTestCase {
|
public class MarvelSettingsTests extends MarvelIntegTestCase {
|
||||||
|
|
||||||
private final TimeValue startUp = randomParsedTimeValue();
|
private final TimeValue startUp = newRandomTimeValue();
|
||||||
private final TimeValue interval = randomParsedTimeValue();
|
private final TimeValue interval = newRandomTimeValue();
|
||||||
private final TimeValue indexStatsTimeout = randomParsedTimeValue();
|
private final TimeValue indexStatsTimeout = newRandomTimeValue();
|
||||||
private final String[] indices = randomStringArray();
|
private final String[] indices = randomStringArray();
|
||||||
private final TimeValue clusterStateTimeout = randomParsedTimeValue();
|
private final TimeValue clusterStateTimeout = newRandomTimeValue();
|
||||||
private final TimeValue clusterStatsTimeout = randomParsedTimeValue();
|
private final TimeValue clusterStatsTimeout = newRandomTimeValue();
|
||||||
private final TimeValue recoveryTimeout = randomParsedTimeValue();
|
private final TimeValue recoveryTimeout = newRandomTimeValue();
|
||||||
private final Boolean recoveryActiveOnly = randomBoolean();
|
private final Boolean recoveryActiveOnly = randomBoolean();
|
||||||
private final String[] collectors = randomStringArray();
|
private final String[] collectors = randomStringArray();
|
||||||
private final TimeValue licenseGracePeriod = randomExpirationDelay();
|
private final TimeValue licenseGracePeriod = randomExpirationDelay();
|
||||||
|
@ -61,12 +55,7 @@ public class MarvelSettingsTests extends MarvelIntegTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMarvelSettingService() throws Exception {
|
public void testMarvelSettings() throws Exception {
|
||||||
logger.info("--> printing marvel settings values");
|
|
||||||
for (MarvelSetting setting : MarvelSettings.settings()) {
|
|
||||||
logger.info("\t{}", setting);
|
|
||||||
}
|
|
||||||
|
|
||||||
logger.info("--> testing marvel settings service initialization");
|
logger.info("--> testing marvel settings service initialization");
|
||||||
for (final MarvelSettings marvelSettings : internalCluster().getInstances(MarvelSettings.class)) {
|
for (final MarvelSettings marvelSettings : internalCluster().getInstances(MarvelSettings.class)) {
|
||||||
assertThat(marvelSettings.startUpDelay().millis(), equalTo(startUp.millis()));
|
assertThat(marvelSettings.startUpDelay().millis(), equalTo(startUp.millis()));
|
||||||
|
@ -79,31 +68,37 @@ public class MarvelSettingsTests extends MarvelIntegTestCase {
|
||||||
assertThat(marvelSettings.recoveryActiveOnly(), equalTo(recoveryActiveOnly));
|
assertThat(marvelSettings.recoveryActiveOnly(), equalTo(recoveryActiveOnly));
|
||||||
assertArrayEquals(marvelSettings.collectors(), collectors);
|
assertArrayEquals(marvelSettings.collectors(), collectors);
|
||||||
assertThat(marvelSettings.licenseExpirationGracePeriod().millis(), allOf(greaterThanOrEqualTo(0L), lessThanOrEqualTo(MarvelSettings.MAX_LICENSE_GRACE_PERIOD.millis())));
|
assertThat(marvelSettings.licenseExpirationGracePeriod().millis(), allOf(greaterThanOrEqualTo(0L), lessThanOrEqualTo(MarvelSettings.MAX_LICENSE_GRACE_PERIOD.millis())));
|
||||||
|
|
||||||
for (final MarvelSetting setting : MarvelSettings.dynamicSettings()) {
|
|
||||||
assertThat(marvelSettings.getSettingValue(setting.getName()), equalTo(setting.getValue()));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("--> testing marvel dynamic settings update");
|
logger.info("--> testing marvel dynamic settings update");
|
||||||
for (final MarvelSetting setting : MarvelSettings.dynamicSettings()) {
|
for (String setting : MarvelSettings.dynamicSettings().keySet()) {
|
||||||
Object updated = null;
|
Object updated = null;
|
||||||
Settings.Builder transientSettings = Settings.builder();
|
Settings.Builder transientSettings = Settings.builder();
|
||||||
if (setting instanceof MarvelSetting.TimeValueSetting) {
|
|
||||||
updated = randomParsedTimeValue();
|
|
||||||
transientSettings.put(setting.getName(), updated);
|
|
||||||
|
|
||||||
} else if (setting instanceof MarvelSetting.BooleanSetting) {
|
if (setting.endsWith(".*")) {
|
||||||
updated = randomBoolean();
|
setting = setting.substring(0, setting.lastIndexOf('.'));
|
||||||
transientSettings.put(setting.getName(), updated);
|
}
|
||||||
|
|
||||||
} else if (setting instanceof MarvelSetting.StringSetting) {
|
switch (setting) {
|
||||||
updated = randomAsciiOfLength(10);
|
case MarvelSettings.INTERVAL:
|
||||||
transientSettings.put(setting.getName(), updated);
|
case MarvelSettings.INDEX_STATS_TIMEOUT:
|
||||||
|
case MarvelSettings.INDICES_STATS_TIMEOUT:
|
||||||
} else if (setting instanceof MarvelSetting.StringArraySetting) {
|
case MarvelSettings.CLUSTER_STATE_TIMEOUT:
|
||||||
updated = randomStringArray();
|
case MarvelSettings.CLUSTER_STATS_TIMEOUT:
|
||||||
transientSettings.putArray(setting.getName(), (String[]) updated);
|
case MarvelSettings.INDEX_RECOVERY_TIMEOUT:
|
||||||
|
updated = newRandomTimeValue();
|
||||||
|
transientSettings.put(setting, updated);
|
||||||
|
break;
|
||||||
|
case MarvelSettings.INDEX_RECOVERY_ACTIVE_ONLY:
|
||||||
|
updated = randomBoolean();
|
||||||
|
transientSettings.put(setting, updated);
|
||||||
|
break;
|
||||||
|
case MarvelSettings.INDICES:
|
||||||
|
updated = randomStringArray();
|
||||||
|
transientSettings.putArray(setting, (String[]) updated);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
fail("unknown dynamic setting [" + setting +"]");
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info("--> updating {} to value [{}]", setting, updated);
|
logger.info("--> updating {} to value [{}]", setting, updated);
|
||||||
|
@ -111,25 +106,28 @@ public class MarvelSettingsTests extends MarvelIntegTestCase {
|
||||||
|
|
||||||
// checking that the value has been correctly updated on all marvel settings services
|
// checking that the value has been correctly updated on all marvel settings services
|
||||||
final Object expected = updated;
|
final Object expected = updated;
|
||||||
|
final String finalSetting = setting;
|
||||||
assertBusy(new Runnable() {
|
assertBusy(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
for (final MarvelSettings marvelSettings : internalCluster().getInstances(MarvelSettings.class)) {
|
for (final MarvelSettings marvelSettings : internalCluster().getInstances(MarvelSettings.class)) {
|
||||||
MarvelSetting current = marvelSettings.getSetting(setting.getName());
|
MarvelSetting current = marvelSettings.getSetting(finalSetting);
|
||||||
Object value = current.getValue();
|
Object value = current.getValue();
|
||||||
|
|
||||||
logger.info("--> {} in {}", current, marvelSettings);
|
logger.info("--> {} in {}", current, marvelSettings);
|
||||||
if (setting instanceof MarvelSetting.TimeValueSetting) {
|
if (current instanceof MarvelSetting.TimeValueSetting) {
|
||||||
assertThat(((TimeValue) value).millis(), equalTo(((TimeValue) expected).millis()));
|
assertThat(((TimeValue) value).millis(), equalTo(((TimeValue) expected).millis()));
|
||||||
|
|
||||||
} else if (setting instanceof MarvelSetting.BooleanSetting) {
|
} else if (current instanceof MarvelSetting.BooleanSetting) {
|
||||||
assertThat((Boolean) value, equalTo((Boolean) expected));
|
assertThat((Boolean) value, equalTo((Boolean) expected));
|
||||||
|
|
||||||
} else if (setting instanceof MarvelSetting.StringSetting) {
|
} else if (current instanceof MarvelSetting.StringSetting) {
|
||||||
assertThat((String) value, equalTo((String) expected));
|
assertThat((String) value, equalTo((String) expected));
|
||||||
|
|
||||||
} else if (setting instanceof MarvelSetting.StringArraySetting) {
|
} else if (current instanceof MarvelSetting.StringArraySetting) {
|
||||||
assertArrayEquals((String[]) value, (String[]) expected);
|
assertArrayEquals((String[]) value, (String[]) expected);
|
||||||
|
} else {
|
||||||
|
fail("unable to check value for unknown dynamic setting [" + finalSetting + "]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -147,7 +145,7 @@ public class MarvelSettingsTests extends MarvelIntegTestCase {
|
||||||
return requestBuilder;
|
return requestBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
private TimeValue randomParsedTimeValue() {
|
private TimeValue newRandomTimeValue() {
|
||||||
return TimeValue.parseTimeValue(randomFrom("30m", "1h", "3h", "5h", "7h", "10h", "1d"), null, getClass().getSimpleName());
|
return TimeValue.parseTimeValue(randomFrom("30m", "1h", "3h", "5h", "7h", "10h", "1d"), null, getClass().getSimpleName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,6 +160,6 @@ public class MarvelSettingsTests extends MarvelIntegTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
private TimeValue randomExpirationDelay() {
|
private TimeValue randomExpirationDelay() {
|
||||||
return randomBoolean() ? randomParsedTimeValue() : TimeValue.timeValueHours(randomIntBetween(-10, 10) * 24);
|
return randomBoolean() ? newRandomTimeValue() : TimeValue.timeValueHours(randomIntBetween(-10, 10) * 24);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue