Skip to content

Commit

Permalink
fix bug (that should have shown before) (#1136)
Browse files Browse the repository at this point in the history
Signed-off-by: Gregor Zeitlinger <[email protected]>
  • Loading branch information
zeitlinger authored Oct 9, 2024
1 parent 7805ed2 commit a0bf173
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Original file line number Diff line number Diff line change
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(TextFormat.printer().printToString(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 @@ -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);
}
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(TextFormat.printer().printToString(protobufData)).isEqualTo(expectedProtobuf);

// text
ByteArrayOutputStream out = new ByteArrayOutputStream();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 } }");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit a0bf173

Please sign in to comment.