Skip to content

Commit 8f515e9

Browse files
committed
fix errorprone
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
1 parent 5504e3b commit 8f515e9

File tree

4 files changed

+71
-79
lines changed

4 files changed

+71
-79
lines changed

prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/CounterTest.java

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -216,34 +216,24 @@ public void testExemplarSampler() throws Exception {
216216

217217
@Override
218218
public String getCurrentTraceId() {
219-
switch (callNumber) {
220-
case 1:
221-
return "abc";
222-
case 3:
223-
return "def";
224-
case 4:
225-
return "123";
226-
case 5:
227-
return "bab";
228-
default:
229-
throw new RuntimeException("unexpected call");
230-
}
219+
return switch (callNumber) {
220+
case 1 -> "abc";
221+
case 3 -> "def";
222+
case 4 -> "123";
223+
case 5 -> "bab";
224+
default -> throw new RuntimeException("unexpected call");
225+
};
231226
}
232227

233228
@Override
234229
public String getCurrentSpanId() {
235-
switch (callNumber) {
236-
case 1:
237-
return "123";
238-
case 3:
239-
return "456";
240-
case 4:
241-
return "abc";
242-
case 5:
243-
return "cdc";
244-
default:
245-
throw new RuntimeException("unexpected call");
246-
}
230+
return switch (callNumber) {
231+
case 1 -> "123";
232+
case 3 -> "456";
233+
case 4 -> "abc";
234+
case 5 -> "cdc";
235+
default -> throw new RuntimeException("unexpected call");
236+
};
247237
}
248238

249239
@Override

prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/GaugeTest.java

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -120,34 +120,24 @@ public void testExemplarSampler() throws Exception {
120120

121121
@Override
122122
public String getCurrentTraceId() {
123-
switch (callNumber) {
124-
case 1:
125-
return "abc";
126-
case 3:
127-
return "def";
128-
case 4:
129-
return "123";
130-
case 5:
131-
return "bab";
132-
default:
133-
throw new RuntimeException("unexpected call");
134-
}
123+
return switch (callNumber) {
124+
case 1 -> "abc";
125+
case 3 -> "def";
126+
case 4 -> "123";
127+
case 5 -> "bab";
128+
default -> throw new RuntimeException("unexpected call");
129+
};
135130
}
136131

137132
@Override
138133
public String getCurrentSpanId() {
139-
switch (callNumber) {
140-
case 1:
141-
return "123";
142-
case 3:
143-
return "456";
144-
case 4:
145-
return "abc";
146-
case 5:
147-
return "cdc";
148-
default:
149-
throw new RuntimeException("unexpected call");
150-
}
134+
return switch (callNumber) {
135+
case 1 -> "123";
136+
case 3 -> "456";
137+
case 4 -> "abc";
138+
case 5 -> "cdc";
139+
default -> throw new RuntimeException("unexpected call");
140+
};
151141
}
152142

153143
@Override

prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/HistogramTest.java

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -922,22 +922,24 @@ public void testDefaults() throws IOException {
922922
+ "} }";
923923
String expectedTextFormat =
924924
// default classic buckets
925-
"# TYPE test histogram\n"
926-
+ "test_bucket{le=\"0.005\"} 0\n"
927-
+ "test_bucket{le=\"0.01\"} 0\n"
928-
+ "test_bucket{le=\"0.025\"} 0\n"
929-
+ "test_bucket{le=\"0.05\"} 0\n"
930-
+ "test_bucket{le=\"0.1\"} 0\n"
931-
+ "test_bucket{le=\"0.25\"} 0\n"
932-
+ "test_bucket{le=\"0.5\"} 1\n"
933-
+ "test_bucket{le=\"1.0\"} 1\n"
934-
+ "test_bucket{le=\"2.5\"} 1\n"
935-
+ "test_bucket{le=\"5.0\"} 1\n"
936-
+ "test_bucket{le=\"10.0\"} 1\n"
937-
+ "test_bucket{le=\"+Inf\"} 1\n"
938-
+ "test_count 1\n"
939-
+ "test_sum 0.5\n"
940-
+ "# EOF\n";
925+
"""
926+
# TYPE test histogram
927+
test_bucket{le="0.005"} 0
928+
test_bucket{le="0.01"} 0
929+
test_bucket{le="0.025"} 0
930+
test_bucket{le="0.05"} 0
931+
test_bucket{le="0.1"} 0
932+
test_bucket{le="0.25"} 0
933+
test_bucket{le="0.5"} 1
934+
test_bucket{le="1.0"} 1
935+
test_bucket{le="2.5"} 1
936+
test_bucket{le="5.0"} 1
937+
test_bucket{le="10.0"} 1
938+
test_bucket{le="+Inf"} 1
939+
test_count 1
940+
test_sum 0.5
941+
# EOF
942+
""";
941943

942944
// protobuf
943945
Metrics.MetricFamily protobufData = new PrometheusProtobufWriterImpl().convert(snapshot);

prometheus-metrics-instrumentation-caffeine/src/test/java/io/prometheus/metrics/instrumentation/caffeine/CacheMetricsCollectorTest.java

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,19 @@ public void cacheExposesMetricsForHitMissAndEviction(Options options) {
7979
if (options.collectEvictionWeightAsCounter) {
8080
assertCounterMetric(registry, "caffeine_cache_eviction_weight", "users", 2.0);
8181
openMetricEvictionWeightExpectedText =
82-
"# TYPE caffeine_cache_eviction_weight counter\n"
83-
+ "# HELP caffeine_cache_eviction_weight Weight of evicted cache entries, doesn't include manually removed entries\n"
84-
+ "caffeine_cache_eviction_weight_total{cache=\"users\"} 2.0\n";
82+
"""
83+
# TYPE caffeine_cache_eviction_weight counter
84+
# HELP caffeine_cache_eviction_weight Weight of evicted cache entries, doesn't include manually removed entries
85+
caffeine_cache_eviction_weight_total{cache="users"} 2.0
86+
""";
8587
} else {
8688
assertGaugeMetric(registry, "caffeine_cache_eviction_weight", "users", 2.0);
8789
openMetricEvictionWeightExpectedText =
88-
"# TYPE caffeine_cache_eviction_weight gauge\n"
89-
+ "# HELP caffeine_cache_eviction_weight Weight of evicted cache entries, doesn't include manually removed entries\n"
90-
+ "caffeine_cache_eviction_weight{cache=\"users\"} 2.0\n";
90+
"""
91+
# TYPE caffeine_cache_eviction_weight gauge
92+
# HELP caffeine_cache_eviction_weight Weight of evicted cache entries, doesn't include manually removed entries
93+
caffeine_cache_eviction_weight{cache="users"} 2.0
94+
""";
9195
}
9296

9397
final String expected =
@@ -152,22 +156,28 @@ public void weightedCacheExposesMetricsForHitMissAndEvictionWeightedSize(Options
152156
if (options.collectEvictionWeightAsCounter) {
153157
assertCounterMetric(registry, "caffeine_cache_eviction_weight", "users", 31.0);
154158
openMetricEvictionWeightExpectedText =
155-
"# TYPE caffeine_cache_eviction_weight counter\n"
156-
+ "# HELP caffeine_cache_eviction_weight Weight of evicted cache entries, doesn't include manually removed entries\n"
157-
+ "caffeine_cache_eviction_weight_total{cache=\"users\"} 31.0\n";
159+
"""
160+
# TYPE caffeine_cache_eviction_weight counter
161+
# HELP caffeine_cache_eviction_weight Weight of evicted cache entries, doesn't include manually removed entries
162+
caffeine_cache_eviction_weight_total{cache="users"} 31.0
163+
""";
158164
} else {
159165
assertGaugeMetric(registry, "caffeine_cache_eviction_weight", "users", 31.0);
160166
openMetricEvictionWeightExpectedText =
161-
"# TYPE caffeine_cache_eviction_weight gauge\n"
162-
+ "# HELP caffeine_cache_eviction_weight Weight of evicted cache entries, doesn't include manually removed entries\n"
163-
+ "caffeine_cache_eviction_weight{cache=\"users\"} 31.0\n";
167+
"""
168+
# TYPE caffeine_cache_eviction_weight gauge
169+
# HELP caffeine_cache_eviction_weight Weight of evicted cache entries, doesn't include manually removed entries
170+
caffeine_cache_eviction_weight{cache="users"} 31.0
171+
""";
164172
}
165173
String openMetricWeightedSizeExpectedText;
166174
if (options.collectWeightedSize) {
167175
openMetricWeightedSizeExpectedText =
168-
"# TYPE caffeine_cache_weighted_size gauge\n"
169-
+ "# HELP caffeine_cache_weighted_size Approximate accumulated weight of cache entries\n"
170-
+ "caffeine_cache_weighted_size{cache=\"users\"} 31.0\n";
176+
"""
177+
# TYPE caffeine_cache_weighted_size gauge
178+
# HELP caffeine_cache_weighted_size Approximate accumulated weight of cache entries
179+
caffeine_cache_weighted_size{cache="users"} 31.0
180+
""";
171181
} else {
172182
openMetricWeightedSizeExpectedText = "";
173183
}

0 commit comments

Comments
 (0)