diff --git a/marvel/src/main/java/org/elasticsearch/marvel/agent/collector/CollectorModule.java b/marvel/src/main/java/org/elasticsearch/marvel/agent/collector/CollectorModule.java index 25b71d3f5a1..2f092b11203 100644 --- a/marvel/src/main/java/org/elasticsearch/marvel/agent/collector/CollectorModule.java +++ b/marvel/src/main/java/org/elasticsearch/marvel/agent/collector/CollectorModule.java @@ -7,7 +7,7 @@ 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.indices.IndexCollector; +import org.elasticsearch.marvel.agent.collector.indices.IndexStatsCollector; import java.util.HashSet; import java.util.Set; @@ -18,7 +18,7 @@ public class CollectorModule extends AbstractModule { public CollectorModule() { // Registers default collectors - registerCollector(IndexCollector.class); + registerCollector(IndexStatsCollector.class); } @Override diff --git a/marvel/src/main/java/org/elasticsearch/marvel/agent/collector/indices/IndexCollector.java b/marvel/src/main/java/org/elasticsearch/marvel/agent/collector/indices/IndexStatsCollector.java similarity index 86% rename from marvel/src/main/java/org/elasticsearch/marvel/agent/collector/indices/IndexCollector.java rename to marvel/src/main/java/org/elasticsearch/marvel/agent/collector/indices/IndexStatsCollector.java index 6df746e713d..f3184d68723 100644 --- a/marvel/src/main/java/org/elasticsearch/marvel/agent/collector/indices/IndexCollector.java +++ b/marvel/src/main/java/org/elasticsearch/marvel/agent/collector/indices/IndexStatsCollector.java @@ -21,19 +21,19 @@ import java.util.Collection; /** * Collector for indices statistics. * - * This collector runs on the master node only and collect a {@link IndexMarvelDoc} document + * This collector runs on the master node only and collect a {@link IndexStatsMarvelDoc} document * for each existing index in the cluster. */ -public class IndexCollector extends AbstractCollector { +public class IndexStatsCollector extends AbstractCollector { - public static final String NAME = "index-collector"; + public static final String NAME = "index-stats-collector"; protected static final String TYPE = "marvel_index"; private final ClusterName clusterName; private final Client client; @Inject - public IndexCollector(Settings settings, ClusterService clusterService, ClusterName clusterName, Client client) { + public IndexStatsCollector(Settings settings, ClusterService clusterService, ClusterName clusterName, Client client) { super(settings, NAME, clusterService); this.client = client; this.clusterName = clusterName; @@ -62,7 +62,7 @@ public class IndexCollector extends AbstractCollector { } protected MarvelDoc buildMarvelDoc(String clusterName, String type, long timestamp, IndexStats indexStats) { - return IndexMarvelDoc.createMarvelDoc(clusterName, type, timestamp, + return IndexStatsMarvelDoc.createMarvelDoc(clusterName, type, timestamp, indexStats.getIndex(), indexStats.getTotal().getDocs().getCount(), indexStats.getTotal().getStore().sizeInBytes(), indexStats.getTotal().getStore().throttleTime().millis(), diff --git a/marvel/src/main/java/org/elasticsearch/marvel/agent/collector/indices/IndexMarvelDoc.java b/marvel/src/main/java/org/elasticsearch/marvel/agent/collector/indices/IndexStatsMarvelDoc.java similarity index 92% rename from marvel/src/main/java/org/elasticsearch/marvel/agent/collector/indices/IndexMarvelDoc.java rename to marvel/src/main/java/org/elasticsearch/marvel/agent/collector/indices/IndexStatsMarvelDoc.java index 890f9af7751..9cae619e181 100644 --- a/marvel/src/main/java/org/elasticsearch/marvel/agent/collector/indices/IndexMarvelDoc.java +++ b/marvel/src/main/java/org/elasticsearch/marvel/agent/collector/indices/IndexStatsMarvelDoc.java @@ -14,15 +14,15 @@ import org.elasticsearch.marvel.agent.exporter.MarvelDoc; import java.io.IOException; import java.util.concurrent.TimeUnit; -public class IndexMarvelDoc extends MarvelDoc { +public class IndexStatsMarvelDoc extends MarvelDoc { private final String index; private final Docs docs; private final Store store; private final Indexing indexing; - public IndexMarvelDoc(String clusterName, String type, long timestamp, - String index, Docs docs, Store store, Indexing indexing) { + public IndexStatsMarvelDoc(String clusterName, String type, long timestamp, + String index, Docs docs, Store store, Indexing indexing) { super(clusterName, type, timestamp); this.index = index; this.docs = docs; @@ -31,7 +31,7 @@ public class IndexMarvelDoc extends MarvelDoc { } @Override - public IndexMarvelDoc payload() { + public IndexStatsMarvelDoc payload() { return this; } @@ -69,9 +69,9 @@ public class IndexMarvelDoc extends MarvelDoc { return builder; } - public static IndexMarvelDoc createMarvelDoc(String clusterName, String type, long timestamp, + public static IndexStatsMarvelDoc createMarvelDoc(String clusterName, String type, long timestamp, String index, long docsCount, long storeSizeInBytes, long storeThrottleTimeInMillis, long indexingThrottleTimeInMillis) { - return new IndexMarvelDoc(clusterName, type, timestamp, index, + return new IndexStatsMarvelDoc(clusterName, type, timestamp, index, new Docs(docsCount), new Store(storeSizeInBytes, storeThrottleTimeInMillis), new Indexing(indexingThrottleTimeInMillis)); diff --git a/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/indices/IndexCollectorTests.java b/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/indices/IndexCollectorTests.java deleted file mode 100644 index cd01c2d9562..00000000000 --- a/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/indices/IndexCollectorTests.java +++ /dev/null @@ -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.indices; - -import org.elasticsearch.cluster.ClusterName; -import org.elasticsearch.cluster.ClusterService; -import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.marvel.agent.exporter.MarvelDoc; -import org.elasticsearch.test.ElasticsearchSingleNodeTest; -import org.junit.Test; - -import java.util.Collection; -import java.util.Iterator; - -import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount; -import static org.hamcrest.Matchers.*; - -public class IndexCollectorTests extends ElasticsearchSingleNodeTest { - - @Test - public void testIndexCollectorNoIndices() throws Exception { - Collection results = newIndexCollector().doCollect(); - assertThat(results, is(empty())); - } - - @Test - public void testIndexCollectorOneIndex() throws Exception { - int nbDocs = randomIntBetween(1, 20); - for (int i = 0; i < nbDocs; i++) { - client().prepareIndex("test", "test").setSource("num", i).get(); - } - client().admin().indices().prepareRefresh().get(); - assertHitCount(client().prepareCount().get(), nbDocs); - - Collection results = newIndexCollector().doCollect(); - assertThat(results, hasSize(1)); - - MarvelDoc marvelDoc = results.iterator().next(); - assertNotNull(marvelDoc); - assertThat(marvelDoc, instanceOf(IndexMarvelDoc.class)); - - IndexMarvelDoc indexMarvelDoc = (IndexMarvelDoc) marvelDoc; - assertThat(indexMarvelDoc.clusterName(), equalTo(client().admin().cluster().prepareHealth().get().getClusterName())); - assertThat(indexMarvelDoc.timestamp(), greaterThan(0L)); - assertThat(indexMarvelDoc.type(), equalTo(IndexCollector.TYPE)); - - assertThat(indexMarvelDoc.getIndex(), equalTo("test")); - assertNotNull(indexMarvelDoc.getDocs()); - assertThat(indexMarvelDoc.getDocs().getCount(), equalTo((long) nbDocs)); - assertNotNull(indexMarvelDoc.getStore()); - assertThat(indexMarvelDoc.getStore().getSizeInBytes(), greaterThan(0L)); - assertThat(indexMarvelDoc.getStore().getThrottleTimeInMillis(), equalTo(0L)); - assertNotNull(indexMarvelDoc.getIndexing()); - assertThat(indexMarvelDoc.getIndexing().getThrottleTimeInMillis(), equalTo(0L)); - } - - @Test - public void testIndexCollectorMultipleIndices() throws Exception { - int nbIndices = randomIntBetween(1, 5); - int[] docsPerIndex = new int[nbIndices]; - - for (int i = 0; i < nbIndices; i++) { - docsPerIndex[i] = randomIntBetween(1, 20); - for (int j = 0; j < docsPerIndex[i]; j++) { - client().prepareIndex("test-" + i, "test").setSource("num", i).get(); - } - } - - String clusterName = client().admin().cluster().prepareHealth().get().getClusterName(); - client().admin().indices().prepareRefresh().get(); - for (int i = 0; i < nbIndices; i++) { - assertHitCount(client().prepareCount("test-" + i).get(), docsPerIndex[i]); - } - - Collection results = newIndexCollector().doCollect(); - assertThat(results, hasSize(nbIndices)); - - for (int i = 0; i < nbIndices; i++) { - boolean found = false; - - Iterator it = results.iterator(); - while (!found && it.hasNext()) { - MarvelDoc marvelDoc = it.next(); - assertThat(marvelDoc, instanceOf(IndexMarvelDoc.class)); - - IndexMarvelDoc indexMarvelDoc = (IndexMarvelDoc) marvelDoc; - if (indexMarvelDoc.getIndex().equals("test-" + i)) { - assertThat(indexMarvelDoc.clusterName(), equalTo(clusterName)); - assertThat(indexMarvelDoc.timestamp(), greaterThan(0L)); - assertThat(indexMarvelDoc.type(), equalTo(IndexCollector.TYPE)); - - assertNotNull(indexMarvelDoc.getDocs()); - assertThat(indexMarvelDoc.getDocs().getCount(), equalTo((long) docsPerIndex[i])); - assertNotNull(indexMarvelDoc.getStore()); - assertThat(indexMarvelDoc.getStore().getSizeInBytes(), greaterThan(0L)); - assertThat(indexMarvelDoc.getStore().getThrottleTimeInMillis(), equalTo(0L)); - assertNotNull(indexMarvelDoc.getIndexing()); - assertThat(indexMarvelDoc.getIndexing().getThrottleTimeInMillis(), equalTo(0L)); - found = true; - } - } - assertThat("could not find collected stats for index [test-" + i + "]", found, is(true)); - } - } - - private IndexCollector newIndexCollector() { - return new IndexCollector(getInstanceFromNode(Settings.class), getInstanceFromNode(ClusterService.class), getInstanceFromNode(ClusterName.class), client()); - } -} diff --git a/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/indices/IndexStatsCollectorTests.java b/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/indices/IndexStatsCollectorTests.java new file mode 100644 index 00000000000..a0ddabe185d --- /dev/null +++ b/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/indices/IndexStatsCollectorTests.java @@ -0,0 +1,112 @@ +/* + * 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.indices; + +import org.elasticsearch.cluster.ClusterName; +import org.elasticsearch.cluster.ClusterService; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.marvel.agent.exporter.MarvelDoc; +import org.elasticsearch.test.ElasticsearchSingleNodeTest; +import org.junit.Test; + +import java.util.Collection; +import java.util.Iterator; + +import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount; +import static org.hamcrest.Matchers.*; + +public class IndexStatsCollectorTests extends ElasticsearchSingleNodeTest { + + @Test + public void testIndexStatsCollectorNoIndices() throws Exception { + Collection results = newIndexStatsCollector().doCollect(); + assertThat(results, is(empty())); + } + + @Test + public void testIndexStatsCollectorOneIndex() throws Exception { + int nbDocs = randomIntBetween(1, 20); + for (int i = 0; i < nbDocs; i++) { + client().prepareIndex("test", "test").setSource("num", i).get(); + } + client().admin().indices().prepareRefresh().get(); + assertHitCount(client().prepareCount().get(), nbDocs); + + Collection results = newIndexStatsCollector().doCollect(); + assertThat(results, hasSize(1)); + + MarvelDoc marvelDoc = results.iterator().next(); + assertNotNull(marvelDoc); + assertThat(marvelDoc, instanceOf(IndexStatsMarvelDoc.class)); + + IndexStatsMarvelDoc indexStatsMarvelDoc = (IndexStatsMarvelDoc) marvelDoc; + assertThat(indexStatsMarvelDoc.clusterName(), equalTo(client().admin().cluster().prepareHealth().get().getClusterName())); + assertThat(indexStatsMarvelDoc.timestamp(), greaterThan(0L)); + assertThat(indexStatsMarvelDoc.type(), equalTo(IndexStatsCollector.TYPE)); + + assertThat(indexStatsMarvelDoc.getIndex(), equalTo("test")); + assertNotNull(indexStatsMarvelDoc.getDocs()); + assertThat(indexStatsMarvelDoc.getDocs().getCount(), equalTo((long) nbDocs)); + assertNotNull(indexStatsMarvelDoc.getStore()); + assertThat(indexStatsMarvelDoc.getStore().getSizeInBytes(), greaterThan(0L)); + assertThat(indexStatsMarvelDoc.getStore().getThrottleTimeInMillis(), equalTo(0L)); + assertNotNull(indexStatsMarvelDoc.getIndexing()); + assertThat(indexStatsMarvelDoc.getIndexing().getThrottleTimeInMillis(), equalTo(0L)); + } + + @Test + public void testIndexStatsCollectorMultipleIndices() throws Exception { + int nbIndices = randomIntBetween(1, 5); + int[] docsPerIndex = new int[nbIndices]; + + for (int i = 0; i < nbIndices; i++) { + docsPerIndex[i] = randomIntBetween(1, 20); + for (int j = 0; j < docsPerIndex[i]; j++) { + client().prepareIndex("test-" + i, "test").setSource("num", i).get(); + } + } + + String clusterName = client().admin().cluster().prepareHealth().get().getClusterName(); + client().admin().indices().prepareRefresh().get(); + for (int i = 0; i < nbIndices; i++) { + assertHitCount(client().prepareCount("test-" + i).get(), docsPerIndex[i]); + } + + Collection results = newIndexStatsCollector().doCollect(); + assertThat(results, hasSize(nbIndices)); + + for (int i = 0; i < nbIndices; i++) { + boolean found = false; + + Iterator it = results.iterator(); + while (!found && it.hasNext()) { + MarvelDoc marvelDoc = it.next(); + assertThat(marvelDoc, instanceOf(IndexStatsMarvelDoc.class)); + + IndexStatsMarvelDoc indexStatsMarvelDoc = (IndexStatsMarvelDoc) marvelDoc; + if (indexStatsMarvelDoc.getIndex().equals("test-" + i)) { + assertThat(indexStatsMarvelDoc.clusterName(), equalTo(clusterName)); + assertThat(indexStatsMarvelDoc.timestamp(), greaterThan(0L)); + assertThat(indexStatsMarvelDoc.type(), equalTo(IndexStatsCollector.TYPE)); + + assertNotNull(indexStatsMarvelDoc.getDocs()); + assertThat(indexStatsMarvelDoc.getDocs().getCount(), equalTo((long) docsPerIndex[i])); + assertNotNull(indexStatsMarvelDoc.getStore()); + assertThat(indexStatsMarvelDoc.getStore().getSizeInBytes(), greaterThan(0L)); + assertThat(indexStatsMarvelDoc.getStore().getThrottleTimeInMillis(), equalTo(0L)); + assertNotNull(indexStatsMarvelDoc.getIndexing()); + assertThat(indexStatsMarvelDoc.getIndexing().getThrottleTimeInMillis(), equalTo(0L)); + found = true; + } + } + assertThat("could not find collected stats for index [test-" + i + "]", found, is(true)); + } + } + + private IndexStatsCollector newIndexStatsCollector() { + return new IndexStatsCollector(getInstanceFromNode(Settings.class), getInstanceFromNode(ClusterService.class), getInstanceFromNode(ClusterName.class), client()); + } +} diff --git a/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/indices/IndexMarvelDocTests.java b/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/indices/IndexStatsMarvelDocTests.java similarity index 90% rename from marvel/src/test/java/org/elasticsearch/marvel/agent/collector/indices/IndexMarvelDocTests.java rename to marvel/src/test/java/org/elasticsearch/marvel/agent/collector/indices/IndexStatsMarvelDocTests.java index 4401c3f70de..07739ee0e6f 100644 --- a/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/indices/IndexMarvelDocTests.java +++ b/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/indices/IndexStatsMarvelDocTests.java @@ -10,7 +10,7 @@ import org.junit.Test; import static org.hamcrest.Matchers.equalTo; -public class IndexMarvelDocTests extends ElasticsearchTestCase { +public class IndexStatsMarvelDocTests extends ElasticsearchTestCase { @Test public void testCreateMarvelDoc() { @@ -23,7 +23,7 @@ public class IndexMarvelDocTests extends ElasticsearchTestCase { long storeThrottle = randomLong(); long indexingThrottle = randomLong(); - IndexMarvelDoc marvelDoc = IndexMarvelDoc.createMarvelDoc(cluster, type, timestamp, + IndexStatsMarvelDoc marvelDoc = IndexStatsMarvelDoc.createMarvelDoc(cluster, type, timestamp, index, docsCount, storeSize, storeThrottle, indexingThrottle); assertNotNull(marvelDoc); diff --git a/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/HttpESExporterTests.java b/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/HttpESExporterTests.java index 2d23979d652..5c9b6ac2670 100644 --- a/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/HttpESExporterTests.java +++ b/marvel/src/test/java/org/elasticsearch/marvel/agent/exporter/HttpESExporterTests.java @@ -12,7 +12,7 @@ import org.elasticsearch.cluster.metadata.IndexTemplateMetaData; import org.elasticsearch.common.Strings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.marvel.agent.AgentService; -import org.elasticsearch.marvel.agent.collector.indices.IndexMarvelDoc; +import org.elasticsearch.marvel.agent.collector.indices.IndexStatsMarvelDoc; import org.elasticsearch.node.Node; import org.elasticsearch.test.ElasticsearchIntegrationTest; import org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope; @@ -224,7 +224,7 @@ public class HttpESExporterTests extends ElasticsearchIntegrationTest { final static AtomicLong timeStampGenerator = new AtomicLong(); private MarvelDoc newRandomMarvelDoc() { - return IndexMarvelDoc.createMarvelDoc(internalCluster().getClusterName(), "test_marvelDoc", timeStampGenerator.incrementAndGet(), + return IndexStatsMarvelDoc.createMarvelDoc(internalCluster().getClusterName(), "test_marvelDoc", timeStampGenerator.incrementAndGet(), "test_index", randomInt(), randomLong(), randomLong(), randomLong()); } }