Remove always-true param from IndicesService#stats (#45231)

Parameter `includePrevious` is always true, so this commit inlines it.
This commit is contained in:
David Turner 2019-08-06 17:21:27 +01:00
parent 355713b9ca
commit f5d1381e01
2 changed files with 28 additions and 40 deletions

View File

@ -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<Index, List<IndexShardStats>> statsByShard(final IndicesService indicesService, final CommonStatsFlags flags) {

View File

@ -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,