Skip to content

Commit

Permalink
[processor/routing] Do not err on failure to build exporters (open-te…
Browse files Browse the repository at this point in the history
…lemetry#7423)

* [processor/routing] Do not err on failure to build exporters

When registering the exporters, it is possible that an error is returned when the default exporter isn't found, which is the case when the processor is specified only for one pipeline type for multiple exists.

Given that we can't check in which pipelines the processor is active, we can't do much more than just ignore a possible configuration error.

Fixes open-telemetry#6920

Signed-off-by: Juraci Paixão Kröhling <juraci@kroehling.de>
  • Loading branch information
jpkrohling authored Feb 8, 2022
1 parent a386213 commit 60b1180
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
- `mysqlreceiver`: Add golden files for integration test (#7303)
- `nginxreceiver`: Standardize integration test (#7515)
- `mysqlreceiver`: Update to use mdatagen v2 (#7507)
- `routingprocessor`: Do not err on failure to build exporters (#7423)
- `postgresqlreceiver`: Add integration tests (#7501)
- `apachereceiver`: Add integration test (#7517)
- `mysqlreceiver`: Use scrapererror to report errors (#7513)
Expand Down
1 change: 1 addition & 0 deletions processor/routingprocessor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var (
errNoExporters = errors.New("no exporters defined for the route")
errNoTableItems = errors.New("the routing table is empty")
errNoMissingFromAttribute = errors.New("the FromAttribute property is empty")
errDefaultExporterNotFound = errors.New("default exporter not found")
errExporterNotFound = errors.New("exporter not found")
errNoExportersAfterRegistration = errors.New("provided configuration resulted in no exporter available to accept data")
)
Expand Down
4 changes: 2 additions & 2 deletions processor/routingprocessor/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func TestTraces_ErrorRequestedExporterNotFoundForRoute(t *testing.T) {
assert.Truef(t, errors.Is(err, errNoExportersAfterRegistration), "got: %v", err)
}

func TestTraces_ErrorRequestedExporterNotFoundForDefaultRoute(t *testing.T) {
func TestTraces_RequestedExporterNotFoundForDefaultRoute(t *testing.T) {
// prepare
exp := newProcessor(zap.NewNop(), &Config{
DefaultExporters: []string{"non-existing"},
Expand Down Expand Up @@ -133,7 +133,7 @@ func TestTraces_ErrorRequestedExporterNotFoundForDefaultRoute(t *testing.T) {
err = exp.Start(context.Background(), host)

// verify
assert.True(t, errors.Is(err, errExporterNotFound))
assert.True(t, errors.Is(err, errNoExportersAfterRegistration))
}

func TestTraces_InvalidExporter(t *testing.T) {
Expand Down
39 changes: 30 additions & 9 deletions processor/routingprocessor/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ package routingprocessor // import "github.com/open-telemetry/opentelemetry-coll

import (
"context"
"errors"
"fmt"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/model/pdata"
"go.uber.org/multierr"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -316,13 +316,34 @@ func (r *router) routeLogsForContext(ctx context.Context, tl pdata.Logs) routedL
// registerExporters registers the exporters as per the configured routing table
// taking into account the provided map of available exporters.
func (r *router) registerExporters(hostExporters map[config.DataType]map[config.ComponentID]component.Exporter) error {
err := multierr.Combine(
r.registerTracesExporters(hostExporters[config.TracesDataType]),
r.registerMetricsExporters(hostExporters[config.MetricsDataType]),
r.registerLogsExporters(hostExporters[config.LogsDataType]),
)
if err != nil {
return err
for _, reg := range []struct {
registerFunc func(map[config.ComponentID]component.Exporter) error
typ config.Type
}{
{
r.registerTracesExporters,
config.TracesDataType,
},
{
r.registerMetricsExporters,
config.MetricsDataType,
},
{
r.registerLogsExporters,
config.LogsDataType,
},
} {
if err := reg.registerFunc(hostExporters[reg.typ]); err != nil {
if errors.Is(err, errDefaultExporterNotFound) {
r.logger.Warn("can't find the default exporter for the routing processor for this pipeline type. This is OK if you did not specify this processor for that pipeline type",
zap.Any("pipeline_type", reg.typ),
zap.Error(err),
)
} else {
// this seems to be more serious than what expected
return err
}
}
}

if len(r.defaultLogsExporters) == 0 &&
Expand Down Expand Up @@ -418,7 +439,7 @@ func (r *router) registerExportersForDefaultRoute(available ExporterMap) error {
v, ok := available[exp]
if !ok {
return fmt.Errorf("error registering default exporter %q: %w",
exp, errExporterNotFound,
exp, errDefaultExporterNotFound,
)
}

Expand Down

0 comments on commit 60b1180

Please sign in to comment.