Skip to content

Commit 2f2ba8c

Browse files
authored
[processor/k8sattributes] Add support for profiles signal (#35999)
#### Description Add support for profiles signal to `k8sattributesprocessor`. #### Link to tracking issue Fixes #35983 #### Testing - factory_test.go - processor_test.go
1 parent 0250081 commit 2f2ba8c

File tree

15 files changed

+440
-46
lines changed

15 files changed

+440
-46
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: k8sattributesprocessor
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Add support for profiles signal
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: [35983]
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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
<!-- status autogenerated section -->
33
| Status | |
44
| ------------- |-----------|
5-
| Stability | [beta]: logs, metrics, traces |
5+
| Stability | [development]: profiles |
6+
| | [beta]: logs, metrics, traces |
67
| Distributions | [contrib], [k8s] |
78
| Issues | [![Open issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aopen%20label%3Aprocessor%2Fk8sattributes%20&label=open&color=orange&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aopen+is%3Aissue+label%3Aprocessor%2Fk8sattributes) [![Closed issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aclosed%20label%3Aprocessor%2Fk8sattributes%20&label=closed&color=blue&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aclosed+is%3Aissue+label%3Aprocessor%2Fk8sattributes) |
89
| [Code Owners](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/CONTRIBUTING.md#becoming-a-code-owner) | [@dmitryax](https://www.github.com/dmitryax), [@fatsheep9146](https://www.github.com/fatsheep9146), [@TylerHelmuth](https://www.github.com/TylerHelmuth) |
910
| Emeritus | [@rmfitzpatrick](https://www.github.com/rmfitzpatrick) |
1011

12+
[development]: https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/component-stability.md#development
1113
[beta]: https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/component-stability.md#beta
1214
[contrib]: https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-contrib
1315
[k8s]: https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-k8s

processor/k8sattributesprocessor/e2e_test.go

Lines changed: 255 additions & 21 deletions
Large diffs are not rendered by default.

processor/k8sattributesprocessor/factory.go

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ import (
88

99
"go.opentelemetry.io/collector/component"
1010
"go.opentelemetry.io/collector/consumer"
11+
"go.opentelemetry.io/collector/consumer/consumerprofiles"
1112
"go.opentelemetry.io/collector/processor"
1213
"go.opentelemetry.io/collector/processor/processorhelper"
14+
"go.opentelemetry.io/collector/processor/processorhelper/processorhelperprofiles"
15+
"go.opentelemetry.io/collector/processor/processorprofiles"
1316

1417
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/k8sconfig"
1518
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/k8sattributesprocessor/internal/kube"
@@ -22,12 +25,13 @@ var defaultExcludes = ExcludeConfig{Pods: []ExcludePodConfig{{Name: "jaeger-agen
2225

2326
// NewFactory returns a new factory for the k8s processor.
2427
func NewFactory() processor.Factory {
25-
return processor.NewFactory(
28+
return processorprofiles.NewFactory(
2629
metadata.Type,
2730
createDefaultConfig,
28-
processor.WithTraces(createTracesProcessor, metadata.TracesStability),
29-
processor.WithMetrics(createMetricsProcessor, metadata.MetricsStability),
30-
processor.WithLogs(createLogsProcessor, metadata.LogsStability),
31+
processorprofiles.WithTraces(createTracesProcessor, metadata.TracesStability),
32+
processorprofiles.WithMetrics(createMetricsProcessor, metadata.MetricsStability),
33+
processorprofiles.WithLogs(createLogsProcessor, metadata.LogsStability),
34+
processorprofiles.WithProfiles(createProfilesProcessor, metadata.ProfilesStability),
3135
)
3236
}
3337

@@ -68,6 +72,15 @@ func createMetricsProcessor(
6872
return createMetricsProcessorWithOptions(ctx, params, cfg, nextMetricsConsumer)
6973
}
7074

75+
func createProfilesProcessor(
76+
ctx context.Context,
77+
params processor.Settings,
78+
cfg component.Config,
79+
nextProfilesConsumer consumerprofiles.Profiles,
80+
) (processorprofiles.Profiles, error) {
81+
return createProfilesProcessorWithOptions(ctx, params, cfg, nextProfilesConsumer)
82+
}
83+
7184
func createTracesProcessorWithOptions(
7285
ctx context.Context,
7386
set processor.Settings,
@@ -128,6 +141,27 @@ func createLogsProcessorWithOptions(
128141
processorhelper.WithShutdown(kp.Shutdown))
129142
}
130143

144+
func createProfilesProcessorWithOptions(
145+
ctx context.Context,
146+
set processor.Settings,
147+
cfg component.Config,
148+
nextProfilesConsumer consumerprofiles.Profiles,
149+
options ...option,
150+
) (processorprofiles.Profiles, error) {
151+
kp := createKubernetesProcessor(set, cfg, options...)
152+
153+
return processorhelperprofiles.NewProfiles(
154+
ctx,
155+
set,
156+
cfg,
157+
nextProfilesConsumer,
158+
kp.processProfiles,
159+
processorhelperprofiles.WithCapabilities(consumerCapabilities),
160+
processorhelperprofiles.WithStart(kp.Start),
161+
processorhelperprofiles.WithShutdown(kp.Shutdown),
162+
)
163+
}
164+
131165
func createKubernetesProcessor(
132166
params processor.Settings,
133167
cfg component.Config,

processor/k8sattributesprocessor/factory_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/stretchr/testify/assert"
1111
"go.opentelemetry.io/collector/component/componenttest"
1212
"go.opentelemetry.io/collector/consumer/consumertest"
13+
"go.opentelemetry.io/collector/processor/processorprofiles"
1314
"go.opentelemetry.io/collector/processor/processortest"
1415
)
1516

@@ -41,6 +42,10 @@ func TestCreateProcessor(t *testing.T) {
4142
assert.NotNil(t, lp)
4243
assert.NoError(t, err)
4344

45+
pp, err := factory.(processorprofiles.Factory).CreateProfiles(context.Background(), params, cfg, consumertest.NewNop())
46+
assert.NotNil(t, pp)
47+
assert.NoError(t, err)
48+
4449
oCfg := cfg.(*Config)
4550
oCfg.Passthrough = true
4651

@@ -56,6 +61,10 @@ func TestCreateProcessor(t *testing.T) {
5661
assert.NotNil(t, lp)
5762
assert.NoError(t, err)
5863

64+
pp, err = factory.(processorprofiles.Factory).CreateProfiles(context.Background(), params, cfg, consumertest.NewNop())
65+
assert.NotNil(t, pp)
66+
assert.NoError(t, err)
67+
5968
// Switch it back so other tests run afterwards will not fail on unexpected state
6069
kubeClientProvider = realClient
6170
}

processor/k8sattributesprocessor/go.mod

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,19 @@ require (
1616
go.opentelemetry.io/collector/config/configtelemetry v0.113.0
1717
go.opentelemetry.io/collector/confmap v1.19.0
1818
go.opentelemetry.io/collector/consumer v0.113.0
19+
go.opentelemetry.io/collector/consumer/consumerprofiles v0.113.0
1920
go.opentelemetry.io/collector/consumer/consumertest v0.113.0
2021
go.opentelemetry.io/collector/featuregate v1.19.0
2122
go.opentelemetry.io/collector/pdata v1.19.0
23+
go.opentelemetry.io/collector/pdata/pprofile v0.113.0
2224
go.opentelemetry.io/collector/pipeline v0.113.0
25+
go.opentelemetry.io/collector/pipeline/pipelineprofiles v0.113.0
2326
go.opentelemetry.io/collector/processor v0.113.0
27+
go.opentelemetry.io/collector/processor/processorhelper/processorhelperprofiles v0.113.0
28+
go.opentelemetry.io/collector/processor/processorprofiles v0.113.0
2429
go.opentelemetry.io/collector/processor/processortest v0.113.0
2530
go.opentelemetry.io/collector/receiver/otlpreceiver v0.113.0
31+
go.opentelemetry.io/collector/receiver/receiverprofiles v0.113.0
2632
go.opentelemetry.io/collector/receiver/receivertest v0.113.0
2733
go.opentelemetry.io/collector/semconv v0.113.0
2834
go.opentelemetry.io/otel/metric v1.32.0
@@ -94,15 +100,11 @@ require (
94100
go.opentelemetry.io/collector/config/configtls v1.19.0 // indirect
95101
go.opentelemetry.io/collector/config/internal v0.113.0 // indirect
96102
go.opentelemetry.io/collector/consumer/consumererror v0.113.0 // indirect
97-
go.opentelemetry.io/collector/consumer/consumerprofiles v0.113.0 // indirect
98103
go.opentelemetry.io/collector/extension v0.113.0 // indirect
99104
go.opentelemetry.io/collector/extension/auth v0.113.0 // indirect
100105
go.opentelemetry.io/collector/internal/sharedcomponent v0.113.0 // indirect
101-
go.opentelemetry.io/collector/pdata/pprofile v0.113.0 // indirect
102106
go.opentelemetry.io/collector/pdata/testdata v0.113.0 // indirect
103-
go.opentelemetry.io/collector/processor/processorprofiles v0.113.0 // indirect
104107
go.opentelemetry.io/collector/receiver v0.113.0 // indirect
105-
go.opentelemetry.io/collector/receiver/receiverprofiles v0.113.0 // indirect
106108
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.56.0 // indirect
107109
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 // indirect
108110
go.opentelemetry.io/otel v1.32.0 // indirect

processor/k8sattributesprocessor/go.sum

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

processor/k8sattributesprocessor/internal/metadata/generated_status.go

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

processor/k8sattributesprocessor/metadata.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ status:
44
class: processor
55
stability:
66
beta: [logs, metrics, traces]
7+
development: [profiles]
78
distributions: [contrib, k8s]
89
codeowners:
910
active: [dmitryax, fatsheep9146, TylerHelmuth]

processor/k8sattributesprocessor/processor.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"go.opentelemetry.io/collector/pdata/pcommon"
1414
"go.opentelemetry.io/collector/pdata/plog"
1515
"go.opentelemetry.io/collector/pdata/pmetric"
16+
"go.opentelemetry.io/collector/pdata/pprofile"
1617
"go.opentelemetry.io/collector/pdata/ptrace"
1718
conventions "go.opentelemetry.io/collector/semconv/v1.8.0"
1819
"go.uber.org/zap"
@@ -117,6 +118,16 @@ func (kp *kubernetesprocessor) processLogs(ctx context.Context, ld plog.Logs) (p
117118
return ld, nil
118119
}
119120

121+
// processProfiles process profiles and add k8s metadata using resource IP, hostname or incoming IP as pod origin.
122+
func (kp *kubernetesprocessor) processProfiles(ctx context.Context, pd pprofile.Profiles) (pprofile.Profiles, error) {
123+
rp := pd.ResourceProfiles()
124+
for i := 0; i < rp.Len(); i++ {
125+
kp.processResource(ctx, rp.At(i).Resource())
126+
}
127+
128+
return pd, nil
129+
}
130+
120131
// processResource adds Pod metadata tags to resource based on pod association configuration
121132
func (kp *kubernetesprocessor) processResource(ctx context.Context, resource pcommon.Resource) {
122133
podIdentifierValue := extractPodID(ctx, resource.Attributes(), kp.podAssociations)

0 commit comments

Comments
 (0)