Skip to content

Commit e898720

Browse files
authored
chore: Fix CounterTest created timestamp flake (#2049)
## What changed Relaxed the `CounterTest.testTotalStrippedFromName` protobuf text assertion so `created_timestamp` accepts both forms emitted by protobuf text format: - `created_timestamp { seconds: ... nanos: ... }` - `created_timestamp { seconds: ... }` ## Why This test was flaky when the created timestamp landed exactly on a whole-second boundary. In that case, protobuf text format omits the `nanos` field when it is zero, but the test required `nanos` to always be present. ## Impact This does not change product behavior. It removes a nondeterministic test failure in CI by matching the actual protobuf output contract more accurately. ## Root cause The assertion encoded a stronger formatting assumption than protobuf guarantees. `protobuf-java` may omit zero-valued `nanos` in text output. ## Validation - `./mvnw test -pl prometheus-metrics-core -Dtest=CounterTest#testTotalStrippedFromName -Dcoverage.skip=true -Dcheckstyle.skip=true` - `mise run build`
1 parent 9e05c1d commit e898720

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

  • prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics

prometheus-metrics-core/src/test/java/io/prometheus/metrics/core/metrics/CounterTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ void testTotalStrippedFromName(String name) {
123123
assertThat(ProtobufUtil.shortDebugString(protobufData))
124124
.matches(
125125
"^name: \"my_counter_seconds_total\" type: COUNTER metric \\{ counter \\{ value: 0.0"
126-
+ " created_timestamp \\{ seconds: \\d+ nanos: \\d+ } } }$");
126+
+ " created_timestamp \\{ seconds: \\d+( nanos: \\d+)? } } }$");
127127
}
128128

129129
@Test

0 commit comments

Comments
 (0)