Skip to content

Commit

Permalink
[consumer] Add new consumererrorprofiles module (#11207)
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

Split off from #11131. Adds new module for consumer errors for profiles.

---------

Co-authored-by: Damien Mathieu <[email protected]>
  • Loading branch information
mx-psi and dmathieu authored Oct 9, 2024
1 parent 623986c commit 5ac1607
Show file tree
Hide file tree
Showing 10 changed files with 256 additions and 28 deletions.
25 changes: 25 additions & 0 deletions .chloggen/mx-psi_consumererrorprofiles.yaml
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: consumererrorprofiles

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add new module consumereerrorprofiles for consumer error profiles.

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

# (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]
1 change: 1 addition & 0 deletions consumer/consumererror/consumererrorprofiles/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../../Makefile.Common
36 changes: 36 additions & 0 deletions consumer/consumererror/consumererrorprofiles/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
module go.opentelemetry.io/collector/consumer/consumererror/consumererrorprofiles

go 1.22.0

require (
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/collector/consumer v0.109.0
go.opentelemetry.io/collector/pdata/pprofile v0.111.0
go.opentelemetry.io/collector/pdata/testdata v0.111.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.17.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/text v0.17.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect
google.golang.org/grpc v1.67.1 // indirect
google.golang.org/protobuf v1.35.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

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

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

replace go.opentelemetry.io/collector/pdata/testdata => ../../../pdata/testdata

replace go.opentelemetry.io/collector/pdata/pprofile => ../../../pdata/pprofile
77 changes: 77 additions & 0 deletions consumer/consumererror/consumererrorprofiles/go.sum

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

25 changes: 25 additions & 0 deletions consumer/consumererror/consumererrorprofiles/signalerrors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package consumererrorprofiles // import "go.opentelemetry.io/collector/consumer/consumererror/consumererrorprofiles"

import (
"go.opentelemetry.io/collector/consumer/consumererror/internal"
"go.opentelemetry.io/collector/pdata/pprofile"
)

// Profiles is an error that may carry associated Profile data for a subset of received data
// that failed to be processed or sent.
type Profiles struct {
internal.Retryable[pprofile.Profiles]
}

// NewProfiles creates a Profiles that can encapsulate received data that failed to be processed or sent.
func NewProfiles(err error, data pprofile.Profiles) error {
return Profiles{
Retryable: internal.Retryable[pprofile.Profiles]{
Err: err,
Value: data,
},
}
}
46 changes: 46 additions & 0 deletions consumer/consumererror/consumererrorprofiles/signalerrors_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package consumererrorprofiles // import "go.opentelemetry.io/collector/consumer/consumererror/consumererrorprofiles"

import (
"errors"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"go.opentelemetry.io/collector/pdata/testdata"
)

func TestProfiles(t *testing.T) {
td := testdata.GenerateProfiles(1)
err := errors.New("some error")
profileErr := NewProfiles(err, td)
assert.Equal(t, err.Error(), profileErr.Error())
var target Profiles
assert.False(t, errors.As(nil, &target))
assert.False(t, errors.As(err, &target))
require.ErrorAs(t, profileErr, &target)
assert.Equal(t, td, target.Data())
}

func TestProfiles_Unwrap(t *testing.T) {
td := testdata.GenerateProfiles(1)
var err error = testErrorType{"some error"}
// Wrapping err with error Profiles.
profileErr := NewProfiles(err, td)
target := testErrorType{}
require.NotEqual(t, err, target)
// Unwrapping profileErr for err and assigning to target.
require.ErrorAs(t, profileErr, &target)
require.Equal(t, err, target)
}

type testErrorType struct {
s string
}

func (t testErrorType) Error() string {
return ""
}
31 changes: 31 additions & 0 deletions consumer/consumererror/internal/retryable.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package internal // import "go.opentelemetry.io/collector/consumer/consumererror/internal"

import (
"go.opentelemetry.io/collector/pdata/plog"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/collector/pdata/pprofile"
"go.opentelemetry.io/collector/pdata/ptrace"
)

type Retryable[V ptrace.Traces | pmetric.Metrics | plog.Logs | pprofile.Profiles] struct {
Err error
Value V
}

// Error provides the error message
func (err Retryable[V]) Error() string {
return err.Err.Error()
}

// Unwrap returns the wrapped error for functions Is and As in standard package errors.
func (err Retryable[V]) Unwrap() error {
return err.Err
}

// Data returns the telemetry data that failed to be processed or sent.
func (err Retryable[V]) Data() V {
return err.Value
}
40 changes: 13 additions & 27 deletions consumer/consumererror/signalerrors.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,70 +4,56 @@
package consumererror // import "go.opentelemetry.io/collector/consumer/consumererror"

import (
"go.opentelemetry.io/collector/consumer/consumererror/internal"
"go.opentelemetry.io/collector/pdata/plog"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/collector/pdata/ptrace"
)

type retryable[V ptrace.Traces | pmetric.Metrics | plog.Logs] struct {
error
data V
}

// Unwrap returns the wrapped error for functions Is and As in standard package errors.
func (err retryable[V]) Unwrap() error {
return err.error
}

// Data returns the telemetry data that failed to be processed or sent.
func (err retryable[V]) Data() V {
return err.data
}

// Traces is an error that may carry associated Trace data for a subset of received data
// that failed to be processed or sent.
type Traces struct {
retryable[ptrace.Traces]
internal.Retryable[ptrace.Traces]
}

// NewTraces creates a Traces that can encapsulate received data that failed to be processed or sent.
func NewTraces(err error, data ptrace.Traces) error {
return Traces{
retryable: retryable[ptrace.Traces]{
error: err,
data: data,
Retryable: internal.Retryable[ptrace.Traces]{
Err: err,
Value: data,
},
}
}

// Logs is an error that may carry associated Log data for a subset of received data
// that failed to be processed or sent.
type Logs struct {
retryable[plog.Logs]
internal.Retryable[plog.Logs]
}

// NewLogs creates a Logs that can encapsulate received data that failed to be processed or sent.
func NewLogs(err error, data plog.Logs) error {
return Logs{
retryable: retryable[plog.Logs]{
error: err,
data: data,
Retryable: internal.Retryable[plog.Logs]{
Err: err,
Value: data,
},
}
}

// Metrics is an error that may carry associated Metrics data for a subset of received data
// that failed to be processed or sent.
type Metrics struct {
retryable[pmetric.Metrics]
internal.Retryable[pmetric.Metrics]
}

// NewMetrics creates a Metrics that can encapsulate received data that failed to be processed or sent.
func NewMetrics(err error, data pmetric.Metrics) error {
return Metrics{
retryable: retryable[pmetric.Metrics]{
error: err,
data: data,
Retryable: internal.Retryable[pmetric.Metrics]{
Err: err,
Value: data,
},
}
}
2 changes: 1 addition & 1 deletion consumer/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.22.0
require (
github.com/stretchr/testify v1.9.0
go.opentelemetry.io/collector/pdata v1.17.0
go.opentelemetry.io/collector/pdata/pprofile v0.111.0
go.opentelemetry.io/collector/pdata/testdata v0.111.0
go.uber.org/goleak v1.3.0
)
Expand All @@ -16,7 +17,6 @@ require (
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/pprofile v0.111.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/sys v0.24.0 // indirect
Expand Down
1 change: 1 addition & 0 deletions versions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ module-sets:
- go.opentelemetry.io/collector/connector/forwardconnector
- go.opentelemetry.io/collector/consumer
- go.opentelemetry.io/collector/consumer/consumerprofiles
- go.opentelemetry.io/collector/consumer/consumererror/consumererrorprofiles
- go.opentelemetry.io/collector/consumer/consumertest
- go.opentelemetry.io/collector/exporter
- go.opentelemetry.io/collector/exporter/debugexporter
Expand Down

0 comments on commit 5ac1607

Please sign in to comment.