Skip to content

Commit

Permalink
Merge branch 'jaegertracing:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
vaidikcode authored Nov 5, 2024
2 parents aafa37c + 0a24f6d commit 1909ee1
Show file tree
Hide file tree
Showing 34 changed files with 96 additions and 85 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
12 changes: 3 additions & 9 deletions cmd/agent/app/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ func TestAgentSamplingEndpoint(t *testing.T) {
}
select {
case err := <-errorch:
if err != nil {
t.Fatalf("error from agent: %s", err)
}
require.NoError(t, err, "error from agent")
break wait_loop
default:
time.Sleep(time.Millisecond)
Expand Down Expand Up @@ -155,9 +153,7 @@ func TestStartStopRace(t *testing.T) {
// Before the bug was fixed this test was failing as expected when
// run with -race flag.

if err := agent.Run(); err != nil {
t.Fatalf("error from agent.Run(): %s", err)
}
require.NoError(t, agent.Run())

t.Log("stopping agent")
agent.Stop()
Expand Down Expand Up @@ -192,9 +188,7 @@ func TestStartStopWithSocketBufferSet(t *testing.T) {
agent, err := cfg.CreateAgent(fakeCollectorProxy{}, zap.NewNop(), metricsFactory)
require.NoError(t, err)

if err := agent.Run(); err != nil {
t.Fatalf("error from agent.Run(): %s", err)
}
require.NoError(t, agent.Run())

t.Log("stopping agent")
agent.Stop()
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"
"net/http"
Expand Down Expand Up @@ -79,7 +80,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 @@ -418,7 +417,7 @@ func TestFindTracesMissingQuery_GRPC(t *testing.T) {
func TestFindTracesFailure_GRPC(t *testing.T) {
t.Parallel()
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 @@ -217,7 +217,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 @@ -485,7 +485,7 @@ func TestSearchDBFailure(t *testing.T) {
t.Parallel()
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
Loading

0 comments on commit 1909ee1

Please sign in to comment.