Marvel: Merge ClusterInfoCollector in ClusterStatsCollector

This commit merge the ClusterInfoCollector in the ClusterStatsCollector so that cluster stats are retrieved only once.

Original commit: elastic/x-pack-elasticsearch@fe70149210
This commit is contained in:
Tanguy Leroux 2015-12-31 14:55:40 +01:00
parent eeb5842730
commit 2cec08798b
10 changed files with 143 additions and 246 deletions

View File

@ -15,7 +15,7 @@ import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.util.CollectionUtils;
import org.elasticsearch.common.util.concurrent.EsExecutors;
import org.elasticsearch.marvel.agent.collector.Collector;
import org.elasticsearch.marvel.agent.collector.cluster.ClusterInfoCollector;
import org.elasticsearch.marvel.agent.collector.cluster.ClusterStatsCollector;
import org.elasticsearch.marvel.agent.exporter.ExportBulk;
import org.elasticsearch.marvel.agent.exporter.Exporter;
import org.elasticsearch.marvel.agent.exporter.Exporters;
@ -63,7 +63,7 @@ public class AgentService extends AbstractLifecycleComponent<AgentService> {
for (Collector collector : collectors) {
if (Regex.simpleMatch(filters, collector.name().toLowerCase(Locale.ROOT))) {
list.add(collector);
} else if (collector instanceof ClusterInfoCollector) {
} else if (collector instanceof ClusterStatsCollector) {
list.add(collector);
}
}

View File

@ -7,7 +7,6 @@ package org.elasticsearch.marvel.agent.collector;
import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.common.inject.multibindings.Multibinder;
import org.elasticsearch.marvel.agent.collector.cluster.ClusterInfoCollector;
import org.elasticsearch.marvel.agent.collector.cluster.ClusterStateCollector;
import org.elasticsearch.marvel.agent.collector.cluster.ClusterStatsCollector;
import org.elasticsearch.marvel.agent.collector.indices.IndexRecoveryCollector;
@ -25,7 +24,6 @@ public class CollectorModule extends AbstractModule {
public CollectorModule() {
// Registers default collectors
registerCollector(ClusterInfoCollector.class);
registerCollector(IndicesStatsCollector.class);
registerCollector(IndexStatsCollector.class);
registerCollector(ClusterStatsCollector.class);

View File

@ -1,85 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.marvel.agent.collector.cluster;
import org.elasticsearch.ElasticsearchSecurityException;
import org.elasticsearch.Version;
import org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.license.core.License;
import org.elasticsearch.license.plugin.core.LicenseUtils;
import org.elasticsearch.license.plugin.core.LicensesManagerService;
import org.elasticsearch.marvel.agent.collector.AbstractCollector;
import org.elasticsearch.marvel.agent.exporter.MarvelDoc;
import org.elasticsearch.marvel.agent.settings.MarvelSettings;
import org.elasticsearch.marvel.license.MarvelLicensee;
import org.elasticsearch.marvel.shield.SecuredClient;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
/**
* Collector for registered licenses and additional cluster information.
* <p>
* This collector runs on the master node and collect data about all
* known licenses that are currently registered. It also ships some stats
* about the cluster (to be used in Phone Home feature).
*/
public class ClusterInfoCollector extends AbstractCollector<ClusterInfoMarvelDoc> {
public static final String NAME = "cluster-info-collector";
public static final String TYPE = "cluster_info";
private final ClusterName clusterName;
private final LicensesManagerService licensesManagerService;
private final Client client;
@Inject
public ClusterInfoCollector(Settings settings, ClusterService clusterService, MarvelSettings marvelSettings, MarvelLicensee marvelLicensee,
LicensesManagerService licensesManagerService, ClusterName clusterName, SecuredClient client) {
super(settings, NAME, clusterService, marvelSettings, marvelLicensee);
this.clusterName = clusterName;
this.licensesManagerService = licensesManagerService;
this.client = client;
}
@Override
protected boolean shouldCollect() {
// This collector can always collect data on the master node
return isLocalNodeMaster();
}
@Override
protected Collection<MarvelDoc> doCollect() throws Exception {
List<MarvelDoc> results = new ArrayList<>(1);
License license = licensesManagerService.getLicense();
// Retrieves additional cluster stats
ClusterStatsResponse clusterStats = null;
try {
clusterStats = client.admin().cluster().prepareClusterStats().get(marvelSettings.clusterStatsTimeout());
} catch (ElasticsearchSecurityException e) {
if (LicenseUtils.isLicenseExpiredException(e)) {
logger.trace("collector [{}] - unable to collect data because of expired license", e, name());
} else {
throw e;
}
}
String clusterUUID = clusterUUID();
long timestamp = System.currentTimeMillis();
results.add(new ClusterInfoMarvelDoc(dataIndexNameResolver.resolve(timestamp), TYPE, clusterUUID, clusterUUID, timestamp,
clusterName.value(), Version.CURRENT.toString(), license, clusterStats));
return Collections.unmodifiableCollection(results);
}
}

View File

@ -5,11 +5,16 @@
*/
package org.elasticsearch.marvel.agent.collector.cluster;
import org.elasticsearch.ElasticsearchSecurityException;
import org.elasticsearch.Version;
import org.elasticsearch.action.admin.cluster.stats.ClusterStatsResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.license.plugin.core.LicenseUtils;
import org.elasticsearch.license.plugin.core.LicensesManagerService;
import org.elasticsearch.marvel.agent.collector.AbstractCollector;
import org.elasticsearch.marvel.agent.exporter.MarvelDoc;
import org.elasticsearch.marvel.agent.settings.MarvelSettings;
@ -24,34 +29,66 @@ import java.util.List;
/**
* Collector for cluster stats.
* <p>
* This collector runs on the master node only and collects the {@link ClusterStatsMarvelDoc} document
* at a given frequency.
* This collector runs on the master node. It collect data about the current
* license and also retrieves the cluster stats.
* <p>
* the license and cluster stats are indexed in the data index in a "cluster_info"
* document; the cluster stats are also indexed in the timestamped index in a
* "cluster_stats" document.
*/
public class ClusterStatsCollector extends AbstractCollector<ClusterStatsCollector> {
public static final String NAME = "cluster-stats-collector";
public static final String TYPE = "cluster_stats";
public static final String CLUSTER_INFO_TYPE = "cluster_info";
public static final String CLUSTER_STATS_TYPE = "cluster_stats";
private final ClusterName clusterName;
private final LicensesManagerService licensesManagerService;
private final Client client;
@Inject
public ClusterStatsCollector(Settings settings, ClusterService clusterService, MarvelSettings marvelSettings, MarvelLicensee marvelLicensee,
SecuredClient client) {
public ClusterStatsCollector(Settings settings, ClusterService clusterService, MarvelSettings marvelSettings, MarvelLicensee marvelLicensee,
SecuredClient client, LicensesManagerService licensesManagerService, ClusterName clusterName) {
super(settings, NAME, clusterService, marvelSettings, marvelLicensee);
this.client = client;
this.clusterName = clusterName;
this.licensesManagerService = licensesManagerService;
}
@Override
protected boolean shouldCollect() {
return super.shouldCollect() && isLocalNodeMaster();
// This collector can always collect data on the master node
return isLocalNodeMaster();
}
@Override
protected Collection<MarvelDoc> doCollect() throws Exception {
List<MarvelDoc> results = new ArrayList<>(1);
ClusterStatsResponse clusterStatsResponse = client.admin().cluster().prepareClusterStats().get(marvelSettings.clusterStatsTimeout());
results.add(new ClusterStatsMarvelDoc(clusterUUID(), TYPE, System.currentTimeMillis(), clusterStatsResponse));
long timestamp = System.currentTimeMillis();
String clusterUUID = clusterUUID();
// Retrieves cluster stats
ClusterStatsResponse clusterStats = null;
try {
clusterStats = client.admin().cluster().prepareClusterStats().get(marvelSettings.clusterStatsTimeout());
} catch (ElasticsearchSecurityException e) {
if (LicenseUtils.isLicenseExpiredException(e)) {
logger.trace("collector [{}] - unable to collect data because of expired license", e, name());
} else {
throw e;
}
}
// Adds a cluster info document
results.add(new ClusterInfoMarvelDoc(dataIndexNameResolver.resolve(timestamp), CLUSTER_INFO_TYPE, clusterUUID, clusterUUID, timestamp,
clusterName.value(), Version.CURRENT.toString(), licensesManagerService.getLicense(), clusterStats));
// Adds a cluster stats document
if (super.shouldCollect()) {
results.add(new ClusterStatsMarvelDoc(clusterUUID, CLUSTER_STATS_TYPE, timestamp, clusterStats));
}
return Collections.unmodifiableCollection(results);
}
}

View File

@ -7,7 +7,6 @@ package org.elasticsearch.marvel.agent.renderer;
import org.elasticsearch.common.inject.AbstractModule;
import org.elasticsearch.common.inject.multibindings.MapBinder;
import org.elasticsearch.marvel.agent.collector.cluster.ClusterInfoCollector;
import org.elasticsearch.marvel.agent.collector.cluster.ClusterStateCollector;
import org.elasticsearch.marvel.agent.collector.cluster.ClusterStatsCollector;
import org.elasticsearch.marvel.agent.collector.indices.IndexRecoveryCollector;
@ -42,9 +41,6 @@ public class RendererModule extends AbstractModule {
MapBinder<String, Renderer> mbinder = MapBinder.newMapBinder(binder(), String.class, Renderer.class);
// Bind default renderers
bind(ClusterInfoRenderer.class).asEagerSingleton();
mbinder.addBinding(ClusterInfoCollector.TYPE).to(ClusterInfoRenderer.class);
bind(IndicesStatsRenderer.class).asEagerSingleton();
mbinder.addBinding(IndicesStatsCollector.TYPE).to(IndicesStatsRenderer.class);
@ -52,7 +48,8 @@ public class RendererModule extends AbstractModule {
mbinder.addBinding(IndexStatsCollector.TYPE).to(IndexStatsRenderer.class);
bind(ClusterStatsRenderer.class).asEagerSingleton();
mbinder.addBinding(ClusterStatsCollector.TYPE).to(ClusterStatsRenderer.class);
mbinder.addBinding(ClusterStatsCollector.CLUSTER_INFO_TYPE).to(ClusterInfoRenderer.class);
mbinder.addBinding(ClusterStatsCollector.CLUSTER_STATS_TYPE).to(ClusterStatsRenderer.class);
bind(ClusterStateRenderer.class).asEagerSingleton();
mbinder.addBinding(ClusterStateCollector.TYPE).to(ClusterStateRenderer.class);

View File

@ -1,112 +0,0 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.marvel.agent.collector.cluster;
import org.apache.lucene.util.LuceneTestCase.BadApple;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.license.plugin.core.LicensesManagerService;
import org.elasticsearch.marvel.agent.collector.AbstractCollectorTestCase;
import org.elasticsearch.marvel.agent.exporter.MarvelDoc;
import org.elasticsearch.marvel.agent.settings.MarvelSettings;
import org.elasticsearch.marvel.license.MarvelLicensee;
import java.util.Collection;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.notNullValue;
//test is just too slow, please fix it to not be sleep-based
@BadApple(bugUrl = "https://github.com/elastic/x-plugins/issues/1007")
public class ClusterInfoCollectorTests extends AbstractCollectorTestCase {
public void testClusterInfoCollector() throws Exception {
Collection<MarvelDoc> results = newClusterInfoCollector().doCollect();
assertThat(results, hasSize(1));
MarvelDoc marvelDoc = results.iterator().next();
assertNotNull(marvelDoc);
assertThat(marvelDoc, instanceOf(ClusterInfoMarvelDoc.class));
ClusterInfoMarvelDoc clusterInfoMarvelDoc = (ClusterInfoMarvelDoc) marvelDoc;
assertThat(clusterInfoMarvelDoc.clusterUUID(), equalTo(client().admin().cluster().prepareState().setMetaData(true).get().getState().metaData().clusterUUID()));
assertThat(clusterInfoMarvelDoc.timestamp(), greaterThan(0L));
assertThat(clusterInfoMarvelDoc.type(), equalTo(ClusterInfoCollector.TYPE));
assertThat(clusterInfoMarvelDoc.getClusterName(), equalTo(client().admin().cluster().prepareState().setMetaData(true).get().getClusterName().value()));
assertThat(clusterInfoMarvelDoc.getVersion(), equalTo(client().admin().cluster().prepareNodesInfo().get().getNodes()[0].getVersion().toString()));
assertThat(clusterInfoMarvelDoc.getLicense(), notNullValue());
assertNotNull(clusterInfoMarvelDoc.getClusterStats());
assertThat(clusterInfoMarvelDoc.getClusterStats().getNodesStats().getCounts().getTotal(), equalTo(internalCluster().getNodeNames().length));
}
public void testClusterInfoCollectorWithLicensing() {
try {
String[] nodes = internalCluster().getNodeNames();
for (String node : nodes) {
logger.debug("--> creating a new instance of the collector");
ClusterInfoCollector collector = newClusterInfoCollector(node);
assertNotNull(collector);
logger.debug("--> enabling license and checks that the collector can collect data (if node is master)");
enableLicense();
if (node.equals(internalCluster().getMasterName())) {
assertCanCollect(collector);
} else {
assertCannotCollect(collector);
}
logger.debug("--> starting graceful period and checks that the collector can still collect data (if node is master)");
beginGracefulPeriod();
if (node.equals(internalCluster().getMasterName())) {
assertCanCollect(collector);
} else {
assertCannotCollect(collector);
}
logger.debug("--> ending graceful period and checks that the collector can still collect data (if node is master)");
endGracefulPeriod();
if (node.equals(internalCluster().getMasterName())) {
assertCanCollect(collector);
} else {
assertCannotCollect(collector);
}
logger.debug("--> disabling license and checks that the collector can still collect data (if node is master)");
disableLicense();
if (node.equals(internalCluster().getMasterName())) {
assertCanCollect(collector);
} else {
assertCannotCollect(collector);
}
}
} finally {
// Ensure license is enabled before finishing the test
enableLicense();
}
}
private ClusterInfoCollector newClusterInfoCollector() {
// This collector runs on master node only
return newClusterInfoCollector(internalCluster().getMasterName());
}
private ClusterInfoCollector newClusterInfoCollector(String nodeId) {
assertNotNull(nodeId);
return new ClusterInfoCollector(internalCluster().getInstance(Settings.class, nodeId),
internalCluster().getInstance(ClusterService.class, nodeId),
internalCluster().getInstance(MarvelSettings.class, nodeId),
internalCluster().getInstance(MarvelLicensee.class, nodeId),
internalCluster().getInstance(LicensesManagerService.class, nodeId),
internalCluster().getInstance(ClusterName.class, nodeId),
securedClient(nodeId));
}
}

View File

@ -6,8 +6,11 @@
package org.elasticsearch.marvel.agent.collector.cluster;
import org.apache.lucene.util.LuceneTestCase.BadApple;
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.license.plugin.core.LicensesManagerService;
import org.elasticsearch.marvel.agent.collector.AbstractCollector;
import org.elasticsearch.marvel.agent.collector.AbstractCollectorTestCase;
import org.elasticsearch.marvel.agent.exporter.MarvelDoc;
import org.elasticsearch.marvel.agent.settings.MarvelSettings;
@ -19,22 +22,43 @@ import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.notNullValue;
//test is just too slow, please fix it to not be sleep-based
@BadApple(bugUrl = "https://github.com/elastic/x-plugins/issues/1007")
public class ClusterStatsCollectorTests extends AbstractCollectorTestCase {
public void testClusterStatsCollector() throws Exception {
Collection<MarvelDoc> results = newClusterStatsCollector().doCollect();
assertThat(results, hasSize(1));
assertThat(results, hasSize(2));
MarvelDoc marvelDoc = results.iterator().next();
// Check cluster info document
MarvelDoc marvelDoc = results.stream().filter(o -> o instanceof ClusterInfoMarvelDoc).findFirst().get();
assertNotNull(marvelDoc);
assertThat(marvelDoc, instanceOf(ClusterInfoMarvelDoc.class));
ClusterInfoMarvelDoc clusterInfoMarvelDoc = (ClusterInfoMarvelDoc) marvelDoc;
assertThat(clusterInfoMarvelDoc.clusterUUID(), equalTo(client().admin().cluster().prepareState().setMetaData(true).get().getState().metaData().clusterUUID()));
assertThat(clusterInfoMarvelDoc.timestamp(), greaterThan(0L));
assertThat(clusterInfoMarvelDoc.type(), equalTo(ClusterStatsCollector.CLUSTER_INFO_TYPE));
assertThat(clusterInfoMarvelDoc.getClusterName(), equalTo(client().admin().cluster().prepareState().setMetaData(true).get().getClusterName().value()));
assertThat(clusterInfoMarvelDoc.getVersion(), equalTo(client().admin().cluster().prepareNodesInfo().get().getNodes()[0].getVersion().toString()));
assertThat(clusterInfoMarvelDoc.getLicense(), notNullValue());
assertNotNull(clusterInfoMarvelDoc.getClusterStats());
assertThat(clusterInfoMarvelDoc.getClusterStats().getNodesStats().getCounts().getTotal(), equalTo(internalCluster().getNodeNames().length));
// Check cluster stats document
marvelDoc = results.stream().filter(o -> o instanceof ClusterStatsMarvelDoc).findFirst().get();
assertNotNull(marvelDoc);
assertThat(marvelDoc, instanceOf(ClusterStatsMarvelDoc.class));
ClusterStatsMarvelDoc clusterStatsMarvelDoc = (ClusterStatsMarvelDoc) marvelDoc;
assertThat(clusterStatsMarvelDoc.clusterUUID(), equalTo(client().admin().cluster().prepareState().setMetaData(true).get().getState().metaData().clusterUUID()));
assertThat(clusterStatsMarvelDoc.timestamp(), greaterThan(0L));
assertThat(clusterStatsMarvelDoc.type(), equalTo(ClusterStatsCollector.TYPE));
assertThat(clusterStatsMarvelDoc.type(), equalTo(ClusterStatsCollector.CLUSTER_STATS_TYPE));
assertNotNull(clusterStatsMarvelDoc.getClusterStats());
assertThat(clusterStatsMarvelDoc.getClusterStats().getNodesStats().getCounts().getTotal(), equalTo(internalCluster().getNodeNames().length));
@ -51,7 +75,7 @@ public class ClusterStatsCollectorTests extends AbstractCollectorTestCase {
logger.debug("--> enabling license and checks that the collector can collect data if node is master");
enableLicense();
if (node.equals(internalCluster().getMasterName())) {
assertCanCollect(collector);
assertCanCollect(collector, ClusterInfoMarvelDoc.class, ClusterStatsMarvelDoc.class);
} else {
assertCannotCollect(collector);
}
@ -59,18 +83,26 @@ public class ClusterStatsCollectorTests extends AbstractCollectorTestCase {
logger.debug("--> starting graceful period and checks that the collector can still collect data if node is master");
beginGracefulPeriod();
if (node.equals(internalCluster().getMasterName())) {
assertCanCollect(collector);
assertCanCollect(collector, ClusterInfoMarvelDoc.class, ClusterStatsMarvelDoc.class);
} else {
assertCannotCollect(collector);
}
logger.debug("--> ending graceful period and checks that the collector cannot collect data");
logger.debug("--> ending graceful period and checks that the collector can still collect data (if node is master)");
endGracefulPeriod();
assertCannotCollect(collector);
if (node.equals(internalCluster().getMasterName())) {
assertCanCollect(collector, ClusterInfoMarvelDoc.class);
} else {
assertCannotCollect(collector);
}
logger.debug("--> disabling license and checks that the collector cannot collect data");
logger.debug("--> disabling license and checks that the collector can still collect data (if node is master)");
disableLicense();
assertCannotCollect(collector);
if (node.equals(internalCluster().getMasterName())) {
assertCanCollect(collector, ClusterInfoMarvelDoc.class);
} else {
assertCannotCollect(collector);
}
}
} finally {
// Ensure license is enabled before finishing the test
@ -89,6 +121,19 @@ public class ClusterStatsCollectorTests extends AbstractCollectorTestCase {
internalCluster().getInstance(ClusterService.class, nodeId),
internalCluster().getInstance(MarvelSettings.class, nodeId),
internalCluster().getInstance(MarvelLicensee.class, nodeId),
securedClient(nodeId));
securedClient(nodeId),
internalCluster().getInstance(LicensesManagerService.class, nodeId),
internalCluster().getInstance(ClusterName.class, nodeId));
}
private void assertCanCollect(AbstractCollector collector, Class<?>... classes) {
super.assertCanCollect(collector);
Collection results = collector.collect();
if (classes != null) {
assertThat(results.size(), equalTo(classes.length));
for (Class<?> cl : classes) {
assertThat(results.stream().filter(o -> cl.isInstance(o)).count(), equalTo(1));
}
}
}
}

View File

@ -8,16 +8,12 @@ package org.elasticsearch.marvel.agent.exporter;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.marvel.agent.collector.Collector;
import org.elasticsearch.marvel.agent.collector.cluster.ClusterInfoCollector;
import org.elasticsearch.marvel.agent.collector.node.NodeStatsCollector;
import org.elasticsearch.marvel.agent.collector.cluster.ClusterStatsCollector;
import org.elasticsearch.marvel.agent.settings.MarvelSettings;
import org.elasticsearch.marvel.test.MarvelIntegTestCase;
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
@ -157,12 +153,8 @@ public abstract class AbstractExporterTemplateTestCase extends MarvelIntegTestCa
}
protected void doExporting() throws Exception {
List<MarvelDoc> docs = new ArrayList<>();
for (Class<? extends Collector> collectorClass : Arrays.asList(ClusterInfoCollector.class, NodeStatsCollector.class)) {
Collector collector = internalCluster().getInstance(collectorClass);
docs.addAll(collector.collect());
}
exporter().export(docs);
Collector collector = internalCluster().getInstance(ClusterStatsCollector.class);
exporter().export(collector.collect());
}
private Exporter exporter() {
@ -187,6 +179,33 @@ public abstract class AbstractExporterTemplateTestCase extends MarvelIntegTestCa
.field("index.number_of_replicas", 1)
.field(MarvelTemplateUtils.VERSION_FIELD, String.valueOf(version))
.endObject()
.endObject().bytes();
.startObject("mappings")
.startObject("_default_")
.startObject("_all")
.field("enabled", false)
.endObject()
.field("date_detection", false)
.startObject("properties")
.startObject("cluster_uuid")
.field("type", "string")
.field("index", "not_analyzed")
.endObject()
.startObject("timestamp")
.field("type", "date")
.field("format", "date_time")
.endObject()
.endObject()
.endObject()
.startObject("cluster_info")
.field("enabled", false)
.endObject()
.startObject("cluster_stats")
.startObject("properties")
.startObject("cluster_stats")
.field("type", "object")
.endObject()
.endObject()
.endObject()
.endObject().bytes();
}
}

View File

@ -11,7 +11,7 @@ import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.license.core.License;
import org.elasticsearch.marvel.agent.collector.cluster.ClusterInfoCollector;
import org.elasticsearch.marvel.agent.collector.cluster.ClusterStatsCollector;
import org.elasticsearch.marvel.agent.exporter.MarvelTemplateUtils;
import org.elasticsearch.marvel.agent.settings.MarvelSettings;
import org.elasticsearch.marvel.test.MarvelIntegTestCase;
@ -39,7 +39,7 @@ public class ClusterInfoTests extends MarvelIntegTestCase {
return Settings.builder()
.put(super.nodeSettings(nodeOrdinal))
.put(MarvelSettings.INTERVAL_SETTING.getKey(), "-1")
.put(MarvelSettings.COLLECTORS_SETTING.getKey(), ClusterInfoCollector.NAME)
.put(MarvelSettings.COLLECTORS_SETTING.getKey(), ClusterStatsCollector.NAME)
.build();
}
@ -65,17 +65,15 @@ public class ClusterInfoTests extends MarvelIntegTestCase {
awaitIndexExists(dataIndex);
logger.debug("--> waiting for cluster info collector to collect data");
awaitMarvelDocsCount(equalTo(1L), ClusterInfoCollector.TYPE);
awaitMarvelDocsCount(equalTo(1L), ClusterStatsCollector.CLUSTER_INFO_TYPE);
logger.debug("--> retrieving cluster info document");
GetResponse response = client().prepareGet(dataIndex, ClusterInfoCollector.TYPE, clusterUUID).get();
GetResponse response = client().prepareGet(dataIndex, ClusterStatsCollector.CLUSTER_INFO_TYPE, clusterUUID).get();
assertTrue("cluster_info document does not exist in data index", response.isExists());
logger.debug("--> checking that the document contains all required information");
logger.debug("--> checking that the document contains license information");
assertThat(response.getIndex(), equalTo(dataIndex));
assertThat(response.getType(), equalTo(ClusterInfoCollector.TYPE));
assertThat(response.getType(), equalTo(ClusterStatsCollector.CLUSTER_INFO_TYPE));
assertThat(response.getId(), equalTo(clusterUUID));
Map<String, Object> source = response.getSource();
@ -124,7 +122,7 @@ public class ClusterInfoTests extends MarvelIntegTestCase {
assertHitCount(client().prepareSearch().setSize(0)
.setIndices(dataIndex)
.setTypes(ClusterInfoCollector.TYPE)
.setTypes(ClusterStatsCollector.CLUSTER_INFO_TYPE)
.setQuery(QueryBuilders.boolQuery()
.should(QueryBuilders.matchQuery(License.XFields.STATUS.underscore().toString(), License.Status.ACTIVE.label()))
.should(QueryBuilders.matchQuery(License.XFields.STATUS.underscore().toString(), License.Status.INVALID.label()))

View File

@ -61,13 +61,13 @@ public class ClusterStatsTests extends MarvelIntegTestCase {
// ok.. we'll start collecting now...
updateMarvelInterval(3L, TimeUnit.SECONDS);
awaitMarvelDocsCount(greaterThan(0L), ClusterStatsCollector.TYPE);
awaitMarvelDocsCount(greaterThan(0L), ClusterStatsCollector.CLUSTER_STATS_TYPE);
assertBusy(new Runnable() {
@Override
public void run() {
logger.debug("--> checking that every document contains the expected fields");
SearchResponse response = client().prepareSearch().setTypes(ClusterStatsCollector.TYPE).get();
SearchResponse response = client().prepareSearch().setTypes(ClusterStatsCollector.CLUSTER_STATS_TYPE).get();
String[] filters = ClusterStatsRenderer.FILTERS;
for (SearchHit searchHit : response.getHits().getHits()) {
Map<String, Object> fields = searchHit.sourceAsMap();