datadog-operator icon indicating copy to clipboard operation
datadog-operator copied to clipboard

[CONTP-136] Add Language Detection Config to APM SSI

Open adel121 opened this issue 9 months ago • 1 comments

What does this PR do?

This Pull Request adds the capability to configure language detection for APM SSI instrumentation and sets default configurations to allow APM SSI users to benefit from language detection by default without the need to do any configurations.

Motivation

Expose language detection feature for APM SSI through the datadog operator.

Additional Notes

  • Enabling language detection should require enabling APM SSI. This is indicated in the description of the new config option.

Minimum Agent Versions

Are there minimum versions of the Datadog Agent and/or Cluster Agent required?

  • Agent: v7.52.0
  • Cluster Agent: v7.52.0

Important Note

In case the user deploys the agent with the process check running in the core agent, language detection will not work because Live Process Collection is not enabled by default.

In this case, the user should also enable live process collection on the core agent in order for it to work.

The user should have something like this:

apiVersion: datadoghq.com/v2alpha1
kind: DatadogAgent
metadata:
  name: datadog
  namespace: system
spec:
  global:
    credentials:
      apiSecret:
        secretName: datadog-secret
        keyName: api-key
    kubelet:
      tlsVerify: false
  override:
    nodeAgent:
      env:
        - name: DD_PROCESS_CONFIG_RUN_IN_CORE_AGENT_ENABLED
          value: "true"
  features:
    apm:
      enabled: true
      instrumentation:
        enabled: true
    liveProcessCollection:
      enabled: true

Describe your test plan

The most straight forward way is to test deploying the agent using the operator in the following cases:

  • Case 1:
    • APM enabled
    • SSI enabled
    • Expectation: language detection is enabled
  • Case 2:
    • APM enabled
    • SSI disabled
    • Expectation: language detection is disabled
  • Case 3:
    • APM disabled
    • Expectation: language detection is disabled
  • Case 4:
    • APM enabled
    • SSI enabled
    • Language Detection disabled
    • Expectation: language detection is disabled

To whether language detection is enabled or not:

  • Verify that no clusterrole is created for the cluster agent to allow listing, watching and patching deployments (usually it is called apm-cluster-agent)
  • Verify that language_detection.enabled option is set to false in the core agent, the cluster agent and process agent. This can be checked by running agent config on each of these three containers.

You should also ensure that you are able to deploy v1alpha1 without any issues.

Sample Testing for Case 1:

Use the following template for datadog agent

apiVersion: datadoghq.com/v2alpha1
kind: DatadogAgent
metadata:
  name: datadog
  namespace: system
spec:
  global:
    credentials:
      apiSecret:
        secretName: datadog-secret
        keyName: api-key
    kubelet:
      tlsVerify: false
  features:
    apm:
      enabled: true
      instrumentation:
        enabled: true

Asserting the clusterrole was created:

adelhajhassan@COMP-Y0K2MF67D1 datadog-operator % kubectl get clusterrole | grep apm
datadog-apm-cluster-agent                                              2024-05-23T10:31:30Z

Asserting the proper config for language detection:

adelhajhassan@COMP-Y0K2MF67D1 datadog-operator % kubectl exec datadog-agent-r2jnp -c agent -- agent config | grep -A1 language_detection
  language_detection:
    cleanup:
--
language_detection:
  enabled: true



adelhajhassan@COMP-Y0K2MF67D1 datadog-operator % kubectl exec datadog-agent-r2jnp -c process-agent -- agent config | grep -A1 language_detection
  language_detection:
    cleanup:
--
language_detection:
  enabled: true


adelhajhassan@COMP-Y0K2MF67D1 datadog-operator % kubectl exec datadog-cluster-agent-55db5d7f9d-cvfs4   -- agent config | grep -A1 language_detection
  language_detection:
    cleanup:
--
language_detection:
  enabled: true

Testing that everything works

Deploy a dummy deployment:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: python-process-deployment
  labels:
    app: python-process-app
spec:
  replicas: 3
  selector:
    matchLabels:
      app: python-process-app
  template:
    metadata:
      labels:
        app: python-process-app
    spec:
      containers:
        - name: python-process-container
          image: python:3.7 # Replace with your Python image
          command: ["python3", "-u", "your-python-script.py"]
          volumeMounts:
            - name: python-script-volume
              mountPath: /your-python-script.py
              subPath: your-python-script.py
      volumes:
        - name: python-script-volume
          configMap:
            name: python-script-configmap
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: python-script-configmap
data:
  your-python-script.py: |
    while True:
      pass

Wait for some time, and then check that the language annotations were added on the deployment:

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: "1"
    internal.dd.datadoghq.com/python-process-container.detected_langs: python

Checklist

  • [x] PR has at least one valid label: bug, enhancement, refactoring, documentation, tooling, and/or dependencies
  • [x] PR has a milestone or the qa/skip-qa label

adel121 avatar May 22 '24 13:05 adel121