Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ public static MetricSnapshots mergeDuplicates(MetricSnapshots metricSnapshots) {
return metricSnapshots;
}

// MetricSnapshots is sorted by prometheus name, so any duplicates are adjacent. Detect them in
// a single allocation-free pass; when there are none (the common case) return the input as-is
// rather than rebuilding it through a map, a list per group and a new MetricSnapshots.
boolean hasDuplicates = false;
for (int i = 1; i < metricSnapshots.size(); i++) {
if (metricSnapshots
.get(i)
.getMetadata()
.getPrometheusName()
.equals(metricSnapshots.get(i - 1).getMetadata().getPrometheusName())) {
hasDuplicates = true;
break;
}
}
if (!hasDuplicates) {
return metricSnapshots;
}

Map<String, List<MetricSnapshot>> grouped = new LinkedHashMap<>();

for (MetricSnapshot snapshot : metricSnapshots) {
Expand Down