Skip to content

Get hidden indices stats in GET _cat/shards #86601

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/changelog/86601.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 86601
summary: Get hidden indices stats in `GET _cat/shards`
area: CAT APIs
type: bug
issues:
- 84656
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,28 @@
/^ foo \s+ 0\n
bar \s+ 1\n
$/


---
"Test cat shards with hidden indices":
- do:
indices.create:
index: foo
body:
settings:
number_of_shards: "1"
number_of_replicas: "0"
hidden: "true"

- do:
index:
index: foo
body: { test: foo }
refresh: true

- do:
cat.shards:
h: [index, docs]

- match:
$body: /foo \s+ 1\n/
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
import org.elasticsearch.action.admin.indices.stats.IndicesStatsRequest;
import org.elasticsearch.action.admin.indices.stats.IndicesStatsResponse;
import org.elasticsearch.action.admin.indices.stats.ShardStats;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.client.internal.node.NodeClient;
import org.elasticsearch.cluster.routing.ShardRouting;
import org.elasticsearch.cluster.routing.UnassignedInfo;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.Table;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.util.concurrent.ListenableFuture;
import org.elasticsearch.core.TimeValue;
import org.elasticsearch.index.bulk.stats.BulkStats;
import org.elasticsearch.index.cache.query.QueryCacheStats;
Expand All @@ -38,7 +40,6 @@
import org.elasticsearch.index.warmer.WarmerStats;
import org.elasticsearch.rest.RestRequest;
import org.elasticsearch.rest.RestResponse;
import org.elasticsearch.rest.action.RestActionListener;
import org.elasticsearch.rest.action.RestResponseListener;
import org.elasticsearch.search.suggest.completion.CompletionStats;

Expand Down Expand Up @@ -75,23 +76,30 @@ protected void documentation(StringBuilder sb) {
@Override
public RestChannelConsumer doCatRequest(final RestRequest request, final NodeClient client) {
final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
final ClusterStateRequest clusterStateRequest = new ClusterStateRequest();

final var clusterStateRequest = new ClusterStateRequest();
clusterStateRequest.masterNodeTimeout(request.paramAsTime("master_timeout", clusterStateRequest.masterNodeTimeout()));
clusterStateRequest.clear().nodes(true).routingTable(true).indices(indices);
return channel -> client.admin().cluster().state(clusterStateRequest, new RestActionListener<ClusterStateResponse>(channel) {
@Override
public void processResponse(final ClusterStateResponse clusterStateResponse) {
IndicesStatsRequest indicesStatsRequest = new IndicesStatsRequest();
indicesStatsRequest.all();
indicesStatsRequest.indices(indices);
client.admin().indices().stats(indicesStatsRequest, new RestResponseListener<IndicesStatsResponse>(channel) {
@Override
public RestResponse buildResponse(IndicesStatsResponse indicesStatsResponse) throws Exception {
return RestTable.buildResponse(buildTable(request, clusterStateResponse, indicesStatsResponse), channel);
}
});
}
});
clusterStateRequest.clear().nodes(true).routingTable(true).indices(indices).indicesOptions(IndicesOptions.strictExpandHidden());

return channel -> {
final var clusterStateFuture = new ListenableFuture<ClusterStateResponse>();
client.admin().cluster().state(clusterStateRequest, clusterStateFuture);
client.admin()
.indices()
.stats(
new IndicesStatsRequest().all().indices(indices).indicesOptions(IndicesOptions.strictExpandHidden()),
new RestResponseListener<Table>(channel) {
@Override
public RestResponse buildResponse(Table table) throws Exception {
return RestTable.buildResponse(table, channel);
}
}.delegateFailure(
(delegate, indicesStatsResponse) -> clusterStateFuture.addListener(
delegate.map(clusterStateResponse -> buildTable(request, clusterStateResponse, indicesStatsResponse))
)
)
);
};
}

@Override
Expand Down