Skip to content

Commit 7be43e9

Browse files
committed
Fix ingest stats test bug. (#50653)
This test code fixes a serialization test bug: https://gradle-enterprise.elastic.co/s/7x2ct6yywkw3o Rarely stats for the same processor are generated and the production code then sums up these stats. However the test code wasn't summing up in that case, which caused inconsistencies between the actual and expected results. Closes #50507
1 parent 1299dda commit 7be43e9

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

server/src/test/java/org/elasticsearch/action/admin/cluster/stats/ClusterStatsNodesTests.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,23 @@ public void testIngestStats() throws Exception {
7171
NodeStats nodeStats = randomValueOtherThanMany(n -> n.getIngestStats() == null, NodeStatsTests::createNodeStats);
7272

7373
SortedMap<String, long[]> processorStats = new TreeMap<>();
74-
nodeStats.getIngestStats().getProcessorStats().values().forEach(l -> l.forEach(s -> processorStats.put(s.getType(),
75-
new long[] { s.getStats().getIngestCount(), s.getStats().getIngestFailedCount(),
76-
s.getStats().getIngestCurrent(), s.getStats().getIngestTimeInMillis()})));
74+
nodeStats.getIngestStats().getProcessorStats().values().forEach(stats -> {
75+
stats.forEach(stat -> {
76+
processorStats.compute(stat.getType(), (key, value) -> {
77+
if (value == null) {
78+
return new long[] { stat.getStats().getIngestCount(), stat.getStats().getIngestFailedCount(),
79+
stat.getStats().getIngestCurrent(), stat.getStats().getIngestTimeInMillis()};
80+
} else {
81+
value[0] += stat.getStats().getIngestCount();
82+
value[1] += stat.getStats().getIngestFailedCount();
83+
value[2] += stat.getStats().getIngestCurrent();
84+
value[3] += stat.getStats().getIngestTimeInMillis();
85+
return value;
86+
}
87+
});
88+
});
89+
});
90+
7791
ClusterStatsNodes.IngestStats stats = new ClusterStatsNodes.IngestStats(Collections.singletonList(nodeStats));
7892
assertThat(stats.pipelineCount, equalTo(nodeStats.getIngestStats().getProcessorStats().size()));
7993
String processorStatsString = "{";

0 commit comments

Comments
 (0)