Skip to content

fix(id): reset DogStatsD buffers on identity refresh - #10339

Open
litianningdatadog wants to merge 1 commit into
masterfrom
tianning.li/microvm-buffer-reset-03-dogstatsd-buffer-reset
Open

litianningdatadog wants to merge 1 commit into
masterfrom
tianning.li/microvm-buffer-reset-03-dogstatsd-buffer-reset

Conversation

@litianningdatadog

@litianningdatadog litianningdatadog commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Prevent DogStatsD buffered data from crossing MicroVM identity boundaries.

Motivation

This is a reviewable slice from the breakdown of monolithic PR #9814, tracked by SVLS-9768. A MicroVM identity refresh must not carry buffered, baseline, or pending exporter state into the next identity.

Changes

  • Reset DogStatsD buffered state during identity refresh.
  • Added coverage for buffer reset behavior.

Dependency tree

  • origin/master
    • #10338 01-common-exporter-agent-spanstats-reset-and-cancel
      • #10342 02-agentless-exporter-identity
      • #10341 06-datastream-reset-and-cancel
    • #10339 03-dogstatsd-buffer-reset ← current PR
    • #10340 04-otel-runtime-baseline
      • #10343 05-otel-runtime-metric-resets

This PR is intentionally draft and is part of the stacked review sequence above.

@dd-octo-sts

dd-octo-sts Bot commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Overall package size

Self size: 8.96 MB
Deduped: 9.69 MB
No deduping: 9.69 MB

Dependency sizes | name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.5.1 | 127.66 kB | 513.61 kB | | opentracing | 0.14.7 | 194.81 kB | 194.81 kB | | dc-polyfill | 0.1.11 | 25.74 kB | 25.74 kB |

🤖 This report was automatically generated by heaviest-objects-in-the-universe

@codecov

codecov Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.71%. Comparing base (3dcb352) to head (24c0e95).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #10339   +/-   ##
=======================================
  Coverage   98.71%   98.71%           
=======================================
  Files        1025     1025           
  Lines      160626   160695   +69     
  Branches       74       74           
=======================================
+ Hits       158563   158632   +69     
  Misses       2063     2063           
Flag Coverage Δ
ai-guard 65.26% <65.93%> (-0.02%) ⬇️
apm-capabilities 63.69% <100.00%> (+0.02%) ⬆️
apm-integrations 81.56% <65.93%> (-0.03%) ⬇️
appsec 58.94% <65.93%> (-0.01%) ⬇️
debugger 70.19% <65.93%> (-0.06%) ⬇️
instrumentation 54.47% <65.93%> (+<0.01%) ⬆️
llmobs 79.07% <65.93%> (-0.04%) ⬇️
master-coverage 98.71% <100.00%> (?)
openfeature 66.52% <65.93%> (-0.03%) ⬇️
platform 69.40% <65.93%> (-0.01%) ⬇️
profiling 66.86% <65.93%> (-0.03%) ⬇️
serverless 65.99% <65.93%> (-0.02%) ⬇️
test-optimization 82.53% <65.93%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@litianningdatadog litianningdatadog added the aws-microvm AWS MicroVM related features label Sep 15, 2026
@litianningdatadog
litianningdatadog requested a lite review from Copilot September 15, 2026 02:19
@litianningdatadog
litianningdatadog marked this pull request as ready for review September 15, 2026 02:21
@litianningdatadog
litianningdatadog requested review from a team as code owners September 15, 2026 02:21
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-16T20:34:40.385684Z b8e2848 New commits
🔒 Security Review ✅ Completed 2026-09-16T20:35:12.961400Z b8e2848 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Active HTTP requests can still deliver stale data after refresh; abort handling and in-flight coverage are needed.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Resets DogStatsD state during MicroVM identity refreshes to prevent stale data from crossing identities.

Changes:

  • Reset buffered, telemetry, and aggregation state on refresh.
  • Add generation checks for detached deliveries.
  • Add identity-refresh regression coverage.
File summaries
File Summary
packages/dd-trace/test/dogstatsd.spec.js Tests reset and stale-send behavior.
packages/dd-trace/src/dogstatsd.js Implements state resets and stale-delivery guards.
Review details

Suppressed comments (1)

