Skip to content

Commit d59ea64

Browse files
authored
Monitoring should wait with collecting data when cluster service is started. (#49426)
Backport of #48277 Otherwise integration tests may fail if the monitoring interval is low: ``` [2019-10-21T09:57:25,527][ERROR][o.e.b.ElasticsearchUncaughtExceptionHandler] [integTest-0] fatal error in thread [elasticsearch[integTest-0][generic][T#4]], exiting java.lang.AssertionError: initial cluster state not set yet at org.elasticsearch.cluster.service.ClusterApplierService.state(ClusterApplierService.java:208) ~[elasticsearch-7.6.0-SNAPSHOT.jar:7.6.0-SNAPSHOT] at org.elasticsearch.cluster.service.ClusterService.state(ClusterService.java:125) ~[elasticsearch-7.6.0-SNAPSHOT.jar:7.6.0-SNAPSHOT] at org.elasticsearch.xpack.monitoring.MonitoringService$MonitoringExecution$1.doRun(MonitoringService.java:231) ~[?:?] at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) ~[elasticsearch-7.6.0-SNAPSHOT.jar:7.6.0-SNAPSHOT] at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) ~[?:?] at java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[?:?] at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingRunnable.run(ThreadContext.java:703) ~[elasticsearch-7.6.0-SNAPSHOT.jar:7.6.0-SNAPSHOT] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[?:?] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[?:?] at java.lang.Thread.run(Thread.java:835) [?:?] ``` I ran into this when lowering the monitoring interval when investigating enrich monitoring test: #48258
1 parent c3e4405 commit d59ea64

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

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

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.elasticsearch.cluster.ClusterState;
1414
import org.elasticsearch.cluster.service.ClusterService;
1515
import org.elasticsearch.common.component.AbstractLifecycleComponent;
16+
import org.elasticsearch.common.component.Lifecycle;
1617
import org.elasticsearch.common.settings.Setting;
1718
import org.elasticsearch.common.settings.Settings;
1819
import org.elasticsearch.common.unit.TimeValue;
@@ -218,6 +219,11 @@ public void doRun() {
218219
return;
219220
}
220221

222+
if (clusterService.lifecycleState() != Lifecycle.State.STARTED) {
223+
logger.debug("cluster service not started");
224+
return;
225+
}
226+
221227
if (semaphore.tryAcquire() == false) {
222228
logger.debug("monitoring execution is skipped until previous execution terminated");
223229
return;

x-pack/plugin/monitoring/src/test/java/org/elasticsearch/xpack/monitoring/MonitoringServiceTests.java

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.elasticsearch.action.ActionListener;
99
import org.elasticsearch.cluster.ClusterState;
1010
import org.elasticsearch.cluster.service.ClusterService;
11+
import org.elasticsearch.common.component.Lifecycle;
1112
import org.elasticsearch.common.settings.ClusterSettings;
1213
import org.elasticsearch.common.settings.Settings;
1314
import org.elasticsearch.license.XPackLicenseState;
@@ -57,6 +58,7 @@ protected XPackLicenseState getLicenseState() {
5758
clusterSettings = new ClusterSettings(Settings.EMPTY, new HashSet<>(monitoring.getSettings()));
5859
when(clusterService.getClusterSettings()).thenReturn(clusterSettings);
5960
when(clusterService.state()).thenReturn(mock(ClusterState.class));
61+
when(clusterService.lifecycleState()).thenReturn(Lifecycle.State.STARTED);
6062
}
6163

6264
@After

0 commit comments

Comments
 (0)