Skip to content

Commit f4442aa

Browse files
bacherfltiffany76
andauthored
[chore] [processor/k8sattributes] improve documentation for the k8sattributes processor (#33800)
**Description:** This PR attempts to improve the documentation of the k8sattributes processor. Being relatively new to this component I tried to make the documentation a bit easier to understand for new users, and highlight some limitations I found while going through the implementation. **Link to tracking Issue:** #32104 **Testing:** Trying out different configurations and association rules to get a better understanding **Documentation:** Extended the readme of this component --------- Signed-off-by: Florian Bacher <[email protected]> Co-authored-by: Tiffany Hrabusa <[email protected]>
1 parent 3cadc39 commit f4442aa

File tree

1 file changed

+121
-4
lines changed

1 file changed

+121
-4
lines changed

processor/k8sattributesprocessor/README.md

Lines changed: 121 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ The processor stores the list of running pods and the associated metadata. When
2626
to the pod from where the datapoint originated, so we can add the relevant pod metadata to the datapoint. By default, it associates the incoming connection IP
2727
to the Pod IP. But for cases where this approach doesn't work (sending through a proxy, etc.), a custom association rule can be specified.
2828

29-
Each association is specified as a list of sources of associations. A source is a rule that matches metadata from the datapoint to pod metadata.
29+
Each association is specified as a list of sources of associations. The maximum number of sources within an association is 4.
30+
A source is a rule that matches metadata from the datapoint to pod metadata.
3031
In order to get an association applied, all the sources specified need to match.
3132

3233
Each sources rule is specified as a pair of `from` (representing the rule type) and `name` (representing the attribute name if `from` is set to `resource_attribute`).
@@ -35,7 +36,7 @@ The following rule types are available:
3536
- `connection`: Takes the IP attribute from connection context (if available). In this case the processor must appear before any batching or tail sampling, which remove this information.
3637
- `resource_attribute`: Allows specifying the attribute name to lookup in the list of attributes of the received Resource. Semantic convention should be used for naming.
3738

38-
Pod association configuration.
39+
Example for a pod association configuration:
3940

4041
```yaml
4142
pod_association:
@@ -64,7 +65,31 @@ The following attributes are added by default:
6465
- k8s.deployment.name
6566
- k8s.node.name
6667

67-
You can change this list with `metadata` configuration.
68+
These attributes are also available for the use within association rules by default.
69+
The `metadata` section can also be extended with additional attributes which, if present in the `metadata` section,
70+
are then also available for the use within association rules. Available attributes are:
71+
- k8s.namespace.name
72+
- k8s.pod.name
73+
- k8s.pod.hostname
74+
- k8s.pod.ip
75+
- k8s.pod.start_time
76+
- k8s.pod.uid
77+
- k8s.replicaset.uid
78+
- k8s.replicaset.name
79+
- k8s.deployment.uid
80+
- k8s.deployment.name
81+
- k8s.daemonset.uid
82+
- k8s.daemonset.name
83+
- k8s.statefulset.uid
84+
- k8s.statefulset.name
85+
- k8s.cronjob.uid
86+
- k8s.cronjob.name
87+
- k8s.job.uid
88+
- k8s.job.name
89+
- k8s.node.name
90+
- k8s.cluster.uid
91+
- Any tags extracted from the pod labels and annotations, as described in [extracting attributes from metadata](#extracting-attributes-from-metadata)
92+
6893

6994
Not all the attributes are guaranteed to be added. Only attribute names from `metadata` should be used for
7095
pod_association's `resource_attribute`, because empty or non-existing values will be ignored.
@@ -84,6 +109,92 @@ Additional container level attributes can be extracted provided that certain res
84109
instance. If it's not set, the latest container instance will be used:
85110
- container.id (not added by default, has to be specified in `metadata`)
86111

112+
Please note, however, that container level attributes can't be used for source rules in the pod_association.
113+
114+
Example for extracting container level attributes:
115+
116+
```yaml
117+
pod_association:
118+
- sources:
119+
- from: connection
120+
extract:
121+
metadata:
122+
- k8s.pod.name
123+
- k8s.pod.uid
124+
- container.image.name
125+
- container.image.tag
126+
- k8s.container.name
127+
```
128+
129+
The previous configuration attaches the attributes listed in the `metadata` section to all resources received by a matching pod with the `k8s.container.name` attribute being present. For example, when the following trace
130+
131+
```json
132+
{
133+
"name": "lets-go",
134+
"context": {
135+
"trace_id": "0x5b8aa5a2d2c872e8321cf37308d69df2",
136+
"span_id": "0x051581bf3cb55c13"
137+
},
138+
"parent_id": null,
139+
"start_time": "2022-04-29T18:52:58.114201Z",
140+
"end_time": "2022-04-29T18:52:58.114687Z",
141+
"attributes": {
142+
"k8s.container.name": "telemetrygen"
143+
}
144+
}
145+
```
146+
147+
is sent to the collector by the following pod,
148+
149+
```yaml
150+
apiVersion: v1
151+
kind: Pod
152+
metadata:
153+
annotations:
154+
workload: deployment
155+
name: telemetrygen-pod
156+
namespace: e2ek8senrichment
157+
uid: 038e2267-b473-489b-b48c-46bafdb852eb
158+
spec:
159+
containers:
160+
- command:
161+
- /telemetrygen
162+
- traces
163+
- --otlp-insecure
164+
- --otlp-endpoint=otelcollector.svc.cluster.local:4317
165+
- --duration=10s
166+
- --rate=1
167+
- --otlp-attributes=k8s.container.name="telemetrygen"
168+
image: ghcr.io/open-telemetry/opentelemetry-collector-contrib/telemetrygen:latest
169+
name: telemetrygen
170+
status:
171+
podIP: 10.244.0.11
172+
```
173+
174+
the processor associates the received trace to the pod, based on the connection IP, and add those attributes to the resulting span:
175+
176+
```json
177+
{
178+
"name": "lets-go",
179+
"context": {
180+
"trace_id": "0x5b8aa5a2d2c872e8321cf37308d69df2",
181+
"span_id": "0x051581bf3cb55c13"
182+
},
183+
"parent_id": null,
184+
"start_time": "2022-04-29T18:52:58.114201Z",
185+
"end_time": "2022-04-29T18:52:58.114687Z",
186+
"attributes": {
187+
"k8s.container.name": "telemetrygen",
188+
"k8s.pod.name": "telemetrygen-pod",
189+
"k8s.pod.uid": "038e2267-b473-489b-b48c-46bafdb852eb",
190+
"container.image.name": "telemetrygen",
191+
"container.image.tag": "latest"
192+
}
193+
}
194+
```
195+
196+
## Extracting attributes from pod labels and annotations
197+
87198
The k8sattributesprocessor can also set resource attributes from k8s labels and annotations of pods, namespaces and nodes.
88199
The config for associating the data passing through the processor (spans, metrics and logs) with specific Pod/Namespace/Node annotations/labels is configured via "annotations" and "labels" keys.
89200
This config represents a list of annotations/labels that are extracted from pods/namespaces/nodes and added to spans, metrics and logs.
@@ -128,27 +239,33 @@ k8sattributes/2:
128239
auth_type: "serviceAccount"
129240
passthrough: false
130241
filter:
242+
# only retrieve pods running on the same node as the collector
131243
node_from_env_var: KUBE_NODE_NAME
132244
extract:
245+
# The attributes provided in 'metadata' will be added to associated resources
133246
metadata:
134247
- k8s.pod.name
135248
- k8s.pod.uid
136249
- k8s.deployment.name
137250
- k8s.namespace.name
138251
- k8s.node.name
139252
- k8s.pod.start_time
140-
labels:
253+
labels:
254+
# This label extraction rule takes the value 'app.kubernetes.io/component' label and maps it to the 'app.label.component' attribute which will be added to the associated resources
141255
- tag_name: app.label.component
142256
key: app.kubernetes.io/component
143257
from: pod
144258
pod_association:
145259
- sources:
260+
# This rule associates all resources containing the 'k8s.pod.ip' attribute with the matching pods. If this attribute is not present in the resource, this rule will not be able to find the matching pod.
146261
- from: resource_attribute
147262
name: k8s.pod.ip
148263
- sources:
264+
# This rule associates all resources containing the 'k8s.pod.uid' attribute with the matching pods. If this attribute is not present in the resource, this rule will not be able to find the matching pod.
149265
- from: resource_attribute
150266
name: k8s.pod.uid
151267
- sources:
268+
# This rule will use the IP from the incoming connection from which the resource is received, and find the matching pod, based on the 'pod.status.podIP' of the observed pods
152269
- from: connection
153270
```
154271

0 commit comments

Comments
 (0)