-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[xconsumererror]: Add Partial error type #14152
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
Open
braydonk
wants to merge
16
commits into
open-telemetry:main
Choose a base branch
from
braydonk:partial_error
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+208
−0
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
404b14c
consumererror: Add partial error type
braydonk 69e2696
add licenses
braydonk fbbad1d
move PartialError to xconsumererror
braydonk 933c0ea
add testable examples and more detailed godoc
braydonk 60ca1e8
run make gotidy
braydonk d16fe30
add changelog
braydonk d2c3541
make gogenerate
braydonk 2f5dd28
change AsPartial to IsPartial
braydonk fada42c
fix test example
braydonk aa68b13
add xconsumererror to chloggen config
braydonk 11944cf
add unwrap case for coverage
braydonk b4eb6f7
linter doesn't like assert :(
braydonk 933353a
add metadata yaml to xconsumererror
braydonk 8ff8914
also generate chloggen components
braydonk 4edad6b
rename metadata component type
braydonk baf19df
return to state before adding metadata yaml since I opened a separate PR
braydonk 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: enhancement | ||
|
|
||
| # The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) | ||
| component: consumer/consumererror/xconsumererror | ||
|
|
||
| # A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
| note: Add new Partial error, allowing consumers to express a permanent error with a failed item count. | ||
|
|
||
| # One or more tracking issues or pull requests related to the change | ||
| issues: [13423] | ||
|
|
||
| # (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
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
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
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,56 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package xconsumererror // import "go.opentelemetry.io/collector/consumer/consumererror/xconsumererror" | ||
|
|
||
| import ( | ||
| "errors" | ||
|
|
||
| "go.opentelemetry.io/collector/consumer/consumererror" | ||
| ) | ||
|
|
||
| type partialError struct { | ||
| inner error | ||
| failed int | ||
| } | ||
|
|
||
| var _ error = partialError{} | ||
|
|
||
| func (pe partialError) Error() string { | ||
| return pe.inner.Error() | ||
| } | ||
|
|
||
| func (pe partialError) Unwrap() error { | ||
| return pe.inner | ||
| } | ||
|
|
||
| // NewPartial creates a new partial error. This is used to report errors | ||
| // where only a subset of the total items failed to be written, but it | ||
| // is not possible to tell which particular items failed. An example of this | ||
| // would be a backend that can report partial successes, but only communicate | ||
| // the number of failed items without specifying which specific items failed. | ||
| // | ||
| // A partial error wraps a PermanentError; it can be treated as any other permanent | ||
| // error with no changes, meaning that consumers can transition to producing this | ||
| // error when appropriate without breaking any parts of the pipeline that check for | ||
| // permanent errors. | ||
| // | ||
| // In a scenario where the exact items that failed are known and can be retried, | ||
| // it's recommended to use the respective signal error ([consumererror.Logs], | ||
| // [consumererror.Metrics], or [consumererror.Traces]). | ||
| func NewPartial(err error, failed int) error { | ||
| return consumererror.NewPermanent(partialError{ | ||
| inner: err, | ||
| failed: failed, | ||
| }) | ||
| } | ||
|
|
||
| // IsPartial checks if an error was wrapped with the NewPartial function, | ||
| // or if it contains one such error in its Unwrap() tree. The results are | ||
| // the count of failed items if the error is a partial error, and a boolean | ||
| // result of whether the error was a partial or not. | ||
| func IsPartial(err error) (int, bool) { | ||
| var pe partialError | ||
| ok := errors.As(err, &pe) | ||
| return pe.failed, ok | ||
| } | ||
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,65 @@ | ||
| // Copyright The OpenTelemetry Authors | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package xconsumererror_test | ||
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
|
|
||
| "go.opentelemetry.io/collector/consumer/consumererror" | ||
| "go.opentelemetry.io/collector/consumer/consumererror/xconsumererror" | ||
| ) | ||
|
|
||
| func TestPartial(t *testing.T) { | ||
| internalErr := errors.New("some points failed") | ||
| err := xconsumererror.NewPartial(internalErr, 5) | ||
| // The partial error must be wrapped and be able to be | ||
| // treated as a plain permanent error. | ||
| require.True(t, consumererror.IsPermanent(err)) | ||
| // The error should be unwrappable to verify the internal | ||
| // error if necessary. | ||
| require.ErrorIs(t, err, internalErr) | ||
| // It must be possible to retrieve the failed items from | ||
| // the partial error. | ||
| failed, ok := xconsumererror.IsPartial(err) | ||
| require.True(t, ok) | ||
| require.Equal(t, 5, failed) | ||
| } | ||
|
|
||
| func ExampleNewPartial() { | ||
| // Produce a partial error. | ||
| failedItems := 5 | ||
| consumptionErr := errors.New("some points failed to be written") | ||
| err := xconsumererror.NewPartial(consumptionErr, failedItems) | ||
| fmt.Println(err) | ||
|
|
||
| // Output: Permanent error: some points failed to be written | ||
| } | ||
|
|
||
| func ExampleIsPartial() { | ||
| // Produce a partial error. | ||
| partialErr := xconsumererror.NewPartial(errors.New("some points failed to be written"), 10) | ||
|
|
||
| // IsPartial will return the failed item count, and a boolean | ||
| // to indicate whether it is a partial error or not. | ||
| if count, ok := xconsumererror.IsPartial(partialErr); ok { | ||
| fmt.Println(count) | ||
| } | ||
|
|
||
| // Output: 10 | ||
| } | ||
|
|
||
| func ExampleIsPartial_second() { | ||
| // Produce a partial error. | ||
| partialErr := xconsumererror.NewPartial(errors.New("some points failed to be written"), 10) | ||
|
|
||
| // Partial errors wrap a Permanent error, so it can simply be treated | ||
| // as one if the number of failed items isn't important. | ||
| fmt.Println(consumererror.IsPermanent(partialErr)) | ||
|
|
||
| // Output: true | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you say there are circumstances where an OTLP receiver can reply with a partial success in response to a partial error from the pipeline? I would expect that, at least in cases where there is no batch processor, no queue or wait_for_result: true, etc.