Fix flaky DatadogMetricsTest (broken wait helper, origin detection, UDP races)#5384
Merged
Conversation
The suite was flaky on CI and failed 5/5 on dev machines, for four reasons: 1. The waitReceiveMessage helper was broken: its startsWith(expected) check never matched (all datagrams start with "tapir." or "datadog."), its polarity was inverted (it looped WHILE the expected message was present), and its first clause was unbounded (a potential infinite hang). Its effective behaviour degraded to "return once ANY message arrives", so assertions raced in-flight UDP datagrams. Replaced by eventually-wrapped assertions (idiom from ServerMetricsTest, 15s timeout / 150ms interval). 2. java-dogstatsd-client enables origin detection by default; on machines where a container id resolves it appends |c:<container-id> to every datagram, breaking all exact-string assertions (the local 5/5 failure). Disabled via originDetectionEnabled(false). 3. Client-side aggregation flushes every 2 seconds, so datagrams arrive late and counters can be split or merged across flush windows; the counter tests are now tagged Retryable, as no amount of waiting can heal a split/merged counter. 4. MockStatsDServer.receivedMessages was a plain var written by a daemon thread and read by the test thread; now @volatile. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
DatadogMetricsTestwas flaky on CI (e.g. the failure on #5369, where the 4xx counter assertion ran before the datagram arrived) and failed 5/5 when run on a dev machine. Four root causes:waitReceiveMessagehelper was broken. Itsm.startsWith(expected)check could never match — the default sentinel was"method"and others were"4xx"/"0.3", while every datagram starts withtapir.ordatadog.. Its polarity was also inverted (it kept looping while the expected message was present, rather than until it appeared), and its first clause was unbounded (a potential infinite hang if no message ever arrived). The effective behaviour degraded to "return as soon as ANY message arrives", so the assertions that followed raced in-flight UDP datagrams. The"0.3"sentinel in the duration test was additionally wrong — the last histogram sent is3.3.|c:<container-id>to every datagram, so all exact-string assertions fail (hence 5/5 local failures). Now disabled via.originDetectionEnabled(false)on every client.MockStatsDServer.receivedMessageswas a plainvarwritten by a daemon receiver thread and read by the test thread, with no@volatile.Fix
waitReceiveMessagecalls witheventually-wrapped assertions, using the same idiom asServerMetricsTest(class-levelEventually.PatienceConfig, 15s timeout / 150ms interval for slow CI); deleted the broken helper..originDetectionEnabled(false)to all five client builders.Retryable: aggregation can in rare cases split or merge counter increments across 2-second flush windows, which no amount of waiting can heal — the suite's existing retry mechanism handles this.receivedMessages@volatile.Verification
On a machine where origin detection resolves a container id:
datadogMetrics/testOnly ...DatadogMetricsTest— 0/5 passed (all 5 fail on the appended|c:<container-id>).datadogMetrics2_12/Test/compileanddatadogMetrics3/Test/compile— success.datadogMetrics/Test/scalafmtCheck— success.🤖 Generated with Claude Code