Skip to content

Commit

Permalink
Merge branch 'main' into testifier/require-error
Browse files Browse the repository at this point in the history
  • Loading branch information
yurishkuro authored Nov 4, 2024
2 parents bc98d24 + c65757f commit 78c54fd
Show file tree
Hide file tree
Showing 30 changed files with 89 additions and 64 deletions.
16 changes: 16 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ issues:
text: "exitAfterDefer"
- linters: [gocritic]
text: "appendAssign"
- linters: [perfsprint]
text: "fmt.Sprintf can be replaced"
exclude-dirs-use-default: false
exclude-dirs:
- mocks
Expand Down Expand Up @@ -96,6 +98,9 @@ linters:
# Reports ill-formed or insufficient nolint directives.
- nolintlint

# Checks that fmt.Sprintf can be replaced with a faster alternative.
- perfsprint

# Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint.
- revive

Expand Down Expand Up @@ -153,6 +158,17 @@ linters-settings:
- fieldalignment
# Disable shadow
- shadow
perfsprint:
# Optimizes even if it requires an int or uint type cast.
int-conversion: false
# Optimizes into `err.Error()` even if it is only equivalent for non-nil errors.
err-error: true
# Optimizes `fmt.Errorf`.
errorf: true
# Optimizes `fmt.Sprintf` with only one argument.
sprintf1: false
# Optimizes into strings concatenation.
strconcat: false
revive:
ignore-generated-header: true
severity: error
Expand Down
5 changes: 3 additions & 2 deletions cmd/anonymizer/app/uiconv/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package uiconv
import (
"bufio"
"encoding/json"
"errors"
"fmt"
"os"

Expand All @@ -14,7 +15,7 @@ import (
uimodel "github.com/jaegertracing/jaeger/model/json"
)

var errNoMoreSpans = fmt.Errorf("no more spans")
var errNoMoreSpans = errors.New("no more spans")

// spanReader loads previously captured spans from a file.
type spanReader struct {
Expand Down Expand Up @@ -53,7 +54,7 @@ func (r *spanReader) NextSpan() (*uimodel.Span, error) {
}
if b != '[' {
r.eofReached = true
return nil, fmt.Errorf("file must begin with '['")
return nil, errors.New("file must begin with '['")
}
}
s, err := r.reader.ReadString('\n')
Expand Down
6 changes: 3 additions & 3 deletions cmd/collector/app/handler/http_thrift_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package handler
import (
"bytes"
"context"
"fmt"
"errors"
"io"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -79,7 +79,7 @@ func TestThriftFormat(t *testing.T) {
assert.EqualValues(t, http.StatusAccepted, statusCode)
assert.EqualValues(t, "", resBodyStr)

handler.jaegerBatchesHandler.(*mockJaegerHandler).err = fmt.Errorf("Bad times ahead")
handler.jaegerBatchesHandler.(*mockJaegerHandler).err = errors.New("Bad times ahead")
statusCode, resBodyStr, err = postBytes("application/vnd.apache.thrift.binary", server.URL+`/api/traces`, someBytes)
require.NoError(t, err)
assert.EqualValues(t, http.StatusInternalServerError, statusCode)
Expand Down Expand Up @@ -161,7 +161,7 @@ func TestCannotReadBodyFromRequest(t *testing.T) {
type errReader struct{}

func (*errReader) Read([]byte) (int, error) {
return 0, fmt.Errorf("Simulated error reading body")
return 0, errors.New("Simulated error reading body")
}

type dummyResponseWriter struct {
Expand Down
3 changes: 2 additions & 1 deletion cmd/collector/app/span_processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package app

import (
"context"
"errors"
"fmt"
"io"
"reflect"
Expand Down Expand Up @@ -250,7 +251,7 @@ func TestSpanProcessor(t *testing.T) {
func TestSpanProcessorErrors(t *testing.T) {
logger, logBuf := testutils.NewLogger()
w := &fakeSpanWriter{
err: fmt.Errorf("some-error"),
err: errors.New("some-error"),
}
mb := metricstest.NewFactory(time.Hour)
defer mb.Backend.Stop()
Expand Down
3 changes: 2 additions & 1 deletion cmd/es-index-cleaner/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package main

import (
"encoding/base64"
"errors"
"fmt"
"log"
"net/http"
Expand Down Expand Up @@ -33,7 +34,7 @@ func main() {
Long: "Jaeger es-index-cleaner removes Jaeger indices",
RunE: func(_ *cobra.Command, args []string) error {
if len(args) != 2 {
return fmt.Errorf("wrong number of arguments")
return errors.New("wrong number of arguments")
}
numOfDays, err := strconv.Atoi(args[0])
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/es-rollover/app/init/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func (c Action) Do() error {
}
if c.Config.UseILM {
if version < ilmVersionSupport {
return fmt.Errorf("ILM is supported only for ES version 7+")
return errors.New("ILM is supported only for ES version 7+")
}
policyExist, err := c.ILMClient.Exists(c.Config.ILMPolicyName)
if err != nil {
Expand Down
13 changes: 7 additions & 6 deletions cmd/jaeger/internal/extension/jaegerquery/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package jaegerquery

import (
"context"
"errors"
"fmt"
"net/http"
"testing"
Expand Down Expand Up @@ -42,28 +43,28 @@ type fakeFactory struct {

func (ff fakeFactory) CreateDependencyReader() (dependencystore.Reader, error) {
if ff.name == "need-dependency-reader-error" {
return nil, fmt.Errorf("test-error")
return nil, errors.New("test-error")
}
return &depsmocks.Reader{}, nil
}

func (ff fakeFactory) CreateSpanReader() (spanstore.Reader, error) {
if ff.name == "need-span-reader-error" {
return nil, fmt.Errorf("test-error")
return nil, errors.New("test-error")
}
return &spanstoremocks.Reader{}, nil
}

func (ff fakeFactory) CreateSpanWriter() (spanstore.Writer, error) {
if ff.name == "need-span-writer-error" {
return nil, fmt.Errorf("test-error")
return nil, errors.New("test-error")
}
return &spanstoremocks.Writer{}, nil
}

func (ff fakeFactory) Initialize(metrics.Factory, *zap.Logger) error {
if ff.name == "need-initialize-error" {
return fmt.Errorf("test-error")
return errors.New("test-error")
}
return nil
}
Expand All @@ -75,14 +76,14 @@ type fakeMetricsFactory struct {
// Initialize implements storage.MetricsFactory.
func (fmf fakeMetricsFactory) Initialize(*zap.Logger) error {
if fmf.name == "need-initialize-error" {
return fmt.Errorf("test-error")
return errors.New("test-error")
}
return nil
}

func (fmf fakeMetricsFactory) CreateMetricsReader() (metricsstore.Reader, error) {
if fmf.name == "need-metrics-reader-error" {
return nil, fmt.Errorf("test-error")
return nil, errors.New("test-error")
}
return &metricsstoremocks.Reader{}, nil
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/jaeger/internal/extension/jaegerstorage/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package jaegerstorage

import (
"errors"
"fmt"
"reflect"
"time"
Expand Down Expand Up @@ -96,7 +97,7 @@ func (cfg *Backend) Unmarshal(conf *confmap.Conf) error {

func (cfg *Config) Validate() error {
if len(cfg.Backends) == 0 {
return fmt.Errorf("at least one storage is required")
return errors.New("at least one storage is required")
}
for name, b := range cfg.Backends {
empty := Backend{}
Expand Down
4 changes: 2 additions & 2 deletions cmd/jaeger/internal/extension/jaegerstorage/extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package jaegerstorage
import (
"context"
"encoding/json"
"fmt"
"errors"
"net/http"
"net/http/httptest"
"testing"
Expand Down Expand Up @@ -88,7 +88,7 @@ func TestStorageExtensionType(t *testing.T) {
}

func TestStorageFactoryBadShutdownError(t *testing.T) {
shutdownError := fmt.Errorf("shutdown error")
shutdownError := errors.New("shutdown error")
ext := storageExt{
factories: map[string]storage.Factory{
"foo": errorFactory{closeErr: shutdownError},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package storagecleaner

import (
"context"
"errors"
"fmt"
"net/http"
"sync/atomic"
Expand Down Expand Up @@ -78,7 +79,7 @@ func TestStorageCleanerExtension(t *testing.T) {
},
{
name: "good storage with error",
factory: &PurgerFactory{err: fmt.Errorf("error")},
factory: &PurgerFactory{err: errors.New("error")},
status: http.StatusInternalServerError,
},
{
Expand Down
10 changes: 5 additions & 5 deletions cmd/query/app/apiv3/grpc_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package apiv3

import (
"context"
"fmt"
"errors"
"net"
"testing"

Expand Down Expand Up @@ -105,7 +105,7 @@ func TestGetTrace(t *testing.T) {
func TestGetTraceStorageError(t *testing.T) {
tsc := newTestServerClient(t)
tsc.reader.On("GetTrace", matchContext, matchTraceID).Return(
nil, fmt.Errorf("storage_error")).Once()
nil, errors.New("storage_error")).Once()

getTraceStream, err := tsc.client.GetTrace(context.Background(), &api_v3.GetTraceRequest{
TraceId: "156",
Expand Down Expand Up @@ -186,7 +186,7 @@ func TestFindTracesQueryNil(t *testing.T) {
func TestFindTracesStorageError(t *testing.T) {
tsc := newTestServerClient(t)
tsc.reader.On("FindTraces", matchContext, mock.AnythingOfType("*spanstore.TraceQueryParameters")).Return(
nil, fmt.Errorf("storage_error"), nil).Once()
nil, errors.New("storage_error"), nil).Once()

responseStream, err := tsc.client.FindTraces(context.Background(), &api_v3.FindTracesRequest{
Query: &api_v3.TraceQueryParameters{
Expand Down Expand Up @@ -215,7 +215,7 @@ func TestGetServices(t *testing.T) {
func TestGetServicesStorageError(t *testing.T) {
tsc := newTestServerClient(t)
tsc.reader.On("GetServices", matchContext).Return(
nil, fmt.Errorf("storage_error")).Once()
nil, errors.New("storage_error")).Once()

response, err := tsc.client.GetServices(context.Background(), &api_v3.GetServicesRequest{})
require.ErrorContains(t, err, "storage_error")
Expand Down Expand Up @@ -243,7 +243,7 @@ func TestGetOperations(t *testing.T) {
func TestGetOperationsStorageError(t *testing.T) {
tsc := newTestServerClient(t)
tsc.reader.On("GetOperations", matchContext, mock.AnythingOfType("spanstore.OperationQueryParameters")).Return(
nil, fmt.Errorf("storage_error")).Once()
nil, errors.New("storage_error")).Once()

response, err := tsc.client.GetOperations(context.Background(), &api_v3.GetOperationsRequest{})
require.ErrorContains(t, err, "storage_error")
Expand Down
2 changes: 1 addition & 1 deletion cmd/query/app/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func stringSliceAsHeader(slice []string) (http.Header, error) {

header, err := tp.ReadMIMEHeader()
if err != nil && !errors.Is(err, io.EOF) {
return nil, fmt.Errorf("failed to parse headers")
return nil, errors.New("failed to parse headers")
}

return http.Header(header), nil
Expand Down
3 changes: 1 addition & 2 deletions cmd/query/app/grpc_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package app
import (
"context"
"errors"
"fmt"
"net"
"testing"
"time"
Expand Down Expand Up @@ -407,7 +406,7 @@ func TestFindTracesMissingQuery_GRPC(t *testing.T) {

func TestFindTracesFailure_GRPC(t *testing.T) {
withServerAndClient(t, func(server *grpcServer, client *grpcClient) {
mockErrorGRPC := fmt.Errorf("whatsamattayou")
mockErrorGRPC := errors.New("whatsamattayou")

server.spanReader.On("FindTraces", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("*spanstore.TraceQueryParameters")).
Return(nil, mockErrorGRPC).Once()
Expand Down
4 changes: 2 additions & 2 deletions cmd/query/app/http_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func TestLogOnServerError(t *testing.T) {
type httpResponseErrWriter struct{}

func (*httpResponseErrWriter) Write([]byte) (int, error) {
return 0, fmt.Errorf("failed to write")
return 0, errors.New("failed to write")
}
func (*httpResponseErrWriter) WriteHeader(int /* statusCode */) {}
func (*httpResponseErrWriter) Header() http.Header {
Expand Down Expand Up @@ -468,7 +468,7 @@ func TestSearchModelConversionFailure(t *testing.T) {
func TestSearchDBFailure(t *testing.T) {
ts := initializeTestServer(t)
ts.spanReader.On("FindTraces", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("*spanstore.TraceQueryParameters")).
Return(nil, fmt.Errorf("whatsamattayou")).Once()
Return(nil, errors.New("whatsamattayou")).Once()

var response structuredResponse
err := getJSON(ts.server.URL+`/api/traces?service=service&start=0&end=0&operation=operation&limit=200&minDuration=20ms`, &response)
Expand Down
3 changes: 2 additions & 1 deletion cmd/query/app/static_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package app

import (
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -309,7 +310,7 @@ type fakeFile struct {
}

func (*fakeFile) Read([]byte) (n int, err error) {
return 0, fmt.Errorf("read error")
return 0, errors.New("read error")
}

func TestLoadIndexHTMLReadError(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions crossdock/services/tracehandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func validateAdaptiveSamplingTraces(expected *traceRequest, actual []*ui.Trace)
return fmt.Errorf("%s tag value should be '%s'", samplerTypeKey, jaeger.SamplerTypeProbabilistic)
}
if isDefaultProbability(probability) {
return fmt.Errorf("adaptive sampling probability not used")
return errors.New("adaptive sampling probability not used")
}
}
return nil
Expand All @@ -201,7 +201,7 @@ func (h *TraceHandler) createAndRetrieveTraces(service string, request *traceReq
}
traces := h.getTraces(service, request.Operation, request.Tags)
if len(traces) == 0 {
return nil, fmt.Errorf("could not retrieve traces from query service")
return nil, errors.New("could not retrieve traces from query service")
}
return traces, nil
}
Expand Down Expand Up @@ -261,7 +261,7 @@ func validateTraces(expected *traceRequest, actual []*ui.Trace) error {
}
tags := convertTagsIntoMap(trace.Spans[0].Tags)
if !expectedTagsExist(expected.Tags, tags) {
return fmt.Errorf("expected tags not found")
return errors.New("expected tags not found")
}
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions internal/tracegen/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
package tracegen

import (
"errors"
"flag"
"fmt"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -54,7 +54,7 @@ func Run(c *Config, tracers []trace.Tracer, logger *zap.Logger) error {
if c.Duration > 0 {
c.Traces = 0
} else if c.Traces <= 0 {
return fmt.Errorf("either `traces` or `duration` must be greater than 0")
return errors.New("either `traces` or `duration` must be greater than 0")
}

wg := sync.WaitGroup{}
Expand Down
Loading

0 comments on commit 78c54fd

Please sign in to comment.