← Back to Pull requests

Expose configuration for event collection mode #3642

Closed
unknown closed this pull request without merging on Oct 23, 2026 18:47 UTC
View on GitHub
unknown unknown commented on Oct 21, 2026 16:44 UTC
Author

What does this PR do?

Adds a collectionMode field (poll|watch) to the event collection feature, mapped to the kubernetes_apiserver check's event_collection_mode option. "watch" streams events through a single persistent reflector-backed watch instead of re-opening a watch on every check run.

Motivation

Expose a new agent configuration.

Minimum Agent Versions

  • Cluster Agent: 7.81.1
  • Describe your test plan

    Tested on minikube (Kubernetes v1.37.0, containerd 2.3.4) with an operator image built from this branch. Each scenario was checked by running agent configcheck in the Cluster Agent, where the kubernetes_apiserver check runs.

    Default (no collectionMode)

    <details>
    <summary> Supporting configuration </summary>

    ...
    spec:
      global:
        ...
      # no features.eventCollection fields set
    ...
    

    </details>

    <details>
    <summary> Proof</summary>

    # CHECK USES THE CLUSTER AGENT IMAGE'S DEFAULT CONFIG
    root@datadog-cluster-agent-7f56fd9b9-dpfxh:/# agent configcheck
    === kubernetes_apiserver check ===
    Configuration provider: file
    Configuration source: file:/etc/datadog-agent/conf.d/kubernetes_apiserver.d/conf.yaml.default
    Config for instance ID: kubernetes_apiserver:d7eb902eea9f51f7
    {}
    ~
    

    # NO CHECK CONFIGMAP IS CREATED
    $ kubectl -n system get configmap datadog-kube-apiserver-config
    Error from server (NotFound): configmaps "datadog-kube-apiserver-config" not found
    

    </details>

    Outcome: PASS existing behavior is unchanged: no ConfigMap, and the check runs from the image default.

    collectionMode: poll

    <details>
    <summary> Supporting configuration </summary>

    ...
    spec:
      features:
        eventCollection:
          collectionMode: poll
    ...
    

    </details>

    <details>
    <summary> Proof</summary>

    # CHECK USES THE CLUSTER AGENT IMAGE'S DEFAULT CONFIG (SAME POD AS DEFAULT, NO ROLLOUT)
    root@datadog-cluster-agent-7f56fd9b9-dpfxh:/# agent configcheck
    === kubernetes_apiserver check ===
    Configuration provider: file
    Configuration source: file:/etc/datadog-agent/conf.d/kubernetes_apiserver.d/conf.yaml.default
    Config for instance ID: kubernetes_apiserver:d7eb902eea9f51f7
    {}
    ~
    

    # NO CHECK CONFIGMAP IS CREATED
    $ kubectl -n system get configmap datadog-kube-apiserver-config
    Error from server (NotFound): configmaps "datadog-kube-apiserver-config" not found
    

    </details>

    Outcome: PASS an explicit poll is treated like the default: no ConfigMap, and the Cluster Agent isn't restarted.

    collectionMode: watch

    <details>
    <summary> Supporting configuration </summary>

    ...
    spec:
      features:
        eventCollection:
          collectionMode: watch
    ...
    

    </details>

    <details>
    <summary> Proof</summary>

    # CHECK USES THE OPERATOR-MANAGED CONFIG WITH WATCH MODE
    root@datadog-cluster-agent-59fb99cbf4-xbgpd:/# agent configcheck
    === kubernetes_apiserver check ===
    Configuration provider: file
    Configuration source: file:/etc/datadog-agent/conf.d/kubernetes_apiserver.d/kubernetes_apiserver.yaml
    Config for instance ID: kubernetes_apiserver:33baea1590a247b8
    event_collection_mode: watch
    unbundle_events: false
    ~
    

    # CONFIGMAP OMITS collected_event_types WHEN UNBUNDLING IS OFF
    $ kubectl -n system get configmap datadog-kube-apiserver-config -o jsonpath='{.data.kubernetes_apiserver\.yaml}'
    init_config: null
    instances:
    - event_collection_mode: watch
      unbundle_events: false
    

    </details>

    Outcome: PASS event_collection_mode: watch reaches the check and the Cluster Agent logs no config errors.

    unbundleEvents only (no collectionMode)

    <details>
    <summary> Supporting configuration </summary>

    ...
    spec:
      features:
        eventCollection:
          unbundleEvents: true
          collectedEventTypes:
            - kind: Pod
              reasons: ["Failed", "BackOff"]
            - kind: Node
              reasons: ["NodeNotReady"]
    ...
    

    </details>

    <details>
    <summary> Proof</summary>

    # UNBUNDLED CONFIG WITHOUT event_collection_mode
    root@datadog-cluster-agent-74fbcf797-vnxqp:/# agent configcheck
    === kubernetes_apiserver check ===
    Configuration provider: file
    Configuration source: file:/etc/datadog-agent/conf.d/kubernetes_apiserver.d/kubernetes_apiserver.yaml
    Config for instance ID: kubernetes_apiserver:ac3c90410994b66d
    collected_event_types:
      - kind: Pod
        reasons:
          - Failed
          - BackOff
      - kind: Node
        reasons:
          - NodeNotReady
    unbundle_events: true
    ~
    

    </details>

    Outcome: PASS the unbundled-events ConfigMap is the same as before this change, with no event_collection_mode key. An empty value would make the Cluster Agent reject the config.

    collectionMode: watch with unbundleEvents

    <details>
    <summary> Supporting configuration </summary>

    ...
    spec:
      features:
        eventCollection:
          collectionMode: watch
          unbundleEvents: true
          collectedEventTypes:
            - kind: Pod
              reasons: ["Failed", "BackOff"]
            - kind: Node
              reasons: ["NodeNotReady"]
    ...
    

    </details>

    <details>
    <summary> Proof</summary>

    # BOTH SETTINGS IN ONE CONFIG
    root@datadog-cluster-agent-7cc4f96c9b-9c8kb:/# agent configcheck
    === kubernetes_apiserver check ===
    Configuration provider: file
    Configuration source: file:/etc/datadog-agent/conf.d/kubernetes_apiserver.d/kubernetes_apiserver.yaml
    Config for instance ID: kubernetes_apiserver:7a5b73b4a601d6ef
    collected_event_types:
      - kind: Pod
        reasons:
          - Failed
          - BackOff
      - kind: Node
        reasons:
          - NodeNotReady
    event_collection_mode: watch
    unbundle_events: true
    ~
    

    </details>

    Outcome: PASS watch mode and unbundled events are both in the same check config.

    collectionMode: watch, Cluster Agent < 7.81.1

    <details>
    <summary> Supporting configuration </summary>

    ...
    spec:
      features:
        eventCollection:
          collectionMode: watch
      override:
        clusterAgent:
          image:
            tag: 7.81.0 # minimum is 7.81.1
    ...
    

    </details>

    <details>
    <summary> Proof</summary>

    # OPERATOR LOGS INCLUDE ERROR
    {"level":"INFO","ts":"2026-10-21T17:37:27.810Z","logger":"controllers.DatadogAgentInternal","msg":"features.eventCollection.collectionMode watch requires a newer Cluster Agent, ignoring and using the Cluster Agent default","namespace":"system","name":"datadog","reconcileID":"095d040f-0329-4e85-854a-1c1f0ed4d0e4","kind":"DatadogAgentInternal","version":"7.81.0","minVersion":"7.81.1-0"}
    

    # CHECK FALLS BACK TO THE CLUSTER AGENT IMAGE'S DEFAULT CONFIG
    root@datadog-cluster-agent-7795f6fdcb-q45cx:/# agent configcheck
    === kubernetes_apiserver check ===
    Configuration provider: file
    Configuration source: file:/etc/datadog-agent/conf.d/kubernetes_apiserver.d/conf.yaml.default
    Config for instance ID: kubernetes_apiserver:d7eb902eea9f51f7
    {}
    ~
    

    # NO CHECK CONFIGMAP (THE ONE FROM THE PREVIOUS SCENARIO WAS CLEANED UP)
    $ kubectl -n system get configmap datadog-kube-apiserver-config
    Error from server (NotFound): configmaps "datadog-kube-apiserver-config" not found
    

    </details>

    Outcome: PASS watch is not enabled on an unsupported Cluster Agent, and the operator's logs include the configuration error.

    collectionMode: watch, Cluster Agent = 7.81.1

    <details>
    <summary> Supporting configuration </summary>

    ...
    spec:
      features:
        eventCollection:
          collectionMode: watch
      override:
        clusterAgent:
          image:
            tag: 7.81.1 # minimum version (backported in DataDog/datadog-agent#53329)
    ...
    

    </details>

    <details>
    <summary> Proof</summary>

    # CHECK USES WATCH MODE ON THE MINIMUM VERSION
    root@datadog-cluster-agent-5bbdd55c6d-hmx7f:/# agent configcheck
    === kubernetes_apiserver check ===
    Configuration provider: file
    Configuration source: file:/etc/datadog-agent/conf.d/kubernetes_apiserver.d/kubernetes_apiserver.yaml
    Config for instance ID: kubernetes_apiserver:33baea1590a247b8
    event_collection_mode: watch
    unbundle_events: false
    ~
    

    # CHECK RUNS SUCCESSFULLY WITH WATCH MODE
    root@datadog-cluster-agent-5bbdd55c6d-hmx7f:/# agent status
    ...
        kubernetes_apiserver
        --------------------
          Instance ID: kubernetes_apiserver [OK]
          Configuration Source: file:/etc/datadog-agent/conf.d/kubernetes_apiserver.d/kubernetes_apiserver.yaml[0]
          Total Runs: 3
    ...
    

    </details>

    Outcome: PASS the minimum-version boundary is inclusive, and the 7.81.1 check runs [OK] with watch mode.

    Invalid collectionMode

    <details>
    <summary> Supporting configuration </summary>

    ...
    spec:
      features:
        eventCollection:
          collectionMode: wach # invalid
    ...
    

    </details>

    <details>
    <summary> Proof</summary>

    # API SERVER REJECTS THE VALUE
    $ kubectl -n system apply -f collection-mode-invalid.yaml
    The DatadogAgent "datadog" is invalid: spec.features.eventCollection.collectionMode: Unsupported value: "wach": supported values: "poll", "watch"
    

    </details>

    Outcome: PASS CRD enum validation rejects invalid values before they reach the operator.

    Checklist

  • PR has at least one valid label: bug, enhancement, refactoring, documentation, tooling, and/or dependencies

  • PR has a milestone or the qa/skip-qa label

  • All commits are signed (see: [signing commits][1])
  • [1]: https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: gabedos Review duration: 3003m
    All Vouch review confidence checks passed
    Residual risk 0.30 = Change Risk (0.75) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.75 · 650 lines diff across 8 files
    0.75
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Sensitive Paths sensitive_paths
    0.075
    Real PR Conversation Timeline
    1 comments
    "Review active on #3642"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 75.2% (HIGH) · Higher = larger blast radius
    75.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 29.7% · Safe to merge
    29.7%