|
12 | 12 | import io.prometheus.metrics.model.snapshots.HistogramSnapshot; |
13 | 13 | import io.prometheus.metrics.model.snapshots.InfoSnapshot; |
14 | 14 | import io.prometheus.metrics.model.snapshots.Labels; |
15 | | -import io.prometheus.metrics.model.snapshots.MetricMetadata; |
16 | 15 | import io.prometheus.metrics.model.snapshots.MetricSnapshots; |
17 | 16 | import io.prometheus.metrics.model.snapshots.NativeHistogramBuckets; |
18 | 17 | import io.prometheus.metrics.model.snapshots.Quantiles; |
19 | 18 | import io.prometheus.metrics.model.snapshots.StateSetSnapshot; |
20 | 19 | import io.prometheus.metrics.model.snapshots.SummarySnapshot; |
21 | | -import io.prometheus.metrics.model.snapshots.Unit; |
22 | 20 | import java.io.ByteArrayOutputStream; |
23 | 21 | import java.io.IOException; |
24 | 22 | import java.nio.charset.StandardCharsets; |
25 | | -import java.util.Collections; |
26 | 23 | import org.junit.jupiter.api.Test; |
27 | 24 |
|
28 | 25 | class OpenMetrics2TextFormatWriterTest { |
@@ -90,35 +87,6 @@ void testGetOpenMetrics2Properties() { |
90 | 87 | assertThat(writer.getOpenMetrics2Properties().getCompositeValues()).isTrue(); |
91 | 88 | } |
92 | 89 |
|
93 | | - @Test |
94 | | - void testCounterNoTotalSuffix() throws IOException { |
95 | | - MetricSnapshots snapshots = |
96 | | - MetricSnapshots.of( |
97 | | - new CounterSnapshot( |
98 | | - new MetricMetadata( |
99 | | - "my_counter_seconds", |
100 | | - "my_counter_seconds", |
101 | | - "my_counter", |
102 | | - "Test counter", |
103 | | - Unit.SECONDS), |
104 | | - Collections.singletonList( |
105 | | - CounterSnapshot.CounterDataPointSnapshot.builder() |
106 | | - .value(42.0) |
107 | | - .labels(Labels.of("method", "GET")) |
108 | | - .build()))); |
109 | | - |
110 | | - String om2Output = writeWithOM2(snapshots); |
111 | | - |
112 | | - // OM2: name as provided, no _total or unit suffix appending. |
113 | | - assertThat(om2Output) |
114 | | - .isEqualTo( |
115 | | - "# TYPE my_counter counter\n" |
116 | | - + "# UNIT my_counter seconds\n" |
117 | | - + "# HELP my_counter Test counter\n" |
118 | | - + "my_counter{method=\"GET\"} 42.0\n" |
119 | | - + "# EOF\n"); |
120 | | - } |
121 | | - |
122 | 90 | @Test |
123 | 91 | void testCounterWithTotalSuffix() throws IOException { |
124 | 92 | MetricSnapshots snapshots = |
@@ -688,49 +656,6 @@ void testNativeGaugeHistogramWithNegativeAndPositiveSpans() throws IOException { |
688 | 656 | + "# EOF\n"); |
689 | 657 | } |
690 | 658 |
|
691 | | - @Test |
692 | | - void testNativeHistogramWithDots() throws IOException { |
693 | | - Exemplar exemplar = |
694 | | - Exemplar.builder() |
695 | | - .labels(Labels.of("some.exemplar.key", "some value")) |
696 | | - .value(3.0) |
697 | | - .timestampMillis(1690298864383L) |
698 | | - .build(); |
699 | | - |
700 | | - MetricSnapshots snapshots = |
701 | | - MetricSnapshots.of( |
702 | | - new HistogramSnapshot( |
703 | | - new MetricMetadata( |
704 | | - "my.request.duration.seconds", |
705 | | - "my.request.duration.seconds", |
706 | | - "my.request.duration", |
707 | | - "Request duration in seconds", |
708 | | - Unit.SECONDS), |
709 | | - Collections.singletonList( |
710 | | - HistogramSnapshot.HistogramDataPointSnapshot.builder() |
711 | | - .labels(Labels.builder().label("http.path", "/hello").build()) |
712 | | - .sum(3.2) |
713 | | - .nativeSchema(5) |
714 | | - .nativeZeroCount(1) |
715 | | - .nativeBucketsForPositiveValues( |
716 | | - NativeHistogramBuckets.builder().bucket(2, 3).build()) |
717 | | - .exemplars(Exemplars.of(exemplar)) |
718 | | - .build()))); |
719 | | - |
720 | | - String output = writeWithNativeHistograms(snapshots); |
721 | | - |
722 | | - assertThat(output) |
723 | | - .isEqualTo( |
724 | | - "# TYPE \"my.request.duration\" histogram\n" |
725 | | - + "# UNIT \"my.request.duration\" seconds\n" |
726 | | - + "# HELP \"my.request.duration\" Request duration in seconds\n" |
727 | | - + "{\"my.request.duration\",\"http.path\"=\"/hello\"}" |
728 | | - + " {count:4,sum:3.2,schema:5,zero_threshold:0.0,zero_count:1," |
729 | | - + "positive_spans:[2:1],positive_buckets:[3]}" |
730 | | - + " # {\"some.exemplar.key\"=\"some value\"} 3.0 1690298864.383\n" |
731 | | - + "# EOF\n"); |
732 | | - } |
733 | | - |
734 | 659 | @Test |
735 | 660 | void testCompositeSummary() throws IOException { |
736 | 661 | MetricSnapshots snapshots = |
@@ -917,6 +842,6 @@ private String write(MetricSnapshots snapshots, ExpositionFormatWriter writer) |
917 | 842 | throws IOException { |
918 | 843 | ByteArrayOutputStream out = new ByteArrayOutputStream(); |
919 | 844 | writer.write(out, snapshots, EscapingScheme.ALLOW_UTF8); |
920 | | - return out.toString(StandardCharsets.UTF_8); |
| 845 | + return out.toString(StandardCharsets.UTF_8.name()); |
921 | 846 | } |
922 | 847 | } |
0 commit comments