diff --git a/integration-tests/it-exporter/it-exporter-test/src/test/java/io/prometheus/metrics/it/exporter/test/ExporterIT.java b/integration-tests/it-exporter/it-exporter-test/src/test/java/io/prometheus/metrics/it/exporter/test/ExporterIT.java index b01e6b3a8..5a80d8bdf 100644 --- a/integration-tests/it-exporter/it-exporter-test/src/test/java/io/prometheus/metrics/it/exporter/test/ExporterIT.java +++ b/integration-tests/it-exporter/it-exporter-test/src/test/java/io/prometheus/metrics/it/exporter/test/ExporterIT.java @@ -110,11 +110,15 @@ public void testPrometheusProtobufDebugFormat(String format, String expected) th .replace("", sampleApp); if ("prometheus-protobuf".equals(format)) { - assertThat(actualResponse) - .matches( - Pattern.quote(expectedResponse) - .replace("", "\\E\\d+\\Q") - .replace("", "\\E\\d+\\Q")); + // Protobuf text format omits fields with value 0, so nanos may be absent. + // Replace the nanos placeholder with a regex-friendly marker before quoting. + String withOptionalNanos = + expectedResponse.replace("\n nanos: ", ""); + String pattern = + Pattern.quote(withOptionalNanos) + .replace("", "\\E\\d+\\Q") + .replace("", "\\E(\n nanos: \\d+)?\\Q"); + assertThat(actualResponse).matches(pattern); } else { assertThat(actualResponse).isEqualTo(expectedResponse); }