-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add consumer profiles #10464
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
Merged
Merged
Add consumer profiles #10464
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0c3b24d
add consumer profiles
dmathieu c3a88fa
add changelog entry
dmathieu fe7cd2c
add doc strings
dmathieu 21912e4
make consumerprofiles its own module
dmathieu 6c33da6
fix changelog
dmathieu 3a0b45c
fix gotidy
dmathieu 0c6d994
run make crosslink
dmathieu 53a1927
Merge branch 'main' into profiles-consumer
dmathieu 30cb26f
run gotidy
dmathieu 09e9221
Update consumer/consumerprofiles/go.mod
dmathieu 18fbb65
Merge branch 'main' into profiles-consumer
dmathieu 6bc3a17
run gotidy
dmathieu cd3ef63
Merge branch 'main' into profiles-consumer
dmathieu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Use this changelog template to create an entry for release notes. | ||
|
||
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
change_type: new_component | ||
|
||
# The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) | ||
component: consumer/consumerprofiles | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: Allow handling profiles in consumer. | ||
|
||
# One or more tracking issues or pull requests related to the change | ||
issues: [10464] | ||
|
||
# (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: | ||
|
||
# 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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include ../../Makefile.Common |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module go.opentelemetry.io/collector/consumer/consumerprofiles | ||
|
||
go 1.21.0 | ||
|
||
replace go.opentelemetry.io/collector/pdata => ../../pdata | ||
|
||
replace go.opentelemetry.io/collector/pdata/pprofile => ../../pdata/pprofile | ||
|
||
replace go.opentelemetry.io/collector/consumer => ../ | ||
|
||
require ( | ||
github.com/stretchr/testify v1.9.0 | ||
go.opentelemetry.io/collector/consumer v0.104.0 | ||
go.opentelemetry.io/collector/pdata/pprofile v0.104.0 | ||
) | ||
|
||
require ( | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/gogo/protobuf v1.3.2 // indirect | ||
github.com/json-iterator/go v1.1.12 // indirect | ||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | ||
github.com/modern-go/reflect2 v1.0.2 // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
go.opentelemetry.io/collector/pdata v1.11.0 // indirect | ||
go.uber.org/multierr v1.11.0 // indirect | ||
golang.org/x/net v0.25.0 // indirect | ||
golang.org/x/sys v0.20.0 // indirect | ||
golang.org/x/text v0.15.0 // indirect | ||
google.golang.org/genproto/googleapis/rpc v0.0.0-20240528184218-531527333157 // indirect | ||
google.golang.org/grpc v1.65.0 // indirect | ||
google.golang.org/protobuf v1.34.2 // indirect | ||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||
) | ||
|
||
replace go.opentelemetry.io/collector/pdata/testdata => ../../pdata/testdata |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package consumerprofiles // import "go.opentelemetry.io/collector/consumer/consumerprofiles" | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
"go.opentelemetry.io/collector/consumer" | ||
"go.opentelemetry.io/collector/consumer/internal" | ||
"go.opentelemetry.io/collector/pdata/pprofile" | ||
) | ||
|
||
var errNilFunc = errors.New("nil consumer func") | ||
|
||
// Profiles is an interface that receives pprofile.Profiles, processes it | ||
// as needed, and sends it to the next processing node if any or to the destination. | ||
type Profiles interface { | ||
internal.BaseConsumer | ||
// ConsumeProfiles receives pprofile.Profiles for consumption. | ||
ConsumeProfiles(ctx context.Context, td pprofile.Profiles) error | ||
} | ||
|
||
// ConsumeProfilesFunc is a helper function that is similar to ConsumeProfiles. | ||
type ConsumeProfilesFunc func(ctx context.Context, td pprofile.Profiles) error | ||
|
||
// ConsumeProfiles calls f(ctx, td). | ||
func (f ConsumeProfilesFunc) ConsumeProfiles(ctx context.Context, td pprofile.Profiles) error { | ||
return f(ctx, td) | ||
} | ||
|
||
type baseProfiles struct { | ||
*internal.BaseImpl | ||
ConsumeProfilesFunc | ||
} | ||
|
||
// NewProfiles returns a Profiles configured with the provided options. | ||
func NewProfiles(consume ConsumeProfilesFunc, options ...consumer.Option) (Profiles, error) { | ||
if consume == nil { | ||
return nil, errNilFunc | ||
} | ||
return &baseProfiles{ | ||
BaseImpl: internal.NewBaseImpl(options...), | ||
ConsumeProfilesFunc: consume, | ||
}, nil | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package consumerprofiles | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"go.opentelemetry.io/collector/consumer" | ||
"go.opentelemetry.io/collector/pdata/pprofile" | ||
) | ||
|
||
func TestDefaultProfiles(t *testing.T) { | ||
cp, err := NewProfiles(func(context.Context, pprofile.Profiles) error { return nil }) | ||
assert.NoError(t, err) | ||
assert.NoError(t, cp.ConsumeProfiles(context.Background(), pprofile.NewProfiles())) | ||
assert.Equal(t, consumer.Capabilities{MutatesData: false}, cp.Capabilities()) | ||
} | ||
|
||
func TestNilFuncProfiles(t *testing.T) { | ||
_, err := NewProfiles(nil) | ||
assert.Equal(t, errNilFunc, err) | ||
} | ||
|
||
func TestWithCapabilitiesProfiles(t *testing.T) { | ||
cp, err := NewProfiles( | ||
func(context.Context, pprofile.Profiles) error { return nil }, | ||
consumer.WithCapabilities(consumer.Capabilities{MutatesData: true})) | ||
assert.NoError(t, err) | ||
assert.NoError(t, cp.ConsumeProfiles(context.Background(), pprofile.NewProfiles())) | ||
assert.Equal(t, consumer.Capabilities{MutatesData: true}, cp.Capabilities()) | ||
} | ||
|
||
func TestConsumeProfiles(t *testing.T) { | ||
consumeCalled := false | ||
cp, err := NewProfiles(func(context.Context, pprofile.Profiles) error { consumeCalled = true; return nil }) | ||
assert.NoError(t, err) | ||
assert.NoError(t, cp.ConsumeProfiles(context.Background(), pprofile.NewProfiles())) | ||
assert.True(t, consumeCalled) | ||
} | ||
|
||
func TestConsumeProfiles_ReturnError(t *testing.T) { | ||
want := errors.New("my_error") | ||
cp, err := NewProfiles(func(context.Context, pprofile.Profiles) error { return want }) | ||
assert.NoError(t, err) | ||
assert.Equal(t, want, cp.ConsumeProfiles(context.Background(), pprofile.NewProfiles())) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package internal // import "go.opentelemetry.io/collector/consumer/internal" | ||
|
||
// Capabilities describes the capabilities of a Processor. | ||
type Capabilities struct { | ||
// MutatesData is set to true if Consume* function of the | ||
// processor modifies the input Traces, Logs or Metrics argument. | ||
// Processors which modify the input data MUST set this flag to true. If the processor | ||
// does not modify the data it MUST set this flag to false. If the processor creates | ||
// a copy of the data before modifying then this flag can be safely set to false. | ||
MutatesData bool | ||
} | ||
|
||
type BaseConsumer interface { | ||
Capabilities() Capabilities | ||
} | ||
|
||
type BaseImpl struct { | ||
Cap Capabilities | ||
} | ||
|
||
// Option to construct new consumers. | ||
type Option func(*BaseImpl) | ||
|
||
// Capabilities returns the capabilities of the component | ||
func (bs BaseImpl) Capabilities() Capabilities { | ||
return bs.Cap | ||
} | ||
|
||
func NewBaseImpl(options ...Option) *BaseImpl { | ||
bs := &BaseImpl{ | ||
Cap: Capabilities{MutatesData: false}, | ||
} | ||
|
||
for _, op := range options { | ||
op(bs) | ||
} | ||
|
||
return bs | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.