Skip to content

Commit 5cc0707

Browse files
authored
Move CombineErrors to consumererror package (#2442)
Signed-off-by: Bogdan Drutu <[email protected]>
1 parent 9de6dd7 commit 5cc0707

File tree

18 files changed

+89
-70
lines changed

18 files changed

+89
-70
lines changed

component/componenterror/errors.go

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ package componenterror
1818

1919
import (
2020
"errors"
21-
"fmt"
22-
"strings"
2321

2422
"go.opentelemetry.io/collector/consumer/consumererror"
2523
)
@@ -36,28 +34,7 @@ var (
3634
)
3735

3836
// CombineErrors converts a list of errors into one error.
37+
// Deprecated: use consumererror.CombineErrors instead.
3938
func CombineErrors(errs []error) error {
40-
numErrors := len(errs)
41-
if numErrors == 0 {
42-
// No errors
43-
return nil
44-
}
45-
46-
if numErrors == 1 {
47-
return errs[0]
48-
}
49-
50-
errMsgs := make([]string, 0, numErrors)
51-
permanent := false
52-
for _, err := range errs {
53-
if !permanent && consumererror.IsPermanent(err) {
54-
permanent = true
55-
}
56-
errMsgs = append(errMsgs, err.Error())
57-
}
58-
err := fmt.Errorf("[%s]", strings.Join(errMsgs, "; "))
59-
if permanent {
60-
err = consumererror.Permanent(err)
61-
}
62-
return err
39+
return consumererror.CombineErrors(errs)
6340
}

config/configcheck/configcheck.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"strings"
2626

2727
"go.opentelemetry.io/collector/component"
28-
"go.opentelemetry.io/collector/component/componenterror"
28+
"go.opentelemetry.io/collector/consumer/consumererror"
2929
)
3030

3131
// The regular expression for valid config field tag.
@@ -56,7 +56,7 @@ func ValidateConfigFromFactories(factories component.Factories) error {
5656
}
5757
}
5858

59-
return componenterror.CombineErrors(errs)
59+
return consumererror.CombineErrors(errs)
6060
}
6161

6262
// ValidateConfig enforces that given configuration object is following the patterns
@@ -109,7 +109,7 @@ func validateConfigDataType(t reflect.Type) error {
109109
// reflect.UnsafePointer.
110110
}
111111

112-
if err := componenterror.CombineErrors(errs); err != nil {
112+
if err := consumererror.CombineErrors(errs); err != nil {
113113
return fmt.Errorf(
114114
"type %q from package %q has invalid config settings: %v",
115115
t.Name(),
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright The OpenTelemetry Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package consumererror
16+
17+
import (
18+
"fmt"
19+
"strings"
20+
)
21+
22+
// CombineErrors converts a list of errors into one error.
23+
func CombineErrors(errs []error) error {
24+
numErrors := len(errs)
25+
if numErrors == 0 {
26+
// No errors
27+
return nil
28+
}
29+
30+
if numErrors == 1 {
31+
return errs[0]
32+
}
33+
34+
errMsgs := make([]string, 0, numErrors)
35+
permanent := false
36+
for _, err := range errs {
37+
if !permanent && IsPermanent(err) {
38+
permanent = true
39+
}
40+
errMsgs = append(errMsgs, err.Error())
41+
}
42+
err := fmt.Errorf("[%s]", strings.Join(errMsgs, "; "))
43+
if permanent {
44+
err = Permanent(err)
45+
}
46+
return err
47+
}

component/componenterror/errors_test.go renamed to consumer/consumererror/combineerrors_test.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,11 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
package componenterror_test
15+
package consumererror
1616

1717
import (
1818
"fmt"
1919
"testing"
20-
21-
"go.opentelemetry.io/collector/component/componenterror"
22-
"go.opentelemetry.io/collector/consumer/consumererror"
2320
)
2421

2522
func TestCombineErrors(t *testing.T) {
@@ -50,20 +47,20 @@ func TestCombineErrors(t *testing.T) {
5047
errors: []error{
5148
fmt.Errorf("foo"),
5249
fmt.Errorf("bar"),
53-
consumererror.Permanent(fmt.Errorf("permanent"))},
50+
Permanent(fmt.Errorf("permanent"))},
5451
expected: "Permanent error: [foo; bar; Permanent error: permanent]",
5552
},
5653
}
5754

5855
for _, tc := range testCases {
59-
got := componenterror.CombineErrors(tc.errors)
56+
got := CombineErrors(tc.errors)
6057
if (got == nil) != tc.expectNil {
6158
t.Errorf("CombineErrors(%v) == nil? Got: %t. Want: %t", tc.errors, got == nil, tc.expectNil)
6259
}
6360
if got != nil && tc.expected != got.Error() {
6461
t.Errorf("CombineErrors(%v) = %q. Want: %q", tc.errors, got, tc.expected)
6562
}
66-
if tc.expectedPermanent && !consumererror.IsPermanent(got) {
63+
if tc.expectedPermanent && !IsPermanent(got) {
6764
t.Errorf("CombineErrors(%v) = %q. Want: consumererror.permanent", tc.errors, got)
6865
}
6966
}

exporter/kafkaexporter/jaeger_marshaller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"github.com/gogo/protobuf/jsonpb"
2121
jaegerproto "github.com/jaegertracing/jaeger/model"
2222

23-
"go.opentelemetry.io/collector/component/componenterror"
23+
"go.opentelemetry.io/collector/consumer/consumererror"
2424
"go.opentelemetry.io/collector/consumer/pdata"
2525
jaegertranslator "go.opentelemetry.io/collector/translator/trace/jaeger"
2626
)
@@ -50,7 +50,7 @@ func (j jaegerMarshaller) Marshal(traces pdata.Traces) ([]Message, error) {
5050
messages = append(messages, Message{Value: bts})
5151
}
5252
}
53-
return messages, componenterror.CombineErrors(errs)
53+
return messages, consumererror.CombineErrors(errs)
5454
}
5555

5656
func (j jaegerMarshaller) Encoding() string {

exporter/prometheusremotewriteexporter/exporter.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import (
3131
"github.com/golang/snappy"
3232
"github.com/prometheus/prometheus/prompb"
3333

34-
"go.opentelemetry.io/collector/component/componenterror"
3534
"go.opentelemetry.io/collector/consumer/consumererror"
3635
"go.opentelemetry.io/collector/consumer/pdata"
3736
otlp "go.opentelemetry.io/collector/internal/data/protogen/metrics/v1"
@@ -155,7 +154,7 @@ func (prwe *PrwExporter) PushMetrics(ctx context.Context, md pdata.Metrics) (int
155154
}
156155

157156
if dropped != 0 {
158-
return dropped, componenterror.CombineErrors(errs)
157+
return dropped, consumererror.CombineErrors(errs)
159158
}
160159

161160
return 0, nil

processor/cloningfanoutconnector.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ package processor
1717
import (
1818
"context"
1919

20-
"go.opentelemetry.io/collector/component/componenterror"
2120
"go.opentelemetry.io/collector/consumer"
21+
"go.opentelemetry.io/collector/consumer/consumererror"
2222
"go.opentelemetry.io/collector/consumer/pdata"
2323
)
2424

@@ -61,7 +61,7 @@ func (mfc metricsCloningFanOutConnector) ConsumeMetrics(ctx context.Context, md
6161
}
6262
}
6363

64-
return componenterror.CombineErrors(errs)
64+
return consumererror.CombineErrors(errs)
6565
}
6666

6767
// NewTracesCloningFanOutConnector wraps multiple traces consumers in a single one and clones the data
@@ -98,7 +98,7 @@ func (tfc tracesCloningFanOutConnector) ConsumeTraces(ctx context.Context, td pd
9898
}
9999
}
100100

101-
return componenterror.CombineErrors(errs)
101+
return consumererror.CombineErrors(errs)
102102
}
103103

104104
// NewLogsCloningFanOutConnector wraps multiple trace consumers in a single one.
@@ -134,5 +134,5 @@ func (lfc logsCloningFanOutConnector) ConsumeLogs(ctx context.Context, ld pdata.
134134
}
135135
}
136136

137-
return componenterror.CombineErrors(errs)
137+
return consumererror.CombineErrors(errs)
138138
}

processor/fanoutconnector.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ package processor
1717
import (
1818
"context"
1919

20-
"go.opentelemetry.io/collector/component/componenterror"
2120
"go.opentelemetry.io/collector/consumer"
21+
"go.opentelemetry.io/collector/consumer/consumererror"
2222
"go.opentelemetry.io/collector/consumer/pdata"
2323
)
2424

@@ -46,7 +46,7 @@ func (mfc metricsFanOutConnector) ConsumeMetrics(ctx context.Context, md pdata.M
4646
errs = append(errs, err)
4747
}
4848
}
49-
return componenterror.CombineErrors(errs)
49+
return consumererror.CombineErrors(errs)
5050
}
5151

5252
// NewTracesFanOutConnector wraps multiple trace consumers in a single one.
@@ -70,7 +70,7 @@ func (tfc traceFanOutConnector) ConsumeTraces(ctx context.Context, td pdata.Trac
7070
errs = append(errs, err)
7171
}
7272
}
73-
return componenterror.CombineErrors(errs)
73+
return consumererror.CombineErrors(errs)
7474
}
7575

7676
// NewLogsFanOutConnector wraps multiple log consumers in a single one.
@@ -94,5 +94,5 @@ func (fc logsFanOutConnector) ConsumeLogs(ctx context.Context, ld pdata.Logs) er
9494
errs = append(errs, err)
9595
}
9696
}
97-
return componenterror.CombineErrors(errs)
97+
return consumererror.CombineErrors(errs)
9898
}

receiver/jaegerreceiver/trace_receiver.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import (
4949
"go.opentelemetry.io/collector/component/componenterror"
5050
"go.opentelemetry.io/collector/config/configgrpc"
5151
"go.opentelemetry.io/collector/consumer"
52+
"go.opentelemetry.io/collector/consumer/consumererror"
5253
"go.opentelemetry.io/collector/obsreport"
5354
jaegertranslator "go.opentelemetry.io/collector/translator/trace/jaeger"
5455
)
@@ -233,7 +234,7 @@ func (jr *jReceiver) Shutdown(context.Context) error {
233234
jr.grpc.Stop()
234235
jr.grpc = nil
235236
}
236-
err = componenterror.CombineErrors(errs)
237+
err = consumererror.CombineErrors(errs)
237238
})
238239

239240
return err

receiver/scraperhelper/errors.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"fmt"
2020
"strings"
2121

22-
"go.opentelemetry.io/collector/component/componenterror"
2322
"go.opentelemetry.io/collector/consumer/consumererror"
2423
)
2524

@@ -35,7 +34,7 @@ func CombineScrapeErrors(errs []error) error {
3534
}
3635

3736
if !partialScrapeErr {
38-
return componenterror.CombineErrors(errs)
37+
return consumererror.CombineErrors(errs)
3938
}
4039

4140
errMsgs := make([]string, 0, len(errs))

0 commit comments

Comments
 (0)