Skip to content

Commit 72baf4b

Browse files
authored
Fix flaky protobuf debug format test when nanos is zero (#1958)
## Summary - Protobuf3 text format omits fields with default (zero) values - When `created_timestamp` lands on an exact second boundary, the `nanos` field is absent - The test pattern now makes the `nanos` line optional ## Test plan - [ ] CI passes (specifically Java 25 integration tests) --------- Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
1 parent 2277116 commit 72baf4b

File tree

1 file changed

+9
-5
lines changed
  • integration-tests/it-exporter/it-exporter-test/src/test/java/io/prometheus/metrics/it/exporter/test

1 file changed

+9
-5
lines changed

integration-tests/it-exporter/it-exporter-test/src/test/java/io/prometheus/metrics/it/exporter/test/ExporterIT.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,15 @@ public void testPrometheusProtobufDebugFormat(String format, String expected) th
110110
.replace("<app>", sampleApp);
111111

112112
if ("prometheus-protobuf".equals(format)) {
113-
assertThat(actualResponse)
114-
.matches(
115-
Pattern.quote(expectedResponse)
116-
.replace("<CREATED_TIMESTAMP_SECONDS>", "\\E\\d+\\Q")
117-
.replace("<CREATED_TIMESTAMP_NANOS>", "\\E\\d+\\Q"));
113+
// Protobuf text format omits fields with value 0, so nanos may be absent.
114+
// Replace the nanos placeholder with a regex-friendly marker before quoting.
115+
String withOptionalNanos =
116+
expectedResponse.replace("\n nanos: <CREATED_TIMESTAMP_NANOS>", "<OPTIONAL_NANOS>");
117+
String pattern =
118+
Pattern.quote(withOptionalNanos)
119+
.replace("<CREATED_TIMESTAMP_SECONDS>", "\\E\\d+\\Q")
120+
.replace("<OPTIONAL_NANOS>", "\\E(\n nanos: \\d+)?\\Q");
121+
assertThat(actualResponse).matches(pattern);
118122
} else {
119123
assertThat(actualResponse).isEqualTo(expectedResponse);
120124
}

0 commit comments

Comments
 (0)