Skip to content

Commit 8cb8418

Browse files
committed
fix test
1 parent abe0c34 commit 8cb8418

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

exporters/prometheus/src/test/java/io/opentelemetry/exporter/prometheus/Otel2PrometheusConverterTest.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@
3838
import io.opentelemetry.sdk.metrics.internal.data.ImmutableSummaryPointData;
3939
import io.opentelemetry.sdk.resources.Resource;
4040
import io.prometheus.metrics.expositionformats.ExpositionFormats;
41+
import io.prometheus.metrics.model.snapshots.CounterSnapshot;
4142
import io.prometheus.metrics.model.snapshots.Labels;
43+
import io.prometheus.metrics.model.snapshots.MetricSnapshot;
4244
import io.prometheus.metrics.model.snapshots.MetricSnapshots;
4345
import java.io.ByteArrayOutputStream;
4446
import java.io.IOException;
@@ -47,6 +49,7 @@
4749
import java.util.Arrays;
4850
import java.util.Collections;
4951
import java.util.List;
52+
import java.util.Optional;
5053
import java.util.concurrent.atomic.AtomicInteger;
5154
import java.util.function.Predicate;
5255
import java.util.regex.Pattern;
@@ -241,7 +244,7 @@ private static Stream<Arguments> resourceAttributesAdditionArgs() {
241244
: "my_metric_units",
242245

243246
// "cluster" attribute is added (due to reg expr specified) and only it
244-
"cluster=\"mycluster\",foo1=\"bar1\",foo2=\"bar2\",otel_scope_name=\"scope\""));
247+
"cluster=\"mycluster\",foo1=\"bar1\",foo2=\"bar2\",otel_scope_foo=\"bar\",otel_scope_name=\"scope\",otel_scope_schema_url=\"schemaUrl\",otel_scope_version=\"version\""));
245248
}
246249

247250
// Resource attributes which also exists in the metric labels are not added twice
@@ -260,7 +263,7 @@ private static Stream<Arguments> resourceAttributesAdditionArgs() {
260263

261264
// "cluster" attribute is present only once and the value is taken
262265
// from the metric attributes and not the resource attributes
263-
"cluster=\"mycluster2\",foo2=\"bar2\",otel_scope_name=\"scope\""));
266+
"cluster=\"mycluster2\",foo2=\"bar2\",otel_scope_foo=\"bar\",otel_scope_name=\"scope\",otel_scope_schema_url=\"schemaUrl\",otel_scope_version=\"version\""));
264267

265268
// Empty attributes
266269
arguments.add(
@@ -275,7 +278,7 @@ private static Stream<Arguments> resourceAttributesAdditionArgs() {
275278
stringKey("host"), "localhost", stringKey("cluster"), "mycluster"))),
276279
/* allowedResourceAttributesFilter= */ Predicates.startsWith("clu"),
277280
"my_metric_units",
278-
"cluster=\"mycluster\",otel_scope_name=\"scope\""));
281+
"cluster=\"mycluster\",otel_scope_foo=\"bar\",otel_scope_name=\"scope\",otel_scope_schema_url=\"schemaUrl\",otel_scope_version=\"version\""));
279282

280283
return arguments.stream();
281284
}
@@ -316,7 +319,11 @@ void labelValueSerialization(Attributes attributes) {
316319

317320
MetricSnapshots snapshots = converter.convert(Collections.singletonList(metricData));
318321

319-
Labels labels = snapshots.get(0).getDataPoints().get(0).getLabels();
322+
Optional<MetricSnapshot> metricSnapshot =
323+
snapshots.stream().filter(snapshot -> snapshot instanceof CounterSnapshot).findFirst();
324+
assertThat(metricSnapshot).isPresent();
325+
326+
Labels labels = metricSnapshot.get().getDataPoints().get(0).getLabels();
320327
attributes.forEach(
321328
(key, value) -> {
322329
String labelValue = labels.get(key.getKey());

0 commit comments

Comments
 (0)