Skip to content

Commit

Permalink
Naming nit
Browse files Browse the repository at this point in the history
  • Loading branch information
NEUpanning committed Oct 9, 2023
1 parent c31ecc7 commit 373cc6f
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion docs/changelog/100466.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pr: 100466
summary: "Introduce needShardsStats in the stats request to indicate that we only fetch a summary"
summary: "Introduce includeShardsStats in the stats request to indicate that we only fetch a summary"
area: Stats
type: enhancement
issues: [99744]
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class NodesStatsRequest extends BaseNodesRequest<NodesStatsRequest> {

private CommonStatsFlags indices = new CommonStatsFlags();
private final Set<String> requestedMetrics = new HashSet<>();
private boolean needShardsStats = true;
private boolean includeShardsStats = true;

public NodesStatsRequest() {
super((String[]) null);
Expand All @@ -47,9 +47,9 @@ public NodesStatsRequest(StreamInput in) throws IOException {
requestedMetrics.clear();
requestedMetrics.addAll(in.readStringCollectionAsList());
if (in.getTransportVersion().onOrAfter(TransportVersions.NEED_SHARDS_STATS_ADDED)) {
needShardsStats = in.readBoolean();
includeShardsStats = in.readBoolean();
} else {
needShardsStats = true;
includeShardsStats = true;
}
}

Expand Down Expand Up @@ -176,12 +176,12 @@ public String getDescription() {
};
}

public boolean needShardsStats() {
return needShardsStats;
public boolean includeShardsStats() {
return includeShardsStats;
}

public void setNeedShardsStats(boolean needShardsStats) {
this.needShardsStats = needShardsStats;
public void setIncludeShardsStats(boolean includeShardsStats) {
this.includeShardsStats = includeShardsStats;
}

@Override
Expand All @@ -190,7 +190,7 @@ public void writeTo(StreamOutput out) throws IOException {
indices.writeTo(out);
out.writeStringCollection(requestedMetrics);
if (out.getTransportVersion().onOrAfter(TransportVersions.NEED_SHARDS_STATS_ADDED)) {
out.writeBoolean(needShardsStats);
out.writeBoolean(includeShardsStats);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected NodeStats nodeOperation(NodeStatsRequest nodeStatsRequest, Task task)
Set<String> metrics = request.requestedMetrics();
return nodeService.stats(
request.indices(),
request.needShardsStats(),
request.includeShardsStats(),
NodesStatsRequest.Metric.OS.containedIn(metrics),
NodesStatsRequest.Metric.PROCESS.containedIn(metrics),
NodesStatsRequest.Metric.JVM.containedIn(metrics),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ public boolean awaitClose(long timeout, TimeUnit timeUnit) throws InterruptedExc
return closeLatch.await(timeout, timeUnit);
}

public NodeIndicesStats stats(CommonStatsFlags flags, boolean needShardsStats) {
public NodeIndicesStats stats(CommonStatsFlags flags, boolean includeShardsStats) {
CommonStats commonStats = new CommonStats(flags);
// the cumulative statistics also account for shards that are no longer on this node, which is tracked by oldShardsStats
for (Flag flag : flags.getFlags()) {
Expand All @@ -471,7 +471,11 @@ public NodeIndicesStats stats(CommonStatsFlags flags, boolean needShardsStats) {
}
}

return new NodeIndicesStats(commonStats, statsByIndex(this, flags), needShardsStats ? statsByShard(this, flags) : new HashMap<>(0));
return new NodeIndicesStats(
commonStats,
statsByIndex(this, flags),
includeShardsStats ? statsByShard(this, flags) : new HashMap<>(0)
);
}

static Map<Index, CommonStats> statsByIndex(final IndicesService indicesService, final CommonStatsFlags flags) {
Expand Down
4 changes: 2 additions & 2 deletions server/src/main/java/org/elasticsearch/node/NodeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ private Map<String, Integer> findComponentVersions() {

public NodeStats stats(
CommonStatsFlags indices,
boolean needShardsStats,
boolean includeShardsStats,
boolean os,
boolean process,
boolean jvm,
Expand All @@ -177,7 +177,7 @@ public NodeStats stats(
return new NodeStats(
transportService.getLocalNode(),
System.currentTimeMillis(),
indices.anySet() ? indicesService.stats(indices, needShardsStats) : null,
indices.anySet() ? indicesService.stats(indices, includeShardsStats) : null,
os ? monitorService.osService().stats() : null,
process ? monitorService.processService().stats() : null,
jvm ? monitorService.jvmService().stats() : null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
nodesStatsRequest.timeout(request.param("timeout"));
// level parameter validation
final NodeStatsLevel nodeStatsLevel = NodeStatsLevel.of(request, NodeStatsLevel.NODE);
nodesStatsRequest.setNeedShardsStats(nodeStatsLevel == NodeStatsLevel.NODE ? false : true);
nodesStatsRequest.setIncludeShardsStats(nodeStatsLevel == NodeStatsLevel.NODE ? false : true);

if (metrics.size() == 1 && metrics.contains("_all")) {
if (request.hasParam("index_metric")) {
Expand Down

0 comments on commit 373cc6f

Please sign in to comment.