Skip to content

Commit a0bf173

Browse files
authored
fix bug (that should have shown before) (#1136)
Signed-off-by: Gregor Zeitlinger <[email protected]>
1 parent 7805ed2 commit a0bf173

File tree

6 files changed

+12
-6
lines changed

6 files changed

+12
-6
lines changed

CONTRIBUTING.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,9 @@ Prometheus uses GitHub to manage reviews of pull requests.
1616
This repository uses [Google Java Format](https://github.com/google/google-java-format) to format the code.
1717

1818
Run `./mvnw spotless:apply` to format the code (only changed files) before committing.
19+
20+
## Running Tests
21+
22+
If you're getting errors when running tests:
23+
24+
- Make sure that the IDE uses only the "Maven Shade" dependency of "prometheus-metrics-exposition-formats" and the "prometheus-metrics-tracer*" dependencies.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public void testTotalStrippedFromName() {
113113
}) {
114114
Counter counter = Counter.builder().name(name).unit(Unit.SECONDS).build();
115115
Metrics.MetricFamily protobufData = new PrometheusProtobufWriter().convert(counter.collect());
116-
assertThat(TextFormat.printer().shortDebugString(protobufData))
116+
assertThat(TextFormat.printer().printToString(protobufData))
117117
.isEqualTo(
118118
"name: \"my_counter_seconds_total\" type: COUNTER metric { counter { value: 0.0 } }");
119119
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ private void run() throws NoSuchFieldException, IllegalAccessException {
9292
new PrometheusProtobufWriter().convert(histogram.collect());
9393
String expectedWithMetadata =
9494
"name: \"test\" type: HISTOGRAM metric { histogram { " + expected + " } }";
95-
assertThat(TextFormat.printer().shortDebugString(protobufData))
95+
assertThat(TextFormat.printer().printToString(protobufData))
9696
.as("test \"" + name + "\" failed")
9797
.isEqualTo(expectedWithMetadata);
9898
}
@@ -941,7 +941,7 @@ public void testDefaults() throws IOException {
941941

942942
// protobuf
943943
Metrics.MetricFamily protobufData = new PrometheusProtobufWriter().convert(snapshot);
944-
assertThat(TextFormat.printer().shortDebugString(protobufData)).isEqualTo(expectedProtobuf);
944+
assertThat(TextFormat.printer().printToString(protobufData)).isEqualTo(expectedProtobuf);
945945

946946
// text
947947
ByteArrayOutputStream out = new ByteArrayOutputStream();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public void testInfoStrippedFromName() {
2727
Info info = Info.builder().name(name).labelNames(labelName).build();
2828
info.addLabelValues("value");
2929
Metrics.MetricFamily protobufData = new PrometheusProtobufWriter().convert(info.collect());
30-
assertThat(TextFormat.printer().shortDebugString(protobufData))
30+
assertThat(TextFormat.printer().printToString(protobufData))
3131
.isEqualTo(
3232
"name: \"jvm_runtime_info\" type: GAUGE metric { label { name: \"my_key\" value: \"value\" } gauge { value: 1.0 } }");
3333
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public void testMaxAge() throws InterruptedException {
128128
assertThat(getQuantile(summary, 0.99, Labels.EMPTY)).isEqualTo(8.0); // From bucket 2.
129129
Thread.sleep(600);
130130
assertThat(getQuantile(summary, 0.99, Labels.EMPTY))
131-
.isEqualTo(Double.NaN); // Bucket 1 again, now it is empty.
131+
.isNaN(); // Bucket 1 again, now it is empty.
132132
}
133133

134134
@Test

prometheus-metrics-exposition-formats/src/test/java/io/prometheus/metrics/expositionformats/ExpositionFormatsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2634,7 +2634,7 @@ private void assertPrometheusTextWithoutCreated(String expected, MetricSnapshot
26342634
private void assertPrometheusProtobuf(String expected, MetricSnapshot snapshot) {
26352635
PrometheusProtobufWriter writer = new PrometheusProtobufWriter();
26362636
Metrics.MetricFamily protobufData = writer.convert(snapshot);
2637-
String actual = TextFormat.printer().shortDebugString(protobufData);
2637+
String actual = TextFormat.printer().printToString(protobufData);
26382638
assertThat(actual).isEqualTo(expected);
26392639
}
26402640
}

0 commit comments

Comments
 (0)