-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Description
Component(s)
receiver/k8scluster
Is your feature request related to a problem? Please describe.
The k8sclusterreceiver doesn't collect metrics for sidecar containers, only for the main containers in a pod:
opentelemetry-collector-contrib/receiver/k8sclusterreceiver/internal/pod/pods.go
Lines 89 to 91 in ab268ae
| for _, c := range pod.Spec.Containers { | |
| container.RecordSpecMetrics(logger, mb, c, pod, ts) | |
| } |
Describe the solution you'd like
This OtelCol receiver could also collect telemetry from sidecar containers e.g. status, restarts, requests, limits.
Sidecar containers became generally available in Kubernetes 1.29 as special init containers defining a restartPolicy.
Example from the sidecar doc:
apiVersion: apps/v1
kind: Deployment
metadata:
...
spec:
...
template:
...
spec:
containers:
...
initContainers:
- name: logshipper
image: alpine:latest
restartPolicy: Always
command: ['sh', '-c', 'tail -F /opt/logs.txt']
volumeMounts:
- name: data
mountPath: /opt
Main and init containers are sharing the same spec (with restartPolicy only applicable to init containers), so we can likely reuse the existing container telemetry processing code as-is for sidecars.
Init containers are typically meant to be short-lived and were likely excluded for that reason. Only sidecars should be picked up when processing spec.initContainers.
Describe alternatives you've considered
No response
Additional context
Official sidecar containers are:
- available since Kubernetes 1.28 (EOL Oct 2024),
- enabled by default since 1.29 (EOL Feb 2025) and
- stable as of 1.33 (May 2025).
Sidecar containers are the secondary containers that run along with the main application container within the same Pod. These containers are used to enhance or to extend the functionality of the primary app container by providing additional services, or functionality such as logging, monitoring, security, or data synchronization, without directly altering the primary application code.
These containers live as long as the main container(s) of the pod, and as a workaround, used to be implemented as main containers with lifecycle hooks.
Tip
React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it. Learn more here.