Skip to content

Commit 2aba52d

Browse files
authored
Implement xpack.monitoring.elasticsearch.collection.enabled setting (elastic#33474)
* Implement xpack.monitoring.elasticsearch.collection.enabled setting * Fixing line lengths * Updating constructor calls in test * Removing unused import * Fixing line lengths in test classes * Make monitoringService.isElasticsearchCollectionEnabled() return true for tests * Remove wrong expectation * Adding unit tests for new flag to be false * Fixing line wrapping/indentation for better readability * Adding docs * Fixing logic in ClusterStatsCollector::shouldCollect * Rebasing with master and resolving conflicts * Simplifying implementation by gating scheduling * Doc fixes / improvements * Making methods package private * Fixing wording * Fixing method access
1 parent a95226b commit 2aba52d

File tree

6 files changed

+64
-9
lines changed

6 files changed

+64
-9
lines changed

docs/reference/monitoring/configuring-monitoring.asciidoc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ indices. You can also adjust how monitoring data is displayed.
1313

1414
. To collect monitoring data about your {es} cluster:
1515

16-
.. Verify that the `xpack.monitoring.enabled` and
17-
`xpack.monitoring.collection.enabled` settings are `true` on each node in the
18-
cluster. By default, data collection is disabled. For more information, see
19-
<<monitoring-settings>>.
16+
.. Verify that the `xpack.monitoring.enabled`,
17+
`xpack.monitoring.collection.enabled`, and
18+
`xpack.monitoring.elasticsearch.collection.enabled` settings are `true` on each
19+
node in the cluster. By default xpack.monitoring.collection.enabled is disabled
20+
(`false`), and that overrides xpack.monitoring.elasticsearch.collection.enabled,
21+
which defaults to being enabled (`true`). Both settings can be set dynamically
22+
at runtime. For more information, see <<monitoring-settings>>.
2023

2124
.. Optional: Specify which indices you want to monitor.
2225
+

docs/reference/monitoring/pause-export.asciidoc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ monitoring data from other sources such as {kib}, Beats, and Logstash is ignored
1616
You can update this setting by using the
1717
{ref}/cluster-update-settings.html[Cluster Update Settings API].
1818

19+
If you want to collect data from sources such as {kib}, Beats, and Logstash but
20+
not collect data about your {es} cluster, you can disable data collection
21+
just for {es}:
22+
23+
[source,yaml]
24+
---------------------------------------------------
25+
xpack.monitoring.collection.enabled: true
26+
xpack.monitoring.elasticsearch.collection.enabled: false
27+
---------------------------------------------------
28+
1929
If you want to separately disable a specific exporter, you can specify the
2030
`enabled` setting (which defaults to `true`) per exporter. For example:
2131

docs/reference/settings/monitoring-settings.asciidoc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,17 @@ option in `kibana.yml` to the same value.
6666
You can update this setting through the
6767
<<cluster-update-settings,Cluster Update Settings API>>.
6868

69+
`xpack.monitoring.elasticsearch.collection.enabled`::
70+
71+
Controls whether statistics about your {es} cluster should be collected. Defaults to `true`.
72+
This is different from xpack.monitoring.collection.enabled, which allows you to enable or disable
73+
all monitoring collection. However, this setting simply disables the collection of Elasticsearch
74+
data while still allowing other data (e.g., Kibana, Logstash, Beats, or APM Server monitoring data)
75+
to pass through this cluster.
76+
+
77+
You can update this setting through the
78+
<<cluster-update-settings,Cluster Update Settings API>>.
79+
6980
`xpack.monitoring.collection.cluster.stats.timeout`::
7081

7182
Sets the timeout for collecting the cluster statistics. Defaults to `10s`.

x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/Monitoring.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ public List<Setting<?>> getSettings() {
174174
settings.add(MonitoringField.HISTORY_DURATION);
175175
settings.add(CLEAN_WATCHER_HISTORY);
176176
settings.add(MonitoringService.ENABLED);
177+
settings.add(MonitoringService.ELASTICSEARCH_COLLECTION_ENABLED);
177178
settings.add(MonitoringService.INTERVAL);
178179
settings.add(Collector.INDICES);
179180
settings.add(ClusterStatsCollector.CLUSTER_STATS_TIMEOUT);

x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/MonitoringService.java

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,21 @@ public class MonitoringService extends AbstractLifecycleComponent {
4343
*/
4444
public static final TimeValue MIN_INTERVAL = TimeValue.timeValueSeconds(1L);
4545

46+
/*
47+
* Dynamically controls enabling or disabling the collection of Monitoring data only from Elasticsearch.
48+
* <p>
49+
* This should only be used while transitioning to Metricbeat-based data collection for Elasticsearch with
50+
* {@linkplain #ENABLED} set to {@code true}. By setting this to {@code false} and that value to {@code true},
51+
* Kibana, Logstash, Beats, and APM Server can all continue to report their stats through this cluster until they
52+
* are transitioned to being monitored by Metricbeat as well.
53+
*/
54+
public static final Setting<Boolean> ELASTICSEARCH_COLLECTION_ENABLED =
55+
Setting.boolSetting("xpack.monitoring.elasticsearch.collection.enabled", true,
56+
Setting.Property.Dynamic, Setting.Property.NodeScope);
57+
4658
/**
47-
* Dynamically controls enabling or disabling the collection of Monitoring data.
59+
* Dynamically controls enabling or disabling the collection of Monitoring data from Elasticsearch as well as other products
60+
* in the stack.
4861
*/
4962
public static final Setting<Boolean> ENABLED =
5063
Setting.boolSetting("xpack.monitoring.collection.enabled", false,
@@ -68,6 +81,7 @@ public class MonitoringService extends AbstractLifecycleComponent {
6881
private final Set<Collector> collectors;
6982
private final Exporters exporters;
7083

84+
private volatile boolean elasticsearchCollectionEnabled;
7185
private volatile boolean enabled;
7286
private volatile TimeValue interval;
7387
private volatile ThreadPool.Cancellable scheduler;
@@ -79,13 +93,21 @@ public class MonitoringService extends AbstractLifecycleComponent {
7993
this.threadPool = Objects.requireNonNull(threadPool);
8094
this.collectors = Objects.requireNonNull(collectors);
8195
this.exporters = Objects.requireNonNull(exporters);
96+
this.elasticsearchCollectionEnabled = ELASTICSEARCH_COLLECTION_ENABLED.get(settings);
8297
this.enabled = ENABLED.get(settings);
8398
this.interval = INTERVAL.get(settings);
8499

100+
clusterService.getClusterSettings()
101+
.addSettingsUpdateConsumer(ELASTICSEARCH_COLLECTION_ENABLED, this::setElasticsearchCollectionEnabled);
85102
clusterService.getClusterSettings().addSettingsUpdateConsumer(ENABLED, this::setMonitoringActive);
86103
clusterService.getClusterSettings().addSettingsUpdateConsumer(INTERVAL, this::setInterval);
87104
}
88105

106+
void setElasticsearchCollectionEnabled(final boolean enabled) {
107+
this.elasticsearchCollectionEnabled = enabled;
108+
scheduleExecution();
109+
}
110+
89111
void setMonitoringActive(final boolean enabled) {
90112
this.enabled = enabled;
91113
scheduleExecution();
@@ -104,6 +126,14 @@ public boolean isMonitoringActive() {
104126
return isStarted() && enabled;
105127
}
106128

129+
boolean isElasticsearchCollectionEnabled() {
130+
return this.elasticsearchCollectionEnabled;
131+
}
132+
133+
boolean shouldScheduleExecution() {
134+
return isElasticsearchCollectionEnabled() && isMonitoringActive();
135+
}
136+
107137
private String threadPoolName() {
108138
return ThreadPool.Names.GENERIC;
109139
}
@@ -155,7 +185,7 @@ void scheduleExecution() {
155185
if (scheduler != null) {
156186
cancelExecution();
157187
}
158-
if (isMonitoringActive()) {
188+
if (shouldScheduleExecution()) {
159189
scheduler = threadPool.scheduleWithFixedDelay(monitor, interval, threadPoolName());
160190
}
161191
}
@@ -188,7 +218,7 @@ class MonitoringExecution extends AbstractRunnable implements Closeable {
188218

189219
@Override
190220
public void doRun() {
191-
if (isMonitoringActive() == false) {
221+
if (shouldScheduleExecution() == false) {
192222
logger.debug("monitoring execution is skipped");
193223
return;
194224
}
@@ -223,7 +253,7 @@ protected void doRun() throws Exception {
223253
new ParameterizedMessage("monitoring collector [{}] failed to collect data", collector.name()), e);
224254
}
225255
}
226-
if (isMonitoringActive()) {
256+
if (shouldScheduleExecution()) {
227257
exporters.export(results, ActionListener.wrap(r -> semaphore.release(), this::onFailure));
228258
} else {
229259
semaphore.release();

x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/collector/indices/IndexRecoveryCollectorTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,4 @@ public void testDoCollect() throws Exception {
182182
assertThat(recoveries.shardRecoveryStates().size(), equalTo(nbRecoveries));
183183
}
184184
}
185-
}
185+
}

0 commit comments

Comments
 (0)