Skip to content

Commit

Permalink
Merge branch 'jaegertracing:main' into add-otel-meter-provider
Browse files Browse the repository at this point in the history
  • Loading branch information
shinigami-777 authored Nov 7, 2024
2 parents 53dbac9 + 38a9993 commit a431fa7
Show file tree
Hide file tree
Showing 118 changed files with 423 additions and 1,707 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/ci-e2e-elasticsearch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ jobs:
with:
go-version: 1.23.x

- name: time settings
run: |
date
echo TZ="$TZ"
- uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # v3.2.0
- name: Run ${{ matrix.version.distribution }} integration tests
id: test-execution
Expand Down
14 changes: 14 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,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 +156,17 @@ linters-settings:
- fieldalignment
# Disable shadow
- shadow
perfsprint:
# Optimizes even if it requires an int or uint type cast.
int-conversion: true
# 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: true
# Optimizes into strings concatenation.
strconcat: true
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: 2 additions & 3 deletions cmd/agent/app/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"expvar"
"flag"
"fmt"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -150,9 +149,9 @@ func TestBuilderWithProcessorErrors(t *testing.T) {
_, err := cfg.CreateAgent(&fakeCollectorProxy{}, zap.NewNop(), metrics.NullFactory)
require.Error(t, err)
if testCase.err != "" {
assert.Contains(t, err.Error(), testCase.err)
assert.ErrorContains(t, err, testCase.err)
} else if testCase.errContains != "" {
assert.True(t, strings.Contains(err.Error(), testCase.errContains), "error must contain %s", testCase.errContains)
assert.ErrorContains(t, err, testCase.errContains, "error must contain %s", testCase.errContains)
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/agent/app/configmanager/grpc/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ func TestSamplingManager_GetSamplingStrategy_error(t *testing.T) {
manager := NewConfigManager(conn)
resp, err := manager.GetSamplingStrategy(context.Background(), "any")
require.Nil(t, resp)
require.Error(t, err)
assert.Contains(t, err.Error(), "failed to get sampling strategy")
assert.ErrorContains(t, err, "failed to get sampling strategy")
}

func TestSamplingManager_GetBaggageRestrictions(t *testing.T) {
Expand Down
3 changes: 1 addition & 2 deletions cmd/agent/app/reporter/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package reporter

import (
"flag"
"fmt"

"github.com/spf13/viper"
"go.uber.org/zap"
Expand Down Expand Up @@ -34,7 +33,7 @@ type Options struct {

// AddFlags adds flags for Options.
func AddFlags(flagSet *flag.FlagSet) {
flagSet.String(reporterType, string(GRPC), fmt.Sprintf("Reporter type to use e.g. %s", string(GRPC)))
flagSet.String(reporterType, string(GRPC), "Reporter type to use e.g. "+string(GRPC))
if !setupcontext.IsAllInOne() {
flagSet.String(agentTags, "", "One or more tags to be added to the Process tags of all spans passing through this agent. Ex: key1=value1,key2=${envVar:defaultValue}")
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/agent/app/reporter/grpc/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ func TestBuilderWithCollectors(t *testing.T) {
assert.Equal(t, conn.Target(), test.target)
}
} else {
require.Error(t, err)
assert.Contains(t, err.Error(), test.expectedError)
assert.ErrorContains(t, err, test.expectedError)
}
})
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/agent/app/reporter/grpc/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,5 @@ func TestBindTLSFlagFailure(t *testing.T) {
})
require.NoError(t, err)
_, err = new(ConnBuilder).InitFromViper(v)
require.Error(t, err)
assert.Contains(t, err.Error(), "failed to process TLS options")
assert.ErrorContains(t, err, "failed to process TLS options")
}
5 changes: 2 additions & 3 deletions cmd/agent/app/reporter/grpc/reporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ func TestReporter_SendFailure(t *testing.T) {
defer conn.Close()
rep := NewReporter(conn, nil, zap.NewNop())
err = rep.send(context.Background(), nil, nil)
require.Error(t, err)
assert.Contains(t, err.Error(), "failed to export spans:")
assert.ErrorContains(t, err, "failed to export spans:")
}

func TestReporter_AddProcessTags_EmptyTags(t *testing.T) {
Expand Down Expand Up @@ -211,6 +210,6 @@ func TestReporter_MultitenantEmitBatch(t *testing.T) {
}
for _, test := range tests {
err = rep.EmitBatch(context.Background(), test.in)
assert.Contains(t, err.Error(), test.err)
assert.ErrorContains(t, err, test.err)
}
}
4 changes: 2 additions & 2 deletions cmd/anonymizer/app/uiconv/extractor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestExtractorTraceOutputFileError(t *testing.T) {
reader,
zap.NewNop(),
)
require.Contains(t, err.Error(), "cannot create output file")
require.ErrorContains(t, err, "cannot create output file")
}

func TestExtractorTraceScanError(t *testing.T) {
Expand All @@ -86,7 +86,7 @@ func TestExtractorTraceScanError(t *testing.T) {
require.NoError(t, err)

err = extractor.Run()
require.Contains(t, err.Error(), "failed when scanning the file")
require.ErrorContains(t, err, "failed when scanning the file")
}

func loadJSON(t *testing.T, fileName string, i any) {
Expand Down
4 changes: 2 additions & 2 deletions cmd/anonymizer/app/uiconv/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestModule_TraceNonExistent(t *testing.T) {
TraceID: "2be38093ead7a083",
}
err := Extract(config, zap.NewNop())
require.Contains(t, err.Error(), "cannot open captured file")
require.ErrorContains(t, err, "cannot open captured file")
}

func TestModule_TraceOutputFileError(t *testing.T) {
Expand All @@ -65,5 +65,5 @@ func TestModule_TraceOutputFileError(t *testing.T) {
defer os.Chmod("fixtures", 0o755)

err = Extract(config, zap.NewNop())
require.Contains(t, err.Error(), "cannot create output file")
require.ErrorContains(t, err, "cannot create output file")
}
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/anonymizer/app/uiconv/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func TestReaderTraceSuccess(t *testing.T) {
func TestReaderTraceNonExistent(t *testing.T) {
inputFile := "fixtures/trace_non_existent.json"
_, err := newSpanReader(inputFile, zap.NewNop())
require.Contains(t, err.Error(), "cannot open captured file")
require.ErrorContains(t, err, "cannot open captured file")
}

func TestReaderTraceEmpty(t *testing.T) {
Expand All @@ -48,7 +48,7 @@ func TestReaderTraceEmpty(t *testing.T) {
require.NoError(t, err)

_, err = r.NextSpan()
require.Contains(t, err.Error(), "cannot read file")
require.ErrorContains(t, err, "cannot read file")
assert.Equal(t, 0, r.spansRead)
assert.True(t, r.eofReached)
}
Expand All @@ -70,7 +70,7 @@ func TestReaderTraceInvalidJson(t *testing.T) {
require.NoError(t, err)

_, err = r.NextSpan()
require.Contains(t, err.Error(), "cannot unmarshal span")
require.ErrorContains(t, err, "cannot unmarshal span")
assert.Equal(t, 0, r.spansRead)
assert.True(t, r.eofReached)
}
3 changes: 1 addition & 2 deletions cmd/collector/app/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ func TestCollector_StartErrors(t *testing.T) {
TenancyMgr: tm,
})
err := c.Start(options)
require.Error(t, err)
assert.Contains(t, err.Error(), expErr)
require.ErrorContains(t, err, expErr)
require.NoError(t, c.Close())
})
}
Expand Down
6 changes: 2 additions & 4 deletions cmd/collector/app/flags/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ func TestCollectorOptionsWithFailedTLSFlags(t *testing.T) {
})
require.NoError(t, err)
_, err = c.InitFromViper(v, zap.NewNop())
require.Error(t, err)
assert.Contains(t, err.Error(), "failed to parse")
assert.ErrorContains(t, err, "failed to parse")
})
}
}
Expand All @@ -91,8 +90,7 @@ func TestCollectorOptionsWithFlags_CheckTLSReloadInterval(t *testing.T) {
prefix + ".tls.reload-interval=24h",
})
if _, ok := otlpPrefixes[prefix]; !ok {
require.Error(t, err)
assert.Contains(t, err.Error(), "unknown flag")
assert.ErrorContains(t, err, "unknown flag")
} else {
require.NoError(t, err)
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/collector/app/handler/grpc_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,8 @@ func TestPostSpansWithError(t *testing.T) {
},
},
})
require.Error(t, err)
require.ErrorContains(t, err, test.expectedError)
require.Nil(t, r)
assert.Contains(t, err.Error(), test.expectedError)
assert.Contains(t, logBuf.String(), test.expectedLog)
assert.Len(t, processor.getSpans(), 1)
})
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
9 changes: 3 additions & 6 deletions cmd/collector/app/handler/otlp_receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,25 +92,22 @@ func TestStartOtlpReceiver_Error(t *testing.T) {
opts := optionsWithPorts(":-1")
tm := &tenancy.Manager{}
_, err := StartOTLPReceiver(opts, logger, spanProcessor, tm)
require.Error(t, err)
assert.Contains(t, err.Error(), "could not start the OTLP receiver")
require.ErrorContains(t, err, "could not start the OTLP receiver")

newTraces := func(consumer.ConsumeTracesFunc, ...consumer.Option) (consumer.Traces, error) {
return nil, errors.New("mock error")
}
f := otlpreceiver.NewFactory()
_, err = startOTLPReceiver(opts, logger, spanProcessor, &tenancy.Manager{}, f, newTraces, f.CreateTraces)
require.Error(t, err)
assert.Contains(t, err.Error(), "could not create the OTLP consumer")
require.ErrorContains(t, err, "could not create the OTLP consumer")

createTracesReceiver := func(
context.Context, receiver.Settings, component.Config, consumer.Traces,
) (receiver.Traces, error) {
return nil, errors.New("mock error")
}
_, err = startOTLPReceiver(opts, logger, spanProcessor, &tenancy.Manager{}, f, consumer.NewTraces, createTracesReceiver)
require.Error(t, err)
assert.Contains(t, err.Error(), "could not create the OTLP receiver")
assert.ErrorContains(t, err, "could not create the OTLP receiver")
}

