Skip to content

Commit 9828e11

Browse files
authored
Expose CommonStatsFlags directly in IndicesStatsRequest. (#30163)
This allows us to simplify the logic in a couple places where all flags need to be accessed.
1 parent c87a3ea commit 9828e11

File tree

3 files changed

+24
-77
lines changed

3 files changed

+24
-77
lines changed

server/src/main/java/org/elasticsearch/action/admin/indices/stats/IndicesStatsRequest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,21 @@ public IndicesStatsRequest clear() {
5454
return this;
5555
}
5656

57+
/**
58+
* Returns the underlying stats flags.
59+
*/
60+
public CommonStatsFlags flags() {
61+
return flags;
62+
}
63+
64+
/**
65+
* Sets the underlying stats flags.
66+
*/
67+
public IndicesStatsRequest flags(CommonStatsFlags flags) {
68+
this.flags = flags;
69+
return this;
70+
}
71+
5772
/**
5873
* Document types to return stats for. Mainly affects {@link #indexing(boolean)} when
5974
* enabled, returning specific indexing stats for those types.

server/src/main/java/org/elasticsearch/action/admin/indices/stats/TransportIndicesStatsAction.java

Lines changed: 3 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -99,65 +99,8 @@ protected ShardStats shardOperation(IndicesStatsRequest request, ShardRouting sh
9999
throw new ShardNotFoundException(indexShard.shardId());
100100
}
101101

102-
CommonStatsFlags flags = new CommonStatsFlags().clear();
103-
104-
if (request.docs()) {
105-
flags.set(CommonStatsFlags.Flag.Docs);
106-
}
107-
if (request.store()) {
108-
flags.set(CommonStatsFlags.Flag.Store);
109-
}
110-
if (request.indexing()) {
111-
flags.set(CommonStatsFlags.Flag.Indexing);
112-
flags.types(request.types());
113-
}
114-
if (request.get()) {
115-
flags.set(CommonStatsFlags.Flag.Get);
116-
}
117-
if (request.search()) {
118-
flags.set(CommonStatsFlags.Flag.Search);
119-
flags.groups(request.groups());
120-
}
121-
if (request.merge()) {
122-
flags.set(CommonStatsFlags.Flag.Merge);
123-
}
124-
if (request.refresh()) {
125-
flags.set(CommonStatsFlags.Flag.Refresh);
126-
}
127-
if (request.flush()) {
128-
flags.set(CommonStatsFlags.Flag.Flush);
129-
}
130-
if (request.warmer()) {
131-
flags.set(CommonStatsFlags.Flag.Warmer);
132-
}
133-
if (request.queryCache()) {
134-
flags.set(CommonStatsFlags.Flag.QueryCache);
135-
}
136-
if (request.fieldData()) {
137-
flags.set(CommonStatsFlags.Flag.FieldData);
138-
flags.fieldDataFields(request.fieldDataFields());
139-
}
140-
if (request.segments()) {
141-
flags.set(CommonStatsFlags.Flag.Segments);
142-
flags.includeSegmentFileSizes(request.includeSegmentFileSizes());
143-
}
144-
if (request.completion()) {
145-
flags.set(CommonStatsFlags.Flag.Completion);
146-
flags.completionDataFields(request.completionFields());
147-
}
148-
if (request.translog()) {
149-
flags.set(CommonStatsFlags.Flag.Translog);
150-
}
151-
if (request.requestCache()) {
152-
flags.set(CommonStatsFlags.Flag.RequestCache);
153-
}
154-
if (request.recovery()) {
155-
flags.set(CommonStatsFlags.Flag.Recovery);
156-
}
157-
158-
return new ShardStats(
159-
indexShard.routingEntry(),
160-
indexShard.shardPath(),
161-
new CommonStats(indicesService.getIndicesQueryCache(), indexShard, flags), indexShard.commitStats(), indexShard.seqNoStats());
102+
CommonStats commonStats = new CommonStats(indicesService.getIndicesQueryCache(), indexShard, request.flags());
103+
return new ShardStats(indexShard.routingEntry(), indexShard.shardPath(), commonStats,
104+
indexShard.commitStats(), indexShard.seqNoStats());
162105
}
163106
}

server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestIndicesStatsAction.java

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
package org.elasticsearch.rest.action.admin.indices;
2121

22+
import org.elasticsearch.action.admin.indices.stats.CommonStatsFlags;
23+
import org.elasticsearch.action.admin.indices.stats.CommonStatsFlags.Flag;
2224
import org.elasticsearch.action.admin.indices.stats.IndicesStatsRequest;
2325
import org.elasticsearch.action.support.IndicesOptions;
2426
import org.elasticsearch.client.node.NodeClient;
@@ -57,23 +59,10 @@ public String getName() {
5759
static final Map<String, Consumer<IndicesStatsRequest>> METRICS;
5860

5961
static {
60-
final Map<String, Consumer<IndicesStatsRequest>> metrics = new HashMap<>();
61-
metrics.put("docs", r -> r.docs(true));
62-
metrics.put("store", r -> r.store(true));
63-
metrics.put("indexing", r -> r.indexing(true));
64-
metrics.put("search", r -> r.search(true));
65-
metrics.put("get", r -> r.get(true));
66-
metrics.put("merge", r -> r.merge(true));
67-
metrics.put("refresh", r -> r.refresh(true));
68-
metrics.put("flush", r -> r.flush(true));
69-
metrics.put("warmer", r -> r.warmer(true));
70-
metrics.put("query_cache", r -> r.queryCache(true));
71-
metrics.put("segments", r -> r.segments(true));
72-
metrics.put("fielddata", r -> r.fieldData(true));
73-
metrics.put("completion", r -> r.completion(true));
74-
metrics.put("request_cache", r -> r.requestCache(true));
75-
metrics.put("recovery", r -> r.recovery(true));
76-
metrics.put("translog", r -> r.translog(true));
62+
Map<String, Consumer<IndicesStatsRequest>> metrics = new HashMap<>();
63+
for (Flag flag : CommonStatsFlags.Flag.values()) {
64+
metrics.put(flag.getRestName(), m -> m.flags().set(flag, true));
65+
}
7766
METRICS = Collections.unmodifiableMap(metrics);
7867
}
7968

0 commit comments

Comments
 (0)