feat(apm): add adaptive sampling commands#553
Draft
rachelyangdog wants to merge 2 commits into
Draft
Conversation
Adds `pup apm sampling-rules {list,get,create,update,delete}` for
managing customer per-(service,env,resource) head-based sampling rules.
Backed by Remote Config product APM_TRACING with provenance=customer.
Rules surface on traces with `_dd.p.dm:-11` and
`ingestion_reason:remote_rule`.
## Commands
pup apm sampling-rules list [--service S --env E]
pup apm sampling-rules get <id>
pup apm sampling-rules create --service S --env E --resource R --sample-rate F
pup apm sampling-rules update <id> --service S --env E --resource R --sample-rate F
pup apm sampling-rules delete <id>
When `--service` and `--env` are both given, list narrows via the
backend's `/configs/by_target` endpoint.
## Scopes
- apm_remote_configuration_read (added to default + read_only)
- apm_remote_configuration_write (added to default)
Both scopes are on pup's OUISvc registrable client allowlist as of the
recent OAuth rollout. Backend support is in place:
- dd-source PR `rachel.yang/apm-trace-configurations-oauth-auth`
(Rapid service-default OAuth on trace-configurations)
- dd-go PR `rachel.yang/rc-api-proxy-apm-tracing-oauth`
(rc-api-proxy authn_methods on apm_tracing routes)
## Tests
8 tests added in `commands::apm::tests`, matching the
service_remapping_* pattern:
test_sampling_rules_list
test_sampling_rules_list_by_target
test_sampling_rules_get
test_sampling_rules_get_not_found
test_sampling_rules_create
test_sampling_rules_create_api_error
test_sampling_rules_update
test_sampling_rules_delete
All pass locally. The 5 unrelated test failures in `cases`, `dbm`,
`logs`, `metrics`, `traces` are pre-existing DNS-resolution flakes
against `unused.local` and not touched by this change.
## Follow-ups
- `pup apm adaptive-sampling` commands (allotment + onboarding) —
separate PR. Requires the `apm_service_ingest_{read,write}` scopes
which are also already on the OUISvc allowlist.
- Flip the agent-skills `dd-apm/sampling` skill PR from draft to
ready once these commands ship in a release.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adds `pup apm adaptive-sampling` subcommands for managing Datadog's
adaptive sampling (server-driven dynamic sampling) — onboarding
services and configuring the monthly byte/percent allotment. Datadog
auto-tunes per-(service, env, resource) sampling rates to fit the
budget. Generated rules surface on traces with `_dd.p.dm:-12` and
`ingestion_reason:adaptive_rule`.
Builds on the sampling-rules PR (#PR_B1) and the same OAuth rollout.
## Commands
pup apm adaptive-sampling onboarding-status [--service S --env E]
pup apm adaptive-sampling onboard --service S --env E
pup apm adaptive-sampling offboard --service S --env E
pup apm adaptive-sampling get-allotment
pup apm adaptive-sampling set-allotment (--bytes N | --percent F)
pup apm adaptive-sampling check
pup apm adaptive-sampling preview (--bytes N | --percent F)
`set-allotment` and `preview` take exactly one of `--bytes` or
`--percent` (enforced via clap `conflicts_with`). Strategy is inferred:
`fixed_target` for bytes, `percent_total` for percent.
## Scopes
- apm_service_ingest_read (added to default + read_only)
- apm_service_ingest_write (added to default)
Both already on pup's OUISvc registrable client allowlist (added in the
same rollout as `apm_remote_configuration_{read,write}` for the
sampling-rules commands).
The adaptive-sampling endpoints require BOTH `apm_service_ingest_*` AND
`apm_remote_configuration_*` (RoutePermissions with operator AND) —
the latter is added by the sampling-rules PR this builds on.
## Endpoints
GET/POST /api/ui/adaptive_sampling/onboarding_status
GET/POST /api/ui/adaptive_sampling/allotment_config
POST /api/ui/adaptive_sampling/preview
GET /api/ui/adaptive_sampling/allotment_check
All in dd-source `trace-configurations` service, which got
`ValidOAuthAccessToken` in the dd-source-side OAuth PR.
## Tests
9 tests added in `commands::apm::tests`:
test_adaptive_sampling_onboarding_status_no_filter
test_adaptive_sampling_onboarding_status_with_filter
test_adaptive_sampling_onboard
test_adaptive_sampling_offboard
test_adaptive_sampling_get_allotment
test_adaptive_sampling_set_allotment_bytes
test_adaptive_sampling_set_allotment_percent
test_adaptive_sampling_check
test_adaptive_sampling_preview
All pass locally. The same 5 pre-existing DNS-flakes in unrelated
modules (cases/dbm/logs/metrics/traces) remain — not touched here.
## Follow-up
Once both B1 (sampling-rules) and this PR (B2) ship in a pup release,
flip the agent-skills `dd-apm/sampling` skill PR from draft to ready.
Co-Authored-By: Claude Opus 4.7 (1M context) <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.
What does this PR do?
Motivation
Additional Notes
Checklist
Related Issues