func TestOtelHost_ReportFatalError(t *testing.T) {
Expand Down
9 changes: 3 additions & 6 deletions cmd/collector/app/handler/zipkin_receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,23 +141,20 @@ func TestStartZipkinReceiver_Error(t *testing.T) {
opts.Zipkin.HTTPHostPort = ":-1"

_, err := StartZipkinReceiver(opts, logger, spanProcessor, tm)
require.Error(t, err)
assert.Contains(t, err.Error(), "could not start Zipkin receiver")
require.ErrorContains(t, err, "could not start Zipkin receiver")

newTraces := func(consumer.ConsumeTracesFunc, ...consumer.Option) (consumer.Traces, error) {
return nil, errors.New("mock error")
}
f := zipkinreceiver.NewFactory()
_, err = startZipkinReceiver(opts, logger, spanProcessor, tm, f, newTraces, f.CreateTraces)
require.Error(t, err)
assert.Contains(t, err.Error(), "could not create Zipkin consumer")
require.ErrorContains(t, err, "could not create Zipkin consumer")

createTracesReceiver := func(
context.Context, receiver.Settings, component.Config, consumer.Traces,
) (receiver.Traces, error) {
return nil, errors.New("mock error")
}
_, err = startZipkinReceiver(opts, logger, spanProcessor, tm, f, consumer.NewTraces, createTracesReceiver)
require.Error(t, err)
assert.Contains(t, err.Error(), "could not create Zipkin receiver")
assert.ErrorContains(t, err, "could not create Zipkin receiver")
}
5 changes: 3 additions & 2 deletions cmd/collector/app/server/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net"
"net/http"
"net/http/httptest"
"strconv"
"testing"
"time"

Expand Down Expand Up @@ -207,7 +208,7 @@ func TestSpanCollectorHTTPS(t *testing.T) {
defer test.clientTLS.Close()
require.NoError(t, err0)
dialer := &net.Dialer{Timeout: 2 * time.Second}
conn, clientError := tls.DialWithDialer(dialer, "tcp", "localhost:"+fmt.Sprintf("%d", ports.CollectorHTTP), clientTLSCfg)
conn, clientError := tls.DialWithDialer(dialer, "tcp", "localhost:"+strconv.Itoa(ports.CollectorHTTP), clientTLSCfg)
var clientClose func() error
clientClose = nil
if conn != nil {
Expand All @@ -230,7 +231,7 @@ func TestSpanCollectorHTTPS(t *testing.T) {
},
}

response, requestError := client.Post("https://localhost:"+fmt.Sprintf("%d", ports.CollectorHTTP), "", nil)
response, requestError := client.Post("https://localhost:"+strconv.Itoa(ports.CollectorHTTP), "", nil)

if test.expectClientError {
require.Error(t, requestError)
Expand Down
Loading

0 comments on commit a431fa7

Please sign in to comment.