Skip to content

Commit

Permalink
[chore] [clickhouseexporter] use errors.Join instead of go.uber.org/m…
Browse files Browse the repository at this point in the history
…ultierr (#25183)

Part of:
#25121
  • Loading branch information
shivanshuraj1333 authored Aug 14, 2023
1 parent 3b1ab22 commit 977eae4
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 16 deletions.
7 changes: 3 additions & 4 deletions exporter/clickhouseexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/ClickHouse/clickhouse-go/v2"
"go.opentelemetry.io/collector/config/configopaque"
"go.opentelemetry.io/collector/exporter/exporterhelper"
"go.uber.org/multierr"
)

// Config defines configuration for Elastic exporter.
Expand Down Expand Up @@ -59,17 +58,17 @@ var (
// Validate the clickhouse server configuration.
func (cfg *Config) Validate() (err error) {
if cfg.Endpoint == "" {
err = multierr.Append(err, errConfigNoEndpoint)
err = errors.Join(err, errConfigNoEndpoint)
}
dsn, e := cfg.buildDSN(cfg.Database)
if e != nil {
err = multierr.Append(err, e)
err = errors.Join(err, e)
}

// Validate DSN with clickhouse driver.
// Last chance to catch invalid config.
if _, e := clickhouse.ParseDSN(dsn); e != nil {
err = multierr.Append(err, e)
err = errors.Join(err, e)
}

return err
Expand Down
5 changes: 2 additions & 3 deletions exporter/clickhouseexporter/exporter_logs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/plog"
conventions "go.opentelemetry.io/collector/semconv/v1.18.0"
"go.uber.org/multierr"
"go.uber.org/zap"
"go.uber.org/zap/zaptest"
)
Expand Down Expand Up @@ -61,10 +60,10 @@ func TestLogsExporter_New(t *testing.T) {

var err error
exporter, err := newLogsExporter(zap.NewNop(), test.config)
err = multierr.Append(err, err)
err = errors.Join(err, err)

if exporter != nil {
err = multierr.Append(err, exporter.start(context.TODO(), nil))
err = errors.Join(err, exporter.start(context.TODO(), nil))
defer func() {
require.NoError(t, exporter.shutdown(context.TODO()))
}()
Expand Down
12 changes: 6 additions & 6 deletions exporter/clickhouseexporter/exporter_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ package clickhouseexporter // import "github.com/open-telemetry/opentelemetry-co
import (
"context"
"database/sql"
"errors"
"fmt"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.uber.org/multierr"
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/exporter/clickhouseexporter/internal"
Expand Down Expand Up @@ -68,15 +68,15 @@ func (e *metricsExporter) pushMetricsData(ctx context.Context, md pmetric.Metric
//exhaustive:enforce
switch r.Type() {
case pmetric.MetricTypeGauge:
errs = multierr.Append(errs, metricsMap[pmetric.MetricTypeGauge].Add(resAttr, metrics.SchemaUrl(), scopeInstr, scopeURL, r.Gauge(), r.Name(), r.Description(), r.Unit()))
errs = errors.Join(errs, metricsMap[pmetric.MetricTypeGauge].Add(resAttr, metrics.SchemaUrl(), scopeInstr, scopeURL, r.Gauge(), r.Name(), r.Description(), r.Unit()))
case pmetric.MetricTypeSum:
errs = multierr.Append(errs, metricsMap[pmetric.MetricTypeSum].Add(resAttr, metrics.SchemaUrl(), scopeInstr, scopeURL, r.Sum(), r.Name(), r.Description(), r.Unit()))
errs = errors.Join(errs, metricsMap[pmetric.MetricTypeSum].Add(resAttr, metrics.SchemaUrl(), scopeInstr, scopeURL, r.Sum(), r.Name(), r.Description(), r.Unit()))
case pmetric.MetricTypeHistogram:
errs = multierr.Append(errs, metricsMap[pmetric.MetricTypeHistogram].Add(resAttr, metrics.SchemaUrl(), scopeInstr, scopeURL, r.Histogram(), r.Name(), r.Description(), r.Unit()))
errs = errors.Join(errs, metricsMap[pmetric.MetricTypeHistogram].Add(resAttr, metrics.SchemaUrl(), scopeInstr, scopeURL, r.Histogram(), r.Name(), r.Description(), r.Unit()))
case pmetric.MetricTypeExponentialHistogram:
errs = multierr.Append(errs, metricsMap[pmetric.MetricTypeExponentialHistogram].Add(resAttr, metrics.SchemaUrl(), scopeInstr, scopeURL, r.ExponentialHistogram(), r.Name(), r.Description(), r.Unit()))
errs = errors.Join(errs, metricsMap[pmetric.MetricTypeExponentialHistogram].Add(resAttr, metrics.SchemaUrl(), scopeInstr, scopeURL, r.ExponentialHistogram(), r.Name(), r.Description(), r.Unit()))
case pmetric.MetricTypeSummary:
errs = multierr.Append(errs, metricsMap[pmetric.MetricTypeSummary].Add(resAttr, metrics.SchemaUrl(), scopeInstr, scopeURL, r.Summary(), r.Name(), r.Description(), r.Unit()))
errs = errors.Join(errs, metricsMap[pmetric.MetricTypeSummary].Add(resAttr, metrics.SchemaUrl(), scopeInstr, scopeURL, r.Summary(), r.Name(), r.Description(), r.Unit()))
case pmetric.MetricTypeEmpty:
return fmt.Errorf("metrics type is unset")
default:
Expand Down
2 changes: 1 addition & 1 deletion exporter/clickhouseexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ require (
go.opentelemetry.io/collector/exporter v0.82.0
go.opentelemetry.io/collector/pdata v1.0.0-rcv0014
go.opentelemetry.io/collector/semconv v0.82.0
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.25.0
)

Expand Down Expand Up @@ -53,6 +52,7 @@ require (
go.opentelemetry.io/otel v1.16.0 // indirect
go.opentelemetry.io/otel/metric v1.16.0 // indirect
go.opentelemetry.io/otel/trace v1.16.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/net v0.14.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/text v0.12.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions exporter/clickhouseexporter/internal/metrics_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import (
"context"
"database/sql"
"encoding/hex"
"errors"
"fmt"
"strings"
"sync"

"github.com/ClickHouse/clickhouse-go/v2"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.uber.org/multierr"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -101,7 +101,7 @@ func InsertMetrics(ctx context.Context, db *sql.DB, metricsMap map[pmetric.Metri
close(errsChan)
var errs error
for err := range errsChan {
errs = multierr.Append(errs, err)
errs = errors.Join(errs, err)
}
return errs
}
Expand Down

0 comments on commit 977eae4

Please sign in to comment.