From f5d1381e011265ffd467f0ae58214875f8784612 Mon Sep 17 00:00:00 2001 From: David Turner Date: Tue, 6 Aug 2019 17:21:27 +0100 Subject: [PATCH] Remove always-true param from IndicesService#stats (#45231) Parameter `includePrevious` is always true, so this commit inlines it. --- .../elasticsearch/indices/IndicesService.java | 66 ++++++++----------- .../org/elasticsearch/node/NodeService.java | 2 +- 2 files changed, 28 insertions(+), 40 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/indices/IndicesService.java b/server/src/main/java/org/elasticsearch/indices/IndicesService.java index 4253d15df49..241eb8f4ca8 100644 --- a/server/src/main/java/org/elasticsearch/indices/IndicesService.java +++ b/server/src/main/java/org/elasticsearch/indices/IndicesService.java @@ -328,48 +328,36 @@ public class IndicesService extends AbstractLifecycleComponent return closeLatch.await(timeout, timeUnit); } - /** - * Returns the node stats indices stats. The {@code includePrevious} flag controls - * if old shards stats will be aggregated as well (only for relevant stats, such as - * refresh and indexing, not for docs/store). - */ - public NodeIndicesStats stats(boolean includePrevious) { - return stats(includePrevious, new CommonStatsFlags().all()); - } - - public NodeIndicesStats stats(boolean includePrevious, CommonStatsFlags flags) { - CommonStats oldStats = new CommonStats(flags); - - if (includePrevious) { - Flag[] setFlags = flags.getFlags(); - for (Flag flag : setFlags) { - switch (flag) { - case Get: - oldStats.get.add(oldShardsStats.getStats); - break; - case Indexing: - oldStats.indexing.add(oldShardsStats.indexingStats); - break; - case Search: - oldStats.search.add(oldShardsStats.searchStats); - break; - case Merge: - oldStats.merge.add(oldShardsStats.mergeStats); - break; - case Refresh: - oldStats.refresh.add(oldShardsStats.refreshStats); - break; - case Recovery: - oldStats.recoveryStats.add(oldShardsStats.recoveryStats); - break; - case Flush: - oldStats.flush.add(oldShardsStats.flushStats); - break; - } + public NodeIndicesStats stats(CommonStatsFlags flags) { + 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()) { + switch (flag) { + case Get: + commonStats.get.add(oldShardsStats.getStats); + break; + case Indexing: + commonStats.indexing.add(oldShardsStats.indexingStats); + break; + case Search: + commonStats.search.add(oldShardsStats.searchStats); + break; + case Merge: + commonStats.merge.add(oldShardsStats.mergeStats); + break; + case Refresh: + commonStats.refresh.add(oldShardsStats.refreshStats); + break; + case Recovery: + commonStats.recoveryStats.add(oldShardsStats.recoveryStats); + break; + case Flush: + commonStats.flush.add(oldShardsStats.flushStats); + break; } } - return new NodeIndicesStats(oldStats, statsByShard(this, flags)); + return new NodeIndicesStats(commonStats, statsByShard(this, flags)); } Map> statsByShard(final IndicesService indicesService, final CommonStatsFlags flags) { diff --git a/server/src/main/java/org/elasticsearch/node/NodeService.java b/server/src/main/java/org/elasticsearch/node/NodeService.java index 3f71a21966c..895be6fca60 100644 --- a/server/src/main/java/org/elasticsearch/node/NodeService.java +++ b/server/src/main/java/org/elasticsearch/node/NodeService.java @@ -107,7 +107,7 @@ public class NodeService implements Closeable { // for indices stats we want to include previous allocated shards stats as well (it will // only be applied to the sensible ones to use, like refresh/merge/flush/indexing stats) return new NodeStats(transportService.getLocalNode(), System.currentTimeMillis(), - indices.anySet() ? indicesService.stats(true, indices) : null, + indices.anySet() ? indicesService.stats(indices) : null, os ? monitorService.osService().stats() : null, process ? monitorService.processService().stats() : null, jvm ? monitorService.jvmService().stats() : null,