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 5 commits
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
5 changes: 5 additions & 0 deletions docs/changelog/100466.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 100466
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 @@ -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 includeShardsStats = true;

public NodesStatsRequest() {
super((String[]) null);
Expand All @@ -44,6 +46,11 @@ 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)) {
includeShardsStats = in.readBoolean();
} else {
includeShardsStats = true;
}
DaveCTurner marked this conversation as resolved.
Show resolved Hide resolved
}

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

public boolean includeShardsStats() {
return includeShardsStats;
}

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

@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(includeShardsStats);
}
}

/**
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.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 @@ -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 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,7 @@ public NodeIndicesStats stats(CommonStatsFlags flags) {
}
}

return new NodeIndicesStats(commonStats, statsByIndex(this, flags), statsByShard(this, flags));
return new NodeIndicesStats(commonStats, statsByIndex(this, flags), statsByShard(this, flags), includeShardsStats);
}

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 @@ -59,6 +59,7 @@
public class NodeIndicesStats implements Writeable, ChunkedToXContent {

private static final TransportVersion VERSION_SUPPORTING_STATS_BY_INDEX = TransportVersions.V_8_5_0;
public static final HashMap<Index, List<IndexShardStats>> EMPTY_STATS_BY_SHARD = new HashMap<>(0);
NEUpanning marked this conversation as resolved.
Show resolved Hide resolved

private final CommonStats stats;
private final Map<Index, List<IndexShardStats>> statsByShard;
Expand Down Expand Up @@ -86,8 +87,17 @@ public NodeIndicesStats(StreamInput in) throws IOException {
}
}

public NodeIndicesStats(CommonStats oldStats, Map<Index, CommonStats> statsByIndex, Map<Index, List<IndexShardStats>> statsByShard) {
this.statsByShard = Objects.requireNonNull(statsByShard);
public NodeIndicesStats(
CommonStats oldStats,
Map<Index, CommonStats> statsByIndex,
Map<Index, List<IndexShardStats>> statsByShard,
boolean includeShardsStats
) {
if (includeShardsStats) {
this.statsByShard = Objects.requireNonNull(statsByShard);
} else {
this.statsByShard = EMPTY_STATS_BY_SHARD;
}
this.statsByIndex = Objects.requireNonNull(statsByIndex);

// make a total common stats from old ones and current ones
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 includeShardsStats,
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, 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 @@ -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.setIncludeShardsStats(nodeStatsLevel == NodeStatsLevel.NODE ? false : true);
NEUpanning marked this conversation as resolved.
Show resolved Hide resolved

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 @@ -680,7 +680,7 @@ public static NodeStats createNodeStats() {
statsByShard.put(indexTest, indexShardStats);

CommonStats oldStats = new CommonStats(CommonStatsFlags.ALL);
nodeIndicesStats = new NodeIndicesStats(oldStats, statsByIndex, statsByShard);
nodeIndicesStats = new NodeIndicesStats(oldStats, statsByIndex, statsByShard, true);
}
OsStats osStats = null;
if (frequently()) {
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 @@ -19,7 +19,7 @@
public class NodeIndicesStatsTests extends ESTestCase {

public void testInvalidLevel() {
final NodeIndicesStats stats = new NodeIndicesStats(null, Collections.emptyMap(), Collections.emptyMap());
final NodeIndicesStats stats = new NodeIndicesStats(null, Collections.emptyMap(), Collections.emptyMap(), true);
NEUpanning marked this conversation as resolved.
Show resolved Hide resolved
final String level = randomAlphaOfLength(16);
final ToXContent.Params params = new ToXContent.MapParams(Collections.singletonMap("level", level));
final IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> stats.toXContentChunked(params));
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
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ private List<NodeStats> buildNodeStats(ClusterState clusterState, long bytesPerS
IndexShardStats shardStats = new IndexShardStats(shardId, new ShardStats[] { shardStat });
indexStats.computeIfAbsent(shardId.getIndex(), k -> new ArrayList<>()).add(shardStats);
}
NodeIndicesStats nodeIndexStats = new NodeIndicesStats(new CommonStats(), Collections.emptyMap(), indexStats);
NodeIndicesStats nodeIndexStats = new NodeIndicesStats(new CommonStats(), Collections.emptyMap(), indexStats, true);
NEUpanning marked this conversation as resolved.
Show resolved Hide resolved
nodeStatsList.add(mockNodeStats(node, nodeIndexStats));
}
return nodeStatsList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ private static NodeStats mockNodeStats() {
segmentsStats.addBitsetMemoryInBytes(++iota);
indicesCommonStats.getSegments().add(segmentsStats);

final NodeIndicesStats indices = new NodeIndicesStats(indicesCommonStats, emptyMap(), emptyMap());
final NodeIndicesStats indices = new NodeIndicesStats(indicesCommonStats, emptyMap(), emptyMap(), true);
NEUpanning marked this conversation as resolved.
Show resolved Hide resolved

// Filesystem
final FsInfo.DeviceStats ioStatsOne = new FsInfo.DeviceStats(
Expand Down