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); return closeLatch.await(timeout, timeUnit);
} }
/** public NodeIndicesStats stats(CommonStatsFlags flags) {
* Returns the node stats indices stats. The {@code includePrevious} flag controls CommonStats commonStats = new CommonStats(flags);
* if old shards stats will be aggregated as well (only for relevant stats, such as // the cumulative statistics also account for shards that are no longer on this node, which is tracked by oldShardsStats
* refresh and indexing, not for docs/store). for (Flag flag : flags.getFlags()) {
*/
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) { switch (flag) {
case Get: case Get:
oldStats.get.add(oldShardsStats.getStats); commonStats.get.add(oldShardsStats.getStats);
break; break;
case Indexing: case Indexing:
oldStats.indexing.add(oldShardsStats.indexingStats); commonStats.indexing.add(oldShardsStats.indexingStats);
break; break;
case Search: case Search:
oldStats.search.add(oldShardsStats.searchStats); commonStats.search.add(oldShardsStats.searchStats);
break; break;
case Merge: case Merge:
oldStats.merge.add(oldShardsStats.mergeStats); commonStats.merge.add(oldShardsStats.mergeStats);
break; break;
case Refresh: case Refresh:
oldStats.refresh.add(oldShardsStats.refreshStats); commonStats.refresh.add(oldShardsStats.refreshStats);
break; break;
case Recovery: case Recovery:
oldStats.recoveryStats.add(oldShardsStats.recoveryStats); commonStats.recoveryStats.add(oldShardsStats.recoveryStats);
break; break;
case Flush: case Flush:
oldStats.flush.add(oldShardsStats.flushStats); commonStats.flush.add(oldShardsStats.flushStats);
break; 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) { 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 // 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) // only be applied to the sensible ones to use, like refresh/merge/flush/indexing stats)
return new NodeStats(transportService.getLocalNode(), System.currentTimeMillis(), 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, os ? monitorService.osService().stats() : null,
process ? monitorService.processService().stats() : null, process ? monitorService.processService().stats() : null,
jvm ? monitorService.jvmService().stats() : null, jvm ? monitorService.jvmService().stats() : null,