mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-25 01:19:02 +00:00
Add Index UUID to /_stats
Response (#31871)
* Add "uuid" field to each index's section in the `/_stats` response * closes #31791
This commit is contained in:
parent
15740d6229
commit
4b5071f2d0
@ -47,7 +47,9 @@ setup:
|
||||
- match: { _shards.total: 18 }
|
||||
- is_true: _all
|
||||
- is_true: indices.test1
|
||||
- is_true: indices.test1.uuid
|
||||
- is_true: indices.test2
|
||||
- is_true: indices.test2.uuid
|
||||
|
||||
|
||||
---
|
||||
|
@ -29,10 +29,13 @@ public class IndexStats implements Iterable<IndexShardStats> {
|
||||
|
||||
private final String index;
|
||||
|
||||
private final String uuid;
|
||||
|
||||
private final ShardStats shards[];
|
||||
|
||||
public IndexStats(String index, ShardStats[] shards) {
|
||||
public IndexStats(String index, String uuid, ShardStats[] shards) {
|
||||
this.index = index;
|
||||
this.uuid = uuid;
|
||||
this.shards = shards;
|
||||
}
|
||||
|
||||
@ -40,6 +43,10 @@ public class IndexStats implements Iterable<IndexShardStats> {
|
||||
return this.index;
|
||||
}
|
||||
|
||||
public String getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public ShardStats[] getShards() {
|
||||
return this.shards;
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.common.io.stream.StreamOutput;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.index.Index;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@ -84,19 +85,22 @@ public class IndicesStatsResponse extends BroadcastResponse {
|
||||
}
|
||||
Map<String, IndexStats> indicesStats = new HashMap<>();
|
||||
|
||||
Set<String> indices = new HashSet<>();
|
||||
Set<Index> indices = new HashSet<>();
|
||||
for (ShardStats shard : shards) {
|
||||
indices.add(shard.getShardRouting().getIndexName());
|
||||
indices.add(shard.getShardRouting().index());
|
||||
}
|
||||
|
||||
for (String indexName : indices) {
|
||||
for (Index index : indices) {
|
||||
List<ShardStats> shards = new ArrayList<>();
|
||||
String indexName = index.getName();
|
||||
for (ShardStats shard : this.shards) {
|
||||
if (shard.getShardRouting().getIndexName().equals(indexName)) {
|
||||
shards.add(shard);
|
||||
}
|
||||
}
|
||||
indicesStats.put(indexName, new IndexStats(indexName, shards.toArray(new ShardStats[shards.size()])));
|
||||
indicesStats.put(
|
||||
indexName, new IndexStats(indexName, index.getUUID(), shards.toArray(new ShardStats[shards.size()]))
|
||||
);
|
||||
}
|
||||
this.indicesStats = indicesStats;
|
||||
return indicesStats;
|
||||
@ -169,7 +173,7 @@ public class IndicesStatsResponse extends BroadcastResponse {
|
||||
builder.startObject(Fields.INDICES);
|
||||
for (IndexStats indexStats : getIndices().values()) {
|
||||
builder.startObject(indexStats.getIndex());
|
||||
|
||||
builder.field("uuid", indexStats.getUuid());
|
||||
builder.startObject("primaries");
|
||||
indexStats.getPrimaries().toXContent(builder, params);
|
||||
builder.endObject();
|
||||
|
@ -153,6 +153,13 @@ public class IndicesStatsTests extends ESSingleNodeTestCase {
|
||||
assertEquals(0, common.refresh.getListeners());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testUuidOnRootStatsIndices() {
|
||||
String uuid = createIndex("test").indexUUID();
|
||||
IndicesStatsResponse rsp = client().admin().indices().prepareStats().get();
|
||||
assertEquals(uuid, rsp.getIndex("test").getUuid());
|
||||
}
|
||||
|
||||
/**
|
||||
* Gives access to package private IndicesStatsResponse constructor for test purpose.
|
||||
**/
|
||||
@ -160,5 +167,4 @@ public class IndicesStatsTests extends ESSingleNodeTestCase {
|
||||
int failedShards, List<DefaultShardOperationFailedException> shardFailures) {
|
||||
return new IndicesStatsResponse(shards, totalShards, successfulShards, failedShards, shardFailures);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ public class IndicesStatsMonitoringDocTests extends BaseFilteredMonitoringDocTes
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
indicesStats = Collections.singletonList(new IndexStats("index-0", new ShardStats[] {
|
||||
indicesStats = Collections.singletonList(new IndexStats("index-0", "dcvO5uZATE-EhIKc3tk9Bg", new ShardStats[] {
|
||||
// Primaries
|
||||
new ShardStats(mockShardRouting(true), mockShardPath(), mockCommonStats(), null, null),
|
||||
new ShardStats(mockShardRouting(true), mockShardPath(), mockCommonStats(), null, null),
|
||||
|
Loading…
x
Reference in New Issue
Block a user