forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tidy up
consumer/consumererror
package. (#2768)
* Tidy up `consumer/consumererror` package. * Updated docblocks for grammar and consistency * Added `IsPartial()` predicate to match `IsPermanent()` * Ensured tests for `PartialError` test the public interface Remove `PartialError` and replace with individual signal error types Refactor consumererror signal extraction to simplify exporterhelper request interface * Rename consumererror signal error types to align with rest of codebase * Rename `onPartialError` to `onError` in `exporterhelper.request` interface * Provide conversion methods to consumererror signal error types. This moves the accessors for signal data to methods on the individual error types and provides As<Signal>() package functions that behave as targeted versions of the errors.As() function. * Avoid unnecessary allocation, fixup docs
- Loading branch information
Showing
33 changed files
with
216 additions
and
144 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 was deleted.
Oops, something went wrong.
This file contains 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
File renamed without changes.
This file contains 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,108 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package consumererror | ||
|
||
import ( | ||
"errors" | ||
|
||
"go.opentelemetry.io/collector/consumer/pdata" | ||
) | ||
|
||
// Traces is an error that may carry associated Trace data for a subset of received data | ||
// that faiiled to be processed or sent. | ||
type Traces struct { | ||
error | ||
failed pdata.Traces | ||
} | ||
|
||
// NewTraces creates a Traces that can encapsulate received data that failed to be processed or sent. | ||
func NewTraces(err error, failed pdata.Traces) error { | ||
return Traces{ | ||
error: err, | ||
failed: failed, | ||
} | ||
} | ||
|
||
// AsTraces finds the first error in err's chain that can be assigned to target. If such an error is found | ||
// it is assigned to target and true is returned, otherwise false is returned. | ||
func AsTraces(err error, target *Traces) bool { | ||
if err == nil { | ||
return false | ||
} | ||
return errors.As(err, target) | ||
} | ||
|
||
// GetTraces returns failed traces from the associated error. | ||
func (err Traces) GetTraces() pdata.Traces { | ||
return err.failed | ||
} | ||
|
||
// Logs is an error that may carry associated Log data for a subset of received data | ||
// that faiiled to be processed or sent. | ||
type Logs struct { | ||
error | ||
failed pdata.Logs | ||
} | ||
|
||
// NewLogs creates a Logs that can encapsulate received data that failed to be processed or sent. | ||
func NewLogs(err error, failed pdata.Logs) error { | ||
return Logs{ | ||
error: err, | ||
failed: failed, | ||
} | ||
} | ||
|
||
// AsLogs finds the first error in err's chain that can be assigned to target. If such an error is found | ||
// it is assigned to target and true is returned, otherwise false is returned. | ||
func AsLogs(err error, target *Logs) bool { | ||
if err == nil { | ||
return false | ||
} | ||
return errors.As(err, target) | ||
} | ||
|
||
// GetLogs returns failed logs from the associated error. | ||
func (err Logs) GetLogs() pdata.Logs { | ||
return err.failed | ||
} | ||
|
||
// Metrics is an error that may carry associated Metrics data for a subset of received data | ||
// that faiiled to be processed or sent. | ||
type Metrics struct { | ||
error | ||
failed pdata.Metrics | ||
} | ||
|
||
// NewMetrics creates a Metrics that can encapsulate received data that failed to be processed or sent. | ||
func NewMetrics(err error, failed pdata.Metrics) error { | ||
return Metrics{ | ||
error: err, | ||
failed: failed, | ||
} | ||
} | ||
|
||
// AsMetrics finds the first error in err's chain that can be assigned to target. If such an error is found | ||
// it is assigned to target and true is returned, otherwise false is returned. | ||
func AsMetrics(err error, target *Metrics) bool { | ||
if err == nil { | ||
return false | ||
} | ||
return errors.As(err, target) | ||
} | ||
|
||
// GetMetrics returns failed metrics from the associated error. | ||
func (err Metrics) GetMetrics() pdata.Metrics { | ||
return err.failed | ||
} |
This file contains 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 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 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 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.