Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[kubelet] Check for metrics exclusion based on pod annotations #17251

Closed

Conversation

jennchenn
Copy link
Member

@jennchenn jennchenn commented Mar 21, 2024

What does this PR do?

This passes the pod annotations to the agent is_excluded binding to determine if kubelet metrics should be filtered.

Motivation

Support for exclusion of metrics based on pod annotations was added in agent 7.45. However, this did not filter out kubelet metrics as the annotations were not passed through to the binding.

Additional Notes

Related change to the binding in the agent here: DataDog/datadog-agent#23984

QA steps:

  1. Deploy the agent with changes from [rtloader/containers] Allow filtering containers by pod annotations for Python checks datadog-agent#23984
  2. Deploy a pod with two containers e.g.
# nginx-test-deployment.yaml

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
        service: nginx
        team: container-integrations
      annotations:
        ad.datadoghq.com/nginx.logs: '[{"type": "docker","image": "nginx","service": "nginx","source": "nginx"}]'
    spec:
      containers:
        - name: nginx
          image: nginx:latest
          resources:
            limits:
              cpu: 100m
              memory: 32Mi
            requests:
              cpu: 10m
              memory: 32Mi
          ports:
            - name: http
              containerPort: 80
          volumeMounts:
            - name: conf
              mountPath: /etc/nginx/nginx.conf
              subPath: nginx.conf
            - name: conf
              mountPath: /etc/nginx/html/index.html
              subPath: index.html
            - name: cache
              mountPath: /var/cache/nginx
            - name: var-run
              mountPath: /var/run
        - name: nginx-test
          image: nginx:latest
      volumes:
        - name: conf
          configMap:
            name: nginx
        - name: cache
          emptyDir: {}
        - name: var-run
          emptyDir: {}
...
---
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  maxUnavailable: 1
  selector:
    matchLabels:
      app: nginx
...
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: nginx
data:
  nginx.conf: |
    worker_processes  5;
    events {
      worker_connections  4096;
    }
    http {
        server {
            listen [::]:8080 ipv6only=off;
            location /nginx_status {
              stub_status on;
              access_log  /dev/stdout;
              allow all;
            }
        }
    }
  index.html: |
    <html>
      <head>
        <title>Index</title>
      </head>
      <body>
        <h1>Index</h1>
      </body>
    </html>
...

  1. Toggle adding the following annotation and verify that the corresponding container's kubelet metrics are filtered out when the annotation is present
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx
  labels:
    app: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
        service: nginx
        team: container-integrations
      annotations:
        ad.datadoghq.com/nginx-test.exclude: "true"
        ad.datadoghq.com/nginx.logs: '[{"type": "docker","image": "nginx","service": "nginx","source": "nginx"}]'
...
image

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Changelog entries must be created for modifications to shipped code
  • Add the qa/skip-qa label if the PR doesn't need to be tested during QA.

Copy link

codecov bot commented Mar 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.47%. Comparing base (70f798d) to head (705a7b0).
Report is 941 commits behind head on master.

Additional details and impacted files
Flag Coverage Δ
activemq ?
cassandra ?
confluent_platform ?
ecs_fargate 83.52% <100.00%> (ø)
hive ?
hivemq ?
hudi ?
ignite ?
jboss_wildfly ?
kafka ?
kubelet 91.08% <100.00%> (+0.08%) ⬆️
presto ?
solr ?

Flags with carried forward coverage won't be shown. Click here to find out more.

Copy link

Test Results

  6 files    6 suites   35s ⏱️
 84 tests  84 ✅ 0 💤 0 ❌
170 runs  168 ✅ 2 💤 0 ❌

Results for commit 705a7b0.

@jennchenn jennchenn added this to the 7.54.0 milestone Mar 25, 2024
@dd-devflow dd-devflow bot closed this Sep 21, 2024
@dd-devflow dd-devflow bot deleted the jenn/CONS-6217_check-exclusion-via-annotations branch September 21, 2024 00:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant