Skip to content

Commit

Permalink
[chore] add profiles support to exporter receiver builder (#10954)
Browse files Browse the repository at this point in the history
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description

This allows building profiles in the exporter builder.
As this is only changing internal modules, I am marking it as chore (and
skipping changelog entry).

#### Link to tracking issue
#10375

cc @mx-psi
  • Loading branch information
dmathieu authored Aug 30, 2024
1 parent 32171d2 commit c5dbf54
Show file tree
Hide file tree
Showing 17 changed files with 94 additions and 3 deletions.
1 change: 1 addition & 0 deletions cmd/builder/internal/builder/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ var (
"/connector/connectorprofiles",
"/exporter",
"/exporter/debugexporter",
"/exporter/exporterprofiles",
"/exporter/nopexporter",
"/exporter/otlpexporter",
"/exporter/otlphttpexporter",
Expand Down
1 change: 1 addition & 0 deletions cmd/otelcorecol/builder-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ replaces:
- go.opentelemetry.io/collector/connector/forwardconnector => ../../connector/forwardconnector
- go.opentelemetry.io/collector/exporter => ../../exporter
- go.opentelemetry.io/collector/exporter/debugexporter => ../../exporter/debugexporter
- go.opentelemetry.io/collector/exporter/exporterprofiles => ../../exporter/exporterprofiles
- go.opentelemetry.io/collector/exporter/loggingexporter => ../../exporter/loggingexporter
- go.opentelemetry.io/collector/exporter/nopexporter => ../../exporter/nopexporter
- go.opentelemetry.io/collector/exporter/otlpexporter => ../../exporter/otlpexporter
Expand Down
3 changes: 3 additions & 0 deletions cmd/otelcorecol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ require (
go.opentelemetry.io/collector/consumer v0.108.1 // indirect
go.opentelemetry.io/collector/consumer/consumerprofiles v0.108.1 // indirect
go.opentelemetry.io/collector/consumer/consumertest v0.108.1 // indirect
go.opentelemetry.io/collector/exporter/exporterprofiles v0.108.1 // indirect
go.opentelemetry.io/collector/extension/auth v0.108.1 // indirect
go.opentelemetry.io/collector/featuregate v1.14.1 // indirect
go.opentelemetry.io/collector/internal/globalgates v0.108.1 // indirect
Expand Down Expand Up @@ -206,6 +207,8 @@ replace go.opentelemetry.io/collector/exporter => ../../exporter

replace go.opentelemetry.io/collector/exporter/debugexporter => ../../exporter/debugexporter

replace go.opentelemetry.io/collector/exporter/exporterprofiles => ../../exporter/exporterprofiles

replace go.opentelemetry.io/collector/exporter/loggingexporter => ../../exporter/loggingexporter

replace go.opentelemetry.io/collector/exporter/nopexporter => ../../exporter/nopexporter
Expand Down
3 changes: 3 additions & 0 deletions exporter/debugexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ require (
go.opentelemetry.io/collector/config/configretry v1.14.1 // indirect
go.opentelemetry.io/collector/consumer/consumerprofiles v0.108.1 // indirect
go.opentelemetry.io/collector/consumer/consumertest v0.108.1 // indirect
go.opentelemetry.io/collector/exporter/exporterprofiles v0.108.1 // indirect
go.opentelemetry.io/collector/extension v0.108.1 // indirect
go.opentelemetry.io/collector/pdata/pprofile v0.108.1 // indirect
go.opentelemetry.io/collector/receiver v0.108.1 // indirect
Expand Down Expand Up @@ -97,3 +98,5 @@ replace go.opentelemetry.io/collector/consumer/consumertest => ../../consumer/co
replace go.opentelemetry.io/collector/component/componentstatus => ../../component/componentstatus

replace go.opentelemetry.io/collector/receiver/receiverprofiles => ../../receiver/receiverprofiles

replace go.opentelemetry.io/collector/exporter/exporterprofiles => ../exporterprofiles
8 changes: 7 additions & 1 deletion exporter/exportertest/nop_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/consumer/consumertest"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/exporter/exporterprofiles"
)

var nopType = component.MustNewType("nop")
Expand All @@ -33,6 +34,7 @@ func NewNopFactory() exporter.Factory {
exporter.WithTraces(createTracesExporter, component.StabilityLevelStable),
exporter.WithMetrics(createMetricsExporter, component.StabilityLevelStable),
exporter.WithLogs(createLogsExporter, component.StabilityLevelStable),
exporterprofiles.WithProfiles(createProfilesExporter, component.StabilityLevelAlpha),
)
}

Expand All @@ -48,13 +50,17 @@ func createLogsExporter(context.Context, exporter.Settings, component.Config) (e
return nopInstance, nil
}

func createProfilesExporter(context.Context, exporter.Settings, component.Config) (exporterprofiles.Profiles, error) {
return nopInstance, nil
}

type nopConfig struct{}

var nopInstance = &nopExporter{
Consumer: consumertest.NewNop(),
}

// nopExporter stores consumed traces and metrics for testing purposes.
// nopExporter stores consumed traces, metrics, logs and profiles for testing purposes.
type nopExporter struct {
component.StartFunc
component.ShutdownFunc
Expand Down
7 changes: 7 additions & 0 deletions exporter/exportertest/nop_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/pdata/plog"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/collector/pdata/pprofile"
"go.opentelemetry.io/collector/pdata/ptrace"
)

Expand Down Expand Up @@ -41,6 +42,12 @@ func TestNewNopFactory(t *testing.T) {
assert.NoError(t, logs.Start(context.Background(), componenttest.NewNopHost()))
assert.NoError(t, logs.ConsumeLogs(context.Background(), plog.NewLogs()))
assert.NoError(t, logs.Shutdown(context.Background()))

profiles, err := factory.CreateProfilesExporter(context.Background(), NewNopSettings(), cfg)
require.NoError(t, err)
assert.NoError(t, profiles.Start(context.Background(), componenttest.NewNopHost()))
assert.NoError(t, profiles.ConsumeProfiles(context.Background(), pprofile.NewProfiles()))
assert.NoError(t, profiles.Shutdown(context.Background()))
}

func TestNewNopBuilder(t *testing.T) {
Expand Down
5 changes: 4 additions & 1 deletion exporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ require (
go.opentelemetry.io/collector/consumer v0.108.1
go.opentelemetry.io/collector/consumer/consumerprofiles v0.108.1
go.opentelemetry.io/collector/consumer/consumertest v0.108.1
go.opentelemetry.io/collector/exporter/exporterprofiles v0.108.1
go.opentelemetry.io/collector/extension v0.108.1
go.opentelemetry.io/collector/pdata v1.14.1
go.opentelemetry.io/collector/pdata/pprofile v0.108.1
go.opentelemetry.io/collector/pdata/testdata v0.108.1
go.opentelemetry.io/collector/receiver v0.108.1
go.opentelemetry.io/otel v1.29.0
Expand Down Expand Up @@ -54,7 +56,6 @@ require (
github.com/prometheus/procfs v0.15.1 // indirect
go.opentelemetry.io/collector/component/componentstatus v0.108.1 // indirect
go.opentelemetry.io/collector/confmap v1.14.1 // indirect
go.opentelemetry.io/collector/pdata/pprofile v0.108.1 // indirect
go.opentelemetry.io/collector/receiver/receiverprofiles v0.108.1 // indirect
go.opentelemetry.io/otel/exporters/prometheus v0.51.0 // indirect
golang.org/x/net v0.28.0 // indirect
Expand Down Expand Up @@ -97,3 +98,5 @@ replace go.opentelemetry.io/collector/consumer/consumertest => ../consumer/consu
replace go.opentelemetry.io/collector/component/componentstatus => ../component/componentstatus

replace go.opentelemetry.io/collector/receiver/receiverprofiles => ../receiver/receiverprofiles

replace go.opentelemetry.io/collector/exporter/exporterprofiles => ./exporterprofiles
3 changes: 3 additions & 0 deletions exporter/loggingexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ require (
go.opentelemetry.io/collector/consumer v0.108.1 // indirect
go.opentelemetry.io/collector/consumer/consumerprofiles v0.108.1 // indirect
go.opentelemetry.io/collector/consumer/consumertest v0.108.1 // indirect
go.opentelemetry.io/collector/exporter/exporterprofiles v0.108.1 // indirect
go.opentelemetry.io/collector/extension v0.108.1 // indirect
go.opentelemetry.io/collector/pdata/pprofile v0.108.1 // indirect
go.opentelemetry.io/collector/receiver v0.108.1 // indirect
Expand Down Expand Up @@ -102,3 +103,5 @@ replace go.opentelemetry.io/collector/consumer/consumertest => ../../consumer/co
replace go.opentelemetry.io/collector/component/componentstatus => ../../component/componentstatus

replace go.opentelemetry.io/collector/receiver/receiverprofiles => ../../receiver/receiverprofiles

replace go.opentelemetry.io/collector/exporter/exporterprofiles => ../exporterprofiles
3 changes: 3 additions & 0 deletions exporter/nopexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ require (
go.opentelemetry.io/collector/config/configtelemetry v0.108.1 // indirect
go.opentelemetry.io/collector/consumer v0.108.1 // indirect
go.opentelemetry.io/collector/consumer/consumerprofiles v0.108.1 // indirect
go.opentelemetry.io/collector/exporter/exporterprofiles v0.108.1 // indirect
go.opentelemetry.io/collector/pdata/pprofile v0.108.1 // indirect
go.opentelemetry.io/collector/receiver v0.108.1 // indirect
go.opentelemetry.io/collector/receiver/receiverprofiles v0.108.1 // indirect
Expand Down Expand Up @@ -92,3 +93,5 @@ replace go.opentelemetry.io/collector/consumer/consumertest => ../../consumer/co
replace go.opentelemetry.io/collector/component/componentstatus => ../../component/componentstatus

replace go.opentelemetry.io/collector/receiver/receiverprofiles => ../../receiver/receiverprofiles

replace go.opentelemetry.io/collector/exporter/exporterprofiles => ../exporterprofiles
3 changes: 3 additions & 0 deletions exporter/otlpexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ require (
go.opentelemetry.io/collector/config/internal v0.108.1 // indirect
go.opentelemetry.io/collector/consumer/consumerprofiles v0.108.1 // indirect
go.opentelemetry.io/collector/consumer/consumertest v0.108.1 // indirect
go.opentelemetry.io/collector/exporter/exporterprofiles v0.108.1 // indirect
go.opentelemetry.io/collector/extension v0.108.1 // indirect
go.opentelemetry.io/collector/extension/auth v0.108.1 // indirect
go.opentelemetry.io/collector/featuregate v1.14.1 // indirect
Expand Down Expand Up @@ -150,3 +151,5 @@ replace go.opentelemetry.io/collector/consumer/consumertest => ../../consumer/co
replace go.opentelemetry.io/collector/component/componentstatus => ../../component/componentstatus

replace go.opentelemetry.io/collector/receiver/receiverprofiles => ../../receiver/receiverprofiles

replace go.opentelemetry.io/collector/exporter/exporterprofiles => ../exporterprofiles
3 changes: 3 additions & 0 deletions exporter/otlphttpexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ require (
go.opentelemetry.io/collector/config/internal v0.108.1 // indirect
go.opentelemetry.io/collector/consumer/consumerprofiles v0.108.1 // indirect
go.opentelemetry.io/collector/consumer/consumertest v0.108.1 // indirect
go.opentelemetry.io/collector/exporter/exporterprofiles v0.108.1 // indirect
go.opentelemetry.io/collector/extension v0.108.1 // indirect
go.opentelemetry.io/collector/extension/auth v0.108.1 // indirect
go.opentelemetry.io/collector/featuregate v1.14.1 // indirect
Expand Down Expand Up @@ -147,3 +148,5 @@ replace go.opentelemetry.io/collector/client => ../../client
replace go.opentelemetry.io/collector/component/componentstatus => ../../component/componentstatus

replace go.opentelemetry.io/collector/receiver/receiverprofiles => ../../receiver/receiverprofiles

replace go.opentelemetry.io/collector/exporter/exporterprofiles => ../exporterprofiles
3 changes: 3 additions & 0 deletions internal/e2e/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ require (
go.opentelemetry.io/collector/config/internal v0.108.1 // indirect
go.opentelemetry.io/collector/connector/connectorprofiles v0.108.1 // indirect
go.opentelemetry.io/collector/consumer/consumerprofiles v0.108.1 // indirect
go.opentelemetry.io/collector/exporter/exporterprofiles v0.108.1 // indirect
go.opentelemetry.io/collector/extension/auth v0.108.1 // indirect
go.opentelemetry.io/collector/featuregate v1.14.1 // indirect
go.opentelemetry.io/collector/internal/globalgates v0.108.1 // indirect
Expand Down Expand Up @@ -197,3 +198,5 @@ replace go.opentelemetry.io/collector/receiver/receiverprofiles => ../../receive
replace go.opentelemetry.io/collector/processor/processorprofiles => ../../processor/processorprofiles

replace go.opentelemetry.io/collector/connector/connectorprofiles => ../../connector/connectorprofiles

replace go.opentelemetry.io/collector/exporter/exporterprofiles => ../../exporter/exporterprofiles
3 changes: 3 additions & 0 deletions otelcol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ require (
go.opentelemetry.io/collector/consumer v0.108.1 // indirect
go.opentelemetry.io/collector/consumer/consumerprofiles v0.108.1 // indirect
go.opentelemetry.io/collector/consumer/consumertest v0.108.1 // indirect
go.opentelemetry.io/collector/exporter/exporterprofiles v0.108.1 // indirect
go.opentelemetry.io/collector/internal/globalgates v0.108.1 // indirect
go.opentelemetry.io/collector/pdata v1.14.1 // indirect
go.opentelemetry.io/collector/pdata/pprofile v0.108.1 // indirect
Expand Down Expand Up @@ -170,3 +171,5 @@ replace go.opentelemetry.io/collector/receiver/receiverprofiles => ../receiver/r
replace go.opentelemetry.io/collector/processor/processorprofiles => ../processor/processorprofiles

replace go.opentelemetry.io/collector/connector/connectorprofiles => ../connector/connectorprofiles

replace go.opentelemetry.io/collector/exporter/exporterprofiles => ../exporter/exporterprofiles
3 changes: 3 additions & 0 deletions otelcol/otelcoltest/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ require (
go.opentelemetry.io/collector/consumer v0.108.1 // indirect
go.opentelemetry.io/collector/consumer/consumerprofiles v0.108.1 // indirect
go.opentelemetry.io/collector/consumer/consumertest v0.108.1 // indirect
go.opentelemetry.io/collector/exporter/exporterprofiles v0.108.1 // indirect
go.opentelemetry.io/collector/featuregate v1.14.1 // indirect
go.opentelemetry.io/collector/internal/globalgates v0.108.1 // indirect
go.opentelemetry.io/collector/pdata v1.14.1 // indirect
Expand Down Expand Up @@ -185,3 +186,5 @@ replace go.opentelemetry.io/collector/receiver/receiverprofiles => ../../receive
replace go.opentelemetry.io/collector/processor/processorprofiles => ../../processor/processorprofiles

replace go.opentelemetry.io/collector/connector/connectorprofiles => ../../connector/connectorprofiles

replace go.opentelemetry.io/collector/exporter/exporterprofiles => ../../exporter/exporterprofiles
3 changes: 3 additions & 0 deletions service/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ require (
go.opentelemetry.io/collector/consumer/consumerprofiles v0.108.1
go.opentelemetry.io/collector/consumer/consumertest v0.108.1
go.opentelemetry.io/collector/exporter v0.108.1
go.opentelemetry.io/collector/exporter/exporterprofiles v0.108.1
go.opentelemetry.io/collector/extension v0.108.1
go.opentelemetry.io/collector/extension/zpagesextension v0.108.1
go.opentelemetry.io/collector/featuregate v1.14.1
Expand Down Expand Up @@ -178,3 +179,5 @@ replace go.opentelemetry.io/collector/receiver/receiverprofiles => ../receiver/r
replace go.opentelemetry.io/collector/processor/processorprofiles => ../processor/processorprofiles

replace go.opentelemetry.io/collector/connector/connectorprofiles => ../connector/connectorprofiles

replace go.opentelemetry.io/collector/exporter/exporterprofiles => ../exporter/exporterprofiles
17 changes: 17 additions & 0 deletions service/internal/builders/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/exporter/exporterprofiles"
"go.opentelemetry.io/collector/exporter/exportertest"
)

Expand Down Expand Up @@ -80,6 +81,22 @@ func (b *ExporterBuilder) CreateLogs(ctx context.Context, set exporter.Settings)
return f.CreateLogsExporter(ctx, set, cfg)
}

// CreateProfiles creates a Profiles exporter based on the settings and config.
func (b *ExporterBuilder) CreateProfiles(ctx context.Context, set exporter.Settings) (exporterprofiles.Profiles, error) {
cfg, existsCfg := b.cfgs[set.ID]
if !existsCfg {
return nil, fmt.Errorf("exporter %q is not configured", set.ID)
}

f, existsFactory := b.factories[set.ID.Type()]
if !existsFactory {
return nil, fmt.Errorf("exporter factory not available for: %q", set.ID)
}

logStabilityLevel(set.Logger, f.ProfilesExporterStability())
return f.CreateProfilesExporter(ctx, set, cfg)
}

func (b *ExporterBuilder) Factory(componentType component.Type) component.Factory {
return b.factories[componentType]
}
Expand Down
28 changes: 27 additions & 1 deletion service/internal/builders/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/consumer/consumertest"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/exporter/exporterprofiles"
"go.opentelemetry.io/collector/exporter/exportertest"
)

Expand All @@ -27,6 +28,7 @@ func TestExporterBuilder(t *testing.T) {
exporter.WithTraces(createExporterTraces, component.StabilityLevelDevelopment),
exporter.WithMetrics(createExporterMetrics, component.StabilityLevelAlpha),
exporter.WithLogs(createExporterLogs, component.StabilityLevelDeprecated),
exporterprofiles.WithProfiles(createExporterProfiles, component.StabilityLevelDevelopment),
),
}...)
require.NoError(t, err)
Expand Down Expand Up @@ -87,6 +89,15 @@ func TestExporterBuilder(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, nopExporterInstance, le)
}

pe, err := b.CreateProfiles(context.Background(), createExporterSettings(tt.id))
if tt.err != "" {
assert.EqualError(t, err, tt.err)
assert.Nil(t, pe)
} else {
assert.NoError(t, err)
assert.Equal(t, nopExporterInstance, pe)
}
})
}
}
Expand All @@ -100,6 +111,7 @@ func TestExporterBuilderMissingConfig(t *testing.T) {
exporter.WithTraces(createExporterTraces, component.StabilityLevelDevelopment),
exporter.WithMetrics(createExporterMetrics, component.StabilityLevelAlpha),
exporter.WithLogs(createExporterLogs, component.StabilityLevelDeprecated),
exporterprofiles.WithProfiles(createExporterProfiles, component.StabilityLevelDevelopment),
),
}...)

Expand All @@ -119,6 +131,10 @@ func TestExporterBuilderMissingConfig(t *testing.T) {
le, err := bErr.CreateLogs(context.Background(), createExporterSettings(missingID))
assert.EqualError(t, err, "exporter \"all/missing\" is not configured")
assert.Nil(t, le)

pe, err := bErr.CreateProfiles(context.Background(), createExporterSettings(missingID))
assert.EqualError(t, err, "exporter \"all/missing\" is not configured")
assert.Nil(t, pe)
}

func TestExporterBuilderFactory(t *testing.T) {
Expand Down Expand Up @@ -159,13 +175,19 @@ func TestNewNopExporterConfigsAndFactories(t *testing.T) {
bLogs, err := builder.CreateLogs(context.Background(), set)
require.NoError(t, err)
assert.IsType(t, logs, bLogs)

profiles, err := factory.CreateProfilesExporter(context.Background(), set, cfg)
require.NoError(t, err)
bProfiles, err := builder.CreateProfiles(context.Background(), set)
require.NoError(t, err)
assert.IsType(t, profiles, bProfiles)
}

var nopExporterInstance = &nopExporter{
Consumer: consumertest.NewNop(),
}

// nopExporter stores consumed traces and metrics for testing purposes.
// nopExporter stores consumed traces, metrics, logs and profiles for testing purposes.
type nopExporter struct {
component.StartFunc
component.ShutdownFunc
Expand All @@ -184,6 +206,10 @@ func createExporterLogs(context.Context, exporter.Settings, component.Config) (e
return nopExporterInstance, nil
}

func createExporterProfiles(context.Context, exporter.Settings, component.Config) (exporterprofiles.Profiles, error) {
return nopExporterInstance, nil
}

func createExporterSettings(id component.ID) exporter.Settings {
return exporter.Settings{
ID: id,
Expand Down

0 comments on commit c5dbf54

Please sign in to comment.