|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2023 Oracle and/or its affiliates. |
| 2 | + * Copyright (c) 2023, 2025 Oracle and/or its affiliates. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -202,6 +202,42 @@ void testRetrievingByScope() {
|
202 | 202 | endsWith(OPENMETRICS_EOF)));
|
203 | 203 | }
|
204 | 204 |
|
| 205 | + @Test |
| 206 | + void testMeterNameWithColon() { |
| 207 | + Counter withColon = meterRegistry.getOrCreate(Counter.builder("c:withColon")); |
| 208 | + withColon.increment(); |
| 209 | + |
| 210 | + Counter withoutColon = meterRegistry.getOrCreate(Counter.builder("cWithoutColon")); |
| 211 | + withoutColon.increment(2L); |
| 212 | + |
| 213 | + Counter withQuestionMark = meterRegistry.getOrCreate(Counter.builder("c?withQuestionMark")); |
| 214 | + withQuestionMark.increment(); |
| 215 | + |
| 216 | + MicrometerPrometheusFormatter formatter = MicrometerPrometheusFormatter.builder(meterRegistry) |
| 217 | + .resultMediaType(MediaTypes.APPLICATION_OPENMETRICS_TEXT) |
| 218 | + .scopeTagName(SCOPE_TAG_NAME) |
| 219 | + .scopeSelection(Set.of("app")) |
| 220 | + .build(); |
| 221 | + |
| 222 | + Optional<Object> outputOpt = formatter.format(); |
| 223 | + |
| 224 | + assertThat("Formatted output", |
| 225 | + checkAndCast(outputOpt), |
| 226 | + allOf(containsString(scopeExpr("c:withColon_total", |
| 227 | + "this_scope", |
| 228 | + "app", |
| 229 | + "1.0")), |
| 230 | + containsString(scopeExpr("cWithoutColon_total", |
| 231 | + "this_scope", |
| 232 | + "app", |
| 233 | + "2.0")), |
| 234 | + containsString(scopeExpr("c_withQuestionMark_total", |
| 235 | + "this_scope", |
| 236 | + "app", |
| 237 | + "1.0")), |
| 238 | + endsWith(OPENMETRICS_EOF))); |
| 239 | + } |
| 240 | + |
205 | 241 | private static String scopeExpr(String meterName, String key, String value, String suffix) {
|
206 | 242 | return meterName + "{" + key + "=\"" + value + "\"} " + suffix;
|
207 | 243 | }
|
|
0 commit comments