Skip to content

Legacy Profiler Injection

Profiler injection is only for compatibility with legacy deployments

Use Flameshot for new deployments. With Flameshot, you can set the profiling duration per process and trigger profiling on a schedule or when CPU or memory usage reaches a threshold.

The legacy datakit-profiler Sidecar samples Java applications with async-profiler and Python applications with py-spy.

Prerequisites

  • The Profile collector is enabled in DataKit.
  • Pod security policies allow the Sidecar to add the SYS_PTRACE and SYS_ADMIN capabilities.

Operator Configuration

Configure a rule per language in admission_inject_v2.profilers in the Operator. With check_annotation: false, this example injects the Java profiler into Pods in production that already have app=movies-java. Use the namespace and labels from your workload.

{
    "admission_inject_v2": {
        "profilers": [
            {
                "name": "legacy-java-profiler",
                "language": "java",
                "namespace_selectors": [
                    "^production$"
                ],
                "label_selectors": [
                    "app=movies-java"
                ],
                "check_annotation": false,
                "image": "pubrepo.truewatch.com/datakit-operator/async-profiler:0.6.0",
                "envs": {
                    "DK_AGENT_HOST": "datakit-service.datakit.svc.cluster.local",
                    "DK_AGENT_PORT": "9529",
                    "DK_PROFILE_DURATION": "240",
                    "DK_PROFILE_SCHEDULE": "0 * * * *"
                }
            }
        ]
    }
}

For per-workload opt-in, set check_annotation: true on the rule. On a Deployment that matches the selectors, set admission.datakit/java-profiler.version or admission.datakit/python-profiler.version in spec.template.metadata.annotations to the corresponding image tag. To disable profiling on one workload, set admission.datakit/profiler.enabled: "false".

After a match, the Operator adds the datakit-profiler Sidecar, a shared process namespace, and mounts for the working directory, /tmp, and /etc/localtime. It also sets the Pod restartPolicy to Always. Before deployment, confirm that these changes comply with the Pod security policy.

Java (async-profiler)

Nodes allow perf_events; this usually requires kernel.perf_event_paranoid to be no greater than 2.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: movies-java
  namespace: production
spec:
  replicas: 1
  selector:
    matchLabels:
      app: movies-java
  template:
    metadata:
      labels:
        app: movies-java
    spec:
      containers:
        - name: app
          image: example/movies-java:1.2.3
          securityContext:
            seccompProfile:
              type: Unconfined

Python (py-spy)

py-spy supports CPython only. Copy the rule above, change name, set language to python and image to pubrepo.truewatch.com/datakit-operator/py-spy:0.1.0, and select an existing label on the Python workload, such as app=movies-python.

Verify injection

After editing the ConfigMap directly, restart the Operator and recreate the target Pods. Check the new Pods for the datakit-profiler container.

kubectl get pods -n production -l 'app in (movies-java,movies-python)' -o custom-columns='POD:.metadata.name,CONTAINERS:.spec.containers[*].name'

If samples are missing, check the sidecar logs, capabilities, and DataKit Profile endpoint. For Java, also check perf_events on the node. For Python, confirm the target process runs CPython.