Skip to content

Autodiscovery Config Filtering via CEL - #41031

Merged
dd-mergequeue[bot] merged 27 commits into
mainfrom
gabedos/ad-config-cel-filtering
Oct 21, 2025
Merged

Autodiscovery Config Filtering via CEL#41031
dd-mergequeue[bot] merged 27 commits into
mainfrom
gabedos/ad-config-cel-filtering

Conversation

@gabedos

@gabedos gabedos commented Sep 17, 2025

Copy link
Copy Markdown
Contributor

What does this PR do?

Introduces a new matching capability for check-configurations and services within Autodiscovery. The cel_selector takes in rules defined by Google's Common Expression Language and allows more granular decision making onto which service a check gets scheduled on.

The cel_selector will be able to be configured independently and also with traditional ad_identifiers / advanced_ad_identifiers:

  1. If used alone, the cel_selector will be used to compare every candidate service with the check-config (more computational expensive and can be risky).
  2. If the cel_selector is defined with an ADID, then the Autodiscovery Identifier will be applied first. Only if the ADIDs match between the service and config will the cel_selector execute to perform more granular matching.

The support of the cel_selector in Autodiscovery is limited to containers, kube_services, kube_endpoints, and in the near future processes. The structures for each entity are defined here in the WorkloadFilter proto definitions. This still remains to be documented.

Motivation

Expose more granular check scheduling capabilities for the Agent. CONTP-984

Describe how you validated your changes

Deploy the Agent with the subsequent helm chart.
  • On the Node Agent, it contains a check config which targets all containers in the datadog-agent namespace. It also contains a check config which targets an nginx image in a container called load-balancer.
  • On the Cluster Agent, it container a check config which targets my-nginx service in the default namespace with datadog-obs annotation. It also contains a check config which targets all services in the cluster.
datadog:
  kubelet:
    tlsVerify: false
  clusterChecks:
    enabled: true
  confd:
    # Schedules redisdb check on every container in the "datadog-agent" namespace
    redisdb.yaml: |-
      cel_selector:
        containers:
          - container.pod.namespace == "datadog-agent" && container.image.reference != ""
      init_config:
      instances:
        - host: "%%host%%"
          port: "%%port%%"
          name: "gabedos-test-cel"
    # Schedules http_check on load-balancer container running nginx image
    http_check.yaml: |-
      ad_identifiers:
        - nginx
      cel_selector:
        containers:
          - container.name.matches("load-balancer")
      init_config:
      instances:
        - url: "http://%%host%%"
          name: "my-cel-nginx"
clusterAgent:
  enabled: true
  replicas: 1
  confd:
    http_check.yaml: |-
      advanced_ad_identifiers:
        - kube_service:
            name: "my-nginx"
            namespace: "default"
      cel_selector:
        kube_services:
          - kube_service.annotations["datadog-obs"] == "true"
      cluster_check: true
      init_config:
      instances:
        - url: "http://%%host%%"
          name: "my-nginx"
    http_check2.yaml: |-
      cel_selector:
        kube_services:
          - kube_service.name.matches("") || kube_service.namespace != ""
      cluster_check: true
      init_config:
      instances:
        - url: "http://%%host%%"
          name: "all-services-check"

Case 1 (Node + CEL + File): On the node agent, you should expect agent configcheck to expose a redisdb check configured for all containers in the datadog-agent namespace (node agent, dca, and clc runners).

Case 2 (Node + ADID + CEL + File): On the node agent, you should expect `agent configcheck` to expose a http check configured for the nginx pod.
apiVersion: v1
kind: Pod
metadata:
  name: nginx-pod
spec:
  containers:
    - name: load-balancer
      image: nginx:latest
      ports:
        - containerPort: 80

Case 3 (DCA + CEL + File): On the cluster agent, you should expect agent configcheck to expose a http check2 configured for every single service in your cluster.

Case 4 (DCA + ADID + CEL + File): On the cluster agent, you should expect `agent configcheck` to expose a http check configured for the service defined below.
apiVersion: v1
kind: Service
metadata:
  name: my-nginx
  namespace: default
  annotations:
    team: "platform-team"
    datadog-obs: "true"
spec:
  selector:
    app: nginx
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
  type: ClusterIP

Additional Notes

CELSelector via Annotations: We have decided to not implement support for parsing this rule when defining check configuration via annotations/labels on a resource. We assume that if you are explicitly adding a check config directly onto a granular resource, the user would be wanting to run the check. This simplifies Agent side code as well as reduces risks of misconfiguration from users.

