Skip to content

Commit

Permalink
[chore]: enable all rules of perfsprint
Browse files Browse the repository at this point in the history
Signed-off-by: Matthieu MOREL <[email protected]>
  • Loading branch information
mmorel-35 committed Nov 14, 2024
1 parent 61e9b35 commit c382578
Show file tree
Hide file tree
Showing 19 changed files with 53 additions and 46 deletions.
8 changes: 4 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ linters-settings:
ignore-words:
- cancelled
perfsprint:
err-error: false
errorf: false
err-error: true
errorf: true
int-conversion: true
sprintf1: false
strconcat: false
sprintf1: true
strconcat: true
revive:
# Sets the default failure confidence.
# This means that linting errors with less than 0.8 confidence will be ignored.
Expand Down
2 changes: 1 addition & 1 deletion bridge/opencensus/internal/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,5 @@ func (s *Span) AddLink(l octrace.Link) {

// String prints a string representation of this span.
func (s *Span) String() string {
return fmt.Sprintf("span %s", s.otelSpan.SpanContext().SpanID().String())
return "span " + s.otelSpan.SpanContext().SpanID().String()
}
3 changes: 2 additions & 1 deletion codes/codes.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package codes // import "go.opentelemetry.io/otel/codes"

import (
"encoding/json"
"errors"
"fmt"
"strconv"
)
Expand Down Expand Up @@ -63,7 +64,7 @@ func (c *Code) UnmarshalJSON(b []byte) error {
return nil
}
if c == nil {
return fmt.Errorf("nil receiver passed to UnmarshalJSON")
return errors.New("nil receiver passed to UnmarshalJSON")
}

var x interface{}
Expand Down
3 changes: 2 additions & 1 deletion exporters/otlp/otlpmetric/otlpmetricgrpc/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package otlpmetricgrpc // import "go.opentelemetry.io/otel/exporters/otlp/otlpme

import (
"context"
"errors"
"fmt"
"sync"

Expand Down Expand Up @@ -114,7 +115,7 @@ func (e *Exporter) Shutdown(ctx context.Context) error {
return err
}

var errShutdown = fmt.Errorf("gRPC exporter is shutdown")
var errShutdown = errors.New("gRPC exporter is shutdown")

type shutdownClient struct{}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func cleanPath(urlPath string, defaultPath string) string {
return defaultPath
}
if !path.IsAbs(tmp) {
tmp = fmt.Sprintf("/%s", tmp)
tmp = "/" + tmp
}
return tmp
}
Expand Down
2 changes: 1 addition & 1 deletion exporters/otlp/otlpmetric/otlpmetrichttp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ func newResponseError(header http.Header, wrapped error) error {

func (e retryableError) Error() string {
if e.err != nil {
return fmt.Sprintf("retry-able request failure: %s", e.err.Error())
return "retry-able request failure: " + e.err.Error()
}

return "retry-able request failure"
Expand Down
3 changes: 2 additions & 1 deletion exporters/otlp/otlpmetric/otlpmetrichttp/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package otlpmetrichttp // import "go.opentelemetry.io/otel/exporters/otlp/otlpme

import (
"context"
"errors"
"fmt"
"sync"

Expand Down Expand Up @@ -114,7 +115,7 @@ func (e *Exporter) Shutdown(ctx context.Context) error {
return err
}

var errShutdown = fmt.Errorf("HTTP exporter is shutdown")
var errShutdown = errors.New("HTTP exporter is shutdown")

type shutdownClient struct{}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func cleanPath(urlPath string, defaultPath string) string {
return defaultPath
}
if !path.IsAbs(tmp) {
tmp = fmt.Sprintf("/%s", tmp)
tmp = "/" + tmp
}
return tmp
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func cleanPath(urlPath string, defaultPath string) string {
return defaultPath
}
if !path.IsAbs(tmp) {
tmp = fmt.Sprintf("/%s", tmp)
tmp = "/" + tmp
}
return tmp
}
Expand Down
2 changes: 1 addition & 1 deletion exporters/otlp/otlptrace/otlptracehttp/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func newResponseError(header http.Header, wrapped error) error {

func (e retryableError) Error() string {
if e.err != nil {
return fmt.Sprintf("retry-able request failure: %s", e.err.Error())
return "retry-able request failure: " + e.err.Error()
}

return "retry-able request failure"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func cleanPath(urlPath string, defaultPath string) string {
return defaultPath
}
if !path.IsAbs(tmp) {
tmp = fmt.Sprintf("/%s", tmp)
tmp = "/" + tmp
}
return tmp
}
Expand Down
5 changes: 3 additions & 2 deletions sdk/metric/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ package metric // import "go.opentelemetry.io/otel/sdk/metric"

import (
"context"
"fmt"

"errors"

"go.opentelemetry.io/otel/sdk/metric/metricdata"
)

// ErrExporterShutdown is returned if Export or Shutdown are called after an
// Exporter has been Shutdown.
var ErrExporterShutdown = fmt.Errorf("exporter is shutdown")
var ErrExporterShutdown = errors.New("exporter is shutdown")

// Exporter handles the delivery of metric data to external receivers. This is
// the final component in the metric push pipeline.
Expand Down
2 changes: 1 addition & 1 deletion sdk/metric/meter.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ func (m *meter) RegisterCallback(f metric.Callback, insts ...metric.Observable)
validInstruments = append(validInstruments, inst)
default:
// Instrument external to the SDK.
return nil, fmt.Errorf("invalid observable: from different implementation")
return nil, errors.New("invalid observable: from different implementation")
}
}

Expand Down
22 changes: 11 additions & 11 deletions sdk/metric/metricdata/metricdatatest/comparisons.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func equalResourceMetrics(a, b metricdata.ResourceMetrics, cfg config) (reasons
},
))
if r != "" {
reasons = append(reasons, fmt.Sprintf("ResourceMetrics ScopeMetrics not equal:\n%s", r))
reasons = append(reasons, "ResourceMetrics ScopeMetrics not equal:\n"+r)
}
return reasons
}
Expand All @@ -56,7 +56,7 @@ func equalScopeMetrics(a, b metricdata.ScopeMetrics, cfg config) (reasons []stri
},
))
if r != "" {
reasons = append(reasons, fmt.Sprintf("ScopeMetrics Metrics not equal:\n%s", r))
reasons = append(reasons, "ScopeMetrics Metrics not equal:\n"+r)
}
return reasons
}
Expand Down Expand Up @@ -172,7 +172,7 @@ func equalGauges[N int64 | float64](a, b metricdata.Gauge[N], cfg config) (reaso
},
))
if r != "" {
reasons = append(reasons, fmt.Sprintf("Gauge DataPoints not equal:\n%s", r))
reasons = append(reasons, "Gauge DataPoints not equal:\n"+r)
}
return reasons
}
Expand All @@ -199,7 +199,7 @@ func equalSums[N int64 | float64](a, b metricdata.Sum[N], cfg config) (reasons [
},
))
if r != "" {
reasons = append(reasons, fmt.Sprintf("Sum DataPoints not equal:\n%s", r))
reasons = append(reasons, "Sum DataPoints not equal:\n"+r)
}
return reasons
}
Expand All @@ -223,7 +223,7 @@ func equalHistograms[N int64 | float64](a, b metricdata.Histogram[N], cfg config
},
))
if r != "" {
reasons = append(reasons, fmt.Sprintf("Histogram DataPoints not equal:\n%s", r))
reasons = append(reasons, "Histogram DataPoints not equal:\n"+r)
}
return reasons
}
Expand Down Expand Up @@ -264,7 +264,7 @@ func equalDataPoints[N int64 | float64](a, b metricdata.DataPoint[N], cfg config
},
))
if r != "" {
reasons = append(reasons, fmt.Sprintf("Exemplars not equal:\n%s", r))
reasons = append(reasons, "Exemplars not equal:\n"+r)
}
}
return reasons
Expand Down Expand Up @@ -318,7 +318,7 @@ func equalHistogramDataPoints[N int64 | float64](a, b metricdata.HistogramDataPo
},
))
if r != "" {
reasons = append(reasons, fmt.Sprintf("Exemplars not equal:\n%s", r))
reasons = append(reasons, "Exemplars not equal:\n"+r)
}
}
return reasons
Expand All @@ -343,7 +343,7 @@ func equalExponentialHistograms[N int64 | float64](a, b metricdata.ExponentialHi
},
))
if r != "" {
reasons = append(reasons, fmt.Sprintf("Histogram DataPoints not equal:\n%s", r))
reasons = append(reasons, "Histogram DataPoints not equal:\n"+r)
}
return reasons
}
Expand Down Expand Up @@ -406,7 +406,7 @@ func equalExponentialHistogramDataPoints[N int64 | float64](a, b metricdata.Expo
},
))
if r != "" {
reasons = append(reasons, fmt.Sprintf("Exemplars not equal:\n%s", r))
reasons = append(reasons, "Exemplars not equal:\n"+r)
}
}
return reasons
Expand All @@ -432,7 +432,7 @@ func equalSummary(a, b metricdata.Summary, cfg config) (reasons []string) {
},
))
if r != "" {
reasons = append(reasons, fmt.Sprintf("Summary DataPoints not equal:\n%s", r))
reasons = append(reasons, "Summary DataPoints not equal:\n"+r)
}
return reasons
}
Expand Down Expand Up @@ -634,7 +634,7 @@ func compareDiff[T any](extraExpected, extraActual []T) string {
}

func missingAttrStr(name string) string {
return fmt.Sprintf("missing attribute %s", name)
return "missing attribute " + name
}

func hasAttributesExemplars[T int64 | float64](exemplar metricdata.Exemplar[T], attrs ...attribute.KeyValue) (reasons []string) {
Expand Down
11 changes: 6 additions & 5 deletions sdk/metric/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,27 @@ package metric // import "go.opentelemetry.io/otel/sdk/metric"

import (
"context"
"fmt"

"errors"

"go.opentelemetry.io/otel/sdk/metric/metricdata"
)

// errDuplicateRegister is logged by a Reader when an attempt to registered it
// more than once occurs.
var errDuplicateRegister = fmt.Errorf("duplicate reader registration")
var errDuplicateRegister = errors.New("duplicate reader registration")

// ErrReaderNotRegistered is returned if Collect or Shutdown are called before
// the reader is registered with a MeterProvider.
var ErrReaderNotRegistered = fmt.Errorf("reader is not registered")
var ErrReaderNotRegistered = errors.New("reader is not registered")

// ErrReaderShutdown is returned if Collect or Shutdown are called after a
// reader has been Shutdown once.
var ErrReaderShutdown = fmt.Errorf("reader is shutdown")
var ErrReaderShutdown = errors.New("reader is shutdown")

// errNonPositiveDuration is logged when an environmental variable
// has non-positive value.
var errNonPositiveDuration = fmt.Errorf("non-positive duration")
var errNonPositiveDuration = errors.New("non-positive duration")

// Reader is the interface used between the SDK and an
// exporter. Control flow is bi-directional through the
Expand Down
4 changes: 2 additions & 2 deletions sdk/resource/auto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package resource_test
import (
"context"
"errors"
"fmt"

"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -76,7 +76,7 @@ func TestDetect(t *testing.T) {
}

for _, c := range cases {
t.Run(fmt.Sprintf("case-%s", c.name), func(t *testing.T) {
t.Run("case-"+c.name, func(t *testing.T) {
r, err := resource.Detect(context.Background(), c.detectors...)
if c.wantErr != nil {
assert.ErrorIs(t, err, c.wantErr)
Expand Down
7 changes: 4 additions & 3 deletions sdk/resource/builtin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ package resource_test

import (
"context"
"fmt"

"errors"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -15,7 +16,7 @@ import (
)

func TestBuiltinStringDetector(t *testing.T) {
E := fmt.Errorf("no K")
E := errors.New("no K")
res, err := resource.StringDetector("", attribute.Key("K"), func() (string, error) {
return "", E
}).Detect(context.Background())
Expand All @@ -33,7 +34,7 @@ func TestStringDetectorErrors(t *testing.T) {
{
desc: "explicit error from func should be returned",
s: resource.StringDetector("", attribute.Key("K"), func() (string, error) {
return "", fmt.Errorf("k-is-missing")
return "", errors.New("k-is-missing")
}),
errContains: "k-is-missing",
},
Expand Down
11 changes: 6 additions & 5 deletions sdk/resource/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"errors"
"fmt"
"os"
"strconv"
"strings"
"sync"
"testing"
Expand Down Expand Up @@ -56,7 +57,7 @@ func TestNewWithAttributes(t *testing.T) {
},
}
for _, c := range cases {
t.Run(fmt.Sprintf("case-%s", c.name), func(t *testing.T) {
t.Run("case-"+c.name, func(t *testing.T) {
res := resource.NewSchemaless(c.in...)
if diff := cmp.Diff(
res.Attributes(),
Expand Down Expand Up @@ -177,7 +178,7 @@ func TestMerge(t *testing.T) {
},
}
for _, c := range cases {
t.Run(fmt.Sprintf("case-%s", c.name), func(t *testing.T) {
t.Run("case-"+c.name, func(t *testing.T) {
res, err := resource.Merge(c.a, c.b)
if c.isErr {
assert.Error(t, err)
Expand Down Expand Up @@ -560,7 +561,7 @@ func TestWithProcessPID(t *testing.T) {

require.NoError(t, err)
require.EqualValues(t, map[string]string{
"process.pid": fmt.Sprint(fakePID),
"process.pid": strconv.Itoa(fakePID),
}, toMap(res))
}

Expand Down Expand Up @@ -674,7 +675,7 @@ func TestWithProcess(t *testing.T) {
require.NoError(t, err)
jsonCommandArgs, _ := json.Marshal(fakeCommandArgs)
require.EqualValues(t, map[string]string{
"process.pid": fmt.Sprint(fakePID),
"process.pid": strconv.Itoa(fakePID),
"process.executable.name": fakeExecutableName,
"process.executable.path": fakeExecutablePath,
"process.command_args": string(jsonCommandArgs),
Expand Down Expand Up @@ -731,7 +732,7 @@ func TestWithContainerID(t *testing.T) {
{
name: "error",
containerIDProvider: func() (string, error) {
return "", fmt.Errorf("unable to get container id")
return "", errors.New("unable to get container id")
},
expectedResource: map[string]string{},
expectedErr: true,
Expand Down
Loading

0 comments on commit c382578

Please sign in to comment.