Skip to content

Commit 068fb3d

Browse files
committed
[processor/k8sattributes] support extracting labels and annotations from Deployments
Signed-off-by: odubajDT <[email protected]>
1 parent bc9c0f4 commit 068fb3d

21 files changed

+725
-177
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: processor/k8sattributes
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: "Support extracting labels and annotations from k8s Deployments"
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [37957]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: []

processor/k8sattributesprocessor/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,12 @@ wait_for_metadata_timeout: 10s
218218

219219
## Extracting attributes from pod labels and annotations
220220

221-
The k8sattributesprocessor can also set resource attributes from k8s labels and annotations of pods, namespaces and nodes.
222-
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.
223-
This config represents a list of annotations/labels that are extracted from pods/namespaces/nodes and added to spans, metrics and logs.
221+
The k8sattributesprocessor can also set resource attributes from k8s labels and annotations of pods, namespaces, deployments and nodes.
222+
The config for associating the data passing through the processor (spans, metrics and logs) with specific Pod/Namespace/Deployment/Node annotations/labels is configured via "annotations" and "labels" keys.
223+
This config represents a list of annotations/labels that are extracted from pods/namespaces/deployments/nodes and added to spans, metrics and logs.
224224
Each item is specified as a config of tag_name (representing the tag name to tag the spans with),
225225
key (representing the key used to extract value) and from (representing the kubernetes object used to extract the value).
226-
The "from" field has only three possible values "pod", "namespace" and "node" and defaults to "pod" if none is specified.
226+
The "from" field has only three possible values "pod", "namespace", "deployment" and "node" and defaults to "pod" if none is specified.
227227

228228
A few examples to use this config are as follows:
229229

@@ -313,7 +313,7 @@ rules:
313313
resources: ["pods", "namespaces", "nodes"]
314314
verbs: ["get", "watch", "list"]
315315
- apiGroups: ["apps"]
316-
resources: ["replicasets"]
316+
resources: ["replicasets", "deployments"]
317317
verbs: ["get", "list", "watch"]
318318
- apiGroups: ["extensions"]
319319
resources: ["replicasets"]
@@ -360,7 +360,7 @@ rules:
360360
resources: ["pods"]
361361
verbs: ["get", "watch", "list"]
362362
- apiGroups: ["apps"]
363-
resources: ["replicasets"]
363+
resources: ["replicasets", "deployments"]
364364
verbs: ["get", "list", "watch"]
365365
---
366366
apiVersion: rbac.authorization.k8s.io/v1

processor/k8sattributesprocessor/client_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type fakeClient struct {
2828
NodeInformer cache.SharedInformer
2929
Namespaces map[string]*kube.Namespace
3030
Nodes map[string]*kube.Node
31+
Deployments map[string]*kube.Deployment
3132
StopCh chan struct{}
3233
}
3334

@@ -37,7 +38,7 @@ func selectors() (labels.Selector, fields.Selector) {
3738
}
3839

3940
// newFakeClient instantiates a new FakeClient object and satisfies the ClientProvider type
40-
func newFakeClient(_ component.TelemetrySettings, _ k8sconfig.APIConfig, rules kube.ExtractionRules, filters kube.Filters, associations []kube.Association, _ kube.Excludes, _ kube.APIClientsetProvider, _ kube.InformerProvider, _ kube.InformerProviderNamespace, _ kube.InformerProviderReplicaSet, _ bool, _ time.Duration) (kube.Client, error) {
41+
func newFakeClient(_ component.TelemetrySettings, _ k8sconfig.APIConfig, rules kube.ExtractionRules, filters kube.Filters, associations []kube.Association, _ kube.Excludes, _ kube.APIClientsetProvider, _ kube.InformersFactoryList, _ bool, _ time.Duration) (kube.Client, error) {
4142
cs := fake.NewSimpleClientset()
4243

4344
ls, fs := selectors()
@@ -71,6 +72,11 @@ func (f *fakeClient) GetNode(nodeName string) (*kube.Node, bool) {
7172
return node, ok
7273
}
7374

75+
func (f *fakeClient) GetDeployment(deploymentUID string) (*kube.Deployment, bool) {
76+
d, ok := f.Deployments[deploymentUID]
77+
return d, ok
78+
}
79+
7480
// Start is a noop for FakeClient.
7581
func (f *fakeClient) Start() error {
7682
if f.Informer != nil {

processor/k8sattributesprocessor/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ func (cfg *Config) Validate() error {
7474
}
7575

7676
switch f.From {
77-
case "", kube.MetadataFromPod, kube.MetadataFromNamespace, kube.MetadataFromNode:
77+
case "", kube.MetadataFromPod, kube.MetadataFromNamespace, kube.MetadataFromNode, kube.MetadataFromDeployment:
7878
default:
79-
return fmt.Errorf("%s is not a valid choice for From. Must be one of: pod, namespace, node", f.From)
79+
return fmt.Errorf("%s is not a valid choice for From. Must be one of: pod, namespace, deployment, node", f.From)
8080
}
8181

8282
if f.KeyRegex != "" {

processor/k8sattributesprocessor/documentation.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,30 @@
3636

3737
The following telemetry is emitted by this component.
3838

39+
### otelcol_otelsvc_k8s_deployment_added
40+
41+
Number of deployment add events received
42+
43+
| Unit | Metric Type | Value Type | Monotonic |
44+
| ---- | ----------- | ---------- | --------- |
45+
| 1 | Sum | Int | true |
46+
47+
### otelcol_otelsvc_k8s_deployment_deleted
48+
49+
Number of deployment delete events received
50+
51+
| Unit | Metric Type | Value Type | Monotonic |
52+
| ---- | ----------- | ---------- | --------- |
53+
| 1 | Sum | Int | true |
54+
55+
### otelcol_otelsvc_k8s_deployment_updated
56+
57+
Number of deployment update events received
58+
59+
| Unit | Metric Type | Value Type | Monotonic |
60+
| ---- | ----------- | ---------- | --------- |
61+
| 1 | Sum | Int | true |
62+
3963
### otelcol_otelsvc_k8s_ip_lookup_miss
4064

4165
Number of times pod by IP lookup failed.

0 commit comments

Comments
 (0)