packages/dd-trace/src/dogstatsd.js:384

  • The new generation guard is covered only on the UDP/DNS paths in this spec. The HTTP callback also suppresses stale completion and, importantly, prevents the error path from falling back to UDP, but no test holds the mocked HTTP request open across updateTags; a regression here could resend the old queue or record its transport telemetry. Add an HTTP case that flushes, refreshes before invoking the callback with an error, and asserts no UDP fallback or stale telemetry.
      if (!this.#isCurrentIdentity(identityRefreshGeneration)) {
        done?.()
        return
      }
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines 379 to +381
const buffer = Buffer.concat(queue)
request(buffer, this.#httpOptions, (error, _result, _statusCode, _headers, dropped) => {
if (!this.#isCurrentIdentity(identityRefreshGeneration)) {
@datadog-prod-us1-4

This comment has been minimized.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 24c0e95350

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".


const buffer = Buffer.concat(queue)
request(buffer, this.#httpOptions, (error, _result, _statusCode, _headers, dropped) => {
if (!this.#isCurrentIdentity(identityRefreshGeneration)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Abort HTTP sends before stale payloads transmit

When an identity refresh occurs after request() starts but before its DNS/connect/write completes, this generation check runs only in the response callback, after the old buffer may already have been transmitted. Consequently, each resumed MicroVM clone can still submit the pre-snapshot HTTP payload; the guard merely suppresses its telemetry and UDP fallback. Track and abort active HTTP requests during updateTags(), and cover this sibling of the UDP/DNS case.

AGENTS.md reference: AGENTS.md:L79-L79

Useful? React with 👍 / 👎.

@pr-commenter

pr-commenter Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

Benchmarks

Benchmark execution time: 2026-09-16 20:42:43

Comparing candidate commit b8e2848 in PR branch tianning.li/microvm-buffer-reset-03-dogstatsd-buffer-reset with baseline commit 3dcb352 in branch master.

📊 Benchmarking dashboard

Found 0 performance improvements and 0 performance regressions! Performance is the same for 2303 metrics, 10 unstable metrics.

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

Unstable benchmarks

These benchmarks have a confidence interval too wide to call a change; treat them as noise rather than signal.

scenario:appsec-appsec-enabled-24

  • unstable max_rss_usage [-27.034MB; +8.179MB] or [-9.505%; +2.876%]

scenario:appsec-iast-with-vulnerability-iast-enabled-default-config-20

  • unstable max_rss_usage [-10.281MB; +31.960MB] or [-3.017%; +9.378%]

scenario:encoders-0.4-immediate-flush-20

  • unstable max_rss_usage [-9.569MB; +4.575MB] or [-12.936%; +6.185%]

scenario:llmobs-encode-unicode-mixed-20

  • unstable max_rss_usage [-7.771MB; +10.863MB] or [-10.400%; +14.539%]

scenario:plugin-aws-sdk-eventbridge-inject-detail-26

  • unstable execution_time [-164.340ms; +255.938ms] or [-4.157%; +6.473%]

scenario:plugin-graphql-long-with-depth-off-26

  • unstable execution_time [-409.671ms; +384.957ms] or [-5.299%; +4.979%]
  • unstable max_rss_usage [-33.685MB; +29.755MB] or [-14.883%; +13.146%]
  • unstable throughput [-17.761op/s; +16.816op/s] or [-5.323%; +5.040%]

scenario:plugin-graphql-long-with-depth-on-max-26

  • unstable max_rss_usage [-22.628MB; +14.961MB] or [-8.692%; +5.747%]

scenario:plugin-mongodb-core-plain-find-26

  • unstable execution_time [-111.468ms; +131.059ms] or [-5.377%; +6.322%]

@litianningdatadog
litianningdatadog force-pushed the tianning.li/microvm-buffer-reset-03-dogstatsd-buffer-reset branch from 24c0e95 to b8e2848 Compare September 16, 2026 20:30

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b8e2848166

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 505 to +507
socket.send(buffer, 0, buffer.length, this.#port, address, (error) => {
if (error) {
if (!this.#isCurrentIdentity(identityRefreshGeneration)) {
complete()

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Cancel UDP sends that outlive the identity

When a MicroVM snapshot is taken after socket.send() is queued but before it completes, this generation check runs only from the completion callback, after libuv has already accepted the old buffer; each resumed clone can therefore still transmit the stale datagram. The new pending-callback test confirms only that stale completions are ignored, not that the packets are canceled. Track and invalidate the outstanding UDP transport at refresh, and cover the sibling case by asserting that a receiver gets no pre-refresh packet.

AGENTS.md reference: AGENTS.md:L78-L79

Useful? React with 👍 / 👎.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

aws-microvm AWS MicroVM related features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants