Skip to content

Commit

Permalink
[chore][exporter/datadogexporter] use errors.Join instead of go.uber.…
Browse files Browse the repository at this point in the history
…org/multierr (open-telemetry#27888)

**Description:** 
use errors.Join instead of go.uber.org/multierr

**Link to tracking Issue:** <Issue number if applicable>
open-telemetry#25121 

**Testing:** <Describe what testing was performed and which tests were
added.>

**Documentation:** <Describe the documentation added.>
  • Loading branch information
bagmeg authored Oct 23, 2023
1 parent 43e259f commit e027722
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
9 changes: 5 additions & 4 deletions exporter/datadogexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"go.opentelemetry.io/collector/config/configopaque"
"go.opentelemetry.io/collector/confmap"
"go.opentelemetry.io/collector/exporter/exporterhelper"
"go.uber.org/multierr"
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter/internal/hostmetadata/valid"
Expand Down Expand Up @@ -517,13 +516,15 @@ func (e renameError) Error() string {
)
}

func handleRemovedSettings(configMap *confmap.Conf) (err error) {
func handleRemovedSettings(configMap *confmap.Conf) error {
var errs []error
for _, removedErr := range removedSettings {
if configMap.IsSet(removedErr.oldName) {
err = multierr.Append(err, removedErr)
errs = append(errs, removedErr)
}
}
return

return errors.Join(errs...)
}

var _ confmap.Unmarshaler = (*Config)(nil)
Expand Down
7 changes: 5 additions & 2 deletions exporter/datadogexporter/config_warnings.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
package datadogexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/datadogexporter"

import (
"errors"
"fmt"

"go.opentelemetry.io/collector/confmap"
"go.uber.org/multierr"
)

var _ error = (*deprecatedError)(nil)
Expand Down Expand Up @@ -60,15 +60,18 @@ func (e deprecatedError) UpdateCfg(cfg *Config) {
// handleRenamedSettings for a given configuration map.
// Error out if any pair of old-new options are set at the same time.
func handleRenamedSettings(configMap *confmap.Conf, cfg *Config) (warnings []error, err error) {
var errs []error
for _, renaming := range renamedSettings {
isOldNameUsed, errCheck := renaming.Check(configMap)
err = multierr.Append(err, errCheck)
errs = append(errs, errCheck)

if errCheck == nil && isOldNameUsed {
warnings = append(warnings, renaming)
// only update config if old name is in use
renaming.UpdateCfg(cfg)
}
}
err = errors.Join(errs...)

return
}
2 changes: 1 addition & 1 deletion exporter/datadogexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ require (
go.opentelemetry.io/collector/receiver v0.87.1-0.20231017160804-ec0725874313
go.opentelemetry.io/collector/receiver/otlpreceiver v0.87.1-0.20231017160804-ec0725874313
go.opentelemetry.io/collector/semconv v0.87.1-0.20231017160804-ec0725874313
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.26.0
google.golang.org/protobuf v1.31.0
gopkg.in/yaml.v2 v2.4.0
Expand Down Expand Up @@ -206,6 +205,7 @@ require (
go.opentelemetry.io/otel/trace v1.19.0 // indirect
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
go.uber.org/atomic v1.11.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/exp v0.0.0-20230711023510-fffb14384f22 // indirect
golang.org/x/mod v0.13.0 // indirect
golang.org/x/net v0.17.0 // indirect
Expand Down
13 changes: 6 additions & 7 deletions exporter/datadogexporter/metrics_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package datadogexporter // import "github.com/open-telemetry/opentelemetry-colle
import (
"bytes"
"context"
"errors"
"fmt"
"net/http"
"sync"
Expand All @@ -20,7 +21,6 @@ import (
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.uber.org/multierr"
"go.uber.org/zap"
zorkian "gopkg.in/zorkian/go-datadog-api.v2"

Expand Down Expand Up @@ -220,29 +220,28 @@ func (exp *metricsExporter) PushMetricsData(ctx context.Context, md pmetric.Metr

var sl sketches.SketchSeriesList
var sp []*pb.ClientStatsPayload
var errs []error
if isMetricExportV2Enabled() {
var ms []datadogV2.MetricSeries
ms, sl, sp = consumer.(*metrics.Consumer).All(exp.getPushTime(), exp.params.BuildInfo, tags, metadata)
err = nil
if len(ms) > 0 {
exp.params.Logger.Debug("exporting native Datadog payload", zap.Any("metric", ms))
_, experr := exp.retrier.DoWithRetries(ctx, func(context.Context) error {
ctx = clientutil.GetRequestContext(ctx, string(exp.cfg.API.Key))
_, httpresp, merr := exp.metricsAPI.SubmitMetrics(ctx, datadogV2.MetricPayload{Series: ms}, *clientutil.GZipSubmitMetricsOptionalParameters)
return clientutil.WrapError(merr, httpresp)
})
err = multierr.Append(err, experr)
errs = append(errs, experr)
}
} else {
var ms []zorkian.Metric
ms, sl, sp = consumer.(*metrics.ZorkianConsumer).All(exp.getPushTime(), exp.params.BuildInfo, tags)
err = nil
if len(ms) > 0 {
exp.params.Logger.Debug("exporting Zorkian Datadog payload", zap.Any("metric", ms))
_, experr := exp.retrier.DoWithRetries(ctx, func(context.Context) error {
return exp.client.PostMetrics(ms)
})
err = multierr.Append(err, experr)
errs = append(errs, experr)
}
}

Expand All @@ -251,7 +250,7 @@ func (exp *metricsExporter) PushMetricsData(ctx context.Context, md pmetric.Metr
_, experr := exp.retrier.DoWithRetries(ctx, func(ctx context.Context) error {
return exp.pushSketches(ctx, sl)
})
err = multierr.Append(err, experr)
errs = append(errs, experr)
}

if len(sp) > 0 {
Expand All @@ -262,5 +261,5 @@ func (exp *metricsExporter) PushMetricsData(ctx context.Context, md pmetric.Metr
}
}

return err
return errors.Join(errs...)
}

0 comments on commit e027722

Please sign in to comment.