[anomalydetection] Smart adaptive log sampling bridge module 2/4 - #53430
[anomalydetection] Smart adaptive log sampling bridge module 2/4#53430CelianR wants to merge 23 commits into
Conversation
Move push subscription delivery, cooldown, and filtering out of the anomaly scorer into a standalone severityevents package, so the scorer only derives severity state and future consumers can depend on a small reusable leaf package instead of the full observer surface. Co-authored-by: Cursor <cursoragent@cursor.com>
A subscription that joins mid-stream previously adopted the current level as a silent baseline and only learned about future transitions, never the state it joined into. Dispatcher now remembers the last level fed via Advance and delivers it as an initial synthetic event (FromLevel == ToLevel, Direction == Both) before SubscribeScorer returns, so late subscribers can see the current state right away. Directional filters correctly exclude this non-directional event, and Reset clears the remembered level so it isn't replayed as stale after a reset. Co-authored-by: Cursor <cursoragent@cursor.com>
The severityevents package's exported types still carried an "AnomalyScorer" prefix left over from before the extraction out of observer/def, which stuttered when referenced from other packages (severityeventsdef.AnomalyScorerConfiguration). Rename AnomalyScorerConfiguration/AnomalyScorerEventFilter/AnomalyScorerListener/AnomalyScorerEventDirection (and its constants) to SeverityEventsConfiguration/SeverityEventFilter/SeverityEventListener/SeverityEventDirection, matching the package's own domain instead of the scorer that used to own it. The SubscribeScorer method name is left unchanged since it is structurally shared with observer.Component and renaming it would ripple beyond this package. Also fixes a stale reference in pkg/aggregator/observer_handle_test.go, which predated this rename: it referenced observer.AnomalyScorerConfiguration, a type that had already moved out of observer/def into severityevents/def in an earlier commit and was left uncompilable. Co-authored-by: Cursor <cursoragent@cursor.com>
Cover the new severityevents/{def,impl} package, its relationship to the anomaly scorer, the mid-stream initial-delivery behavior, and the single-writer assumption on Dispatcher.Advance/Reset.
Co-authored-by: Cursor <cursoragent@cursor.com>
…vents references.
- comp/anomalydetection/observer/impl/BUILD.bazel: fix dep ordering flagged by buildifier.
- comp/anomalydetection/severityevents/def/component.go -> contract.go: rename so the components lint tool stops treating this plain contract package as a formal v2 Fx component requiring a `type Component interface` (severityevents has no fx wiring, matching the precedent set by comp/def and comp/core/delegatedauth/def).
- go.mod, comp/anomalydetection/{recorder,severityevents}/def/go.mod, internal/qbranch/anomalydetection-testbench/go.mod: add the missing replace/require entries for the new severityevents/def module so go mod tidy resolves across every module that transitively depends on observer/def.
- comp/anomalydetection/reporter/impl/notify.go and internal/qbranch/anomalydetection-testbench/bench/api.go: fix stale references to observerdef.SeverityLevel/SeverityEvent/AnomalyScorerConfiguration, types that moved to severityevents/def in an earlier commit and were left uncompilable outside the observer package's own bazel targets.
Co-authored-by: Cursor <cursoragent@cursor.com>
Brief overview of the def/impl split, the scorer's relationship to the Dispatcher, and the mid-stream initial-delivery behavior. Co-authored-by: Cursor <cursoragent@cursor.com>
- Run `dda inv modules.add-all-replace` to add the missing severityevents/def replace entry to every module's go.mod (the check_modules_replace CI job enforces that every local module's replace block is fully regenerated and in sync, not just the modules that directly need it to compile). - Run `bazel run //:gazelle` to add the missing severityevents/def test dep to observer/impl's go_test target, and to normalize severityevents/impl's BUILD.bazel single-item srcs lists to gazelle's inline style. - Add the missing package doc comment to severityeventsimpl (dispatcher.go), fixing a revive/package-comments lint failure. Co-authored-by: Cursor <cursoragent@cursor.com>
- Only start a subscription's cooldown clock when the initial synthetic event actually passes cfg.Filter. A filtered-out initial event (e.g. a de-escalations-only subscriber joining while already High) previously still seeded lastStateEntryTs, which could suppress that listener's very first real transition even though it never received anything. - Defer publishing a new subscription into d.subs until after its initial event has been delivered, so a concurrent Advance can never see (and advance) a subscription before its own initial snapshot has been sent. Previously the subscription was appended before the callback fired outside the lock, leaving a window where a real transition could reach the listener ahead of its initial state. Both fixes are covered by new deterministic regression tests (the second reproduces the ordering race via a reentrant Advance call fired from inside the initial callback itself, avoiding a flaky goroutine-based test). Co-authored-by: Cursor <cursoragent@cursor.com>
Keep one listener per dispatcher so subscribe-time ordering logic disappears, and treat Low as the default baseline so the first non-Low observation emits a real escalation event. Co-authored-by: Cursor <cursoragent@cursor.com>
Resolve upstream go.mod conflicts by taking main's removal of pkg/config/viperconfig and matching the related replace cleanup in pkg/security/seclwin/go.mod. Co-authored-by: Cursor <cursoragent@cursor.com>
Provide a cheap lock-free snapshot API for anomaly-detection consumers that need the current severity level without owning callback state, built directly on the severityevents Subscriber contract from the push-dispatcher PR. A subscriber joining mid-stream now picks up the current level immediately, via the dispatcher's initial-delivery behavior. Rebased onto the updated celian/severityevents-push branch (renamed types, contract.go, CI fixes); this used to be celian/severityevents. Co-authored-by: Cursor <cursoragent@cursor.com>
…eader Replace Reader.Unsubscribe() with a SeverityEventsReaderSubscription struct bundling the Reader and its Unsubscribe func, keeping Reader a pure read-only view. Co-authored-by: Cursor <cursoragent@cursor.com>
The cfg param is unused in the test fake's body; rename to _ to satisfy the revive unused-parameter check. Co-authored-by: Cursor <cursoragent@cursor.com>
…-pull Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # comp/anomalydetection/observer/def/component.go # comp/anomalydetection/observer/impl/anomaly_scorer.go # comp/anomalydetection/observer/impl/anomaly_scorer_test.go # comp/anomalydetection/observer/impl/observer.go # comp/anomalydetection/severityevents/README.md # comp/anomalydetection/severityevents/def/contract.go # comp/anomalydetection/severityevents/def/types.go # comp/anomalydetection/severityevents/impl/BUILD.bazel # comp/anomalydetection/severityevents/impl/dispatcher.go # comp/anomalydetection/severityevents/impl/dispatcher_test.go # internal/qbranch/anomalydetection-testbench/bench/api.go # pkg/aggregator/observer_handle_test.go
Introduces the shared anomaly-detection config-gate component
(comp/anomalydetection/config/{def,impl}) with AnomalyDetectionEnabled and
AnomalyScorerEnabled helpers, and the full
logs_config.experimental_adaptive_sampling.smart_severity_profiles config
tree: enabled, medium/high rate_limit, burst_size, pass_through, and
cooldown. Observer, logssource, and demultiplexer sub-gates consult
effective enablement so smart severity profiles implicitly enable analysis
and the anomaly scorer even when left unset, warning via Warnf only when
the user explicitly set anomaly_detection.enabled: false.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Replace *_secs integer settings with duration-typed keys (window, cooldown, point_retention) parsed via GetDuration and stored as seconds internally, with correct duration schema metadata (format: duration, golang_type:duration). Co-authored-by: Cursor <cursoragent@cursor.com>
pkg/logs/dynamicadaptivesampling bridges the anomaly-detection observer's severity reader to the log sampler: SetReader/Current() expose the last published SeverityLevel via an atomic pointer, and Module() subscribes to the observer's severity reader on startup (guarded by the smart severity profiles config key). Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Go Package Import DifferencesBaseline: 08d84a7
|
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d24173b9ff
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| return nil, nil | ||
| } | ||
|
|
||
| sub, err := observerComp.SubscribeSeverityEventsReader(severityeventsdef.SeverityEventsConfiguration{}) |
There was a problem hiding this comment.
Honor the configured cooldown for severity profiles
When smart severity profiles are enabled, this bridge subscribes with an empty SeverityEventsConfiguration, so the logs_config.experimental_adaptive_sampling.smart_severity_profiles.cooldown setting is ignored and de-escalations are delivered immediately. In environments that rely on the default 5m cooldown, consumers of Current() will switch back to Low as soon as the scorer emits a low raw value, making the dynamic sampling profile much more aggressive/flappy than configured. Parse the cooldown config and pass it as CooldownSecs in this subscription.
Useful? React with 👍 / 👎.
|
🎯 Code Coverage (details) 🔗 Commit SHA: d24173b | Docs | Datadog PR Page | Give us feedback! |
Files inventory check summaryFile checks results against ancestor 08d84a79: Results for datadog-agent_7.82.0~devel.git.653.d24173b9.pipeline.123703842-1_amd64.deb:No change detected |
Static quality checks✅ Please find below the results from static quality gates Successful checksInfo
4 successful checks with minimal change (< 2 KiB)
|
Regression DetectorRegression Detector ResultsMetrics dashboard Baseline: 08d84a7 Optimization Goals: ❌ Regression(s) detected
|
| perf | experiment | goal | Δ mean % | Δ mean % CI | trials | links |
|---|---|---|---|---|---|---|
| ❌ | quality_gate_logs | % cpu utilization | +5.22 | [+4.08, +6.36] | 1 | Logs bounds checks dashboard |
| ➖ | quality_gate_metrics_logs | memory utilization | +0.65 | [+0.40, +0.90] | 1 | Logs bounds checks dashboard |
| ➖ | quality_gate_idle_all_features | memory utilization | -0.12 | [-0.15, -0.08] | 1 | Logs bounds checks dashboard |
| ➖ | quality_gate_security_no_fs_load | memory utilization | -0.14 | [-0.24, -0.04] | 1 | Logs bounds checks dashboard |
| ➖ | quality_gate_security_idle | memory utilization | -0.17 | [-0.23, -0.10] | 1 | Logs bounds checks dashboard |
| ➖ | quality_gate_security_mean_fs_load | memory utilization | -0.20 | [-0.24, -0.17] | 1 | Logs bounds checks dashboard |
| ➖ | quality_gate_idle | memory utilization | -0.60 | [-0.65, -0.55] | 1 | Logs bounds checks dashboard |
Bounds Checks: ✅ Passed
| perf | experiment | bounds_check_name | replicates_passed | observed_value | links |
|---|---|---|---|---|---|
| ✅ | quality_gate_idle | intake_connections | 10/10 | 3 ≤ 4 | bounds checks dashboard |
| ✅ | quality_gate_idle | memory_usage | 10/10 | 145.41MiB ≤ 154MiB | bounds checks dashboard |
| ✅ | quality_gate_idle | total_bytes_received | 10/10 | 579.04KiB ≤ 819.20KiB | bounds checks dashboard |
| ✅ | quality_gate_idle_all_features | intake_connections | 10/10 | 3 ≤ 4 | bounds checks dashboard |
| ✅ | quality_gate_idle_all_features | memory_usage | 10/10 | 484.34MiB ≤ 495MiB | bounds checks dashboard |
| ✅ | quality_gate_idle_all_features | total_bytes_received | 10/10 | 0.89MiB ≤ 1.25MiB | bounds checks dashboard |
| ✅ | quality_gate_logs | intake_connections | 10/10 | 4 ≤ 6 | bounds checks dashboard |
| ✅ | quality_gate_logs | memory_usage | 10/10 | 184.83MiB ≤ 195MiB | bounds checks dashboard |
| ✅ | quality_gate_logs | missed_bytes | 10/10 | 0B = 0B | bounds checks dashboard |
| ✅ | quality_gate_logs | total_bytes_received | 10/10 | 264.61MiB ≤ 292MiB | bounds checks dashboard |
| ✅ | quality_gate_metrics_logs | cpu_usage | 10/10 | 332.65 ≤ 2000 | bounds checks dashboard |
| ✅ | quality_gate_metrics_logs | intake_connections | 10/10 | 3 ≤ 6 | bounds checks dashboard |
| ✅ | quality_gate_metrics_logs | memory_usage | 10/10 | 394.82MiB ≤ 430MiB | bounds checks dashboard |
| ✅ | quality_gate_metrics_logs | missed_bytes | 10/10 | 0B = 0B | bounds checks dashboard |
| ✅ | quality_gate_metrics_logs | total_bytes_received | 10/10 | 0.86GiB ≤ 1.04GiB | bounds checks dashboard |
| ✅ | quality_gate_security_idle | cpu_usage | 10/10 | 28.78 ≤ 40 | bounds checks dashboard |
| ✅ | quality_gate_security_idle | memory_usage | 10/10 | 295.12MiB ≤ 330MiB | bounds checks dashboard |
| ✅ | quality_gate_security_mean_fs_load | cpu_usage | 10/10 | 72.00 ≤ 80 | bounds checks dashboard |
| ✅ | quality_gate_security_mean_fs_load | memory_usage | 10/10 | 272.94MiB ≤ 310MiB | bounds checks dashboard |
| ✅ | quality_gate_security_no_fs_load | cpu_usage | 10/10 | 28.84 ≤ 40 | bounds checks dashboard |
| ✅ | quality_gate_security_no_fs_load | memory_usage | 10/10 | 280.88MiB ≤ 320MiB | bounds checks dashboard |
Explanation
Confidence level: 90.00%
Effect size tolerance: |Δ mean %| ≥ 5.00%
Performance changes are noted in the perf column of each table:
- ✅ = significantly better comparison variant performance
- ❌ = significantly worse comparison variant performance
- ➖ = no significant change in performance
A regression test is an A/B test of target performance in a repeatable rig, where "performance" is measured as "comparison variant minus baseline variant" for an optimization goal (e.g., ingress throughput). Due to intrinsic variability in measuring that goal, we can only estimate its mean value for each experiment; we report uncertainty in that value as a 90.00% confidence interval denoted "Δ mean % CI".
For each experiment, we decide whether a change in performance is a "regression" -- a change worth investigating further -- if all of the following criteria are true:
-
Its estimated |Δ mean %| ≥ 5.00%, indicating the change is big enough to merit a closer look.
-
Its 90.00% confidence interval "Δ mean % CI" does not contain zero, indicating that if our statistical model is accurate, there is at least a 90.00% chance there is a difference in performance between baseline and comparison variants.
-
Its configuration does not mark it "erratic".
Replicate Execution Details
We run multiple replicates for each experiment/variant. However, we allow replicates to be automatically retried if there are any failures, up to 8 times, at which point the replicate is marked dead and we are unable to run analysis for the entire experiment. We call each of these attempts at running replicates a replicate execution. This section lists all replicate executions that failed due to the target crashing or being oom killed.
Note: In the below tables we bucket failures by experiment, variant, and failure type. For each of these buckets we list out the replicate indexes that failed with an annotation signifying how many times said replicate failed with the given failure mode. In the below example the baseline variant of the experiment named experiment_with_failures had two replicates that failed by oom kills. Replicate 0, which failed 8 executions, and replicate 1 which failed 6 executions, all with the same failure mode.
| Experiment | Variant | Replicates | Failure | Logs | Debug Dashboard |
|---|---|---|---|---|---|
| experiment_with_failures | baseline | 0 (x8) 1 (x6) | Oom killed | Debug Dashboard |
The debug dashboard links will take you to a debugging dashboard specifically designed to investigate replicate execution failures.
❌ Retried Profiling Replicate Execution Failures (ddprof)
Note: Profiling replicas may still be executing. See the debug dashboard for up to date status.
| Experiment | Variant | Replicates | Failure | Debug Dashboard |
|---|---|---|---|---|
| quality_gate_idle | baseline | 10 | Oom killed | Debug Dashboard |
| quality_gate_idle_all_features | baseline | 10 | Oom killed | Debug Dashboard |
| quality_gate_idle_all_features | comparison | 10 | Oom killed | Debug Dashboard |
| quality_gate_logs | baseline | 10 | Oom killed | Debug Dashboard |
| quality_gate_logs | comparison | 10 | Oom killed | Debug Dashboard |
| quality_gate_metrics_logs | baseline | 10 | Oom killed | Debug Dashboard |
| quality_gate_metrics_logs | comparison | 10 | Oom killed | Debug Dashboard |
| quality_gate_security_idle | baseline | 10 | Oom killed | Debug Dashboard |
| quality_gate_security_idle | comparison | 10 | Oom killed | Debug Dashboard |
| quality_gate_security_no_fs_load | baseline | 10 | Oom killed | Debug Dashboard |
| quality_gate_security_no_fs_load | comparison | 10 | Oom killed | Debug Dashboard |
CI Pass/Fail Decision
✅ Passed. All Quality Gates passed.
- quality_gate_metrics_logs, bounds check total_bytes_received: 10/10 replicas passed. Gate passed.
- quality_gate_metrics_logs, bounds check missed_bytes: 10/10 replicas passed. Gate passed.
- quality_gate_metrics_logs, bounds check memory_usage: 10/10 replicas passed. Gate passed.
- quality_gate_metrics_logs, bounds check intake_connections: 10/10 replicas passed. Gate passed.
- quality_gate_metrics_logs, bounds check cpu_usage: 10/10 replicas passed. Gate passed.
- quality_gate_logs, bounds check missed_bytes: 10/10 replicas passed. Gate passed.
- quality_gate_logs, bounds check total_bytes_received: 10/10 replicas passed. Gate passed.
- quality_gate_logs, bounds check memory_usage: 10/10 replicas passed. Gate passed.
- quality_gate_logs, bounds check intake_connections: 10/10 replicas passed. Gate passed.
- quality_gate_idle, bounds check total_bytes_received: 10/10 replicas passed. Gate passed.
- quality_gate_idle, bounds check memory_usage: 10/10 replicas passed. Gate passed.
- quality_gate_idle, bounds check intake_connections: 10/10 replicas passed. Gate passed.
- quality_gate_security_mean_fs_load, bounds check cpu_usage: 10/10 replicas passed. Gate passed.
- quality_gate_security_mean_fs_load, bounds check memory_usage: 10/10 replicas passed. Gate passed.
- quality_gate_security_no_fs_load, bounds check memory_usage: 10/10 replicas passed. Gate passed.
- quality_gate_security_no_fs_load, bounds check cpu_usage: 10/10 replicas passed. Gate passed.
- quality_gate_security_idle, bounds check memory_usage: 10/10 replicas passed. Gate passed.
- quality_gate_security_idle, bounds check cpu_usage: 10/10 replicas passed. Gate passed.
- quality_gate_idle_all_features, bounds check intake_connections: 10/10 replicas passed. Gate passed.
- quality_gate_idle_all_features, bounds check memory_usage: 10/10 replicas passed. Gate passed.
- quality_gate_idle_all_features, bounds check total_bytes_received: 10/10 replicas passed. Gate passed.
fc5a389 to
7e37b75
Compare
What does this PR do?
Note
Feature documentation.
You can review commit by commit:
This adds the
dynamicadaptivesamplingmodule, the bridge that receives anomaly detection severity events and exposes the current severity level to consumers, and wires it into the agent run command. It is not yet consumed by anything (the sampler doesn't read it yet) — see the follow-up PRs in this stack (2/3, 3/3).Adds:
dynamicadaptivesamplingmodule, the bridge that receives anomaly eventsdynamicadaptivesampling.Module()into the agent run commandMotivation
Describe how you validated your changes
Additional Notes
Design note:
dynamicadaptivesamplingreceives events from anomaly detection and is used as a bridge such that the samplers read the events from there.