Skip to content

Commit cdde837

Browse files
authored
Implement xpack.monitoring.elasticsearch.collection.enabled setting (#33474) (#33791)
* 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 490a537 commit cdde837

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
@@ -65,6 +65,17 @@ option in `kibana.yml` to the same value.
6565
You can update this setting through the
6666
<<cluster-update-settings,Cluster Update Settings API>>.
6767

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

7081
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
@@ -178,6 +178,7 @@ public List<Setting<?>> getSettings() {
178178
settings.add(MonitoringField.HISTORY_DURATION);
179179
settings.add(CLEAN_WATCHER_HISTORY);
180180
settings.add(MonitoringService.ENABLED);
181+
settings.add(MonitoringService.ELASTICSEARCH_COLLECTION_ENABLED);
181182
settings.add(MonitoringService.INTERVAL);
182183
settings.add(Collector.INDICES);
183184
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
@@ -63,8 +63,21 @@ private static void deprecateMinusOne(final TimeValue value) {
6363
*/
6464
public static final TimeValue MIN_INTERVAL = TimeValue.timeValueSeconds(1L);
6565

66+
/*
67+
* Dynamically controls enabling or disabling the collection of Monitoring data only from Elasticsearch.
68+
* <p>
69+
* This should only be used while transitioning to Metricbeat-based data collection for Elasticsearch with
70+
* {@linkplain #ENABLED} set to {@code true}. By setting this to {@code false} and that value to {@code true},
71+
* Kibana, Logstash, Beats, and APM Server can all continue to report their stats through this cluster until they
72+
* are transitioned to being monitored by Metricbeat as well.
73+
*/
74+
public static final Setting<Boolean> ELASTICSEARCH_COLLECTION_ENABLED =
75+
Setting.boolSetting("xpack.monitoring.elasticsearch.collection.enabled", true,
76+
Setting.Property.Dynamic, Setting.Property.NodeScope);
77+
6678
/**
67-
* Dynamically controls enabling or disabling the collection of Monitoring data.
79+
* Dynamically controls enabling or disabling the collection of Monitoring data from Elasticsearch as well as other products
80+
* in the stack.
6881
*/
6982
public static final Setting<Boolean> ENABLED =
7083
Setting.boolSetting("xpack.monitoring.collection.enabled", false,
@@ -96,6 +109,7 @@ private static void deprecateMinusOne(final TimeValue value) {
96109
private final Set<Collector> collectors;
97110
private final Exporters exporters;
98111

112+
private volatile boolean elasticsearchCollectionEnabled;
99113
private volatile boolean enabled;
100114
private volatile TimeValue interval;
101115
private volatile ThreadPool.Cancellable scheduler;
@@ -107,13 +121,21 @@ private static void deprecateMinusOne(final TimeValue value) {
107121
this.threadPool = Objects.requireNonNull(threadPool);
108122
this.collectors = Objects.requireNonNull(collectors);
109123
this.exporters = Objects.requireNonNull(exporters);
124+
this.elasticsearchCollectionEnabled = ELASTICSEARCH_COLLECTION_ENABLED.get(settings);
110125
this.enabled = ENABLED.get(settings);
111126
this.interval = INTERVAL.get(settings);
112127

128+
clusterService.getClusterSettings()
129+
.addSettingsUpdateConsumer(ELASTICSEARCH_COLLECTION_ENABLED, this::setElasticsearchCollectionEnabled);
113130
clusterService.getClusterSettings().addSettingsUpdateConsumer(ENABLED, this::setMonitoringActive);
114131
clusterService.getClusterSettings().addSettingsUpdateConsumer(INTERVAL, this::setInterval);
115132
}
116133

134+
void setElasticsearchCollectionEnabled(final boolean enabled) {
135+
this.elasticsearchCollectionEnabled = enabled;
136+
scheduleExecution();
137+
}
138+
117139
void setMonitoringActive(final boolean enabled) {
118140
this.enabled = enabled;
119141
scheduleExecution();
@@ -135,6 +157,14 @@ public boolean isMonitoringActive() {
135157
&& interval.millis() >= MIN_INTERVAL.millis();
136158
}
137159

160+
boolean isElasticsearchCollectionEnabled() {
161+
return this.elasticsearchCollectionEnabled;
162+
}
163+
164+
boolean shouldScheduleExecution() {
165+
return isElasticsearchCollectionEnabled() && isMonitoringActive();
166+
}
167+
138168
private String threadPoolName() {
139169
return ThreadPool.Names.GENERIC;
140170
}
@@ -186,7 +216,7 @@ void scheduleExecution() {
186216
if (scheduler != null) {
187217
cancelExecution();
188218
}
189-
if (isMonitoringActive()) {
219+
if (shouldScheduleExecution()) {
190220
scheduler = threadPool.scheduleWithFixedDelay(monitor, interval, threadPoolName());
191221
}
192222
}
@@ -219,7 +249,7 @@ class MonitoringExecution extends AbstractRunnable implements Closeable {
219249

220250
@Override
221251
public void doRun() {
222-
if (isMonitoringActive() == false) {
252+
if (shouldScheduleExecution() == false) {
223253
logger.debug("monitoring execution is skipped");
224254
return;
225255
}
@@ -254,7 +284,7 @@ protected void doRun() throws Exception {
254284
new ParameterizedMessage("monitoring collector [{}] failed to collect data", collector.name()), e);
255285
}
256286
}
257-
if (isMonitoringActive()) {
287+
if (shouldScheduleExecution()) {
258288
exporters.export(results, ActionListener.wrap(r -> semaphore.release(), this::onFailure));
259289
} else {
260290
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)