DCA KubeServices + KubeEndpoints: We want to allow users to filter on services and endpoints based on their parameters like name, namespace, and annotations. Currently in the cluster-agent we do not store a complete view of these entities. Autodiscovery has its own direct collector from the APIServer. Therefore, we must store the metadata of the k8s object within the Autodiscovery service entity. This is limited to the name, namespace, and annotations of the entity.

Performance: This change was tested and profiled on an experimental cluster. We can see that in terms of CPU usage there are no drastic changes. The service reconciliation only happens when new workloads enter the node which should be relatively infrequent. In terms of memory usage, the compiled regex expression accounts for about half the memory usage for the compiled program and the other half is other miscellaneous costs of CEL. Memory costs linearly scale with the size of rules which users define.

CPU Profiles image
Memory Profiles image

TODO Remaining Work:

  1. Re-evaluate whether we want to restrict users to define rules that have granular identifiers. For container checks this means including a short image name. For services/endpoints this means including a name and namespace in the conditions.

@gabedos
gabedos force-pushed the gabedos/ad-config-cel-filtering branch from 40c1310 to 3bd30ed Compare September 17, 2025 19:01
@cit-pr-commenter

cit-pr-commenter Bot commented Sep 17, 2025

Copy link
Copy Markdown

Regression Detector

Regression Detector Results

Metrics dashboard
Target profiles
Run ID: d813a414-7c7f-45a9-b997-cd5000596e40

Baseline: 8497514
Comparison: f8a0d60
Diff

Optimization Goals: ✅ No significant changes detected

Experiments ignored for regressions

Regressions in experiments with settings containing erratic: true are ignored.

perf experiment goal Δ mean % Δ mean % CI trials links
docker_containers_cpu % cpu utilization -23.81 [-25.43, -22.18] 1 Logs

Fine details of change detection per experiment

perf experiment goal Δ mean % Δ mean % CI trials links
quality_gate_metrics_logs memory utilization +1.11 [+0.89, +1.32] 1 Logs bounds checks dashboard
tcp_syslog_to_blackhole ingress throughput +0.70 [+0.62, +0.79] 1 Logs
otlp_ingest_metrics memory utilization +0.39 [+0.26, +0.51] 1 Logs
file_tree memory utilization +0.37 [+0.33, +0.41] 1 Logs
quality_gate_idle memory utilization +0.18 [+0.13, +0.24] 1 Logs bounds checks dashboard
ddot_metrics_sum_delta memory utilization +0.07 [-0.09, +0.22] 1 Logs
ddot_logs memory utilization +0.07 [-0.00, +0.14] 1 Logs
file_to_blackhole_100ms_latency egress throughput +0.06 [-0.54, +0.67] 1 Logs
file_to_blackhole_0ms_latency egress throughput +0.05 [-0.55, +0.66] 1 Logs
file_to_blackhole_500ms_latency egress throughput +0.02 [-0.59, +0.64] 1 Logs
uds_dogstatsd_to_api ingress throughput +0.00 [-0.21, +0.21] 1 Logs
tcp_dd_logs_filter_exclude ingress throughput +0.00 [-0.01, +0.01] 1 Logs
uds_dogstatsd_20mb_12k_contexts_20_senders memory utilization -0.01 [-0.06, +0.03] 1 Logs
quality_gate_idle_all_features memory utilization -0.03 [-0.07, +0.01] 1 Logs bounds checks dashboard
file_to_blackhole_1000ms_latency egress throughput -0.12 [-0.74, +0.50] 1 Logs
otlp_ingest_logs memory utilization -0.15 [-0.29, -0.02] 1 Logs
ddot_metrics_sum_cumulativetodelta_exporter memory utilization -0.24 [-0.43, -0.05] 1 Logs
docker_containers_memory memory utilization -0.30 [-0.74, +0.15] 1 Logs
ddot_metrics memory utilization -0.57 [-0.73, -0.40] 1 Logs
ddot_metrics_sum_cumulative memory utilization -0.62 [-0.73, -0.51] 1 Logs
quality_gate_logs % cpu utilization -2.31 [-5.03, +0.42] 1 Logs bounds checks dashboard
docker_containers_cpu % cpu utilization -23.81 [-25.43, -22.18] 1 Logs

Bounds Checks: ❌ Failed

