Skip to content

Commit

Permalink
Deprecate exporterhelperprofiles module in favor of xexporterhelper (#…
Browse files Browse the repository at this point in the history
…11890)

to allow adding more experimental data types.

Updates
#11778
  • Loading branch information
dmitryax authored Dec 14, 2024
1 parent c6c249d commit 97f6c3a
Show file tree
Hide file tree
Showing 24 changed files with 765 additions and 225 deletions.
20 changes: 20 additions & 0 deletions .chloggen/deprecate-exporterhelperprofiles.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Use this changelog template to create an entry for release notes.

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

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

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Deprecate exporterhelperprofiles module in favor of xexporterhelper to allow adding more experimental data types.

# One or more tracking issues or pull requests related to the change
issues: [11778]

# 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: [api]
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ consumer/consumerprofiles @open-telemetry/collector-approve
consumer/xconsumer @open-telemetry/collector-approvers @mx-psi @dmathieu
connector/connectorprofiles @open-telemetry/collector-approvers @mx-psi @dmathieu
exporter/exporterhelper/exporterhelperprofiles @open-telemetry/collector-approvers @mx-psi @dmathieu
exporter/exporterhelper/xexporterhelper @open-telemetry/collector-approvers @mx-psi @dmathieu
exporter/exporterprofiles @open-telemetry/collector-approvers @mx-psi @dmathieu
exporter/xexporter @open-telemetry/collector-approvers @mx-psi @dmathieu
processor/processorprofiles @open-telemetry/collector-approvers @mx-psi @dmathieu
Expand Down
2 changes: 1 addition & 1 deletion cmd/builder/internal/builder/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ var replaceModules = []string{
"/exporter/debugexporter",
"/exporter/xexporter",
"/exporter/exportertest",
"/exporter/exporterhelper/exporterhelperprofiles",
"/exporter/exporterhelper/xexporterhelper",
"/exporter/nopexporter",
"/exporter/otlpexporter",
"/exporter/otlphttpexporter",
Expand Down
2 changes: 1 addition & 1 deletion cmd/otelcorecol/builder-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ replaces:
- go.opentelemetry.io/collector/exporter/debugexporter => ../../exporter/debugexporter
- go.opentelemetry.io/collector/exporter/exportertest => ../../exporter/exportertest
- go.opentelemetry.io/collector/exporter/xexporter => ../../exporter/xexporter
- go.opentelemetry.io/collector/exporter/exporterhelper/exporterhelperprofiles => ../../exporter/exporterhelper/exporterhelperprofiles
- go.opentelemetry.io/collector/exporter/exporterhelper/xexporterhelper => ../../exporter/exporterhelper/xexporterhelper
- go.opentelemetry.io/collector/exporter/nopexporter => ../../exporter/nopexporter
- go.opentelemetry.io/collector/exporter/otlpexporter => ../../exporter/otlpexporter
- go.opentelemetry.io/collector/exporter/otlphttpexporter => ../../exporter/otlphttpexporter
Expand Down
6 changes: 3 additions & 3 deletions cmd/otelcorecol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ require (
go.opentelemetry.io/collector/connector/connectortest v0.115.0 // indirect
go.opentelemetry.io/collector/consumer v1.21.0 // indirect
go.opentelemetry.io/collector/consumer/consumererror v0.115.0 // indirect
go.opentelemetry.io/collector/consumer/consumererror/xconsumererror v0.115.0 // indirect
go.opentelemetry.io/collector/consumer/consumererror/xconsumererror v0.0.0-00010101000000-000000000000 // indirect
go.opentelemetry.io/collector/consumer/consumertest v0.115.0 // indirect
go.opentelemetry.io/collector/consumer/xconsumer v0.115.1-0.20241213185000-4593ba7de234 // indirect
go.opentelemetry.io/collector/exporter/exporterhelper/exporterhelperprofiles v0.115.0 // indirect
go.opentelemetry.io/collector/exporter/exporterhelper/xexporterhelper v0.115.0 // indirect
go.opentelemetry.io/collector/exporter/exportertest v0.115.0 // indirect
go.opentelemetry.io/collector/exporter/xexporter v0.115.0 // indirect
go.opentelemetry.io/collector/extension/auth v0.115.0 // indirect
Expand Down Expand Up @@ -227,7 +227,7 @@ replace go.opentelemetry.io/collector/exporter/exportertest => ../../exporter/ex

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

replace go.opentelemetry.io/collector/exporter/exporterhelper/exporterhelperprofiles => ../../exporter/exporterhelper/exporterhelperprofiles
replace go.opentelemetry.io/collector/exporter/exporterhelper/xexporterhelper => ../../exporter/exporterhelper/xexporterhelper

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

Expand Down
4 changes: 2 additions & 2 deletions exporter/debugexporter/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"go.opentelemetry.io/collector/exporter/debugexporter/internal/metadata"
"go.opentelemetry.io/collector/exporter/debugexporter/internal/otlptext"
"go.opentelemetry.io/collector/exporter/exporterhelper"
"go.opentelemetry.io/collector/exporter/exporterhelper/exporterhelperprofiles"
"go.opentelemetry.io/collector/exporter/exporterhelper/xexporterhelper"
"go.opentelemetry.io/collector/exporter/xexporter"
)

Expand Down Expand Up @@ -90,7 +90,7 @@ func createProfiles(ctx context.Context, set exporter.Settings, config component
cfg := config.(*Config)
exporterLogger := createLogger(cfg, set.TelemetrySettings.Logger)
debug := newDebugExporter(exporterLogger, cfg.Verbosity)
return exporterhelperprofiles.NewProfilesExporter(ctx, set, config,
return xexporterhelper.NewProfilesExporter(ctx, set, config,
debug.pushProfiles,
exporterhelper.WithCapabilities(consumer.Capabilities{MutatesData: false}),
exporterhelper.WithTimeout(exporterhelper.TimeoutConfig{Timeout: 0}),
Expand Down
6 changes: 3 additions & 3 deletions exporter/debugexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
go.opentelemetry.io/collector/confmap v1.21.0
go.opentelemetry.io/collector/consumer v1.21.0
go.opentelemetry.io/collector/exporter v0.115.0
go.opentelemetry.io/collector/exporter/exporterhelper/exporterhelperprofiles v0.115.0
go.opentelemetry.io/collector/exporter/exporterhelper/xexporterhelper v0.115.0
go.opentelemetry.io/collector/exporter/exportertest v0.115.0
go.opentelemetry.io/collector/exporter/xexporter v0.115.0
go.opentelemetry.io/collector/pdata v1.21.0
Expand Down Expand Up @@ -41,7 +41,7 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
go.opentelemetry.io/collector/config/configretry v1.21.0 // indirect
go.opentelemetry.io/collector/consumer/consumererror v0.115.0 // indirect
go.opentelemetry.io/collector/consumer/consumererror/xconsumererror v0.115.0 // indirect
go.opentelemetry.io/collector/consumer/consumererror/xconsumererror v0.0.0-00010101000000-000000000000 // indirect
go.opentelemetry.io/collector/consumer/consumertest v0.115.0 // indirect
go.opentelemetry.io/collector/consumer/xconsumer v0.115.1-0.20241213185000-4593ba7de234 // indirect
go.opentelemetry.io/collector/extension v0.115.0 // indirect
Expand Down Expand Up @@ -104,7 +104,7 @@ replace go.opentelemetry.io/collector/receiver/xreceiver => ../../receiver/xrece

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

replace go.opentelemetry.io/collector/exporter/exporterhelper/exporterhelperprofiles => ../exporterhelper/exporterhelperprofiles
replace go.opentelemetry.io/collector/exporter/exporterhelper/xexporterhelper => ../exporterhelper/xexporterhelper

replace go.opentelemetry.io/collector/pipeline => ../../pipeline

Expand Down
9 changes: 6 additions & 3 deletions exporter/exporterhelper/exporterhelperprofiles/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,17 @@ require (
go.opentelemetry.io/collector/config/configretry v1.21.0
go.opentelemetry.io/collector/consumer v1.21.0
go.opentelemetry.io/collector/consumer/consumererror v0.115.0
go.opentelemetry.io/collector/consumer/consumererror/xconsumererror v0.115.0
go.opentelemetry.io/collector/consumer/consumertest v0.115.0
go.opentelemetry.io/collector/consumer/xconsumer v0.115.1-0.20241213185000-4593ba7de234
go.opentelemetry.io/collector/exporter v0.115.0
go.opentelemetry.io/collector/exporter/exporterhelper/xexporterhelper v0.0.0-00010101000000-000000000000
go.opentelemetry.io/collector/exporter/exportertest v0.115.0
go.opentelemetry.io/collector/exporter/xexporter v0.115.0
go.opentelemetry.io/collector/pdata/pprofile v0.115.0
go.opentelemetry.io/collector/pdata/testdata v0.115.0
go.opentelemetry.io/collector/pipeline/xpipeline v0.115.0
go.opentelemetry.io/otel v1.32.0
go.opentelemetry.io/otel/sdk v1.32.0
go.opentelemetry.io/otel/trace v1.32.0
go.uber.org/zap v1.27.0
)

require (
Expand All @@ -37,17 +35,20 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.115.0 // indirect
go.opentelemetry.io/collector/consumer/consumererror/xconsumererror v0.0.0-00010101000000-000000000000 // indirect
go.opentelemetry.io/collector/extension v0.115.0 // indirect
go.opentelemetry.io/collector/extension/experimental/storage v0.115.0 // indirect
go.opentelemetry.io/collector/featuregate v1.21.0 // indirect
go.opentelemetry.io/collector/pdata v1.21.0 // indirect
go.opentelemetry.io/collector/pipeline v0.115.0 // indirect
go.opentelemetry.io/collector/pipeline/xpipeline v0.115.0 // indirect
go.opentelemetry.io/collector/receiver v0.115.0 // indirect
go.opentelemetry.io/collector/receiver/receivertest v0.115.0 // indirect
go.opentelemetry.io/collector/receiver/xreceiver v0.115.0 // indirect
go.opentelemetry.io/otel/metric v1.32.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.32.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/text v0.18.0 // indirect
Expand Down Expand Up @@ -99,6 +100,8 @@ replace go.opentelemetry.io/collector/pipeline => ../../../pipeline

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

replace go.opentelemetry.io/collector/exporter/exporterhelper/xexporterhelper => ../xexporterhelper

replace go.opentelemetry.io/collector/consumer/consumererror => ../../../consumer/consumererror

replace go.opentelemetry.io/collector/extension/extensiontest => ../../../extension/extensiontest
Expand Down
161 changes: 8 additions & 153 deletions exporter/exporterhelper/exporterhelperprofiles/profiles.go
Original file line number Diff line number Diff line change
@@ -1,164 +1,19 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

// Deprecated: [0.116.0] Use go.opentelemetry.io/collector/exporter/exporterhelper/xexporterhelper instead.
package exporterhelperprofiles // import "go.opentelemetry.io/collector/exporter/exporterhelper/exporterhelperprofiles"

import (
"context"
"errors"

"go.uber.org/zap"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer/consumererror"
"go.opentelemetry.io/collector/consumer/consumererror/xconsumererror"
"go.opentelemetry.io/collector/consumer/xconsumer"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/exporter/exporterhelper"
"go.opentelemetry.io/collector/exporter/exporterhelper/internal"
"go.opentelemetry.io/collector/exporter/exporterqueue"
"go.opentelemetry.io/collector/exporter/xexporter"
"go.opentelemetry.io/collector/pdata/pprofile"
"go.opentelemetry.io/collector/pipeline/xpipeline"
)

var (
profilesMarshaler = &pprofile.ProtoMarshaler{}
profilesUnmarshaler = &pprofile.ProtoUnmarshaler{}
)

type profilesRequest struct {
pd pprofile.Profiles
pusher xconsumer.ConsumeProfilesFunc
}

func newProfilesRequest(pd pprofile.Profiles, pusher xconsumer.ConsumeProfilesFunc) exporterhelper.Request {
return &profilesRequest{
pd: pd,
pusher: pusher,
}
}

func newProfileRequestUnmarshalerFunc(pusher xconsumer.ConsumeProfilesFunc) exporterqueue.Unmarshaler[exporterhelper.Request] {
return func(bytes []byte) (exporterhelper.Request, error) {
profiles, err := profilesUnmarshaler.UnmarshalProfiles(bytes)
if err != nil {
return nil, err
}
return newProfilesRequest(profiles, pusher), nil
}
}

func profilesRequestMarshaler(req exporterhelper.Request) ([]byte, error) {
return profilesMarshaler.MarshalProfiles(req.(*profilesRequest).pd)
}

func (req *profilesRequest) OnError(err error) exporterhelper.Request {
var profileError xconsumererror.Profiles
if errors.As(err, &profileError) {
return newProfilesRequest(profileError.Data(), req.pusher)
}
return req
}

func (req *profilesRequest) Export(ctx context.Context) error {
return req.pusher(ctx, req.pd)
}

func (req *profilesRequest) ItemsCount() int {
return req.pd.SampleCount()
}

type profileExporter struct {
*internal.BaseExporter
xconsumer.Profiles
}
import "go.opentelemetry.io/collector/exporter/exporterhelper/xexporterhelper"

// NewProfilesExporter creates an xexporter.Profiles that records observability metrics and wraps every request with a Span.
func NewProfilesExporter(
ctx context.Context,
set exporter.Settings,
cfg component.Config,
pusher xconsumer.ConsumeProfilesFunc,
options ...exporterhelper.Option,
) (xexporter.Profiles, error) {
if cfg == nil {
return nil, errNilConfig
}
if pusher == nil {
return nil, errNilPushProfileData
}
profilesOpts := []exporterhelper.Option{
internal.WithMarshaler(profilesRequestMarshaler), internal.WithUnmarshaler(newProfileRequestUnmarshalerFunc(pusher)),
}
return NewProfilesRequestExporter(ctx, set, requestFromProfiles(pusher), append(profilesOpts, options...)...)
}
// Deprecated: [0.116.0] Use xexporterhelper.NewProfilesExporter instead.
var NewProfilesExporter = xexporterhelper.NewProfilesExporter

// RequestFromProfilesFunc converts pprofile.Profiles into a user-defined Request.
// Experimental: This API is at the early stage of development and may change without backward compatibility
// until https://github.com/open-telemetry/opentelemetry-collector/issues/8122 is resolved.
type RequestFromProfilesFunc func(context.Context, pprofile.Profiles) (exporterhelper.Request, error)

// requestFromProfiles returns a RequestFromProfilesFunc that converts pprofile.Profiles into a Request.
func requestFromProfiles(pusher xconsumer.ConsumeProfilesFunc) RequestFromProfilesFunc {
return func(_ context.Context, profiles pprofile.Profiles) (exporterhelper.Request, error) {
return newProfilesRequest(profiles, pusher), nil
}
}
// Deprecated: [0.116.0] Use xexporterhelper.RequestFromProfilesFunc instead.
type RequestFromProfilesFunc = xexporterhelper.RequestFromProfilesFunc

// NewProfilesRequestExporter creates a new profiles exporter based on a custom ProfilesConverter and RequestSender.
// Experimental: This API is at the early stage of development and may change without backward compatibility
// until https://github.com/open-telemetry/opentelemetry-collector/issues/8122 is resolved.
func NewProfilesRequestExporter(
_ context.Context,
set exporter.Settings,
converter RequestFromProfilesFunc,
options ...exporterhelper.Option,
) (xexporter.Profiles, error) {
if set.Logger == nil {
return nil, errNilLogger
}

if converter == nil {
return nil, errNilProfilesConverter
}

be, err := internal.NewBaseExporter(set, xpipeline.SignalProfiles, newProfilesExporterWithObservability, options...)
if err != nil {
return nil, err
}

tc, err := xconsumer.NewProfiles(func(ctx context.Context, pd pprofile.Profiles) error {
req, cErr := converter(ctx, pd)
if cErr != nil {
set.Logger.Error("Failed to convert profiles. Dropping data.",
zap.Int("dropped_samples", pd.SampleCount()),
zap.Error(err))
return consumererror.NewPermanent(cErr)
}
return be.Send(ctx, req)
}, be.ConsumerOptions...)

return &profileExporter{
BaseExporter: be,
Profiles: tc,
}, err
}

type profilesExporterWithObservability struct {
internal.BaseRequestSender
obsrep *internal.ObsReport
}

func newProfilesExporterWithObservability(obsrep *internal.ObsReport) internal.RequestSender {
return &profilesExporterWithObservability{obsrep: obsrep}
}

func (tewo *profilesExporterWithObservability) Send(ctx context.Context, req exporterhelper.Request) error {
c := tewo.obsrep.StartProfilesOp(ctx)
numSamples := req.ItemsCount()
// Forward the data to the next consumer (this pusher is the next).
err := tewo.NextSender.Send(c, req)
tewo.obsrep.EndProfilesOp(c, numSamples, err)
return err
}
// Deprecated: [0.116.0] Use xexporterhelper.NewProfilesRequestExporter instead.
var NewProfilesRequestExporter = xexporterhelper.NewProfilesRequestExporter
43 changes: 0 additions & 43 deletions exporter/exporterhelper/exporterhelperprofiles/profiles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ import (
"go.opentelemetry.io/collector/config/configretry"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/consumer/consumererror"
"go.opentelemetry.io/collector/consumer/consumererror/xconsumererror"
"go.opentelemetry.io/collector/consumer/consumertest"
"go.opentelemetry.io/collector/consumer/xconsumer"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/exporter/exporterhelper"
"go.opentelemetry.io/collector/exporter/exporterhelper/internal"
"go.opentelemetry.io/collector/exporter/exportertest"
Expand All @@ -42,47 +40,6 @@ const (

var fakeProfilesExporterConfig = struct{}{}

func TestProfilesRequest(t *testing.T) {
lr := newProfilesRequest(testdata.GenerateProfiles(1), nil)

profileErr := xconsumererror.NewProfiles(errors.New("some error"), pprofile.NewProfiles())
assert.EqualValues(
t,
newProfilesRequest(pprofile.NewProfiles(), nil),
lr.(exporterhelper.RequestErrorHandler).OnError(profileErr),
)
}

func TestProfilesExporter_InvalidName(t *testing.T) {
le, err := NewProfilesExporter(context.Background(), exportertest.NewNopSettings(), nil, newPushProfilesData(nil))
require.Nil(t, le)
require.Equal(t, errNilConfig, err)
}

func TestProfilesExporter_NilLogger(t *testing.T) {
le, err := NewProfilesExporter(context.Background(), exporter.Settings{}, &fakeProfilesExporterConfig, newPushProfilesData(nil))
require.Nil(t, le)
require.Equal(t, errNilLogger, err)
}

func TestProfilesRequestExporter_NilLogger(t *testing.T) {
le, err := NewProfilesRequestExporter(context.Background(), exporter.Settings{}, internal.RequestFromProfilesFunc(nil))
require.Nil(t, le)
require.Equal(t, errNilLogger, err)
}

func TestProfilesExporter_NilPushProfilesData(t *testing.T) {
le, err := NewProfilesExporter(context.Background(), exportertest.NewNopSettings(), &fakeProfilesExporterConfig, nil)
require.Nil(t, le)
require.Equal(t, errNilPushProfileData, err)
}

func TestProfilesRequestExporter_NilProfilesConverter(t *testing.T) {
le, err := NewProfilesRequestExporter(context.Background(), exportertest.NewNopSettings(), nil)
require.Nil(t, le)
require.Equal(t, errNilProfilesConverter, err)
}

func TestProfilesExporter_Default(t *testing.T) {
ld := pprofile.NewProfiles()
le, err := NewProfilesExporter(context.Background(), exportertest.NewNopSettings(), &fakeProfilesExporterConfig, newPushProfilesData(nil))
Expand Down
1 change: 1 addition & 0 deletions exporter/exporterhelper/xexporterhelper/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../../Makefile.Common
Loading

0 comments on commit 97f6c3a

Please sign in to comment.