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_PTRACEandSYS_ADMINcapabilities.
Operator Configuration¶
Configure admission_inject_v2.profilers for the languages you want to profile. The following rules select Pods in the production namespace by their profiling labels.
{
"admission_inject_v2": {
"profilers": [
{
"name": "legacy-java-profiler",
"language": "java",
"namespace_selectors": [
"^production$"
],
"label_selectors": [
"profiling=async-profiler"
],
"check_annotation": false,
"image": "pubrepo.guance.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 * * * *"
}
},
{
"name": "legacy-python-profiler",
"language": "python",
"namespace_selectors": [
"^production$"
],
"label_selectors": [
"profiling=py-spy"
],
"check_annotation": false,
"image": "pubrepo.guance.com/datakit-operator/py-spy:0.1.0",
"envs": {
"DK_AGENT_HOST": "datakit-service.datakit.svc.cluster.local",
"DK_AGENT_PORT": "9529",
"DK_PROFILE_DURATION": "240",
"DK_PROFILE_SCHEDULE": "0 * * * *"
}
}
]
}
}
With check_annotation: true, set admission.datakit/java-profiler.version or admission.datakit/python-profiler.version on the Pod for the appropriate language. The value overrides the image tag. To disable the legacy Profiler for one Pod, 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
profiling: async-profiler
spec:
containers:
- name: app
image: example/movies-java:1.2.3
securityContext:
seccompProfile:
type: Unconfined
After creation, run kubectl get pod -n production -l app=movies-java -o yaml and confirm that datakit-profiler is present. If no data is available, check the Sidecar logs, kernel settings, capabilities, and the DataKit Profile receiver address.
Python (py-spy)¶
py-spy supports CPython only.
apiVersion: apps/v1
kind: Deployment
metadata:
name: movies-python
namespace: production
spec:
replicas: 1
selector:
matchLabels:
app: movies-python
template:
metadata:
labels:
app: movies-python
profiling: py-spy
spec:
containers:
- name: app
image: example/movies-python:1.2.3
After creation, run kubectl get pod -n production -l app=movies-python -o yaml and confirm that datakit-profiler is present. If no data is available, check the Sidecar logs, capabilities, whether the target process is CPython, and the DataKit Profile receiver address.