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..a87153ec6 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 @@ -7,13 +7,13 @@ import io.prometheus.metrics.core.exemplars.ExemplarSamplerConfigTestUtil; import io.prometheus.metrics.expositionformats.PrometheusProtobufWriter; +import io.prometheus.metrics.expositionformats.TextFormatUtil; import io.prometheus.metrics.expositionformats.generated.com_google_protobuf_4_28_2.Metrics; import io.prometheus.metrics.model.snapshots.CounterSnapshot; import io.prometheus.metrics.model.snapshots.Exemplar; import io.prometheus.metrics.model.snapshots.Label; import io.prometheus.metrics.model.snapshots.Labels; import io.prometheus.metrics.model.snapshots.Unit; -import io.prometheus.metrics.shaded.com_google_protobuf_4_28_2.TextFormat; import io.prometheus.metrics.tracer.common.SpanContext; import io.prometheus.metrics.tracer.initializer.SpanContextSupplier; import java.util.Arrays; @@ -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(TextFormatUtil.shortDebugString(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..4d55c3236 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 @@ -9,6 +9,7 @@ import io.prometheus.metrics.core.exemplars.ExemplarSamplerConfigTestUtil; import io.prometheus.metrics.expositionformats.OpenMetricsTextFormatWriter; import io.prometheus.metrics.expositionformats.PrometheusProtobufWriter; +import io.prometheus.metrics.expositionformats.TextFormatUtil; import io.prometheus.metrics.expositionformats.generated.com_google_protobuf_4_28_2.Metrics; import io.prometheus.metrics.model.snapshots.ClassicHistogramBucket; import io.prometheus.metrics.model.snapshots.Exemplar; @@ -16,7 +17,6 @@ import io.prometheus.metrics.model.snapshots.HistogramSnapshot; import io.prometheus.metrics.model.snapshots.Labels; import io.prometheus.metrics.model.snapshots.MetricSnapshots; -import io.prometheus.metrics.shaded.com_google_protobuf_4_28_2.TextFormat; import io.prometheus.metrics.tracer.common.SpanContext; import io.prometheus.metrics.tracer.initializer.SpanContextSupplier; import java.io.ByteArrayOutputStream; @@ -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(TextFormatUtil.shortDebugString(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(TextFormatUtil.shortDebugString(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..e3b06ecc8 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 @@ -5,10 +5,10 @@ import io.prometheus.metrics.expositionformats.OpenMetricsTextFormatWriter; import io.prometheus.metrics.expositionformats.PrometheusProtobufWriter; +import io.prometheus.metrics.expositionformats.TextFormatUtil; import io.prometheus.metrics.expositionformats.generated.com_google_protobuf_4_28_2.Metrics; import io.prometheus.metrics.model.snapshots.Labels; import io.prometheus.metrics.model.snapshots.MetricSnapshots; -import io.prometheus.metrics.shaded.com_google_protobuf_4_28_2.TextFormat; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -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(TextFormatUtil.shortDebugString(protobufData)) .isEqualTo( "name: \"jvm_runtime_info\" type: GAUGE metric { label { name: \"my_key\" value: \"value\" } gauge { value: 1.0 } }"); } diff --git a/prometheus-metrics-exposition-formats/pom.xml b/prometheus-metrics-exposition-formats/pom.xml index b5d9f75bd..4f2f35422 100644 --- a/prometheus-metrics-exposition-formats/pom.xml +++ b/prometheus-metrics-exposition-formats/pom.xml @@ -127,6 +127,11 @@ true true + + + com.google.protobuf:protobuf-java + + com.google.protobuf diff --git a/prometheus-metrics-exposition-formats/src/main/java/io/prometheus/metrics/expositionformats/TextFormatUtil.java b/prometheus-metrics-exposition-formats/src/main/java/io/prometheus/metrics/expositionformats/TextFormatUtil.java index 54daaaa3e..da64f30bb 100644 --- a/prometheus-metrics-exposition-formats/src/main/java/io/prometheus/metrics/expositionformats/TextFormatUtil.java +++ b/prometheus-metrics-exposition-formats/src/main/java/io/prometheus/metrics/expositionformats/TextFormatUtil.java @@ -1,5 +1,7 @@ package io.prometheus.metrics.expositionformats; +import com.google.protobuf.MessageOrBuilder; +import com.google.protobuf.TextFormat; import io.prometheus.metrics.model.snapshots.Labels; import java.io.IOException; import java.io.OutputStreamWriter; @@ -81,4 +83,8 @@ static void writeLabels( } writer.write('}'); } + + public static String shortDebugString(MessageOrBuilder protobufData) { + return TextFormat.printer().shortDebugString(protobufData); + } } 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..7a7a0ea7e 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 @@ -2,7 +2,6 @@ import static org.assertj.core.api.Assertions.assertThat; -import com.google.protobuf.TextFormat; import io.prometheus.metrics.expositionformats.generated.com_google_protobuf_4_28_2.Metrics; import io.prometheus.metrics.model.snapshots.*; import io.prometheus.metrics.model.snapshots.CounterSnapshot.CounterDataPointSnapshot; @@ -2634,7 +2633,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 = TextFormatUtil.shortDebugString(protobufData); assertThat(actual).isEqualTo(expected); } }