Marvel: Update Shard mapping
Closes elastic/elasticsearch#751 Original commit: elastic/x-pack-elasticsearch@af4276785c
This commit is contained in:
parent
daf4a9765c
commit
0ebc6198ac
|
@ -252,7 +252,30 @@
|
||||||
"index": "not_analyzed"
|
"index": "not_analyzed"
|
||||||
},
|
},
|
||||||
"shard": {
|
"shard": {
|
||||||
"type": "object"
|
"properties": {
|
||||||
|
"state": {
|
||||||
|
"type": "string",
|
||||||
|
"index": "not_analyzed"
|
||||||
|
},
|
||||||
|
"primary": {
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
"index": {
|
||||||
|
"type": "string",
|
||||||
|
"index": "not_analyzed"
|
||||||
|
},
|
||||||
|
"relocating_node": {
|
||||||
|
"type": "string",
|
||||||
|
"index": "not_analyzed"
|
||||||
|
},
|
||||||
|
"shard": {
|
||||||
|
"type": "long"
|
||||||
|
},
|
||||||
|
"node": {
|
||||||
|
"type": "string",
|
||||||
|
"index": "not_analyzed"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,27 +6,37 @@
|
||||||
package org.elasticsearch.marvel.agent.renderer.shards;
|
package org.elasticsearch.marvel.agent.renderer.shards;
|
||||||
|
|
||||||
import org.apache.lucene.util.LuceneTestCase.AwaitsFix;
|
import org.apache.lucene.util.LuceneTestCase.AwaitsFix;
|
||||||
|
import org.elasticsearch.action.search.SearchRequestBuilder;
|
||||||
import org.elasticsearch.action.search.SearchResponse;
|
import org.elasticsearch.action.search.SearchResponse;
|
||||||
|
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||||
import org.elasticsearch.common.settings.Settings;
|
import org.elasticsearch.common.settings.Settings;
|
||||||
|
import org.elasticsearch.index.query.QueryBuilders;
|
||||||
import org.elasticsearch.marvel.agent.collector.shards.ShardsCollector;
|
import org.elasticsearch.marvel.agent.collector.shards.ShardsCollector;
|
||||||
import org.elasticsearch.marvel.agent.settings.MarvelSettings;
|
import org.elasticsearch.marvel.agent.settings.MarvelSettings;
|
||||||
import org.elasticsearch.marvel.test.MarvelIntegTestCase;
|
import org.elasticsearch.marvel.test.MarvelIntegTestCase;
|
||||||
import org.elasticsearch.search.SearchHit;
|
import org.elasticsearch.search.SearchHit;
|
||||||
|
import org.elasticsearch.search.aggregations.Aggregation;
|
||||||
|
import org.elasticsearch.search.aggregations.AggregationBuilders;
|
||||||
|
import org.elasticsearch.search.aggregations.bucket.terms.StringTerms;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.greaterThan;
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
||||||
|
import static org.hamcrest.Matchers.*;
|
||||||
|
|
||||||
@AwaitsFix(bugUrl="https://github.com/elastic/x-plugins/issues/729")
|
@AwaitsFix(bugUrl="https://github.com/elastic/x-plugins/issues/729")
|
||||||
public class ShardsIT extends MarvelIntegTestCase {
|
public class ShardsIT extends MarvelIntegTestCase {
|
||||||
|
|
||||||
|
private static final String INDEX_PREFIX = "test-shards-";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Settings nodeSettings(int nodeOrdinal) {
|
protected Settings nodeSettings(int nodeOrdinal) {
|
||||||
return Settings.builder()
|
return Settings.builder()
|
||||||
.put(super.nodeSettings(nodeOrdinal))
|
.put(super.nodeSettings(nodeOrdinal))
|
||||||
.put(MarvelSettings.INTERVAL, "3s")
|
.put(MarvelSettings.INTERVAL, "3s")
|
||||||
.put(MarvelSettings.COLLECTORS, ShardsCollector.NAME)
|
.put(MarvelSettings.COLLECTORS, ShardsCollector.NAME)
|
||||||
|
.put(MarvelSettings.INDICES, INDEX_PREFIX + "*")
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +44,7 @@ public class ShardsIT extends MarvelIntegTestCase {
|
||||||
public void testShards() throws Exception {
|
public void testShards() throws Exception {
|
||||||
logger.debug("--> creating some indices so that shards collector reports data");
|
logger.debug("--> creating some indices so that shards collector reports data");
|
||||||
for (int i = 0; i < randomIntBetween(1, 5); i++) {
|
for (int i = 0; i < randomIntBetween(1, 5); i++) {
|
||||||
client().prepareIndex("test-" + i, "foo").setRefresh(true).setSource("field1", "value1").get();
|
client().prepareIndex(INDEX_PREFIX + i, "foo").setRefresh(true).setSource("field1", "value1").get();
|
||||||
}
|
}
|
||||||
|
|
||||||
awaitMarvelDocsCount(greaterThan(0L), ShardsCollector.TYPE);
|
awaitMarvelDocsCount(greaterThan(0L), ShardsCollector.TYPE);
|
||||||
|
@ -55,4 +65,34 @@ public class ShardsIT extends MarvelIntegTestCase {
|
||||||
|
|
||||||
logger.debug("--> shards successfully collected");
|
logger.debug("--> shards successfully collected");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This test uses a terms aggregation to check that the "not_analyzed"
|
||||||
|
* fields of the "shards" document type are indeed not analyzed
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testNotAnalyzedFields() throws Exception {
|
||||||
|
final String indexName = INDEX_PREFIX + randomInt();
|
||||||
|
assertAcked(prepareCreate(indexName).setSettings(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1, IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0));
|
||||||
|
|
||||||
|
awaitMarvelDocsCount(greaterThan(0L), ShardsCollector.TYPE);
|
||||||
|
|
||||||
|
SearchRequestBuilder searchRequestBuilder = client()
|
||||||
|
.prepareSearch()
|
||||||
|
.setTypes(ShardsCollector.TYPE)
|
||||||
|
.setQuery(QueryBuilders.termQuery("shard.index", indexName));
|
||||||
|
|
||||||
|
String[] notAnalyzedFields = {"state_uuid", "shard.state", "shard.index", "shard.node"};
|
||||||
|
for (String field : notAnalyzedFields) {
|
||||||
|
searchRequestBuilder.addAggregation(AggregationBuilders.terms("agg_" + field.replace('.', '_')).field(field));
|
||||||
|
}
|
||||||
|
|
||||||
|
SearchResponse response = searchRequestBuilder.get();
|
||||||
|
assertThat(response.getHits().getTotalHits(), greaterThanOrEqualTo(1L));
|
||||||
|
|
||||||
|
for (Aggregation aggregation : response.getAggregations()) {
|
||||||
|
assertThat(aggregation, instanceOf(StringTerms.class));
|
||||||
|
assertThat(((StringTerms) aggregation).getBuckets().size(), equalTo(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue