Skip to content
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

Introduce includeShardsStats in the stats request to indicate that we only fetch a summary #100466

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
Next Next commit
introduce needShardsStats in the stats request to only fetch a summary
  • Loading branch information
NEUpanning committed Oct 7, 2023
commit 0d5aecf55764e083cb48d03d6dabc7e845e740f1
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ static TransportVersion def(int id) {
public static final TransportVersion NESTED_KNN_VECTOR_QUERY_V = def(8_511_00_0);
public static final TransportVersion ML_PACKAGE_LOADER_PLATFORM_ADDED = def(8_512_00_0);
public static final TransportVersion PLUGIN_DESCRIPTOR_OPTIONAL_CLASSNAME = def(8_513_00_0);
public static final TransportVersion NEED_SHARDS_STATS_ADDED = def(8_514_00_0);
/*
* STOP! READ THIS FIRST! No, really,
* ____ _____ ___ ____ _ ____ _____ _ ____ _____ _ _ ___ ____ _____ ___ ____ ____ _____ _
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package org.elasticsearch.action.admin.cluster.node.stats;

import org.elasticsearch.TransportVersions;
import org.elasticsearch.action.admin.indices.stats.CommonStatsFlags;
import org.elasticsearch.action.support.nodes.BaseNodesRequest;
import org.elasticsearch.common.Strings;
Expand All @@ -33,6 +34,7 @@ public class NodesStatsRequest extends BaseNodesRequest<NodesStatsRequest> {

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming nit/suggestion:

Suggested change
private boolean needShardsStats = true;
private boolean includeShardsStats = true;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. Fixed in 373cc6f


public NodesStatsRequest() {
super((String[]) null);
Expand All @@ -44,6 +46,9 @@ public NodesStatsRequest(StreamInput in) throws IOException {
indices = new CommonStatsFlags(in);
requestedMetrics.clear();
requestedMetrics.addAll(in.readStringCollectionAsList());
if (in.getTransportVersion().onOrAfter(TransportVersions.NEED_SHARDS_STATS_ADDED)) {
needShardsStats = in.readBoolean();
}
DaveCTurner marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down Expand Up @@ -169,11 +174,22 @@ public String getDescription() {
};
}

public boolean needShardsStats() {
return needShardsStats;
}

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

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
indices.writeTo(out);
out.writeStringCollection(requestedMetrics);
if (out.getTransportVersion().onOrAfter(TransportVersions.NEED_SHARDS_STATS_ADDED)) {
out.writeBoolean(needShardsStats);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ protected NodeStats nodeOperation(NodeStatsRequest nodeStatsRequest, Task task)
Set<String> metrics = request.requestedMetrics();
return nodeService.stats(
request.indices(),
request.needShardsStats(),
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 @@ -182,6 +182,7 @@ protected ClusterStatsNodeResponse nodeOperation(ClusterStatsNodeRequest nodeReq
NodeInfo nodeInfo = nodeService.info(true, true, false, true, false, true, false, false, true, false, false, false);
NodeStats nodeStats = nodeService.stats(
CommonStatsFlags.NONE,
false,
true,
true,
true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ private DiskUsage getDiskUsage() {
false,
false,
false,
false,
true,
false,
false,
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) {
public NodeIndicesStats stats(CommonStatsFlags flags, boolean needShardsStats) {
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,7 @@ public NodeIndicesStats stats(CommonStatsFlags flags) {
}
}

return new NodeIndicesStats(commonStats, statsByIndex(this, flags), statsByShard(this, flags));
return new NodeIndicesStats(commonStats, statsByIndex(this, flags), needShardsStats ? statsByShard(this, flags) : new HashMap<>(0));
DaveCTurner marked this conversation as resolved.
Show resolved Hide resolved
}

static Map<Index, CommonStats> statsByIndex(final IndicesService indicesService, final CommonStatsFlags flags) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ private Map<String, Integer> findComponentVersions() {

public NodeStats stats(
CommonStatsFlags indices,
boolean needShardsStats,
boolean os,
boolean process,
boolean jvm,
Expand All @@ -176,7 +177,7 @@ public NodeStats stats(
return new NodeStats(
transportService.getLocalNode(),
System.currentTimeMillis(),
indices.anySet() ? indicesService.stats(indices) : null,
indices.anySet() ? indicesService.stats(indices, needShardsStats) : 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 @@ -91,7 +91,8 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC
NodesStatsRequest nodesStatsRequest = new NodesStatsRequest(nodesIds);
nodesStatsRequest.timeout(request.param("timeout"));
// level parameter validation
NodeStatsLevel.of(request, NodeStatsLevel.NODE);
final NodeStatsLevel nodeStatsLevel = NodeStatsLevel.of(request, NodeStatsLevel.NODE);
nodesStatsRequest.setNeedShardsStats(nodeStatsLevel == NodeStatsLevel.NODE ? false : true);

if (metrics.size() == 1 && metrics.contains("_all")) {
if (request.hasParam("index_metric")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ public void testNoDiskData() {
eq(false),
eq(false),
eq(false),
eq(false),
eq(true),
eq(false),
eq(false),
Expand Down Expand Up @@ -386,6 +387,7 @@ private void simulateDiskOutOfSpace() {
eq(false),
eq(false),
eq(false),
eq(false),
eq(true),
eq(false),
eq(false),
Expand All @@ -409,6 +411,7 @@ private void initializeIncreasedDiskSpaceUsage() {
eq(false),
eq(false),
eq(false),
eq(false),
eq(true),
eq(false),
eq(false),
Expand All @@ -432,6 +435,7 @@ private void simulateHealthDiskSpace() {
eq(false),
eq(false),
eq(false),
eq(false),
eq(true),
eq(false),
eq(false),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2460,6 +2460,7 @@ public void ensureEstimatedStats() {
false,
false,
false,
false,
false
);
assertThat(
Expand Down