[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@54257d7e6f
This commit is contained in:
parent
b73c16287b
commit
64a3339178
|
@ -102,7 +102,9 @@ public class Exporters extends AbstractLifecycleComponent implements Iterable<Ex
|
||||||
}
|
}
|
||||||
|
|
||||||
ExportBulk openBulk() {
|
ExportBulk openBulk() {
|
||||||
if (clusterService.state().version() == ClusterState.UNKNOWN_VERSION) {
|
final ClusterState state = clusterService.state();
|
||||||
|
|
||||||
|
if (ClusterState.UNKNOWN_UUID.equals(state.metaData().clusterUUID()) || state.version() == ClusterState.UNKNOWN_VERSION) {
|
||||||
logger.trace("skipping exporters because the cluster state is not loaded");
|
logger.trace("skipping exporters because the cluster state is not loaded");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ package org.elasticsearch.xpack.monitoring.exporter;
|
||||||
import org.elasticsearch.action.ActionListener;
|
import org.elasticsearch.action.ActionListener;
|
||||||
import org.elasticsearch.client.Client;
|
import org.elasticsearch.client.Client;
|
||||||
import org.elasticsearch.cluster.ClusterState;
|
import org.elasticsearch.cluster.ClusterState;
|
||||||
|
import org.elasticsearch.cluster.metadata.MetaData;
|
||||||
import org.elasticsearch.cluster.service.ClusterService;
|
import org.elasticsearch.cluster.service.ClusterService;
|
||||||
import org.elasticsearch.common.settings.ClusterSettings;
|
import org.elasticsearch.common.settings.ClusterSettings;
|
||||||
import org.elasticsearch.common.settings.Setting;
|
import org.elasticsearch.common.settings.Setting;
|
||||||
|
@ -59,12 +60,13 @@ public class ExportersTests extends ESTestCase {
|
||||||
private Map<String, Exporter.Factory> factories;
|
private Map<String, Exporter.Factory> factories;
|
||||||
private ClusterService clusterService;
|
private ClusterService clusterService;
|
||||||
private ClusterState state;
|
private ClusterState state;
|
||||||
|
private final MetaData metadata = mock(MetaData.class);
|
||||||
private final XPackLicenseState licenseState = mock(XPackLicenseState.class);
|
private final XPackLicenseState licenseState = mock(XPackLicenseState.class);
|
||||||
private ClusterSettings clusterSettings;
|
private ClusterSettings clusterSettings;
|
||||||
private ThreadContext threadContext;
|
private ThreadContext threadContext;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void init() throws Exception {
|
public void init() {
|
||||||
factories = new HashMap<>();
|
factories = new HashMap<>();
|
||||||
|
|
||||||
Client client = mock(Client.class);
|
Client client = mock(Client.class);
|
||||||
|
@ -80,6 +82,7 @@ public class ExportersTests extends ESTestCase {
|
||||||
clusterSettings = new ClusterSettings(Settings.EMPTY, settingsSet);
|
clusterSettings = new ClusterSettings(Settings.EMPTY, settingsSet);
|
||||||
when(clusterService.getClusterSettings()).thenReturn(clusterSettings);
|
when(clusterService.getClusterSettings()).thenReturn(clusterSettings);
|
||||||
when(clusterService.state()).thenReturn(state);
|
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
|
// 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)));
|
factories.put(LocalExporter.TYPE, config -> new LocalExporter(config, client, mock(CleanerService.class)));
|
||||||
|
@ -208,7 +211,11 @@ public class ExportersTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testExporterBlocksOnClusterState() {
|
public void testExporterBlocksOnClusterState() {
|
||||||
|
if (rarely()) {
|
||||||
|
when(metadata.clusterUUID()).thenReturn(ClusterState.UNKNOWN_UUID);
|
||||||
|
} else {
|
||||||
when(state.version()).thenReturn(ClusterState.UNKNOWN_VERSION);
|
when(state.version()).thenReturn(ClusterState.UNKNOWN_VERSION);
|
||||||
|
}
|
||||||
|
|
||||||
final int nbExporters = randomIntBetween(1, 5);
|
final int nbExporters = randomIntBetween(1, 5);
|
||||||
final Settings.Builder settings = Settings.builder();
|
final Settings.Builder settings = Settings.builder();
|
||||||
|
|
Loading…
Reference in New Issue