Skip to content

Commit 9a7e9b8

Browse files
authored
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 8c6f821 commit 9a7e9b8

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
@@ -70,9 +70,23 @@ public void testNetworkTypesToXContent() throws Exception {
7070
public void testIngestStats() throws Exception {
7171
NodeStats nodeStats = randomValueOtherThanMany(n -> n.getIngestStats() == null, NodeStatsTests::createNodeStats);
7272
SortedMap<String, long[]> processorStats = new TreeMap<>();
73-
nodeStats.getIngestStats().getProcessorStats().values().forEach(l -> l.forEach(s -> processorStats.put(s.getType(),
74-
new long[] { s.getStats().getIngestCount(), s.getStats().getIngestFailedCount(),
75-
s.getStats().getIngestCurrent(), s.getStats().getIngestTimeInMillis()})));
73+
nodeStats.getIngestStats().getProcessorStats().values().forEach(stats -> {
74+
stats.forEach(stat -> {
75+
processorStats.compute(stat.getType(), (key, value) -> {
76+
if (value == null) {
77+
return new long[] { stat.getStats().getIngestCount(), stat.getStats().getIngestFailedCount(),
78+
stat.getStats().getIngestCurrent(), stat.getStats().getIngestTimeInMillis()};
79+
} else {
80+
value[0] += stat.getStats().getIngestCount();
81+
value[1] += stat.getStats().getIngestFailedCount();
82+
value[2] += stat.getStats().getIngestCurrent();
83+
value[3] += stat.getStats().getIngestTimeInMillis();
84+
return value;
85+
}
86+
});
87+
});
88+
});
89+
7690
ClusterStatsNodes.IngestStats stats = new ClusterStatsNodes.IngestStats(Collections.singletonList(nodeStats));
7791
assertThat(stats.pipelineCount, equalTo(nodeStats.getIngestStats().getProcessorStats().size()));
7892
String processorStatsString = "{";

0 commit comments

Comments
 (0)