From 64a3339178a68acfc5866ffe8d82597f3a727a56 Mon Sep 17 00:00:00 2001 From: Chris Earle Date: Mon, 16 Apr 2018 13:58:20 -0400 Subject: [PATCH] [Monitoring] Ignore data when no Cluster UUID exists (elastic/x-pack-elasticsearch#4344) This ignores data collection when the cluster is not ready, in addition to the existing check that ignores when the cluster state's version is unknown. Original commit: elastic/x-pack-elasticsearch@54257d7e6f2052bc2d023b0515c6b2e1878b4db8 --- .../xpack/monitoring/exporter/Exporters.java | 4 +++- .../xpack/monitoring/exporter/ExportersTests.java | 13 ++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/exporter/Exporters.java b/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/exporter/Exporters.java index 30035575d35..9333a2f81db 100644 --- a/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/exporter/Exporters.java +++ b/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/exporter/Exporters.java @@ -102,7 +102,9 @@ public class Exporters extends AbstractLifecycleComponent implements Iterable factories; private ClusterService clusterService; private ClusterState state; + private final MetaData metadata = mock(MetaData.class); private final XPackLicenseState licenseState = mock(XPackLicenseState.class); private ClusterSettings clusterSettings; private ThreadContext threadContext; @Before - public void init() throws Exception { + public void init() { factories = new HashMap<>(); Client client = mock(Client.class); @@ -80,6 +82,7 @@ public class ExportersTests extends ESTestCase { clusterSettings = new ClusterSettings(Settings.EMPTY, settingsSet); when(clusterService.getClusterSettings()).thenReturn(clusterSettings); when(clusterService.state()).thenReturn(state); + when(state.metaData()).thenReturn(metadata); // we always need to have the local exporter as it serves as the default one factories.put(LocalExporter.TYPE, config -> new LocalExporter(config, client, mock(CleanerService.class))); @@ -208,8 +211,12 @@ public class ExportersTests extends ESTestCase { } public void testExporterBlocksOnClusterState() { - when(state.version()).thenReturn(ClusterState.UNKNOWN_VERSION); - + if (rarely()) { + when(metadata.clusterUUID()).thenReturn(ClusterState.UNKNOWN_UUID); + } else { + when(state.version()).thenReturn(ClusterState.UNKNOWN_VERSION); + } + final int nbExporters = randomIntBetween(1, 5); final Settings.Builder settings = Settings.builder();