perf experiment bounds_check_name replicates_passed links
docker_containers_cpu simple_check_run 10/10
docker_containers_memory memory_usage 9/10
docker_containers_memory simple_check_run 10/10
file_to_blackhole_0ms_latency lost_bytes 10/10
file_to_blackhole_0ms_latency memory_usage 10/10
file_to_blackhole_1000ms_latency memory_usage 10/10
file_to_blackhole_100ms_latency lost_bytes 10/10
file_to_blackhole_100ms_latency memory_usage 10/10
file_to_blackhole_500ms_latency lost_bytes 10/10
file_to_blackhole_500ms_latency memory_usage 10/10
quality_gate_idle intake_connections 10/10 bounds checks dashboard
quality_gate_idle memory_usage 10/10 bounds checks dashboard
quality_gate_idle_all_features intake_connections 10/10 bounds checks dashboard
quality_gate_idle_all_features memory_usage 10/10 bounds checks dashboard
quality_gate_logs intake_connections 10/10 bounds checks dashboard
quality_gate_logs lost_bytes 10/10 bounds checks dashboard
quality_gate_logs memory_usage 10/10 bounds checks dashboard
quality_gate_metrics_logs cpu_usage 10/10 bounds checks dashboard
quality_gate_metrics_logs intake_connections 10/10 bounds checks dashboard
quality_gate_metrics_logs lost_bytes 10/10 bounds checks dashboard
quality_gate_metrics_logs memory_usage 10/10 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:

  1. Its estimated |Δ mean %| ≥ 5.00%, indicating the change is big enough to merit a closer look.

  2. 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.

  3. Its configuration does not mark it "erratic".

CI Pass/Fail Decision

Passed. All Quality Gates passed.

  • quality_gate_idle, bounds check intake_connections: 10/10 replicas passed. Gate passed.
  • quality_gate_idle, bounds check memory_usage: 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 intake_connections: 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 cpu_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 lost_bytes: 10/10 replicas passed. Gate passed.
  • quality_gate_logs, bounds check lost_bytes: 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.

@agent-platform-auto-pr

agent-platform-auto-pr Bot commented Sep 17, 2025

Copy link
Copy Markdown
Contributor

Static quality checks

✅ Please find below the results from static quality gates
Comparison made with ancestor 8497514

Successful checks

Info

