Commit 4ce0d15 1 parent 72b79d4 commit 4ce0d15 Copy full SHA for 4ce0d15
File tree 1 file changed +5
-6
lines changed
prometheus-metrics-model/src/main/java/io/prometheus/metrics/model/snapshots
1 file changed +5
-6
lines changed Original file line number Diff line number Diff line change 3
3
import java .util .ArrayList ;
4
4
import java .util .Arrays ;
5
5
import java .util .Collection ;
6
+ import java .util .HashSet ;
6
7
import java .util .Iterator ;
7
8
import java .util .List ;
9
+ import java .util .Set ;
8
10
import java .util .stream .Stream ;
9
11
10
12
import static io .prometheus .metrics .model .snapshots .PrometheusNaming .prometheusName ;
@@ -74,6 +76,7 @@ public static Builder builder() {
74
76
public static class Builder {
75
77
76
78
private final List <MetricSnapshot > snapshots = new ArrayList <>();
79
+ private final Set <String > prometheusNames = new HashSet <>();
77
80
78
81
private Builder () {
79
82
}
@@ -83,19 +86,15 @@ public boolean containsMetricName(String name) {
83
86
return false ;
84
87
}
85
88
String prometheusName = prometheusName (name );
86
- for (MetricSnapshot snapshot : snapshots ) {
87
- if (snapshot .getMetadata ().getPrometheusName ().equals (prometheusName )) {
88
- return true ;
89
- }
90
- }
91
- return false ;
89
+ return prometheusNames .contains (prometheusName );
92
90
}
93
91
94
92
/**
95
93
* Add a metric snapshot. Call multiple times to add multiple metric snapshots.
96
94
*/
97
95
public Builder metricSnapshot (MetricSnapshot snapshot ) {
98
96
snapshots .add (snapshot );
97
+ prometheusNames .add (snapshot .getMetadata ().getPrometheusName ());
99
98
return this ;
100
99
}
101
100
You can’t perform that action at this time.
0 commit comments