Renaming interval variable to include units and reordering constructor field values to ensure listener is added last
Original commit: elastic/x-pack-elasticsearch@60983f4190
This commit is contained in:
parent
ef81157c47
commit
7e334a5e4b
|
@ -27,7 +27,6 @@ import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@code AgentService} is a service that does the work of publishing the details to the monitoring cluster.
|
* The {@code AgentService} is a service that does the work of publishing the details to the monitoring cluster.
|
||||||
|
@ -43,7 +42,7 @@ public class AgentService extends AbstractLifecycleComponent<AgentService> {
|
||||||
private volatile ExportingWorker exportingWorker;
|
private volatile ExportingWorker exportingWorker;
|
||||||
|
|
||||||
private volatile Thread workerThread;
|
private volatile Thread workerThread;
|
||||||
private volatile long samplingInterval;
|
private volatile long samplingIntervalMillis;
|
||||||
private final Collection<Collector> collectors;
|
private final Collection<Collector> collectors;
|
||||||
private final String[] settingsCollectors;
|
private final String[] settingsCollectors;
|
||||||
private final Exporters exporters;
|
private final Exporters exporters;
|
||||||
|
@ -51,15 +50,16 @@ public class AgentService extends AbstractLifecycleComponent<AgentService> {
|
||||||
@Inject
|
@Inject
|
||||||
public AgentService(Settings settings, ClusterSettings clusterSettings, Set<Collector> collectors, Exporters exporters) {
|
public AgentService(Settings settings, ClusterSettings clusterSettings, Set<Collector> collectors, Exporters exporters) {
|
||||||
super(settings);
|
super(settings);
|
||||||
samplingInterval = MarvelSettings.INTERVAL.get(settings).millis();
|
this.samplingIntervalMillis = MarvelSettings.INTERVAL.get(settings).millis();
|
||||||
settingsCollectors = MarvelSettings.COLLECTORS.get(settings).toArray(new String[0]);
|
this.settingsCollectors = MarvelSettings.COLLECTORS.get(settings).toArray(new String[0]);
|
||||||
clusterSettings.addSettingsUpdateConsumer(MarvelSettings.INTERVAL, this::setInterval);
|
|
||||||
this.collectors = Collections.unmodifiableSet(filterCollectors(collectors, settingsCollectors));
|
this.collectors = Collections.unmodifiableSet(filterCollectors(collectors, settingsCollectors));
|
||||||
this.exporters = exporters;
|
this.exporters = exporters;
|
||||||
|
|
||||||
|
clusterSettings.addSettingsUpdateConsumer(MarvelSettings.INTERVAL, this::setInterval);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setInterval(TimeValue interval) {
|
private void setInterval(TimeValue interval) {
|
||||||
this.samplingInterval = interval.millis();
|
this.samplingIntervalMillis = interval.millis();
|
||||||
applyIntervalSettings();
|
applyIntervalSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,8 +80,8 @@ public class AgentService extends AbstractLifecycleComponent<AgentService> {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void applyIntervalSettings() {
|
protected void applyIntervalSettings() {
|
||||||
if (samplingInterval <= 0) {
|
if (samplingIntervalMillis <= 0) {
|
||||||
logger.info("data sampling is disabled due to interval settings [{}]", samplingInterval);
|
logger.info("data sampling is disabled due to interval settings [{}]", samplingIntervalMillis);
|
||||||
if (workerThread != null) {
|
if (workerThread != null) {
|
||||||
|
|
||||||
// notify worker to stop on its leisure, not to disturb an exporting operation
|
// notify worker to stop on its leisure, not to disturb an exporting operation
|
||||||
|
@ -151,7 +151,7 @@ public class AgentService extends AbstractLifecycleComponent<AgentService> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public TimeValue getSamplingInterval() {
|
public TimeValue getSamplingInterval() {
|
||||||
return new TimeValue(samplingInterval, TimeUnit.MILLISECONDS);
|
return TimeValue.timeValueMillis(samplingIntervalMillis);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] collectors() {
|
public String[] collectors() {
|
||||||
|
@ -168,7 +168,7 @@ public class AgentService extends AbstractLifecycleComponent<AgentService> {
|
||||||
while (!closed) {
|
while (!closed) {
|
||||||
// sleep first to allow node to complete initialization before collecting the first start
|
// sleep first to allow node to complete initialization before collecting the first start
|
||||||
try {
|
try {
|
||||||
Thread.sleep(samplingInterval);
|
Thread.sleep(samplingIntervalMillis);
|
||||||
|
|
||||||
if (closed) {
|
if (closed) {
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Reference in New Issue