Skip to content

Commit 1475ace

Browse files
authored
Use IDENTITY constants when creating stats in TrainedModelsStatsAction (elastic#123894) (elastic#124202)
1 parent ac38ef2 commit 1475ace

File tree

2 files changed

+13
-19
lines changed

2 files changed

+13
-19
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/GetTrainedModelsStatsAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public static class TrainedModelStats implements ToXContentObject, Writeable {
9090
private final int pipelineCount;
9191

9292
private static final IngestStats EMPTY_INGEST_STATS = new IngestStats(
93-
new IngestStats.Stats(0, 0, 0, 0),
93+
IngestStats.Stats.IDENTITY,
9494
Collections.emptyList(),
9595
Collections.emptyMap()
9696
);

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportGetTrainedModelsStatsAction.java

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -428,24 +428,11 @@ static IngestStats ingestStatsForPipelineIds(NodeStats nodeStats, Set<String> pi
428428
.stream()
429429
.filter(pipelineStat -> pipelineIds.contains(pipelineStat.pipelineId()))
430430
.collect(Collectors.toList());
431-
CounterMetric ingestCount = new CounterMetric();
432-
CounterMetric ingestTimeInMillis = new CounterMetric();
433-
CounterMetric ingestCurrent = new CounterMetric();
434-
CounterMetric ingestFailedCount = new CounterMetric();
431+
IngestStatsAccumulator accumulator = new IngestStatsAccumulator();
435432

436-
filteredPipelineStats.forEach(pipelineStat -> {
437-
IngestStats.Stats stats = pipelineStat.stats();
438-
ingestCount.inc(stats.ingestCount());
439-
ingestTimeInMillis.inc(stats.ingestTimeInMillis());
440-
ingestCurrent.inc(stats.ingestCurrent());
441-
ingestFailedCount.inc(stats.ingestFailedCount());
442-
});
433+
filteredPipelineStats.forEach(pipelineStat -> accumulator.inc(pipelineStat.stats()));
443434

444-
return new IngestStats(
445-
new IngestStats.Stats(ingestCount.count(), ingestTimeInMillis.count(), ingestCurrent.count(), ingestFailedCount.count()),
446-
filteredPipelineStats,
447-
filteredProcessorStats
448-
);
435+
return new IngestStats(accumulator.build(), filteredPipelineStats, filteredProcessorStats);
449436
}
450437

451438
private static IngestStats mergeStats(List<IngestStats> ingestStatsList) {
@@ -515,7 +502,13 @@ void inc(IngestStats.Stats s) {
515502
}
516503

517504
IngestStats.Stats build() {
518-
return new IngestStats.Stats(ingestCount.count(), ingestTimeInMillis.count(), ingestCurrent.count(), ingestFailedCount.count());
505+
IngestStats.Stats stats = new IngestStats.Stats(
506+
ingestCount.count(),
507+
ingestTimeInMillis.count(),
508+
ingestCurrent.count(),
509+
ingestFailedCount.count()
510+
);
511+
return stats.equals(IngestStats.Stats.IDENTITY) ? IngestStats.Stats.IDENTITY : stats;
519512
}
520513
}
521514

@@ -535,7 +528,8 @@ IngestStats.Stats buildStats() {
535528
}
536529

537530
IngestStats.ByteStats buildByteStats() {
538-
return new IngestStats.ByteStats(ingestBytesConsumed.count(), ingestBytesProduced.count());
531+
IngestStats.ByteStats byteStats = new IngestStats.ByteStats(ingestBytesConsumed.count(), ingestBytesProduced.count());
532+
return byteStats.equals(IngestStats.ByteStats.IDENTITY) ? IngestStats.ByteStats.IDENTITY : byteStats;
539533
}
540534

541535
}

0 commit comments

Comments
 (0)