Skip to content

test(profiling): fix flaky test_memory_collector_allocation_tracking_across_snapshots - #20402

Draft
taegyunkim wants to merge 3 commits into
mainfrom
dd/fix/flaky-memalloc-snapshots-20260917
Draft

taegyunkim wants to merge 3 commits into
mainfrom
dd/fix/flaky-memalloc-snapshots-20260917

Conversation

@taegyunkim

Copy link
Copy Markdown
Contributor

Description

Fixing test_memory_collector_allocation_tracking_across_snapshots[py3.13]Questions? Ask in #code-gen-flaky-tests

test_memory_collector_allocation_tracking_across_snapshots[py3.13] intermittently rejected valid process-wide profiler samples whose memory slots were zero. The flake had a 0.03% failure rate and failed one main pipeline with Sample should have either heap-space or alloc-space > 0.

The profile can combine memory samples with other process-wide sample types, so zero memory values do not by themselves make a sample invalid.

Changes

  • Scope memory value validation to samples that actually carry a heap or allocation value.
  • Preserve checks that heap-space, alloc-space, and alloc-samples values are non-negative.
  • Apply the shared invariant to all three allocation-tracking tests that used the blanket assertion.
  • Document the combined-profile invariant with a plain NOTE: comment.

Testing

  • Ran the reported Python 3.13 test repeatedly for ten minutes across all four allocator configurations; the original 0.03% flake did not reproduce.
  • Verified the updated reported test and both sibling callsites across all four Python 3.13 allocator configurations.
  • Ran the full repository lint/check workflow successfully.
  • Re-ran the repository formatter after the comment-only follow-up.

Risks

Low. The change is test-only and retains validation of invalid negative memory values while accepting valid non-memory samples in a combined profile.

Additional Notes

No customer-facing release note is required; apply the changelog/no-changelog label.


PR by Bits - View session in Datadog

Comment @DataDog to request changes

datadog-bits and others added 2 commits September 17, 2026 15:30
DD_908FHU

Co-authored-by: taegyunkim <6655247+taegyunkim@users.noreply.github.com>
DD_908FHU

Co-authored-by: taegyunkim <6655247+taegyunkim@users.noreply.github.com>
@datadog-official

Copy link
Copy Markdown
Contributor

View session in Datadog

Bits Code status: ✅ Done

CI Auto-fix: Disabled | Enable

Comment @DataDog to request changes

@datadog-datadog-prod-us1-2

Copy link
Copy Markdown
Contributor

I can only run on private repositories.

@taegyunkim taegyunkim added the changelog/no-changelog A changelog entry is not required for this PR. label Sep 17, 2026
@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Codeowners resolved as

Resolved from the full PR diff against main using the target branch CODEOWNERS file.
CODEOWNERS team requests not listed below are not required by the current file set.

tests/profiling/collector/test_memalloc.py                              @DataDog/profiling-python

@cit-pr-commenter-54b7da

Copy link
Copy Markdown

Circular import analysis

⚠️ Existing circular imports

There are 1 circular imports that already exist on the base branch and have not been changed by this PR.

ddtrace.errortracking._handled_exceptions.bytecode_injector -> ddtrace.errortracking._handled_exceptions.callbacks -> ddtrace.errortracking._handled_exceptions.collector -> ddtrace.errortracking._handled_exceptions.bytecode_reporting -> ddtrace.errortracking._handled_exceptions.bytecode_injector

@cit-pr-commenter-54b7da

cit-pr-commenter-54b7da Bot commented Sep 17, 2026

Copy link
Copy Markdown

Dependency direction analysis

⚠️ Existing dependency direction violations

There are 218 dependency direction violations that already exist on the base branch and have not been changed by this PR.

Show existing violations (showing 5 of 218 highest severity)
ddtrace.internal.tracemethods -×-> ddtrace.trace  (internal-core -> product:tracing, score=133)
ddtrace.llmobs._utils -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=131)
ddtrace.internal.opentelemetry.span -×-> ddtrace.trace  (product:opentelemetry -> product:tracing, score=131)
ddtrace.llmobs._integrations.openai_agents -×-> ddtrace.trace  (product:llmobs -> product:tracing, score=131)
ddtrace.profiling.collector.stack -×-> ddtrace.trace  (product:profiling -> product:tracing, score=131)

To see all violations, download the layers-base.json and layers-pr.json artifacts from this CI job and run:

uv run --script scripts/import-analysis/layers.py compare layers-base.json layers-pr.json

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

Labels

Bits AI changelog/no-changelog A changelog entry is not required for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants