From a0bf173a2a3ed38847ff3022f8d085b45e14aa2e Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Wed, 9 Oct 2024 17:45:23 +0200 Subject: [PATCH] fix bug (that should have shown before) (#1136) Signed-off-by: Gregor Zeitlinger --- CONTRIBUTING.md | 6 ++++++ .../io/prometheus/metrics/core/metrics/CounterTest.java | 2 +- .../io/prometheus/metrics/core/metrics/HistogramTest.java | 4 ++-- .../java/io/prometheus/metrics/core/metrics/InfoTest.java | 2 +- .../io/prometheus/metrics/core/metrics/SummaryTest.java | 2 +- .../metrics/expositionformats/ExpositionFormatsTest.java | 2 +- 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1e1eb867c..dbac64dd5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -16,3 +16,9 @@ Prometheus uses GitHub to manage reviews of pull requests. This repository uses [Google Java Format](https://github.com/google/google-java-format) to format the code. Run `./mvnw spotless:apply` to format the code (only changed files) before committing. + +## Running Tests + +If you're getting errors when running tests: + +- Make sure that the IDE uses only the "Maven Shade" dependency of "prometheus-metrics-exposition-formats" and the "prometheus-metrics-tracer*" dependencies. diff --git a/prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/CounterTest.java b/prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/CounterTest.java index 3e87d378c..9dfe8af7e 100644 --- a/prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/CounterTest.java +++ b/prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/CounterTest.java @@ -113,7 +113,7 @@ public void testTotalStrippedFromName() { }) { Counter counter = Counter.builder().name(name).unit(Unit.SECONDS).build(); Metrics.MetricFamily protobufData = new PrometheusProtobufWriter().convert(counter.collect()); - assertThat(TextFormat.printer().shortDebugString(protobufData)) + assertThat(TextFormat.printer().printToString(protobufData)) .isEqualTo( "name: \"my_counter_seconds_total\" type: COUNTER metric { counter { value: 0.0 } }"); } diff --git a/prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/HistogramTest.java b/prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/HistogramTest.java index ad514e9d0..46b755907 100644 --- a/prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/HistogramTest.java +++ b/prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/HistogramTest.java @@ -92,7 +92,7 @@ private void run() throws NoSuchFieldException, IllegalAccessException { new PrometheusProtobufWriter().convert(histogram.collect()); String expectedWithMetadata = "name: \"test\" type: HISTOGRAM metric { histogram { " + expected + " } }"; - assertThat(TextFormat.printer().shortDebugString(protobufData)) + assertThat(TextFormat.printer().printToString(protobufData)) .as("test \"" + name + "\" failed") .isEqualTo(expectedWithMetadata); } @@ -941,7 +941,7 @@ public void testDefaults() throws IOException { // protobuf Metrics.MetricFamily protobufData = new PrometheusProtobufWriter().convert(snapshot); - assertThat(TextFormat.printer().shortDebugString(protobufData)).isEqualTo(expectedProtobuf); + assertThat(TextFormat.printer().printToString(protobufData)).isEqualTo(expectedProtobuf); // text ByteArrayOutputStream out = new ByteArrayOutputStream(); diff --git a/prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/InfoTest.java b/prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/InfoTest.java index 4ea61a801..3728f8eee 100644 --- a/prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/InfoTest.java +++ b/prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/InfoTest.java @@ -27,7 +27,7 @@ public void testInfoStrippedFromName() { Info info = Info.builder().name(name).labelNames(labelName).build(); info.addLabelValues("value"); Metrics.MetricFamily protobufData = new PrometheusProtobufWriter().convert(info.collect()); - assertThat(TextFormat.printer().shortDebugString(protobufData)) + assertThat(TextFormat.printer().printToString(protobufData)) .isEqualTo( "name: \"jvm_runtime_info\" type: GAUGE metric { label { name: \"my_key\" value: \"value\" } gauge { value: 1.0 } }"); } diff --git a/prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/SummaryTest.java b/prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/SummaryTest.java index b369ed8fb..642340e13 100644 --- a/prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/SummaryTest.java +++ b/prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/SummaryTest.java @@ -128,7 +128,7 @@ public void testMaxAge() throws InterruptedException { assertThat(getQuantile(summary, 0.99, Labels.EMPTY)).isEqualTo(8.0); // From bucket 2. Thread.sleep(600); assertThat(getQuantile(summary, 0.99, Labels.EMPTY)) - .isEqualTo(Double.NaN); // Bucket 1 again, now it is empty. + .isNaN(); // Bucket 1 again, now it is empty. } @Test diff --git a/prometheus-metrics-exposition-formats/src/test/java/io/prometheus/metrics/expositionformats/ExpositionFormatsTest.java b/prometheus-metrics-exposition-formats/src/test/java/io/prometheus/metrics/expositionformats/ExpositionFormatsTest.java index 5174b2d8e..61d8fbb64 100644 --- a/prometheus-metrics-exposition-formats/src/test/java/io/prometheus/metrics/expositionformats/ExpositionFormatsTest.java +++ b/prometheus-metrics-exposition-formats/src/test/java/io/prometheus/metrics/expositionformats/ExpositionFormatsTest.java @@ -2634,7 +2634,7 @@ private void assertPrometheusTextWithoutCreated(String expected, MetricSnapshot private void assertPrometheusProtobuf(String expected, MetricSnapshot snapshot) { PrometheusProtobufWriter writer = new PrometheusProtobufWriter(); Metrics.MetricFamily protobufData = writer.convert(snapshot); - String actual = TextFormat.printer().shortDebugString(protobufData); + String actual = TextFormat.printer().printToString(protobufData); assertThat(actual).isEqualTo(expected); } }