Quality gate Delta On disk size (MiB) Delta On wire size (MiB)
agent_deb_amd64 $${+0.02}$$ $${676.29}$$ < $${702.15}$$ $${-0.01}$$ $${165.14}$$ < $${177.79}$$
agent_deb_amd64_fips $${+0.02}$$ $${670.8}$$ < $${696.65}$$ $${-0.04}$$ $${164.59}$$ < $${176.53}$$
agent_heroku_amd64 $${+0.01}$$ $${336.63}$$ < $${340.18}$$ $${-0.01}$$ $${89.84}$$ < $${91.08}$$
agent_msi $${+0.06}$$ $${1013.83}$$ < $${1015.38}$$ $${-0.01}$$ $${148.42}$$ < $${150.78}$$
agent_rpm_amd64 $${+0.02}$$ $${676.28}$$ < $${702.14}$$ $${-0.04}$$ $${167.39}$$ < $${180.53}$$
agent_rpm_amd64_fips $${+0.02}$$ $${670.79}$$ < $${696.64}$$ $${+0.02}$$ $${166.05}$$ < $${178.79}$$
agent_rpm_arm64 $${+0.02}$$ $${666.09}$$ < $${686.31}$$ $${-0.01}$$ $${153.33}$$ < $${161.22}$$
agent_rpm_arm64_fips $${+0.02}$$ $${661.61}$$ < $${681.84}$$ $${+0.02}$$ $${152.68}$$ < $${160.18}$$
agent_suse_amd64 $${+0.02}$$ $${676.28}$$ < $${702.14}$$ $${-0.04}$$ $${167.39}$$ < $${180.53}$$
agent_suse_amd64_fips $${+0.02}$$ $${670.79}$$ < $${696.64}$$ $${+0.02}$$ $${166.05}$$ < $${178.79}$$
agent_suse_arm64 $${+0.02}$$ $${666.09}$$ < $${686.31}$$ $${-0.01}$$ $${153.33}$$ < $${161.22}$$
agent_suse_arm64_fips $${+0.02}$$ $${661.61}$$ < $${681.84}$$ $${+0.02}$$ $${152.68}$$ < $${160.18}$$
docker_agent_amd64 $${+0.02}$$ $${746.84}$$ < $${773.59}$$ $${-0}$$ $${251.85}$$ < $${266.06}$$
docker_agent_arm64 $${+0.02}$$ $${760.6}$$ < $${781.7}$$ $${+0.02}$$ $${242.46}$$ < $${251.85}$$
docker_agent_jmx_amd64 $${+0.02}$$ $${937.71}$$ < $${964.45}$$ $${+0.03}$$ $${320.49}$$ < $${334.68}$$
docker_agent_jmx_arm64 $${+0.02}$$ $${940.06}$$ < $${961.17}$$ $${-0.02}$$ $${307.04}$$ < $${316.44}$$
docker_cluster_agent_amd64 $${+0.02}$$ $${213.03}$$ < $${213.74}$$ $${+0}$$ $${72.27}$$ < $${73.14}$$
docker_cluster_agent_arm64 $${0}$$ $${228.92}$$ < $${229.68}$$ $${+0.01}$$ $${68.53}$$ < $${69.41}$$
docker_cws_instrumentation_amd64 $${0}$$ $${7.07}$$ < $${7.12}$$ $${-0}$$ $${2.95}$$ < $${3.29}$$
docker_cws_instrumentation_arm64 $${-0}$$ $${6.69}$$ < $${6.92}$$ $${-0}$$ $${2.7}$$ < $${3.07}$$
docker_dogstatsd_amd64 $${+0}$$ $${38.45}$$ < $${39.3}$$ $${+0}$$ $${14.84}$$ < $${15.76}$$
docker_dogstatsd_arm64 $${-0}$$ $${37.12}$$ < $${37.94}$$ $${-0.01}$$ $${14.28}$$ < $${14.83}$$
dogstatsd_deb_amd64 $${+0}$$ $${29.67}$$ < $${30.53}$$ $${+0}$$ $${7.82}$$ < $${8.75}$$
dogstatsd_deb_arm64 $${+0}$$ $${28.25}$$ < $${29.11}$$ $${-0}$$ $${6.77}$$ < $${7.71}$$
dogstatsd_rpm_amd64 $${+0}$$ $${29.67}$$ < $${30.53}$$ $${+0}$$ $${7.83}$$ < $${8.76}$$
dogstatsd_suse_amd64 $${+0}$$ $${29.67}$$ < $${30.53}$$ $${+0}$$ $${7.83}$$ < $${8.76}$$
iot_agent_deb_amd64 $${+0.01}$$ $${41.92}$$ < $${54.97}$$ $${+0}$$ $${10.9}$$ < $${14.45}$$
iot_agent_deb_arm64 $${+0.01}$$ $${39.74}$$ < $${51.9}$$ $${+0}$$ $${9.42}$$ < $${12.63}$$
iot_agent_deb_armhf $${+0.01}$$ $${39.61}$$ < $${51.84}$$ $${+0}$$ $${9.5}$$ < $${12.74}$$
iot_agent_rpm_amd64 $${+0.01}$$ $${41.92}$$ < $${54.97}$$ $${+0}$$ $${10.92}$$ < $${14.47}$$
iot_agent_suse_amd64 $${+0.01}$$ $${41.92}$$ < $${54.97}$$ $${+0}$$ $${10.92}$$ < $${14.47}$$

@gabedos
gabedos force-pushed the gabedos/ad-config-cel-filtering branch 5 times, most recently from 3472f23 to 710500b Compare September 19, 2025 17:30
@gabedos
gabedos force-pushed the gabedos/update-filter-interface branch from 972dab1 to d3c19d9 Compare September 22, 2025 19:10
Base automatically changed from gabedos/update-filter-interface to main September 22, 2025 21:16
@gabedos
gabedos force-pushed the gabedos/ad-config-cel-filtering branch from 710500b to 1e3b27a Compare September 23, 2025 17:45
@github-actions github-actions Bot added long review PR is complex, plan time to review it team/container-platform The Container Platform Team labels Sep 23, 2025
gabedos and others added 3 commits September 23, 2025 20:44
Simplifies the overall interface of users interacting with the
`WorkloadFilter` store component.

Previously, the experienced flow of using the component look like:
```
Init:
c.filterStore = filterStore
c.selectedFilterIDs = util.GetContainerSharedMetricFilters()

Run:
c.filterStore.IsContainerExcluded(filterableContainer, c.selectedFilterIDs)
```

The new interface allows users to get the actual filters from the store
in a bundle and use that object to make filtering decisions. This avoids
the need of holding onto the filterStore and also the client does not
need to pass around the selectedFilterIDs.
```
Init:
c.containerFilter := filterStore.GetContainerSharedMetricFilters()

Run:
c.containerFilter.IsExcluded(filterableContainer)
```

Simplify the experience of users with the `WorkloadFilter` store
component.

CI
@gabedos
gabedos force-pushed the gabedos/ad-config-cel-filtering branch from 9db067d to 69fc217 Compare September 23, 2025 21:01
@gabedos gabedos changed the title Gabedos/ad config cel filtering Autodiscovery Config Filtering via CEL Sep 23, 2025
@gabedos
gabedos force-pushed the gabedos/ad-config-cel-filtering branch from 69fc217 to 30097b2 Compare September 23, 2025 21:54
@gabedos
gabedos marked this pull request as ready for review September 24, 2025 14:12
@gabedos
gabedos requested review from a team as code owners September 24, 2025 14:12
@gabedos gabedos added the qa/rc-required Only for a PR that requires validation on the Release Candidate label Sep 24, 2025

@aqian01 aqian01 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for files owned by ALP

@gabedos
gabedos force-pushed the gabedos/ad-config-cel-filtering branch from 44d3a70 to 98a5fac Compare September 25, 2025 21:37
Comment thread comp/core/autodiscovery/listeners/common_filter.go Outdated
@gabedos
gabedos force-pushed the gabedos/ad-config-cel-filtering branch from 25debaa to 906f547 Compare October 2, 2025 17:26
@wdhif
wdhif requested a review from adel121 October 9, 2025 14:47
@gabedos gabedos added this to the 7.73.0 milestone Oct 15, 2025
adel121

This comment was marked as outdated.

Comment thread comp/core/workloadfilter/util/celprogram/create.go Outdated

@adel121 adel121 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a small comment

@adel121
adel121 self-requested a review October 16, 2025 09:55
@gabedos
gabedos force-pushed the gabedos/ad-config-cel-filtering branch from c7cda97 to 9e2721f Compare October 16, 2025 18:05
@gabedos
gabedos force-pushed the gabedos/ad-config-cel-filtering branch from 9e2721f to d0e556f Compare October 16, 2025 18:07
@gabedos
gabedos force-pushed the gabedos/ad-config-cel-filtering branch from 5956c87 to 561becf Compare October 20, 2025 14:36
@agent-platform-auto-pr agent-platform-auto-pr Bot deleted a comment from cit-pr-commenter Bot Oct 20, 2025
@gabedos

gabedos commented Oct 21, 2025

Copy link
Copy Markdown
Contributor Author

/merge

@dd-mergequeue
dd-mergequeue Bot merged commit e012fb7 into main Oct 21, 2025
276 checks passed
@dd-mergequeue
dd-mergequeue Bot deleted the gabedos/ad-config-cel-filtering branch October 21, 2025 18:09
@dd-devflow-routing-codex

dd-devflow-routing-codex Bot commented Oct 21, 2025

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2025-10-21 17:44:00 UTC ℹ️ Start processing command /merge


2025-10-21 17:44:07 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in main is approximately 41m (p90).


2025-10-21 18:09:52 UTC ℹ️ MergeQueue: This merge request was merged

gh-worker-dd-mergequeue-cf854d Bot pushed a commit that referenced this pull request Feb 13, 2026
### What does this PR do?

Fixes an issue where empty `cel_selector` fields appear in Fleet Automation inventory payloads for integration configs that don't define CEL selectors.

### Motivation

Following #41031 which added CEL selector support to autodiscovery, the `cel_selector` field appears in all inventory payloads with empty values even when not defined in the config file:

```yaml
cel_selector:
  containers: []
  processes: []
  pods: []
  kube_services: []
  kube_endpoints: []
```

This confuses customers viewing their configs in Fleet Automation, as they see fields that aren't in their actual `.conf` files.

### How

Added `omitempty` YAML tag to the `CELSelector` field in `configFormat` struct, consistent with all other optional fields. This ensures empty CEL selectors are omitted during YAML marshaling for inventory payloads while preserving configs that explicitly define CEL selectors.

### Describe how to test/QA your changes

- Unit tests pass for autodiscovery providers
- Configs without `cel_selector` → field omitted from inventory payload
- Configs with `cel_selector` → field present with values

Co-authored-by: baptiste.foy <baptiste.foy@datadoghq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

long review PR is complex, plan time to review it qa/rc-required Only for a PR that requires validation on the Release Candidate team/container-platform The Container Platform Team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants