Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[processor/resourcedetection] add support for Profiles signal type #36107

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .chloggen/resourcedetectionprocessor-profiles.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: resourcedetectionprocessor

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Introduce support for Profiles signal type."

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [35980]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
2 changes: 2 additions & 0 deletions connector/datadogconnector/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions exporter/datadogexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ require (
go.opentelemetry.io/collector/pdata/testdata v0.113.0 // indirect
go.opentelemetry.io/collector/pipeline v0.113.0 // indirect
go.opentelemetry.io/collector/pipeline/pipelineprofiles v0.113.0 // indirect
go.opentelemetry.io/collector/processor/processorhelper/processorhelperprofiles v0.113.0 // indirect
go.opentelemetry.io/collector/processor/processorprofiles v0.113.0 // indirect
go.opentelemetry.io/collector/processor/processortest v0.113.0 // indirect
go.opentelemetry.io/collector/receiver/receiverprofiles v0.113.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions exporter/datadogexporter/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions exporter/datadogexporter/integrationtest/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion processor/resourcedetectionprocessor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
<!-- status autogenerated section -->
| Status | |
| ------------- |-----------|
| Stability | [beta]: traces, metrics, logs |
| Stability | [development]: profiles |
| | [beta]: traces, metrics, logs |
| Distributions | [contrib], [k8s] |
| Issues | [![Open issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aopen%20label%3Aprocessor%2Fresourcedetection%20&label=open&color=orange&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aopen+is%3Aissue+label%3Aprocessor%2Fresourcedetection) [![Closed issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aclosed%20label%3Aprocessor%2Fresourcedetection%20&label=closed&color=blue&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aclosed+is%3Aissue+label%3Aprocessor%2Fresourcedetection) |
| [Code Owners](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/CONTRIBUTING.md#becoming-a-code-owner) | [@Aneurysm9](https://www.github.com/Aneurysm9), [@dashpole](https://www.github.com/dashpole) |

[development]: https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/component-stability.md#development
[beta]: https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/component-stability.md#beta
[contrib]: https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-contrib
[k8s]: https://github.com/open-telemetry/opentelemetry-collector-releases/tree/main/distributions/otelcol-k8s
Expand Down
33 changes: 29 additions & 4 deletions processor/resourcedetectionprocessor/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ import (
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/consumer/consumerprofiles"
"go.opentelemetry.io/collector/processor"
"go.opentelemetry.io/collector/processor/processorhelper"
"go.opentelemetry.io/collector/processor/processorhelper/processorhelperprofiles"
"go.opentelemetry.io/collector/processor/processorprofiles"

"github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal"
"github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal/aws/ec2"
Expand Down Expand Up @@ -70,12 +73,13 @@ func NewFactory() processor.Factory {
providers: map[component.ID]*internal.ResourceProvider{},
}

return processor.NewFactory(
return processorprofiles.NewFactory(
metadata.Type,
createDefaultConfig,
processor.WithTraces(f.createTracesProcessor, metadata.TracesStability),
processor.WithMetrics(f.createMetricsProcessor, metadata.MetricsStability),
processor.WithLogs(f.createLogsProcessor, metadata.LogsStability))
processorprofiles.WithTraces(f.createTracesProcessor, metadata.TracesStability),
processorprofiles.WithMetrics(f.createMetricsProcessor, metadata.MetricsStability),
processorprofiles.WithLogs(f.createLogsProcessor, metadata.LogsStability),
processorprofiles.WithProfiles(f.createProfilesProcessor, metadata.ProfilesStability))
}

// Type gets the type of the Option config created by this factory.
Expand Down Expand Up @@ -164,6 +168,27 @@ func (f *factory) createLogsProcessor(
processorhelper.WithStart(rdp.Start))
}

func (f *factory) createProfilesProcessor(
ctx context.Context,
set processor.Settings,
cfg component.Config,
nextConsumer consumerprofiles.Profiles,
) (processorprofiles.Profiles, error) {
rdp, err := f.getResourceDetectionProcessor(set, cfg)
if err != nil {
return nil, err
}

return processorhelperprofiles.NewProfiles(
ctx,
set,
cfg,
nextConsumer,
rdp.processProfiles,
processorhelperprofiles.WithCapabilities(consumerCapabilities),
processorhelperprofiles.WithStart(rdp.Start))
}

func (f *factory) getResourceDetectionProcessor(
params processor.Settings,
cfg component.Config,
Expand Down
9 changes: 9 additions & 0 deletions processor/resourcedetectionprocessor/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/confmap/confmaptest"
"go.opentelemetry.io/collector/consumer/consumertest"
"go.opentelemetry.io/collector/processor/processorprofiles"
"go.opentelemetry.io/collector/processor/processortest"
)

Expand All @@ -37,6 +38,10 @@ func TestCreateProcessor(t *testing.T) {
lp, err := factory.CreateLogs(context.Background(), processortest.NewNopSettings(), cfg, consumertest.NewNop())
assert.NoError(t, err)
assert.NotNil(t, lp)

pp, err := factory.(processorprofiles.Factory).CreateProfiles(context.Background(), processortest.NewNopSettings(), cfg, consumertest.NewNop())
assert.NoError(t, err)
assert.NotNil(t, pp)
}

func TestCreateConfigProcessors(t *testing.T) {
Expand Down Expand Up @@ -82,4 +87,8 @@ func TestInvalidConfig(t *testing.T) {
lp, err := factory.CreateLogs(context.Background(), processortest.NewNopSettings(), cfg, consumertest.NewNop())
assert.Error(t, err)
assert.Nil(t, lp)

pp, err := factory.(processorprofiles.Factory).CreateProfiles(context.Background(), processortest.NewNopSettings(), cfg, consumertest.NewNop())
assert.Error(t, err)
assert.Nil(t, pp)
}
7 changes: 4 additions & 3 deletions processor/resourcedetectionprocessor/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ require (
go.opentelemetry.io/collector/config/configtls v1.19.0
go.opentelemetry.io/collector/confmap v1.19.0
go.opentelemetry.io/collector/consumer v0.113.0
go.opentelemetry.io/collector/consumer/consumerprofiles v0.113.0
go.opentelemetry.io/collector/consumer/consumertest v0.113.0
go.opentelemetry.io/collector/featuregate v1.19.0
go.opentelemetry.io/collector/pdata v1.19.0
go.opentelemetry.io/collector/pdata/pprofile v0.113.0
go.opentelemetry.io/collector/processor v0.113.0
go.opentelemetry.io/collector/processor/processorhelper/processorhelperprofiles v0.113.0
go.opentelemetry.io/collector/processor/processorprofiles v0.113.0
go.opentelemetry.io/collector/processor/processortest v0.113.0
go.opentelemetry.io/collector/semconv v0.113.0
go.uber.org/goleak v1.3.0
Expand Down Expand Up @@ -114,13 +118,10 @@ require (
go.opentelemetry.io/collector/config/configcompression v1.19.0 // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.113.0 // indirect
go.opentelemetry.io/collector/config/internal v0.113.0 // indirect
go.opentelemetry.io/collector/consumer/consumerprofiles v0.113.0 // indirect
go.opentelemetry.io/collector/extension v0.113.0 // indirect
go.opentelemetry.io/collector/extension/auth v0.113.0 // indirect
go.opentelemetry.io/collector/pdata/pprofile v0.113.0 // indirect
go.opentelemetry.io/collector/pdata/testdata v0.113.0 // indirect
go.opentelemetry.io/collector/pipeline v0.113.0 // indirect
go.opentelemetry.io/collector/processor/processorprofiles v0.113.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 // indirect
go.opentelemetry.io/otel v1.31.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.30.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions processor/resourcedetectionprocessor/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions processor/resourcedetectionprocessor/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ status:
class: processor
stability:
beta: [traces, metrics, logs]
development: [profiles]
distributions: [contrib, k8s]
codeowners:
active: [Aneurysm9, dashpole]
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/plog"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/collector/pdata/pprofile"
"go.opentelemetry.io/collector/pdata/ptrace"

"github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal"
Expand Down Expand Up @@ -69,3 +70,15 @@ func (rdp *resourceDetectionProcessor) processLogs(_ context.Context, ld plog.Lo
}
return ld, nil
}

// processProfiles implements the ProcessProfilesFunc type.
func (rdp *resourceDetectionProcessor) processProfiles(_ context.Context, ld pprofile.Profiles) (pprofile.Profiles, error) {
rl := ld.ResourceProfiles()
for i := 0; i < rl.Len(); i++ {
rss := rl.At(i)
rss.SetSchemaUrl(internal.MergeSchemaURL(rss.SchemaUrl(), rdp.schemaURL))
res := rss.Resource()
internal.MergeResource(res, rdp.resource, rdp.override)
}
return ld, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ import (
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/plog"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/collector/pdata/pprofile"
"go.opentelemetry.io/collector/pdata/ptrace"
"go.opentelemetry.io/collector/processor"
"go.opentelemetry.io/collector/processor/processorprofiles"
"go.opentelemetry.io/collector/processor/processortest"

"github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor/internal"
Expand Down Expand Up @@ -259,6 +261,37 @@ func TestResourceProcessor(t *testing.T) {
got = tln.AllLogs()[0].ResourceLogs().At(0).Resource().Attributes().AsRaw()

assert.Equal(t, tt.expectedResource, got)

// Test profiles consumer
tpn := new(consumertest.ProfilesSink)
rpp, err := factory.createProfilesProcessor(context.Background(), processortest.NewNopSettings(), cfg, tpn)

if tt.expectedNewError != "" {
assert.EqualError(t, err, tt.expectedNewError)
return
}

require.NoError(t, err)
assert.True(t, rpp.Capabilities().MutatesData)

err = rpp.Start(context.Background(), componenttest.NewNopHost())

if tt.detectedError != nil {
require.NoError(t, err)
return
}

require.NoError(t, err)
defer func() { assert.NoError(t, rpp.Shutdown(context.Background())) }()

pd := pprofile.NewProfiles()
require.NoError(t, pd.ResourceProfiles().AppendEmpty().Resource().Attributes().FromRaw(tt.sourceResource))

err = rpp.ConsumeProfiles(context.Background(), pd)
require.NoError(t, err)
got = tpn.AllProfiles()[0].ResourceProfiles().At(0).Resource().Attributes().AsRaw()

assert.Equal(t, tt.expectedResource, got)
})
}
}
Expand Down Expand Up @@ -328,3 +361,25 @@ func BenchmarkConsumeLogsAll(b *testing.B) {
cfg := &Config{Override: true, Detectors: []string{env.TypeStr, gcp.TypeStr}}
benchmarkConsumeLogs(b, cfg)
}

func benchmarkConsumeProfiles(b *testing.B, cfg *Config) {
factory := NewFactory()
sink := new(consumertest.ProfilesSink)
processor, _ := factory.(processorprofiles.Factory).CreateProfiles(context.Background(), processortest.NewNopSettings(), cfg, sink)

b.ResetTimer()
for n := 0; n < b.N; n++ {
// TODO use testbed.PerfTestDataProvider here once that includes resources
assert.NoError(b, processor.ConsumeProfiles(context.Background(), pprofile.NewProfiles()))
}
}

func BenchmarkConsumeProfilesDefault(b *testing.B) {
cfg := NewFactory().CreateDefaultConfig()
benchmarkConsumeProfiles(b, cfg.(*Config))
}

func BenchmarkConsumeProfilesAll(b *testing.B) {
cfg := &Config{Override: true, Detectors: []string{env.TypeStr, gcp.TypeStr}}
benchmarkConsumeProfiles(b, cfg)
}