Skip to content

Commit

Permalink
fix shading (#1137)
Browse files Browse the repository at this point in the history
Signed-off-by: Gregor Zeitlinger <[email protected]>
  • Loading branch information
zeitlinger authored Oct 10, 2024
1 parent 8d887a0 commit 68849a8
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 } }");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
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;
import io.prometheus.metrics.model.snapshots.Exemplars;
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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 } }");
}
Expand Down
5 changes: 5 additions & 0 deletions prometheus-metrics-exposition-formats/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@
<configuration>
<shadeSourcesContent>true</shadeSourcesContent>
<createSourcesJar>true</createSourcesJar>
<artifactSet>
<includes>
<include>com.google.protobuf:protobuf-java</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>com.google.protobuf</pattern>
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -81,4 +83,8 @@ static void writeLabels(
}
writer.write('}');
}

public static String shortDebugString(MessageOrBuilder protobufData) {
return TextFormat.printer().shortDebugString(protobufData);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 68849a8

Please sign in to comment.