diff --git a/cmd/agent/app/builder.go b/cmd/agent/app/builder.go index 7e14139ed6a..8338e9c959f 100644 --- a/cmd/agent/app/builder.go +++ b/cmd/agent/app/builder.go @@ -21,7 +21,6 @@ import ( "strconv" "github.com/apache/thrift/lib/go/thrift" - "github.com/pkg/errors" "github.com/uber/jaeger-lib/metrics" "go.uber.org/zap" @@ -110,7 +109,7 @@ func (b *Builder) CreateAgent(primaryProxy CollectorProxy, logger *zap.Logger, m r := b.getReporter(primaryProxy) processors, err := b.getProcessors(r, mFactory, logger) if err != nil { - return nil, errors.Wrap(err, "cannot create processors") + return nil, fmt.Errorf("cannot create processors: %w", err) } server := b.HTTPServer.getHTTPServer(primaryProxy.GetManager(), mFactory) return NewAgent(processors, server, logger), nil @@ -150,7 +149,7 @@ func (b *Builder) getProcessors(rep reporter.Reporter, mFactory metrics.Factory, }}) processor, err := cfg.GetThriftProcessor(metrics, protoFactory, handler, logger) if err != nil { - return nil, errors.Wrap(err, "cannot create Thrift Processor") + return nil, fmt.Errorf("cannot create Thrift Processor: %w", err) } retMe[idx] = processor } @@ -176,7 +175,7 @@ func (c *ProcessorConfiguration) GetThriftProcessor( server, err := c.Server.getUDPServer(mFactory) if err != nil { - return nil, errors.Wrap(err, "cannot create UDP Server") + return nil, fmt.Errorf("cannot create UDP Server: %w", err) } return processors.NewThriftProcessor(server, c.Workers, mFactory, factory, handler, logger) @@ -200,7 +199,7 @@ func (c *ServerConfiguration) getUDPServer(mFactory metrics.Factory) (servers.Se } transport, err := thriftudp.NewTUDPServerTransport(c.HostPort) if err != nil { - return nil, errors.Wrap(err, "cannot create UDPServerTransport") + return nil, fmt.Errorf("cannot create UDPServerTransport: %w", err) } return servers.NewTBufferedServer(transport, c.QueueSize, c.MaxPacketSize, mFactory) diff --git a/cmd/agent/app/reporter/grpc/builder.go b/cmd/agent/app/reporter/grpc/builder.go index 13644c34b71..b6a50fd4739 100644 --- a/cmd/agent/app/reporter/grpc/builder.go +++ b/cmd/agent/app/reporter/grpc/builder.go @@ -15,10 +15,11 @@ package grpc import ( + "errors" + "fmt" "strings" grpc_retry "github.com/grpc-ecosystem/go-grpc-middleware/retry" - "github.com/pkg/errors" "go.uber.org/zap" "google.golang.org/grpc" "google.golang.org/grpc/credentials" @@ -56,7 +57,7 @@ func (b *ConnBuilder) CreateConnection(logger *zap.Logger) (*grpc.ClientConn, er logger.Info("Agent requested secure grpc connection to collector(s)") tlsConf, err := b.TLS.Config() if err != nil { - return nil, errors.Wrap(err, "failed to load TLS config") + return nil, fmt.Errorf("failed to load TLS config: %w", err) } creds := credentials.NewTLS(tlsConf) diff --git a/cmd/agent/app/reporter/grpc/collector_proxy.go b/cmd/agent/app/reporter/grpc/collector_proxy.go index c09223a15a3..faad4b87c4b 100644 --- a/cmd/agent/app/reporter/grpc/collector_proxy.go +++ b/cmd/agent/app/reporter/grpc/collector_proxy.go @@ -22,7 +22,6 @@ import ( "github.com/jaegertracing/jaeger/cmd/agent/app/configmanager" grpcManager "github.com/jaegertracing/jaeger/cmd/agent/app/configmanager/grpc" "github.com/jaegertracing/jaeger/cmd/agent/app/reporter" - aReporter "github.com/jaegertracing/jaeger/cmd/agent/app/reporter" ) // ProxyBuilder holds objects communicating with collector @@ -59,7 +58,7 @@ func (b ProxyBuilder) GetConn() *grpc.ClientConn { } // GetReporter returns Reporter -func (b ProxyBuilder) GetReporter() aReporter.Reporter { +func (b ProxyBuilder) GetReporter() reporter.Reporter { return b.reporter } diff --git a/cmd/agent/app/reporter/tchannel/builder.go b/cmd/agent/app/reporter/tchannel/builder.go index a5830a3ba18..fd27a8dc454 100644 --- a/cmd/agent/app/reporter/tchannel/builder.go +++ b/cmd/agent/app/reporter/tchannel/builder.go @@ -16,9 +16,10 @@ package tchannel import ( + "errors" + "fmt" "time" - "github.com/pkg/errors" tchannel "github.com/uber/tchannel-go" "go.uber.org/zap" @@ -129,7 +130,7 @@ func (b *Builder) CreateReporter(logger *zap.Logger) (*Reporter, error) { peerListMgr, err := b.enableDiscovery(b.channel, logger) if err != nil { - return nil, errors.Wrap(err, "cannot enable service discovery") + return nil, fmt.Errorf("cannot enable service discovery: %w", err) } return New(b.CollectorServiceName, b.channel, b.ReportTimeout, peerListMgr, logger), nil } diff --git a/cmd/agent/main.go b/cmd/agent/main.go index 793ab1789fd..77dc9642106 100644 --- a/cmd/agent/main.go +++ b/cmd/agent/main.go @@ -20,7 +20,6 @@ import ( "io" "os" - "github.com/pkg/errors" "github.com/spf13/cobra" "github.com/spf13/viper" "github.com/uber/jaeger-lib/metrics" @@ -69,12 +68,12 @@ func main() { builder := new(app.Builder).InitFromViper(v) agent, err := builder.CreateAgent(cp, logger, mFactory) if err != nil { - return errors.Wrap(err, "unable to initialize Jaeger Agent") + return fmt.Errorf("unable to initialize Jaeger Agent: %w", err) } logger.Info("Starting agent") if err := agent.Run(); err != nil { - return errors.Wrap(err, "failed to run the agent") + return fmt.Errorf("failed to run the agent: %w", err) } svc.RunAndThen(func() { if closer, ok := cp.(io.Closer); ok { diff --git a/cmd/collector/app/server/grpc.go b/cmd/collector/app/server/grpc.go index bbba6664074..af94358d1d2 100644 --- a/cmd/collector/app/server/grpc.go +++ b/cmd/collector/app/server/grpc.go @@ -15,12 +15,12 @@ package server import ( + "fmt" "io/ioutil" "net" "os" "strconv" - "github.com/pkg/errors" "go.uber.org/zap" "google.golang.org/grpc" "google.golang.org/grpc/credentials" @@ -65,7 +65,7 @@ func StartGRPCServer(params *GRPCServerParams) (*grpc.Server, error) { grpcPortStr := ":" + strconv.Itoa(params.Port) listener, err := net.Listen("tcp", grpcPortStr) if err != nil { - return nil, errors.Wrap(err, "failed to listen on gRPC port") + return nil, fmt.Errorf("failed to listen on gRPC port: %w", err) } if err := serveGRPC(server, listener, params); err != nil { diff --git a/cmd/flags/flags.go b/cmd/flags/flags.go index 2ef349c17a1..a240d97da8a 100644 --- a/cmd/flags/flags.go +++ b/cmd/flags/flags.go @@ -17,10 +17,10 @@ package flags import ( "flag" + "fmt" "os" "strings" - "github.com/pkg/errors" "github.com/spf13/viper" "go.uber.org/zap" "go.uber.org/zap/zapcore" @@ -43,7 +43,7 @@ func TryLoadConfigFile(v *viper.Viper) error { v.SetConfigFile(file) err := v.ReadInConfig() if err != nil { - return errors.Wrapf(err, "cannot load config file %s", file) + return fmt.Errorf("cannot load config file %s: %w", file, err) } } return nil diff --git a/cmd/flags/service.go b/cmd/flags/service.go index 2d0972d3c69..567ecd49938 100644 --- a/cmd/flags/service.go +++ b/cmd/flags/service.go @@ -16,12 +16,12 @@ package flags import ( "flag" + "fmt" "os" "os/signal" "syscall" grpcZap "github.com/grpc-ecosystem/go-grpc-middleware/logging/zap" - "github.com/pkg/errors" "github.com/spf13/viper" "github.com/uber/jaeger-lib/metrics" "go.uber.org/zap" @@ -85,7 +85,7 @@ func (s *Service) SetHealthCheckStatus(status healthcheck.Status) { // Start bootstraps the service and starts the admin server. func (s *Service) Start(v *viper.Viper) error { if err := TryLoadConfigFile(v); err != nil { - return errors.Wrap(err, "cannot load config file") + return fmt.Errorf("cannot load config file: %w", err) } sFlags := new(SharedFlags).InitFromViper(v) @@ -99,13 +99,13 @@ func (s *Service) Start(v *viper.Viper) error { zap.AddCallerSkip(3), )) } else { - return errors.Wrap(err, "cannot create logger") + return fmt.Errorf("cannot create logger: %w", err) } metricsBuilder := new(pMetrics.Builder).InitFromViper(v) metricsFactory, err := metricsBuilder.CreateMetricsFactory("") if err != nil { - return errors.Wrap(err, "cannot create metrics factory") + return fmt.Errorf("cannot create metrics factory: %w", err) } s.MetricsFactory = metricsFactory @@ -116,7 +116,7 @@ func (s *Service) Start(v *viper.Viper) error { s.Admin.Handle(route, h) } if err := s.Admin.Serve(); err != nil { - return errors.Wrap(err, "cannot start the admin server") + return fmt.Errorf("cannot start the admin server: %w", err) } return nil diff --git a/cmd/ingester/app/consumer/consumer_test.go b/cmd/ingester/app/consumer/consumer_test.go index fb4b5e3ae02..21a4dcd87ac 100644 --- a/cmd/ingester/app/consumer/consumer_test.go +++ b/cmd/ingester/app/consumer/consumer_test.go @@ -15,6 +15,7 @@ package consumer import ( + "errors" "fmt" "sync" "testing" @@ -22,8 +23,7 @@ import ( "github.com/Shopify/sarama" smocks "github.com/Shopify/sarama/mocks" - "github.com/bsm/sarama-cluster" - "github.com/pkg/errors" + cluster "github.com/bsm/sarama-cluster" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" diff --git a/cmd/ingester/app/processor/metrics_decorator_test.go b/cmd/ingester/app/processor/metrics_decorator_test.go index 1ae04208086..d68d7941bd1 100644 --- a/cmd/ingester/app/processor/metrics_decorator_test.go +++ b/cmd/ingester/app/processor/metrics_decorator_test.go @@ -15,9 +15,9 @@ package processor_test import ( + "errors" "testing" - "github.com/pkg/errors" "github.com/stretchr/testify/assert" "github.com/uber/jaeger-lib/metrics/metricstest" diff --git a/cmd/ingester/app/processor/span_processor.go b/cmd/ingester/app/processor/span_processor.go index a0a52c1b2cb..c31eb793182 100644 --- a/cmd/ingester/app/processor/span_processor.go +++ b/cmd/ingester/app/processor/span_processor.go @@ -15,10 +15,9 @@ package processor import ( + "fmt" "io" - "github.com/pkg/errors" - "github.com/jaegertracing/jaeger/plugin/storage/kafka" "github.com/jaegertracing/jaeger/storage/spanstore" ) @@ -61,7 +60,7 @@ func NewSpanProcessor(params SpanProcessorParams) *KafkaSpanProcessor { func (s KafkaSpanProcessor) Process(message Message) error { mSpan, err := s.unmarshaller.Unmarshal(message.Value()) if err != nil { - return errors.Wrap(err, "cannot unmarshall byte array into span") + return fmt.Errorf("cannot unmarshall byte array into span: %w", err) } return s.writer.WriteSpan(mSpan) } diff --git a/cmd/ingester/app/processor/span_processor_test.go b/cmd/ingester/app/processor/span_processor_test.go index 100b522ebef..373aff3be11 100644 --- a/cmd/ingester/app/processor/span_processor_test.go +++ b/cmd/ingester/app/processor/span_processor_test.go @@ -15,9 +15,9 @@ package processor import ( + "errors" "testing" - "github.com/pkg/errors" "github.com/stretchr/testify/assert" cmocks "github.com/jaegertracing/jaeger/cmd/ingester/app/consumer/mocks" diff --git a/cmd/query/app/http_handler.go b/cmd/query/app/http_handler.go index b80c9203d70..9be69cf84c2 100644 --- a/cmd/query/app/http_handler.go +++ b/cmd/query/app/http_handler.go @@ -27,7 +27,6 @@ import ( "github.com/gorilla/mux" "github.com/opentracing-contrib/go-stdlib/nethttp" "github.com/opentracing/opentracing-go" - "github.com/pkg/errors" "go.uber.org/zap" "github.com/jaegertracing/jaeger/cmd/query/app/querysvc" @@ -263,14 +262,20 @@ func (aH *APIHandler) tracesByIDs(ctx context.Context, traceIDs []model.TraceID) func (aH *APIHandler) dependencies(w http.ResponseWriter, r *http.Request) { endTsMillis, err := strconv.ParseInt(r.FormValue(endTsParam), 10, 64) - if aH.handleError(w, errors.Wrapf(err, "unable to parse %s", endTimeParam), http.StatusBadRequest) { - return + if err != nil { + err = fmt.Errorf("unable to parse %s: %w", endTimeParam, err) + if aH.handleError(w, err, http.StatusBadRequest) { + return + } } var lookback time.Duration if formValue := r.FormValue(lookbackParam); len(formValue) > 0 { lookback, err = time.ParseDuration(formValue + "ms") - if aH.handleError(w, errors.Wrapf(err, "unable to parse %s", lookbackParam), http.StatusBadRequest) { - return + if err != nil { + err = fmt.Errorf("unable to parse %s: %w", lookbackParam, err) + if aH.handleError(w, err, http.StatusBadRequest) { + return + } } } service := r.FormValue(serviceParam) diff --git a/cmd/query/app/query_parser.go b/cmd/query/app/query_parser.go index a99bb10b679..1aa5b6a9cf3 100644 --- a/cmd/query/app/query_parser.go +++ b/cmd/query/app/query_parser.go @@ -23,8 +23,6 @@ import ( "strings" "time" - "github.com/pkg/errors" - "github.com/jaegertracing/jaeger/model" "github.com/jaegertracing/jaeger/storage/spanstore" ) @@ -121,7 +119,7 @@ func (p *queryParser) parse(r *http.Request) (*traceQueryParameters, error) { if traceID, err := model.TraceIDFromString(id); err == nil { traceIDs = append(traceIDs, traceID) } else { - return nil, errors.Wrap(err, "cannot parse traceID param") + return nil, fmt.Errorf("cannot parse traceID param: %w", err) } } @@ -165,7 +163,7 @@ func (p *queryParser) parseDuration(durationParam string, r *http.Request) (time if len(durationInput) > 0 { duration, err := time.ParseDuration(durationInput) if err != nil { - return 0, errors.Wrapf(err, "cannot not parse %s", durationParam) + return 0, fmt.Errorf("cannot not parse %s: %w", durationParam, err) } return duration, nil } diff --git a/cmd/query/app/static_handler.go b/cmd/query/app/static_handler.go index 6ba79356260..cde083e0bd5 100644 --- a/cmd/query/app/static_handler.go +++ b/cmd/query/app/static_handler.go @@ -27,7 +27,6 @@ import ( "github.com/fsnotify/fsnotify" "github.com/gorilla/mux" - "github.com/pkg/errors" "go.uber.org/zap" "github.com/jaegertracing/jaeger/cmd/query/app/ui" @@ -101,7 +100,7 @@ func NewStaticAssetsHandler(staticAssetsRoot string, options StaticAssetsHandler func loadIndexBytes(open func(string) (http.File, error), options StaticAssetsHandlerOptions) ([]byte, error) { indexBytes, err := loadIndexHTML(open) if err != nil { - return nil, errors.Wrap(err, "cannot load index.html") + return nil, fmt.Errorf("cannot load index.html: %w", err) } configString := "JAEGER_CONFIG = DEFAULT_CONFIG" if config, err := loadUIConfig(options.UIConfigPath); err != nil { @@ -188,12 +187,12 @@ func (sH *StaticAssetsHandler) watch() { func loadIndexHTML(open func(string) (http.File, error)) ([]byte, error) { indexFile, err := open("/index.html") if err != nil { - return nil, errors.Wrap(err, "cannot open index.html") + return nil, fmt.Errorf("cannot open index.html: %w", err) } defer indexFile.Close() indexBytes, err := ioutil.ReadAll(indexFile) if err != nil { - return nil, errors.Wrap(err, "cannot read from index.html") + return nil, fmt.Errorf("cannot read from index.html: %w", err) } return indexBytes, nil } @@ -205,7 +204,7 @@ func loadUIConfig(uiConfig string) (map[string]interface{}, error) { ext := filepath.Ext(uiConfig) bytes, err := ioutil.ReadFile(uiConfig) /* nolint #nosec , this comes from an admin, not user */ if err != nil { - return nil, errors.Wrapf(err, "cannot read UI config file %v", uiConfig) + return nil, fmt.Errorf("cannot read UI config file %v: %w", uiConfig, err) } var c map[string]interface{} @@ -219,7 +218,7 @@ func loadUIConfig(uiConfig string) (map[string]interface{}, error) { } if err := unmarshal(bytes, &c); err != nil { - return nil, errors.Wrapf(err, "cannot parse UI config file %v", uiConfig) + return nil, fmt.Errorf("cannot parse UI config file %v: %w", uiConfig, err) } return c, nil } diff --git a/crossdock/services/tracehandler.go b/crossdock/services/tracehandler.go index 01f4cbb3e66..975ba1e60b7 100644 --- a/crossdock/services/tracehandler.go +++ b/crossdock/services/tracehandler.go @@ -18,6 +18,7 @@ package services import ( "bytes" "encoding/json" + "errors" "fmt" "math/rand" "net/http" @@ -25,7 +26,6 @@ import ( "time" "github.com/crossdock/crossdock-go" - "github.com/pkg/errors" "github.com/uber/jaeger-client-go" "go.uber.org/zap" @@ -145,7 +145,7 @@ func (h *TraceHandler) adaptiveSamplingTest(service string, request *traceReques h.logger.Info(fmt.Sprintf("Waiting for adaptive sampling probabilities, iteration %d out of 20", i+1)) rate, err = h.agent.GetSamplingRate(service, request.Operation) if err != nil { - return nil, errors.Wrap(err, "could not retrieve sampling rate from agent") + return nil, fmt.Errorf("could not retrieve sampling rate from agent: %w", err) } if !isDefaultProbability(rate) { break @@ -210,7 +210,7 @@ func (h *TraceHandler) createTracesLoop(service string, request traceRequest, st func (h *TraceHandler) createAndRetrieveTraces(service string, request *traceRequest) ([]*ui.Trace, error) { if err := h.createTrace(service, request); err != nil { - return nil, errors.Wrap(err, "failed to create trace") + return nil, fmt.Errorf("failed to create trace: %w", err) } traces := h.getTraces(service, request.Operation, request.Tags) if len(traces) == 0 { diff --git a/pkg/cassandra/metrics/table.go b/pkg/cassandra/metrics/table.go index 9aaaf6b811b..c1e2e7ab6ca 100644 --- a/pkg/cassandra/metrics/table.go +++ b/pkg/cassandra/metrics/table.go @@ -16,9 +16,9 @@ package metrics import ( + "fmt" "time" - "github.com/pkg/errors" "github.com/uber/jaeger-lib/metrics" "go.uber.org/zap" @@ -48,7 +48,7 @@ func (t *Table) Exec(query cassandra.UpdateQuery, logger *zap.Logger) error { if logger != nil { logger.Error("Failed to exec query", zap.String("query", queryString), zap.Error(err)) } - return errors.Wrapf(err, "failed to Exec query '%s'", queryString) + return fmt.Errorf("failed to Exec query '%s': %w", queryString, err) } return nil } diff --git a/pkg/config/tlscfg/options.go b/pkg/config/tlscfg/options.go index 0be5f3be320..2e5779f3e0a 100644 --- a/pkg/config/tlscfg/options.go +++ b/pkg/config/tlscfg/options.go @@ -20,8 +20,6 @@ import ( "fmt" "io/ioutil" "path/filepath" - - "github.com/pkg/errors" ) // Options describes the configuration properties for TLS Connections. @@ -41,7 +39,7 @@ var systemCertPool = x509.SystemCertPool // to allow overriding in unit test func (p Options) Config() (*tls.Config, error) { certPool, err := p.loadCertPool() if err != nil { - return nil, errors.Wrap(err, "failed to load CA CertPool") + return nil, fmt.Errorf("failed to load CA CertPool: %w", err) } // #nosec G402 tlsCfg := &tls.Config{ @@ -56,7 +54,7 @@ func (p Options) Config() (*tls.Config, error) { if p.CertPath != "" && p.KeyPath != "" { tlsCert, err := tls.LoadX509KeyPair(filepath.Clean(p.CertPath), filepath.Clean(p.KeyPath)) if err != nil { - return nil, errors.Wrap(err, "failed to load server TLS cert and key") + return nil, fmt.Errorf("failed to load server TLS cert and key: %w", err) } tlsCfg.Certificates = append(tlsCfg.Certificates, tlsCert) } @@ -77,7 +75,7 @@ func (p Options) loadCertPool() (*x509.CertPool, error) { if len(p.CAPath) == 0 { // no truststore given, use SystemCertPool certPool, err := systemCertPool() if err != nil { - return nil, errors.Wrap(err, "failed to load SystemCertPool") + return nil, fmt.Errorf("failed to load SystemCertPool: %w", err) } return certPool, nil } @@ -88,7 +86,7 @@ func (p Options) loadCertPool() (*x509.CertPool, error) { func (p Options) loadCert(caPath string) (*x509.CertPool, error) { caPEM, err := ioutil.ReadFile(filepath.Clean(caPath)) if err != nil { - return nil, errors.Wrapf(err, "failed to load CA %s", caPath) + return nil, fmt.Errorf("failed to load CA %s: %w", caPath, err) } certPool := x509.NewCertPool() diff --git a/pkg/discovery/grpcresolver/grpc_resolver_test.go b/pkg/discovery/grpcresolver/grpc_resolver_test.go index dd0ff89cedc..408b3ab3065 100644 --- a/pkg/discovery/grpcresolver/grpc_resolver_test.go +++ b/pkg/discovery/grpcresolver/grpc_resolver_test.go @@ -16,12 +16,12 @@ package grpcresolver import ( "context" + "errors" "fmt" "net" "testing" "time" - "github.com/pkg/errors" "github.com/stretchr/testify/assert" "go.uber.org/zap" "google.golang.org/grpc" diff --git a/pkg/discovery/peerlistmgr/peer_list_mgr.go b/pkg/discovery/peerlistmgr/peer_list_mgr.go index 7ce67ed39b2..27104f7a3a6 100644 --- a/pkg/discovery/peerlistmgr/peer_list_mgr.go +++ b/pkg/discovery/peerlistmgr/peer_list_mgr.go @@ -17,11 +17,11 @@ package peerlistmgr import ( "context" + "fmt" "math/rand" "sync" "time" - "github.com/pkg/errors" "github.com/uber/tchannel-go" "go.uber.org/zap" @@ -63,7 +63,7 @@ func New( instances, err := discoverer.Instances() if err != nil { - return nil, errors.Wrap(err, "cannot get initial set of instances") + return nil, fmt.Errorf("cannot get initial set of instances: %w", err) } mgr.updatePeers(instances) diff --git a/pkg/es/config/config.go b/pkg/es/config/config.go index a7e584bec3f..d28e388add3 100644 --- a/pkg/es/config/config.go +++ b/pkg/es/config/config.go @@ -18,6 +18,7 @@ package config import ( "context" "crypto/tls" + "errors" "io/ioutil" "net/http" "path/filepath" @@ -27,13 +28,12 @@ import ( "time" "github.com/olivere/elastic" - "github.com/pkg/errors" "github.com/uber/jaeger-lib/metrics" "go.uber.org/zap" "github.com/jaegertracing/jaeger/pkg/config/tlscfg" "github.com/jaegertracing/jaeger/pkg/es" - "github.com/jaegertracing/jaeger/pkg/es/wrapper" + eswrapper "github.com/jaegertracing/jaeger/pkg/es/wrapper" "github.com/jaegertracing/jaeger/storage/spanstore" storageMetrics "github.com/jaegertracing/jaeger/storage/spanstore/metrics" ) @@ -87,7 +87,7 @@ type ClientBuilder interface { // NewClient creates a new ElasticSearch client func (c *Configuration) NewClient(logger *zap.Logger, metricsFactory metrics.Factory) (es.Client, error) { if len(c.Servers) < 1 { - return nil, errors.New("No servers specified") + return nil, errors.New("no servers specified") } options, err := c.getConfigOptions(logger) if err != nil { diff --git a/pkg/kafka/auth/config.go b/pkg/kafka/auth/config.go index cf2cd06b765..7b94176f220 100644 --- a/pkg/kafka/auth/config.go +++ b/pkg/kafka/auth/config.go @@ -15,10 +15,10 @@ package auth import ( + "fmt" "strings" "github.com/Shopify/sarama" - "github.com/pkg/errors" "github.com/spf13/viper" "github.com/jaegertracing/jaeger/pkg/config/tlscfg" @@ -63,7 +63,7 @@ func (config *AuthenticationConfig) SetConfiguration(saramaConfig *sarama.Config setPlainTextConfiguration(&config.PlainText, saramaConfig) return nil default: - return errors.Errorf("Unknown/Unsupported authentication method %s to kafka cluster.", config.Authentication) + return fmt.Errorf("Unknown/Unsupported authentication method %s to kafka cluster", config.Authentication) } } diff --git a/pkg/kafka/auth/tls.go b/pkg/kafka/auth/tls.go index 852e805a31a..dd01318c7a8 100644 --- a/pkg/kafka/auth/tls.go +++ b/pkg/kafka/auth/tls.go @@ -15,8 +15,9 @@ package auth import ( + "fmt" + "github.com/Shopify/sarama" - "github.com/pkg/errors" "github.com/jaegertracing/jaeger/pkg/config/tlscfg" ) @@ -25,7 +26,7 @@ func setTLSConfiguration(config *tlscfg.Options, saramaConfig *sarama.Config) er if config.Enabled { tlsConfig, err := config.Config() if err != nil { - return errors.Wrap(err, "error loading tls config") + return fmt.Errorf("error loading tls config: %w", err) } saramaConfig.Net.TLS.Enable = true saramaConfig.Net.TLS.Config = tlsConfig diff --git a/plugin/pkg/distributedlock/cassandra/lock.go b/plugin/pkg/distributedlock/cassandra/lock.go index 7f0ccb7858d..0053c76a4d8 100644 --- a/plugin/pkg/distributedlock/cassandra/lock.go +++ b/plugin/pkg/distributedlock/cassandra/lock.go @@ -16,10 +16,10 @@ package cassandra import ( + "errors" + "fmt" "time" - "github.com/pkg/errors" - "github.com/jaegertracing/jaeger/pkg/cassandra" ) @@ -39,7 +39,7 @@ const ( ) var ( - errLockOwnership = errors.New("This host does not own the resource lock") + errLockOwnership = errors.New("this host does not own the resource lock") ) // NewLock creates a new instance of a distributed locking mechanism based off Cassandra. @@ -59,7 +59,7 @@ func (l *Lock) Acquire(resource string, ttl time.Duration) (bool, error) { var name, owner string applied, err := l.session.Query(cqlInsertLock, resource, l.tenantID, ttlSec).ScanCAS(&name, &owner) if err != nil { - return false, errors.Wrap(err, "Failed to acquire resource lock due to cassandra error") + return false, fmt.Errorf("failed to acquire resource lock due to cassandra error: %w", err) } if applied { // The lock was successfully created @@ -68,7 +68,7 @@ func (l *Lock) Acquire(resource string, ttl time.Duration) (bool, error) { if owner == l.tenantID { // This host already owns the lock, extend the lease if err = l.extendLease(resource, ttl); err != nil { - return false, errors.Wrap(err, "Failed to extend lease on resource lock") + return false, fmt.Errorf("failed to extend lease on resource lock: %w", err) } return true, nil } @@ -80,13 +80,13 @@ func (l *Lock) Forfeit(resource string) (bool, error) { var name, owner string applied, err := l.session.Query(cqlDeleteLock, resource, l.tenantID).ScanCAS(&name, &owner) if err != nil { - return false, errors.Wrap(err, "Failed to forfeit resource lock due to cassandra error") + return false, fmt.Errorf("failed to forfeit resource lock due to cassandra error: %w", err) } if applied { // The lock was successfully deleted return true, nil } - return false, errors.Wrap(errLockOwnership, "Failed to forfeit resource lock") + return false, fmt.Errorf("failed to forfeit resource lock: %w", errLockOwnership) } // extendLease will attempt to extend the lease of an existing lock on a given resource. diff --git a/plugin/pkg/distributedlock/cassandra/lock_test.go b/plugin/pkg/distributedlock/cassandra/lock_test.go index f466d9f7c06..2ff99da2dc3 100644 --- a/plugin/pkg/distributedlock/cassandra/lock_test.go +++ b/plugin/pkg/distributedlock/cassandra/lock_test.go @@ -69,7 +69,7 @@ func TestExtendLease(t *testing.T) { caption: "failed to extend lease", applied: false, errScan: nil, - expectedErrMsg: "This host does not own the resource lock", + expectedErrMsg: "this host does not own the resource lock", }, } for _, tc := range testCases { @@ -116,7 +116,7 @@ func TestAcquire(t *testing.T) { retVals: []string{"", ""}, acquired: false, errScan: errors.New("Failed to create lock"), - expectedErrMsg: "Failed to acquire resource lock due to cassandra error: Failed to create lock", + expectedErrMsg: "failed to acquire resource lock due to cassandra error: Failed to create lock", }, { caption: "successfully created lock", @@ -142,7 +142,7 @@ func TestAcquire(t *testing.T) { retVals: []string{samplingLock, localhost}, updateLockApplied: false, errScan: nil, - expectedErrMsg: "Failed to extend lease on resource lock: This host does not own the resource lock", + expectedErrMsg: "failed to extend lease on resource lock: this host does not own the resource lock", }, { caption: "failed to acquire lock", @@ -202,7 +202,7 @@ func TestForfeit(t *testing.T) { applied: false, retVals: []string{"", ""}, errScan: errors.New("Failed to delete lock"), - expectedErrMsg: "Failed to forfeit resource lock due to cassandra error: Failed to delete lock", + expectedErrMsg: "failed to forfeit resource lock due to cassandra error: Failed to delete lock", }, { caption: "successfully forfeited lock", @@ -216,7 +216,7 @@ func TestForfeit(t *testing.T) { applied: false, retVals: []string{samplingLock, "otherhost"}, errScan: nil, - expectedErrMsg: "Failed to forfeit resource lock: This host does not own the resource lock", + expectedErrMsg: "failed to forfeit resource lock: this host does not own the resource lock", }, } for _, tc := range testCases { diff --git a/plugin/sampling/strategystore/static/strategy_store.go b/plugin/sampling/strategystore/static/strategy_store.go index 6127ea8b391..78d2acae1b5 100644 --- a/plugin/sampling/strategystore/static/strategy_store.go +++ b/plugin/sampling/strategystore/static/strategy_store.go @@ -21,7 +21,6 @@ import ( "fmt" "io/ioutil" - "github.com/pkg/errors" "go.uber.org/zap" ss "github.com/jaegertracing/jaeger/cmd/collector/app/sampling/strategystore" @@ -64,11 +63,11 @@ func loadStrategies(strategiesFile string) (*strategies, error) { } bytes, err := ioutil.ReadFile(strategiesFile) /* nolint #nosec , this comes from an admin, not user */ if err != nil { - return nil, errors.Wrap(err, "Failed to open strategies file") + return nil, fmt.Errorf("failed to open strategies file: %w", err) } var strategies strategies if err := json.Unmarshal(bytes, &strategies); err != nil { - return nil, errors.Wrap(err, "Failed to unmarshal strategies") + return nil, fmt.Errorf("failed to unmarshal strategies: %w", err) } return &strategies, nil } diff --git a/plugin/sampling/strategystore/static/strategy_store_test.go b/plugin/sampling/strategystore/static/strategy_store_test.go index 61715842d5f..7a93365a98b 100644 --- a/plugin/sampling/strategystore/static/strategy_store_test.go +++ b/plugin/sampling/strategystore/static/strategy_store_test.go @@ -28,11 +28,11 @@ import ( func TestStrategyStore(t *testing.T) { _, err := NewStrategyStore(Options{StrategiesFile: "fileNotFound.json"}, zap.NewNop()) - assert.EqualError(t, err, "Failed to open strategies file: open fileNotFound.json: no such file or directory") + assert.EqualError(t, err, "failed to open strategies file: open fileNotFound.json: no such file or directory") _, err = NewStrategyStore(Options{StrategiesFile: "fixtures/bad_strategies.json"}, zap.NewNop()) assert.EqualError(t, err, - "Failed to unmarshal strategies: json: cannot unmarshal string into Go value of type static.strategies") + "failed to unmarshal strategies: json: cannot unmarshal string into Go value of type static.strategies") // Test default strategy logger, buf := testutils.NewLogger() diff --git a/plugin/storage/badger/dependencystore/storage_test.go b/plugin/storage/badger/dependencystore/storage_test.go index 7f5411927d0..5dd79d7b5d8 100644 --- a/plugin/storage/badger/dependencystore/storage_test.go +++ b/plugin/storage/badger/dependencystore/storage_test.go @@ -80,7 +80,7 @@ func TestDependencyReader(t *testing.T) { High: 1, }, SpanID: model.SpanID(j), - OperationName: fmt.Sprintf("operation-a"), + OperationName: "operation-a", Process: &model.Process{ ServiceName: fmt.Sprintf("service-%d", j), }, diff --git a/plugin/storage/badger/spanstore/read_write_test.go b/plugin/storage/badger/spanstore/read_write_test.go index b4a0ec7e698..34caf8b614f 100644 --- a/plugin/storage/badger/spanstore/read_write_test.go +++ b/plugin/storage/badger/spanstore/read_write_test.go @@ -427,9 +427,9 @@ func TestPersist(t *testing.T) { High: 1, }, SpanID: model.SpanID(4), - OperationName: fmt.Sprintf("operation-p"), + OperationName: "operation-p", Process: &model.Process{ - ServiceName: fmt.Sprintf("service-p"), + ServiceName: "service-p", }, StartTime: time.Now(), Duration: time.Duration(1 * time.Hour), diff --git a/plugin/storage/cassandra/dependencystore/bootstrap_test.go b/plugin/storage/cassandra/dependencystore/bootstrap_test.go index 34ed27dffb8..20f272f2794 100644 --- a/plugin/storage/cassandra/dependencystore/bootstrap_test.go +++ b/plugin/storage/cassandra/dependencystore/bootstrap_test.go @@ -16,9 +16,9 @@ package dependencystore import ( + "errors" "testing" - "github.com/pkg/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" diff --git a/plugin/storage/cassandra/dependencystore/storage.go b/plugin/storage/cassandra/dependencystore/storage.go index 521704ab263..e4c76197576 100644 --- a/plugin/storage/cassandra/dependencystore/storage.go +++ b/plugin/storage/cassandra/dependencystore/storage.go @@ -16,9 +16,10 @@ package dependencystore import ( + "errors" + "fmt" "time" - "github.com/pkg/errors" "github.com/uber/jaeger-lib/metrics" "go.uber.org/zap" @@ -133,7 +134,7 @@ func (s *DependencyStore) GetDependencies(endTs time.Time, lookback time.Duratio if err := iter.Close(); err != nil { s.logger.Error("Failure to read Dependencies", zap.Time("endTs", endTs), zap.Duration("lookback", lookback), zap.Error(err)) - return nil, errors.Wrap(err, "Error reading dependencies from storage") + return nil, fmt.Errorf("error reading dependencies from storage: %w", err) } return mDependency, nil } diff --git a/plugin/storage/cassandra/dependencystore/storage_test.go b/plugin/storage/cassandra/dependencystore/storage_test.go index c16770be251..36f998dc182 100644 --- a/plugin/storage/cassandra/dependencystore/storage_test.go +++ b/plugin/storage/cassandra/dependencystore/storage_test.go @@ -166,7 +166,7 @@ func TestDependencyStoreGetDependencies(t *testing.T) { { caption: "failure V1", queryError: errors.New("query error"), - expectedError: "Error reading dependencies from storage: query error", + expectedError: "error reading dependencies from storage: query error", expectedLogs: []string{ "Failure to read Dependencies", }, @@ -175,7 +175,7 @@ func TestDependencyStoreGetDependencies(t *testing.T) { { caption: "failure V2", queryError: errors.New("query error"), - expectedError: "Error reading dependencies from storage: query error", + expectedError: "error reading dependencies from storage: query error", expectedLogs: []string{ "Failure to read Dependencies", }, diff --git a/plugin/storage/cassandra/samplingstore/storage.go b/plugin/storage/cassandra/samplingstore/storage.go index a796c2d739e..f3c0693f88a 100644 --- a/plugin/storage/cassandra/samplingstore/storage.go +++ b/plugin/storage/cassandra/samplingstore/storage.go @@ -18,13 +18,13 @@ package samplingstore import ( "bytes" "encoding/csv" + "fmt" "io" "strconv" "strings" "time" "github.com/gocql/gocql" - "github.com/pkg/errors" "github.com/uber/jaeger-lib/metrics" "go.uber.org/zap" @@ -86,7 +86,7 @@ func (s *SamplingStore) GetThroughput(start, end time.Time) ([]*model.Throughput throughput = append(throughput, s.stringToThroughput(throughputStr)...) } if err := iter.Close(); err != nil { - err = errors.Wrap(err, "Error reading throughput from storage") + err = fmt.Errorf("error reading throughput from storage: %w", err) return nil, err } return throughput, nil @@ -109,7 +109,7 @@ func (s *SamplingStore) GetLatestProbabilities() (model.ServiceOperationProbabil var probabilitiesStr string iter.Scan(&probabilitiesStr) if err := iter.Close(); err != nil { - err = errors.Wrap(err, "Error reading probabilities from storage") + err = fmt.Errorf("error reading probabilities from storage: %w", err) return nil, err } return s.stringToProbabilities(probabilitiesStr), nil @@ -124,7 +124,7 @@ func (s *SamplingStore) GetProbabilitiesAndQPS(start, end time.Time) (map[string hostProbabilitiesAndQPS[host] = append(hostProbabilitiesAndQPS[host], s.stringToProbabilitiesAndQPS(probabilitiesAndQPSStr)) } if err := iter.Close(); err != nil { - err = errors.Wrap(err, "Error reading probabilities and qps from storage") + err = fmt.Errorf("error reading probabilities and qps from storage: %w", err) return nil, err } return hostProbabilitiesAndQPS, nil diff --git a/plugin/storage/cassandra/samplingstore/storage_test.go b/plugin/storage/cassandra/samplingstore/storage_test.go index af963d4babc..4662434ea4b 100644 --- a/plugin/storage/cassandra/samplingstore/storage_test.go +++ b/plugin/storage/cassandra/samplingstore/storage_test.go @@ -158,7 +158,7 @@ func TestGetThroughput(t *testing.T) { { caption: "failure", queryError: errors.New("query error"), - expectedError: "Error reading throughput from storage: query error", + expectedError: "error reading throughput from storage: query error", }, } for _, tc := range testCases { @@ -237,7 +237,7 @@ func TestGetProbabilitiesAndQPS(t *testing.T) { { caption: "failure", queryError: errors.New("query error"), - expectedError: "Error reading probabilities and qps from storage: query error", + expectedError: "error reading probabilities and qps from storage: query error", }, } for _, tc := range testCases { @@ -303,7 +303,7 @@ func TestGetLatestProbabilities(t *testing.T) { { caption: "failure", queryError: errors.New("query error"), - expectedError: "Error reading probabilities from storage: query error", + expectedError: "error reading probabilities from storage: query error", }, } for _, tc := range testCases { diff --git a/plugin/storage/cassandra/spanstore/operation_names.go b/plugin/storage/cassandra/spanstore/operation_names.go index c3e13bc4f96..dfa3150b49f 100644 --- a/plugin/storage/cassandra/spanstore/operation_names.go +++ b/plugin/storage/cassandra/spanstore/operation_names.go @@ -19,7 +19,6 @@ import ( "fmt" "time" - "github.com/pkg/errors" "github.com/uber/jaeger-lib/metrics" "go.uber.org/zap" @@ -178,7 +177,7 @@ func getOperationsV1( }) } if err := iter.Close(); err != nil { - err = errors.Wrap(err, "Error reading operation_names from storage") + err = fmt.Errorf("error reading operation_names from storage: %w", err) return nil, err } @@ -209,7 +208,7 @@ func getOperationsV2( }) } if err := iter.Close(); err != nil { - err = errors.Wrap(err, fmt.Sprintf("Error reading %s from storage", s.table.tableName)) + err = fmt.Errorf("error reading %s from storage: %w", s.table.tableName, err) return nil, err } return operations, nil diff --git a/plugin/storage/cassandra/spanstore/operation_names_test.go b/plugin/storage/cassandra/spanstore/operation_names_test.go index 56a0a84cc7d..bfa6b441a72 100644 --- a/plugin/storage/cassandra/spanstore/operation_names_test.go +++ b/plugin/storage/cassandra/spanstore/operation_names_test.go @@ -193,7 +193,7 @@ func TestOperationNamesStorageGetServices(t *testing.T) { assert.EqualError( t, err, - fmt.Sprintf("Error reading %s from storage: %s", + fmt.Sprintf("error reading %s from storage: %s", schemas[test.schemaVersion].tableName, test.expErr.Error()), ) diff --git a/plugin/storage/cassandra/spanstore/reader.go b/plugin/storage/cassandra/spanstore/reader.go index 09a69b7ff40..1880335f8ab 100644 --- a/plugin/storage/cassandra/spanstore/reader.go +++ b/plugin/storage/cassandra/spanstore/reader.go @@ -17,12 +17,13 @@ package spanstore import ( "context" + "errors" + "fmt" "time" "github.com/opentracing/opentracing-go" ottag "github.com/opentracing/opentracing-go/ext" otlog "github.com/opentracing/opentracing-go/log" - "github.com/pkg/errors" "github.com/uber/jaeger-lib/metrics" "go.uber.org/zap" @@ -71,22 +72,22 @@ const ( var ( // ErrServiceNameNotSet occurs when attempting to query with an empty service name - ErrServiceNameNotSet = errors.New("Service Name must be set") + ErrServiceNameNotSet = errors.New("service Name must be set") // ErrStartTimeMinGreaterThanMax occurs when start time min is above start time max - ErrStartTimeMinGreaterThanMax = errors.New("Start Time Minimum is above Maximum") + ErrStartTimeMinGreaterThanMax = errors.New("start Time Minimum is above Maximum") // ErrDurationMinGreaterThanMax occurs when duration min is above duration max - ErrDurationMinGreaterThanMax = errors.New("Duration Minimum is above Maximum") + ErrDurationMinGreaterThanMax = errors.New("duration Minimum is above Maximum") // ErrMalformedRequestObject occurs when a request object is nil - ErrMalformedRequestObject = errors.New("Malformed request object") + ErrMalformedRequestObject = errors.New("malformed request object") // ErrDurationAndTagQueryNotSupported occurs when duration and tags are both set - ErrDurationAndTagQueryNotSupported = errors.New("Cannot query for duration and tags simultaneously") + ErrDurationAndTagQueryNotSupported = errors.New("cannot query for duration and tags simultaneously") // ErrStartAndEndTimeNotSet occurs when start time and end time are not set - ErrStartAndEndTimeNotSet = errors.New("Start and End Time must be set") + ErrStartAndEndTimeNotSet = errors.New("start and End Time must be set") ) type serviceNamesReader func() ([]string, error) @@ -199,7 +200,7 @@ func (s *SpanReader) readTraceInSpan(ctx context.Context, traceID dbmodel.TraceI err := i.Close() s.metrics.readTraces.Emit(err, time.Since(start)) if err != nil { - return nil, errors.Wrap(err, "Error reading traces from storage") + return nil, fmt.Errorf("error reading traces from storage: %w", err) } if len(retMe.Spans) == 0 { return nil, spanstore.ErrTraceNotFound diff --git a/plugin/storage/cassandra/spanstore/reader_test.go b/plugin/storage/cassandra/spanstore/reader_test.go index abb757acc4f..1aedd0c805a 100644 --- a/plugin/storage/cassandra/spanstore/reader_test.go +++ b/plugin/storage/cassandra/spanstore/reader_test.go @@ -116,7 +116,7 @@ func TestSpanReaderGetTrace(t *testing.T) { { scanner: matchOnce(), closeErr: errors.New("error on close()"), - expectedErr: "Error reading traces from storage: error on close()", + expectedErr: "error reading traces from storage: error on close()", }, } for _, tc := range testCases { @@ -278,7 +278,7 @@ func TestSpanReaderFindTraces(t *testing.T) { expectedCount: 0, expectedLogs: []string{ "Failure to read trace", - "Error reading traces from storage: load query error", + "error reading traces from storage: load query error", `"trace_id":"0000000000000001"`, `"trace_id":"0000000000000002"`, }, diff --git a/plugin/storage/cassandra/spanstore/service_names.go b/plugin/storage/cassandra/spanstore/service_names.go index c4dc4a67d0e..98dc192d78f 100644 --- a/plugin/storage/cassandra/spanstore/service_names.go +++ b/plugin/storage/cassandra/spanstore/service_names.go @@ -16,9 +16,9 @@ package spanstore import ( + "fmt" "time" - "github.com/pkg/errors" "github.com/uber/jaeger-lib/metrics" "go.uber.org/zap" @@ -104,7 +104,7 @@ func (s *ServiceNamesStorage) GetServices() ([]string, error) { services = append(services, service) } if err := iter.Close(); err != nil { - err = errors.Wrap(err, "Error reading service_names from storage") + err = fmt.Errorf("error reading service_names from storage: %w", err) return nil, err } return services, nil diff --git a/plugin/storage/cassandra/spanstore/service_names_test.go b/plugin/storage/cassandra/spanstore/service_names_test.go index 380340ead4a..958ad586b41 100644 --- a/plugin/storage/cassandra/spanstore/service_names_test.go +++ b/plugin/storage/cassandra/spanstore/service_names_test.go @@ -137,7 +137,7 @@ func TestServiceNamesStorageGetServices(t *testing.T) { // expect empty string because mock iter.Scan(&placeholder) does not write to `placeholder` assert.Equal(t, []string{""}, services) } else { - assert.EqualError(t, err, "Error reading service_names from storage: "+expErr.Error()) + assert.EqualError(t, err, "error reading service_names from storage: "+expErr.Error()) } }) diff --git a/plugin/storage/cassandra/spanstore/writer.go b/plugin/storage/cassandra/spanstore/writer.go index 364ef593cc7..ecb16388a0c 100644 --- a/plugin/storage/cassandra/spanstore/writer.go +++ b/plugin/storage/cassandra/spanstore/writer.go @@ -17,11 +17,11 @@ package spanstore import ( "encoding/json" + "fmt" "strings" "time" "unicode/utf8" - "github.com/pkg/errors" "github.com/uber/jaeger-lib/metrics" "go.uber.org/zap" @@ -276,7 +276,7 @@ func (s *SpanWriter) logError(span *dbmodel.Span, err error, msg string, logger With(zap.Int64("span_id", span.SpanID)). With(zap.Error(err)). Error(msg) - return errors.Wrap(err, msg) + return fmt.Errorf("%s: %w", msg, err) } func (s *SpanWriter) saveServiceNameAndOperationName(operation dbmodel.Operation) error { diff --git a/plugin/storage/es/dependencystore/storage.go b/plugin/storage/es/dependencystore/storage.go index 90d0eea1901..160445c5775 100644 --- a/plugin/storage/es/dependencystore/storage.go +++ b/plugin/storage/es/dependencystore/storage.go @@ -18,10 +18,11 @@ package dependencystore import ( "context" "encoding/json" + "errors" + "fmt" "time" "github.com/olivere/elastic" - "github.com/pkg/errors" "go.uber.org/zap" "github.com/jaegertracing/jaeger/model" @@ -69,7 +70,7 @@ func (s *DependencyStore) WriteDependencies(ts time.Time, dependencies []model.D func (s *DependencyStore) createIndex(indexName string) error { _, err := s.client.CreateIndex(indexName).Body(getMapping(s.client.GetVersion())).Do(s.ctx) if err != nil { - return errors.Wrap(err, "Failed to create index") + return fmt.Errorf("failed to create index: %w", err) } return nil } @@ -90,7 +91,7 @@ func (s *DependencyStore) GetDependencies(endTs time.Time, lookback time.Duratio IgnoreUnavailable(true). Do(s.ctx) if err != nil { - return nil, errors.Wrap(err, "Failed to search for dependencies") + return nil, fmt.Errorf("failed to search for dependencies: %w", err) } var retDependencies []dbmodel.DependencyLink @@ -99,7 +100,7 @@ func (s *DependencyStore) GetDependencies(endTs time.Time, lookback time.Duratio source := hit.Source var tToD dbmodel.TimeDependencies if err := json.Unmarshal(*source, &tToD); err != nil { - return nil, errors.New("Unmarshalling ElasticSearch documents failed") + return nil, errors.New("unmarshalling ElasticSearch documents failed") } retDependencies = append(retDependencies, tToD.Dependencies...) } diff --git a/plugin/storage/es/dependencystore/storage_test.go b/plugin/storage/es/dependencystore/storage_test.go index 91b71e9cc02..2058436e0d3 100644 --- a/plugin/storage/es/dependencystore/storage_test.go +++ b/plugin/storage/es/dependencystore/storage_test.go @@ -17,12 +17,12 @@ package dependencystore import ( "encoding/json" + "errors" "strings" "testing" "time" "github.com/olivere/elastic" - "github.com/pkg/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "go.uber.org/zap" @@ -80,12 +80,12 @@ func TestWriteDependencies(t *testing.T) { }{ { createIndexError: errors.New("index not created"), - expectedError: "Failed to create index: index not created", + expectedError: "failed to create index: index not created", esVersion: 6, }, { createIndexError: errors.New("index not created"), - expectedError: "Failed to create index: index not created", + expectedError: "failed to create index: index not created", esVersion: 7, }, } @@ -157,17 +157,17 @@ func TestGetDependencies(t *testing.T) { }, { searchResult: createSearchResult(badDependencies), - expectedError: "Unmarshalling ElasticSearch documents failed", + expectedError: "unmarshalling ElasticSearch documents failed", indices: []interface{}{"jaeger-dependencies-1995-04-21", "jaeger-dependencies-1995-04-20"}, }, { searchError: errors.New("search failure"), - expectedError: "Failed to search for dependencies: search failure", + expectedError: "failed to search for dependencies: search failure", indices: []interface{}{"jaeger-dependencies-1995-04-21", "jaeger-dependencies-1995-04-20"}, }, { searchError: errors.New("search failure"), - expectedError: "Failed to search for dependencies: search failure", + expectedError: "failed to search for dependencies: search failure", indexPrefix: "foo", indices: []interface{}{"foo-jaeger-dependencies-1995-04-21", "foo-jaeger-dependencies-1995-04-20"}, }, diff --git a/plugin/storage/es/factory.go b/plugin/storage/es/factory.go index 7960470ce6f..48acf346f86 100644 --- a/plugin/storage/es/factory.go +++ b/plugin/storage/es/factory.go @@ -18,12 +18,12 @@ package es import ( "bufio" "flag" + "fmt" "os" "path/filepath" "strconv" "strings" - "github.com/pkg/errors" "github.com/spf13/viper" "github.com/uber/jaeger-lib/metrics" "go.uber.org/zap" @@ -80,13 +80,13 @@ func (f *Factory) Initialize(metricsFactory metrics.Factory, logger *zap.Logger) primaryClient, err := f.primaryConfig.NewClient(logger, metricsFactory) if err != nil { - return errors.Wrap(err, "failed to create primary Elasticsearch client") + return fmt.Errorf("failed to create primary Elasticsearch client: %w", err) } f.primaryClient = primaryClient if f.archiveConfig.IsEnabled() { f.archiveClient, err = f.archiveConfig.NewClient(logger, metricsFactory) if err != nil { - return errors.Wrap(err, "failed to create archive Elasticsearch client") + return fmt.Errorf("failed to create archive Elasticsearch client: %w", err) } } return nil diff --git a/plugin/storage/es/spanstore/dbmodel/to_domain.go b/plugin/storage/es/spanstore/dbmodel/to_domain.go index a9e19579d27..06adefe5602 100644 --- a/plugin/storage/es/spanstore/dbmodel/to_domain.go +++ b/plugin/storage/es/spanstore/dbmodel/to_domain.go @@ -22,8 +22,6 @@ import ( "strconv" "strings" - "github.com/pkg/errors" - "github.com/jaegertracing/jaeger/model" ) @@ -188,7 +186,7 @@ func (td ToDomain) convertTagField(k string, v interface{}) (model.KeyValue, err if err == nil { return model.Float64(dKey, f), nil } - return model.String("", ""), errors.Wrapf(err, "invalid tag type in %+v", v) + return model.String("", ""), fmt.Errorf("invalid tag type in %+v: %w", v, err) default: return model.String("", ""), fmt.Errorf("invalid tag type in %+v", v) } diff --git a/plugin/storage/es/spanstore/reader.go b/plugin/storage/es/spanstore/reader.go index 29124eda749..4ac8e3cbb9a 100644 --- a/plugin/storage/es/spanstore/reader.go +++ b/plugin/storage/es/spanstore/reader.go @@ -19,6 +19,7 @@ import ( "bytes" "context" "encoding/json" + "errors" "fmt" "time" @@ -26,7 +27,6 @@ import ( "github.com/opentracing/opentracing-go" ottag "github.com/opentracing/opentracing-go/ext" otlog "github.com/opentracing/opentracing-go/log" - "github.com/pkg/errors" "github.com/uber/jaeger-lib/metrics" "go.uber.org/zap" @@ -64,22 +64,22 @@ const ( var ( // ErrServiceNameNotSet occurs when attempting to query with an empty service name - ErrServiceNameNotSet = errors.New("Service Name must be set") + ErrServiceNameNotSet = errors.New("service Name must be set") // ErrStartTimeMinGreaterThanMax occurs when start time min is above start time max - ErrStartTimeMinGreaterThanMax = errors.New("Start Time Minimum is above Maximum") + ErrStartTimeMinGreaterThanMax = errors.New("start Time Minimum is above Maximum") // ErrDurationMinGreaterThanMax occurs when duration min is above duration max - ErrDurationMinGreaterThanMax = errors.New("Duration Minimum is above Maximum") + ErrDurationMinGreaterThanMax = errors.New("duration Minimum is above Maximum") // ErrMalformedRequestObject occurs when a request object is nil - ErrMalformedRequestObject = errors.New("Malformed request object") + ErrMalformedRequestObject = errors.New("malformed request object") // ErrStartAndEndTimeNotSet occurs when start time and end time are not set - ErrStartAndEndTimeNotSet = errors.New("Start and End Time must be set") + ErrStartAndEndTimeNotSet = errors.New("start and End Time must be set") // ErrUnableToFindTraceIDAggregation occurs when an aggregation query for TraceIDs fail. - ErrUnableToFindTraceIDAggregation = errors.New("Could not find aggregation of traceIDs") + ErrUnableToFindTraceIDAggregation = errors.New("could not find aggregation of traceIDs") defaultMaxDuration = model.DurationAsMicroseconds(time.Hour * 24) @@ -211,11 +211,11 @@ func (s *SpanReader) collectSpans(esSpansRaw []*elastic.SearchHit) ([]*model.Spa for i, esSpanRaw := range esSpansRaw { jsonSpan, err := s.unmarshalJSONSpan(esSpanRaw) if err != nil { - return nil, errors.Wrap(err, "Marshalling JSON to span object failed") + return nil, fmt.Errorf("marshalling JSON to span object failed: %w", err) } span, err := s.spanConverter.SpanToDomain(jsonSpan) if err != nil { - return nil, errors.Wrap(err, "Converting JSONSpan to domain Span failed") + return nil, fmt.Errorf("converting JSONSpan to domain Span failed: %w", err) } spans[i] = span } @@ -274,7 +274,7 @@ func bucketToStringArray(buckets []*elastic.AggregationBucketKeyItem) ([]string, for i, keyitem := range buckets { str, ok := keyitem.Key.(string) if !ok { - return nil, errors.New("Non-string key found in aggregation") + return nil, errors.New("non-string key found in aggregation") } strings[i] = str } @@ -423,7 +423,7 @@ func convertTraceIDsStringsToModels(traceIDs []string) ([]model.TraceID, error) for _, ID := range traceIDs { traceID, err := model.TraceIDFromString(ID) if err != nil { - return nil, errors.Wrap(err, fmt.Sprintf("Making traceID from string '%s' failed", ID)) + return nil, fmt.Errorf("making traceID from string '%s' failed: %w", ID, err) } if _, ok := traceIDsMap[traceID]; !ok { traceIDsMap[traceID] = true @@ -521,7 +521,7 @@ func (s *SpanReader) findTraceIDs(ctx context.Context, traceQuery *spanstore.Tra searchResult, err := searchService.Do(ctx) if err != nil { - return nil, errors.Wrap(err, "Search service failed") + return nil, fmt.Errorf("search services failed: %w", err) } if searchResult.Aggregations == nil { return []string{}, nil diff --git a/plugin/storage/es/spanstore/reader_test.go b/plugin/storage/es/spanstore/reader_test.go index 62f7e63eb58..5d3e4a20bf5 100644 --- a/plugin/storage/es/spanstore/reader_test.go +++ b/plugin/storage/es/spanstore/reader_test.go @@ -491,7 +491,7 @@ func testGet(typ string, t *testing.T) { caption string searchResult *elastic.SearchResult searchError error - expectedError string + expectedError func() string expectedOutput map[string]interface{} }{ { @@ -501,16 +501,26 @@ func testGet(typ string, t *testing.T) { operationsAggregation: []spanstore.Operation{{Name: "123"}}, "default": []string{"123"}, }, + expectedError: func() string { + return "" + }, }, { - caption: typ + " search error", - searchError: errors.New("Search failure"), - expectedError: "Search service failed: Search failure", + caption: typ + " search error", + searchError: errors.New("Search failure"), + expectedError: func() string { + if typ == operationsAggregation { + return "search operations failed: Search failure" + } + return "search services failed: Search failure" + }, }, { - caption: typ + " search error", - searchResult: &elastic.SearchResult{Aggregations: elastic.Aggregations(badAggregations)}, - expectedError: "Could not find aggregation of " + typ, + caption: typ + " search error", + searchResult: &elastic.SearchResult{Aggregations: elastic.Aggregations(badAggregations)}, + expectedError: func() string { + return "could not find aggregation of " + typ + }, }, } @@ -520,8 +530,8 @@ func testGet(typ string, t *testing.T) { withSpanReader(func(r *spanReaderTest) { mockSearchService(r).Return(testCase.searchResult, testCase.searchError) actual, err := returnSearchFunc(typ, r) - if testCase.expectedError != "" { - require.EqualError(t, err, testCase.expectedError) + if testCase.expectedError() != "" { + require.EqualError(t, err, testCase.expectedError()) assert.Nil(t, actual) } else if expectedOutput, ok := testCase.expectedOutput[typ]; ok { assert.EqualValues(t, expectedOutput, actual) @@ -568,7 +578,7 @@ func TestSpanReader_bucketToStringArrayError(t *testing.T) { buckets[2] = &elastic.AggregationBucketKeyItem{Key: 2} _, err := bucketToStringArray(buckets) - assert.EqualError(t, err, "Non-string key found in aggregation") + assert.EqualError(t, err, "non-string key found in aggregation") }) } @@ -804,7 +814,7 @@ func TestTraceIDsStringsToModelsConversion(t *testing.T) { assert.Equal(t, model.NewTraceID(0, 1), traceIDs[0]) traceIDs, err = convertTraceIDsStringsToModels([]string{"dsfjsdklfjdsofdfsdbfkgbgoaemlrksdfbsdofgerjl"}) - assert.EqualError(t, err, "Making traceID from string 'dsfjsdklfjdsofdfsdbfkgbgoaemlrksdfbsdofgerjl' failed: TraceID cannot be longer than 32 hex characters: dsfjsdklfjdsofdfsdbfkgbgoaemlrksdfbsdofgerjl") + assert.EqualError(t, err, "making traceID from string 'dsfjsdklfjdsofdfsdbfkgbgoaemlrksdfbsdofgerjl' failed: TraceID cannot be longer than 32 hex characters: dsfjsdklfjdsofdfsdbfkgbgoaemlrksdfbsdofgerjl") assert.Equal(t, 0, len(traceIDs)) } diff --git a/plugin/storage/es/spanstore/service_operation.go b/plugin/storage/es/spanstore/service_operation.go index e394a0a20eb..44f2acb8a24 100644 --- a/plugin/storage/es/spanstore/service_operation.go +++ b/plugin/storage/es/spanstore/service_operation.go @@ -17,12 +17,12 @@ package spanstore import ( "context" + "errors" "fmt" "hash/fnv" "time" "github.com/olivere/elastic" - "github.com/pkg/errors" "go.uber.org/zap" "github.com/jaegertracing/jaeger/pkg/cache" @@ -87,14 +87,14 @@ func (s *ServiceOperationStorage) getServices(context context.Context, indices [ searchResult, err := searchService.Do(context) if err != nil { - return nil, errors.Wrap(err, "Search service failed") + return nil, fmt.Errorf("search services failed: %w", err) } if searchResult.Aggregations == nil { return []string{}, nil } bucket, found := searchResult.Aggregations.Terms(servicesAggregation) if !found { - return nil, errors.New("Could not find aggregation of " + servicesAggregation) + return nil, errors.New("could not find aggregation of " + servicesAggregation) } serviceNamesBucket := bucket.Buckets return bucketToStringArray(serviceNamesBucket) @@ -118,14 +118,14 @@ func (s *ServiceOperationStorage) getOperations(context context.Context, indices searchResult, err := searchService.Do(context) if err != nil { - return nil, errors.Wrap(err, "Search service failed") + return nil, fmt.Errorf("search operations failed: %w", err) } if searchResult.Aggregations == nil { return []string{}, nil } bucket, found := searchResult.Aggregations.Terms(operationsAggregation) if !found { - return nil, errors.New("Could not find aggregation of " + operationsAggregation) + return nil, errors.New("could not find aggregation of " + operationsAggregation) } operationNamesBucket := bucket.Buckets return bucketToStringArray(operationNamesBucket) diff --git a/plugin/storage/grpc/shared/grpc_client.go b/plugin/storage/grpc/shared/grpc_client.go index 8616509cb68..8f84ded370c 100644 --- a/plugin/storage/grpc/shared/grpc_client.go +++ b/plugin/storage/grpc/shared/grpc_client.go @@ -16,10 +16,10 @@ package shared import ( "context" + "fmt" "io" "time" - "github.com/pkg/errors" "google.golang.org/grpc/metadata" "google.golang.org/grpc/status" @@ -71,7 +71,7 @@ func (c *grpcClient) GetTrace(ctx context.Context, traceID model.TraceID) (*mode TraceID: traceID, }) if err != nil { - return nil, errors.Wrap(err, "plugin error") + return nil, fmt.Errorf("plugin error: %w", err) } trace := model.Trace{} @@ -82,7 +82,7 @@ func (c *grpcClient) GetTrace(ctx context.Context, traceID model.TraceID) (*mode return nil, spanstore.ErrTraceNotFound } } - return nil, errors.Wrap(err, "grpc stream error") + return nil, fmt.Errorf("grpc stream error: %w", err) } for i := range received.Spans { @@ -97,7 +97,7 @@ func (c *grpcClient) GetTrace(ctx context.Context, traceID model.TraceID) (*mode func (c *grpcClient) GetServices(ctx context.Context) ([]string, error) { resp, err := c.readerClient.GetServices(upgradeContextWithBearerToken(ctx), &storage_v1.GetServicesRequest{}) if err != nil { - return nil, errors.Wrap(err, "plugin error") + return nil, fmt.Errorf("plugin error: %w", err) } return resp.Services, nil @@ -113,7 +113,7 @@ func (c *grpcClient) GetOperations( SpanKind: query.SpanKind, }) if err != nil { - return nil, errors.Wrap(err, "plugin error") + return nil, fmt.Errorf("plugin error: %w", err) } var operations []spanstore.Operation @@ -149,7 +149,7 @@ func (c *grpcClient) FindTraces(ctx context.Context, query *spanstore.TraceQuery }, }) if err != nil { - return nil, errors.Wrap(err, "plugin error") + return nil, fmt.Errorf("plugin error: %w", err) } var traces []*model.Trace @@ -157,7 +157,7 @@ func (c *grpcClient) FindTraces(ctx context.Context, query *spanstore.TraceQuery var traceID model.TraceID for received, err := stream.Recv(); err != io.EOF; received, err = stream.Recv() { if err != nil { - return nil, errors.Wrap(err, "stream error") + return nil, fmt.Errorf("stream error: %w", err) } for i, span := range received.Spans { @@ -187,7 +187,7 @@ func (c *grpcClient) FindTraceIDs(ctx context.Context, query *spanstore.TraceQue }, }) if err != nil { - return nil, errors.Wrap(err, "plugin error") + return nil, fmt.Errorf("plugin error: %w", err) } return resp.TraceIDs, nil @@ -199,7 +199,7 @@ func (c *grpcClient) WriteSpan(span *model.Span) error { Span: span, }) if err != nil { - return errors.Wrap(err, "plugin error") + return fmt.Errorf("plugin error: %w", err) } return nil @@ -212,7 +212,7 @@ func (c *grpcClient) GetDependencies(endTs time.Time, lookback time.Duration) ([ StartTime: endTs.Add(-lookback), }) if err != nil { - return nil, errors.Wrap(err, "plugin error") + return nil, fmt.Errorf("plugin error: %w", err) } return resp.Dependencies, nil diff --git a/plugin/storage/grpc/shared/grpc_server.go b/plugin/storage/grpc/shared/grpc_server.go index abf6597f5cd..b4137b15e88 100644 --- a/plugin/storage/grpc/shared/grpc_server.go +++ b/plugin/storage/grpc/shared/grpc_server.go @@ -16,8 +16,7 @@ package shared import ( "context" - - "github.com/pkg/errors" + "fmt" "github.com/jaegertracing/jaeger/model" "github.com/jaegertracing/jaeger/proto-gen/storage_v1" @@ -155,7 +154,7 @@ func (s *grpcServer) sendSpans(spans []*model.Span, sendFn func(*storage_v1.Span chunk = append(chunk, *spans[j]) } if err := sendFn(&storage_v1.SpansResponseChunk{Spans: chunk}); err != nil { - return errors.Wrap(err, "grpc plugin failed to send response") + return fmt.Errorf("grpc plugin failed to send response: %w", err) } } diff --git a/plugin/storage/integration/cassandra_test.go b/plugin/storage/integration/cassandra_test.go index 6089d70a536..b4048af6ef3 100644 --- a/plugin/storage/integration/cassandra_test.go +++ b/plugin/storage/integration/cassandra_test.go @@ -16,11 +16,11 @@ package integration import ( + "errors" "os" "testing" "time" - "github.com/pkg/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/uber/jaeger-lib/metrics" diff --git a/plugin/storage/integration/elasticsearch_test.go b/plugin/storage/integration/elasticsearch_test.go index de138819330..423027bd05d 100644 --- a/plugin/storage/integration/elasticsearch_test.go +++ b/plugin/storage/integration/elasticsearch_test.go @@ -17,6 +17,7 @@ package integration import ( "context" + "errors" "net/http" "os" "strconv" @@ -24,7 +25,6 @@ import ( "time" "github.com/olivere/elastic" - "github.com/pkg/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/uber/jaeger-lib/metrics" diff --git a/plugin/storage/kafka/writer_test.go b/plugin/storage/kafka/writer_test.go index c397c8fb726..51a36cc916f 100644 --- a/plugin/storage/kafka/writer_test.go +++ b/plugin/storage/kafka/writer_test.go @@ -15,12 +15,12 @@ package kafka import ( + "errors" "testing" "time" "github.com/Shopify/sarama" saramaMocks "github.com/Shopify/sarama/mocks" - "github.com/pkg/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/uber/jaeger-lib/metrics/metricstest"