Skip to content

test(telemetry): stop transient fork children flaking test_app_heartbeats_delays#7296

Merged
bm1549 merged 1 commit into
mainfrom
brian.marks/fix-heartbeat-drift-fork-isolation
Jul 13, 2026
Merged

test(telemetry): stop transient fork children flaking test_app_heartbeats_delays#7296
bm1549 merged 1 commit into
mainfrom
brian.marks/fix-heartbeat-drift-fork-isolation

Conversation

@bm1549

@bm1549 bm1549 commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Motivation

test_app_heartbeats_delays is flaky only on uwsgi-poc (43 failures on main in the last 30 days, while every other variant passes), always failing Heartbeat sent too fast: ~1.1s.

The test buckets every app-heartbeat by runtime_id and checks each runtime's average inter-heartbeat delay against [0.75x, 1.5x] of the interval. uwsgi-poc is the only weblog running a prefork uwsgi master + worker with ddtrace bootstrapped at the uwsgi level, so an os.fork() from the sibling session-id tests (/spawn_child) leaves a short-lived extra runtime in the shared telemetry pool: the forked child emits a heartbeat under its parent's runtime_id before regenerating its own, so that runtime has two heartbeats ~0.05s apart. Its average (~1.1s) trips "too fast". The main app worker is healthy (~2s cadence); single-process weblogs like flask-poc never produce this transient runtime.

Changes

_get_heartbeat_delays_by_runtime now selects measurable runtimes by lifespan (first→last heartbeat) instead of heartbeat count. The transient fork child lives ~2s and is excluded; long-lived application runtimes span the observation window and are measured. Lifespan is cadence-independent on purpose: a genuinely slow-drifting worker emits fewer heartbeats but still spans the window, so its drift is still caught (a count-based filter would wrongly drop it).

Workflow

  1. ⚠️ Create your PR as draft ⚠️
  2. Work on you PR until the CI passes
  3. Mark it as ready for review
    • Test logic is modified? -> Get a review from RFC owner.
    • Framework is modified, or non obvious usage of it -> get a review from R&P team

🚀 Once your PR is reviewed and the CI green, you can merge it!

:lifebuoy: #apm-shared-testing :lifebuoy:

Reviewer checklist

  • Anything but tests/ or manifests/ is modified ? I have the approval from R&P teamN/A: only tests/ is modified.
  • A docker base image is modified? — No.
  • A scenario is added, removed or renamed? — No.

🤖 Generated with Claude Code

@bm1549 bm1549 added the ai-generated The pull request includes a significant amount of AI-generated code label Jul 11, 2026
@github-actions

github-actions Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

CODEOWNERS have been resolved as:

tests/test_telemetry.py                                                 @DataDog/libdatadog-telemetry @DataDog/apm-sdk-capabilities @DataDog/system-tests-core

… check

test_app_heartbeats_delays buckets every app-heartbeat in the scenario by
runtime_id and asserts each measured runtime's average inter-heartbeat delay
stays within [0.75x, 1.5x] of the interval. The session-id tests
(test_session_id_headers_across_forks/_across_spawned) spawn short-lived
children via /spawn_child whose telemetry lands in the same shared pool; on
uwsgi-poc a forked child emits a heartbeat under its parent's runtime_id
before regenerating its own, producing a transient runtime with a
sub-interval "duplicate" (~0.05s) whose average (~1.1s) trips "too fast".

Select measurable runtimes by lifespan (first->last heartbeat) rather than
heartbeat count, so transient ~2s children are excluded while a genuinely
slow-drifting worker -- which emits fewer heartbeats over the same window --
stays measured and its drift is still caught.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@bm1549 bm1549 force-pushed the brian.marks/fix-heartbeat-drift-fork-isolation branch from fccde0d to bd9305e Compare July 11, 2026 00:16
@datadog-datadog-prod-us1

datadog-datadog-prod-us1 Bot commented Jul 11, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: bd9305e | Docs | Datadog PR Page | Give us feedback!

@bm1549 bm1549 marked this pull request as ready for review July 13, 2026 13:58
@bm1549 bm1549 requested review from a team as code owners July 13, 2026 13:58
@bm1549 bm1549 requested review from cyrille-leclerc and pawelchcki and removed request for a team July 13, 2026 13:58

@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: bd9305e95e

ℹ️ 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 thread tests/test_telemetry.py
@bm1549 bm1549 merged commit 5317e1b into main Jul 13, 2026
413 checks passed
@bm1549 bm1549 deleted the brian.marks/fix-heartbeat-drift-fork-isolation branch July 13, 2026 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-generated The pull request includes a significant amount of AI-generated code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants