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

[CONTP-683] feat[beta]: Support injecting APM and Dogstatsd sockets using CSI volumes instead of hostpath volume #34828

Merged

Conversation

adel121
Copy link
Contributor

@adel121 adel121 commented Mar 6, 2025

What does this PR do?

Currently, UDS sockets for DSD and APM are injected into user apps in the form of hostpath volumes thanks to the config webhook.

We support two types of hostpath volumes:

  • Socket
  • DirectoryOrCreate

This PR allows configuring the admission controller to leverage the existence of a CSI driver to replace HostPath volumes by CSI volume.

This feature requires the datadog CSI driver to be deployed and running on the cluster.

The CSI volume will take into account the user's choice (Socket vs DirectoryOrCreate) when injecting the CSI driver and will provide the same behaviour in the CSI driver via the mode attribute set in the volumeAttributes.

Motivation

Allow users to use dogstatsd and APM tracing over UDS in namespaces having baseline or restrictive pod security standards. (CSI volumes are accepted in such contexts, hostpath volumes are not).

Describe how you validated your changes

Deploy the datadog csi driver

  • Clone the datadog csi driver repo.
  • From the root path, build the driver with docker build.
  • Deploy the driver with helm install --set image.repository=<image-name> --set image.tag=<tag> datadog-csi ./chart/datadog-csi-driver

Deploy the agent with dca

datadog:
  apiKeyExistingSecret: datadog-secret
  appKeyExistingSecret: datadog-secret
  clusterName: adel-test-dca-csi
  clusterChecks:
    enabled: true
  kubelet:
    tlsVerify: false
  checksCardinality: none

clusterAgent:
  admissionController:
    enabled: true
    mutateUnlabelled: true
  envDict:
    DD_CSI_ENABLED: "true"
    DD_CSI_DRIVER: "k8s.csi.datadoghq.com"
    DD_ADMISSION_CONTROLLER_INJECT_CONFIG_TYPE_SOCKET_VOLUMES: "true"

Deploy a test app

Once all agents (including the cluster agent) are up and running, create a test app in the dev namespace:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: datadogpy
  namespace: dev
spec:
  replicas: 1
  selector:
    matchLabels:
      app: datadogpy
  template:
    metadata:
      labels:
        app: datadogpy
    spec:
      containers:
        - name: datadogpy-local
          image: adelhajhassan918/datadogpy-uds-udp
          imagePullPolicy: Always

Verify CSI Volume Injection

Check the deployment pods and verify that they got CSI volumes injected and mounted:

  - csi:
      driver: k8s.csi.datadoghq.com
      readOnly: false
      volumeAttributes:
        mode: socket
        path: /var/run/datadog/dsd.socket
    name: datadog-dogstatsd
  - csi:
      driver: k8s.csi.datadoghq.com
      readOnly: false
      volumeAttributes:
        mode: socket
        path: /var/run/datadog/apm.socket
    name: datadog-trace-agent

Notice the mode of the volumes is socket, and the path is the socket file path.

They should be mounted like this:

    volumeMounts:
    - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      name: kube-api-access-dhctf
      readOnly: true
    - mountPath: /var/run/datadog/dsd.socket
      name: datadog-dogstatsd
    - mountPath: /var/run/datadog/apm.socket
      name: datadog-trace-agent

Verify custom metrics

Check the UI and verify that the app is able to send custom metrics:
image

Verify that

Uninstall the aget and delete the test app, then try again the same test while removing DD_ADMISSION_CONTROLLER_INJECT_CONFIG_TYPE_SOCKET_VOLUMES: "true".

The effect should be that the injected CSI volume should have mode local and have path var/run/datadog

  - csi:
      driver: k8s.csi.datadoghq.com
      readOnly: false
      volumeAttributes:
        mode: local
        path: /var/run/datadog
    name: datadog
    volumeMounts:
    - mountPath: /var/run/secrets/kubernetes.io/serviceaccount
      name: kube-api-access-bmpk8
      readOnly: true
    - mountPath: /var/run/datadog
      name: datadog

Possible Drawbacks / Trade-offs

Additional Notes

@adel121 adel121 requested review from a team as code owners March 6, 2025 12:40
@adel121 adel121 requested a review from dustmop March 6, 2025 12:40
@adel121 adel121 marked this pull request as draft March 6, 2025 12:40
@github-actions github-actions bot added medium review PR review might take time team/container-platform The Container Platform Team labels Mar 6, 2025
@agent-platform-auto-pr
Copy link
Contributor

agent-platform-auto-pr bot commented Mar 6, 2025

Test changes on VM

Use this command from test-infra-definitions to manually test this PR changes on a VM:

dda inv aws.create-vm --pipeline-id=58053470 --os-family=ubuntu

Note: This applies to commit bbbcaa2

@agent-platform-auto-pr
Copy link
Contributor

agent-platform-auto-pr bot commented Mar 6, 2025

Uncompressed package size comparison

Comparison with ancestor a3816f513378e811645a2ac1f5c82ee308b4bd9b

Diff per package
package diff status size ancestor threshold
datadog-agent-x86_64-rpm 0.01MB ⚠️ 825.01MB 825.00MB 0.50MB
datadog-agent-x86_64-suse 0.01MB ⚠️ 825.01MB 825.00MB 0.50MB
datadog-agent-amd64-deb 0.01MB ⚠️ 815.21MB 815.21MB 0.50MB
datadog-agent-aarch64-rpm 0.00MB 815.86MB 815.86MB 0.50MB
datadog-agent-arm64-deb 0.00MB 806.08MB 806.08MB 0.50MB
datadog-dogstatsd-amd64-deb 0.00MB 39.46MB 39.46MB 0.50MB
datadog-dogstatsd-x86_64-rpm 0.00MB 39.54MB 39.54MB 0.50MB
datadog-dogstatsd-x86_64-suse 0.00MB 39.54MB 39.54MB 0.50MB
datadog-dogstatsd-arm64-deb 0.00MB 37.99MB 37.99MB 0.50MB
datadog-heroku-agent-amd64-deb 0.00MB 440.86MB 440.86MB 0.50MB
datadog-iot-agent-amd64-deb 0.00MB 62.14MB 62.14MB 0.50MB
datadog-iot-agent-x86_64-rpm 0.00MB 62.21MB 62.21MB 0.50MB
datadog-iot-agent-x86_64-suse 0.00MB 62.20MB 62.20MB 0.50MB
datadog-iot-agent-arm64-deb 0.00MB 59.36MB 59.36MB 0.50MB
datadog-iot-agent-aarch64-rpm 0.00MB 59.43MB 59.43MB 0.50MB

Decision

⚠️ Warning

@adel121 adel121 added this to the 7.65.0 milestone Mar 6, 2025
@adel121 adel121 marked this pull request as ready for review March 6, 2025 13:21
@agent-platform-auto-pr
Copy link
Contributor

agent-platform-auto-pr bot commented Mar 6, 2025

Static quality checks ✅

Please find below the results from static quality gates

Successful checks

Info

Result Quality gate On disk size On disk size limit On wire size On wire size limit
static_quality_gate_agent_deb_amd64 788.46MiB 801.8MiB 192.37MiB 202.62MiB
static_quality_gate_agent_deb_arm64 779.73MiB 793.14MiB 174.36MiB 184.51MiB
static_quality_gate_agent_rpm_amd64 788.45MiB 801.79MiB 194.35MiB 205.03MiB
static_quality_gate_agent_rpm_arm64 779.72MiB 793.09MiB 175.88MiB 186.44MiB
static_quality_gate_agent_suse_amd64 788.45MiB 801.81MiB 194.35MiB 205.03MiB
static_quality_gate_agent_suse_arm64 779.72MiB 793.14MiB 175.88MiB 186.44MiB
static_quality_gate_dogstatsd_deb_amd64 37.71MiB 47.67MiB 9.78MiB 19.78MiB
static_quality_gate_dogstatsd_deb_arm64 36.3MiB 46.27MiB 8.48MiB 18.49MiB
static_quality_gate_dogstatsd_rpm_amd64 37.71MiB 47.67MiB 9.79MiB 19.79MiB
static_quality_gate_dogstatsd_suse_amd64 37.71MiB 47.67MiB 9.79MiB 19.79MiB
static_quality_gate_iot_agent_deb_amd64 59.33MiB 69.0MiB 14.91MiB 24.8MiB
static_quality_gate_iot_agent_deb_arm64 56.68MiB 66.4MiB 12.87MiB 22.8MiB
static_quality_gate_iot_agent_rpm_amd64 59.33MiB 69.0MiB 14.93MiB 24.8MiB
static_quality_gate_iot_agent_rpm_arm64 56.69MiB 66.4MiB 12.87MiB 22.8MiB
static_quality_gate_iot_agent_suse_amd64 59.33MiB 69.0MiB 14.93MiB 24.8MiB
static_quality_gate_docker_agent_amd64 873.6MiB 886.12MiB 293.91MiB 304.21MiB
static_quality_gate_docker_agent_arm64 888.15MiB 900.79MiB 280.13MiB 290.47MiB
static_quality_gate_docker_agent_jmx_amd64 1.05GiB 1.06GiB 369.02MiB 379.33MiB
static_quality_gate_docker_agent_jmx_arm64 1.05GiB 1.06GiB 351.19MiB 361.55MiB
static_quality_gate_docker_dogstatsd_amd64 45.86MiB 55.78MiB 17.3MiB 27.28MiB
static_quality_gate_docker_dogstatsd_arm64 44.48MiB 54.45MiB 16.17MiB 26.16MiB
static_quality_gate_docker_cluster_agent_amd64 265.09MiB 274.78MiB 106.42MiB 116.28MiB
static_quality_gate_docker_cluster_agent_arm64 281.02MiB 290.82MiB 101.22MiB 111.12MiB

@adel121 adel121 changed the title feat[beta]: Support injecting Tracing and Dogstatsd sockets using CSI volumes instead of hostpath volume [CONTP-683] feat[beta]: Support injecting Tracing and Dogstatsd sockets using CSI volumes instead of hostpath volume Mar 6, 2025
@adel121 adel121 added the qa/rc-required Only for a PR that requires validation on the Release Candidate label Mar 6, 2025
[BETA] Add support for mounting Datadog CSI Volumes instead of hostpath
volumes in the admission controller config webhook. This applies
to mounting Dogstatsd and Tracing UDS sockets onto user applications.
This requires datadog CSI driver to be installed and running on the cluster.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if we should put a releasenote here given that the datadog CSI driver is not yet publicly released.

Copy link

cit-pr-commenter bot commented Mar 6, 2025

Regression Detector

Regression Detector Results

Metrics dashboard
Target profiles
Run ID: 8d4fcff5-67e4-4200-85b2-e0ea8610913b

Baseline: a3816f5
Comparison: bbbcaa2
Diff

Optimization Goals: ✅ No significant changes detected

Fine details of change detection per experiment

perf experiment goal Δ mean % Δ mean % CI trials links
quality_gate_logs % cpu utilization +3.83 [+1.01, +6.65] 1 Logs
uds_dogstatsd_to_api_cpu % cpu utilization +0.94 [+0.07, +1.81] 1 Logs
quality_gate_idle memory utilization +0.46 [+0.40, +0.51] 1 Logs bounds checks dashboard
file_tree memory utilization +0.45 [+0.35, +0.55] 1 Logs
file_to_blackhole_500ms_latency egress throughput +0.31 [-0.47, +1.09] 1 Logs
file_to_blackhole_1000ms_latency egress throughput +0.15 [-0.62, +0.93] 1 Logs
file_to_blackhole_1000ms_latency_linear_load egress throughput +0.13 [-0.34, +0.61] 1 Logs
file_to_blackhole_0ms_latency_http2 egress throughput +0.02 [-0.79, +0.84] 1 Logs
tcp_dd_logs_filter_exclude ingress throughput +0.01 [-0.01, +0.03] 1 Logs
file_to_blackhole_300ms_latency egress throughput +0.00 [-0.63, +0.63] 1 Logs
file_to_blackhole_0ms_latency egress throughput -0.00 [-0.81, +0.81] 1 Logs
file_to_blackhole_0ms_latency_http1 egress throughput -0.00 [-0.82, +0.81] 1 Logs
uds_dogstatsd_to_api ingress throughput -0.01 [-0.30, +0.28] 1 Logs
file_to_blackhole_100ms_latency egress throughput -0.01 [-0.70, +0.68] 1 Logs
quality_gate_idle_all_features memory utilization -0.08 [-0.13, -0.03] 1 Logs bounds checks dashboard
tcp_syslog_to_blackhole ingress throughput -0.99 [-1.06, -0.92] 1 Logs

Bounds Checks: ✅ Passed

perf experiment bounds_check_name replicates_passed links
file_to_blackhole_0ms_latency lost_bytes 10/10
file_to_blackhole_0ms_latency memory_usage 10/10
file_to_blackhole_0ms_latency_http1 lost_bytes 10/10
file_to_blackhole_0ms_latency_http1 memory_usage 10/10
file_to_blackhole_0ms_latency_http2 lost_bytes 10/10
file_to_blackhole_0ms_latency_http2 memory_usage 10/10
file_to_blackhole_1000ms_latency memory_usage 10/10
file_to_blackhole_1000ms_latency_linear_load 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_300ms_latency lost_bytes 10/10
file_to_blackhole_300ms_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
quality_gate_logs lost_bytes 10/10
quality_gate_logs memory_usage 10/10

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

@hush-hush hush-hush removed the request for review from dustmop March 6, 2025 14:46
Copy link
Contributor

@jhgilbert jhgilbert left a comment

Choose a reason for hiding this comment

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

Approved with suggestions, I see that the release note may be deleted anyway, but wanted to offer revisions just in case. Thanks!

---
features:
- |
[BETA] Add support for mounting Datadog CSI Volumes instead of hostpath
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
[BETA] Add support for mounting Datadog CSI Volumes instead of hostpath
[PREVIEW] Add support for mounting Datadog CSI Volumes instead of hostpath

- |
[BETA] Add support for mounting Datadog CSI Volumes instead of hostpath
volumes in the admission controller config webhook. This applies
to mounting Dogstatsd and Tracing UDS sockets onto user applications.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
to mounting Dogstatsd and Tracing UDS sockets onto user applications.
to mounting Dogstatsd and tracing UDS sockets onto user applications.

I'm not sure about this one, ignore if you're not using "tracing" in the general sense

[BETA] Add support for mounting Datadog CSI Volumes instead of hostpath
volumes in the admission controller config webhook. This applies
to mounting Dogstatsd and Tracing UDS sockets onto user applications.
This requires datadog CSI driver to be installed and running on the cluster.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
This requires datadog CSI driver to be installed and running on the cluster.
This requires the Datadog CSI driver to be installed and running on the cluster.

Comment on lines 11 to 14
[BETA] Add support for mounting Datadog CSI Volumes instead of hostpath
volumes in the admission controller config webhook. This applies
to mounting Dogstatsd and Tracing UDS sockets onto user applications.
This requires datadog CSI driver to be installed and running on the cluster.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
[BETA] Add support for mounting Datadog CSI Volumes instead of hostpath
volumes in the admission controller config webhook. This applies
to mounting Dogstatsd and Tracing UDS sockets onto user applications.
This requires datadog CSI driver to be installed and running on the cluster.
[BETA] Add support for mounting Datadog CSI volumes instead of hostpath
volumes in the admission controller config webhook. This applies
to mounting DogStatsD and tracing TDS sockets onto user applications.
This requires Datadog CSI driver to be installed and running on the cluster.

If you do decide to include this release note, here are some styleguide edits!

@wdhif wdhif self-requested a review March 7, 2025 08:40
@github-actions github-actions bot added long review PR is complex, plan time to review it and removed medium review PR review might take time labels Mar 7, 2025
@adel121 adel121 requested a review from wdhif March 7, 2025 09:14
@@ -227,7 +244,7 @@ func injectExternalDataEnvVar(pod *corev1.Pod) (injected bool) {
return
}

func buildVolume(volumeName, path string, hostpathType corev1.HostPathType, readOnly bool) (corev1.Volume, corev1.VolumeMount) {
func buildHostPathVolume(volumeName, path string, hostpathType corev1.HostPathType, readOnly bool) (corev1.Volume, corev1.VolumeMount) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: readOnly seem to always be true, if there is not potential use case of it being false, it should probably be removed from the function signature.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would prefer to keep it as it is because it makes it easier in the future to support other use cases without it adding significant complexity to the code.

@@ -246,3 +263,27 @@ func buildVolume(volumeName, path string, hostpathType corev1.HostPathType, read

return volume, volumeMount
}

func buildCSIVolume(volumeName, path string, injectionMode csiInjectionMode, readOnly bool, csiDriver string) (corev1.Volume, corev1.VolumeMount) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: readOnly seem to always be true, if there is not potential use case of it being false, it should probably be removed from the function signature.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above

@adel121 adel121 requested a review from wdhif March 7, 2025 09:44
@adel121
Copy link
Contributor Author

adel121 commented Mar 7, 2025

/merge

@dd-devflow
Copy link

dd-devflow bot commented Mar 7, 2025

View all feedbacks in Devflow UI.
2025-03-07 10:40:07 UTC ℹ️ Start processing command /merge


2025-03-07 10:40:12 UTC ℹ️ MergeQueue: pull request added to the queue

The median merge time in main is 30m.


2025-03-07 11:19:43 UTC ℹ️ MergeQueue: This merge request was merged

@adel121 adel121 changed the title [CONTP-683] feat[beta]: Support injecting Tracing and Dogstatsd sockets using CSI volumes instead of hostpath volume [CONTP-683] feat[beta]: Support injecting APM and Dogstatsd sockets using CSI volumes instead of hostpath volume Mar 7, 2025
@dd-mergequeue dd-mergequeue bot merged commit d877ecf into main Mar 7, 2025
261 checks passed
@dd-mergequeue dd-mergequeue bot deleted the adelhajhassan/support_mounting_csi_volumes_in_dca_ac branch March 7, 2025 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature 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.

5 participants