Search in sources :

Example 21 with NodesStatsResponse

use of org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse in project elasticsearch by elastic.

the class CorruptedFileIT method corruptRandomPrimaryFile.

private ShardRouting corruptRandomPrimaryFile(final boolean includePerCommitFiles) throws IOException {
    ClusterState state = client().admin().cluster().prepareState().get().getState();
    Index test = state.metaData().index("test").getIndex();
    GroupShardsIterator shardIterators = state.getRoutingTable().activePrimaryShardsGrouped(new String[] { "test" }, false);
    List<ShardIterator> iterators = iterableAsArrayList(shardIterators);
    ShardIterator shardIterator = RandomPicks.randomFrom(random(), iterators);
    ShardRouting shardRouting = shardIterator.nextOrNull();
    assertNotNull(shardRouting);
    assertTrue(shardRouting.primary());
    assertTrue(shardRouting.assignedToNode());
    String nodeId = shardRouting.currentNodeId();
    NodesStatsResponse nodeStatses = client().admin().cluster().prepareNodesStats(nodeId).setFs(true).get();
    // treeset makes sure iteration order is deterministic
    Set<Path> files = new TreeSet<>();
    for (FsInfo.Path info : nodeStatses.getNodes().get(0).getFs()) {
        String path = info.getPath();
        Path file = PathUtils.get(path).resolve("indices").resolve(test.getUUID()).resolve(Integer.toString(shardRouting.getId())).resolve("index");
        if (Files.exists(file)) {
            // multi data path might only have one path in use
            try (DirectoryStream<Path> stream = Files.newDirectoryStream(file)) {
                for (Path item : stream) {
                    if (Files.isRegularFile(item) && "write.lock".equals(item.getFileName().toString()) == false) {
                        if (includePerCommitFiles || isPerSegmentFile(item.getFileName().toString())) {
                            files.add(item);
                        }
                    }
                }
            }
        }
    }
    pruneOldDeleteGenerations(files);
    CorruptionUtils.corruptFile(random(), files.toArray(new Path[0]));
    return shardRouting;
}
Also used : Path(java.nio.file.Path) ClusterState(org.elasticsearch.cluster.ClusterState) CheckIndex(org.apache.lucene.index.CheckIndex) Index(org.elasticsearch.index.Index) NodesStatsResponse(org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse) FsInfo(org.elasticsearch.monitor.fs.FsInfo) GroupShardsIterator(org.elasticsearch.cluster.routing.GroupShardsIterator) TreeSet(java.util.TreeSet) ShardIterator(org.elasticsearch.cluster.routing.ShardIterator) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting)

Example 22 with NodesStatsResponse

use of org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse in project elasticsearch by elastic.

the class CorruptedTranslogIT method corruptRandomTranslogFiles.

private void corruptRandomTranslogFiles() throws IOException {
    ClusterState state = client().admin().cluster().prepareState().get().getState();
    GroupShardsIterator shardIterators = state.getRoutingTable().activePrimaryShardsGrouped(new String[] { "test" }, false);
    final Index test = state.metaData().index("test").getIndex();
    List<ShardIterator> iterators = iterableAsArrayList(shardIterators);
    ShardIterator shardIterator = RandomPicks.randomFrom(random(), iterators);
    ShardRouting shardRouting = shardIterator.nextOrNull();
    assertNotNull(shardRouting);
    assertTrue(shardRouting.primary());
    assertTrue(shardRouting.assignedToNode());
    String nodeId = shardRouting.currentNodeId();
    NodesStatsResponse nodeStatses = client().admin().cluster().prepareNodesStats(nodeId).setFs(true).get();
    // treeset makes sure iteration order is deterministic
    Set<Path> files = new TreeSet<>();
    for (FsInfo.Path fsPath : nodeStatses.getNodes().get(0).getFs()) {
        String path = fsPath.getPath();
        final String relativeDataLocationPath = "indices/" + test.getUUID() + "/" + Integer.toString(shardRouting.getId()) + "/translog";
        Path file = PathUtils.get(path).resolve(relativeDataLocationPath);
        if (Files.exists(file)) {
            logger.info("--> path: {}", file);
            try (DirectoryStream<Path> stream = Files.newDirectoryStream(file)) {
                for (Path item : stream) {
                    logger.info("--> File: {}", item);
                    if (Files.isRegularFile(item) && item.getFileName().toString().startsWith("translog-")) {
                        files.add(item);
                    }
                }
            }
        }
    }
    Path fileToCorrupt = null;
    if (!files.isEmpty()) {
        int corruptions = randomIntBetween(5, 20);
        for (int i = 0; i < corruptions; i++) {
            fileToCorrupt = RandomPicks.randomFrom(random(), files);
            try (FileChannel raf = FileChannel.open(fileToCorrupt, StandardOpenOption.READ, StandardOpenOption.WRITE)) {
                // read
                raf.position(randomIntBetween(0, (int) Math.min(Integer.MAX_VALUE, raf.size() - 1)));
                long filePointer = raf.position();
                ByteBuffer bb = ByteBuffer.wrap(new byte[1]);
                raf.read(bb);
                bb.flip();
                // corrupt
                byte oldValue = bb.get(0);
                byte newValue = (byte) (oldValue + 1);
                bb.put(0, newValue);
                // rewrite
                raf.position(filePointer);
                raf.write(bb);
                logger.info("--> corrupting file {} --  flipping at position {} from {} to {} file: {}", fileToCorrupt, filePointer, Integer.toHexString(oldValue), Integer.toHexString(newValue), fileToCorrupt);
            }
        }
    }
    assertThat("no file corrupted", fileToCorrupt, notNullValue());
}
Also used : Path(java.nio.file.Path) ClusterState(org.elasticsearch.cluster.ClusterState) FileChannel(java.nio.channels.FileChannel) Index(org.elasticsearch.index.Index) ByteBuffer(java.nio.ByteBuffer) NodesStatsResponse(org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse) FsInfo(org.elasticsearch.monitor.fs.FsInfo) GroupShardsIterator(org.elasticsearch.cluster.routing.GroupShardsIterator) TreeSet(java.util.TreeSet) ShardIterator(org.elasticsearch.cluster.routing.ShardIterator) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting)

Example 23 with NodesStatsResponse

use of org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse in project elasticsearch by elastic.

the class SearchStatsIT method testSimpleStats.

public void testSimpleStats() throws Exception {
    // clear all stats first
    client().admin().indices().prepareStats().clear().execute().actionGet();
    final int numNodes = cluster().numDataNodes();
    assertThat(numNodes, greaterThanOrEqualTo(2));
    // we make sure each node gets at least a single shard...
    final int shardsIdx1 = randomIntBetween(1, 10);
    final int shardsIdx2 = Math.max(numNodes - shardsIdx1, randomIntBetween(1, 10));
    assertThat(numNodes, lessThanOrEqualTo(shardsIdx1 + shardsIdx2));
    assertAcked(prepareCreate("test1").setSettings(Settings.builder().put(SETTING_NUMBER_OF_SHARDS, shardsIdx1).put(SETTING_NUMBER_OF_REPLICAS, 0)));
    int docsTest1 = scaledRandomIntBetween(3 * shardsIdx1, 5 * shardsIdx1);
    for (int i = 0; i < docsTest1; i++) {
        client().prepareIndex("test1", "type", Integer.toString(i)).setSource("field", "value").execute().actionGet();
        if (rarely()) {
            refresh();
        }
    }
    assertAcked(prepareCreate("test2").setSettings(Settings.builder().put(SETTING_NUMBER_OF_SHARDS, shardsIdx2).put(SETTING_NUMBER_OF_REPLICAS, 0)));
    int docsTest2 = scaledRandomIntBetween(3 * shardsIdx2, 5 * shardsIdx2);
    for (int i = 0; i < docsTest2; i++) {
        client().prepareIndex("test2", "type", Integer.toString(i)).setSource("field", "value").execute().actionGet();
        if (rarely()) {
            refresh();
        }
    }
    assertThat(shardsIdx1 + shardsIdx2, equalTo(numAssignedShards("test1", "test2")));
    assertThat(numAssignedShards("test1", "test2"), greaterThanOrEqualTo(2));
    // THERE WILL BE AT LEAST 2 NODES HERE SO WE CAN WAIT FOR GREEN
    ensureGreen();
    refresh();
    int iters = scaledRandomIntBetween(100, 150);
    for (int i = 0; i < iters; i++) {
        SearchResponse searchResponse = internalCluster().coordOnlyNodeClient().prepareSearch().setQuery(QueryBuilders.termQuery("field", "value")).setStats("group1", "group2").highlighter(new HighlightBuilder().field("field")).addScriptField("script1", new Script(ScriptType.INLINE, CustomScriptPlugin.NAME, "_source.field", Collections.emptyMap())).setSize(100).execute().actionGet();
        assertHitCount(searchResponse, docsTest1 + docsTest2);
        assertAllSuccessful(searchResponse);
    }
    IndicesStatsResponse indicesStats = client().admin().indices().prepareStats().execute().actionGet();
    logger.debug("###### indices search stats: {}", indicesStats.getTotal().getSearch());
    assertThat(indicesStats.getTotal().getSearch().getTotal().getQueryCount(), greaterThan(0L));
    assertThat(indicesStats.getTotal().getSearch().getTotal().getQueryTimeInMillis(), greaterThan(0L));
    assertThat(indicesStats.getTotal().getSearch().getTotal().getFetchCount(), greaterThan(0L));
    assertThat(indicesStats.getTotal().getSearch().getTotal().getFetchTimeInMillis(), greaterThan(0L));
    assertThat(indicesStats.getTotal().getSearch().getGroupStats(), nullValue());
    indicesStats = client().admin().indices().prepareStats().setGroups("group1").execute().actionGet();
    assertThat(indicesStats.getTotal().getSearch().getGroupStats(), notNullValue());
    assertThat(indicesStats.getTotal().getSearch().getGroupStats().get("group1").getQueryCount(), greaterThan(0L));
    assertThat(indicesStats.getTotal().getSearch().getGroupStats().get("group1").getQueryTimeInMillis(), greaterThan(0L));
    assertThat(indicesStats.getTotal().getSearch().getGroupStats().get("group1").getFetchCount(), greaterThan(0L));
    assertThat(indicesStats.getTotal().getSearch().getGroupStats().get("group1").getFetchTimeInMillis(), greaterThan(0L));
    NodesStatsResponse nodeStats = client().admin().cluster().prepareNodesStats().execute().actionGet();
    Set<String> nodeIdsWithIndex = nodeIdsWithIndex("test1", "test2");
    int num = 0;
    for (NodeStats stat : nodeStats.getNodes()) {
        Stats total = stat.getIndices().getSearch().getTotal();
        if (nodeIdsWithIndex.contains(stat.getNode().getId())) {
            assertThat(total.getQueryCount(), greaterThan(0L));
            assertThat(total.getQueryTimeInMillis(), greaterThan(0L));
            num++;
        } else {
            assertThat(total.getQueryCount(), equalTo(0L));
            assertThat(total.getQueryTimeInMillis(), equalTo(0L));
        }
    }
    assertThat(num, greaterThan(0));
}
Also used : NodesStatsResponse(org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse) Script(org.elasticsearch.script.Script) IndicesStatsResponse(org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse) NodeStats(org.elasticsearch.action.admin.cluster.node.stats.NodeStats) NodeStats(org.elasticsearch.action.admin.cluster.node.stats.NodeStats) Stats(org.elasticsearch.index.search.stats.SearchStats.Stats) HighlightBuilder(org.elasticsearch.search.fetch.subphase.highlight.HighlightBuilder) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 24 with NodesStatsResponse

use of org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse in project elasticsearch by elastic.

the class RestNodesAction method doCatRequest.

@Override
public RestChannelConsumer doCatRequest(final RestRequest request, final NodeClient client) {
    final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();
    clusterStateRequest.clear().nodes(true);
    clusterStateRequest.local(request.paramAsBoolean("local", clusterStateRequest.local()));
    clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout()));
    final boolean fullId = request.paramAsBoolean("full_id", false);
    return channel -> client.admin().cluster().state(clusterStateRequest, new RestActionListener<ClusterStateResponse>(channel) {

        @Override
        public void processResponse(final ClusterStateResponse clusterStateResponse) {
            NodesInfoRequest nodesInfoRequest = new NodesInfoRequest();
            nodesInfoRequest.clear().jvm(true).os(true).process(true).http(true);
            client.admin().cluster().nodesInfo(nodesInfoRequest, new RestActionListener<NodesInfoResponse>(channel) {

                @Override
                public void processResponse(final NodesInfoResponse nodesInfoResponse) {
                    NodesStatsRequest nodesStatsRequest = new NodesStatsRequest();
                    nodesStatsRequest.clear().jvm(true).os(true).fs(true).indices(true).process(true).script(true);
                    client.admin().cluster().nodesStats(nodesStatsRequest, new RestResponseListener<NodesStatsResponse>(channel) {

                        @Override
                        public RestResponse buildResponse(NodesStatsResponse nodesStatsResponse) throws Exception {
                            return RestTable.buildResponse(buildTable(fullId, request, clusterStateResponse, nodesInfoResponse, nodesStatsResponse), channel);
                        }
                    });
                }
            });
        }
    });
}
Also used : FieldDataStats(org.elasticsearch.index.fielddata.FieldDataStats) GET(org.elasticsearch.rest.RestRequest.Method.GET) FlushStats(org.elasticsearch.index.flush.FlushStats) Table(org.elasticsearch.common.Table) SegmentsStats(org.elasticsearch.index.engine.SegmentsStats) Strings(org.elasticsearch.common.Strings) DiscoveryNode(org.elasticsearch.cluster.node.DiscoveryNode) Settings(org.elasticsearch.common.settings.Settings) IndexingStats(org.elasticsearch.index.shard.IndexingStats) Locale(java.util.Locale) NodesStatsResponse(org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) NodeStats(org.elasticsearch.action.admin.cluster.node.stats.NodeStats) RestResponseListener(org.elasticsearch.rest.action.RestResponseListener) CompletionStats(org.elasticsearch.search.suggest.completion.CompletionStats) NodeIndicesStats(org.elasticsearch.indices.NodeIndicesStats) ScriptStats(org.elasticsearch.script.ScriptStats) MergeStats(org.elasticsearch.index.merge.MergeStats) JvmInfo(org.elasticsearch.monitor.jvm.JvmInfo) DiscoveryNodes(org.elasticsearch.cluster.node.DiscoveryNodes) FsInfo(org.elasticsearch.monitor.fs.FsInfo) RestResponse(org.elasticsearch.rest.RestResponse) OsStats(org.elasticsearch.monitor.os.OsStats) RestController(org.elasticsearch.rest.RestController) QueryCacheStats(org.elasticsearch.index.cache.query.QueryCacheStats) Collectors(java.util.stream.Collectors) NodesStatsRequest(org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) RequestCacheStats(org.elasticsearch.index.cache.request.RequestCacheStats) JvmStats(org.elasticsearch.monitor.jvm.JvmStats) RefreshStats(org.elasticsearch.index.refresh.RefreshStats) NodesInfoRequest(org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest) TransportAddress(org.elasticsearch.common.transport.TransportAddress) ProcessStats(org.elasticsearch.monitor.process.ProcessStats) ClusterStateRequest(org.elasticsearch.action.admin.cluster.state.ClusterStateRequest) HttpInfo(org.elasticsearch.http.HttpInfo) GetStats(org.elasticsearch.index.get.GetStats) SearchStats(org.elasticsearch.index.search.stats.SearchStats) NodesInfoResponse(org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse) NodeInfo(org.elasticsearch.action.admin.cluster.node.info.NodeInfo) NetworkAddress(org.elasticsearch.common.network.NetworkAddress) RestActionListener(org.elasticsearch.rest.action.RestActionListener) NodesInfoResponse(org.elasticsearch.action.admin.cluster.node.info.NodesInfoResponse) ClusterStateResponse(org.elasticsearch.action.admin.cluster.state.ClusterStateResponse) RestResponse(org.elasticsearch.rest.RestResponse) ClusterStateRequest(org.elasticsearch.action.admin.cluster.state.ClusterStateRequest) RestActionListener(org.elasticsearch.rest.action.RestActionListener) NodesStatsRequest(org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest) NodesStatsResponse(org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse) NodesInfoRequest(org.elasticsearch.action.admin.cluster.node.info.NodesInfoRequest)

Example 25 with NodesStatsResponse

use of org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse in project elasticsearch by elastic.

the class TruncateTranslogIT method getTranslogDirs.

private Set<Path> getTranslogDirs(String indexName) throws IOException {
    ClusterState state = client().admin().cluster().prepareState().get().getState();
    GroupShardsIterator shardIterators = state.getRoutingTable().activePrimaryShardsGrouped(new String[] { indexName }, false);
    final Index idx = state.metaData().index(indexName).getIndex();
    List<ShardIterator> iterators = iterableAsArrayList(shardIterators);
    ShardIterator shardIterator = RandomPicks.randomFrom(random(), iterators);
    ShardRouting shardRouting = shardIterator.nextOrNull();
    assertNotNull(shardRouting);
    assertTrue(shardRouting.primary());
    assertTrue(shardRouting.assignedToNode());
    String nodeId = shardRouting.currentNodeId();
    NodesStatsResponse nodeStatses = client().admin().cluster().prepareNodesStats(nodeId).setFs(true).get();
    // treeset makes sure iteration order is deterministic
    Set<Path> translogDirs = new TreeSet<>();
    for (FsInfo.Path fsPath : nodeStatses.getNodes().get(0).getFs()) {
        String path = fsPath.getPath();
        final String relativeDataLocationPath = "indices/" + idx.getUUID() + "/" + Integer.toString(shardRouting.getId()) + "/translog";
        Path translogPath = PathUtils.get(path).resolve(relativeDataLocationPath);
        if (Files.isDirectory(translogPath)) {
            translogDirs.add(translogPath);
        }
    }
    return translogDirs;
}
Also used : Path(java.nio.file.Path) ClusterState(org.elasticsearch.cluster.ClusterState) Index(org.elasticsearch.index.Index) Matchers.containsString(org.hamcrest.Matchers.containsString) NodesStatsResponse(org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse) FsInfo(org.elasticsearch.monitor.fs.FsInfo) GroupShardsIterator(org.elasticsearch.cluster.routing.GroupShardsIterator) TreeSet(java.util.TreeSet) ShardIterator(org.elasticsearch.cluster.routing.ShardIterator) ShardRouting(org.elasticsearch.cluster.routing.ShardRouting)

Aggregations

NodesStatsResponse (org.elasticsearch.action.admin.cluster.node.stats.NodesStatsResponse)34 NodeStats (org.elasticsearch.action.admin.cluster.node.stats.NodeStats)22 Settings (org.elasticsearch.common.settings.Settings)11 ArrayList (java.util.ArrayList)9 IndicesStatsResponse (org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse)7 Client (org.elasticsearch.client.Client)6 IOException (java.io.IOException)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 NodesStatsRequest (org.elasticsearch.action.admin.cluster.node.stats.NodesStatsRequest)5 ClusterStateResponse (org.elasticsearch.action.admin.cluster.state.ClusterStateResponse)5 ByteSizeValue (org.elasticsearch.common.unit.ByteSizeValue)5 Path (java.nio.file.Path)4 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)4 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)4 SearchResponse (org.elasticsearch.action.search.SearchResponse)4 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)4 Index (org.elasticsearch.index.Index)4 BreakerSettings (org.elasticsearch.indices.breaker.BreakerSettings)4 FsInfo (org.elasticsearch.monitor.fs.FsInfo)4 MockTransportService (org.elasticsearch.test.transport.MockTransportService)4