From 1ec293a4a6fbc8189647b3b8a913add32ef9a9e2 Mon Sep 17 00:00:00 2001 From: Tanguy Leroux Date: Thu, 13 Aug 2015 11:40:31 +0200 Subject: [PATCH] Marvel: Add indices options to Index Stats/Recovery collectors Original commit: elastic/x-pack-elasticsearch@a4bc62dff77dc7fea57d654fdd073e9420748bfc --- .../collector/indices/IndexRecoveryCollector.java | 3 +++ .../collector/indices/IndexStatsCollector.java | 2 ++ .../indices/IndexRecoveryCollectorTests.java | 15 +++++++++++---- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/marvel/src/main/java/org/elasticsearch/marvel/agent/collector/indices/IndexRecoveryCollector.java b/marvel/src/main/java/org/elasticsearch/marvel/agent/collector/indices/IndexRecoveryCollector.java index 6645cbedadc..418ac53271e 100644 --- a/marvel/src/main/java/org/elasticsearch/marvel/agent/collector/indices/IndexRecoveryCollector.java +++ b/marvel/src/main/java/org/elasticsearch/marvel/agent/collector/indices/IndexRecoveryCollector.java @@ -7,6 +7,7 @@ package org.elasticsearch.marvel.agent.collector.indices; import com.google.common.collect.ImmutableList; import org.elasticsearch.action.admin.indices.recovery.RecoveryResponse; +import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.client.Client; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterService; @@ -48,6 +49,8 @@ public class IndexRecoveryCollector extends AbstractCollector results = ImmutableList.builder(); RecoveryResponse recoveryResponse = client.admin().indices().prepareRecoveries() + .setIndices(marvelSettings.indices()) + .setIndicesOptions(IndicesOptions.lenientExpandOpen()) .setActiveOnly(marvelSettings.recoveryActiveOnly()) .get(marvelSettings.recoveryTimeout()); diff --git a/marvel/src/main/java/org/elasticsearch/marvel/agent/collector/indices/IndexStatsCollector.java b/marvel/src/main/java/org/elasticsearch/marvel/agent/collector/indices/IndexStatsCollector.java index 44a80935876..129bbde8364 100644 --- a/marvel/src/main/java/org/elasticsearch/marvel/agent/collector/indices/IndexStatsCollector.java +++ b/marvel/src/main/java/org/elasticsearch/marvel/agent/collector/indices/IndexStatsCollector.java @@ -8,6 +8,7 @@ package org.elasticsearch.marvel.agent.collector.indices; import com.google.common.collect.ImmutableList; import org.elasticsearch.action.admin.indices.stats.IndexStats; import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse; +import org.elasticsearch.action.support.IndicesOptions; import org.elasticsearch.client.Client; import org.elasticsearch.cluster.ClusterName; import org.elasticsearch.cluster.ClusterService; @@ -50,6 +51,7 @@ public class IndexStatsCollector extends AbstractCollector IndicesStatsResponse indicesStats = client.admin().indices().prepareStats() .setIndices(marvelSettings.indices()) + .setIndicesOptions(IndicesOptions.lenientExpandOpen()) .get(marvelSettings.indexStatsTimeout()); long timestamp = System.currentTimeMillis(); diff --git a/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/indices/IndexRecoveryCollectorTests.java b/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/indices/IndexRecoveryCollectorTests.java index 5c0742c1bef..7adcae71f23 100644 --- a/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/indices/IndexRecoveryCollectorTests.java +++ b/marvel/src/test/java/org/elasticsearch/marvel/agent/collector/indices/IndexRecoveryCollectorTests.java @@ -33,19 +33,20 @@ import static org.hamcrest.Matchers.*; @ESIntegTestCase.ClusterScope(numDataNodes = 0) public class IndexRecoveryCollectorTests extends ESIntegTestCase { - private boolean activeOnly = false; + private final boolean activeOnly = false; + private final String indexName = "test"; @Override protected Settings nodeSettings(int nodeOrdinal) { return settingsBuilder() .put(super.nodeSettings(nodeOrdinal)) .put(MarvelSettingsService.INDEX_RECOVERY_ACTIVE_ONLY, activeOnly) + .put(MarvelSettingsService.INDICES, indexName) .build(); } @Test public void testIndexRecoveryCollector() throws Exception { - final String indexName = "test"; logger.info("--> start first node"); final String node1 = internalCluster().startNode(); @@ -58,7 +59,7 @@ public class IndexRecoveryCollectorTests extends ESIntegTestCase { assertNotNull(results); assertThat(results, is(empty())); - logger.info("--> create index on node: {}", node1); + logger.info("--> create index [{}] on node [{}]", indexName, node1); assertAcked(prepareCreate(indexName, 1, settingsBuilder().put(SETTING_NUMBER_OF_SHARDS, 3).put(SETTING_NUMBER_OF_REPLICAS, 1))); logger.info("--> indexing sample data"); @@ -66,8 +67,13 @@ public class IndexRecoveryCollectorTests extends ESIntegTestCase { for (int i = 0; i < numDocs; i++) { client().prepareIndex(indexName, "foo").setSource("value", randomInt()).get(); } - flushAndRefresh(indexName); + + logger.info("--> create a second index [other] that won't be part of stats collection", indexName, node1); + client().prepareIndex("other", "bar").setSource("value", randomInt()).get(); + + flushAndRefresh(); assertHitCount(client().prepareCount(indexName).get(), numDocs); + assertHitCount(client().prepareCount("other").get(), 1L); logger.info("--> start second node"); final String node2 = internalCluster().startNode(); @@ -109,6 +115,7 @@ public class IndexRecoveryCollectorTests extends ESIntegTestCase { assertThat(shardRecoveries.size(), greaterThan(0)); for (ShardRecoveryResponse shardRecovery : shardRecoveries) { + assertThat(shardRecovery.getIndex(), equalTo(indexName)); assertThat(shardRecovery.recoveryState().getType(), anyOf(equalTo(RecoveryState.Type.RELOCATION), equalTo(RecoveryState.Type.STORE), equalTo(RecoveryState.Type.REPLICA))); } }