Skip to content
Merged
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 @@ -3,8 +3,10 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.stream.Stream;

import static io.prometheus.metrics.model.snapshots.PrometheusNaming.prometheusName;
Expand Down Expand Up @@ -74,6 +76,7 @@ public static Builder builder() {
public static class Builder {

private final List<MetricSnapshot> snapshots = new ArrayList<>();
private final Set<String> prometheusNames = new HashSet<>();

private Builder() {
}
Expand All @@ -83,19 +86,15 @@ public boolean containsMetricName(String name) {
return false;
}
String prometheusName = prometheusName(name);
for (MetricSnapshot snapshot : snapshots) {
if (snapshot.getMetadata().getPrometheusName().equals(prometheusName)) {
return true;
}
}
return false;
return prometheusNames.contains(prometheusName);
}

/**
* Add a metric snapshot. Call multiple times to add multiple metric snapshots.
*/
public Builder metricSnapshot(MetricSnapshot snapshot) {
snapshots.add(snapshot);
prometheusNames.add(snapshot.getMetadata().getPrometheusName());
return this;
}

Expand Down