diff --git a/.golangci.yml b/.golangci.yml
index bd43de248f8..567a6915e69 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -155,10 +155,6 @@ linters-settings:
enable-all-rules: true
# See https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md
rules:
- # not a completely bad linter, but needs clean-up and sensible width (80 is too small)
- - name: line-length-limit
- disabled: true
- arguments: [80]
# would be ok if we could exclude the test files, but otherwise too noisy
- name: add-constant
disabled: true
diff --git a/cmd/agent/app/agent.go b/cmd/agent/app/agent.go
index 0da0a057d70..5ad2a757cb2 100644
--- a/cmd/agent/app/agent.go
+++ b/cmd/agent/app/agent.go
@@ -69,7 +69,10 @@ func (a *Agent) Run() error {
a.httpAddr.Store(listener.Addr().String())
a.exitWG.Add(1)
go func() {
- a.logger.Info("Starting jaeger-agent HTTP server", zap.Int("http-port", listener.Addr().(*net.TCPAddr).Port))
+ a.logger.Info(
+ "Starting jaeger-agent HTTP server",
+ zap.Int("http-port", listener.Addr().(*net.TCPAddr).Port),
+ )
if err := a.httpServer.Serve(listener); err != http.ErrServerClosed {
a.logger.Error("http server failure", zap.Error(err))
}
@@ -90,7 +93,10 @@ func (a *Agent) HTTPAddr() string {
// Stop forces all agent go routines to exit.
func (a *Agent) Stop() {
// first, close the http server, so that we don't have any more inflight requests
- a.logger.Info("shutting down agent's HTTP server", zap.String("addr", a.HTTPAddr()))
+ a.logger.Info(
+ "shutting down agent's HTTP server",
+ zap.String("addr", a.HTTPAddr()),
+ )
timeout, cancel := context.WithTimeout(context.Background(), 5*time.Second)
if err := a.httpServer.Shutdown(timeout); err != nil {
a.logger.Error("failed to close HTTP server", zap.Error(err))
diff --git a/cmd/agent/app/agent_test.go b/cmd/agent/app/agent_test.go
index 866523cede9..8cd164ad3b4 100644
--- a/cmd/agent/app/agent_test.go
+++ b/cmd/agent/app/agent_test.go
@@ -35,7 +35,11 @@ import (
func TestAgentStartError(t *testing.T) {
cfg := &Builder{}
- agent, err := cfg.CreateAgent(fakeCollectorProxy{}, zap.NewNop(), metrics.NullFactory)
+ agent, err := cfg.CreateAgent(
+ fakeCollectorProxy{},
+ zap.NewNop(),
+ metrics.NullFactory,
+ )
require.NoError(t, err)
agent.httpServer.Addr = "bad-address"
require.Error(t, agent.Run())
@@ -100,13 +104,19 @@ func withRunningAgent(t *testing.T, testcase func(string, chan error)) {
}
logger, logBuf := testutils.NewLogger()
- mBldr := &metricsbuilder.Builder{HTTPRoute: "/metrics", Backend: "prometheus"}
+ mBldr := &metricsbuilder.Builder{
+ HTTPRoute: "/metrics",
+ Backend: "prometheus",
+ }
metricsFactory, err := mBldr.CreateMetricsFactory("jaeger")
require.NoError(t, err)
agent, err := cfg.CreateAgent(fakeCollectorProxy{}, logger, metricsFactory)
require.NoError(t, err)
if h := mBldr.Handler(); metricsFactory != nil && h != nil {
- logger.Info("Registering metrics handler with HTTP server", zap.String("route", mBldr.HTTPRoute))
+ logger.Info(
+ "Registering metrics handler with HTTP server",
+ zap.String("route", mBldr.HTTPRoute),
+ )
agent.GetHTTPRouter().Handle(mBldr.HTTPRoute, h).Methods(http.MethodGet)
}
ch := make(chan error, 2)
@@ -154,7 +164,10 @@ func TestStartStopRace(t *testing.T) {
},
}
logger, logBuf := testutils.NewEchoLogger(t)
- mBldr := &metricsbuilder.Builder{HTTPRoute: "/metrics", Backend: "prometheus"}
+ mBldr := &metricsbuilder.Builder{
+ HTTPRoute: "/metrics",
+ Backend: "prometheus",
+ }
metricsFactory, err := mBldr.CreateMetricsFactory("jaeger")
require.NoError(t, err)
agent, err := cfg.CreateAgent(fakeCollectorProxy{}, logger, metricsFactory)
@@ -197,10 +210,17 @@ func TestStartStopWithSocketBufferSet(t *testing.T) {
},
},
}
- mBldr := &metricsbuilder.Builder{HTTPRoute: "/metrics", Backend: "prometheus"}
+ mBldr := &metricsbuilder.Builder{
+ HTTPRoute: "/metrics",
+ Backend: "prometheus",
+ }
metricsFactory, err := mBldr.CreateMetricsFactory("jaeger")
require.NoError(t, err)
- agent, err := cfg.CreateAgent(fakeCollectorProxy{}, zap.NewNop(), metricsFactory)
+ agent, err := cfg.CreateAgent(
+ fakeCollectorProxy{},
+ zap.NewNop(),
+ metricsFactory,
+ )
require.NoError(t, err)
if err := agent.Run(); err != nil {
diff --git a/cmd/agent/app/builder.go b/cmd/agent/app/builder.go
index 91c40ee2f85..d79bab0a13d 100644
--- a/cmd/agent/app/builder.go
+++ b/cmd/agent/app/builder.go
@@ -58,8 +58,12 @@ type Model string
type Protocol string
var protocolFactoryMap = map[Protocol]thrift.TProtocolFactory{
- compactProtocol: thrift.NewTCompactProtocolFactoryConf(&thrift.TConfiguration{}),
- binaryProtocol: thrift.NewTBinaryProtocolFactoryConf(&thrift.TConfiguration{}),
+ compactProtocol: thrift.NewTCompactProtocolFactoryConf(
+ &thrift.TConfiguration{},
+ ),
+ binaryProtocol: thrift.NewTBinaryProtocolFactoryConf(
+ &thrift.TConfiguration{},
+ ),
}
// CollectorProxy provides access to Reporter and ClientConfigManager
@@ -90,7 +94,7 @@ type ServerConfiguration struct {
QueueSize int `yaml:"queueSize"`
MaxPacketSize int `yaml:"maxPacketSize"`
SocketBufferSize int `yaml:"socketBufferSize"`
- HostPort string `yaml:"hostPort" validate:"nonzero"`
+ HostPort string `yaml:"hostPort" validate:"nonzero"`
}
// HTTPServerConfiguration holds config for a server providing sampling strategies and baggage restrictions to clients
@@ -105,13 +109,21 @@ func (b *Builder) WithReporter(r ...reporter.Reporter) *Builder {
}
// CreateAgent creates the Agent
-func (b *Builder) CreateAgent(primaryProxy CollectorProxy, logger *zap.Logger, mFactory metrics.Factory) (*Agent, error) {
+func (b *Builder) CreateAgent(
+ primaryProxy CollectorProxy,
+ logger *zap.Logger,
+ mFactory metrics.Factory,
+) (*Agent, error) {
r := b.getReporter(primaryProxy)
processors, err := b.getProcessors(r, mFactory, logger)
if err != nil {
return nil, fmt.Errorf("cannot create processors: %w", err)
}
- server := b.HTTPServer.getHTTPServer(primaryProxy.GetManager(), mFactory, logger)
+ server := b.HTTPServer.getHTTPServer(
+ primaryProxy.GetManager(),
+ mFactory,
+ logger,
+ )
b.publishOpts()
return NewAgent(processors, server, logger), nil
@@ -132,31 +144,54 @@ func (b *Builder) getReporter(primaryProxy CollectorProxy) reporter.Reporter {
func (b *Builder) publishOpts() {
for _, p := range b.Processors {
prefix := fmt.Sprintf(processorPrefixFmt, p.Model, p.Protocol)
- safeexpvar.SetInt(prefix+suffixServerMaxPacketSize, int64(p.Server.MaxPacketSize))
- safeexpvar.SetInt(prefix+suffixServerQueueSize, int64(p.Server.QueueSize))
+ safeexpvar.SetInt(
+ prefix+suffixServerMaxPacketSize,
+ int64(p.Server.MaxPacketSize),
+ )
+ safeexpvar.SetInt(
+ prefix+suffixServerQueueSize,
+ int64(p.Server.QueueSize),
+ )
safeexpvar.SetInt(prefix+suffixWorkers, int64(p.Workers))
}
}
-func (b *Builder) getProcessors(rep reporter.Reporter, mFactory metrics.Factory, logger *zap.Logger) ([]processors.Processor, error) {
+func (b *Builder) getProcessors(
+ rep reporter.Reporter,
+ mFactory metrics.Factory,
+ logger *zap.Logger,
+) ([]processors.Processor, error) {
retMe := make([]processors.Processor, len(b.Processors))
for idx, cfg := range b.Processors {
protoFactory, ok := protocolFactoryMap[cfg.Protocol]
if !ok {
- return nil, fmt.Errorf("cannot find protocol factory for protocol %v", cfg.Protocol)
+ return nil, fmt.Errorf(
+ "cannot find protocol factory for protocol %v",
+ cfg.Protocol,
+ )
}
var handler processors.AgentProcessor
switch cfg.Model {
case jaegerModel, zipkinModel:
handler = agentThrift.NewAgentProcessor(rep)
default:
- return nil, fmt.Errorf("cannot find agent processor for data model %v", cfg.Model)
+ return nil, fmt.Errorf(
+ "cannot find agent processor for data model %v",
+ cfg.Model,
+ )
}
- metrics := mFactory.Namespace(metrics.NSOptions{Name: "", Tags: map[string]string{
- "protocol": string(cfg.Protocol),
- "model": string(cfg.Model),
- }})
- processor, err := cfg.GetThriftProcessor(metrics, protoFactory, handler, logger)
+ metrics := mFactory.Namespace(
+ metrics.NSOptions{Name: "", Tags: map[string]string{
+ "protocol": string(cfg.Protocol),
+ "model": string(cfg.Model),
+ }},
+ )
+ processor, err := cfg.GetThriftProcessor(
+ metrics,
+ protoFactory,
+ handler,
+ logger,
+ )
if err != nil {
return nil, fmt.Errorf("cannot create Thrift Processor: %w", err)
}
@@ -166,7 +201,11 @@ func (b *Builder) getProcessors(rep reporter.Reporter, mFactory metrics.Factory,
}
// GetHTTPServer creates an HTTP server that provides sampling strategies and baggage restrictions to client libraries.
-func (c HTTPServerConfiguration) getHTTPServer(manager configmanager.ClientConfigManager, mFactory metrics.Factory, logger *zap.Logger) *http.Server {
+func (c HTTPServerConfiguration) getHTTPServer(
+ manager configmanager.ClientConfigManager,
+ mFactory metrics.Factory,
+ logger *zap.Logger,
+) *http.Server {
hostPort := c.HostPort
if hostPort == "" {
hostPort = defaultHTTPServerHostPort
@@ -188,7 +227,14 @@ func (c *ProcessorConfiguration) GetThriftProcessor(
return nil, fmt.Errorf("cannot create UDP Server: %w", err)
}
- return processors.NewThriftProcessor(server, c.Workers, mFactory, factory, handler, logger)
+ return processors.NewThriftProcessor(
+ server,
+ c.Workers,
+ mFactory,
+ factory,
+ handler,
+ logger,
+ )
}
func (c *ProcessorConfiguration) applyDefaults() {
@@ -202,7 +248,9 @@ func (c *ServerConfiguration) applyDefaults() {
}
// getUDPServer gets a TBufferedServer backed server using the server configuration
-func (c *ServerConfiguration) getUDPServer(mFactory metrics.Factory) (servers.Server, error) {
+func (c *ServerConfiguration) getUDPServer(
+ mFactory metrics.Factory,
+) (servers.Server, error) {
c.applyDefaults()
if c.HostPort == "" {
@@ -218,7 +266,12 @@ func (c *ServerConfiguration) getUDPServer(mFactory metrics.Factory) (servers.Se
}
}
- return servers.NewTBufferedServer(transport, c.QueueSize, c.MaxPacketSize, mFactory)
+ return servers.NewTBufferedServer(
+ transport,
+ c.QueueSize,
+ c.MaxPacketSize,
+ mFactory,
+ )
}
func defaultInt(value int, defaultVal int) int {
@@ -246,7 +299,10 @@ func CreateCollectorProxy(
) (CollectorProxy, error) {
builder, ok := builders[opts.ReporterType]
if !ok {
- return nil, fmt.Errorf("unknown reporter type %s", string(opts.ReporterType))
+ return nil, fmt.Errorf(
+ "unknown reporter type %s",
+ string(opts.ReporterType),
+ )
}
return builder(ctx, opts)
}
diff --git a/cmd/agent/app/builder_test.go b/cmd/agent/app/builder_test.go
index 2cf067c0ad7..deb15291a21 100644
--- a/cmd/agent/app/builder_test.go
+++ b/cmd/agent/app/builder_test.go
@@ -127,7 +127,11 @@ func TestBuilderFromConfig(t *testing.T) {
func TestBuilderWithExtraReporter(t *testing.T) {
cfg := &Builder{}
- agent, err := cfg.CreateAgent(fakeCollectorProxy{}, zap.NewNop(), metrics.NullFactory)
+ agent, err := cfg.CreateAgent(
+ fakeCollectorProxy{},
+ zap.NewNop(),
+ metrics.NullFactory,
+ )
require.NoError(t, err)
assert.NotNil(t, agent)
}
@@ -142,7 +146,11 @@ func TestBuilderWithProcessorErrors(t *testing.T) {
}{
{protocol: Protocol("bad"), err: "cannot find protocol factory for protocol bad"},
{protocol: compactProtocol, model: Model("bad"), err: "cannot find agent processor for data model bad"},
- {protocol: compactProtocol, model: jaegerModel, err: "no host:port provided for udp server: {QueueSize:1000 MaxPacketSize:65000 SocketBufferSize:0 HostPort:}"},
+ {
+ protocol: compactProtocol,
+ model: jaegerModel,
+ err: "no host:port provided for udp server: {QueueSize:1000 MaxPacketSize:65000 SocketBufferSize:0 HostPort:}",
+ },
{protocol: compactProtocol, model: zipkinModel, hostPort: "bad-host-port", errContains: "bad-host-port"},
}
for _, tc := range testCases {
@@ -158,7 +166,11 @@ func TestBuilderWithProcessorErrors(t *testing.T) {
},
},
}
- _, err := cfg.CreateAgent(&fakeCollectorProxy{}, zap.NewNop(), metrics.NullFactory)
+ _, err := cfg.CreateAgent(
+ &fakeCollectorProxy{},
+ zap.NewNop(),
+ metrics.NullFactory,
+ )
require.Error(t, err)
if testCase.err != "" {
assert.Contains(t, err.Error(), testCase.err)
@@ -190,11 +202,17 @@ func (fakeCollectorProxy) GetManager() configmanager.ClientConfigManager {
return fakeCollectorProxy{}
}
-func (fakeCollectorProxy) EmitZipkinBatch(_ context.Context, _ []*zipkincore.Span) (err error) {
+func (fakeCollectorProxy) EmitZipkinBatch(
+ _ context.Context,
+ _ []*zipkincore.Span,
+) (err error) {
return nil
}
-func (fakeCollectorProxy) EmitBatch(_ context.Context, _ *jaeger.Batch) (err error) {
+func (fakeCollectorProxy) EmitBatch(
+ _ context.Context,
+ _ *jaeger.Batch,
+) (err error) {
return nil
}
@@ -202,11 +220,17 @@ func (fakeCollectorProxy) Close() error {
return nil
}
-func (fakeCollectorProxy) GetSamplingStrategy(_ context.Context, _ string) (*api_v2.SamplingStrategyResponse, error) {
+func (fakeCollectorProxy) GetSamplingStrategy(
+ _ context.Context,
+ _ string,
+) (*api_v2.SamplingStrategyResponse, error) {
return nil, errors.New("no peers available")
}
-func (fakeCollectorProxy) GetBaggageRestrictions(_ context.Context, _ string) ([]*baggage.BaggageRestriction, error) {
+func (fakeCollectorProxy) GetBaggageRestrictions(
+ _ context.Context,
+ _ string,
+) ([]*baggage.BaggageRestriction, error) {
return nil, nil
}
@@ -224,12 +248,20 @@ func TestCreateCollectorProxy(t *testing.T) {
err: "at least one collector hostPort address is required when resolver is not available",
},
{
- flags: []string{"--reporter.type=grpc", "--reporter.grpc.host-port=foo"},
- metric: metricstest.ExpectedMetric{Name: "reporter.batches.failures", Tags: map[string]string{"protocol": "grpc", "format": "jaeger"}, Value: 1},
+ flags: []string{"--reporter.type=grpc", "--reporter.grpc.host-port=foo"},
+ metric: metricstest.ExpectedMetric{
+ Name: "reporter.batches.failures",
+ Tags: map[string]string{"protocol": "grpc", "format": "jaeger"},
+ Value: 1,
+ },
},
{
- flags: []string{"--reporter.type=grpc", "--reporter.grpc.host-port=foo"},
- metric: metricstest.ExpectedMetric{Name: "reporter.batches.failures", Tags: map[string]string{"protocol": "grpc", "format": "jaeger"}, Value: 1},
+ flags: []string{"--reporter.type=grpc", "--reporter.grpc.host-port=foo"},
+ metric: metricstest.ExpectedMetric{
+ Name: "reporter.batches.failures",
+ Tags: map[string]string{"protocol": "grpc", "format": "jaeger"},
+ Value: 1,
+ },
},
}
@@ -309,7 +341,11 @@ func TestPublishOpts(t *testing.T) {
baseMetrics := metricstest.NewFactory(time.Second)
defer baseMetrics.Stop()
- agent, err := cfg.CreateAgent(fakeCollectorProxy{}, zap.NewNop(), baseMetrics)
+ agent, err := cfg.CreateAgent(
+ fakeCollectorProxy{},
+ zap.NewNop(),
+ baseMetrics,
+ )
require.NoError(t, err)
assert.NotNil(t, agent)
require.NoError(t, agent.Run())
@@ -317,7 +353,19 @@ func TestPublishOpts(t *testing.T) {
p := cfg.Processors[2]
prefix := fmt.Sprintf(processorPrefixFmt, p.Model, p.Protocol)
- assert.EqualValues(t, 4242, expvar.Get(prefix+suffixServerMaxPacketSize).(*expvar.Int).Value())
- assert.EqualValues(t, 24, expvar.Get(prefix+suffixServerQueueSize).(*expvar.Int).Value())
- assert.EqualValues(t, 42, expvar.Get(prefix+suffixWorkers).(*expvar.Int).Value())
+ assert.EqualValues(
+ t,
+ 4242,
+ expvar.Get(prefix+suffixServerMaxPacketSize).(*expvar.Int).Value(),
+ )
+ assert.EqualValues(
+ t,
+ 24,
+ expvar.Get(prefix+suffixServerQueueSize).(*expvar.Int).Value(),
+ )
+ assert.EqualValues(
+ t,
+ 42,
+ expvar.Get(prefix+suffixWorkers).(*expvar.Int).Value(),
+ )
}
diff --git a/cmd/agent/app/configmanager/grpc/manager.go b/cmd/agent/app/configmanager/grpc/manager.go
index dd49ccbcff8..6fe4fa15716 100644
--- a/cmd/agent/app/configmanager/grpc/manager.go
+++ b/cmd/agent/app/configmanager/grpc/manager.go
@@ -38,7 +38,10 @@ func NewConfigManager(conn *grpc.ClientConn) *ConfigManagerProxy {
}
// GetSamplingStrategy returns sampling strategies from collector.
-func (s *ConfigManagerProxy) GetSamplingStrategy(ctx context.Context, serviceName string) (*api_v2.SamplingStrategyResponse, error) {
+func (s *ConfigManagerProxy) GetSamplingStrategy(
+ ctx context.Context,
+ serviceName string,
+) (*api_v2.SamplingStrategyResponse, error) {
resp, err := s.client.GetSamplingStrategy(ctx, &api_v2.SamplingStrategyParameters{ServiceName: serviceName})
if err != nil {
return nil, fmt.Errorf("failed to get sampling strategy: %w", err)
@@ -47,6 +50,9 @@ func (s *ConfigManagerProxy) GetSamplingStrategy(ctx context.Context, serviceNam
}
// GetBaggageRestrictions returns baggage restrictions from collector.
-func (*ConfigManagerProxy) GetBaggageRestrictions(_ context.Context, _ string) ([]*baggage.BaggageRestriction, error) {
+func (*ConfigManagerProxy) GetBaggageRestrictions(
+ _ context.Context,
+ _ string,
+) ([]*baggage.BaggageRestriction, error) {
return nil, errors.New("baggage not implemented")
}
diff --git a/cmd/agent/app/configmanager/grpc/manager_test.go b/cmd/agent/app/configmanager/grpc/manager_test.go
index dd14a81f70e..fa992ec9e70 100644
--- a/cmd/agent/app/configmanager/grpc/manager_test.go
+++ b/cmd/agent/app/configmanager/grpc/manager_test.go
@@ -37,18 +37,30 @@ func TestSamplingManager_GetSamplingStrategy(t *testing.T) {
s, addr := initializeGRPCTestServer(t, func(s *grpc.Server) {
api_v2.RegisterSamplingManagerServer(s, &mockSamplingHandler{})
})
- conn, err := grpc.NewClient(addr.String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
+ conn, err := grpc.NewClient(
+ addr.String(),
+ grpc.WithTransportCredentials(insecure.NewCredentials()),
+ )
defer close(t, conn)
require.NoError(t, err)
defer s.GracefulStop()
manager := NewConfigManager(conn)
resp, err := manager.GetSamplingStrategy(context.Background(), "any")
require.NoError(t, err)
- assert.Equal(t, &api_v2.SamplingStrategyResponse{StrategyType: api_v2.SamplingStrategyType_PROBABILISTIC}, resp)
+ assert.Equal(
+ t,
+ &api_v2.SamplingStrategyResponse{
+ StrategyType: api_v2.SamplingStrategyType_PROBABILISTIC,
+ },
+ resp,
+ )
}
func TestSamplingManager_GetSamplingStrategy_error(t *testing.T) {
- conn, err := grpc.NewClient("foo", grpc.WithTransportCredentials(insecure.NewCredentials()))
+ conn, err := grpc.NewClient(
+ "foo",
+ grpc.WithTransportCredentials(insecure.NewCredentials()),
+ )
defer close(t, conn)
require.NoError(t, err)
manager := NewConfigManager(conn)
@@ -67,11 +79,17 @@ func TestSamplingManager_GetBaggageRestrictions(t *testing.T) {
type mockSamplingHandler struct{}
-func (*mockSamplingHandler) GetSamplingStrategy(context.Context, *api_v2.SamplingStrategyParameters) (*api_v2.SamplingStrategyResponse, error) {
+func (*mockSamplingHandler) GetSamplingStrategy(
+ context.Context,
+ *api_v2.SamplingStrategyParameters,
+) (*api_v2.SamplingStrategyResponse, error) {
return &api_v2.SamplingStrategyResponse{StrategyType: api_v2.SamplingStrategyType_PROBABILISTIC}, nil
}
-func initializeGRPCTestServer(t *testing.T, beforeServe func(server *grpc.Server)) (*grpc.Server, net.Addr) {
+func initializeGRPCTestServer(
+ t *testing.T,
+ beforeServe func(server *grpc.Server),
+) (*grpc.Server, net.Addr) {
server := grpc.NewServer()
lis, err := net.Listen("tcp", "localhost:0")
require.NoError(t, err)
diff --git a/cmd/agent/app/configmanager/manager.go b/cmd/agent/app/configmanager/manager.go
index de12a5d6f74..c8c752df450 100644
--- a/cmd/agent/app/configmanager/manager.go
+++ b/cmd/agent/app/configmanager/manager.go
@@ -29,6 +29,12 @@ import (
// 1) which sampling strategy a given service should be using
// 2) which baggage restrictions a given service should be using.
type ClientConfigManager interface {
- GetSamplingStrategy(ctx context.Context, serviceName string) (*api_v2.SamplingStrategyResponse, error)
- GetBaggageRestrictions(ctx context.Context, serviceName string) ([]*baggage.BaggageRestriction, error)
+ GetSamplingStrategy(
+ ctx context.Context,
+ serviceName string,
+ ) (*api_v2.SamplingStrategyResponse, error)
+ GetBaggageRestrictions(
+ ctx context.Context,
+ serviceName string,
+ ) ([]*baggage.BaggageRestriction, error)
}
diff --git a/cmd/agent/app/configmanager/metrics.go b/cmd/agent/app/configmanager/metrics.go
index 08b64d76678..9fd2152f187 100644
--- a/cmd/agent/app/configmanager/metrics.go
+++ b/cmd/agent/app/configmanager/metrics.go
@@ -44,14 +44,20 @@ type ManagerWithMetrics struct {
}
// WrapWithMetrics wraps ClientConfigManager and creates metrics for its invocations.
-func WrapWithMetrics(manager ClientConfigManager, mFactory metrics.Factory) *ManagerWithMetrics {
+func WrapWithMetrics(
+ manager ClientConfigManager,
+ mFactory metrics.Factory,
+) *ManagerWithMetrics {
m := configManagerMetrics{}
metrics.Init(&m, mFactory, nil)
return &ManagerWithMetrics{wrapped: manager, metrics: m}
}
// GetSamplingStrategy returns sampling strategy from server.
-func (m *ManagerWithMetrics) GetSamplingStrategy(ctx context.Context, serviceName string) (*api_v2.SamplingStrategyResponse, error) {
+func (m *ManagerWithMetrics) GetSamplingStrategy(
+ ctx context.Context,
+ serviceName string,
+) (*api_v2.SamplingStrategyResponse, error) {
r, err := m.wrapped.GetSamplingStrategy(ctx, serviceName)
if err != nil {
m.metrics.SamplingFailures.Inc(1)
@@ -62,7 +68,10 @@ func (m *ManagerWithMetrics) GetSamplingStrategy(ctx context.Context, serviceNam
}
// GetBaggageRestrictions returns baggage restrictions from server.
-func (m *ManagerWithMetrics) GetBaggageRestrictions(ctx context.Context, serviceName string) ([]*baggage.BaggageRestriction, error) {
+func (m *ManagerWithMetrics) GetBaggageRestrictions(
+ ctx context.Context,
+ serviceName string,
+) ([]*baggage.BaggageRestriction, error) {
r, err := m.wrapped.GetBaggageRestrictions(ctx, serviceName)
if err != nil {
m.metrics.BaggageFailures.Inc(1)
diff --git a/cmd/agent/app/configmanager/metrics_test.go b/cmd/agent/app/configmanager/metrics_test.go
index 7eb0755cec0..5494708dab0 100644
--- a/cmd/agent/app/configmanager/metrics_test.go
+++ b/cmd/agent/app/configmanager/metrics_test.go
@@ -30,14 +30,22 @@ import (
type noopManager struct{}
-func (noopManager) GetSamplingStrategy(_ context.Context, s string) (*api_v2.SamplingStrategyResponse, error) {
+func (noopManager) GetSamplingStrategy(
+ _ context.Context,
+ s string,
+) (*api_v2.SamplingStrategyResponse, error) {
if s == "failed" {
return nil, errors.New("failed")
}
- return &api_v2.SamplingStrategyResponse{StrategyType: api_v2.SamplingStrategyType_PROBABILISTIC}, nil
+ return &api_v2.SamplingStrategyResponse{
+ StrategyType: api_v2.SamplingStrategyType_PROBABILISTIC,
+ }, nil
}
-func (noopManager) GetBaggageRestrictions(_ context.Context, s string) ([]*baggage.BaggageRestriction, error) {
+func (noopManager) GetBaggageRestrictions(
+ _ context.Context,
+ s string,
+) ([]*baggage.BaggageRestriction, error) {
if s == "failed" {
return nil, errors.New("failed")
}
@@ -50,16 +58,66 @@ func TestMetrics(t *testing.T) {
err error
}{
{expected: []metricstest.ExpectedMetric{
- {Name: "collector-proxy", Tags: map[string]string{"result": "ok", "endpoint": "sampling"}, Value: 1},
- {Name: "collector-proxy", Tags: map[string]string{"result": "err", "endpoint": "sampling"}, Value: 0},
- {Name: "collector-proxy", Tags: map[string]string{"result": "ok", "endpoint": "baggage"}, Value: 1},
- {Name: "collector-proxy", Tags: map[string]string{"result": "err", "endpoint": "baggage"}, Value: 0},
+ {
+ Name: "collector-proxy",
+ Tags: map[string]string{
+ "result": "ok",
+ "endpoint": "sampling",
+ },
+ Value: 1,
+ },
+ {
+ Name: "collector-proxy",
+ Tags: map[string]string{
+ "result": "err",
+ "endpoint": "sampling",
+ },
+ Value: 0,
+ },
+ {
+ Name: "collector-proxy",
+ Tags: map[string]string{"result": "ok", "endpoint": "baggage"},
+ Value: 1,
+ },
+ {
+ Name: "collector-proxy",
+ Tags: map[string]string{
+ "result": "err",
+ "endpoint": "baggage",
+ },
+ Value: 0,
+ },
}},
{expected: []metricstest.ExpectedMetric{
- {Name: "collector-proxy", Tags: map[string]string{"result": "ok", "endpoint": "sampling"}, Value: 0},
- {Name: "collector-proxy", Tags: map[string]string{"result": "err", "endpoint": "sampling"}, Value: 1},
- {Name: "collector-proxy", Tags: map[string]string{"result": "ok", "endpoint": "baggage"}, Value: 0},
- {Name: "collector-proxy", Tags: map[string]string{"result": "err", "endpoint": "baggage"}, Value: 1},
+ {
+ Name: "collector-proxy",
+ Tags: map[string]string{
+ "result": "ok",
+ "endpoint": "sampling",
+ },
+ Value: 0,
+ },
+ {
+ Name: "collector-proxy",
+ Tags: map[string]string{
+ "result": "err",
+ "endpoint": "sampling",
+ },
+ Value: 1,
+ },
+ {
+ Name: "collector-proxy",
+ Tags: map[string]string{"result": "ok", "endpoint": "baggage"},
+ Value: 0,
+ },
+ {
+ Name: "collector-proxy",
+ Tags: map[string]string{
+ "result": "err",
+ "endpoint": "baggage",
+ },
+ Value: 1,
+ },
}, err: errors.New("failed")},
}
@@ -70,10 +128,16 @@ func TestMetrics(t *testing.T) {
mgr := WrapWithMetrics(&noopManager{}, metricsFactory)
if test.err != nil {
- s, err := mgr.GetSamplingStrategy(context.Background(), test.err.Error())
+ s, err := mgr.GetSamplingStrategy(
+ context.Background(),
+ test.err.Error(),
+ )
require.Nil(t, s)
require.EqualError(t, err, test.err.Error())
- b, err := mgr.GetBaggageRestrictions(context.Background(), test.err.Error())
+ b, err := mgr.GetBaggageRestrictions(
+ context.Background(),
+ test.err.Error(),
+ )
require.Nil(t, b)
require.EqualError(t, err, test.err.Error())
} else {
diff --git a/cmd/agent/app/customtransport/buffered_read_transport.go b/cmd/agent/app/customtransport/buffered_read_transport.go
index 2d5b8573a9b..479263094a0 100644
--- a/cmd/agent/app/customtransport/buffered_read_transport.go
+++ b/cmd/agent/app/customtransport/buffered_read_transport.go
@@ -30,7 +30,9 @@ type TBufferedReadTransport struct {
var _ thrift.TTransport = (*TBufferedReadTransport)(nil)
// NewTBufferedReadTransport creates a buffer backed TTransport
-func NewTBufferedReadTransport(readBuf *bytes.Buffer) (*TBufferedReadTransport, error) {
+func NewTBufferedReadTransport(
+ readBuf *bytes.Buffer,
+) (*TBufferedReadTransport, error) {
return &TBufferedReadTransport{readBuf: readBuf}, nil
}
diff --git a/cmd/agent/app/flags.go b/cmd/agent/app/flags.go
index ce2ab098769..7cbfdce4f9e 100644
--- a/cmd/agent/app/flags.go
+++ b/cmd/agent/app/flags.go
@@ -41,9 +41,21 @@ var defaultProcessors = []struct {
protocol Protocol
port int
}{
- {model: "zipkin", protocol: "compact", port: ports.AgentZipkinThriftCompactUDP},
- {model: "jaeger", protocol: "compact", port: ports.AgentJaegerThriftCompactUDP},
- {model: "jaeger", protocol: "binary", port: ports.AgentJaegerThriftBinaryUDP},
+ {
+ model: "zipkin",
+ protocol: "compact",
+ port: ports.AgentZipkinThriftCompactUDP,
+ },
+ {
+ model: "jaeger",
+ protocol: "compact",
+ port: ports.AgentJaegerThriftCompactUDP,
+ },
+ {
+ model: "jaeger",
+ protocol: "binary",
+ port: ports.AgentJaegerThriftBinaryUDP,
+ },
}
// AddFlags adds flags for Builder.
@@ -51,28 +63,60 @@ func AddFlags(flags *flag.FlagSet) {
flags.String(
httpServerHostPort,
defaultHTTPServerHostPort,
- "host:port of the http server (e.g. for /sampling point and /baggageRestrictions endpoint)")
+ "host:port of the http server (e.g. for /sampling point and /baggageRestrictions endpoint)",
+ )
for _, p := range defaultProcessors {
prefix := fmt.Sprintf(processorPrefixFmt, p.model, p.protocol)
- flags.Int(prefix+suffixWorkers, defaultServerWorkers, "how many workers the processor should run")
- flags.Int(prefix+suffixServerQueueSize, defaultQueueSize, "length of the queue for the UDP server")
- flags.Int(prefix+suffixServerMaxPacketSize, defaultMaxPacketSize, "max packet size for the UDP server")
- flags.Int(prefix+suffixServerSocketBufferSize, 0, "socket buffer size for UDP packets in bytes")
- flags.String(prefix+suffixServerHostPort, ":"+strconv.Itoa(p.port), "host:port for the UDP server")
+ flags.Int(
+ prefix+suffixWorkers,
+ defaultServerWorkers,
+ "how many workers the processor should run",
+ )
+ flags.Int(
+ prefix+suffixServerQueueSize,
+ defaultQueueSize,
+ "length of the queue for the UDP server",
+ )
+ flags.Int(
+ prefix+suffixServerMaxPacketSize,
+ defaultMaxPacketSize,
+ "max packet size for the UDP server",
+ )
+ flags.Int(
+ prefix+suffixServerSocketBufferSize,
+ 0,
+ "socket buffer size for UDP packets in bytes",
+ )
+ flags.String(
+ prefix+suffixServerHostPort,
+ ":"+strconv.Itoa(p.port),
+ "host:port for the UDP server",
+ )
}
}
// InitFromViper initializes Builder with properties retrieved from Viper.
func (b *Builder) InitFromViper(v *viper.Viper) *Builder {
for _, processor := range defaultProcessors {
- prefix := fmt.Sprintf(processorPrefixFmt, processor.model, processor.protocol)
- p := &ProcessorConfiguration{Model: processor.model, Protocol: processor.protocol}
+ prefix := fmt.Sprintf(
+ processorPrefixFmt,
+ processor.model,
+ processor.protocol,
+ )
+ p := &ProcessorConfiguration{
+ Model: processor.model,
+ Protocol: processor.protocol,
+ }
p.Workers = v.GetInt(prefix + suffixWorkers)
p.Server.QueueSize = v.GetInt(prefix + suffixServerQueueSize)
p.Server.MaxPacketSize = v.GetInt(prefix + suffixServerMaxPacketSize)
- p.Server.SocketBufferSize = v.GetInt(prefix + suffixServerSocketBufferSize)
- p.Server.HostPort = portNumToHostPort(v.GetString(prefix + suffixServerHostPort))
+ p.Server.SocketBufferSize = v.GetInt(
+ prefix + suffixServerSocketBufferSize,
+ )
+ p.Server.HostPort = portNumToHostPort(
+ v.GetString(prefix + suffixServerHostPort),
+ )
b.Processors = append(b.Processors, *p)
}
diff --git a/cmd/agent/app/httpserver/srv.go b/cmd/agent/app/httpserver/srv.go
index 698bad33a7e..1dee894c1e5 100644
--- a/cmd/agent/app/httpserver/srv.go
+++ b/cmd/agent/app/httpserver/srv.go
@@ -30,7 +30,12 @@ import (
// NewHTTPServer creates a new server that hosts an HTTP/JSON endpoint for clients
// to query for sampling strategies and baggage restrictions.
-func NewHTTPServer(hostPort string, manager configmanager.ClientConfigManager, mFactory metrics.Factory, logger *zap.Logger) *http.Server {
+func NewHTTPServer(
+ hostPort string,
+ manager configmanager.ClientConfigManager,
+ mFactory metrics.Factory,
+ logger *zap.Logger,
+) *http.Server {
handler := clientcfghttp.NewHTTPHandler(clientcfghttp.HTTPHandlerParams{
ConfigManager: manager,
MetricsFactory: mFactory,
diff --git a/cmd/agent/app/processors/thrift_processor.go b/cmd/agent/app/processors/thrift_processor.go
index 0045388994f..5646a17331c 100644
--- a/cmd/agent/app/processors/thrift_processor.go
+++ b/cmd/agent/app/processors/thrift_processor.go
@@ -50,7 +50,10 @@ type ThriftProcessor struct {
// code, e.g. jaegerThrift.NewAgentProcessor(handler), where handler implements the Agent
// Thrift service interface, which is invoked with the deserialized struct.
type AgentProcessor interface {
- Process(ctx context.Context, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException)
+ Process(
+ ctx context.Context,
+ iprot, oprot thrift.TProtocol,
+ ) (success bool, err thrift.TException)
}
// NewThriftProcessor creates a TBufferedServer backed ThriftProcessor
@@ -64,7 +67,9 @@ func NewThriftProcessor(
) (*ThriftProcessor, error) {
if numProcessors <= 0 {
return nil, fmt.Errorf(
- "number of processors must be greater than 0, called with %d", numProcessors)
+ "number of processors must be greater than 0, called with %d",
+ numProcessors,
+ )
}
protocolPool := &sync.Pool{
New: func() any {
@@ -117,11 +122,15 @@ func (s *ThriftProcessor) processBuffer() {
protocol := s.protocolPool.Get().(thrift.TProtocol)
payload := readBuf.GetBytes()
protocol.Transport().Write(payload)
- s.logger.Debug("Span(s) received by the agent", zap.Int("bytes-received", len(payload)))
+ s.logger.Debug(
+ "Span(s) received by the agent",
+ zap.Int("bytes-received", len(payload)),
+ )
// NB: oddly, thrift-gen/agent/agent.go:L156 does this: `return true, thrift.WrapTException(err2)`
// So we check for both OK and error.
- if ok, err := s.handler.Process(context.Background(), protocol, protocol); !ok || err != nil {
+ if ok, err := s.handler.Process(context.Background(), protocol, protocol); !ok ||
+ err != nil {
s.logger.Error("Processor failed", zap.Error(err))
s.metrics.HandlerProcessError.Inc(1)
}
diff --git a/cmd/agent/app/processors/thrift_processor_test.go b/cmd/agent/app/processors/thrift_processor_test.go
index ce824a13fff..a7951092856 100644
--- a/cmd/agent/app/processors/thrift_processor_test.go
+++ b/cmd/agent/app/processors/thrift_processor_test.go
@@ -43,8 +43,12 @@ import (
// TODO make these tests faster, they take almost 4 seconds
var (
- compactFactory = thrift.NewTCompactProtocolFactoryConf(&thrift.TConfiguration{})
- binaryFactory = thrift.NewTBinaryProtocolFactoryConf(&thrift.TConfiguration{})
+ compactFactory = thrift.NewTCompactProtocolFactoryConf(
+ &thrift.TConfiguration{},
+ )
+ binaryFactory = thrift.NewTBinaryProtocolFactoryConf(
+ &thrift.TConfiguration{},
+ )
testSpanName = "span1"
@@ -54,17 +58,34 @@ var (
}
)
-func createProcessor(t *testing.T, mFactory metrics.Factory, tFactory thrift.TProtocolFactory, handler AgentProcessor) (string, Processor) {
+func createProcessor(
+ t *testing.T,
+ mFactory metrics.Factory,
+ tFactory thrift.TProtocolFactory,
+ handler AgentProcessor,
+) (string, Processor) {
transport, err := thriftudp.NewTUDPServerTransport("127.0.0.1:0")
require.NoError(t, err)
queueSize := 10
maxPacketSize := 65000
- server, err := servers.NewTBufferedServer(transport, queueSize, maxPacketSize, mFactory)
+ server, err := servers.NewTBufferedServer(
+ transport,
+ queueSize,
+ maxPacketSize,
+ mFactory,
+ )
require.NoError(t, err)
numProcessors := 1
- processor, err := NewThriftProcessor(server, numProcessors, mFactory, tFactory, handler, zaptest.NewLogger(t))
+ processor, err := NewThriftProcessor(
+ server,
+ numProcessors,
+ mFactory,
+ tFactory,
+ handler,
+ zaptest.NewLogger(t),
+ )
require.NoError(t, err)
go processor.Serve()
@@ -80,9 +101,14 @@ func createProcessor(t *testing.T, mFactory metrics.Factory, tFactory thrift.TPr
}
// revive:disable-next-line function-result-limit
-func initCollectorAndReporter(t *testing.T) (*metricstest.Factory, *testutils.GrpcCollector, reporter.Reporter, *grpc.ClientConn) {
+func initCollectorAndReporter(
+ t *testing.T,
+) (*metricstest.Factory, *testutils.GrpcCollector, reporter.Reporter, *grpc.ClientConn) {
grpcCollector := testutils.StartGRPCCollector(t)
- conn, err := grpc.NewClient(grpcCollector.Listener().Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
+ conn, err := grpc.NewClient(
+ grpcCollector.Listener().Addr().String(),
+ grpc.WithTransportCredentials(insecure.NewCredentials()),
+ )
require.NoError(t, err)
rep := grpcrep.NewReporter(conn, map[string]string{}, zaptest.NewLogger(t))
metricsFactory := metricstest.NewFactory(0)
@@ -92,7 +118,11 @@ func initCollectorAndReporter(t *testing.T) (*metricstest.Factory, *testutils.Gr
func TestNewThriftProcessor_ZeroCount(t *testing.T) {
_, err := NewThriftProcessor(nil, 0, nil, nil, nil, zaptest.NewLogger(t))
- require.EqualError(t, err, "number of processors must be greater than 0, called with 0")
+ require.EqualError(
+ t,
+ err,
+ "number of processors must be greater than 0, called with 0",
+ )
}
func TestProcessorWithCompactZipkin(t *testing.T) {
@@ -100,7 +130,12 @@ func TestProcessorWithCompactZipkin(t *testing.T) {
defer conn.Close()
defer collector.Close()
- hostPort, processor := createProcessor(t, metricsFactory, compactFactory, agent.NewAgentProcessor(reporter))
+ hostPort, processor := createProcessor(
+ t,
+ metricsFactory,
+ compactFactory,
+ agent.NewAgentProcessor(reporter),
+ )
defer processor.Stop()
client, clientCloser, err := testutils.NewZipkinThriftUDPClient(hostPort)
@@ -109,7 +144,9 @@ func TestProcessorWithCompactZipkin(t *testing.T) {
span := zipkincore.NewSpan()
span.Name = testSpanName
- span.Annotations = []*zipkincore.Annotation{{Value: zipkincore.CLIENT_SEND, Host: &zipkincore.Endpoint{ServiceName: "foo"}}}
+ span.Annotations = []*zipkincore.Annotation{
+ {Value: zipkincore.CLIENT_SEND, Host: &zipkincore.Endpoint{ServiceName: "foo"}},
+ }
err = client.EmitZipkinBatch(context.Background(), []*zipkincore.Span{span})
require.NoError(t, err)
@@ -121,7 +158,10 @@ type failingHandler struct {
err error
}
-func (h failingHandler) Process(_ context.Context, iprot, oprot thrift.TProtocol) (success bool, err thrift.TException) {
+func (h failingHandler) Process(
+ _ context.Context,
+ iprot, oprot thrift.TProtocol,
+) (success bool, err thrift.TException) {
return false, thrift.NewTApplicationException(0, h.err.Error())
}
@@ -130,14 +170,22 @@ func TestProcessor_HandlerError(t *testing.T) {
handler := failingHandler{err: errors.New("doh")}
- hostPort, processor := createProcessor(t, metricsFactory, compactFactory, handler)
+ hostPort, processor := createProcessor(
+ t,
+ metricsFactory,
+ compactFactory,
+ handler,
+ )
defer processor.Stop()
client, clientCloser, err := testutils.NewZipkinThriftUDPClient(hostPort)
require.NoError(t, err)
defer clientCloser.Close()
- err = client.EmitZipkinBatch(context.Background(), []*zipkincore.Span{{Name: testSpanName}})
+ err = client.EmitZipkinBatch(
+ context.Background(),
+ []*zipkincore.Span{{Name: testSpanName}},
+ )
require.NoError(t, err)
for i := 0; i < 10; i++ {
@@ -148,9 +196,16 @@ func TestProcessor_HandlerError(t *testing.T) {
time.Sleep(time.Millisecond)
}
- metricsFactory.AssertCounterMetrics(t,
- metricstest.ExpectedMetric{Name: "thrift.udp.t-processor.handler-errors", Value: 1},
- metricstest.ExpectedMetric{Name: "thrift.udp.server.packets.processed", Value: 1},
+ metricsFactory.AssertCounterMetrics(
+ t,
+ metricstest.ExpectedMetric{
+ Name: "thrift.udp.t-processor.handler-errors",
+ Value: 1,
+ },
+ metricstest.ExpectedMetric{
+ Name: "thrift.udp.server.packets.processed",
+ Value: 1,
+ },
)
}
@@ -167,11 +222,21 @@ func TestJaegerProcessor(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
- metricsFactory, collector, reporter, conn := initCollectorAndReporter(t)
-
- hostPort, processor := createProcessor(t, metricsFactory, test.factory, agent.NewAgentProcessor(reporter))
-
- client, clientCloser, err := testutils.NewJaegerThriftUDPClient(hostPort, test.factory)
+ metricsFactory, collector, reporter, conn := initCollectorAndReporter(
+ t,
+ )
+
+ hostPort, processor := createProcessor(
+ t,
+ metricsFactory,
+ test.factory,
+ agent.NewAgentProcessor(reporter),
+ )
+
+ client, clientCloser, err := testutils.NewJaegerThriftUDPClient(
+ hostPort,
+ test.factory,
+ )
require.NoError(t, err)
err = client.EmitBatch(context.Background(), batch)
@@ -187,7 +252,11 @@ func TestJaegerProcessor(t *testing.T) {
}
}
-func assertJaegerProcessorCorrectness(t *testing.T, collector *testutils.GrpcCollector, metricsFactory *metricstest.Factory) {
+func assertJaegerProcessorCorrectness(
+ t *testing.T,
+ collector *testutils.GrpcCollector,
+ metricsFactory *metricstest.Factory,
+) {
sizeF := func() int {
return len(collector.GetJaegerBatches())
}
@@ -197,7 +266,11 @@ func assertJaegerProcessorCorrectness(t *testing.T, collector *testutils.GrpcCol
assertCollectorReceivedData(t, metricsFactory, sizeF, nameF, "jaeger")
}
-func assertZipkinProcessorCorrectness(t *testing.T, collector *testutils.GrpcCollector, metricsFactory *metricstest.Factory) {
+func assertZipkinProcessorCorrectness(
+ t *testing.T,
+ collector *testutils.GrpcCollector,
+ metricsFactory *metricstest.Factory,
+) {
sizeF := func() int {
return len(collector.GetJaegerBatches())
}
@@ -239,8 +312,16 @@ func assertCollectorReceivedData(
}
metricsFactory.AssertCounterMetrics(t, []metricstest.ExpectedMetric{
- {Name: "reporter.batches.submitted", Tags: map[string]string{"format": format}, Value: 1},
- {Name: "reporter.spans.submitted", Tags: map[string]string{"format": format}, Value: 1},
+ {
+ Name: "reporter.batches.submitted",
+ Tags: map[string]string{"format": format},
+ Value: 1,
+ },
+ {
+ Name: "reporter.spans.submitted",
+ Tags: map[string]string{"format": format},
+ Value: 1,
+ },
{Name: "thrift.udp.server.packets.processed", Value: 1},
}...)
}
diff --git a/cmd/agent/app/proxy_builders.go b/cmd/agent/app/proxy_builders.go
index 0501d9a8fe1..779c5e94308 100644
--- a/cmd/agent/app/proxy_builders.go
+++ b/cmd/agent/app/proxy_builders.go
@@ -21,8 +21,16 @@ import (
)
// GRPCCollectorProxyBuilder creates CollectorProxyBuilder for GRPC reporter
-func GRPCCollectorProxyBuilder(builder *grpc.ConnBuilder) CollectorProxyBuilder {
+func GRPCCollectorProxyBuilder(
+ builder *grpc.ConnBuilder,
+) CollectorProxyBuilder {
return func(ctx context.Context, opts ProxyBuilderOptions) (proxy CollectorProxy, err error) {
- return grpc.NewCollectorProxy(ctx, builder, opts.AgentTags, opts.Metrics, opts.Logger)
+ return grpc.NewCollectorProxy(
+ ctx,
+ builder,
+ opts.AgentTags,
+ opts.Metrics,
+ opts.Logger,
+ )
}
}
diff --git a/cmd/agent/app/reporter/client_metrics.go b/cmd/agent/app/reporter/client_metrics.go
index 4213c1929ef..8426360b8cb 100644
--- a/cmd/agent/app/reporter/client_metrics.go
+++ b/cmd/agent/app/reporter/client_metrics.go
@@ -34,8 +34,8 @@ const (
// clientMetrics are maintained only for data submitted in Jaeger Thrift format.
type clientMetrics struct {
- BatchesReceived metrics.Counter `metric:"batches_received" help:"Total count of batches received from conforming clients"`
- BatchesSent metrics.Counter `metric:"batches_sent" help:"Total count of batches sent by clients"`
+ BatchesReceived metrics.Counter `metric:"batches_received" help:"Total count of batches received from conforming clients"`
+ BatchesSent metrics.Counter `metric:"batches_sent" help:"Total count of batches sent by clients"`
ConnectedClients metrics.Gauge `metric:"connected_clients" help:"Total count of unique clients sending data to the agent"`
// NB: The following three metrics all have the same name, but different "cause" tags.
@@ -91,7 +91,9 @@ type ClientMetricsReporterParams struct {
}
// WrapWithClientMetrics creates ClientMetricsReporter.
-func WrapWithClientMetrics(params ClientMetricsReporterParams) *ClientMetricsReporter {
+func WrapWithClientMetrics(
+ params ClientMetricsReporterParams,
+) *ClientMetricsReporter {
if params.ExpireFrequency == 0 {
params.ExpireFrequency = defaultExpireFrequency
}
@@ -99,7 +101,13 @@ func WrapWithClientMetrics(params ClientMetricsReporterParams) *ClientMetricsRep
params.ExpireTTL = defaultExpireTTL
}
cm := new(clientMetrics)
- metrics.MustInit(cm, params.MetricsFactory.Namespace(metrics.NSOptions{Name: "client_stats"}), nil)
+ metrics.MustInit(
+ cm,
+ params.MetricsFactory.Namespace(
+ metrics.NSOptions{Name: "client_stats"},
+ ),
+ nil,
+ )
r := &ClientMetricsReporter{
params: params,
clientMetrics: cm,
@@ -110,12 +118,18 @@ func WrapWithClientMetrics(params ClientMetricsReporterParams) *ClientMetricsRep
}
// EmitZipkinBatch delegates to underlying Reporter.
-func (r *ClientMetricsReporter) EmitZipkinBatch(ctx context.Context, spans []*zipkincore.Span) error {
+func (r *ClientMetricsReporter) EmitZipkinBatch(
+ ctx context.Context,
+ spans []*zipkincore.Span,
+) error {
return r.params.Reporter.EmitZipkinBatch(ctx, spans)
}
// EmitBatch processes client data loss metrics and delegates to the underlying reporter.
-func (r *ClientMetricsReporter) EmitBatch(ctx context.Context, batch *jaeger.Batch) error {
+func (r *ClientMetricsReporter) EmitBatch(
+ ctx context.Context,
+ batch *jaeger.Batch,
+) error {
r.updateClientMetrics(batch)
return r.params.Reporter.EmitBatch(ctx, batch)
}
@@ -148,9 +162,11 @@ func (r *ClientMetricsReporter) expireClientMetrics(t time.Time) {
stats.lock.Lock()
defer stats.lock.Unlock()
- if !stats.lastUpdated.IsZero() && t.Sub(stats.lastUpdated) > r.params.ExpireTTL {
+ if !stats.lastUpdated.IsZero() &&
+ t.Sub(stats.lastUpdated) > r.params.ExpireTTL {
r.lastReceivedClientStats.Delete(k)
- r.params.Logger.Debug("have not heard from a client for a while, freeing stats",
+ r.params.Logger.Debug(
+ "have not heard from a client for a while, freeing stats",
zap.Any("client-uuid", k),
zap.Time("last-message", stats.lastUpdated),
)
@@ -171,9 +187,13 @@ func (r *ClientMetricsReporter) updateClientMetrics(batch *jaeger.Batch) {
}
entry, found := r.lastReceivedClientStats.Load(clientUUID)
if !found {
- ent, loaded := r.lastReceivedClientStats.LoadOrStore(clientUUID, &lastReceivedClientStats{})
+ ent, loaded := r.lastReceivedClientStats.LoadOrStore(
+ clientUUID,
+ &lastReceivedClientStats{},
+ )
if !loaded {
- r.params.Logger.Debug("received batch from a new client, starting to keep stats",
+ r.params.Logger.Debug(
+ "received batch from a new client, starting to keep stats",
zap.String("client-uuid", clientUUID),
)
}
@@ -204,9 +224,15 @@ func (s *lastReceivedClientStats) update(
if s.batchSeqNo > 0 {
metrics.BatchesSent.Inc(batchSeqNo - s.batchSeqNo)
if stats != nil {
- metrics.FailedToEmitSpans.Inc(stats.FailedToEmitSpans - s.failedToEmitSpans)
- metrics.TooLargeDroppedSpans.Inc(stats.TooLargeDroppedSpans - s.tooLargeDroppedSpans)
- metrics.FullQueueDroppedSpans.Inc(stats.FullQueueDroppedSpans - s.fullQueueDroppedSpans)
+ metrics.FailedToEmitSpans.Inc(
+ stats.FailedToEmitSpans - s.failedToEmitSpans,
+ )
+ metrics.TooLargeDroppedSpans.Inc(
+ stats.TooLargeDroppedSpans - s.tooLargeDroppedSpans,
+ )
+ metrics.FullQueueDroppedSpans.Inc(
+ stats.FullQueueDroppedSpans - s.fullQueueDroppedSpans,
+ )
}
}
diff --git a/cmd/agent/app/reporter/client_metrics_test.go b/cmd/agent/app/reporter/client_metrics_test.go
index 64c1edb3d80..854f4de165e 100644
--- a/cmd/agent/app/reporter/client_metrics_test.go
+++ b/cmd/agent/app/reporter/client_metrics_test.go
@@ -52,7 +52,10 @@ func testClientMetrics(fn func(tr *clientMetricsTest)) {
testClientMetricsWithParams(ClientMetricsReporterParams{}, fn)
}
-func testClientMetricsWithParams(params ClientMetricsReporterParams, fn func(tr *clientMetricsTest)) {
+func testClientMetricsWithParams(
+ params ClientMetricsReporterParams,
+ fn func(tr *clientMetricsTest),
+) {
r1 := testutils.NewInMemoryReporter()
zapCore, logs := observer.New(zap.DebugLevel)
mb := metricstest.NewFactory(time.Hour)
@@ -76,7 +79,10 @@ func testClientMetricsWithParams(params ClientMetricsReporterParams, fn func(tr
func TestClientMetricsReporter_Zipkin(t *testing.T) {
testClientMetrics(func(tr *clientMetricsTest) {
- require.NoError(t, tr.r.EmitZipkinBatch(context.Background(), []*zipkincore.Span{{}}))
+ require.NoError(
+ t,
+ tr.r.EmitZipkinBatch(context.Background(), []*zipkincore.Span{{}}),
+ )
assert.Len(t, tr.mr.ZipkinSpans(), 1)
})
}
@@ -115,9 +121,21 @@ func TestClientMetricsReporter_Jaeger(t *testing.T) {
expCounters: []metricstest.ExpectedMetric{
{Name: prefix + "batches_received", Value: 1},
{Name: prefix + "batches_sent", Value: 0},
- {Name: prefix + "spans_dropped", Tags: tag("cause", "full-queue"), Value: 0},
- {Name: prefix + "spans_dropped", Tags: tag("cause", "too-large"), Value: 0},
- {Name: prefix + "spans_dropped", Tags: tag("cause", "send-failure"), Value: 0},
+ {
+ Name: prefix + "spans_dropped",
+ Tags: tag("cause", "full-queue"),
+ Value: 0,
+ },
+ {
+ Name: prefix + "spans_dropped",
+ Tags: tag("cause", "too-large"),
+ Value: 0,
+ },
+ {
+ Name: prefix + "spans_dropped",
+ Tags: tag("cause", "send-failure"),
+ Value: 0,
+ },
},
expGauges: []metricstest.ExpectedMetric{
{Name: prefix + "connected_clients", Value: 1},
@@ -134,9 +152,21 @@ func TestClientMetricsReporter_Jaeger(t *testing.T) {
expCounters: []metricstest.ExpectedMetric{
{Name: prefix + "batches_received", Value: 2},
{Name: prefix + "batches_sent", Value: 5},
- {Name: prefix + "spans_dropped", Tags: tag("cause", "full-queue"), Value: 5},
- {Name: prefix + "spans_dropped", Tags: tag("cause", "too-large"), Value: 5},
- {Name: prefix + "spans_dropped", Tags: tag("cause", "send-failure"), Value: 5},
+ {
+ Name: prefix + "spans_dropped",
+ Tags: tag("cause", "full-queue"),
+ Value: 5,
+ },
+ {
+ Name: prefix + "spans_dropped",
+ Tags: tag("cause", "too-large"),
+ Value: 5,
+ },
+ {
+ Name: prefix + "spans_dropped",
+ Tags: tag("cause", "send-failure"),
+ Value: 5,
+ },
},
},
{
@@ -158,9 +188,21 @@ func TestClientMetricsReporter_Jaeger(t *testing.T) {
}, expCounters: []metricstest.ExpectedMetric{
{Name: prefix + "batches_received", Value: 4},
{Name: prefix + "batches_sent", Value: 10},
- {Name: prefix + "spans_dropped", Tags: tag("cause", "full-queue"), Value: 7},
- {Name: prefix + "spans_dropped", Tags: tag("cause", "too-large"), Value: 8},
- {Name: prefix + "spans_dropped", Tags: tag("cause", "send-failure"), Value: 9},
+ {
+ Name: prefix + "spans_dropped",
+ Tags: tag("cause", "full-queue"),
+ Value: 7,
+ },
+ {
+ Name: prefix + "spans_dropped",
+ Tags: tag("cause", "too-large"),
+ Value: 8,
+ },
+ {
+ Name: prefix + "spans_dropped",
+ Tags: tag("cause", "send-failure"),
+ Value: 9,
+ },
},
},
}
@@ -178,7 +220,9 @@ func TestClientMetricsReporter_Jaeger(t *testing.T) {
Stats: test.stats,
}
if test.clientUUID != nil {
- batch.Process.Tags = []*jaeger.Tag{{Key: "client-uuid", VStr: test.clientUUID}}
+ batch.Process.Tags = []*jaeger.Tag{
+ {Key: "client-uuid", VStr: test.clientUUID},
+ }
}
err := tr.r.EmitBatch(context.Background(), batch)
@@ -211,13 +255,30 @@ func TestClientMetricsReporter_ClientUUID(t *testing.T) {
{process: nil, clientUUID: ""},
{process: &jaeger.Process{}, clientUUID: ""},
{process: &jaeger.Process{Tags: []*jaeger.Tag{}}, clientUUID: ""},
- {process: &jaeger.Process{Tags: []*jaeger.Tag{{Key: "blah"}}}, clientUUID: ""},
- {process: &jaeger.Process{Tags: []*jaeger.Tag{{Key: "client-uuid"}}}, clientUUID: ""},
- {process: &jaeger.Process{Tags: []*jaeger.Tag{{Key: "client-uuid", VStr: &id}}}, clientUUID: id},
+ {
+ process: &jaeger.Process{Tags: []*jaeger.Tag{{Key: "blah"}}},
+ clientUUID: "",
+ },
+ {
+ process: &jaeger.Process{
+ Tags: []*jaeger.Tag{{Key: "client-uuid"}},
+ },
+ clientUUID: "",
+ },
+ {
+ process: &jaeger.Process{
+ Tags: []*jaeger.Tag{{Key: "client-uuid", VStr: &id}},
+ },
+ clientUUID: id,
+ },
}
for i, test := range tests {
t.Run(fmt.Sprintf("iter%d", i), func(t *testing.T) {
- assert.Equal(t, test.clientUUID, clientUUID(&jaeger.Batch{Process: test.process}))
+ assert.Equal(
+ t,
+ test.clientUUID,
+ clientUUID(&jaeger.Batch{Process: test.process}),
+ )
})
}
}
@@ -235,7 +296,9 @@ func TestClientMetricsReporter_Expire(t *testing.T) {
Spans: []*jaeger.Span{{}},
Process: &jaeger.Process{
ServiceName: "blah",
- Tags: []*jaeger.Tag{{Key: "client-uuid", VStr: &clientUUID}},
+ Tags: []*jaeger.Tag{
+ {Key: "client-uuid", VStr: &clientUUID},
+ },
},
SeqNo: nPtr(1),
}
diff --git a/cmd/agent/app/reporter/connect_metrics.go b/cmd/agent/app/reporter/connect_metrics.go
index 7af947eab1c..fc9145df288 100644
--- a/cmd/agent/app/reporter/connect_metrics.go
+++ b/cmd/agent/app/reporter/connect_metrics.go
@@ -37,7 +37,11 @@ type ConnectMetrics struct {
// NewConnectMetrics will be initialize ConnectMetrics
func NewConnectMetrics(mf metrics.Factory) *ConnectMetrics {
cm := &ConnectMetrics{}
- metrics.MustInit(&cm.metrics, mf.Namespace(metrics.NSOptions{Name: "connection_status"}), nil)
+ metrics.MustInit(
+ &cm.metrics,
+ mf.Namespace(metrics.NSOptions{Name: "connection_status"}),
+ nil,
+ )
if r := expvar.Get("gRPCTarget"); r == nil {
cm.target = expvar.NewString("gRPCTarget")
diff --git a/cmd/agent/app/reporter/connect_metrics_test.go b/cmd/agent/app/reporter/connect_metrics_test.go
index d57a445284e..1a69f71b2ae 100644
--- a/cmd/agent/app/reporter/connect_metrics_test.go
+++ b/cmd/agent/app/reporter/connect_metrics_test.go
@@ -41,17 +41,33 @@ func TestConnectMetrics(t *testing.T) {
// no connection
cm.OnConnectionStatusChange(false)
- assert.EqualValues(t, 0, getGauge()["connection_status.collector_connected"])
+ assert.EqualValues(
+ t,
+ 0,
+ getGauge()["connection_status.collector_connected"],
+ )
// first connection
cm.OnConnectionStatusChange(true)
- assert.EqualValues(t, 1, getGauge()["connection_status.collector_connected"])
- assert.EqualValues(t, 1, getCount()["connection_status.collector_reconnects"])
+ assert.EqualValues(
+ t,
+ 1,
+ getGauge()["connection_status.collector_connected"],
+ )
+ assert.EqualValues(
+ t,
+ 1,
+ getCount()["connection_status.collector_reconnects"],
+ )
// reconnect
cm.OnConnectionStatusChange(false)
cm.OnConnectionStatusChange(true)
- assert.EqualValues(t, 2, getCount()["connection_status.collector_reconnects"])
+ assert.EqualValues(
+ t,
+ 2,
+ getCount()["connection_status.collector_reconnects"],
+ )
cm.RecordTarget("collector-host")
assert.Equal(t, `"collector-host"`, expvar.Get("gRPCTarget").String())
diff --git a/cmd/agent/app/reporter/flags.go b/cmd/agent/app/reporter/flags.go
index c3ec9616789..7332009a592 100644
--- a/cmd/agent/app/reporter/flags.go
+++ b/cmd/agent/app/reporter/flags.go
@@ -45,9 +45,17 @@ type Options struct {
// AddFlags adds flags for Options.
func AddFlags(flags *flag.FlagSet) {
- flags.String(reporterType, string(GRPC), fmt.Sprintf("Reporter type to use e.g. %s", string(GRPC)))
+ flags.String(
+ reporterType,
+ string(GRPC),
+ fmt.Sprintf("Reporter type to use e.g. %s", string(GRPC)),
+ )
if !setupcontext.IsAllInOne() {
- flags.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}")
+ flags.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}",
+ )
}
}
diff --git a/cmd/agent/app/reporter/grpc/builder.go b/cmd/agent/app/reporter/grpc/builder.go
index 9290107dd3a..9b514fe0249 100644
--- a/cmd/agent/app/reporter/grpc/builder.go
+++ b/cmd/agent/app/reporter/grpc/builder.go
@@ -58,7 +58,11 @@ func NewConnBuilder() *ConnBuilder {
}
// CreateConnection creates the gRPC connection
-func (b *ConnBuilder) CreateConnection(ctx context.Context, logger *zap.Logger, mFactory metrics.Factory) (*grpc.ClientConn, error) {
+func (b *ConnBuilder) CreateConnection(
+ ctx context.Context,
+ logger *zap.Logger,
+ mFactory metrics.Factory,
+) (*grpc.ClientConn, error) {
var dialOptions []grpc.DialOption
var dialTarget string
if b.TLS.Enabled { // user requested a secure connection
@@ -76,8 +80,15 @@ func (b *ConnBuilder) CreateConnection(ctx context.Context, logger *zap.Logger,
}
if b.Notifier != nil && b.Discoverer != nil {
- logger.Info("Using external discovery service with roundrobin load balancer")
- grpcResolver := grpcresolver.New(b.Notifier, b.Discoverer, logger, b.DiscoveryMinPeers)
+ logger.Info(
+ "Using external discovery service with roundrobin load balancer",
+ )
+ grpcResolver := grpcresolver.New(
+ b.Notifier,
+ b.Discoverer,
+ logger,
+ b.DiscoveryMinPeers,
+ )
dialTarget = grpcResolver.Scheme() + ":///round_robin"
} else {
if b.CollectorHostPorts == nil {
@@ -99,7 +110,10 @@ func (b *ConnBuilder) CreateConnection(ctx context.Context, logger *zap.Logger,
}
}
dialOptions = append(dialOptions, grpc.WithDefaultServiceConfig(grpcresolver.GRPCServiceConfig))
- dialOptions = append(dialOptions, grpc.WithUnaryInterceptor(grpc_retry.UnaryClientInterceptor(grpc_retry.WithMax(b.MaxRetry))))
+ dialOptions = append(
+ dialOptions,
+ grpc.WithUnaryInterceptor(grpc_retry.UnaryClientInterceptor(grpc_retry.WithMax(b.MaxRetry))),
+ )
dialOptions = append(dialOptions, b.AdditionalDialOptions...)
conn, err := grpc.NewClient(dialTarget, dialOptions...)
@@ -108,7 +122,9 @@ func (b *ConnBuilder) CreateConnection(ctx context.Context, logger *zap.Logger,
}
connectMetrics := reporter.NewConnectMetrics(
- mFactory.Namespace(metrics.NSOptions{Tags: map[string]string{"protocol": "grpc"}}),
+ mFactory.Namespace(
+ metrics.NSOptions{Tags: map[string]string{"protocol": "grpc"}},
+ ),
)
go func(cc *grpc.ClientConn, cm *reporter.ConnectMetrics) {
@@ -128,7 +144,11 @@ func (b *ConnBuilder) CreateConnection(ctx context.Context, logger *zap.Logger,
cm.OnConnectionStatusChange(false)
}
- logger.Info("Agent collector connection state change", zap.String("dialTarget", dialTarget), zap.Stringer("status", s))
+ logger.Info(
+ "Agent collector connection state change",
+ zap.String("dialTarget", dialTarget),
+ zap.Stringer("status", s),
+ )
cc.WaitForStateChange(ctx, s)
}
}
diff --git a/cmd/agent/app/reporter/grpc/builder_test.go b/cmd/agent/app/reporter/grpc/builder_test.go
index 18ae28df95f..565e697499b 100644
--- a/cmd/agent/app/reporter/grpc/builder_test.go
+++ b/cmd/agent/app/reporter/grpc/builder_test.go
@@ -83,9 +83,13 @@ func TestBuilderWithCollectors(t *testing.T) {
expectedError string
}{
{
- target: "///round_robin",
- name: "with roundrobin schema",
- hostPorts: []string{"127.0.0.1:9876", "127.0.0.1:9877", "127.0.0.1:9878"},
+ target: "///round_robin",
+ name: "with roundrobin schema",
+ hostPorts: []string{
+ "127.0.0.1:9876",
+ "127.0.0.1:9877",
+ "127.0.0.1:9878",
+ },
checkSuffixOnly: true,
notifier: nil,
discoverer: nil,
@@ -127,13 +131,20 @@ func TestBuilderWithCollectors(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
- conn, err := cfg.CreateConnection(ctx, zap.NewNop(), metrics.NullFactory)
+ conn, err := cfg.CreateConnection(
+ ctx,
+ zap.NewNop(),
+ metrics.NullFactory,
+ )
if test.expectedError == "" {
require.NoError(t, err)
defer conn.Close()
require.NotNil(t, conn)
if test.checkSuffixOnly {
- assert.True(t, strings.HasSuffix(conn.Target(), test.target))
+ assert.True(
+ t,
+ strings.HasSuffix(conn.Target(), test.target),
+ )
} else {
assert.Equal(t, conn.Target(), test.target)
}
@@ -187,7 +198,13 @@ func TestProxyBuilder(t *testing.T) {
defer cancel()
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
- proxy, err := NewCollectorProxy(ctx, test.grpcBuilder, nil, metrics.NullFactory, zap.NewNop())
+ proxy, err := NewCollectorProxy(
+ ctx,
+ test.grpcBuilder,
+ nil,
+ metrics.NullFactory,
+ zap.NewNop(),
+ )
if test.expectError {
require.Error(t, err)
@@ -319,7 +336,9 @@ func TestProxyClientTLS(t *testing.T) {
if test.serverTLS.Enabled {
tlsCfg, err := test.serverTLS.Config(zap.NewNop())
require.NoError(t, err)
- opts = []grpc.ServerOption{grpc.Creds(credentials.NewTLS(tlsCfg))}
+ opts = []grpc.ServerOption{
+ grpc.Creds(credentials.NewTLS(tlsCfg)),
+ }
}
defer test.serverTLS.Close()
@@ -334,8 +353,10 @@ func TestProxyClientTLS(t *testing.T) {
_, port, _ := net.SplitHostPort(addr.String())
grpcBuilder := &ConnBuilder{
- CollectorHostPorts: []string{net.JoinHostPort("localhost", port)},
- TLS: test.clientTLS,
+ CollectorHostPorts: []string{
+ net.JoinHostPort("localhost", port),
+ },
+ TLS: test.clientTLS,
}
proxy, err := NewCollectorProxy(
ctx,
@@ -352,7 +373,13 @@ func TestProxyClientTLS(t *testing.T) {
r := proxy.GetReporter()
- err = r.EmitBatch(ctx, &jaeger.Batch{Spans: []*jaeger.Span{{OperationName: "op"}}, Process: &jaeger.Process{ServiceName: "service"}})
+ err = r.EmitBatch(
+ ctx,
+ &jaeger.Batch{
+ Spans: []*jaeger.Span{{OperationName: "op"}},
+ Process: &jaeger.Process{ServiceName: "service"},
+ },
+ )
if test.expectError {
require.Error(t, err)
@@ -369,7 +396,14 @@ type fakeInterceptor struct {
isCalled bool
}
-func (f *fakeInterceptor) intercept(ctx context.Context, method string, req, reply any, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
+func (f *fakeInterceptor) intercept(
+ ctx context.Context,
+ method string,
+ req, reply any,
+ cc *grpc.ClientConn,
+ invoker grpc.UnaryInvoker,
+ opts ...grpc.CallOption,
+) error {
f.isCalled = true
return invoker(ctx, method, req, reply, cc, opts...)
}
@@ -383,8 +417,10 @@ func TestBuilderWithAdditionalDialOptions(t *testing.T) {
defer fi.assertCalled(t)
cb := ConnBuilder{
- CollectorHostPorts: []string{"127.0.0.1:14268"},
- AdditionalDialOptions: []grpc.DialOption{grpc.WithUnaryInterceptor(fi.intercept)},
+ CollectorHostPorts: []string{"127.0.0.1:14268"},
+ AdditionalDialOptions: []grpc.DialOption{
+ grpc.WithUnaryInterceptor(fi.intercept),
+ },
}
ctx, cancel := context.WithCancel(context.Background())
@@ -394,6 +430,11 @@ func TestBuilderWithAdditionalDialOptions(t *testing.T) {
defer r.Close()
assert.NotNil(t, r)
- err = r.Invoke(context.Background(), "test", map[string]string{}, map[string]string{}, []grpc.CallOption{}...)
+ err = r.Invoke(
+ context.Background(),
+ "test",
+ map[string]string{},
+ map[string]string{},
+ []grpc.CallOption{}...)
require.Error(t, err, "should error because no server is running")
}
diff --git a/cmd/agent/app/reporter/grpc/collector_proxy.go b/cmd/agent/app/reporter/grpc/collector_proxy.go
index ec41f729b06..e280741009c 100644
--- a/cmd/agent/app/reporter/grpc/collector_proxy.go
+++ b/cmd/agent/app/reporter/grpc/collector_proxy.go
@@ -37,12 +37,23 @@ type ProxyBuilder struct {
}
// NewCollectorProxy creates ProxyBuilder
-func NewCollectorProxy(ctx context.Context, builder *ConnBuilder, agentTags map[string]string, mFactory metrics.Factory, logger *zap.Logger) (*ProxyBuilder, error) {
+func NewCollectorProxy(
+ ctx context.Context,
+ builder *ConnBuilder,
+ agentTags map[string]string,
+ mFactory metrics.Factory,
+ logger *zap.Logger,
+) (*ProxyBuilder, error) {
conn, err := builder.CreateConnection(ctx, logger, mFactory)
if err != nil {
return nil, err
}
- grpcMetrics := mFactory.Namespace(metrics.NSOptions{Name: "", Tags: map[string]string{"protocol": "grpc"}})
+ grpcMetrics := mFactory.Namespace(
+ metrics.NSOptions{
+ Name: "",
+ Tags: map[string]string{"protocol": "grpc"},
+ },
+ )
r1 := NewReporter(conn, agentTags, logger)
r2 := reporter.WrapWithMetrics(r1, grpcMetrics)
r3 := reporter.WrapWithClientMetrics(reporter.ClientMetricsReporterParams{
@@ -51,9 +62,12 @@ func NewCollectorProxy(ctx context.Context, builder *ConnBuilder, agentTags map[
MetricsFactory: mFactory,
})
return &ProxyBuilder{
- conn: conn,
- reporter: r3,
- manager: configmanager.WrapWithMetrics(grpcManager.NewConfigManager(conn), grpcMetrics),
+ conn: conn,
+ reporter: r3,
+ manager: configmanager.WrapWithMetrics(
+ grpcManager.NewConfigManager(conn),
+ grpcMetrics,
+ ),
tlsCloser: &builder.TLS,
}, nil
}
diff --git a/cmd/agent/app/reporter/grpc/collector_proxy_test.go b/cmd/agent/app/reporter/grpc/collector_proxy_test.go
index 4d717c809d2..38f5acb6b99 100644
--- a/cmd/agent/app/reporter/grpc/collector_proxy_test.go
+++ b/cmd/agent/app/reporter/grpc/collector_proxy_test.go
@@ -48,7 +48,13 @@ func TestMultipleCollectors(t *testing.T) {
defer mFactory.Stop()
ctx, cancel := context.WithCancel(context.Background())
cancel()
- proxy, err := NewCollectorProxy(ctx, &ConnBuilder{CollectorHostPorts: []string{addr1.String(), addr2.String()}}, nil, mFactory, zap.NewNop())
+ proxy, err := NewCollectorProxy(
+ ctx,
+ &ConnBuilder{CollectorHostPorts: []string{addr1.String(), addr2.String()}},
+ nil,
+ mFactory,
+ zap.NewNop(),
+ )
require.NoError(t, err)
require.NotNil(t, proxy)
assert.NotNil(t, proxy.GetReporter())
@@ -59,9 +65,16 @@ func TestMultipleCollectors(t *testing.T) {
r := proxy.GetReporter()
// TODO do not iterate, just create two batches
for i := 0; i < 100; i++ {
- err := r.EmitBatch(context.Background(), &jaeger.Batch{Spans: []*jaeger.Span{{OperationName: "op"}}, Process: &jaeger.Process{ServiceName: "service"}})
+ err := r.EmitBatch(
+ context.Background(),
+ &jaeger.Batch{
+ Spans: []*jaeger.Span{{OperationName: "op"}},
+ Process: &jaeger.Process{ServiceName: "service"},
+ },
+ )
require.NoError(t, err)
- if len(spanHandler1.getRequests()) > 0 && len(spanHandler2.getRequests()) > 0 {
+ if len(spanHandler1.getRequests()) > 0 &&
+ len(spanHandler2.getRequests()) > 0 {
bothServers = true
break
}
@@ -73,7 +86,11 @@ func TestMultipleCollectors(t *testing.T) {
require.NoError(t, proxy.Close())
}
-func initializeGRPCTestServer(t *testing.T, beforeServe func(server *grpc.Server), opts ...grpc.ServerOption) (*grpc.Server, net.Addr) {
+func initializeGRPCTestServer(
+ t *testing.T,
+ beforeServe func(server *grpc.Server),
+ opts ...grpc.ServerOption,
+) (*grpc.Server, net.Addr) {
server := grpc.NewServer(opts...)
lis, err := net.Listen("tcp", "localhost:0")
require.NoError(t, err)
diff --git a/cmd/agent/app/reporter/grpc/flags.go b/cmd/agent/app/reporter/grpc/flags.go
index 9ea504be4e2..6f1888bec5b 100644
--- a/cmd/agent/app/reporter/grpc/flags.go
+++ b/cmd/agent/app/reporter/grpc/flags.go
@@ -40,7 +40,11 @@ var tlsFlagsConfig = tlscfg.ClientFlagsConfig{
func AddFlags(flags *flag.FlagSet) {
flags.Uint(retry, defaultMaxRetry, "Sets the maximum number of retries for a call")
flags.Int(discoveryMinPeers, 3, "Max number of collectors to which the agent will try to connect at any given time")
- flags.String(collectorHostPort, "", "Comma-separated string representing host:port of a static list of collectors to connect to directly")
+ flags.String(
+ collectorHostPort,
+ "",
+ "Comma-separated string representing host:port of a static list of collectors to connect to directly",
+ )
tlsFlagsConfig.AddFlags(flags)
}
diff --git a/cmd/agent/app/reporter/grpc/flags_test.go b/cmd/agent/app/reporter/grpc/flags_test.go
index 9ba6e58843b..6006ea4fb43 100644
--- a/cmd/agent/app/reporter/grpc/flags_test.go
+++ b/cmd/agent/app/reporter/grpc/flags_test.go
@@ -32,16 +32,34 @@ func TestBindFlags(t *testing.T) {
expected *ConnBuilder
}{
{
- cOpts: []string{"--reporter.grpc.host-port=localhost:1111", "--reporter.grpc.retry.max=15"},
- expected: &ConnBuilder{CollectorHostPorts: []string{"localhost:1111"}, MaxRetry: 15, DiscoveryMinPeers: 3},
+ cOpts: []string{
+ "--reporter.grpc.host-port=localhost:1111",
+ "--reporter.grpc.retry.max=15",
+ },
+ expected: &ConnBuilder{
+ CollectorHostPorts: []string{"localhost:1111"},
+ MaxRetry: 15,
+ DiscoveryMinPeers: 3,
+ },
},
{
- cOpts: []string{"--reporter.grpc.host-port=localhost:1111,localhost:2222"},
- expected: &ConnBuilder{CollectorHostPorts: []string{"localhost:1111", "localhost:2222"}, MaxRetry: defaultMaxRetry, DiscoveryMinPeers: 3},
+ cOpts: []string{"--reporter.grpc.host-port=localhost:1111,localhost:2222"},
+ expected: &ConnBuilder{
+ CollectorHostPorts: []string{"localhost:1111", "localhost:2222"},
+ MaxRetry: defaultMaxRetry,
+ DiscoveryMinPeers: 3,
+ },
},
{
- cOpts: []string{"--reporter.grpc.host-port=localhost:1111,localhost:2222", "--reporter.grpc.discovery.min-peers=5"},
- expected: &ConnBuilder{CollectorHostPorts: []string{"localhost:1111", "localhost:2222"}, MaxRetry: defaultMaxRetry, DiscoveryMinPeers: 5},
+ cOpts: []string{
+ "--reporter.grpc.host-port=localhost:1111,localhost:2222",
+ "--reporter.grpc.discovery.min-peers=5",
+ },
+ expected: &ConnBuilder{
+ CollectorHostPorts: []string{"localhost:1111", "localhost:2222"},
+ MaxRetry: defaultMaxRetry,
+ DiscoveryMinPeers: 5,
+ },
},
}
for _, test := range tests {
diff --git a/cmd/agent/app/reporter/grpc/reporter.go b/cmd/agent/app/reporter/grpc/reporter.go
index 20ba5241497..62acfc4219b 100644
--- a/cmd/agent/app/reporter/grpc/reporter.go
+++ b/cmd/agent/app/reporter/grpc/reporter.go
@@ -42,22 +42,34 @@ type Reporter struct {
}
// NewReporter creates gRPC reporter.
-func NewReporter(conn *grpc.ClientConn, agentTags map[string]string, logger *zap.Logger) *Reporter {
+func NewReporter(
+ conn *grpc.ClientConn,
+ agentTags map[string]string,
+ logger *zap.Logger,
+) *Reporter {
return &Reporter{
collector: api_v2.NewCollectorServiceClient(conn),
agentTags: makeModelKeyValue(agentTags),
logger: logger,
- sanitizer: zipkin2.NewChainedSanitizer(zipkin2.NewStandardSanitizers()...),
+ sanitizer: zipkin2.NewChainedSanitizer(
+ zipkin2.NewStandardSanitizers()...),
}
}
// EmitBatch implements EmitBatch() of Reporter
func (r *Reporter) EmitBatch(ctx context.Context, b *thrift.Batch) error {
- return r.send(ctx, jConverter.ToDomain(b.Spans, nil), jConverter.ToDomainProcess(b.Process))
+ return r.send(
+ ctx,
+ jConverter.ToDomain(b.Spans, nil),
+ jConverter.ToDomainProcess(b.Process),
+ )
}
// EmitZipkinBatch implements EmitZipkinBatch() of Reporter
-func (r *Reporter) EmitZipkinBatch(ctx context.Context, zSpans []*zipkincore.Span) error {
+func (r *Reporter) EmitZipkinBatch(
+ ctx context.Context,
+ zSpans []*zipkincore.Span,
+) error {
for i := range zSpans {
zSpans[i] = r.sanitizer.Sanitize(zSpans[i])
}
@@ -68,15 +80,23 @@ func (r *Reporter) EmitZipkinBatch(ctx context.Context, zSpans []*zipkincore.Spa
return r.send(ctx, trace.Spans, nil)
}
-func (r *Reporter) send(ctx context.Context, spans []*model.Span, process *model.Process) error {
+func (r *Reporter) send(
+ ctx context.Context,
+ spans []*model.Span,
+ process *model.Process,
+) error {
spans, process = addProcessTags(spans, process, r.agentTags)
batch := model.Batch{Spans: spans, Process: process}
req := &api_v2.PostSpansRequest{Batch: batch}
_, err := r.collector.PostSpans(ctx, req)
if err != nil {
stat, ok := status.FromError(err)
- if ok && stat.Code() == codes.PermissionDenied && stat.Message() == "missing tenant header" {
- r.logger.Debug("Could not report untenanted spans over gRPC", zap.Error(err))
+ if ok && stat.Code() == codes.PermissionDenied &&
+ stat.Message() == "missing tenant header" {
+ r.logger.Debug(
+ "Could not report untenanted spans over gRPC",
+ zap.Error(err),
+ )
} else {
r.logger.Error("Could not send spans over gRPC", zap.Error(err))
}
@@ -86,7 +106,11 @@ func (r *Reporter) send(ctx context.Context, spans []*model.Span, process *model
}
// addProcessTags appends jaeger tags for the agent to every span it sends to the collector.
-func addProcessTags(spans []*model.Span, process *model.Process, agentTags []model.KeyValue) ([]*model.Span, *model.Process) {
+func addProcessTags(
+ spans []*model.Span,
+ process *model.Process,
+ agentTags []model.KeyValue,
+) ([]*model.Span, *model.Process) {
if len(agentTags) == 0 {
return spans, process
}
diff --git a/cmd/agent/app/reporter/grpc/reporter_test.go b/cmd/agent/app/reporter/grpc/reporter_test.go
index 19345ce8527..14e491ad90c 100644
--- a/cmd/agent/app/reporter/grpc/reporter_test.go
+++ b/cmd/agent/app/reporter/grpc/reporter_test.go
@@ -46,7 +46,10 @@ func (h *mockSpanHandler) getRequests() []*api_v2.PostSpansRequest {
return h.requests
}
-func (h *mockSpanHandler) PostSpans(c context.Context, r *api_v2.PostSpansRequest) (*api_v2.PostSpansResponse, error) {
+func (h *mockSpanHandler) PostSpans(
+ c context.Context,
+ r *api_v2.PostSpansRequest,
+) (*api_v2.PostSpansResponse, error) {
h.mux.Lock()
defer h.mux.Unlock()
h.requests = append(h.requests, r)
@@ -59,7 +62,10 @@ func TestReporter_EmitZipkinBatch(t *testing.T) {
api_v2.RegisterCollectorServiceServer(s, handler)
})
defer s.Stop()
- conn, err := grpc.NewClient(addr.String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
+ conn, err := grpc.NewClient(
+ addr.String(),
+ grpc.WithTransportCredentials(insecure.NewCredentials()),
+ )
require.NoError(t, err)
defer conn.Close()
@@ -72,12 +78,26 @@ func TestReporter_EmitZipkinBatch(t *testing.T) {
expected model.Batch
err string
}{
- {in: &zipkincore.Span{}, err: "cannot find service name in Zipkin span [traceID=0, spanID=0]"},
{
- in: &zipkincore.Span{Name: "jonatan", TraceID: 1, ID: 2, Timestamp: &a, Annotations: []*zipkincore.Annotation{{Value: zipkincore.CLIENT_SEND, Host: &zipkincore.Endpoint{ServiceName: "spring"}}}},
+ in: &zipkincore.Span{},
+ err: "cannot find service name in Zipkin span [traceID=0, spanID=0]",
+ },
+ {
+ in: &zipkincore.Span{
+ Name: "jonatan",
+ TraceID: 1,
+ ID: 2,
+ Timestamp: &a,
+ Annotations: []*zipkincore.Annotation{
+ {Value: zipkincore.CLIENT_SEND, Host: &zipkincore.Endpoint{ServiceName: "spring"}},
+ },
+ },
expected: model.Batch{
Spans: []*model.Span{{
- TraceID: model.NewTraceID(0, 1), SpanID: model.NewSpanID(2), OperationName: "jonatan", Duration: time.Microsecond * 1,
+ TraceID: model.NewTraceID(
+ 0,
+ 1,
+ ), SpanID: model.NewSpanID(2), OperationName: "jonatan", Duration: time.Microsecond * 1,
Tags: model.KeyValues{{Key: "span.kind", VStr: "client", VType: model.StringType}},
Process: &model.Process{ServiceName: "spring"}, StartTime: tm.UTC(),
}},
@@ -85,7 +105,10 @@ func TestReporter_EmitZipkinBatch(t *testing.T) {
},
}
for _, test := range tests {
- err = rep.EmitZipkinBatch(context.Background(), []*zipkincore.Span{test.in})
+ err = rep.EmitZipkinBatch(
+ context.Background(),
+ []*zipkincore.Span{test.in},
+ )
if test.err != "" {
require.EqualError(t, err, test.err)
} else {
@@ -101,7 +124,10 @@ func TestReporter_EmitBatch(t *testing.T) {
api_v2.RegisterCollectorServiceServer(s, handler)
})
defer s.Stop()
- conn, err := grpc.NewClient(addr.String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
+ conn, err := grpc.NewClient(
+ addr.String(),
+ grpc.WithTransportCredentials(insecure.NewCredentials()),
+ )
require.NoError(t, err)
defer conn.Close()
rep := NewReporter(conn, nil, zap.NewNop())
@@ -113,8 +139,14 @@ func TestReporter_EmitBatch(t *testing.T) {
err string
}{
{
- in: &jThrift.Batch{Process: &jThrift.Process{ServiceName: "node"}, Spans: []*jThrift.Span{{OperationName: "foo", StartTime: int64(model.TimeAsEpochMicroseconds(tm))}}},
- expected: model.Batch{Process: &model.Process{ServiceName: "node"}, Spans: []*model.Span{{OperationName: "foo", StartTime: tm.UTC()}}},
+ in: &jThrift.Batch{
+ Process: &jThrift.Process{ServiceName: "node"},
+ Spans: []*jThrift.Span{{OperationName: "foo", StartTime: int64(model.TimeAsEpochMicroseconds(tm))}},
+ },
+ expected: model.Batch{
+ Process: &model.Process{ServiceName: "node"},
+ Spans: []*model.Span{{OperationName: "foo", StartTime: tm.UTC()}},
+ },
},
}
for _, test := range tests {
@@ -129,7 +161,10 @@ func TestReporter_EmitBatch(t *testing.T) {
}
func TestReporter_SendFailure(t *testing.T) {
- conn, err := grpc.NewClient("invalid-host-name-blah:12345", grpc.WithTransportCredentials(insecure.NewCredentials()))
+ conn, err := grpc.NewClient(
+ "invalid-host-name-blah:12345",
+ grpc.WithTransportCredentials(insecure.NewCredentials()),
+ )
require.NoError(t, err)
defer conn.Close()
rep := NewReporter(conn, nil, zap.NewNop())
@@ -140,21 +175,37 @@ func TestReporter_SendFailure(t *testing.T) {
func TestReporter_AddProcessTags_EmptyTags(t *testing.T) {
tags := map[string]string{}
- spans := []*model.Span{{TraceID: model.NewTraceID(0, 1), SpanID: model.NewSpanID(2), OperationName: "jonatan"}}
+ spans := []*model.Span{
+ {
+ TraceID: model.NewTraceID(0, 1),
+ SpanID: model.NewSpanID(2),
+ OperationName: "jonatan",
+ },
+ }
actualSpans, _ := addProcessTags(spans, nil, makeModelKeyValue(tags))
assert.Equal(t, spans, actualSpans)
}
func TestReporter_AddProcessTags_ZipkinBatch(t *testing.T) {
tags := map[string]string{"key": "value"}
- spans := []*model.Span{{TraceID: model.NewTraceID(0, 1), SpanID: model.NewSpanID(2), OperationName: "jonatan", Process: &model.Process{ServiceName: "spring"}}}
+ spans := []*model.Span{
+ {
+ TraceID: model.NewTraceID(0, 1),
+ SpanID: model.NewSpanID(2),
+ OperationName: "jonatan",
+ Process: &model.Process{ServiceName: "spring"},
+ },
+ }
expectedSpans := []*model.Span{
{
TraceID: model.NewTraceID(0, 1),
SpanID: model.NewSpanID(2),
OperationName: "jonatan",
- Process: &model.Process{ServiceName: "spring", Tags: []model.KeyValue{model.String("key", "value")}},
+ Process: &model.Process{
+ ServiceName: "spring",
+ Tags: []model.KeyValue{model.String("key", "value")},
+ },
},
}
actualSpans, _ := addProcessTags(spans, nil, makeModelKeyValue(tags))
@@ -164,10 +215,19 @@ func TestReporter_AddProcessTags_ZipkinBatch(t *testing.T) {
func TestReporter_AddProcessTags_JaegerBatch(t *testing.T) {
tags := map[string]string{"key": "value"}
- spans := []*model.Span{{TraceID: model.NewTraceID(0, 1), SpanID: model.NewSpanID(2), OperationName: "jonatan"}}
+ spans := []*model.Span{
+ {
+ TraceID: model.NewTraceID(0, 1),
+ SpanID: model.NewSpanID(2),
+ OperationName: "jonatan",
+ },
+ }
process := &model.Process{ServiceName: "spring"}
- expectedProcess := &model.Process{ServiceName: "spring", Tags: []model.KeyValue{model.String("key", "value")}}
+ expectedProcess := &model.Process{
+ ServiceName: "spring",
+ Tags: []model.KeyValue{model.String("key", "value")},
+ }
_, actualProcess := addProcessTags(spans, process, makeModelKeyValue(tags))
assert.Equal(t, expectedProcess, actualProcess)
@@ -183,15 +243,24 @@ func TestReporter_MakeModelKeyValue(t *testing.T) {
type mockMultitenantSpanHandler struct{}
-func (*mockMultitenantSpanHandler) PostSpans(ctx context.Context, r *api_v2.PostSpansRequest) (*api_v2.PostSpansResponse, error) {
+func (*mockMultitenantSpanHandler) PostSpans(
+ ctx context.Context,
+ r *api_v2.PostSpansRequest,
+) (*api_v2.PostSpansResponse, error) {
md, ok := metadata.FromIncomingContext(ctx)
if !ok {
- return &api_v2.PostSpansResponse{}, status.Errorf(codes.PermissionDenied, "missing tenant header")
+ return &api_v2.PostSpansResponse{}, status.Errorf(
+ codes.PermissionDenied,
+ "missing tenant header",
+ )
}
tenants := md["x-tenant"]
if len(tenants) < 1 {
- return &api_v2.PostSpansResponse{}, status.Errorf(codes.PermissionDenied, "missing tenant header")
+ return &api_v2.PostSpansResponse{}, status.Errorf(
+ codes.PermissionDenied,
+ "missing tenant header",
+ )
} else if len(tenants) > 1 {
return &api_v2.PostSpansResponse{}, status.Errorf(codes.PermissionDenied, "extra tenant header")
}
@@ -205,7 +274,10 @@ func TestReporter_MultitenantEmitBatch(t *testing.T) {
api_v2.RegisterCollectorServiceServer(s, handler)
})
defer s.Stop()
- conn, err := grpc.NewClient(addr.String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
+ conn, err := grpc.NewClient(
+ addr.String(),
+ grpc.WithTransportCredentials(insecure.NewCredentials()),
+ )
require.NoError(t, err)
defer func() { require.NoError(t, conn.Close()) }()
rep := NewReporter(conn, nil, zap.NewNop())
@@ -216,7 +288,10 @@ func TestReporter_MultitenantEmitBatch(t *testing.T) {
err string
}{
{
- in: &jThrift.Batch{Process: &jThrift.Process{ServiceName: "node"}, Spans: []*jThrift.Span{{OperationName: "foo", StartTime: int64(model.TimeAsEpochMicroseconds(tm))}}},
+ in: &jThrift.Batch{
+ Process: &jThrift.Process{ServiceName: "node"},
+ Spans: []*jThrift.Span{{OperationName: "foo", StartTime: int64(model.TimeAsEpochMicroseconds(tm))}},
+ },
err: "missing tenant header",
},
}
diff --git a/cmd/agent/app/reporter/metrics.go b/cmd/agent/app/reporter/metrics.go
index a1edaca36c2..f969510c8f4 100644
--- a/cmd/agent/app/reporter/metrics.go
+++ b/cmd/agent/app/reporter/metrics.go
@@ -53,7 +53,10 @@ type MetricsReporter struct {
}
// WrapWithMetrics wraps Reporter and creates metrics for its invocations.
-func WrapWithMetrics(reporter Reporter, mFactory metrics.Factory) *MetricsReporter {
+func WrapWithMetrics(
+ reporter Reporter,
+ mFactory metrics.Factory,
+) *MetricsReporter {
batchesMetrics := map[string]batchMetrics{}
for _, s := range []string{zipkinBatches, jaegerBatches} {
bm := batchMetrics{}
@@ -69,14 +72,20 @@ func WrapWithMetrics(reporter Reporter, mFactory metrics.Factory) *MetricsReport
}
// EmitZipkinBatch emits batch to collector.
-func (r *MetricsReporter) EmitZipkinBatch(ctx context.Context, spans []*zipkincore.Span) error {
+func (r *MetricsReporter) EmitZipkinBatch(
+ ctx context.Context,
+ spans []*zipkincore.Span,
+) error {
err := r.wrapped.EmitZipkinBatch(ctx, spans)
updateMetrics(r.metrics[zipkinBatches], int64(len(spans)), err)
return err
}
// EmitBatch emits batch to collector.
-func (r *MetricsReporter) EmitBatch(ctx context.Context, batch *jaeger.Batch) error {
+func (r *MetricsReporter) EmitBatch(
+ ctx context.Context,
+ batch *jaeger.Batch,
+) error {
size := int64(0)
if batch != nil {
size = int64(len(batch.GetSpans()))
diff --git a/cmd/agent/app/reporter/metrics_test.go b/cmd/agent/app/reporter/metrics_test.go
index 39806d462e6..bd3f5ae2868 100644
--- a/cmd/agent/app/reporter/metrics_test.go
+++ b/cmd/agent/app/reporter/metrics_test.go
@@ -35,67 +35,191 @@ func TestMetricsReporter(t *testing.T) {
rep *mockReporter
}{
{expectedCounters: []metricstest.ExpectedMetric{
- {Name: "reporter.batches.submitted", Tags: map[string]string{"format": "jaeger"}, Value: 1},
- {Name: "reporter.batches.failures", Tags: map[string]string{"format": "jaeger"}, Value: 0},
- {Name: "reporter.spans.submitted", Tags: map[string]string{"format": "jaeger"}, Value: 0},
- {Name: "reporter.spans.failures", Tags: map[string]string{"format": "jaeger"}, Value: 0},
+ {
+ Name: "reporter.batches.submitted",
+ Tags: map[string]string{"format": "jaeger"},
+ Value: 1,
+ },
+ {
+ Name: "reporter.batches.failures",
+ Tags: map[string]string{"format": "jaeger"},
+ Value: 0,
+ },
+ {
+ Name: "reporter.spans.submitted",
+ Tags: map[string]string{"format": "jaeger"},
+ Value: 0,
+ },
+ {
+ Name: "reporter.spans.failures",
+ Tags: map[string]string{"format": "jaeger"},
+ Value: 0,
+ },
}, expectedGauges: []metricstest.ExpectedMetric{
- {Name: "reporter.batch_size", Tags: map[string]string{"format": "jaeger"}, Value: 0},
+ {
+ Name: "reporter.batch_size",
+ Tags: map[string]string{"format": "jaeger"},
+ Value: 0,
+ },
}, action: func(reporter Reporter) {
err := reporter.EmitBatch(context.Background(), nil)
require.NoError(t, err)
}, rep: &mockReporter{}},
{expectedCounters: []metricstest.ExpectedMetric{
- {Name: "reporter.batches.submitted", Tags: map[string]string{"format": "jaeger"}, Value: 1},
- {Name: "reporter.batches.failures", Tags: map[string]string{"format": "jaeger"}, Value: 0},
- {Name: "reporter.spans.submitted", Tags: map[string]string{"format": "jaeger"}, Value: 1},
- {Name: "reporter.spans.failures", Tags: map[string]string{"format": "jaeger"}, Value: 0},
+ {
+ Name: "reporter.batches.submitted",
+ Tags: map[string]string{"format": "jaeger"},
+ Value: 1,
+ },
+ {
+ Name: "reporter.batches.failures",
+ Tags: map[string]string{"format": "jaeger"},
+ Value: 0,
+ },
+ {
+ Name: "reporter.spans.submitted",
+ Tags: map[string]string{"format": "jaeger"},
+ Value: 1,
+ },
+ {
+ Name: "reporter.spans.failures",
+ Tags: map[string]string{"format": "jaeger"},
+ Value: 0,
+ },
}, expectedGauges: []metricstest.ExpectedMetric{
- {Name: "reporter.batch_size", Tags: map[string]string{"format": "jaeger"}, Value: 1},
+ {
+ Name: "reporter.batch_size",
+ Tags: map[string]string{"format": "jaeger"},
+ Value: 1,
+ },
}, action: func(reporter Reporter) {
- err := reporter.EmitBatch(context.Background(), &jaeger.Batch{Spans: []*jaeger.Span{{}}})
+ err := reporter.EmitBatch(
+ context.Background(),
+ &jaeger.Batch{Spans: []*jaeger.Span{{}}},
+ )
require.NoError(t, err)
}, rep: &mockReporter{}},
{expectedCounters: []metricstest.ExpectedMetric{
- {Name: "reporter.batches.submitted", Tags: map[string]string{"format": "zipkin"}, Value: 1},
- {Name: "reporter.batches.failures", Tags: map[string]string{"format": "zipkin"}, Value: 0},
- {Name: "reporter.spans.submitted", Tags: map[string]string{"format": "zipkin"}, Value: 0},
- {Name: "reporter.spans.failures", Tags: map[string]string{"format": "zipkin"}, Value: 0},
+ {
+ Name: "reporter.batches.submitted",
+ Tags: map[string]string{"format": "zipkin"},
+ Value: 1,
+ },
+ {
+ Name: "reporter.batches.failures",
+ Tags: map[string]string{"format": "zipkin"},
+ Value: 0,
+ },
+ {
+ Name: "reporter.spans.submitted",
+ Tags: map[string]string{"format": "zipkin"},
+ Value: 0,
+ },
+ {
+ Name: "reporter.spans.failures",
+ Tags: map[string]string{"format": "zipkin"},
+ Value: 0,
+ },
}, expectedGauges: []metricstest.ExpectedMetric{
- {Name: "reporter.batch_size", Tags: map[string]string{"format": "zipkin"}, Value: 0},
+ {
+ Name: "reporter.batch_size",
+ Tags: map[string]string{"format": "zipkin"},
+ Value: 0,
+ },
}, action: func(reporter Reporter) {
err := reporter.EmitZipkinBatch(context.Background(), nil)
require.NoError(t, err)
}, rep: &mockReporter{}},
{expectedCounters: []metricstest.ExpectedMetric{
- {Name: "reporter.batches.submitted", Tags: map[string]string{"format": "zipkin"}, Value: 1},
- {Name: "reporter.batches.failures", Tags: map[string]string{"format": "zipkin"}, Value: 0},
- {Name: "reporter.spans.submitted", Tags: map[string]string{"format": "zipkin"}, Value: 1},
- {Name: "reporter.spans.failures", Tags: map[string]string{"format": "zipkin"}, Value: 0},
+ {
+ Name: "reporter.batches.submitted",
+ Tags: map[string]string{"format": "zipkin"},
+ Value: 1,
+ },
+ {
+ Name: "reporter.batches.failures",
+ Tags: map[string]string{"format": "zipkin"},
+ Value: 0,
+ },
+ {
+ Name: "reporter.spans.submitted",
+ Tags: map[string]string{"format": "zipkin"},
+ Value: 1,
+ },
+ {
+ Name: "reporter.spans.failures",
+ Tags: map[string]string{"format": "zipkin"},
+ Value: 0,
+ },
}, expectedGauges: []metricstest.ExpectedMetric{
- {Name: "reporter.batch_size", Tags: map[string]string{"format": "zipkin"}, Value: 1},
+ {
+ Name: "reporter.batch_size",
+ Tags: map[string]string{"format": "zipkin"},
+ Value: 1,
+ },
}, action: func(reporter Reporter) {
- err := reporter.EmitZipkinBatch(context.Background(), []*zipkincore.Span{{}})
+ err := reporter.EmitZipkinBatch(
+ context.Background(),
+ []*zipkincore.Span{{}},
+ )
require.NoError(t, err)
}, rep: &mockReporter{}},
{expectedCounters: []metricstest.ExpectedMetric{
- {Name: "reporter.batches.submitted", Tags: map[string]string{"format": "jaeger"}, Value: 0},
- {Name: "reporter.batches.failures", Tags: map[string]string{"format": "jaeger"}, Value: 1},
- {Name: "reporter.spans.submitted", Tags: map[string]string{"format": "jaeger"}, Value: 0},
- {Name: "reporter.spans.failures", Tags: map[string]string{"format": "jaeger"}, Value: 1},
+ {
+ Name: "reporter.batches.submitted",
+ Tags: map[string]string{"format": "jaeger"},
+ Value: 0,
+ },
+ {
+ Name: "reporter.batches.failures",
+ Tags: map[string]string{"format": "jaeger"},
+ Value: 1,
+ },
+ {
+ Name: "reporter.spans.submitted",
+ Tags: map[string]string{"format": "jaeger"},
+ Value: 0,
+ },
+ {
+ Name: "reporter.spans.failures",
+ Tags: map[string]string{"format": "jaeger"},
+ Value: 1,
+ },
}, expectedGauges: []metricstest.ExpectedMetric{
- {Name: "reporter.batch_size", Tags: map[string]string{"format": "jaeger"}, Value: 0},
+ {
+ Name: "reporter.batch_size",
+ Tags: map[string]string{"format": "jaeger"},
+ Value: 0,
+ },
}, action: func(reporter Reporter) {
- err := reporter.EmitBatch(context.Background(), &jaeger.Batch{Spans: []*jaeger.Span{{}}})
+ err := reporter.EmitBatch(
+ context.Background(),
+ &jaeger.Batch{Spans: []*jaeger.Span{{}}},
+ )
require.Error(t, err)
}, rep: &mockReporter{err: errors.New("foo")}},
{expectedCounters: []metricstest.ExpectedMetric{
- {Name: "reporter.batches.failures", Tags: map[string]string{"format": "zipkin"}, Value: 1},
- {Name: "reporter.spans.failures", Tags: map[string]string{"format": "zipkin"}, Value: 2},
+ {
+ Name: "reporter.batches.failures",
+ Tags: map[string]string{"format": "zipkin"},
+ Value: 1,
+ },
+ {
+ Name: "reporter.spans.failures",
+ Tags: map[string]string{"format": "zipkin"},
+ Value: 2,
+ },
}, expectedGauges: []metricstest.ExpectedMetric{
- {Name: "reporter.batch_size", Tags: map[string]string{"format": "zipkin"}, Value: 0},
+ {
+ Name: "reporter.batch_size",
+ Tags: map[string]string{"format": "zipkin"},
+ Value: 0,
+ },
}, action: func(reporter Reporter) {
- err := reporter.EmitZipkinBatch(context.Background(), []*zipkincore.Span{{}, {}})
+ err := reporter.EmitZipkinBatch(
+ context.Background(),
+ []*zipkincore.Span{{}, {}},
+ )
require.Error(t, err)
}, rep: &mockReporter{errors.New("foo")}},
}
diff --git a/cmd/agent/app/reporter/reporter.go b/cmd/agent/app/reporter/reporter.go
index 550a4a2dd9b..0e3993adec3 100644
--- a/cmd/agent/app/reporter/reporter.go
+++ b/cmd/agent/app/reporter/reporter.go
@@ -42,7 +42,10 @@ func NewMultiReporter(reps ...Reporter) MultiReporter {
}
// EmitZipkinBatch calls each EmitZipkinBatch, returning the first error.
-func (mr MultiReporter) EmitZipkinBatch(ctx context.Context, spans []*zipkincore.Span) error {
+func (mr MultiReporter) EmitZipkinBatch(
+ ctx context.Context,
+ spans []*zipkincore.Span,
+) error {
var errs []error
for _, rep := range mr {
if err := rep.EmitZipkinBatch(ctx, spans); err != nil {
@@ -53,7 +56,10 @@ func (mr MultiReporter) EmitZipkinBatch(ctx context.Context, spans []*zipkincore
}
// EmitBatch calls each EmitBatch, returning the first error.
-func (mr MultiReporter) EmitBatch(ctx context.Context, batch *jaeger.Batch) error {
+func (mr MultiReporter) EmitBatch(
+ ctx context.Context,
+ batch *jaeger.Batch,
+) error {
var errs []error
for _, rep := range mr {
if err := rep.EmitBatch(ctx, batch); err != nil {
diff --git a/cmd/agent/app/reporter/reporter_test.go b/cmd/agent/app/reporter/reporter_test.go
index 7f566906761..ec21aa1dab0 100644
--- a/cmd/agent/app/reporter/reporter_test.go
+++ b/cmd/agent/app/reporter/reporter_test.go
@@ -69,7 +69,10 @@ type mockReporter struct {
err error
}
-func (r mockReporter) EmitZipkinBatch(_ context.Context, _ []*zipkincore.Span) error {
+func (r mockReporter) EmitZipkinBatch(
+ _ context.Context,
+ _ []*zipkincore.Span,
+) error {
return r.err
}
diff --git a/cmd/agent/app/servers/server.go b/cmd/agent/app/servers/server.go
index 42d6f85fcf2..b2adc8053ee 100644
--- a/cmd/agent/app/servers/server.go
+++ b/cmd/agent/app/servers/server.go
@@ -25,7 +25,9 @@ type Server interface {
IsServing() bool
Stop()
DataChan() chan *ReadBuf
- DataRecd(*ReadBuf) // must be called by consumer after reading data from the ReadBuf
+ DataRecd(
+ *ReadBuf,
+ ) // must be called by consumer after reading data from the ReadBuf
}
// ReadBuf is a structure that holds the bytes to read into as well as the number of bytes
diff --git a/cmd/agent/app/servers/tbuffered_server_test.go b/cmd/agent/app/servers/tbuffered_server_test.go
index 862bcb9a5fb..50703e852ec 100644
--- a/cmd/agent/app/servers/tbuffered_server_test.go
+++ b/cmd/agent/app/servers/tbuffered_server_test.go
@@ -42,7 +42,12 @@ func TestTBufferedServerSendReceive(t *testing.T) {
require.NoError(t, err)
maxPacketSize := 65000
- server, err := NewTBufferedServer(transport, 100, maxPacketSize, metricsFactory)
+ server, err := NewTBufferedServer(
+ transport,
+ 100,
+ maxPacketSize,
+ metricsFactory,
+ )
require.NoError(t, err)
go server.Serve()
defer server.Stop()
@@ -56,7 +61,10 @@ func TestTBufferedServerSendReceive(t *testing.T) {
span.Name = "span1"
for i := 0; i < 1000; i++ {
- err := client.EmitZipkinBatch(context.Background(), []*zipkincore.Span{span})
+ err := client.EmitZipkinBatch(
+ context.Background(),
+ []*zipkincore.Span{span},
+ )
require.NoError(t, err)
select {
@@ -64,7 +72,9 @@ func TestTBufferedServerSendReceive(t *testing.T) {
assert.NotEmpty(t, readBuf.GetBytes())
inMemReporter := testutils.NewInMemoryReporter()
- protoFact := thrift.NewTCompactProtocolFactoryConf(&thrift.TConfiguration{})
+ protoFact := thrift.NewTCompactProtocolFactoryConf(
+ &thrift.TConfiguration{},
+ )
trans := &customtransport.TBufferedReadTransport{}
protocol := protoFact.GetProtocol(trans)
@@ -129,7 +139,12 @@ func TestTBufferedServerMetrics(t *testing.T) {
defer transport.wg.Done()
maxPacketSize := 65000
- server, err := NewTBufferedServer(transport, 1, maxPacketSize, metricsFactory)
+ server, err := NewTBufferedServer(
+ transport,
+ 1,
+ maxPacketSize,
+ metricsFactory,
+ )
require.NoError(t, err)
go server.Serve()
defer server.Stop()
@@ -159,18 +174,39 @@ func TestTBufferedServerMetrics(t *testing.T) {
t.Fatal("expecting a packet in the channel")
}
- metricsFactory.AssertCounterMetrics(t,
- metricstest.ExpectedMetric{Name: "thrift.udp.server.packets.processed", Value: 1},
- metricstest.ExpectedMetric{Name: "thrift.udp.server.packets.dropped", Value: 1},
- metricstest.ExpectedMetric{Name: "thrift.udp.server.read.errors", Value: 1},
+ metricsFactory.AssertCounterMetrics(
+ t,
+ metricstest.ExpectedMetric{
+ Name: "thrift.udp.server.packets.processed",
+ Value: 1,
+ },
+ metricstest.ExpectedMetric{
+ Name: "thrift.udp.server.packets.dropped",
+ Value: 1,
+ },
+ metricstest.ExpectedMetric{
+ Name: "thrift.udp.server.read.errors",
+ Value: 1,
+ },
)
- metricsFactory.AssertGaugeMetrics(t,
- metricstest.ExpectedMetric{Name: "thrift.udp.server.packet_size", Value: 65000},
- metricstest.ExpectedMetric{Name: "thrift.udp.server.queue_size", Value: 1},
+ metricsFactory.AssertGaugeMetrics(
+ t,
+ metricstest.ExpectedMetric{
+ Name: "thrift.udp.server.packet_size",
+ Value: 65000,
+ },
+ metricstest.ExpectedMetric{
+ Name: "thrift.udp.server.queue_size",
+ Value: 1,
+ },
)
server.DataRecd(readBuf)
- metricsFactory.AssertGaugeMetrics(t,
- metricstest.ExpectedMetric{Name: "thrift.udp.server.queue_size", Value: 0},
+ metricsFactory.AssertGaugeMetrics(
+ t,
+ metricstest.ExpectedMetric{
+ Name: "thrift.udp.server.queue_size",
+ Value: 0,
+ },
)
}
diff --git a/cmd/agent/app/servers/thriftudp/socket_buffer.go b/cmd/agent/app/servers/thriftudp/socket_buffer.go
index 5dd4763593f..008de1761c3 100644
--- a/cmd/agent/app/servers/thriftudp/socket_buffer.go
+++ b/cmd/agent/app/servers/thriftudp/socket_buffer.go
@@ -31,7 +31,12 @@ func setSocketBuffer(conn *net.UDPConn, bufferSize int) error {
var syscallErr error
controlErr := rawConn.Control(func(fd uintptr) {
- syscallErr = syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_RCVBUF, bufferSize)
+ syscallErr = syscall.SetsockoptInt(
+ int(fd),
+ syscall.SOL_SOCKET,
+ syscall.SO_RCVBUF,
+ bufferSize,
+ )
})
if controlErr != nil {
return fmt.Errorf("rawconn control failed: %w", controlErr)
diff --git a/cmd/agent/app/servers/thriftudp/transport.go b/cmd/agent/app/servers/thriftudp/transport.go
index e124b16a102..14e5e2a8034 100644
--- a/cmd/agent/app/servers/thriftudp/transport.go
+++ b/cmd/agent/app/servers/thriftudp/transport.go
@@ -48,7 +48,10 @@ var _ thrift.TTransport = (*TUDPTransport)(nil)
// Example:
//
// trans, err := thriftudp.NewTUDPClientTransport("192.168.1.1:9090", "")
-func NewTUDPClientTransport(destHostPort string, locHostPort string) (*TUDPTransport, error) {
+func NewTUDPClientTransport(
+ destHostPort string,
+ locHostPort string,
+) (*TUDPTransport, error) {
destAddr, err := net.ResolveUDPAddr("udp", destHostPort)
if err != nil {
return nil, thrift.NewTTransportException(thrift.NOT_OPEN, err.Error())
@@ -58,7 +61,10 @@ func NewTUDPClientTransport(destHostPort string, locHostPort string) (*TUDPTrans
if locHostPort != "" {
locAddr, err = net.ResolveUDPAddr("udp", locHostPort)
if err != nil {
- return nil, thrift.NewTTransportException(thrift.NOT_OPEN, err.Error())
+ return nil, thrift.NewTTransportException(
+ thrift.NOT_OPEN,
+ err.Error(),
+ )
}
}
@@ -123,7 +129,10 @@ func (p *TUDPTransport) Addr() net.Addr {
// Read reads one UDP packet and puts it in the specified buf
func (p *TUDPTransport) Read(buf []byte) (int, error) {
if !p.IsOpen() {
- return 0, thrift.NewTTransportException(thrift.NOT_OPEN, "Connection not open")
+ return 0, thrift.NewTTransportException(
+ thrift.NOT_OPEN,
+ "Connection not open",
+ )
}
n, err := p.conn.Read(buf)
return n, thrift.NewTTransportExceptionFromError(err)
@@ -139,10 +148,16 @@ func (*TUDPTransport) RemainingBytes() uint64 {
// Write writes specified buf to the write buffer
func (p *TUDPTransport) Write(buf []byte) (int, error) {
if !p.IsOpen() {
- return 0, thrift.NewTTransportException(thrift.NOT_OPEN, "Connection not open")
+ return 0, thrift.NewTTransportException(
+ thrift.NOT_OPEN,
+ "Connection not open",
+ )
}
if len(p.writeBuf.Bytes())+len(buf) > MaxLength {
- return 0, thrift.NewTTransportException(thrift.INVALID_DATA, "Data does not fit within one UDP packet")
+ return 0, thrift.NewTTransportException(
+ thrift.INVALID_DATA,
+ "Data does not fit within one UDP packet",
+ )
}
n, err := p.writeBuf.Write(buf)
return n, thrift.NewTTransportExceptionFromError(err)
@@ -151,7 +166,10 @@ func (p *TUDPTransport) Write(buf []byte) (int, error) {
// Flush flushes the write buffer as one udp packet
func (p *TUDPTransport) Flush(_ context.Context) error {
if !p.IsOpen() {
- return thrift.NewTTransportException(thrift.NOT_OPEN, "Connection not open")
+ return thrift.NewTTransportException(
+ thrift.NOT_OPEN,
+ "Connection not open",
+ )
}
_, err := p.conn.Write(p.writeBuf.Bytes())
diff --git a/cmd/agent/app/servers/thriftudp/transport_test.go b/cmd/agent/app/servers/thriftudp/transport_test.go
index ccacdcd42fe..a2e64caaf9d 100644
--- a/cmd/agent/app/servers/thriftudp/transport_test.go
+++ b/cmd/agent/app/servers/thriftudp/transport_test.go
@@ -45,7 +45,11 @@ func TestNewTUDPClientTransport(t *testing.T) {
require.NotNil(t, trans.Addr())
// Check address
- assert.True(t, strings.HasPrefix(trans.Addr().String(), "127.0.0.1:"), "address check")
+ assert.True(
+ t,
+ strings.HasPrefix(trans.Addr().String(), "127.0.0.1:"),
+ "address check",
+ )
require.Equal(t, "udp", trans.Addr().Network())
err = trans.Open()
@@ -160,9 +164,18 @@ func TestDoubleCloseError(t *testing.T) {
conn.Close()
err = trans.Close()
- require.Error(t, err, "must return error when underlying connection is closed")
-
- assert.Equal(t, errConnAlreadyClosed, trans.Close(), "second Close() returns an error")
+ require.Error(
+ t,
+ err,
+ "must return error when underlying connection is closed",
+ )
+
+ assert.Equal(
+ t,
+ errConnAlreadyClosed,
+ trans.Close(),
+ "second Close() returns an error",
+ )
}
func TestConnClosedReadWrite(t *testing.T) {
diff --git a/cmd/agent/app/testutils/in_memory_reporter.go b/cmd/agent/app/testutils/in_memory_reporter.go
index df86a59091f..4162828d09b 100644
--- a/cmd/agent/app/testutils/in_memory_reporter.go
+++ b/cmd/agent/app/testutils/in_memory_reporter.go
@@ -39,7 +39,10 @@ func NewInMemoryReporter() *InMemoryReporter {
}
// EmitZipkinBatch implements the corresponding method of the Reporter interface
-func (i *InMemoryReporter) EmitZipkinBatch(_ context.Context, spans []*zipkincore.Span) error {
+func (i *InMemoryReporter) EmitZipkinBatch(
+ _ context.Context,
+ spans []*zipkincore.Span,
+) error {
i.mutex.Lock()
defer i.mutex.Unlock()
i.zSpans = append(i.zSpans, spans...)
@@ -47,7 +50,10 @@ func (i *InMemoryReporter) EmitZipkinBatch(_ context.Context, spans []*zipkincor
}
// EmitBatch implements the corresponding method of the Reporter interface
-func (i *InMemoryReporter) EmitBatch(_ context.Context, batch *jaeger.Batch) (err error) {
+func (i *InMemoryReporter) EmitBatch(
+ _ context.Context,
+ batch *jaeger.Batch,
+) (err error) {
i.mutex.Lock()
defer i.mutex.Unlock()
i.jSpans = append(i.jSpans, batch.Spans...)
diff --git a/cmd/agent/app/testutils/mock_grpc_collector.go b/cmd/agent/app/testutils/mock_grpc_collector.go
index 6c0bec83f2d..7c0ac978146 100644
--- a/cmd/agent/app/testutils/mock_grpc_collector.go
+++ b/cmd/agent/app/testutils/mock_grpc_collector.go
@@ -81,7 +81,10 @@ func (h *mockSpanHandler) GetJaegerBatches() []model.Batch {
return batches
}
-func (h *mockSpanHandler) PostSpans(_ context.Context, r *api_v2.PostSpansRequest) (*api_v2.PostSpansResponse, error) {
+func (h *mockSpanHandler) PostSpans(
+ _ context.Context,
+ r *api_v2.PostSpansRequest,
+) (*api_v2.PostSpansResponse, error) {
h.t.Logf("mockSpanHandler received %d spans", len(r.Batch.Spans))
h.mux.Lock()
defer h.mux.Unlock()
diff --git a/cmd/agent/app/testutils/thriftudp_client.go b/cmd/agent/app/testutils/thriftudp_client.go
index e04312b2cc9..d2752b112e5 100644
--- a/cmd/agent/app/testutils/thriftudp_client.go
+++ b/cmd/agent/app/testutils/thriftudp_client.go
@@ -25,19 +25,26 @@ import (
)
// NewZipkinThriftUDPClient creates a new zipking agent client that works like Jaeger client
-func NewZipkinThriftUDPClient(hostPort string) (*agent.AgentClient, io.Closer, error) {
+func NewZipkinThriftUDPClient(
+ hostPort string,
+) (*agent.AgentClient, io.Closer, error) {
clientTransport, err := thriftudp.NewTUDPClientTransport(hostPort, "")
if err != nil {
return nil, nil, err
}
- protocolFactory := thrift.NewTCompactProtocolFactoryConf(&thrift.TConfiguration{})
+ protocolFactory := thrift.NewTCompactProtocolFactoryConf(
+ &thrift.TConfiguration{},
+ )
client := agent.NewAgentClientFactory(clientTransport, protocolFactory)
return client, clientTransport, nil
}
// NewJaegerThriftUDPClient creates a new jaeger agent client that works like Jaeger client
-func NewJaegerThriftUDPClient(hostPort string, protocolFactory thrift.TProtocolFactory) (*agent.AgentClient, io.Closer, error) {
+func NewJaegerThriftUDPClient(
+ hostPort string,
+ protocolFactory thrift.TProtocolFactory,
+) (*agent.AgentClient, io.Closer, error) {
clientTransport, err := thriftudp.NewTUDPClientTransport(hostPort, "")
if err != nil {
return nil, nil, err
diff --git a/cmd/agent/app/testutils/thriftudp_client_test.go b/cmd/agent/app/testutils/thriftudp_client_test.go
index 857223369f5..88eb2d4c75c 100644
--- a/cmd/agent/app/testutils/thriftudp_client_test.go
+++ b/cmd/agent/app/testutils/thriftudp_client_test.go
@@ -32,7 +32,9 @@ func TestNewZipkinThriftUDPClient(t *testing.T) {
}
func TestNewJaegerThriftUDPClient(t *testing.T) {
- compactFactory := thrift.NewTCompactProtocolFactoryConf(&thrift.TConfiguration{})
+ compactFactory := thrift.NewTCompactProtocolFactoryConf(
+ &thrift.TConfiguration{},
+ )
_, _, err := NewJaegerThriftUDPClient("256.2.3:0", compactFactory)
require.Error(t, err)
diff --git a/cmd/agent/main.go b/cmd/agent/main.go
index 01ebdedd3f6..ad5a0a92817 100644
--- a/cmd/agent/main.go
+++ b/cmd/agent/main.go
@@ -38,9 +38,15 @@ import (
)
func main() {
- println("***************************************************************************************************")
- println("*** WARNING jaeger-agent is deprecated. See https://github.com/jaegertracing/jaeger/issues/4739 ***")
- println("***************************************************************************************************")
+ println(
+ "***************************************************************************************************",
+ )
+ println(
+ "*** WARNING jaeger-agent is deprecated. See https://github.com/jaegertracing/jaeger/issues/4739 ***",
+ )
+ println(
+ "***************************************************************************************************",
+ )
svc := flags.NewService(ports.AgentAdminHTTP)
svc.NoStorage = true
@@ -64,7 +70,10 @@ func main() {
rOpts := new(reporter.Options).InitFromViper(v, logger)
grpcBuilder, err := grpc.NewConnBuilder().InitFromViper(v)
if err != nil {
- logger.Fatal("Failed to configure gRPC connection", zap.Error(err))
+ logger.Fatal(
+ "Failed to configure gRPC connection",
+ zap.Error(err),
+ )
}
builders := map[reporter.Type]app.CollectorProxyBuilder{
reporter.GRPC: app.GRPCCollectorProxyBuilder(grpcBuilder),
diff --git a/cmd/all-in-one/all_in_one_test.go b/cmd/all-in-one/all_in_one_test.go
index f5186001976..00b79c6169b 100644
--- a/cmd/all-in-one/all_in_one_test.go
+++ b/cmd/all-in-one/all_in_one_test.go
@@ -58,7 +58,9 @@ var httpClient = &http.Client{
func TestAllInOne(t *testing.T) {
if os.Getenv("TEST_MODE") != "integration" {
- t.Skip("Integration test for all-in-one skipped; set environment variable TEST_MODE=integration to enable")
+ t.Skip(
+ "Integration test for all-in-one skipped; set environment variable TEST_MODE=integration to enable",
+ )
}
// Check if the query service is available
@@ -95,7 +97,9 @@ func checkWebUI(t *testing.T) {
require.NoError(t, err)
body := string(bodyBytes)
t.Run("Static_files", func(t *testing.T) {
- pattern := regexp.MustCompile(` 1 {
return "", status.Errorf(codes.PermissionDenied, "extra tenant header")
}
diff --git a/cmd/collector/app/handler/grpc_handler_test.go b/cmd/collector/app/handler/grpc_handler_test.go
index 289f7ae3aa9..3b59c06257b 100644
--- a/cmd/collector/app/handler/grpc_handler_test.go
+++ b/cmd/collector/app/handler/grpc_handler_test.go
@@ -44,7 +44,10 @@ type mockSpanProcessor struct {
spanFormat processor.SpanFormat
}
-func (p *mockSpanProcessor) ProcessSpans(spans []*model.Span, opts processor.SpansOptions) ([]bool, error) {
+func (p *mockSpanProcessor) ProcessSpans(
+ spans []*model.Span,
+ opts processor.SpansOptions,
+) ([]bool, error) {
p.mux.Lock()
defer p.mux.Unlock()
p.spans = append(p.spans, spans...)
@@ -95,7 +98,10 @@ func (*mockSpanProcessor) Close() error {
return nil
}
-func initializeGRPCTestServer(t *testing.T, beforeServe func(s *grpc.Server)) (*grpc.Server, net.Addr) {
+func initializeGRPCTestServer(
+ t *testing.T,
+ beforeServe func(s *grpc.Server),
+) (*grpc.Server, net.Addr) {
server := grpc.NewServer()
beforeServe(server)
lis, err := net.Listen("tcp", "localhost:0")
@@ -107,8 +113,14 @@ func initializeGRPCTestServer(t *testing.T, beforeServe func(s *grpc.Server)) (*
return server, lis.Addr()
}
-func newClient(t *testing.T, addr net.Addr) (api_v2.CollectorServiceClient, *grpc.ClientConn) {
- conn, err := grpc.NewClient(addr.String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
+func newClient(
+ t *testing.T,
+ addr net.Addr,
+) (api_v2.CollectorServiceClient, *grpc.ClientConn) {
+ conn, err := grpc.NewClient(
+ addr.String(),
+ grpc.WithTransportCredentials(insecure.NewCredentials()),
+ )
require.NoError(t, err)
return api_v2.NewCollectorServiceClient(conn), conn
}
@@ -128,18 +140,27 @@ func TestPostSpans(t *testing.T) {
expected []*model.Span
}{
{
- batch: model.Batch{Process: &model.Process{ServiceName: "batch-process"}, Spans: []*model.Span{{OperationName: "test-op", Process: &model.Process{ServiceName: "bar"}}}},
+ batch: model.Batch{
+ Process: &model.Process{ServiceName: "batch-process"},
+ Spans: []*model.Span{{OperationName: "test-op", Process: &model.Process{ServiceName: "bar"}}},
+ },
expected: []*model.Span{{OperationName: "test-op", Process: &model.Process{ServiceName: "bar"}}},
},
{
- batch: model.Batch{Process: &model.Process{ServiceName: "batch-process"}, Spans: []*model.Span{{OperationName: "test-op"}}},
+ batch: model.Batch{
+ Process: &model.Process{ServiceName: "batch-process"},
+ Spans: []*model.Span{{OperationName: "test-op"}},
+ },
expected: []*model.Span{{OperationName: "test-op", Process: &model.Process{ServiceName: "batch-process"}}},
},
}
for _, test := range tests {
- _, err := client.PostSpans(context.Background(), &api_v2.PostSpansRequest{
- Batch: test.batch,
- })
+ _, err := client.PostSpans(
+ context.Background(),
+ &api_v2.PostSpansRequest{
+ Batch: test.batch,
+ },
+ )
require.NoError(t, err)
got := processor.getSpans()
require.Equal(t, len(test.batch.GetSpans()), len(got))
@@ -195,15 +216,18 @@ func TestPostSpansWithError(t *testing.T) {
defer server.Stop()
client, conn := newClient(t, addr)
defer conn.Close()
- r, err := client.PostSpans(context.Background(), &api_v2.PostSpansRequest{
- Batch: model.Batch{
- Spans: []*model.Span{
- {
- OperationName: "fake-operation",
+ r, err := client.PostSpans(
+ context.Background(),
+ &api_v2.PostSpansRequest{
+ Batch: model.Batch{
+ Spans: []*model.Span{
+ {
+ OperationName: "fake-operation",
+ },
},
},
},
- })
+ )
require.Error(t, err)
require.Nil(t, r)
assert.Contains(t, err.Error(), test.expectedError)
@@ -214,7 +238,11 @@ func TestPostSpansWithError(t *testing.T) {
}
// withMetadata returns a Context with metadata for outbound (client) calls
-func withMetadata(ctx context.Context, headerName, headerValue string, t *testing.T) context.Context {
+func withMetadata(
+ ctx context.Context,
+ headerName, headerValue string,
+ t *testing.T,
+) context.Context {
t.Helper()
md := metadata.New(map[string]string{headerName: headerValue})
@@ -239,12 +267,25 @@ func TestPostTenantedSpans(t *testing.T) {
client, conn := newClient(t, addr)
defer conn.Close()
- ctxWithTenant := withMetadata(context.Background(), tenantHeader, dummyTenant, t)
+ ctxWithTenant := withMetadata(
+ context.Background(),
+ tenantHeader,
+ dummyTenant,
+ t,
+ )
ctxNoTenant := context.Background()
mdTwoTenants := metadata.Pairs()
mdTwoTenants.Set(tenantHeader, "a", "b")
- ctxTwoTenants := metadata.NewOutgoingContext(context.Background(), mdTwoTenants)
- ctxBadTenant := withMetadata(context.Background(), tenantHeader, "invalid-tenant", t)
+ ctxTwoTenants := metadata.NewOutgoingContext(
+ context.Background(),
+ mdTwoTenants,
+ )
+ ctxBadTenant := withMetadata(
+ context.Background(),
+ tenantHeader,
+ "invalid-tenant",
+ t,
+ )
withMetadata(context.Background(),
tenantHeader, dummyTenant, t)
@@ -258,18 +299,29 @@ func TestPostTenantedSpans(t *testing.T) {
expectedTenants map[string]bool
}{
{
- name: "valid tenant",
- ctx: ctxWithTenant,
- batch: model.Batch{Process: &model.Process{ServiceName: "batch-process"}, Spans: []*model.Span{{OperationName: "test-op", Process: &model.Process{ServiceName: "bar"}}}},
+ name: "valid tenant",
+ ctx: ctxWithTenant,
+ batch: model.Batch{
+ Process: &model.Process{ServiceName: "batch-process"},
+ Spans: []*model.Span{{OperationName: "test-op", Process: &model.Process{ServiceName: "bar"}}},
+ },
- mustFail: false,
- expected: []*model.Span{{OperationName: "test-op", Process: &model.Process{ServiceName: "bar"}}},
+ mustFail: false,
+ expected: []*model.Span{
+ {
+ OperationName: "test-op",
+ Process: &model.Process{ServiceName: "bar"},
+ },
+ },
expectedTenants: map[string]bool{dummyTenant: true},
},
{
- name: "no tenant",
- ctx: ctxNoTenant,
- batch: model.Batch{Process: &model.Process{ServiceName: "batch-process"}, Spans: []*model.Span{{OperationName: "test-op", Process: &model.Process{ServiceName: "bar"}}}},
+ name: "no tenant",
+ ctx: ctxNoTenant,
+ batch: model.Batch{
+ Process: &model.Process{ServiceName: "batch-process"},
+ Spans: []*model.Span{{OperationName: "test-op", Process: &model.Process{ServiceName: "bar"}}},
+ },
// Because NewGRPCHandler expects a tenant header, it will reject spans without one
mustFail: true,
@@ -277,9 +329,12 @@ func TestPostTenantedSpans(t *testing.T) {
expectedTenants: nil,
},
{
- name: "two tenants",
- ctx: ctxTwoTenants,
- batch: model.Batch{Process: &model.Process{ServiceName: "batch-process"}, Spans: []*model.Span{{OperationName: "test-op", Process: &model.Process{ServiceName: "bar"}}}},
+ name: "two tenants",
+ ctx: ctxTwoTenants,
+ batch: model.Batch{
+ Process: &model.Process{ServiceName: "batch-process"},
+ Spans: []*model.Span{{OperationName: "test-op", Process: &model.Process{ServiceName: "bar"}}},
+ },
// NewGRPCHandler rejects spans with multiple values for tenant header
mustFail: true,
@@ -287,9 +342,12 @@ func TestPostTenantedSpans(t *testing.T) {
expectedTenants: nil,
},
{
- name: "invalid tenant",
- ctx: ctxBadTenant,
- batch: model.Batch{Process: &model.Process{ServiceName: "batch-process"}, Spans: []*model.Span{{OperationName: "test-op", Process: &model.Process{ServiceName: "bar"}}}},
+ name: "invalid tenant",
+ ctx: ctxBadTenant,
+ batch: model.Batch{
+ Process: &model.Process{ServiceName: "batch-process"},
+ Spans: []*model.Span{{OperationName: "test-op", Process: &model.Process{ServiceName: "bar"}}},
+ },
// NewGRPCHandler rejects spans with multiple values for tenant header
mustFail: true,
@@ -315,7 +373,11 @@ func TestPostTenantedSpans(t *testing.T) {
}
// withIncomingMetadata returns a Context with metadata for a server to receive
-func withIncomingMetadata(ctx context.Context, headerName, headerValue string, t *testing.T) context.Context {
+func withIncomingMetadata(
+ ctx context.Context,
+ headerName, headerValue string,
+ t *testing.T,
+) context.Context {
t.Helper()
md := metadata.New(map[string]string{headerName: headerValue})
@@ -328,7 +390,10 @@ func TestGetTenant(t *testing.T) {
mdTwoTenants := metadata.Pairs()
mdTwoTenants.Set(tenantHeader, "a", "b")
- ctxTwoTenants := metadata.NewOutgoingContext(context.Background(), mdTwoTenants)
+ ctxTwoTenants := metadata.NewOutgoingContext(
+ context.Background(),
+ mdTwoTenants,
+ )
tests := []struct {
name string
@@ -337,8 +402,13 @@ func TestGetTenant(t *testing.T) {
mustFail bool
}{
{
- name: "valid tenant",
- ctx: withIncomingMetadata(context.TODO(), tenantHeader, "acme", t),
+ name: "valid tenant",
+ ctx: withIncomingMetadata(
+ context.TODO(),
+ tenantHeader,
+ "acme",
+ t,
+ ),
mustFail: false,
tenant: "acme",
},
@@ -355,8 +425,13 @@ func TestGetTenant(t *testing.T) {
tenant: "",
},
{
- name: "invalid tenant",
- ctx: withIncomingMetadata(context.TODO(), tenantHeader, "an-invalid-tenant", t),
+ name: "invalid tenant",
+ ctx: withIncomingMetadata(
+ context.TODO(),
+ tenantHeader,
+ "an-invalid-tenant",
+ t,
+ ),
mustFail: true,
tenant: "",
},
@@ -396,7 +471,10 @@ func TestBatchConsumer(t *testing.T) {
batch: model.Batch{
Process: &model.Process{ServiceName: "testservice"},
Spans: []*model.Span{
- {OperationName: "test-op", Process: &model.Process{ServiceName: "foo"}},
+ {
+ OperationName: "test-op",
+ Process: &model.Process{ServiceName: "foo"},
+ },
},
},
transport: processor.GRPCTransport,
@@ -412,11 +490,20 @@ func TestBatchConsumer(t *testing.T) {
t.Parallel()
t.Run(tc.name, func(t *testing.T) {
processor := mockSpanProcessor{}
- batchConsumer := newBatchConsumer(logger, &processor, tc.transport, tc.spanFormat, tenancy.NewManager(&tenancy.Options{}))
+ batchConsumer := newBatchConsumer(
+ logger,
+ &processor,
+ tc.transport,
+ tc.spanFormat,
+ tenancy.NewManager(&tenancy.Options{}),
+ )
err := batchConsumer.consume(context.Background(), &model.Batch{
Process: &model.Process{ServiceName: "testservice"},
Spans: []*model.Span{
- {OperationName: "test-op", Process: &model.Process{ServiceName: "foo"}},
+ {
+ OperationName: "test-op",
+ Process: &model.Process{ServiceName: "foo"},
+ },
},
})
require.NoError(t, err)
diff --git a/cmd/collector/app/handler/http_thrift_handler.go b/cmd/collector/app/handler/http_thrift_handler.go
index 0434bc09ccc..b4120a28c15 100644
--- a/cmd/collector/app/handler/http_thrift_handler.go
+++ b/cmd/collector/app/handler/http_thrift_handler.go
@@ -63,31 +63,51 @@ func (aH *APIHandler) SaveSpan(w http.ResponseWriter, r *http.Request) {
bodyBytes, err := io.ReadAll(r.Body)
r.Body.Close()
if err != nil {
- http.Error(w, fmt.Sprintf(UnableToReadBodyErrFormat, err), http.StatusInternalServerError)
+ http.Error(
+ w,
+ fmt.Sprintf(UnableToReadBodyErrFormat, err),
+ http.StatusInternalServerError,
+ )
return
}
contentType, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
if err != nil {
- http.Error(w, fmt.Sprintf("Cannot parse content type: %v", err), http.StatusBadRequest)
+ http.Error(
+ w,
+ fmt.Sprintf("Cannot parse content type: %v", err),
+ http.StatusBadRequest,
+ )
return
}
if _, ok := acceptedThriftFormats[contentType]; !ok {
- http.Error(w, fmt.Sprintf("Unsupported content type: %v", html.EscapeString(contentType)), http.StatusBadRequest)
+ http.Error(
+ w,
+ fmt.Sprintf("Unsupported content type: %v", html.EscapeString(contentType)),
+ http.StatusBadRequest,
+ )
return
}
tdes := thrift.NewTDeserializer()
batch := &tJaeger.Batch{}
if err = tdes.Read(r.Context(), batch, bodyBytes); err != nil {
- http.Error(w, fmt.Sprintf(UnableToReadBodyErrFormat, err), http.StatusBadRequest)
+ http.Error(
+ w,
+ fmt.Sprintf(UnableToReadBodyErrFormat, err),
+ http.StatusBadRequest,
+ )
return
}
batches := []*tJaeger.Batch{batch}
opts := SubmitBatchOptions{InboundTransport: processor.HTTPTransport}
if _, err = aH.jaegerBatchesHandler.SubmitBatches(batches, opts); err != nil {
- http.Error(w, fmt.Sprintf("Cannot submit Jaeger batch: %v", err), http.StatusInternalServerError)
+ http.Error(
+ w,
+ fmt.Sprintf("Cannot submit Jaeger batch: %v", err),
+ http.StatusInternalServerError,
+ )
return
}
diff --git a/cmd/collector/app/handler/http_thrift_handler_test.go b/cmd/collector/app/handler/http_thrift_handler_test.go
index cc50ae64b92..a9ca2292b84 100644
--- a/cmd/collector/app/handler/http_thrift_handler_test.go
+++ b/cmd/collector/app/handler/http_thrift_handler_test.go
@@ -44,7 +44,10 @@ type mockJaegerHandler struct {
batches []*jaeger.Batch
}
-func (p *mockJaegerHandler) SubmitBatches(batches []*jaeger.Batch, _ SubmitBatchOptions) ([]*jaeger.BatchSubmitResponse, error) {
+func (p *mockJaegerHandler) SubmitBatches(
+ batches []*jaeger.Batch,
+ _ SubmitBatchOptions,
+) ([]*jaeger.BatchSubmitResponse, error) {
p.mux.Lock()
defer p.mux.Unlock()
p.batches = append(p.batches, batches...)
@@ -80,21 +83,39 @@ func TestThriftFormat(t *testing.T) {
server, handler := initializeTestServer(nil)
defer server.Close()
- statusCode, resBodyStr, err := postBytes("application/x-thrift", server.URL+`/api/traces`, someBytes)
+ statusCode, resBodyStr, err := postBytes(
+ "application/x-thrift",
+ server.URL+`/api/traces`,
+ someBytes,
+ )
require.NoError(t, err)
assert.EqualValues(t, http.StatusAccepted, statusCode)
assert.EqualValues(t, "", resBodyStr)
- statusCode, resBodyStr, err = postBytes("application/x-thrift; charset=utf-8", server.URL+`/api/traces`, someBytes)
+ statusCode, resBodyStr, err = postBytes(
+ "application/x-thrift; charset=utf-8",
+ server.URL+`/api/traces`,
+ someBytes,
+ )
require.NoError(t, err)
assert.EqualValues(t, http.StatusAccepted, statusCode)
assert.EqualValues(t, "", resBodyStr)
- handler.jaegerBatchesHandler.(*mockJaegerHandler).err = fmt.Errorf("Bad times ahead")
- statusCode, resBodyStr, err = postBytes("application/vnd.apache.thrift.binary", server.URL+`/api/traces`, someBytes)
+ handler.jaegerBatchesHandler.(*mockJaegerHandler).err = fmt.Errorf(
+ "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)
- assert.EqualValues(t, "Cannot submit Jaeger batch: Bad times ahead\n", resBodyStr)
+ assert.EqualValues(
+ t,
+ "Cannot submit Jaeger batch: Bad times ahead\n",
+ resBodyStr,
+ )
}
func TestViaClient(t *testing.T) {
@@ -128,35 +149,63 @@ func TestViaClient(t *testing.T) {
break
}
- assert.Len(t, handler.jaegerBatchesHandler.(*mockJaegerHandler).getBatches(), 1)
+ assert.Len(
+ t,
+ handler.jaegerBatchesHandler.(*mockJaegerHandler).getBatches(),
+ 1,
+ )
}
func TestBadBody(t *testing.T) {
server, _ := initializeTestServer(nil)
defer server.Close()
bodyBytes := []byte("not good")
- statusCode, resBodyStr, err := postBytes("application/x-thrift", server.URL+`/api/traces`, bodyBytes)
+ statusCode, resBodyStr, err := postBytes(
+ "application/x-thrift",
+ server.URL+`/api/traces`,
+ bodyBytes,
+ )
require.NoError(t, err)
assert.EqualValues(t, http.StatusBadRequest, statusCode)
- assert.EqualValues(t, "Unable to process request body: Unknown data type 110\n", resBodyStr)
+ assert.EqualValues(
+ t,
+ "Unable to process request body: Unknown data type 110\n",
+ resBodyStr,
+ )
}
func TestWrongFormat(t *testing.T) {
server, _ := initializeTestServer(nil)
defer server.Close()
- statusCode, resBodyStr, err := postBytes("nosoupforyou", server.URL+`/api/traces`, []byte{})
+ statusCode, resBodyStr, err := postBytes(
+ "nosoupforyou",
+ server.URL+`/api/traces`,
+ []byte{},
+ )
require.NoError(t, err)
assert.EqualValues(t, http.StatusBadRequest, statusCode)
- assert.EqualValues(t, "Unsupported content type: nosoupforyou\n", resBodyStr)
+ assert.EqualValues(
+ t,
+ "Unsupported content type: nosoupforyou\n",
+ resBodyStr,
+ )
}
func TestMalformedFormat(t *testing.T) {
server, _ := initializeTestServer(nil)
defer server.Close()
- statusCode, resBodyStr, err := postBytes("application/json; =iammalformed", server.URL+`/api/traces`, []byte{})
+ statusCode, resBodyStr, err := postBytes(
+ "application/json; =iammalformed",
+ server.URL+`/api/traces`,
+ []byte{},
+ )
require.NoError(t, err)
assert.EqualValues(t, http.StatusBadRequest, statusCode)
- assert.EqualValues(t, "Cannot parse content type: mime: invalid media parameter\n", resBodyStr)
+ assert.EqualValues(
+ t,
+ "Cannot parse content type: mime: invalid media parameter\n",
+ resBodyStr,
+ )
}
func TestCannotReadBodyFromRequest(t *testing.T) {
@@ -166,7 +215,11 @@ func TestCannotReadBodyFromRequest(t *testing.T) {
rw := dummyResponseWriter{}
handler.SaveSpan(&rw, req)
assert.EqualValues(t, http.StatusInternalServerError, rw.myStatusCode)
- assert.EqualValues(t, "Unable to process request body: Simulated error reading body\n", rw.myBody)
+ assert.EqualValues(
+ t,
+ "Unable to process request body: Simulated error reading body\n",
+ rw.myBody,
+ )
}
type errReader struct{}
@@ -193,8 +246,15 @@ func (d *dummyResponseWriter) WriteHeader(statusCode int) {
d.myStatusCode = statusCode
}
-func postBytes(contentType, urlStr string, bodyBytes []byte) (int, string, error) {
- req, err := http.NewRequest(http.MethodPost, urlStr, bytes.NewBuffer([]byte(bodyBytes)))
+func postBytes(
+ contentType, urlStr string,
+ bodyBytes []byte,
+) (int, string, error) {
+ req, err := http.NewRequest(
+ http.MethodPost,
+ urlStr,
+ bytes.NewBuffer([]byte(bodyBytes)),
+ )
if err != nil {
return 0, "", err
}
diff --git a/cmd/collector/app/handler/otlp_receiver.go b/cmd/collector/app/handler/otlp_receiver.go
index 84177b69592..aa5cad79ff8 100644
--- a/cmd/collector/app/handler/otlp_receiver.go
+++ b/cmd/collector/app/handler/otlp_receiver.go
@@ -42,7 +42,12 @@ import (
var _ component.Host = (*otelHost)(nil) // API check
// StartOTLPReceiver starts OpenTelemetry OTLP receiver listening on gRPC and HTTP ports.
-func StartOTLPReceiver(options *flags.CollectorOptions, logger *zap.Logger, spanProcessor processor.SpanProcessor, tm *tenancy.Manager) (receiver.Traces, error) {
+func StartOTLPReceiver(
+ options *flags.CollectorOptions,
+ logger *zap.Logger,
+ spanProcessor processor.SpanProcessor,
+ tm *tenancy.Manager,
+) (receiver.Traces, error) {
otlpFactory := otlpreceiver.NewFactory()
return startOTLPReceiver(
options,
@@ -74,7 +79,10 @@ func startOTLPReceiver(
applyHTTPSettings(otlpReceiverConfig.HTTP.ServerConfig, &options.OTLP.HTTP)
statusReporter := func(ev *component.StatusEvent) {
// TODO this could be wired into changing healthcheck.HealthCheck
- logger.Info("OTLP receiver status change", zap.Stringer("status", ev.Status()))
+ logger.Info(
+ "OTLP receiver status change",
+ zap.Stringer("status", ev.Status()),
+ )
}
otlpReceiverSettings := receiver.CreateSettings{
TelemetrySettings: component.TelemetrySettings{
@@ -114,7 +122,9 @@ func applyGRPCSettings(cfg *configgrpc.ServerConfig, opts *flags.GRPCOptions) {
cfg.TLSSetting = applyTLSSettings(&opts.TLS)
}
if opts.MaxReceiveMessageLength > 0 {
- cfg.MaxRecvMsgSizeMiB = uint64(opts.MaxReceiveMessageLength / (1024 * 1024))
+ cfg.MaxRecvMsgSizeMiB = uint64(
+ opts.MaxReceiveMessageLength / (1024 * 1024),
+ )
}
if opts.MaxConnectionAge != 0 || opts.MaxConnectionAgeGrace != 0 {
cfg.Keepalive = &configgrpc.KeepaliveServerConfig{
@@ -154,7 +164,11 @@ func applyTLSSettings(opts *tlscfg.Options) *configtls.ServerConfig {
}
}
-func newConsumerDelegate(logger *zap.Logger, spanProcessor processor.SpanProcessor, tm *tenancy.Manager) *consumerDelegate {
+func newConsumerDelegate(
+ logger *zap.Logger,
+ spanProcessor processor.SpanProcessor,
+ tm *tenancy.Manager,
+) *consumerDelegate {
return &consumerDelegate{
batchConsumer: newBatchConsumer(logger,
spanProcessor,
@@ -170,7 +184,10 @@ type consumerDelegate struct {
protoFromTraces func(td ptrace.Traces) ([]*model.Batch, error)
}
-func (c *consumerDelegate) consume(ctx context.Context, td ptrace.Traces) error {
+func (c *consumerDelegate) consume(
+ ctx context.Context,
+ td ptrace.Traces,
+) error {
batches, err := c.protoFromTraces(td)
if err != nil {
return err
@@ -193,7 +210,10 @@ func (h *otelHost) ReportFatalError(err error) {
h.logger.Fatal("OTLP receiver error", zap.Error(err))
}
-func (*otelHost) GetFactory(_ component.Kind, _ component.Type) component.Factory {
+func (*otelHost) GetFactory(
+ _ component.Kind,
+ _ component.Type,
+) component.Factory {
return nil
}
diff --git a/cmd/collector/app/handler/otlp_receiver_test.go b/cmd/collector/app/handler/otlp_receiver_test.go
index d89defd536f..8d1deb12452 100644
--- a/cmd/collector/app/handler/otlp_receiver_test.go
+++ b/cmd/collector/app/handler/otlp_receiver_test.go
@@ -51,7 +51,12 @@ func TestStartOtlpReceiver(t *testing.T) {
spanProcessor := &mockSpanProcessor{}
logger, _ := testutils.NewLogger()
tm := &tenancy.Manager{}
- rec, err := StartOTLPReceiver(optionsWithPorts(":0"), logger, spanProcessor, tm)
+ rec, err := StartOTLPReceiver(
+ optionsWithPorts(":0"),
+ logger,
+ spanProcessor,
+ tm,
+ )
require.NoError(t, err)
defer func() {
require.NoError(t, rec.Shutdown(context.Background()))
@@ -82,7 +87,11 @@ func TestConsumerDelegate(t *testing.T) {
t.Run(test.expectLog, func(t *testing.T) {
logger, logBuf := testutils.NewLogger()
spanProcessor := &mockSpanProcessor{expectedError: test.expectErr}
- consumer := newConsumerDelegate(logger, spanProcessor, &tenancy.Manager{})
+ consumer := newConsumerDelegate(
+ logger,
+ spanProcessor,
+ &tenancy.Manager{},
+ )
err := consumer.consume(context.Background(), makeTracesOneSpan())
@@ -110,7 +119,15 @@ func TestStartOtlpReceiver_Error(t *testing.T) {
return nil, errors.New("mock error")
}
f := otlpreceiver.NewFactory()
- _, err = startOTLPReceiver(opts, logger, spanProcessor, &tenancy.Manager{}, f, newTraces, f.CreateTracesReceiver)
+ _, err = startOTLPReceiver(
+ opts,
+ logger,
+ spanProcessor,
+ &tenancy.Manager{},
+ f,
+ newTraces,
+ f.CreateTracesReceiver,
+ )
require.Error(t, err)
assert.Contains(t, err.Error(), "could not create the OTLP consumer")
@@ -119,7 +136,15 @@ func TestStartOtlpReceiver_Error(t *testing.T) {
) (receiver.Traces, error) {
return nil, errors.New("mock error")
}
- _, err = startOTLPReceiver(opts, logger, spanProcessor, &tenancy.Manager{}, f, consumer.NewTraces, createTracesReceiver)
+ _, 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")
}
@@ -149,7 +174,10 @@ func TestOtelHost_ReportFatalError(t *testing.T) {
func TestOtelHost(t *testing.T) {
host := &otelHost{}
- assert.Nil(t, host.GetFactory(component.KindReceiver, component.DataTypeTraces))
+ assert.Nil(
+ t,
+ host.GetFactory(component.KindReceiver, component.DataTypeTraces),
+ )
assert.Nil(t, host.GetExtensions())
assert.Nil(t, host.GetExporters())
}
@@ -180,8 +208,16 @@ func TestApplyOTLPGRPCServerSettings(t *testing.T) {
assert.EqualValues(t, 42, out.MaxRecvMsgSizeMiB)
require.NotNil(t, out.Keepalive)
require.NotNil(t, out.Keepalive.ServerParameters)
- assert.Equal(t, 33*time.Second, out.Keepalive.ServerParameters.MaxConnectionAge)
- assert.Equal(t, 37*time.Second, out.Keepalive.ServerParameters.MaxConnectionAgeGrace)
+ assert.Equal(
+ t,
+ 33*time.Second,
+ out.Keepalive.ServerParameters.MaxConnectionAge,
+ )
+ assert.Equal(
+ t,
+ 37*time.Second,
+ out.Keepalive.ServerParameters.MaxConnectionAgeGrace,
+ )
require.NotNil(t, out.TLSSetting)
assert.Equal(t, "ca", out.TLSSetting.CAFile)
assert.Equal(t, "cert", out.TLSSetting.CertFile)
@@ -209,8 +245,15 @@ func TestApplyOTLPHTTPServerSettings(t *testing.T) {
ReloadInterval: 24 * time.Hour,
},
CORS: corscfg.Options{
- AllowedOrigins: []string{"http://example.domain.com", "http://*.domain.com"},
- AllowedHeaders: []string{"Content-Type", "Accept", "X-Requested-With"},
+ AllowedOrigins: []string{
+ "http://example.domain.com",
+ "http://*.domain.com",
+ },
+ AllowedHeaders: []string{
+ "Content-Type",
+ "Accept",
+ "X-Requested-With",
+ },
},
}
@@ -227,6 +270,14 @@ func TestApplyOTLPHTTPServerSettings(t *testing.T) {
assert.Equal(t, "1.1", out.TLSSetting.MinVersion)
assert.Equal(t, "1.3", out.TLSSetting.MaxVersion)
assert.Equal(t, 24*time.Hour, out.TLSSetting.ReloadInterval)
- assert.Equal(t, []string{"Content-Type", "Accept", "X-Requested-With"}, out.CORS.AllowedHeaders)
- assert.Equal(t, []string{"http://example.domain.com", "http://*.domain.com"}, out.CORS.AllowedOrigins)
+ assert.Equal(
+ t,
+ []string{"Content-Type", "Accept", "X-Requested-With"},
+ out.CORS.AllowedHeaders,
+ )
+ assert.Equal(
+ t,
+ []string{"http://example.domain.com", "http://*.domain.com"},
+ out.CORS.AllowedOrigins,
+ )
}
diff --git a/cmd/collector/app/handler/thrift_span_handler.go b/cmd/collector/app/handler/thrift_span_handler.go
index 3448a3fbc62..e633fd75ab1 100644
--- a/cmd/collector/app/handler/thrift_span_handler.go
+++ b/cmd/collector/app/handler/thrift_span_handler.go
@@ -35,13 +35,19 @@ type SubmitBatchOptions struct {
// ZipkinSpansHandler consumes and handles zipkin spans
type ZipkinSpansHandler interface {
// SubmitZipkinBatch records a batch of spans in Zipkin Thrift format
- SubmitZipkinBatch(spans []*zipkincore.Span, options SubmitBatchOptions) ([]*zipkincore.Response, error)
+ SubmitZipkinBatch(
+ spans []*zipkincore.Span,
+ options SubmitBatchOptions,
+ ) ([]*zipkincore.Response, error)
}
// JaegerBatchesHandler consumes and handles Jaeger batches
type JaegerBatchesHandler interface {
// SubmitBatches records a batch of spans in Jaeger Thrift format
- SubmitBatches(batches []*jaeger.Batch, options SubmitBatchOptions) ([]*jaeger.BatchSubmitResponse, error)
+ SubmitBatches(
+ batches []*jaeger.Batch,
+ options SubmitBatchOptions,
+ ) ([]*jaeger.BatchSubmitResponse, error)
}
type jaegerBatchesHandler struct {
@@ -50,14 +56,20 @@ type jaegerBatchesHandler struct {
}
// NewJaegerSpanHandler returns a JaegerBatchesHandler
-func NewJaegerSpanHandler(logger *zap.Logger, modelProcessor processor.SpanProcessor) JaegerBatchesHandler {
+func NewJaegerSpanHandler(
+ logger *zap.Logger,
+ modelProcessor processor.SpanProcessor,
+) JaegerBatchesHandler {
return &jaegerBatchesHandler{
logger: logger,
modelProcessor: modelProcessor,
}
}
-func (jbh *jaegerBatchesHandler) SubmitBatches(batches []*jaeger.Batch, options SubmitBatchOptions) ([]*jaeger.BatchSubmitResponse, error) {
+func (jbh *jaegerBatchesHandler) SubmitBatches(
+ batches []*jaeger.Batch,
+ options SubmitBatchOptions,
+) ([]*jaeger.BatchSubmitResponse, error) {
responses := make([]*jaeger.BatchSubmitResponse, 0, len(batches))
for _, batch := range batches {
mSpans := make([]*model.Span, 0, len(batch.Spans))
@@ -65,12 +77,18 @@ func (jbh *jaegerBatchesHandler) SubmitBatches(batches []*jaeger.Batch, options
mSpan := jConv.ToDomainSpan(span, batch.Process)
mSpans = append(mSpans, mSpan)
}
- oks, err := jbh.modelProcessor.ProcessSpans(mSpans, processor.SpansOptions{
- InboundTransport: options.InboundTransport,
- SpanFormat: processor.JaegerSpanFormat,
- })
+ oks, err := jbh.modelProcessor.ProcessSpans(
+ mSpans,
+ processor.SpansOptions{
+ InboundTransport: options.InboundTransport,
+ SpanFormat: processor.JaegerSpanFormat,
+ },
+ )
if err != nil {
- jbh.logger.Error("Collector failed to process span batch", zap.Error(err))
+ jbh.logger.Error(
+ "Collector failed to process span batch",
+ zap.Error(err),
+ )
return nil, err
}
batchOk := true
@@ -81,7 +99,10 @@ func (jbh *jaegerBatchesHandler) SubmitBatches(batches []*jaeger.Batch, options
}
}
- jbh.logger.Debug("Span batch processed by the collector.", zap.Bool("ok", batchOk))
+ jbh.logger.Debug(
+ "Span batch processed by the collector.",
+ zap.Bool("ok", batchOk),
+ )
res := &jaeger.BatchSubmitResponse{
Ok: batchOk,
}
@@ -97,7 +118,11 @@ type zipkinSpanHandler struct {
}
// NewZipkinSpanHandler returns a ZipkinSpansHandler
-func NewZipkinSpanHandler(logger *zap.Logger, modelHandler processor.SpanProcessor, sanitizer zipkinS.Sanitizer) ZipkinSpansHandler {
+func NewZipkinSpanHandler(
+ logger *zap.Logger,
+ modelHandler processor.SpanProcessor,
+ sanitizer zipkinS.Sanitizer,
+) ZipkinSpansHandler {
return &zipkinSpanHandler{
logger: logger,
modelProcessor: modelHandler,
@@ -106,7 +131,10 @@ func NewZipkinSpanHandler(logger *zap.Logger, modelHandler processor.SpanProcess
}
// SubmitZipkinBatch records a batch of spans already in Zipkin Thrift format.
-func (h *zipkinSpanHandler) SubmitZipkinBatch(spans []*zipkincore.Span, options SubmitBatchOptions) ([]*zipkincore.Response, error) {
+func (h *zipkinSpanHandler) SubmitZipkinBatch(
+ spans []*zipkincore.Span,
+ options SubmitBatchOptions,
+) ([]*zipkincore.Response, error) {
mSpans := make([]*model.Span, 0, len(spans))
convCount := make([]int, len(spans))
for i, span := range spans {
@@ -121,7 +149,10 @@ func (h *zipkinSpanHandler) SubmitZipkinBatch(spans []*zipkincore.Span, options
SpanFormat: processor.ZipkinSpanFormat,
})
if err != nil {
- h.logger.Error("Collector failed to process Zipkin span batch", zap.Error(err))
+ h.logger.Error(
+ "Collector failed to process Zipkin span batch",
+ zap.Error(err),
+ )
return nil, err
}
responses := make([]*zipkincore.Response, len(spans))
@@ -146,10 +177,16 @@ func (h *zipkinSpanHandler) SubmitZipkinBatch(spans []*zipkincore.Span, options
}
// ConvertZipkinToModel is a helper function that logs warnings during conversion
-func convertZipkinToModel(zSpan *zipkincore.Span, logger *zap.Logger) []*model.Span {
+func convertZipkinToModel(
+ zSpan *zipkincore.Span,
+ logger *zap.Logger,
+) []*model.Span {
mSpans, err := zipkin.ToDomainSpan(zSpan)
if err != nil {
- logger.Warn("Warning while converting zipkin to domain span", zap.Error(err))
+ logger.Warn(
+ "Warning while converting zipkin to domain span",
+ zap.Error(err),
+ )
}
return mSpans
}
diff --git a/cmd/collector/app/handler/thrift_span_handler_test.go b/cmd/collector/app/handler/thrift_span_handler_test.go
index d247f1ab59d..bc52e2508c3 100644
--- a/cmd/collector/app/handler/thrift_span_handler_test.go
+++ b/cmd/collector/app/handler/thrift_span_handler_test.go
@@ -45,7 +45,10 @@ func TestJaegerSpanHandler(t *testing.T) {
}
for _, tc := range testChunks {
logger := zap.NewNop()
- h := NewJaegerSpanHandler(logger, &shouldIErrorProcessor{tc.expectedErr != nil})
+ h := NewJaegerSpanHandler(
+ logger,
+ &shouldIErrorProcessor{tc.expectedErr != nil},
+ )
res, err := h.SubmitBatches([]*jaeger.Batch{
{
Process: &jaeger.Process{ServiceName: "someServiceName"},
@@ -69,7 +72,10 @@ type shouldIErrorProcessor struct {
var errTestError = errors.New("Whoops")
-func (s *shouldIErrorProcessor) ProcessSpans(mSpans []*model.Span, _ processor.SpansOptions) ([]bool, error) {
+func (s *shouldIErrorProcessor) ProcessSpans(
+ mSpans []*model.Span,
+ _ processor.SpansOptions,
+) ([]bool, error) {
if s.shouldError {
return nil, errTestError
}
@@ -110,7 +116,8 @@ func TestZipkinSpanHandler(t *testing.T) {
h := NewZipkinSpanHandler(
logger,
&shouldIErrorProcessor{tc.expectedErr != nil},
- zipkinsanitizer.NewChainedSanitizer(zipkinsanitizer.NewStandardSanitizers()...),
+ zipkinsanitizer.NewChainedSanitizer(
+ zipkinsanitizer.NewStandardSanitizers()...),
)
var spans []*zipkincore.Span
if tc.filename != "" {
diff --git a/cmd/collector/app/handler/zipkin_receiver_test.go b/cmd/collector/app/handler/zipkin_receiver_test.go
index 54abedd1964..0868314e81a 100644
--- a/cmd/collector/app/handler/zipkin_receiver_test.go
+++ b/cmd/collector/app/handler/zipkin_receiver_test.go
@@ -127,7 +127,11 @@ func TestZipkinReceiver(t *testing.T) {
t.Logf("response: %s %s", response.Status, string(bodyBytes))
}
require.NoError(t, response.Body.Close())
- require.Equal(t, processor.ZipkinSpanFormat, spanProcessor.getSpanFormat())
+ require.Equal(
+ t,
+ processor.ZipkinSpanFormat,
+ spanProcessor.getSpanFormat(),
+ )
})
}
}
@@ -148,7 +152,15 @@ func TestStartZipkinReceiver_Error(t *testing.T) {
return nil, errors.New("mock error")
}
f := zipkinreceiver.NewFactory()
- _, err = startZipkinReceiver(opts, logger, spanProcessor, tm, f, newTraces, f.CreateTracesReceiver)
+ _, err = startZipkinReceiver(
+ opts,
+ logger,
+ spanProcessor,
+ tm,
+ f,
+ newTraces,
+ f.CreateTracesReceiver,
+ )
require.Error(t, err)
assert.Contains(t, err.Error(), "could not create Zipkin consumer")
@@ -157,7 +169,15 @@ func TestStartZipkinReceiver_Error(t *testing.T) {
) (receiver.Traces, error) {
return nil, errors.New("mock error")
}
- _, err = startZipkinReceiver(opts, logger, spanProcessor, tm, f, consumer.NewTraces, createTracesReceiver)
+ _, err = startZipkinReceiver(
+ opts,
+ logger,
+ spanProcessor,
+ tm,
+ f,
+ consumer.NewTraces,
+ createTracesReceiver,
+ )
require.Error(t, err)
assert.Contains(t, err.Error(), "could not create Zipkin receiver")
}
diff --git a/cmd/collector/app/handler/zipkin_receiver_tls_test.go b/cmd/collector/app/handler/zipkin_receiver_tls_test.go
index 4f34eb101ca..599e409bc6e 100644
--- a/cmd/collector/app/handler/zipkin_receiver_tls_test.go
+++ b/cmd/collector/app/handler/zipkin_receiver_tls_test.go
@@ -174,7 +174,9 @@ func TestSpanCollectorZipkinTLS(t *testing.T) {
tm := &tenancy.Manager{}
opts := &flags.CollectorOptions{}
- opts.Zipkin.HTTPHostPort = ports.PortToHostPort(ports.CollectorZipkin)
+ opts.Zipkin.HTTPHostPort = ports.PortToHostPort(
+ ports.CollectorZipkin,
+ )
opts.Zipkin.TLS = test.serverTLS
defer test.serverTLS.Close()
@@ -192,7 +194,12 @@ func TestSpanCollectorZipkinTLS(t *testing.T) {
defer test.clientTLS.Close()
require.NoError(t, err0)
dialer := &net.Dialer{Timeout: 2 * time.Second}
- conn, clientError := tls.DialWithDialer(dialer, "tcp", fmt.Sprintf("localhost:%d", ports.CollectorZipkin), clientTLSCfg)
+ conn, clientError := tls.DialWithDialer(
+ dialer,
+ "tcp",
+ fmt.Sprintf("localhost:%d", ports.CollectorZipkin),
+ clientTLSCfg,
+ )
if test.expectTLSClientErr {
require.Error(t, clientError)
@@ -207,7 +214,11 @@ func TestSpanCollectorZipkinTLS(t *testing.T) {
},
}
- response, requestError := client.Post(fmt.Sprintf("https://localhost:%d", ports.CollectorZipkin), "", nil)
+ response, requestError := client.Post(
+ fmt.Sprintf("https://localhost:%d", ports.CollectorZipkin),
+ "",
+ nil,
+ )
if test.expectZipkinClientErr {
require.Error(t, requestError)
diff --git a/cmd/collector/app/metrics.go b/cmd/collector/app/metrics.go
index 8602507b7da..91589e98b93 100644
--- a/cmd/collector/app/metrics.go
+++ b/cmd/collector/app/metrics.go
@@ -120,15 +120,34 @@ type SpanCounts struct {
}
// NewSpanProcessorMetrics returns a SpanProcessorMetrics
-func NewSpanProcessorMetrics(serviceMetrics metrics.Factory, hostMetrics metrics.Factory, otherFormatTypes []processor.SpanFormat) *SpanProcessorMetrics {
+func NewSpanProcessorMetrics(
+ serviceMetrics metrics.Factory,
+ hostMetrics metrics.Factory,
+ otherFormatTypes []processor.SpanFormat,
+) *SpanProcessorMetrics {
spanCounts := SpanCountsByFormat{
- processor.ZipkinSpanFormat: newCountsByTransport(serviceMetrics, processor.ZipkinSpanFormat),
- processor.JaegerSpanFormat: newCountsByTransport(serviceMetrics, processor.JaegerSpanFormat),
- processor.ProtoSpanFormat: newCountsByTransport(serviceMetrics, processor.ProtoSpanFormat),
- processor.UnknownSpanFormat: newCountsByTransport(serviceMetrics, processor.UnknownSpanFormat),
+ processor.ZipkinSpanFormat: newCountsByTransport(
+ serviceMetrics,
+ processor.ZipkinSpanFormat,
+ ),
+ processor.JaegerSpanFormat: newCountsByTransport(
+ serviceMetrics,
+ processor.JaegerSpanFormat,
+ ),
+ processor.ProtoSpanFormat: newCountsByTransport(
+ serviceMetrics,
+ processor.ProtoSpanFormat,
+ ),
+ processor.UnknownSpanFormat: newCountsByTransport(
+ serviceMetrics,
+ processor.UnknownSpanFormat,
+ ),
}
for _, otherFormatType := range otherFormatTypes {
- spanCounts[otherFormatType] = newCountsByTransport(serviceMetrics, otherFormatType)
+ spanCounts[otherFormatType] = newCountsByTransport(
+ serviceMetrics,
+ otherFormatType,
+ )
}
m := &SpanProcessorMetrics{
SaveLatency: hostMetrics.Timer(metrics.TimerOptions{Name: "save-latency", Tags: nil}),
@@ -138,30 +157,54 @@ func NewSpanProcessorMetrics(serviceMetrics metrics.Factory, hostMetrics metrics
QueueCapacity: hostMetrics.Gauge(metrics.Options{Name: "queue-capacity", Tags: nil}),
QueueLength: hostMetrics.Gauge(metrics.Options{Name: "queue-length", Tags: nil}),
SpansBytes: hostMetrics.Gauge(metrics.Options{Name: "spans.bytes", Tags: nil}),
- SavedOkBySvc: newMetricsBySvc(serviceMetrics.Namespace(metrics.NSOptions{Name: "", Tags: map[string]string{"result": "ok"}}), "saved-by-svc"),
- SavedErrBySvc: newMetricsBySvc(serviceMetrics.Namespace(metrics.NSOptions{Name: "", Tags: map[string]string{"result": "err"}}), "saved-by-svc"),
- spanCounts: spanCounts,
- serviceNames: hostMetrics.Gauge(metrics.Options{Name: "spans.serviceNames", Tags: nil}),
+ SavedOkBySvc: newMetricsBySvc(
+ serviceMetrics.Namespace(metrics.NSOptions{Name: "", Tags: map[string]string{"result": "ok"}}),
+ "saved-by-svc",
+ ),
+ SavedErrBySvc: newMetricsBySvc(
+ serviceMetrics.Namespace(metrics.NSOptions{Name: "", Tags: map[string]string{"result": "err"}}),
+ "saved-by-svc",
+ ),
+ spanCounts: spanCounts,
+ serviceNames: hostMetrics.Gauge(metrics.Options{Name: "spans.serviceNames", Tags: nil}),
}
return m
}
func newMetricsBySvc(factory metrics.Factory, category string) metricsBySvc {
- spansFactory := factory.Namespace(metrics.NSOptions{Name: "spans", Tags: nil})
- tracesFactory := factory.Namespace(metrics.NSOptions{Name: "traces", Tags: nil})
+ spansFactory := factory.Namespace(
+ metrics.NSOptions{Name: "spans", Tags: nil},
+ )
+ tracesFactory := factory.Namespace(
+ metrics.NSOptions{Name: "traces", Tags: nil},
+ )
return metricsBySvc{
spans: newSpanCountsBySvc(spansFactory, category, maxServiceNames),
traces: newTraceCountsBySvc(tracesFactory, category, maxServiceNames),
}
}
-func newTraceCountsBySvc(factory metrics.Factory, category string, maxServices int) traceCountsBySvc {
- extraSlotsForOtherServicesSamples := len(otherServicesSamplers) - 1 // excluding UnrecognizedSampler
+func newTraceCountsBySvc(
+ factory metrics.Factory,
+ category string,
+ maxServices int,
+) traceCountsBySvc {
+ extraSlotsForOtherServicesSamples := len(
+ otherServicesSamplers,
+ ) - 1 // excluding UnrecognizedSampler
return traceCountsBySvc{
countsBySvc: countsBySvc{
- counts: newTraceCountsOtherServices(factory, category, "false"),
- debugCounts: newTraceCountsOtherServices(factory, category, "true"),
+ counts: newTraceCountsOtherServices(
+ factory,
+ category,
+ "false",
+ ),
+ debugCounts: newTraceCountsOtherServices(
+ factory,
+ category,
+ "true",
+ ),
factory: factory,
lock: &sync.Mutex{},
maxServiceNames: maxServices + extraSlotsForOtherServicesSamples,
@@ -176,7 +219,11 @@ func newTraceCountsBySvc(factory metrics.Factory, category string, maxServices i
}
}
-func newTraceCountsOtherServices(factory metrics.Factory, category string, isDebug string) map[string]metrics.Counter {
+func newTraceCountsOtherServices(
+ factory metrics.Factory,
+ category string,
+ isDebug string,
+) map[string]metrics.Counter {
m := make(map[string]metrics.Counter)
for kSampler, vString := range otherServicesSamplers {
m[vString] = factory.Counter(
@@ -192,11 +239,23 @@ func newTraceCountsOtherServices(factory metrics.Factory, category string, isDeb
return m
}
-func newSpanCountsBySvc(factory metrics.Factory, category string, maxServiceNames int) spanCountsBySvc {
+func newSpanCountsBySvc(
+ factory metrics.Factory,
+ category string,
+ maxServiceNames int,
+) spanCountsBySvc {
return spanCountsBySvc{
countsBySvc: countsBySvc{
- counts: map[string]metrics.Counter{otherServices: factory.Counter(metrics.Options{Name: category, Tags: map[string]string{"svc": otherServices, "debug": "false"}})},
- debugCounts: map[string]metrics.Counter{otherServices: factory.Counter(metrics.Options{Name: category, Tags: map[string]string{"svc": otherServices, "debug": "true"}})},
+ counts: map[string]metrics.Counter{
+ otherServices: factory.Counter(
+ metrics.Options{Name: category, Tags: map[string]string{"svc": otherServices, "debug": "false"}},
+ ),
+ },
+ debugCounts: map[string]metrics.Counter{
+ otherServices: factory.Counter(
+ metrics.Options{Name: category, Tags: map[string]string{"svc": otherServices, "debug": "true"}},
+ ),
+ },
factory: factory,
lock: &sync.Mutex{},
maxServiceNames: maxServiceNames,
@@ -205,17 +264,32 @@ func newSpanCountsBySvc(factory metrics.Factory, category string, maxServiceName
}
}
-func newCountsByTransport(factory metrics.Factory, format processor.SpanFormat) SpanCountsByTransport {
- factory = factory.Namespace(metrics.NSOptions{Tags: map[string]string{"format": string(format)}})
+func newCountsByTransport(
+ factory metrics.Factory,
+ format processor.SpanFormat,
+) SpanCountsByTransport {
+ factory = factory.Namespace(
+ metrics.NSOptions{Tags: map[string]string{"format": string(format)}},
+ )
return SpanCountsByTransport{
- processor.HTTPTransport: newCounts(factory, processor.HTTPTransport),
- processor.GRPCTransport: newCounts(factory, processor.GRPCTransport),
- processor.UnknownTransport: newCounts(factory, processor.UnknownTransport),
+ processor.HTTPTransport: newCounts(factory, processor.HTTPTransport),
+ processor.GRPCTransport: newCounts(factory, processor.GRPCTransport),
+ processor.UnknownTransport: newCounts(
+ factory,
+ processor.UnknownTransport,
+ ),
}
}
-func newCounts(factory metrics.Factory, transport processor.InboundTransport) SpanCounts {
- factory = factory.Namespace(metrics.NSOptions{Tags: map[string]string{"transport": string(transport)}})
+func newCounts(
+ factory metrics.Factory,
+ transport processor.InboundTransport,
+) SpanCounts {
+ factory = factory.Namespace(
+ metrics.NSOptions{
+ Tags: map[string]string{"transport": string(transport)},
+ },
+ )
return SpanCounts{
RejectedBySvc: newMetricsBySvc(factory, "rejected"),
ReceivedBySvc: newMetricsBySvc(factory, "received"),
@@ -223,7 +297,10 @@ func newCounts(factory metrics.Factory, transport processor.InboundTransport) Sp
}
// GetCountsForFormat gets the SpanCounts for a given format and transport. If none exists, we use the Unknown format.
-func (m *SpanProcessorMetrics) GetCountsForFormat(spanFormat processor.SpanFormat, transport processor.InboundTransport) SpanCounts {
+func (m *SpanProcessorMetrics) GetCountsForFormat(
+ spanFormat processor.SpanFormat,
+ transport processor.InboundTransport,
+) SpanCounts {
c, ok := m.spanCounts[spanFormat]
if !ok {
c = m.spanCounts[processor.UnknownSpanFormat]
@@ -253,13 +330,20 @@ func (m metricsBySvc) ReportServiceNameForSpan(span *model.Span) {
}
// countSpansByServiceName counts how many spans are received per service.
-func (m metricsBySvc) countSpansByServiceName(serviceName string, isDebug bool) {
+func (m metricsBySvc) countSpansByServiceName(
+ serviceName string,
+ isDebug bool,
+) {
m.spans.countByServiceName(serviceName, isDebug)
}
// countTracesByServiceName counts how many traces are received per service,
// i.e. the counter is only incremented for the root spans.
-func (m metricsBySvc) countTracesByServiceName(serviceName string, isDebug bool, samplerType model.SamplerType) {
+func (m metricsBySvc) countTracesByServiceName(
+ serviceName string,
+ isDebug bool,
+ samplerType model.SamplerType,
+) {
m.traces.countByServiceName(serviceName, isDebug, samplerType)
}
@@ -273,7 +357,11 @@ func (m metricsBySvc) countTracesByServiceName(serviceName string, isDebug bool,
// total number of stored counters, so if it exceeds say the 90% threshold
// an alert should be raised to investigate what's causing so many unique
// service names.
-func (m *traceCountsBySvc) countByServiceName(serviceName string, isDebug bool, samplerType model.SamplerType) {
+func (m *traceCountsBySvc) countByServiceName(
+ serviceName string,
+ isDebug bool,
+ samplerType model.SamplerType,
+) {
serviceName = normalizer.ServiceName(serviceName)
counts := m.counts
if isDebug {
diff --git a/cmd/collector/app/metrics_test.go b/cmd/collector/app/metrics_test.go
index 8c0990f76d9..e49ce15ab65 100644
--- a/cmd/collector/app/metrics_test.go
+++ b/cmd/collector/app/metrics_test.go
@@ -30,15 +30,32 @@ import (
func TestProcessorMetrics(t *testing.T) {
baseMetrics := metricstest.NewFactory(time.Hour)
defer baseMetrics.Backend.Stop()
- serviceMetrics := baseMetrics.Namespace(jaegerM.NSOptions{Name: "service", Tags: nil})
- hostMetrics := baseMetrics.Namespace(jaegerM.NSOptions{Name: "host", Tags: nil})
- spm := NewSpanProcessorMetrics(serviceMetrics, hostMetrics, []processor.SpanFormat{processor.SpanFormat("scruffy")})
- benderFormatHTTPMetrics := spm.GetCountsForFormat("bender", processor.HTTPTransport)
+ serviceMetrics := baseMetrics.Namespace(
+ jaegerM.NSOptions{Name: "service", Tags: nil},
+ )
+ hostMetrics := baseMetrics.Namespace(
+ jaegerM.NSOptions{Name: "host", Tags: nil},
+ )
+ spm := NewSpanProcessorMetrics(
+ serviceMetrics,
+ hostMetrics,
+ []processor.SpanFormat{processor.SpanFormat("scruffy")},
+ )
+ benderFormatHTTPMetrics := spm.GetCountsForFormat(
+ "bender",
+ processor.HTTPTransport,
+ )
assert.NotNil(t, benderFormatHTTPMetrics)
- benderFormatGRPCMetrics := spm.GetCountsForFormat("bender", processor.GRPCTransport)
+ benderFormatGRPCMetrics := spm.GetCountsForFormat(
+ "bender",
+ processor.GRPCTransport,
+ )
assert.NotNil(t, benderFormatGRPCMetrics)
- grpcChannelFormat := spm.GetCountsForFormat(processor.JaegerSpanFormat, processor.GRPCTransport)
+ grpcChannelFormat := spm.GetCountsForFormat(
+ processor.JaegerSpanFormat,
+ processor.GRPCTransport,
+ )
assert.NotNil(t, grpcChannelFormat)
grpcChannelFormat.ReceivedBySvc.ReportServiceNameForSpan(&model.Span{
Process: &model.Process{},
@@ -57,8 +74,16 @@ func TestProcessorMetrics(t *testing.T) {
assert.EqualValues(t, 1, counters["service.spans.received|debug=false|format=jaeger|svc=fry|transport=grpc"])
assert.EqualValues(t, 2, counters["service.spans.received|debug=true|format=jaeger|svc=fry|transport=grpc"])
- assert.EqualValues(t, 1, counters["service.traces.received|debug=false|format=jaeger|sampler_type=unrecognized|svc=fry|transport=grpc"])
- assert.EqualValues(t, 1, counters["service.traces.received|debug=true|format=jaeger|sampler_type=unrecognized|svc=fry|transport=grpc"])
+ assert.EqualValues(
+ t,
+ 1,
+ counters["service.traces.received|debug=false|format=jaeger|sampler_type=unrecognized|svc=fry|transport=grpc"],
+ )
+ assert.EqualValues(
+ t,
+ 1,
+ counters["service.traces.received|debug=true|format=jaeger|sampler_type=unrecognized|svc=fry|transport=grpc"],
+ )
assert.Empty(t, gauges)
}
@@ -75,7 +100,12 @@ func TestNewTraceCountsBySvc(t *testing.T) {
counters, _ := baseMetrics.Backend.Snapshot()
assert.EqualValues(t, 1, counters["not_on_my_level|debug=false|sampler_type=unrecognized|svc=fry"])
assert.EqualValues(t, 1, counters["not_on_my_level|debug=false|sampler_type=unrecognized|svc=leela"])
- assert.EqualValues(t, 2, counters["not_on_my_level|debug=false|sampler_type=unrecognized|svc=other-services"], counters)
+ assert.EqualValues(
+ t,
+ 2,
+ counters["not_on_my_level|debug=false|sampler_type=unrecognized|svc=other-services"],
+ counters,
+ )
metrics.countByServiceName("bender", true, model.SamplerTypeConst)
metrics.countByServiceName("bender", true, model.SamplerTypeProbabilistic)
@@ -88,7 +118,12 @@ func TestNewTraceCountsBySvc(t *testing.T) {
counters, _ = baseMetrics.Backend.Snapshot()
assert.EqualValues(t, 1, counters["not_on_my_level|debug=true|sampler_type=const|svc=bender"])
assert.EqualValues(t, 1, counters["not_on_my_level|debug=true|sampler_type=probabilistic|svc=bender"])
- assert.EqualValues(t, 1, counters["not_on_my_level|debug=true|sampler_type=probabilistic|svc=other-services"], counters)
+ assert.EqualValues(
+ t,
+ 1,
+ counters["not_on_my_level|debug=true|sampler_type=probabilistic|svc=other-services"],
+ counters,
+ )
assert.EqualValues(t, 1, counters["not_on_my_level|debug=true|sampler_type=ratelimiting|svc=other-services"])
assert.EqualValues(t, 1, counters["not_on_my_level|debug=true|sampler_type=const|svc=other-services"])
assert.EqualValues(t, 1, counters["not_on_my_level|debug=true|sampler_type=lowerbound|svc=other-services"])
@@ -107,7 +142,11 @@ func TestNewSpanCountsBySvc(t *testing.T) {
counters, _ := baseMetrics.Backend.Snapshot()
assert.EqualValues(t, 1, counters["not_on_my_level|debug=false|svc=fry"])
assert.EqualValues(t, 1, counters["not_on_my_level|debug=false|svc=leela"])
- assert.EqualValues(t, 2, counters["not_on_my_level|debug=false|svc=other-services"])
+ assert.EqualValues(
+ t,
+ 2,
+ counters["not_on_my_level|debug=false|svc=other-services"],
+ )
metrics.countByServiceName("zoidberg", true)
metrics.countByServiceName("bender", true)
@@ -115,9 +154,17 @@ func TestNewSpanCountsBySvc(t *testing.T) {
metrics.countByServiceName("fry", true)
counters, _ = baseMetrics.Backend.Snapshot()
- assert.EqualValues(t, 1, counters["not_on_my_level|debug=true|svc=zoidberg"])
+ assert.EqualValues(
+ t,
+ 1,
+ counters["not_on_my_level|debug=true|svc=zoidberg"],
+ )
assert.EqualValues(t, 1, counters["not_on_my_level|debug=true|svc=bender"])
- assert.EqualValues(t, 2, counters["not_on_my_level|debug=true|svc=other-services"])
+ assert.EqualValues(
+ t,
+ 2,
+ counters["not_on_my_level|debug=true|svc=other-services"],
+ )
}
func TestBuildKey(t *testing.T) {
diff --git a/cmd/collector/app/options.go b/cmd/collector/app/options.go
index 477f1296073..5720e83f06e 100644
--- a/cmd/collector/app/options.go
+++ b/cmd/collector/app/options.go
@@ -145,7 +145,9 @@ func (options) ReportBusy(reportBusy bool) Option {
}
// ExtraFormatTypes creates an Option that initializes the extra list of format types
-func (options) ExtraFormatTypes(extraFormatTypes []processor.SpanFormat) Option {
+func (options) ExtraFormatTypes(
+ extraFormatTypes []processor.SpanFormat,
+) Option {
return func(b *options) {
b.extraFormatTypes = extraFormatTypes
}
diff --git a/cmd/collector/app/options_test.go b/cmd/collector/app/options_test.go
index e416166829f..4b225691acc 100644
--- a/cmd/collector/app/options_test.go
+++ b/cmd/collector/app/options_test.go
@@ -50,7 +50,11 @@ func TestAllOptionSet(t *testing.T) {
)
assert.EqualValues(t, 5, opts.numWorkers)
assert.EqualValues(t, 10, opts.queueSize)
- assert.EqualValues(t, map[string]string{"extra": "tags"}, opts.collectorTags)
+ assert.EqualValues(
+ t,
+ map[string]string{"extra": "tags"},
+ opts.collectorTags,
+ )
assert.EqualValues(t, 1000, opts.dynQueueSizeWarmup)
assert.EqualValues(t, 1024, opts.dynQueueSizeMemory)
assert.True(t, opts.spanSizeMetricsEnabled)
diff --git a/cmd/collector/app/sampling/grpc_handler.go b/cmd/collector/app/sampling/grpc_handler.go
index 1110bf37497..3127b10f5a6 100644
--- a/cmd/collector/app/sampling/grpc_handler.go
+++ b/cmd/collector/app/sampling/grpc_handler.go
@@ -34,6 +34,9 @@ func NewGRPCHandler(store strategystore.StrategyStore) GRPCHandler {
}
// GetSamplingStrategy returns sampling decision from store.
-func (s GRPCHandler) GetSamplingStrategy(ctx context.Context, param *api_v2.SamplingStrategyParameters) (*api_v2.SamplingStrategyResponse, error) {
+func (s GRPCHandler) GetSamplingStrategy(
+ ctx context.Context,
+ param *api_v2.SamplingStrategyParameters,
+) (*api_v2.SamplingStrategyResponse, error) {
return s.store.GetSamplingStrategy(ctx, param.GetServiceName())
}
diff --git a/cmd/collector/app/sampling/grpc_handler_test.go b/cmd/collector/app/sampling/grpc_handler_test.go
index ed9a65a72c6..4b60aa69010 100644
--- a/cmd/collector/app/sampling/grpc_handler_test.go
+++ b/cmd/collector/app/sampling/grpc_handler_test.go
@@ -28,13 +28,18 @@ import (
type mockSamplingStore struct{}
-func (mockSamplingStore) GetSamplingStrategy(ctx context.Context, serviceName string) (*api_v2.SamplingStrategyResponse, error) {
+func (mockSamplingStore) GetSamplingStrategy(
+ ctx context.Context,
+ serviceName string,
+) (*api_v2.SamplingStrategyResponse, error) {
if serviceName == "error" {
return nil, errors.New("some error")
} else if serviceName == "nil" {
return nil, nil
}
- return &api_v2.SamplingStrategyResponse{StrategyType: api_v2.SamplingStrategyType_PROBABILISTIC}, nil
+ return &api_v2.SamplingStrategyResponse{
+ StrategyType: api_v2.SamplingStrategyType_PROBABILISTIC,
+ }, nil
}
func (mockSamplingStore) Close() error {
@@ -49,7 +54,10 @@ func TestNewGRPCHandler(t *testing.T) {
}{
{req: &api_v2.SamplingStrategyParameters{ServiceName: "error"}, err: "some error"},
{req: &api_v2.SamplingStrategyParameters{ServiceName: "nil"}, resp: nil},
- {req: &api_v2.SamplingStrategyParameters{ServiceName: "foo"}, resp: &api_v2.SamplingStrategyResponse{StrategyType: api_v2.SamplingStrategyType_PROBABILISTIC}},
+ {
+ req: &api_v2.SamplingStrategyParameters{ServiceName: "foo"},
+ resp: &api_v2.SamplingStrategyResponse{StrategyType: api_v2.SamplingStrategyType_PROBABILISTIC},
+ },
}
h := NewGRPCHandler(mockSamplingStore{})
for _, test := range tests {
diff --git a/cmd/collector/app/sampling/strategystore/factory.go b/cmd/collector/app/sampling/strategystore/factory.go
index 4a4059c4f5f..fc40f957978 100644
--- a/cmd/collector/app/sampling/strategystore/factory.go
+++ b/cmd/collector/app/sampling/strategystore/factory.go
@@ -29,7 +29,11 @@ import (
// plugin.Configurable
type Factory interface {
// Initialize performs internal initialization of the factory.
- Initialize(metricsFactory metrics.Factory, ssFactory storage.SamplingStoreFactory, logger *zap.Logger) error
+ Initialize(
+ metricsFactory metrics.Factory,
+ ssFactory storage.SamplingStoreFactory,
+ logger *zap.Logger,
+ ) error
// CreateStrategyStore initializes the StrategyStore and returns it.
CreateStrategyStore() (StrategyStore, Aggregator, error)
diff --git a/cmd/collector/app/sampling/strategystore/interface.go b/cmd/collector/app/sampling/strategystore/interface.go
index 9d2c3fb271b..699cca87930 100644
--- a/cmd/collector/app/sampling/strategystore/interface.go
+++ b/cmd/collector/app/sampling/strategystore/interface.go
@@ -30,7 +30,10 @@ type StrategyStore interface {
io.Closer
// GetSamplingStrategy retrieves the sampling strategy for the specified service.
- GetSamplingStrategy(ctx context.Context, serviceName string) (*api_v2.SamplingStrategyResponse, error)
+ GetSamplingStrategy(
+ ctx context.Context,
+ serviceName string,
+ ) (*api_v2.SamplingStrategyResponse, error)
}
// Aggregator defines an interface used to aggregate operation throughput.
@@ -43,7 +46,11 @@ type Aggregator interface {
HandleRootSpan(span *model.Span, logger *zap.Logger)
// RecordThroughput records throughput for an operation for aggregation.
- RecordThroughput(service, operation string, samplerType model.SamplerType, probability float64)
+ RecordThroughput(
+ service, operation string,
+ samplerType model.SamplerType,
+ probability float64,
+ )
// Start starts aggregating operation throughput.
Start()
diff --git a/cmd/collector/app/sanitizer/cache/auto_refresh_cache.go b/cmd/collector/app/sanitizer/cache/auto_refresh_cache.go
index b3d8c433fdd..f8b3ffed944 100644
--- a/cmd/collector/app/sanitizer/cache/auto_refresh_cache.go
+++ b/cmd/collector/app/sanitizer/cache/auto_refresh_cache.go
@@ -79,7 +79,10 @@ func (c *autoRefreshCache) IsEmpty() bool {
// Initialize warm the cache and start up the auto cache refreshes
func (c *autoRefreshCache) Initialize() error {
if err := c.warmCache(); err != nil {
- c.logger.Error("Cannot warm cache from storage or external source", zap.Error(err))
+ c.logger.Error(
+ "Cannot warm cache from storage or external source",
+ zap.Error(err),
+ )
}
c.initializeCacheRefresh()
return nil
@@ -97,7 +100,9 @@ func (c *autoRefreshCache) initializeCacheRefresh() {
}
// refreshFromExternalSource regularly retrieves data from an external source and saves it to storage
-func (c *autoRefreshCache) refreshFromExternalSource(refreshInterval time.Duration) {
+func (c *autoRefreshCache) refreshFromExternalSource(
+ refreshInterval time.Duration,
+) {
time.Sleep(getRandomSleepTime(refreshInterval))
c.updateAndSaveToStorage()
ticker := time.NewTicker(refreshInterval)
@@ -116,7 +121,10 @@ func (c *autoRefreshCache) refreshFromExternalSource(refreshInterval time.Durati
func (c *autoRefreshCache) updateAndSaveToStorage() {
cache, err := c.extSource.Load()
if err != nil {
- c.logger.Error("Failed to retrieve cache from external source", zap.Error(err))
+ c.logger.Error(
+ "Failed to retrieve cache from external source",
+ zap.Error(err),
+ )
return
}
// Get read lock so that the cache isn't modified while the cache is dumped to storage
diff --git a/cmd/collector/app/sanitizer/cache/auto_refresh_cache_test.go b/cmd/collector/app/sanitizer/cache/auto_refresh_cache_test.go
index 8295fe9ec48..8ce0f763bb7 100644
--- a/cmd/collector/app/sanitizer/cache/auto_refresh_cache_test.go
+++ b/cmd/collector/app/sanitizer/cache/auto_refresh_cache_test.go
@@ -38,7 +38,9 @@ var (
// dont_go:generate mockery -name=ServiceAliasMappingStorage
// dont_go:generate mockery -name=ServiceAliasMappingExternalSource
-func getCache(t *testing.T) (*autoRefreshCache, *mocks.ServiceAliasMappingExternalSource, *mocks.ServiceAliasMappingStorage) {
+func getCache(
+ t *testing.T,
+) (*autoRefreshCache, *mocks.ServiceAliasMappingExternalSource, *mocks.ServiceAliasMappingStorage) {
mockExtSource := &mocks.ServiceAliasMappingExternalSource{}
mockStorage := &mocks.ServiceAliasMappingStorage{}
logger := zap.NewNop()
@@ -121,7 +123,12 @@ func TestWarmCache(t *testing.T) {
mE.On("Load").Return(testCache2, nil).Times(1)
err = c.warmCache()
require.NoError(t, err)
- assert.Equal(t, "rt-demand", c.Get("demand"), "External load should've succeeded")
+ assert.Equal(
+ t,
+ "rt-demand",
+ c.Get("demand"),
+ "External load should've succeeded",
+ )
mS.On("Load").Return(nil, errDefault).Times(1)
mE.On("Load").Return(nil, errDefault).Times(1)
diff --git a/cmd/collector/app/sanitizer/utf8_sanitizer.go b/cmd/collector/app/sanitizer/utf8_sanitizer.go
index bd959ac6a1e..ddd8affc021 100644
--- a/cmd/collector/app/sanitizer/utf8_sanitizer.go
+++ b/cmd/collector/app/sanitizer/utf8_sanitizer.go
@@ -45,13 +45,27 @@ func NewUTF8Sanitizer(logger *zap.Logger) SanitizeSpan {
// Sanitize sanitizes the UTF8 in the spans.
func (s *utf8Sanitizer) Sanitize(span *model.Span) *model.Span {
if !utf8.ValidString(span.OperationName) {
- s.logSpan(span, "Invalid utf8 operation name", zap.String("operation_name", span.OperationName))
- span.Tags = append(span.Tags, model.Binary(invalidOperation, []byte(span.OperationName)))
+ s.logSpan(
+ span,
+ "Invalid utf8 operation name",
+ zap.String("operation_name", span.OperationName),
+ )
+ span.Tags = append(
+ span.Tags,
+ model.Binary(invalidOperation, []byte(span.OperationName)),
+ )
span.OperationName = invalidOperation
}
if !utf8.ValidString(span.Process.ServiceName) {
- s.logSpan(span, "Invalid utf8 service name", zap.String("service_name", span.Process.ServiceName))
- span.Tags = append(span.Tags, model.Binary(invalidService, []byte(span.Process.ServiceName)))
+ s.logSpan(
+ span,
+ "Invalid utf8 service name",
+ zap.String("service_name", span.Process.ServiceName),
+ )
+ span.Tags = append(
+ span.Tags,
+ model.Binary(invalidService, []byte(span.Process.ServiceName)),
+ )
span.Process.ServiceName = invalidService
}
sanitizeKV(span.Process.Tags)
@@ -62,7 +76,11 @@ func (s *utf8Sanitizer) Sanitize(span *model.Span) *model.Span {
return span
}
-func (s *utf8Sanitizer) logSpan(span *model.Span, message string, field zapcore.Field) {
+func (s *utf8Sanitizer) logSpan(
+ span *model.Span,
+ message string,
+ field zapcore.Field,
+) {
s.logger.Info(
message,
zap.String("trace_id", span.TraceID.String()),
@@ -72,7 +90,10 @@ func (s *utf8Sanitizer) logSpan(span *model.Span, message string, field zapcore.
func sanitizeKV(keyValues model.KeyValues) {
for i, kv := range keyValues {
if !utf8.ValidString(kv.Key) {
- keyValues[i] = model.Binary(invalidTagKey, []byte(fmt.Sprintf("%s:%s", kv.Key, kv.AsStringLossy())))
+ keyValues[i] = model.Binary(
+ invalidTagKey,
+ []byte(fmt.Sprintf("%s:%s", kv.Key, kv.AsStringLossy())),
+ )
} else if kv.VType == model.StringType && !utf8.ValidString(kv.VStr) {
keyValues[i] = model.Binary(kv.Key, []byte(kv.VStr))
}
diff --git a/cmd/collector/app/sanitizer/utf8_sanitizer_test.go b/cmd/collector/app/sanitizer/utf8_sanitizer_test.go
index 377e5823954..dbf05b0e159 100644
--- a/cmd/collector/app/sanitizer/utf8_sanitizer_test.go
+++ b/cmd/collector/app/sanitizer/utf8_sanitizer_test.go
@@ -75,7 +75,10 @@ func TestUTF8Sanitizer_SanitizeKV(t *testing.T) {
model.String(invalidUTF8(), invalidUTF8()),
},
expected: model.KeyValues{
- model.Binary(invalidTagKey, []byte(invalidUTF8()+":"+invalidUTF8())),
+ model.Binary(
+ invalidTagKey,
+ []byte(invalidUTF8()+":"+invalidUTF8()),
+ ),
},
},
{
@@ -101,7 +104,11 @@ func TestUTF8Sanitizer_SanitizeServiceName(t *testing.T) {
},
})
assert.Equal(t, invalidService, actual.Process.ServiceName)
- assert.Equal(t, model.Binary(invalidService, []byte(invalidUTF8())), actual.Tags[0])
+ assert.Equal(
+ t,
+ model.Binary(invalidService, []byte(invalidUTF8())),
+ actual.Tags[0],
+ )
}
func TestUTF8Sanitizer_SanitizeOperationName(t *testing.T) {
@@ -110,7 +117,11 @@ func TestUTF8Sanitizer_SanitizeOperationName(t *testing.T) {
Process: &model.Process{},
})
assert.Equal(t, invalidOperation, actual.OperationName)
- assert.Equal(t, model.Binary(invalidOperation, []byte(invalidUTF8())), actual.Tags[0])
+ assert.Equal(
+ t,
+ model.Binary(invalidOperation, []byte(invalidUTF8())),
+ actual.Tags[0],
+ )
}
func TestUTF8Sanitizer_SanitizeProcessTags(t *testing.T) {
diff --git a/cmd/collector/app/sanitizer/zipkin/span_sanitizer.go b/cmd/collector/app/sanitizer/zipkin/span_sanitizer.go
index 82fad02c7d6..5818f0fbdb9 100644
--- a/cmd/collector/app/sanitizer/zipkin/span_sanitizer.go
+++ b/cmd/collector/app/sanitizer/zipkin/span_sanitizer.go
@@ -168,7 +168,8 @@ type errorTagSanitizer struct{}
func (*errorTagSanitizer) Sanitize(span *zc.Span) *zc.Span {
for _, binAnno := range span.BinaryAnnotations {
- if binAnno.AnnotationType != zc.AnnotationType_BOOL && strings.EqualFold("error", binAnno.Key) {
+ if binAnno.AnnotationType != zc.AnnotationType_BOOL &&
+ strings.EqualFold("error", binAnno.Key) {
binAnno.AnnotationType = zc.AnnotationType_BOOL
switch {
@@ -183,7 +184,10 @@ func (*errorTagSanitizer) Sanitize(span *zc.Span) *zc.Span {
Value: binAnno.Value,
AnnotationType: zc.AnnotationType_STRING,
}
- span.BinaryAnnotations = append(span.BinaryAnnotations, annoErrorMsg)
+ span.BinaryAnnotations = append(
+ span.BinaryAnnotations,
+ annoErrorMsg,
+ )
binAnno.Value = []byte{1}
}
}
diff --git a/cmd/collector/app/sanitizer/zipkin/span_sanitizer_test.go b/cmd/collector/app/sanitizer/zipkin/span_sanitizer_test.go
index c9584ab9a9b..278232e8c3c 100644
--- a/cmd/collector/app/sanitizer/zipkin/span_sanitizer_test.go
+++ b/cmd/collector/app/sanitizer/zipkin/span_sanitizer_test.go
@@ -107,7 +107,11 @@ func TestSpanParentIDSanitizer(t *testing.T) {
if test.tag {
if assert.Len(t, actual.BinaryAnnotations, 1) {
assert.Equal(t, "0", string(actual.BinaryAnnotations[0].Value))
- assert.Equal(t, zeroParentIDTag, string(actual.BinaryAnnotations[0].Key))
+ assert.Equal(
+ t,
+ zeroParentIDTag,
+ string(actual.BinaryAnnotations[0].Key),
+ )
}
} else {
assert.Empty(t, actual.BinaryAnnotations)
@@ -126,19 +130,34 @@ func TestSpanErrorSanitizer(t *testing.T) {
}{
// value is string
{
- &zipkincore.BinaryAnnotation{Key: "error", AnnotationType: zipkincore.AnnotationType_STRING},
+ &zipkincore.BinaryAnnotation{
+ Key: "error",
+ AnnotationType: zipkincore.AnnotationType_STRING,
+ },
true, true, false,
},
{
- &zipkincore.BinaryAnnotation{Key: "error", Value: []byte("true"), AnnotationType: zipkincore.AnnotationType_STRING},
+ &zipkincore.BinaryAnnotation{
+ Key: "error",
+ Value: []byte("true"),
+ AnnotationType: zipkincore.AnnotationType_STRING,
+ },
true, true, false,
},
{
- &zipkincore.BinaryAnnotation{Key: "error", Value: []byte("message"), AnnotationType: zipkincore.AnnotationType_STRING},
+ &zipkincore.BinaryAnnotation{
+ Key: "error",
+ Value: []byte("message"),
+ AnnotationType: zipkincore.AnnotationType_STRING,
+ },
true, true, true,
},
{
- &zipkincore.BinaryAnnotation{Key: "error", Value: []byte("false"), AnnotationType: zipkincore.AnnotationType_STRING},
+ &zipkincore.BinaryAnnotation{
+ Key: "error",
+ Value: []byte("false"),
+ AnnotationType: zipkincore.AnnotationType_STRING,
+ },
true, false, false,
},
}
@@ -155,14 +174,35 @@ func TestSpanErrorSanitizer(t *testing.T) {
expectedVal = []byte{1}
}
- assert.Equal(t, expectedVal, sanitized.BinaryAnnotations[0].Value, test.binAnn.Key)
- assert.Equal(t, zipkincore.AnnotationType_BOOL, sanitized.BinaryAnnotations[0].AnnotationType)
+ assert.Equal(
+ t,
+ expectedVal,
+ sanitized.BinaryAnnotations[0].Value,
+ test.binAnn.Key,
+ )
+ assert.Equal(
+ t,
+ zipkincore.AnnotationType_BOOL,
+ sanitized.BinaryAnnotations[0].AnnotationType,
+ )
if test.addErrMsgAnno {
assert.Len(t, sanitized.BinaryAnnotations, 2)
- assert.Equal(t, "error.message", sanitized.BinaryAnnotations[1].Key)
- assert.Equal(t, "message", string(sanitized.BinaryAnnotations[1].Value))
- assert.Equal(t, zipkincore.AnnotationType_STRING, sanitized.BinaryAnnotations[1].AnnotationType)
+ assert.Equal(
+ t,
+ "error.message",
+ sanitized.BinaryAnnotations[1].Key,
+ )
+ assert.Equal(
+ t,
+ "message",
+ string(sanitized.BinaryAnnotations[1].Value),
+ )
+ assert.Equal(
+ t,
+ zipkincore.AnnotationType_STRING,
+ sanitized.BinaryAnnotations[1].AnnotationType,
+ )
} else {
assert.Len(t, sanitized.BinaryAnnotations, 1)
}
diff --git a/cmd/collector/app/server/grpc.go b/cmd/collector/app/server/grpc.go
index bbd8bca4ae3..2c58b391064 100644
--- a/cmd/collector/app/server/grpc.go
+++ b/cmd/collector/app/server/grpc.go
@@ -56,7 +56,10 @@ func StartGRPCServer(params *GRPCServerParams) (*grpc.Server, error) {
var grpcOpts []grpc.ServerOption
if params.MaxReceiveMessageLength > 0 {
- grpcOpts = append(grpcOpts, grpc.MaxRecvMsgSize(params.MaxReceiveMessageLength))
+ grpcOpts = append(
+ grpcOpts,
+ grpc.MaxRecvMsgSize(params.MaxReceiveMessageLength),
+ )
}
grpcOpts = append(grpcOpts, grpc.KeepaliveParams(keepalive.ServerParameters{
MaxConnectionAge: params.MaxConnectionAge,
@@ -90,18 +93,34 @@ func StartGRPCServer(params *GRPCServerParams) (*grpc.Server, error) {
return server, nil
}
-func serveGRPC(server *grpc.Server, listener net.Listener, params *GRPCServerParams) error {
+func serveGRPC(
+ server *grpc.Server,
+ listener net.Listener,
+ params *GRPCServerParams,
+) error {
healthServer := health.NewServer()
api_v2.RegisterCollectorServiceServer(server, params.Handler)
- api_v2.RegisterSamplingManagerServer(server, sampling.NewGRPCHandler(params.SamplingStore))
-
- healthServer.SetServingStatus("jaeger.api_v2.CollectorService", grpc_health_v1.HealthCheckResponse_SERVING)
- healthServer.SetServingStatus("jaeger.api_v2.SamplingManager", grpc_health_v1.HealthCheckResponse_SERVING)
+ api_v2.RegisterSamplingManagerServer(
+ server,
+ sampling.NewGRPCHandler(params.SamplingStore),
+ )
+
+ healthServer.SetServingStatus(
+ "jaeger.api_v2.CollectorService",
+ grpc_health_v1.HealthCheckResponse_SERVING,
+ )
+ healthServer.SetServingStatus(
+ "jaeger.api_v2.SamplingManager",
+ grpc_health_v1.HealthCheckResponse_SERVING,
+ )
grpc_health_v1.RegisterHealthServer(server, healthServer)
- params.Logger.Info("Starting jaeger-collector gRPC server", zap.String("grpc.host-port", params.HostPortActual))
+ params.Logger.Info(
+ "Starting jaeger-collector gRPC server",
+ zap.String("grpc.host-port", params.HostPortActual),
+ )
go func() {
if err := server.Serve(listener); err != nil {
params.Logger.Error("Could not launch gRPC service", zap.Error(err))
diff --git a/cmd/collector/app/server/grpc_test.go b/cmd/collector/app/server/grpc_test.go
index 647445a2b5b..15c397ee588 100644
--- a/cmd/collector/app/server/grpc_test.go
+++ b/cmd/collector/app/server/grpc_test.go
@@ -39,13 +39,21 @@ import (
func TestFailToListen(t *testing.T) {
logger, _ := zap.NewDevelopment()
server, err := StartGRPCServer(&GRPCServerParams{
- HostPort: ":-1",
- Handler: handler.NewGRPCHandler(logger, &mockSpanProcessor{}, &tenancy.Manager{}),
+ HostPort: ":-1",
+ Handler: handler.NewGRPCHandler(
+ logger,
+ &mockSpanProcessor{},
+ &tenancy.Manager{},
+ ),
SamplingStore: &mockSamplingStore{},
Logger: logger,
})
assert.Nil(t, server)
- require.EqualError(t, err, "failed to listen on gRPC port: listen tcp: address -1: invalid port")
+ require.EqualError(
+ t,
+ err,
+ "failed to listen on gRPC port: listen tcp: address -1: invalid port",
+ )
}
func TestFailServe(t *testing.T) {
@@ -59,12 +67,20 @@ func TestFailServe(t *testing.T) {
server := grpc.NewServer()
defer server.Stop()
serveGRPC(server, lis, &GRPCServerParams{
- Handler: handler.NewGRPCHandler(logger, &mockSpanProcessor{}, &tenancy.Manager{}),
+ Handler: handler.NewGRPCHandler(
+ logger,
+ &mockSpanProcessor{},
+ &tenancy.Manager{},
+ ),
SamplingStore: &mockSamplingStore{},
Logger: logger,
OnError: func(e error) {
assert.Len(t, logs.All(), 1)
- assert.Equal(t, "Could not launch gRPC service", logs.All()[0].Message)
+ assert.Equal(
+ t,
+ "Could not launch gRPC service",
+ logs.All()[0].Message,
+ )
wg.Done()
},
})
@@ -74,7 +90,11 @@ func TestFailServe(t *testing.T) {
func TestSpanCollector(t *testing.T) {
logger, _ := zap.NewDevelopment()
params := &GRPCServerParams{
- Handler: handler.NewGRPCHandler(logger, &mockSpanProcessor{}, &tenancy.Manager{}),
+ Handler: handler.NewGRPCHandler(
+ logger,
+ &mockSpanProcessor{},
+ &tenancy.Manager{},
+ ),
SamplingStore: &mockSamplingStore{},
Logger: logger,
MaxReceiveMessageLength: 1024 * 1024,
@@ -91,7 +111,10 @@ func TestSpanCollector(t *testing.T) {
defer conn.Close()
c := api_v2.NewCollectorServiceClient(conn)
- response, err := c.PostSpans(context.Background(), &api_v2.PostSpansRequest{})
+ response, err := c.PostSpans(
+ context.Background(),
+ &api_v2.PostSpansRequest{},
+ )
require.NoError(t, err)
require.NotNil(t, response)
}
@@ -99,7 +122,11 @@ func TestSpanCollector(t *testing.T) {
func TestCollectorStartWithTLS(t *testing.T) {
logger, _ := zap.NewDevelopment()
params := &GRPCServerParams{
- Handler: handler.NewGRPCHandler(logger, &mockSpanProcessor{}, &tenancy.Manager{}),
+ Handler: handler.NewGRPCHandler(
+ logger,
+ &mockSpanProcessor{},
+ &tenancy.Manager{},
+ ),
SamplingStore: &mockSamplingStore{},
Logger: logger,
TLSConfig: tlscfg.Options{
@@ -118,7 +145,11 @@ func TestCollectorStartWithTLS(t *testing.T) {
func TestCollectorReflection(t *testing.T) {
logger, _ := zap.NewDevelopment()
params := &GRPCServerParams{
- Handler: handler.NewGRPCHandler(logger, &mockSpanProcessor{}, &tenancy.Manager{}),
+ Handler: handler.NewGRPCHandler(
+ logger,
+ &mockSpanProcessor{},
+ &tenancy.Manager{},
+ ),
SamplingStore: &mockSamplingStore{},
Logger: logger,
}
diff --git a/cmd/collector/app/server/http.go b/cmd/collector/app/server/http.go
index f903c048f10..aced9aa4f0e 100644
--- a/cmd/collector/app/server/http.go
+++ b/cmd/collector/app/server/http.go
@@ -53,7 +53,10 @@ type HTTPServerParams struct {
// StartHTTPServer based on the given parameters
func StartHTTPServer(params *HTTPServerParams) (*http.Server, error) {
- params.Logger.Info("Starting jaeger-collector HTTP server", zap.String("http host-port", params.HostPort))
+ params.Logger.Info(
+ "Starting jaeger-collector HTTP server",
+ zap.String("http host-port", params.HostPort),
+ )
errorLog, _ := zap.NewStdLogAt(params.Logger, zapcore.ErrorLevel)
server := &http.Server{
@@ -64,7 +67,9 @@ func StartHTTPServer(params *HTTPServerParams) (*http.Server, error) {
ErrorLog: errorLog,
}
if params.TLSConfig.Enabled {
- tlsCfg, err := params.TLSConfig.Config(params.Logger) // This checks if the certificates are correctly provided
+ tlsCfg, err := params.TLSConfig.Config(
+ params.Logger,
+ ) // This checks if the certificates are correctly provided
if err != nil {
return nil, err
}
@@ -81,24 +86,34 @@ func StartHTTPServer(params *HTTPServerParams) (*http.Server, error) {
return server, nil
}
-func serveHTTP(server *http.Server, listener net.Listener, params *HTTPServerParams) {
+func serveHTTP(
+ server *http.Server,
+ listener net.Listener,
+ params *HTTPServerParams,
+) {
r := mux.NewRouter()
apiHandler := handler.NewAPIHandler(params.Handler)
apiHandler.RegisterRoutes(r)
- cfgHandler := clientcfgHandler.NewHTTPHandler(clientcfgHandler.HTTPHandlerParams{
- ConfigManager: &clientcfgHandler.ConfigManager{
- SamplingStrategyStore: params.SamplingStore,
- // TODO provide baggage manager
+ cfgHandler := clientcfgHandler.NewHTTPHandler(
+ clientcfgHandler.HTTPHandlerParams{
+ ConfigManager: &clientcfgHandler.ConfigManager{
+ SamplingStrategyStore: params.SamplingStore,
+ // TODO provide baggage manager
+ },
+ MetricsFactory: params.MetricsFactory,
+ BasePath: "/api",
+ LegacySamplingEndpoint: false,
},
- MetricsFactory: params.MetricsFactory,
- BasePath: "/api",
- LegacySamplingEndpoint: false,
- })
+ )
cfgHandler.RegisterRoutes(r)
recoveryHandler := recoveryhandler.NewRecoveryHandler(params.Logger, true)
- server.Handler = httpmetrics.Wrap(recoveryHandler(r), params.MetricsFactory, params.Logger)
+ server.Handler = httpmetrics.Wrap(
+ recoveryHandler(r),
+ params.MetricsFactory,
+ params.Logger,
+ )
go func() {
var err error
if params.TLSConfig.Enabled {
@@ -108,7 +123,10 @@ func serveHTTP(server *http.Server, listener net.Listener, params *HTTPServerPar
}
if err != nil {
if err != http.ErrServerClosed {
- params.Logger.Error("Could not start HTTP collector", zap.Error(err))
+ params.Logger.Error(
+ "Could not start HTTP collector",
+ zap.Error(err),
+ )
}
}
params.HealthCheck.Set(healthcheck.Unavailable)
diff --git a/cmd/collector/app/server/http_test.go b/cmd/collector/app/server/http_test.go
index 20a71289fde..39e9956823d 100644
--- a/cmd/collector/app/server/http_test.go
+++ b/cmd/collector/app/server/http_test.go
@@ -72,7 +72,10 @@ func TestSpanCollectorHTTP(t *testing.T) {
defer mFact.Backend.Stop()
logger, _ := zap.NewDevelopment()
params := &HTTPServerParams{
- Handler: handler.NewJaegerSpanHandler(logger, &mockSpanProcessor{}),
+ Handler: handler.NewJaegerSpanHandler(
+ logger,
+ &mockSpanProcessor{},
+ ),
SamplingStore: &mockSamplingStore{},
MetricsFactory: mFact,
HealthCheck: healthcheck.New(),
@@ -198,8 +201,11 @@ func TestSpanCollectorHTTPS(t *testing.T) {
mFact := metricstest.NewFactory(time.Hour)
defer mFact.Backend.Stop()
params := &HTTPServerParams{
- HostPort: fmt.Sprintf(":%d", ports.CollectorHTTP),
- Handler: handler.NewJaegerSpanHandler(logger, &mockSpanProcessor{}),
+ HostPort: fmt.Sprintf(":%d", ports.CollectorHTTP),
+ Handler: handler.NewJaegerSpanHandler(
+ logger,
+ &mockSpanProcessor{},
+ ),
SamplingStore: &mockSamplingStore{},
MetricsFactory: mFact,
HealthCheck: healthcheck.New(),
@@ -218,7 +224,12 @@ 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:"+fmt.Sprintf("%d", ports.CollectorHTTP),
+ clientTLSCfg,
+ )
var clientClose func() error
clientClose = nil
if conn != nil {
@@ -241,7 +252,11 @@ func TestSpanCollectorHTTPS(t *testing.T) {
},
}
- response, requestError := client.Post("https://localhost:"+fmt.Sprintf("%d", ports.CollectorHTTP), "", nil)
+ response, requestError := client.Post(
+ "https://localhost:"+fmt.Sprintf("%d", ports.CollectorHTTP),
+ "",
+ nil,
+ )
if test.expectClientError {
require.Error(t, requestError)
@@ -260,8 +275,11 @@ func TestStartHTTPServerParams(t *testing.T) {
mFact := metricstest.NewFactory(time.Hour)
defer mFact.Stop()
params := &HTTPServerParams{
- HostPort: fmt.Sprintf(":%d", ports.CollectorHTTP),
- Handler: handler.NewJaegerSpanHandler(logger, &mockSpanProcessor{}),
+ HostPort: fmt.Sprintf(":%d", ports.CollectorHTTP),
+ Handler: handler.NewJaegerSpanHandler(
+ logger,
+ &mockSpanProcessor{},
+ ),
SamplingStore: &mockSamplingStore{},
MetricsFactory: mFact,
HealthCheck: healthcheck.New(),
diff --git a/cmd/collector/app/server/test.go b/cmd/collector/app/server/test.go
index 38667d9f034..68cdd9466b5 100644
--- a/cmd/collector/app/server/test.go
+++ b/cmd/collector/app/server/test.go
@@ -24,7 +24,10 @@ import (
type mockSamplingStore struct{}
-func (mockSamplingStore) GetSamplingStrategy(_ context.Context, serviceName string) (*api_v2.SamplingStrategyResponse, error) {
+func (mockSamplingStore) GetSamplingStrategy(
+ _ context.Context,
+ serviceName string,
+) (*api_v2.SamplingStrategyResponse, error) {
return nil, nil
}
@@ -38,6 +41,9 @@ func (*mockSpanProcessor) Close() error {
return nil
}
-func (*mockSpanProcessor) ProcessSpans(spans []*model.Span, _ processor.SpansOptions) ([]bool, error) {
+func (*mockSpanProcessor) ProcessSpans(
+ spans []*model.Span,
+ _ processor.SpansOptions,
+) ([]bool, error) {
return []bool{}, nil
}
diff --git a/cmd/collector/app/span_handler_builder.go b/cmd/collector/app/span_handler_builder.go
index 6f87ab97327..f4824146584 100644
--- a/cmd/collector/app/span_handler_builder.go
+++ b/cmd/collector/app/span_handler_builder.go
@@ -47,10 +47,14 @@ type SpanHandlers struct {
}
// BuildSpanProcessor builds the span processor to be used with the handlers
-func (b *SpanHandlerBuilder) BuildSpanProcessor(additional ...ProcessSpan) processor.SpanProcessor {
+func (b *SpanHandlerBuilder) BuildSpanProcessor(
+ additional ...ProcessSpan,
+) processor.SpanProcessor {
hostname, _ := os.Hostname()
svcMetrics := b.metricsFactory()
- hostMetrics := svcMetrics.Namespace(metrics.NSOptions{Tags: map[string]string{"host": hostname}})
+ hostMetrics := svcMetrics.Namespace(
+ metrics.NSOptions{Tags: map[string]string{"host": hostname}},
+ )
return NewSpanProcessor(
b.SpanWriter,
@@ -62,14 +66,18 @@ func (b *SpanHandlerBuilder) BuildSpanProcessor(additional ...ProcessSpan) proce
Options.NumWorkers(b.CollectorOpts.NumWorkers),
Options.QueueSize(b.CollectorOpts.QueueSize),
Options.CollectorTags(b.CollectorOpts.CollectorTags),
- Options.DynQueueSizeWarmup(uint(b.CollectorOpts.QueueSize)), // same as queue size for now
+ Options.DynQueueSizeWarmup(
+ uint(b.CollectorOpts.QueueSize),
+ ), // same as queue size for now
Options.DynQueueSizeMemory(b.CollectorOpts.DynQueueSizeMemory),
Options.SpanSizeMetricsEnabled(b.CollectorOpts.SpanSizeMetricsEnabled),
)
}
// BuildHandlers builds span handlers (Zipkin, Jaeger)
-func (b *SpanHandlerBuilder) BuildHandlers(spanProcessor processor.SpanProcessor) *SpanHandlers {
+func (b *SpanHandlerBuilder) BuildHandlers(
+ spanProcessor processor.SpanProcessor,
+) *SpanHandlers {
return &SpanHandlers{
handler.NewZipkinSpanHandler(
b.Logger,
diff --git a/cmd/collector/app/span_processor.go b/cmd/collector/app/span_processor.go
index 03d9ae460dd..e3472e010a4 100644
--- a/cmd/collector/app/span_processor.go
+++ b/cmd/collector/app/span_processor.go
@@ -87,7 +87,11 @@ func NewSpanProcessor(
return sp
}
-func newSpanProcessor(spanWriter spanstore.Writer, additional []ProcessSpan, opts ...Option) *spanProcessor {
+func newSpanProcessor(
+ spanWriter spanstore.Writer,
+ additional []ProcessSpan,
+ opts ...Option,
+) *spanProcessor {
options := Options.apply(opts...)
handlerMetrics := NewSpanProcessorMetrics(
options.serviceMetrics,
@@ -174,7 +178,10 @@ func (sp *spanProcessor) countSpan(span *model.Span, tenant string) {
sp.spansProcessed.Add(1)
}
-func (sp *spanProcessor) ProcessSpans(mSpans []*model.Span, options processor.SpansOptions) ([]bool, error) {
+func (sp *spanProcessor) ProcessSpans(
+ mSpans []*model.Span,
+ options processor.SpansOptions,
+) ([]bool, error) {
sp.preProcessSpans(mSpans, options.Tenant)
sp.metrics.BatchSize.Update(int64(len(mSpans)))
retMe := make([]bool, len(mSpans))
@@ -189,7 +196,12 @@ func (sp *spanProcessor) ProcessSpans(mSpans []*model.Span, options processor.Sp
}
for i, mSpan := range mSpans {
- ok := sp.enqueueSpan(mSpan, options.SpanFormat, options.InboundTransport, options.Tenant)
+ ok := sp.enqueueSpan(
+ mSpan,
+ options.SpanFormat,
+ options.InboundTransport,
+ options.Tenant,
+ )
if !ok && sp.reportBusy {
return nil, processor.ErrBusy
}
@@ -209,8 +221,13 @@ func (sp *spanProcessor) addCollectorTags(span *model.Span) {
}
dedupKey := make(map[string]struct{})
for _, tag := range span.Process.Tags {
- if value, ok := sp.collectorTags[tag.Key]; ok && value == tag.AsString() {
- sp.logger.Debug("ignore collector process tags", zap.String("key", tag.Key), zap.String("value", value))
+ if value, ok := sp.collectorTags[tag.Key]; ok &&
+ value == tag.AsString() {
+ sp.logger.Debug(
+ "ignore collector process tags",
+ zap.String("key", tag.Key),
+ zap.String("value", value),
+ )
dedupKey[tag.Key] = struct{}{}
}
}
@@ -226,7 +243,12 @@ func (sp *spanProcessor) addCollectorTags(span *model.Span) {
// Note: spans may share the Process object, so no changes should be made to Process
// in this function as it may cause race conditions.
-func (sp *spanProcessor) enqueueSpan(span *model.Span, originalFormat processor.SpanFormat, transport processor.InboundTransport, tenant string) bool {
+func (sp *spanProcessor) enqueueSpan(
+ span *model.Span,
+ originalFormat processor.SpanFormat,
+ transport processor.InboundTransport,
+ tenant string,
+) bool {
spanCounts := sp.metrics.GetCountsForFormat(originalFormat, transport)
spanCounts.ReceivedBySvc.ReportServiceNameForSpan(span)
@@ -236,7 +258,10 @@ func (sp *spanProcessor) enqueueSpan(span *model.Span, originalFormat processor.
}
// add format tag
- span.Tags = append(span.Tags, model.String("internal.span.format", string(originalFormat)))
+ span.Tags = append(
+ span.Tags,
+ model.String("internal.span.format", string(originalFormat)),
+ )
item := &queueItem{
queuedTime: time.Now(),
@@ -246,7 +271,10 @@ func (sp *spanProcessor) enqueueSpan(span *model.Span, originalFormat processor.
return sp.queue.Produce(item)
}
-func (sp *spanProcessor) background(reportPeriod time.Duration, callback func()) {
+func (sp *spanProcessor) background(
+ reportPeriod time.Duration,
+ callback func(),
+) {
go func() {
ticker := time.NewTicker(reportPeriod)
defer ticker.Stop()
@@ -299,7 +327,11 @@ func (sp *spanProcessor) updateQueueSize() {
// resizing is a costly operation, we only perform it if we are at least n% apart from the desired value
if diff > minRequiredChange {
s := int(idealQueueSize)
- sp.logger.Info("Resizing the internal span queue", zap.Int("new-size", s), zap.Uint64("average-span-size-bytes", average))
+ sp.logger.Info(
+ "Resizing the internal span queue",
+ zap.Int("new-size", s),
+ zap.Uint64("average-span-size-bytes", average),
+ )
sp.queue.Resize(s)
}
}
diff --git a/cmd/collector/app/span_processor_test.go b/cmd/collector/app/span_processor_test.go
index ed1b6bde619..0e2178af620 100644
--- a/cmd/collector/app/span_processor_test.go
+++ b/cmd/collector/app/span_processor_test.go
@@ -58,7 +58,10 @@ func TestBySvcMetrics(t *testing.T) {
debug bool
}
- spanFormat := [2]processor.SpanFormat{processor.ZipkinSpanFormat, processor.JaegerSpanFormat}
+ spanFormat := [2]processor.SpanFormat{
+ processor.ZipkinSpanFormat,
+ processor.JaegerSpanFormat,
+ }
serviceNames := [2]string{allowedService, blackListedService}
rootSpanEnabled := [2]bool{true, false}
debugEnabled := [2]bool{true, false}
@@ -85,7 +88,9 @@ func TestBySvcMetrics(t *testing.T) {
mb := metricstest.NewFactory(time.Hour)
defer mb.Backend.Stop()
logger := zap.NewNop()
- serviceMetrics := mb.Namespace(metrics.NSOptions{Name: "service", Tags: nil})
+ serviceMetrics := mb.Namespace(
+ metrics.NSOptions{Name: "service", Tags: nil},
+ )
hostMetrics := mb.Namespace(metrics.NSOptions{Name: "host", Tags: nil})
sp := newSpanProcessor(
&fakeSpanWriter{},
@@ -102,13 +107,21 @@ func TestBySvcMetrics(t *testing.T) {
switch test.format {
case processor.ZipkinSpanFormat:
span := makeZipkinSpan(test.serviceName, test.rootSpan, test.debug)
- sanitizer := zipkinsanitizer.NewChainedSanitizer(zipkinsanitizer.NewStandardSanitizers()...)
+ sanitizer := zipkinsanitizer.NewChainedSanitizer(
+ zipkinsanitizer.NewStandardSanitizers()...)
zHandler := handler.NewZipkinSpanHandler(logger, sp, sanitizer)
- zHandler.SubmitZipkinBatch([]*zc.Span{span, span}, handler.SubmitBatchOptions{})
+ zHandler.SubmitZipkinBatch(
+ []*zc.Span{span, span},
+ handler.SubmitBatchOptions{},
+ )
metricPrefix = "service"
format = "zipkin"
case processor.JaegerSpanFormat:
- span, process := makeJaegerSpan(test.serviceName, test.rootSpan, test.debug)
+ span, process := makeJaegerSpan(
+ test.serviceName,
+ test.rootSpan,
+ test.debug,
+ )
jHandler := handler.NewJaegerSpanHandler(logger, sp)
jHandler.SubmitBatches([]*jaeger.Batch{
{
@@ -182,7 +195,10 @@ type fakeSpanWriter struct {
tenants map[string]bool
}
-func (n *fakeSpanWriter) WriteSpan(ctx context.Context, span *model.Span) error {
+func (n *fakeSpanWriter) WriteSpan(
+ ctx context.Context,
+ span *model.Span,
+) error {
n.spansLock.Lock()
defer n.spansLock.Unlock()
n.spans = append(n.spans, span)
@@ -224,7 +240,11 @@ func makeZipkinSpan(service string, rootSpan bool, debugEnabled bool) *zc.Span {
return span
}
-func makeJaegerSpan(service string, rootSpan bool, debugEnabled bool) (*jaeger.Span, *jaeger.Process) {
+func makeJaegerSpan(
+ service string,
+ rootSpan bool,
+ debugEnabled bool,
+) (*jaeger.Span, *jaeger.Process) {
flags := int32(0)
if debugEnabled {
flags = 2
@@ -265,7 +285,9 @@ func TestSpanProcessorErrors(t *testing.T) {
}
mb := metricstest.NewFactory(time.Hour)
defer mb.Backend.Stop()
- serviceMetrics := mb.Namespace(metrics.NSOptions{Name: "service", Tags: nil})
+ serviceMetrics := mb.Namespace(
+ metrics.NSOptions{Name: "service", Tags: nil},
+ )
p := NewSpanProcessor(w,
nil,
Options.Logger(logger),
@@ -302,7 +324,10 @@ type blockingWriter struct {
inWriteSpan atomic.Int32
}
-func (w *blockingWriter) WriteSpan(ctx context.Context, span *model.Span) error {
+func (w *blockingWriter) WriteSpan(
+ ctx context.Context,
+ span *model.Span,
+) error {
w.inWriteSpan.Add(1)
w.Lock()
defer w.Unlock()
@@ -350,7 +375,9 @@ func TestSpanProcessorBusy(t *testing.T) {
func TestSpanProcessorWithNilProcess(t *testing.T) {
mb := metricstest.NewFactory(time.Hour)
defer mb.Backend.Stop()
- serviceMetrics := mb.Namespace(metrics.NSOptions{Name: "service", Tags: nil})
+ serviceMetrics := mb.Namespace(
+ metrics.NSOptions{Name: "service", Tags: nil},
+ )
w := &fakeSpanWriter{}
p := NewSpanProcessor(w, nil, Options.ServiceMetrics(serviceMetrics)).(*spanProcessor)
@@ -483,14 +510,21 @@ func TestSpanProcessorCountSpan(t *testing.T) {
if !tt.expectedUpdateGauge {
assert.Fail(t, "gauge has been updated unexpectedly")
}
- assert.Equal(t, p.bytesProcessed.Load(), uint64(g["spans.bytes"]))
+ assert.Equal(
+ t,
+ p.bytesProcessed.Load(),
+ uint64(g["spans.bytes"]),
+ )
return
}
time.Sleep(time.Millisecond)
}
if tt.expectedUpdateGauge {
- assert.Fail(t, "gauge hasn't been updated within a reasonable amount of time")
+ assert.Fail(
+ t,
+ "gauge hasn't been updated within a reasonable amount of time",
+ )
}
})
}
@@ -574,7 +608,13 @@ func TestUpdateDynQueueSize(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
w := &fakeSpanWriter{}
- p := newSpanProcessor(w, nil, Options.QueueSize(tt.initialCapacity), Options.DynQueueSizeWarmup(tt.warmup), Options.DynQueueSizeMemory(tt.sizeInBytes))
+ p := newSpanProcessor(
+ w,
+ nil,
+ Options.QueueSize(tt.initialCapacity),
+ Options.DynQueueSizeWarmup(tt.warmup),
+ Options.DynQueueSizeMemory(tt.sizeInBytes),
+ )
assert.EqualValues(t, tt.initialCapacity, p.queue.Capacity())
p.spansProcessed.Store(tt.spansProcessed)
@@ -588,18 +628,32 @@ func TestUpdateDynQueueSize(t *testing.T) {
func TestUpdateQueueSizeNoActivityYet(t *testing.T) {
w := &fakeSpanWriter{}
- p := newSpanProcessor(w, nil, Options.QueueSize(1), Options.DynQueueSizeWarmup(1), Options.DynQueueSizeMemory(1))
+ p := newSpanProcessor(
+ w,
+ nil,
+ Options.QueueSize(1),
+ Options.DynQueueSizeWarmup(1),
+ Options.DynQueueSizeMemory(1),
+ )
assert.NotPanics(t, p.updateQueueSize)
}
func TestStartDynQueueSizeUpdater(t *testing.T) {
w := &fakeSpanWriter{}
oneGiB := uint(1024 * 1024 * 1024)
- p := newSpanProcessor(w, nil, Options.QueueSize(100), Options.DynQueueSizeWarmup(1000), Options.DynQueueSizeMemory(oneGiB))
+ p := newSpanProcessor(
+ w,
+ nil,
+ Options.QueueSize(100),
+ Options.DynQueueSizeWarmup(1000),
+ Options.DynQueueSizeMemory(oneGiB),
+ )
assert.EqualValues(t, 100, p.queue.Capacity())
p.spansProcessed.Store(1000)
- p.bytesProcessed.Store(10 * 1024 * p.spansProcessed.Load()) // 10KiB per span
+ p.bytesProcessed.Store(
+ 10 * 1024 * p.spansProcessed.Load(),
+ ) // 10KiB per span
// 1024 ^ 3 / (10 * 1024) = 104857,6
// ideal queue size = 104857
@@ -674,7 +728,10 @@ func TestSpanProcessorContextPropagation(t *testing.T) {
// Verify that the dummy tenant from SpansOptions context made it to writer
assert.True(t, w.tenants[dummyTenant])
// Verify no other tenantKey context values made it to writer
- assert.True(t, reflect.DeepEqual(w.tenants, map[string]bool{dummyTenant: true}))
+ assert.True(
+ t,
+ reflect.DeepEqual(w.tenants, map[string]bool{dummyTenant: true}),
+ )
}
func TestSpanProcessorWithOnDroppedSpanOption(t *testing.T) {
diff --git a/cmd/collector/main.go b/cmd/collector/main.go
index 9bed4c3bf77..771da6d8f8f 100644
--- a/cmd/collector/main.go
+++ b/cmd/collector/main.go
@@ -47,13 +47,18 @@ const serviceName = "jaeger-collector"
func main() {
svc := cmdFlags.NewService(ports.CollectorAdminHTTP)
- storageFactory, err := storage.NewFactory(storage.FactoryConfigFromEnvAndCLI(os.Args, os.Stderr))
+ storageFactory, err := storage.NewFactory(
+ storage.FactoryConfigFromEnvAndCLI(os.Args, os.Stderr),
+ )
if err != nil {
log.Fatalf("Cannot initialize storage factory: %v", err)
}
strategyStoreFactoryConfig, err := ss.FactoryConfigFromEnv()
if err != nil {
- log.Fatalf("Cannot initialize sampling strategy store factory config: %v", err)
+ log.Fatalf(
+ "Cannot initialize sampling strategy store factory config: %v",
+ err,
+ )
}
strategyStoreFactory, err := ss.NewFactory(*strategyStoreFactoryConfig)
if err != nil {
@@ -70,8 +75,12 @@ func main() {
return err
}
logger := svc.Logger // shortcut
- baseFactory := svc.MetricsFactory.Namespace(metrics.NSOptions{Name: "jaeger"})
- metricsFactory := baseFactory.Namespace(metrics.NSOptions{Name: "collector"})
+ baseFactory := svc.MetricsFactory.Namespace(
+ metrics.NSOptions{Name: "jaeger"},
+ )
+ metricsFactory := baseFactory.Namespace(
+ metrics.NSOptions{Name: "collector"},
+ )
version.NewInfoMetrics(metricsFactory)
storageFactory.InitFromViper(v, logger)
@@ -85,18 +94,29 @@ func main() {
ssFactory, err := storageFactory.CreateSamplingStoreFactory()
if err != nil {
- logger.Fatal("Failed to create sampling store factory", zap.Error(err))
+ logger.Fatal(
+ "Failed to create sampling store factory",
+ zap.Error(err),
+ )
}
strategyStoreFactory.InitFromViper(v, logger)
if err := strategyStoreFactory.Initialize(metricsFactory, ssFactory, logger); err != nil {
- logger.Fatal("Failed to init sampling strategy store factory", zap.Error(err))
+ logger.Fatal(
+ "Failed to init sampling strategy store factory",
+ zap.Error(err),
+ )
}
strategyStore, aggregator, err := strategyStoreFactory.CreateStrategyStore()
if err != nil {
- logger.Fatal("Failed to create sampling strategy store", zap.Error(err))
+ logger.Fatal(
+ "Failed to create sampling strategy store",
+ zap.Error(err),
+ )
}
- collectorOpts, err := new(flags.CollectorOptions).InitFromViper(v, logger)
+ collectorOpts, err := new(
+ flags.CollectorOptions,
+ ).InitFromViper(v, logger)
if err != nil {
logger.Fatal("Failed to initialize collector", zap.Error(err))
}
@@ -119,19 +139,31 @@ func main() {
// Wait for shutdown
svc.RunAndThen(func() {
if err := collector.Close(); err != nil {
- logger.Error("failed to cleanly close the collector", zap.Error(err))
+ logger.Error(
+ "failed to cleanly close the collector",
+ zap.Error(err),
+ )
}
if closer, ok := spanWriter.(io.Closer); ok {
err := closer.Close()
if err != nil {
- logger.Error("failed to close span writer", zap.Error(err))
+ logger.Error(
+ "failed to close span writer",
+ zap.Error(err),
+ )
}
}
if err := storageFactory.Close(); err != nil {
- logger.Error("Failed to close storage factory", zap.Error(err))
+ logger.Error(
+ "Failed to close storage factory",
+ zap.Error(err),
+ )
}
if err := strategyStoreFactory.Close(); err != nil {
- logger.Error("Failed to close sampling strategy store factory", zap.Error(err))
+ logger.Error(
+ "Failed to close sampling strategy store factory",
+ zap.Error(err),
+ )
}
})
return nil
diff --git a/cmd/es-index-cleaner/app/flags.go b/cmd/es-index-cleaner/app/flags.go
index a3a344b8099..08b2036a3f3 100644
--- a/cmd/es-index-cleaner/app/flags.go
+++ b/cmd/es-index-cleaner/app/flags.go
@@ -45,9 +45,17 @@ type Config struct {
// AddFlags adds flags for TLS to the FlagSet.
func (*Config) AddFlags(flags *flag.FlagSet) {
flags.String(indexPrefix, "", "Index prefix")
- flags.Bool(archive, false, "Whether to remove archive indices. It works only for rollover")
+ flags.Bool(
+ archive,
+ false,
+ "Whether to remove archive indices. It works only for rollover",
+ )
flags.Bool(rollover, false, "Whether to remove indices created by rollover")
- flags.Int(timeout, 120, "Number of seconds to wait for master node response")
+ flags.Int(
+ timeout,
+ 120,
+ "Number of seconds to wait for master node response",
+ )
flags.String(indexDateSeparator, "-", "Index date separator")
flags.String(username, "", "The username required by storage")
flags.String(password, "", "The password required by storage")
diff --git a/cmd/es-index-cleaner/app/index_filter.go b/cmd/es-index-cleaner/app/index_filter.go
index 60c28970b64..20476fd4439 100644
--- a/cmd/es-index-cleaner/app/index_filter.go
+++ b/cmd/es-index-cleaner/app/index_filter.go
@@ -48,11 +48,25 @@ func (i *IndexFilter) filter(indices []client.Index) []client.Index {
switch {
case i.Archive:
// archive works only for rollover
- reg, _ = regexp.Compile(fmt.Sprintf("^%sjaeger-span-archive-\\d{6}", i.IndexPrefix))
+ reg, _ = regexp.Compile(
+ fmt.Sprintf("^%sjaeger-span-archive-\\d{6}", i.IndexPrefix),
+ )
case i.Rollover:
- reg, _ = regexp.Compile(fmt.Sprintf("^%sjaeger-(span|service|dependencies|sampling)-\\d{6}", i.IndexPrefix))
+ reg, _ = regexp.Compile(
+ fmt.Sprintf(
+ "^%sjaeger-(span|service|dependencies|sampling)-\\d{6}",
+ i.IndexPrefix,
+ ),
+ )
default:
- reg, _ = regexp.Compile(fmt.Sprintf("^%sjaeger-(span|service|dependencies|sampling)-\\d{4}%s\\d{2}%s\\d{2}", i.IndexPrefix, i.IndexDateSeparator, i.IndexDateSeparator))
+ reg, _ = regexp.Compile(
+ fmt.Sprintf(
+ "^%sjaeger-(span|service|dependencies|sampling)-\\d{4}%s\\d{2}%s\\d{2}",
+ i.IndexPrefix,
+ i.IndexDateSeparator,
+ i.IndexDateSeparator,
+ ),
+ )
}
var filtered []client.Index
diff --git a/cmd/es-index-cleaner/app/index_filter_test.go b/cmd/es-index-cleaner/app/index_filter_test.go
index 6a72970c359..9531dc811e8 100644
--- a/cmd/es-index-cleaner/app/index_filter_test.go
+++ b/cmd/es-index-cleaner/app/index_filter_test.go
@@ -32,124 +32,305 @@ func TestIndexFilter_prefix(t *testing.T) {
}
func testIndexFilter(t *testing.T, prefix string) {
- time20200807 := time.Date(2020, time.August, 0o6, 0, 0, 0, 0, time.UTC).AddDate(0, 0, 1)
+ time20200807 := time.Date(2020, time.August, 0o6, 0, 0, 0, 0, time.UTC).
+ AddDate(0, 0, 1)
indices := []client.Index{
{
- Index: prefix + "jaeger-span-2020-08-06",
- CreationTime: time.Date(2020, time.August, 0o6, 15, 0, 0, 0, time.UTC),
- Aliases: map[string]bool{},
+ Index: prefix + "jaeger-span-2020-08-06",
+ CreationTime: time.Date(
+ 2020,
+ time.August,
+ 0o6,
+ 15,
+ 0,
+ 0,
+ 0,
+ time.UTC,
+ ),
+ Aliases: map[string]bool{},
},
{
- Index: prefix + "jaeger-span-2020-08-05",
- CreationTime: time.Date(2020, time.August, 0o5, 15, 0, 0, 0, time.UTC),
- Aliases: map[string]bool{},
+ Index: prefix + "jaeger-span-2020-08-05",
+ CreationTime: time.Date(
+ 2020,
+ time.August,
+ 0o5,
+ 15,
+ 0,
+ 0,
+ 0,
+ time.UTC,
+ ),
+ Aliases: map[string]bool{},
},
{
- Index: prefix + "jaeger-service-2020-08-06",
- CreationTime: time.Date(2020, time.August, 0o6, 15, 0, 0, 0, time.UTC),
- Aliases: map[string]bool{},
+ Index: prefix + "jaeger-service-2020-08-06",
+ CreationTime: time.Date(
+ 2020,
+ time.August,
+ 0o6,
+ 15,
+ 0,
+ 0,
+ 0,
+ time.UTC,
+ ),
+ Aliases: map[string]bool{},
},
{
- Index: prefix + "jaeger-service-2020-08-05",
- CreationTime: time.Date(2020, time.August, 0o5, 15, 0, 0, 0, time.UTC),
- Aliases: map[string]bool{},
+ Index: prefix + "jaeger-service-2020-08-05",
+ CreationTime: time.Date(
+ 2020,
+ time.August,
+ 0o5,
+ 15,
+ 0,
+ 0,
+ 0,
+ time.UTC,
+ ),
+ Aliases: map[string]bool{},
},
{
- Index: prefix + "jaeger-dependencies-2020-08-06",
- CreationTime: time.Date(2020, time.August, 0o6, 15, 0, 0, 0, time.UTC),
- Aliases: map[string]bool{},
+ Index: prefix + "jaeger-dependencies-2020-08-06",
+ CreationTime: time.Date(
+ 2020,
+ time.August,
+ 0o6,
+ 15,
+ 0,
+ 0,
+ 0,
+ time.UTC,
+ ),
+ Aliases: map[string]bool{},
},
{
- Index: prefix + "jaeger-dependencies-2020-08-05",
- CreationTime: time.Date(2020, time.August, 0o5, 15, 0, 0, 0, time.UTC),
- Aliases: map[string]bool{},
+ Index: prefix + "jaeger-dependencies-2020-08-05",
+ CreationTime: time.Date(
+ 2020,
+ time.August,
+ 0o5,
+ 15,
+ 0,
+ 0,
+ 0,
+ time.UTC,
+ ),
+ Aliases: map[string]bool{},
},
{
- Index: prefix + "jaeger-sampling-2020-08-06",
- CreationTime: time.Date(2020, time.August, 0o6, 15, 0, 0, 0, time.UTC),
- Aliases: map[string]bool{},
+ Index: prefix + "jaeger-sampling-2020-08-06",
+ CreationTime: time.Date(
+ 2020,
+ time.August,
+ 0o6,
+ 15,
+ 0,
+ 0,
+ 0,
+ time.UTC,
+ ),
+ Aliases: map[string]bool{},
},
{
- Index: prefix + "jaeger-sampling-2020-08-05",
- CreationTime: time.Date(2020, time.August, 0o5, 15, 0, 0, 0, time.UTC),
- Aliases: map[string]bool{},
+ Index: prefix + "jaeger-sampling-2020-08-05",
+ CreationTime: time.Date(
+ 2020,
+ time.August,
+ 0o5,
+ 15,
+ 0,
+ 0,
+ 0,
+ time.UTC,
+ ),
+ Aliases: map[string]bool{},
},
{
- Index: prefix + "jaeger-span-archive",
- CreationTime: time.Date(2020, time.August, 0, 15, 0, 0, 0, time.UTC),
- Aliases: map[string]bool{},
+ Index: prefix + "jaeger-span-archive",
+ CreationTime: time.Date(
+ 2020,
+ time.August,
+ 0,
+ 15,
+ 0,
+ 0,
+ 0,
+ time.UTC,
+ ),
+ Aliases: map[string]bool{},
},
{
- Index: prefix + "jaeger-span-000001",
- CreationTime: time.Date(2020, time.August, 0o5, 15, 0, 0, 0, time.UTC),
+ Index: prefix + "jaeger-span-000001",
+ CreationTime: time.Date(
+ 2020,
+ time.August,
+ 0o5,
+ 15,
+ 0,
+ 0,
+ 0,
+ time.UTC,
+ ),
Aliases: map[string]bool{
prefix + "jaeger-span-read": true,
},
},
{
- Index: prefix + "jaeger-span-000002",
- CreationTime: time.Date(2020, time.August, 0o6, 15, 0, 0, 0, time.UTC),
+ Index: prefix + "jaeger-span-000002",
+ CreationTime: time.Date(
+ 2020,
+ time.August,
+ 0o6,
+ 15,
+ 0,
+ 0,
+ 0,
+ time.UTC,
+ ),
Aliases: map[string]bool{
prefix + "jaeger-span-read": true,
prefix + "jaeger-span-write": true,
},
},
{
- Index: prefix + "jaeger-service-000001",
- CreationTime: time.Date(2020, time.August, 0o5, 15, 0, 0, 0, time.UTC),
+ Index: prefix + "jaeger-service-000001",
+ CreationTime: time.Date(
+ 2020,
+ time.August,
+ 0o5,
+ 15,
+ 0,
+ 0,
+ 0,
+ time.UTC,
+ ),
Aliases: map[string]bool{
prefix + "jaeger-service-read": true,
},
},
{
- Index: prefix + "jaeger-service-000002",
- CreationTime: time.Date(2020, time.August, 0o6, 15, 0, 0, 0, time.UTC),
+ Index: prefix + "jaeger-service-000002",
+ CreationTime: time.Date(
+ 2020,
+ time.August,
+ 0o6,
+ 15,
+ 0,
+ 0,
+ 0,
+ time.UTC,
+ ),
Aliases: map[string]bool{
prefix + "jaeger-service-read": true,
prefix + "jaeger-service-write": true,
},
},
{
- Index: prefix + "jaeger-span-archive-000001",
- CreationTime: time.Date(2020, time.August, 0o5, 15, 0, 0, 0, time.UTC),
+ Index: prefix + "jaeger-span-archive-000001",
+ CreationTime: time.Date(
+ 2020,
+ time.August,
+ 0o5,
+ 15,
+ 0,
+ 0,
+ 0,
+ time.UTC,
+ ),
Aliases: map[string]bool{
prefix + "jaeger-span-archive-read": true,
},
},
{
- Index: prefix + "jaeger-span-archive-000002",
- CreationTime: time.Date(2020, time.August, 0o6, 15, 0, 0, 0, time.UTC),
+ Index: prefix + "jaeger-span-archive-000002",
+ CreationTime: time.Date(
+ 2020,
+ time.August,
+ 0o6,
+ 15,
+ 0,
+ 0,
+ 0,
+ time.UTC,
+ ),
Aliases: map[string]bool{
prefix + "jaeger-span-archive-read": true,
prefix + "jaeger-span-archive-write": true,
},
},
{
- Index: "other-jaeger-span-2020-08-05",
- CreationTime: time.Date(2020, time.August, 0o5, 15, 0, 0, 0, time.UTC),
- Aliases: map[string]bool{},
+ Index: "other-jaeger-span-2020-08-05",
+ CreationTime: time.Date(
+ 2020,
+ time.August,
+ 0o5,
+ 15,
+ 0,
+ 0,
+ 0,
+ time.UTC,
+ ),
+ Aliases: map[string]bool{},
},
{
- Index: "other-jaeger-service-2020-08-06",
- CreationTime: time.Date(2020, time.August, 0o6, 15, 0, 0, 0, time.UTC),
- Aliases: map[string]bool{},
+ Index: "other-jaeger-service-2020-08-06",
+ CreationTime: time.Date(
+ 2020,
+ time.August,
+ 0o6,
+ 15,
+ 0,
+ 0,
+ 0,
+ time.UTC,
+ ),
+ Aliases: map[string]bool{},
},
{
- Index: "other-bar-jaeger-span-000002",
- CreationTime: time.Date(2020, time.August, 0o5, 15, 0, 0, 0, time.UTC),
+ Index: "other-bar-jaeger-span-000002",
+ CreationTime: time.Date(
+ 2020,
+ time.August,
+ 0o5,
+ 15,
+ 0,
+ 0,
+ 0,
+ time.UTC,
+ ),
Aliases: map[string]bool{
"other-jaeger-span-read": true,
"other-jaeger-span-write": true,
},
},
{
- Index: "otherfoo-jaeger-span-archive",
- CreationTime: time.Date(2020, time.August, 0, 15, 0, 0, 0, time.UTC),
- Aliases: map[string]bool{},
+ Index: "otherfoo-jaeger-span-archive",
+ CreationTime: time.Date(
+ 2020,
+ time.August,
+ 0,
+ 15,
+ 0,
+ 0,
+ 0,
+ time.UTC,
+ ),
+ Aliases: map[string]bool{},
},
{
- Index: "foo-jaeger-span-archive-000001",
- CreationTime: time.Date(2020, time.August, 0o5, 15, 0, 0, 0, time.UTC),
+ Index: "foo-jaeger-span-archive-000001",
+ CreationTime: time.Date(
+ 2020,
+ time.August,
+ 0o5,
+ 15,
+ 0,
+ 0,
+ 0,
+ time.UTC,
+ ),
Aliases: map[string]bool{
"foo-jaeger-span-archive-read": true,
},
@@ -164,110 +345,235 @@ func testIndexFilter(t *testing.T, prefix string) {
{
name: "normal indices, remove older than 2 days",
filter: &IndexFilter{
- IndexPrefix: prefix,
- IndexDateSeparator: "-",
- Archive: false,
- Rollover: false,
- DeleteBeforeThisDate: time20200807.Add(-time.Hour * 24 * time.Duration(2)),
+ IndexPrefix: prefix,
+ IndexDateSeparator: "-",
+ Archive: false,
+ Rollover: false,
+ DeleteBeforeThisDate: time20200807.Add(
+ -time.Hour * 24 * time.Duration(2),
+ ),
},
},
{
name: "normal indices, remove older 1 days",
filter: &IndexFilter{
- IndexPrefix: prefix,
- IndexDateSeparator: "-",
- Archive: false,
- Rollover: false,
- DeleteBeforeThisDate: time20200807.Add(-time.Hour * 24 * time.Duration(1)),
+ IndexPrefix: prefix,
+ IndexDateSeparator: "-",
+ Archive: false,
+ Rollover: false,
+ DeleteBeforeThisDate: time20200807.Add(
+ -time.Hour * 24 * time.Duration(1),
+ ),
},
expected: []client.Index{
{
- Index: prefix + "jaeger-span-2020-08-05",
- CreationTime: time.Date(2020, time.August, 0o5, 15, 0, 0, 0, time.UTC),
- Aliases: map[string]bool{},
+ Index: prefix + "jaeger-span-2020-08-05",
+ CreationTime: time.Date(
+ 2020,
+ time.August,
+ 0o5,
+ 15,
+ 0,
+ 0,
+ 0,
+ time.UTC,
+ ),
+ Aliases: map[string]bool{},
},
{
- Index: prefix + "jaeger-service-2020-08-05",
- CreationTime: time.Date(2020, time.August, 0o5, 15, 0, 0, 0, time.UTC),
- Aliases: map[string]bool{},
+ Index: prefix + "jaeger-service-2020-08-05",
+ CreationTime: time.Date(
+ 2020,
+ time.August,
+ 0o5,
+ 15,
+ 0,
+ 0,
+ 0,
+ time.UTC,
+ ),
+ Aliases: map[string]bool{},
},
{
- Index: prefix + "jaeger-dependencies-2020-08-05",
- CreationTime: time.Date(2020, time.August, 0o5, 15, 0, 0, 0, time.UTC),
- Aliases: map[string]bool{},
+ Index: prefix + "jaeger-dependencies-2020-08-05",
+ CreationTime: time.Date(
+ 2020,
+ time.August,
+ 0o5,
+ 15,
+ 0,
+ 0,
+ 0,
+ time.UTC,
+ ),
+ Aliases: map[string]bool{},
},
{
- Index: prefix + "jaeger-sampling-2020-08-05",
- CreationTime: time.Date(2020, time.August, 0o5, 15, 0, 0, 0, time.UTC),
- Aliases: map[string]bool{},
+ Index: prefix + "jaeger-sampling-2020-08-05",
+ CreationTime: time.Date(
+ 2020,
+ time.August,
+ 0o5,
+ 15,
+ 0,
+ 0,
+ 0,
+ time.UTC,
+ ),
+ Aliases: map[string]bool{},
},
},
},
{
name: "normal indices, remove older 0 days - it should remove all indices",
filter: &IndexFilter{
- IndexPrefix: prefix,
- IndexDateSeparator: "-",
- Archive: false,
- Rollover: false,
- DeleteBeforeThisDate: time20200807.Add(-time.Hour * 24 * time.Duration(0)),
+ IndexPrefix: prefix,
+ IndexDateSeparator: "-",
+ Archive: false,
+ Rollover: false,
+ DeleteBeforeThisDate: time20200807.Add(
+ -time.Hour * 24 * time.Duration(0),
+ ),
},
expected: []client.Index{
{
- Index: prefix + "jaeger-span-2020-08-06",
- CreationTime: time.Date(2020, time.August, 0o6, 15, 0, 0, 0, time.UTC),
- Aliases: map[string]bool{},
+ Index: prefix + "jaeger-span-2020-08-06",
+ CreationTime: time.Date(
+ 2020,
+ time.August,
+ 0o6,
+ 15,
+ 0,
+ 0,
+ 0,
+ time.UTC,
+ ),
+ Aliases: map[string]bool{},
},
{
- Index: prefix + "jaeger-span-2020-08-05",
- CreationTime: time.Date(2020, time.August, 0o5, 15, 0, 0, 0, time.UTC),
- Aliases: map[string]bool{},
+ Index: prefix + "jaeger-span-2020-08-05",
+ CreationTime: time.Date(
+ 2020,
+ time.August,
+ 0o5,
+ 15,
+ 0,
+ 0,
+ 0,
+ time.UTC,
+ ),
+ Aliases: map[string]bool{},
},
{
- Index: prefix + "jaeger-service-2020-08-06",
- CreationTime: time.Date(2020, time.August, 0o6, 15, 0, 0, 0, time.UTC),
- Aliases: map[string]bool{},
+ Index: prefix + "jaeger-service-2020-08-06",
+ CreationTime: time.Date(
+ 2020,
+ time.August,
+ 0o6,
+ 15,
+ 0,
+ 0,
+ 0,
+ time.UTC,
+ ),
+ Aliases: map[string]bool{},
},
{
- Index: prefix + "jaeger-service-2020-08-05",
- CreationTime: time.Date(2020, time.August, 0o5, 15, 0, 0, 0, time.UTC),
- Aliases: map[string]bool{},
+ Index: prefix + "jaeger-service-2020-08-05",
+ CreationTime: time.Date(
+ 2020,
+ time.August,
+ 0o5,
+ 15,
+ 0,
+ 0,
+ 0,
+ time.UTC,
+ ),
+ Aliases: map[string]bool{},
},
{
- Index: prefix + "jaeger-dependencies-2020-08-06",
- CreationTime: time.Date(2020, time.August, 0o6, 15, 0, 0, 0, time.UTC),
- Aliases: map[string]bool{},
+ Index: prefix + "jaeger-dependencies-2020-08-06",
+ CreationTime: time.Date(
+ 2020,
+ time.August,
+ 0o6,
+ 15,
+ 0,
+ 0,
+ 0,
+ time.UTC,
+ ),
+ Aliases: map[string]bool{},
},
{
- Index: prefix + "jaeger-dependencies-2020-08-05",
- CreationTime: time.Date(2020, time.August, 0o5, 15, 0, 0, 0, time.UTC),
- Aliases: map[string]bool{},
+ Index: prefix + "jaeger-dependencies-2020-08-05",
+ CreationTime: time.Date(
+ 2020,
+ time.August,
+ 0o5,
+ 15,
+ 0,
+ 0,
+ 0,
+ time.UTC,
+ ),
+ Aliases: map[string]bool{},
},
{
- Index: prefix + "jaeger-sampling-2020-08-06",
- CreationTime: time.Date(2020, time.August, 0o6, 15, 0, 0, 0, time.UTC),
- Aliases: map[string]bool{},
+ Index: prefix + "jaeger-sampling-2020-08-06",
+ CreationTime: time.Date(
+ 2020,
+ time.August,
+ 0o6,
+ 15,
+ 0,
+ 0,
+ 0,
+ time.UTC,
+ ),
+ Aliases: map[string]bool{},
},
{
- Index: prefix + "jaeger-sampling-2020-08-05",
- CreationTime: time.Date(2020, time.August, 0o5, 15, 0, 0, 0, time.UTC),
- Aliases: map[string]bool{},
+ Index: prefix + "jaeger-sampling-2020-08-05",
+ CreationTime: time.Date(
+ 2020,
+ time.August,
+ 0o5,
+ 15,
+ 0,
+ 0,
+ 0,
+ time.UTC,
+ ),
+ Aliases: map[string]bool{},
},
},
},
{
name: "archive indices, remove older 1 days - archive works only for rollover",
filter: &IndexFilter{
- IndexPrefix: prefix,
- IndexDateSeparator: "-",
- Archive: true,
- Rollover: false,
- DeleteBeforeThisDate: time20200807.Add(-time.Hour * 24 * time.Duration(1)),
+ IndexPrefix: prefix,
+ IndexDateSeparator: "-",
+ Archive: true,
+ Rollover: false,
+ DeleteBeforeThisDate: time20200807.Add(
+ -time.Hour * 24 * time.Duration(1),
+ ),
},
expected: []client.Index{
{
- Index: prefix + "jaeger-span-archive-000001",
- CreationTime: time.Date(2020, time.August, 5, 15, 0, 0, 0, time.UTC),
+ Index: prefix + "jaeger-span-archive-000001",
+ CreationTime: time.Date(
+ 2020,
+ time.August,
+ 5,
+ 15,
+ 0,
+ 0,
+ 0,
+ time.UTC,
+ ),
Aliases: map[string]bool{
prefix + "jaeger-span-archive-read": true,
},
@@ -277,23 +583,43 @@ func testIndexFilter(t *testing.T, prefix string) {
{
name: "rollover indices, remove older 1 days",
filter: &IndexFilter{
- IndexPrefix: prefix,
- IndexDateSeparator: "-",
- Archive: false,
- Rollover: true,
- DeleteBeforeThisDate: time20200807.Add(-time.Hour * 24 * time.Duration(1)),
+ IndexPrefix: prefix,
+ IndexDateSeparator: "-",
+ Archive: false,
+ Rollover: true,
+ DeleteBeforeThisDate: time20200807.Add(
+ -time.Hour * 24 * time.Duration(1),
+ ),
},
expected: []client.Index{
{
- Index: prefix + "jaeger-span-000001",
- CreationTime: time.Date(2020, time.August, 0o5, 15, 0, 0, 0, time.UTC),
+ Index: prefix + "jaeger-span-000001",
+ CreationTime: time.Date(
+ 2020,
+ time.August,
+ 0o5,
+ 15,
+ 0,
+ 0,
+ 0,
+ time.UTC,
+ ),
Aliases: map[string]bool{
prefix + "jaeger-span-read": true,
},
},
{
- Index: prefix + "jaeger-service-000001",
- CreationTime: time.Date(2020, time.August, 0o5, 15, 0, 0, 0, time.UTC),
+ Index: prefix + "jaeger-service-000001",
+ CreationTime: time.Date(
+ 2020,
+ time.August,
+ 0o5,
+ 15,
+ 0,
+ 0,
+ 0,
+ time.UTC,
+ ),
Aliases: map[string]bool{
prefix + "jaeger-service-read": true,
},
@@ -303,23 +629,43 @@ func testIndexFilter(t *testing.T, prefix string) {
{
name: "rollover indices, remove older 0 days, index in write alias cannot be removed",
filter: &IndexFilter{
- IndexPrefix: prefix,
- IndexDateSeparator: "-",
- Archive: false,
- Rollover: true,
- DeleteBeforeThisDate: time20200807.Add(-time.Hour * 24 * time.Duration(0)),
+ IndexPrefix: prefix,
+ IndexDateSeparator: "-",
+ Archive: false,
+ Rollover: true,
+ DeleteBeforeThisDate: time20200807.Add(
+ -time.Hour * 24 * time.Duration(0),
+ ),
},
expected: []client.Index{
{
- Index: prefix + "jaeger-span-000001",
- CreationTime: time.Date(2020, time.August, 0o5, 15, 0, 0, 0, time.UTC),
+ Index: prefix + "jaeger-span-000001",
+ CreationTime: time.Date(
+ 2020,
+ time.August,
+ 0o5,
+ 15,
+ 0,
+ 0,
+ 0,
+ time.UTC,
+ ),
Aliases: map[string]bool{
prefix + "jaeger-span-read": true,
},
},
{
- Index: prefix + "jaeger-service-000001",
- CreationTime: time.Date(2020, time.August, 0o5, 15, 0, 0, 0, time.UTC),
+ Index: prefix + "jaeger-service-000001",
+ CreationTime: time.Date(
+ 2020,
+ time.August,
+ 0o5,
+ 15,
+ 0,
+ 0,
+ 0,
+ time.UTC,
+ ),
Aliases: map[string]bool{
prefix + "jaeger-service-read": true,
},
@@ -329,16 +675,27 @@ func testIndexFilter(t *testing.T, prefix string) {
{
name: "rollover archive indices, remove older 1 days",
filter: &IndexFilter{
- IndexPrefix: prefix,
- IndexDateSeparator: "-",
- Archive: true,
- Rollover: true,
- DeleteBeforeThisDate: time20200807.Add(-time.Hour * 24 * time.Duration(1)),
+ IndexPrefix: prefix,
+ IndexDateSeparator: "-",
+ Archive: true,
+ Rollover: true,
+ DeleteBeforeThisDate: time20200807.Add(
+ -time.Hour * 24 * time.Duration(1),
+ ),
},
expected: []client.Index{
{
- Index: prefix + "jaeger-span-archive-000001",
- CreationTime: time.Date(2020, time.August, 0o5, 15, 0, 0, 0, time.UTC),
+ Index: prefix + "jaeger-span-archive-000001",
+ CreationTime: time.Date(
+ 2020,
+ time.August,
+ 0o5,
+ 15,
+ 0,
+ 0,
+ 0,
+ time.UTC,
+ ),
Aliases: map[string]bool{
prefix + "jaeger-span-archive-read": true,
},
@@ -348,16 +705,27 @@ func testIndexFilter(t *testing.T, prefix string) {
{
name: "rollover archive indices, remove older 0 days, index in write alias cannot be removed",
filter: &IndexFilter{
- IndexPrefix: prefix,
- IndexDateSeparator: "-",
- Archive: true,
- Rollover: true,
- DeleteBeforeThisDate: time20200807.Add(-time.Hour * 24 * time.Duration(0)),
+ IndexPrefix: prefix,
+ IndexDateSeparator: "-",
+ Archive: true,
+ Rollover: true,
+ DeleteBeforeThisDate: time20200807.Add(
+ -time.Hour * 24 * time.Duration(0),
+ ),
},
expected: []client.Index{
{
- Index: prefix + "jaeger-span-archive-000001",
- CreationTime: time.Date(2020, time.August, 0o5, 15, 0, 0, 0, time.UTC),
+ Index: prefix + "jaeger-span-archive-000001",
+ CreationTime: time.Date(
+ 2020,
+ time.August,
+ 0o5,
+ 15,
+ 0,
+ 0,
+ 0,
+ time.UTC,
+ ),
Aliases: map[string]bool{
prefix + "jaeger-span-archive-read": true,
},
diff --git a/cmd/es-index-cleaner/main.go b/cmd/es-index-cleaner/main.go
index 7cb83afbb29..ea92cbc3534 100644
--- a/cmd/es-index-cleaner/main.go
+++ b/cmd/es-index-cleaner/main.go
@@ -48,7 +48,10 @@ func main() {
}
numOfDays, err := strconv.Atoi(args[0])
if err != nil {
- return fmt.Errorf("could not parse NUM_OF_DAYS argument: %w", err)
+ return fmt.Errorf(
+ "could not parse NUM_OF_DAYS argument: %w",
+ err,
+ )
}
cfg.InitFromViper(v)
@@ -63,7 +66,9 @@ func main() {
defer tlsOpts.Close()
c := &http.Client{
- Timeout: time.Duration(cfg.MasterNodeTimeoutSeconds) * time.Second,
+ Timeout: time.Duration(
+ cfg.MasterNodeTimeoutSeconds,
+ ) * time.Second,
Transport: &http.Transport{
Proxy: http.ProxyFromEnvironment,
TLSClientConfig: tlsCfg,
@@ -86,7 +91,10 @@ func main() {
year, month, day := time.Now().UTC().Date()
tomorrowMidnight := time.Date(year, month, day, 0, 0, 0, 0, time.UTC).AddDate(0, 0, 1)
deleteIndicesBefore := tomorrowMidnight.Add(-time.Hour * 24 * time.Duration(numOfDays))
- logger.Info("Indices before this date will be deleted", zap.String("date", deleteIndicesBefore.Format(time.RFC3339)))
+ logger.Info(
+ "Indices before this date will be deleted",
+ zap.String("date", deleteIndicesBefore.Format(time.RFC3339)),
+ )
filter := &app.IndexFilter{
IndexPrefix: cfg.IndexPrefix,
diff --git a/cmd/es-rollover/app/actions.go b/cmd/es-rollover/app/actions.go
index 108e03d9053..1fb08d6f6ad 100644
--- a/cmd/es-rollover/app/actions.go
+++ b/cmd/es-rollover/app/actions.go
@@ -26,7 +26,11 @@ import (
"github.com/jaegertracing/jaeger/pkg/es/client"
)
-func newESClient(endpoint string, cfg *Config, tlsCfg *tls.Config) client.Client {
+func newESClient(
+ endpoint string,
+ cfg *Config,
+ tlsCfg *tls.Config,
+) client.Client {
httpClient := &http.Client{
Timeout: time.Duration(cfg.Timeout) * time.Second,
Transport: &http.Transport{
@@ -58,7 +62,10 @@ type ActionExecuteOptions struct {
type ActionCreatorFunction func(client.Client, Config) Action
// ExecuteAction execute the action returned by the createAction function
-func ExecuteAction(opts ActionExecuteOptions, createAction ActionCreatorFunction) error {
+func ExecuteAction(
+ opts ActionExecuteOptions,
+ createAction ActionCreatorFunction,
+) error {
cfg := Config{}
cfg.InitFromViper(opts.Viper)
tlsOpts, err := opts.TLSFlags.InitFromViper(opts.Viper)
diff --git a/cmd/es-rollover/app/flags.go b/cmd/es-rollover/app/flags.go
index 56f3acce644..9168265e68b 100644
--- a/cmd/es-rollover/app/flags.go
+++ b/cmd/es-rollover/app/flags.go
@@ -53,10 +53,26 @@ func AddFlags(flags *flag.FlagSet) {
flags.String(username, "", "The username required by storage")
flags.String(password, "", "The password required by storage")
flags.Bool(useILM, false, "Use ILM to manage jaeger indices")
- flags.String(ilmPolicyName, "jaeger-ilm-policy", "The name of the ILM policy to use if ILM is active")
- flags.Int(timeout, 120, "Number of seconds to wait for master node response")
- flags.Bool(skipDependencies, false, "Disable rollover for dependencies index")
- flags.Bool(adaptiveSampling, false, "Enable rollover for adaptive sampling index")
+ flags.String(
+ ilmPolicyName,
+ "jaeger-ilm-policy",
+ "The name of the ILM policy to use if ILM is active",
+ )
+ flags.Int(
+ timeout,
+ 120,
+ "Number of seconds to wait for master node response",
+ )
+ flags.Bool(
+ skipDependencies,
+ false,
+ "Disable rollover for dependencies index",
+ )
+ flags.Bool(
+ adaptiveSampling,
+ false,
+ "Enable rollover for adaptive sampling index",
+ )
}
// InitFromViper initializes config from viper.Viper.
diff --git a/cmd/es-rollover/app/index_options.go b/cmd/es-rollover/app/index_options.go
index f732ba22101..153086eb520 100644
--- a/cmd/es-rollover/app/index_options.go
+++ b/cmd/es-rollover/app/index_options.go
@@ -33,7 +33,12 @@ type IndexOption struct {
}
// RolloverIndices return an array of indices to rollover
-func RolloverIndices(archive bool, skipDependencies bool, adaptiveSampling bool, prefix string) []IndexOption {
+func RolloverIndices(
+ archive bool,
+ skipDependencies bool,
+ adaptiveSampling bool,
+ prefix string,
+) []IndexOption {
if archive {
return []IndexOption{
{
diff --git a/cmd/es-rollover/app/index_options_test.go b/cmd/es-rollover/app/index_options_test.go
index f16f6607a9c..7faa87808b9 100644
--- a/cmd/es-rollover/app/index_options_test.go
+++ b/cmd/es-rollover/app/index_options_test.go
@@ -182,14 +182,31 @@ func TestRolloverIndices(t *testing.T) {
if test.prefix != "" {
test.prefix += "-"
}
- result := RolloverIndices(test.archive, test.skipDependencies, test.adaptiveSampling, test.prefix)
+ result := RolloverIndices(
+ test.archive,
+ test.skipDependencies,
+ test.adaptiveSampling,
+ test.prefix,
+ )
assert.Equal(t, len(test.expected), len(result))
for i, r := range result {
assert.Equal(t, test.expected[i].templateName, r.TemplateName())
assert.Equal(t, test.expected[i].mapping, r.Mapping)
- assert.Equal(t, test.expected[i].readAliasName, r.ReadAliasName())
- assert.Equal(t, test.expected[i].writeAliasName, r.WriteAliasName())
- assert.Equal(t, test.expected[i].initialRolloverIndex, r.InitialRolloverIndex())
+ assert.Equal(
+ t,
+ test.expected[i].readAliasName,
+ r.ReadAliasName(),
+ )
+ assert.Equal(
+ t,
+ test.expected[i].writeAliasName,
+ r.WriteAliasName(),
+ )
+ assert.Equal(
+ t,
+ test.expected[i].initialRolloverIndex,
+ r.InitialRolloverIndex(),
+ )
}
})
}
diff --git a/cmd/es-rollover/app/init/action.go b/cmd/es-rollover/app/init/action.go
index dd4b2ef3fb5..60c4d8aec47 100644
--- a/cmd/es-rollover/app/init/action.go
+++ b/cmd/es-rollover/app/init/action.go
@@ -40,17 +40,19 @@ type Action struct {
func (c Action) getMapping(version uint, templateName string) (string, error) {
mappingBuilder := mappings.MappingBuilder{
- TemplateBuilder: es.TextTemplateBuilder{},
- PrioritySpanTemplate: int64(c.Config.PrioritySpanTemplate),
- PriorityServiceTemplate: int64(c.Config.PriorityServiceTemplate),
- PriorityDependenciesTemplate: int64(c.Config.PriorityDependenciesTemplate),
- PrioritySamplingTemplate: int64(c.Config.PrioritySamplingTemplate),
- Shards: int64(c.Config.Shards),
- Replicas: int64(c.Config.Replicas),
- IndexPrefix: c.Config.IndexPrefix,
- UseILM: c.Config.UseILM,
- ILMPolicyName: c.Config.ILMPolicyName,
- EsVersion: version,
+ TemplateBuilder: es.TextTemplateBuilder{},
+ PrioritySpanTemplate: int64(c.Config.PrioritySpanTemplate),
+ PriorityServiceTemplate: int64(c.Config.PriorityServiceTemplate),
+ PriorityDependenciesTemplate: int64(
+ c.Config.PriorityDependenciesTemplate,
+ ),
+ PrioritySamplingTemplate: int64(c.Config.PrioritySamplingTemplate),
+ Shards: int64(c.Config.Shards),
+ Replicas: int64(c.Config.Replicas),
+ IndexPrefix: c.Config.IndexPrefix,
+ UseILM: c.Config.UseILM,
+ ILMPolicyName: c.Config.ILMPolicyName,
+ EsVersion: version,
}
return mappingBuilder.GetMapping(templateName)
}
@@ -70,10 +72,18 @@ func (c Action) Do() error {
return err
}
if !policyExist {
- return fmt.Errorf("ILM policy %s doesn't exist in Elasticsearch. Please create it and re-run init", c.Config.ILMPolicyName)
+ return fmt.Errorf(
+ "ILM policy %s doesn't exist in Elasticsearch. Please create it and re-run init",
+ c.Config.ILMPolicyName,
+ )
}
}
- rolloverIndices := app.RolloverIndices(c.Config.Archive, c.Config.SkipDependencies, c.Config.AdaptiveSampling, c.Config.IndexPrefix)
+ rolloverIndices := app.RolloverIndices(
+ c.Config.Archive,
+ c.Config.SkipDependencies,
+ c.Config.AdaptiveSampling,
+ c.Config.IndexPrefix,
+ )
for _, indexName := range rolloverIndices {
if err := c.init(version, indexName); err != nil {
return err
@@ -99,7 +109,10 @@ func createIndexIfNotExist(c client.IndexAPI, index string) error {
}
errorMap := jsonError["error"].(map[string]any)
// check for reason, ignore already exist error
- if strings.Contains(errorMap["type"].(string), "resource_already_exists_exception") {
+ if strings.Contains(
+ errorMap["type"].(string),
+ "resource_already_exists_exception",
+ ) {
return nil
}
}
diff --git a/cmd/es-rollover/app/init/action_test.go b/cmd/es-rollover/app/init/action_test.go
index 774c14e0bf8..c208dd909be 100644
--- a/cmd/es-rollover/app/init/action_test.go
+++ b/cmd/es-rollover/app/init/action_test.go
@@ -80,7 +80,10 @@ func TestIndexCreateIfNotExist(t *testing.T) {
indexClient.On("CreateIndex", "jaeger-span").Return(test.returnErr)
err := createIndexIfNotExist(indexClient, "jaeger-span")
if test.containsError != "" {
- assert.True(t, strings.Contains(err.Error(), test.containsError))
+ assert.True(
+ t,
+ strings.Contains(err.Error(), test.containsError),
+ )
} else {
assert.Equal(t, test.expectedErr, err)
}
@@ -111,7 +114,8 @@ func TestRolloverAction(t *testing.T) {
{
name: "error getting version",
setupCallExpectations: func(indexClient *mocks.MockIndexAPI, clusterClient *mocks.MockClusterAPI, ilmClient *mocks.MockILMAPI) {
- clusterClient.On("Version").Return(uint(0), errors.New("version error"))
+ clusterClient.On("Version").
+ Return(uint(0), errors.New("version error"))
},
expectedErr: errors.New("version error"),
config: Config{
@@ -127,7 +131,9 @@ func TestRolloverAction(t *testing.T) {
clusterClient.On("Version").Return(uint(7), nil)
ilmClient.On("Exists", "myilmpolicy").Return(false, nil)
},
- expectedErr: errors.New("ILM policy myilmpolicy doesn't exist in Elasticsearch. Please create it and re-run init"),
+ expectedErr: errors.New(
+ "ILM policy myilmpolicy doesn't exist in Elasticsearch. Please create it and re-run init",
+ ),
config: Config{
Config: app.Config{
Archive: true,
@@ -140,7 +146,8 @@ func TestRolloverAction(t *testing.T) {
name: "fail get ilm policy",
setupCallExpectations: func(indexClient *mocks.MockIndexAPI, clusterClient *mocks.MockClusterAPI, ilmClient *mocks.MockILMAPI) {
clusterClient.On("Version").Return(uint(7), nil)
- ilmClient.On("Exists", "myilmpolicy").Return(false, errors.New("error getting ilm policy"))
+ ilmClient.On("Exists", "myilmpolicy").
+ Return(false, errors.New("error getting ilm policy"))
},
expectedErr: errors.New("error getting ilm policy"),
config: Config{
@@ -155,7 +162,8 @@ func TestRolloverAction(t *testing.T) {
name: "fail to create template",
setupCallExpectations: func(indexClient *mocks.MockIndexAPI, clusterClient *mocks.MockClusterAPI, ilmClient *mocks.MockILMAPI) {
clusterClient.On("Version").Return(uint(7), nil)
- indexClient.On("CreateTemplate", mock.Anything, "jaeger-span").Return(errors.New("error creating template"))
+ indexClient.On("CreateTemplate", mock.Anything, "jaeger-span").
+ Return(errors.New("error creating template"))
},
expectedErr: errors.New("error creating template"),
config: Config{
@@ -171,7 +179,8 @@ func TestRolloverAction(t *testing.T) {
clusterClient.On("Version").Return(uint(7), nil)
indexClient.On("CreateTemplate", mock.Anything, "jaeger-span").Return(nil)
indexClient.On("CreateIndex", "jaeger-span-archive-000001").Return(nil)
- indexClient.On("GetJaegerIndices", "").Return([]client.Index{}, errors.New("error getting jaeger indices"))
+ indexClient.On("GetJaegerIndices", "").
+ Return([]client.Index{}, errors.New("error getting jaeger indices"))
},
expectedErr: errors.New("error getting jaeger indices"),
config: Config{
@@ -185,12 +194,23 @@ func TestRolloverAction(t *testing.T) {
name: "fail to create alias",
setupCallExpectations: func(indexClient *mocks.MockIndexAPI, clusterClient *mocks.MockClusterAPI, ilmClient *mocks.MockILMAPI) {
clusterClient.On("Version").Return(uint(7), nil)
- indexClient.On("CreateTemplate", mock.Anything, "jaeger-span").Return(nil)
- indexClient.On("CreateIndex", "jaeger-span-archive-000001").Return(nil)
- indexClient.On("GetJaegerIndices", "").Return([]client.Index{}, nil)
+ indexClient.On("CreateTemplate", mock.Anything, "jaeger-span").
+ Return(nil)
+ indexClient.On("CreateIndex", "jaeger-span-archive-000001").
+ Return(nil)
+ indexClient.On("GetJaegerIndices", "").
+ Return([]client.Index{}, nil)
indexClient.On("CreateAlias", []client.Alias{
- {Index: "jaeger-span-archive-000001", Name: "jaeger-span-archive-read", IsWriteIndex: false},
- {Index: "jaeger-span-archive-000001", Name: "jaeger-span-archive-write", IsWriteIndex: false},
+ {
+ Index: "jaeger-span-archive-000001",
+ Name: "jaeger-span-archive-read",
+ IsWriteIndex: false,
+ },
+ {
+ Index: "jaeger-span-archive-000001",
+ Name: "jaeger-span-archive-write",
+ IsWriteIndex: false,
+ },
}).Return(errors.New("error creating aliases"))
},
expectedErr: errors.New("error creating aliases"),
@@ -205,12 +225,23 @@ func TestRolloverAction(t *testing.T) {
name: "create rollover index",
setupCallExpectations: func(indexClient *mocks.MockIndexAPI, clusterClient *mocks.MockClusterAPI, ilmClient *mocks.MockILMAPI) {
clusterClient.On("Version").Return(uint(7), nil)
- indexClient.On("CreateTemplate", mock.Anything, "jaeger-span").Return(nil)
- indexClient.On("CreateIndex", "jaeger-span-archive-000001").Return(nil)
- indexClient.On("GetJaegerIndices", "").Return([]client.Index{}, nil)
+ indexClient.On("CreateTemplate", mock.Anything, "jaeger-span").
+ Return(nil)
+ indexClient.On("CreateIndex", "jaeger-span-archive-000001").
+ Return(nil)
+ indexClient.On("GetJaegerIndices", "").
+ Return([]client.Index{}, nil)
indexClient.On("CreateAlias", []client.Alias{
- {Index: "jaeger-span-archive-000001", Name: "jaeger-span-archive-read", IsWriteIndex: false},
- {Index: "jaeger-span-archive-000001", Name: "jaeger-span-archive-write", IsWriteIndex: false},
+ {
+ Index: "jaeger-span-archive-000001",
+ Name: "jaeger-span-archive-read",
+ IsWriteIndex: false,
+ },
+ {
+ Index: "jaeger-span-archive-000001",
+ Name: "jaeger-span-archive-write",
+ IsWriteIndex: false,
+ },
}).Return(nil)
},
expectedErr: nil,
@@ -225,13 +256,24 @@ func TestRolloverAction(t *testing.T) {
name: "create rollover index with ilm",
setupCallExpectations: func(indexClient *mocks.MockIndexAPI, clusterClient *mocks.MockClusterAPI, ilmClient *mocks.MockILMAPI) {
clusterClient.On("Version").Return(uint(7), nil)
- indexClient.On("CreateTemplate", mock.Anything, "jaeger-span").Return(nil)
- indexClient.On("CreateIndex", "jaeger-span-archive-000001").Return(nil)
- indexClient.On("GetJaegerIndices", "").Return([]client.Index{}, nil)
+ indexClient.On("CreateTemplate", mock.Anything, "jaeger-span").
+ Return(nil)
+ indexClient.On("CreateIndex", "jaeger-span-archive-000001").
+ Return(nil)
+ indexClient.On("GetJaegerIndices", "").
+ Return([]client.Index{}, nil)
ilmClient.On("Exists", "jaeger-ilm").Return(true, nil)
indexClient.On("CreateAlias", []client.Alias{
- {Index: "jaeger-span-archive-000001", Name: "jaeger-span-archive-read", IsWriteIndex: false},
- {Index: "jaeger-span-archive-000001", Name: "jaeger-span-archive-write", IsWriteIndex: true},
+ {
+ Index: "jaeger-span-archive-000001",
+ Name: "jaeger-span-archive-read",
+ IsWriteIndex: false,
+ },
+ {
+ Index: "jaeger-span-archive-000001",
+ Name: "jaeger-span-archive-write",
+ IsWriteIndex: true,
+ },
}).Return(nil)
},
expectedErr: nil,
diff --git a/cmd/es-rollover/app/init/flags.go b/cmd/es-rollover/app/init/flags.go
index 7e9ed89dbfe..86263b70d45 100644
--- a/cmd/es-rollover/app/init/flags.go
+++ b/cmd/es-rollover/app/init/flags.go
@@ -46,10 +46,26 @@ type Config struct {
func (*Config) AddFlags(flags *flag.FlagSet) {
flags.Int(shards, 5, "Number of shards")
flags.Int(replicas, 1, "Number of replicas")
- flags.Int(prioritySpanTemplate, 0, "Priority of jaeger-span index template (ESv8 only)")
- flags.Int(priorityServiceTemplate, 0, "Priority of jaeger-service index template (ESv8 only)")
- flags.Int(priorityDependenciesTemplate, 0, "Priority of jaeger-dependencies index template (ESv8 only)")
- flags.Int(prioritySamplingTemplate, 0, "Priority of jaeger-sampling index template (ESv8 only)")
+ flags.Int(
+ prioritySpanTemplate,
+ 0,
+ "Priority of jaeger-span index template (ESv8 only)",
+ )
+ flags.Int(
+ priorityServiceTemplate,
+ 0,
+ "Priority of jaeger-service index template (ESv8 only)",
+ )
+ flags.Int(
+ priorityDependenciesTemplate,
+ 0,
+ "Priority of jaeger-dependencies index template (ESv8 only)",
+ )
+ flags.Int(
+ prioritySamplingTemplate,
+ 0,
+ "Priority of jaeger-sampling index template (ESv8 only)",
+ )
}
// InitFromViper initializes config from viper.Viper.
diff --git a/cmd/es-rollover/app/lookback/action.go b/cmd/es-rollover/app/lookback/action.go
index 6d2e5dcf4c7..12dd0d7cb70 100644
--- a/cmd/es-rollover/app/lookback/action.go
+++ b/cmd/es-rollover/app/lookback/action.go
@@ -35,7 +35,12 @@ type Action struct {
// Do the lookback action
func (a *Action) Do() error {
- rolloverIndices := app.RolloverIndices(a.Config.Archive, a.Config.SkipDependencies, a.Config.AdaptiveSampling, a.Config.IndexPrefix)
+ rolloverIndices := app.RolloverIndices(
+ a.Config.Archive,
+ a.Config.SkipDependencies,
+ a.Config.AdaptiveSampling,
+ a.Config.IndexPrefix,
+ )
for _, indexName := range rolloverIndices {
if err := a.lookback(indexName); err != nil {
return err
@@ -52,23 +57,40 @@ func (a *Action) lookback(indexSet app.IndexOption) error {
readAliasName := indexSet.ReadAliasName()
readAliasIndices := filter.ByAlias(jaegerIndex, []string{readAliasName})
- excludedWriteIndex := filter.ByAliasExclude(readAliasIndices, []string{indexSet.WriteAliasName()})
- finalIndices := filter.ByDate(excludedWriteIndex, getTimeReference(timeNow(), a.Unit, a.UnitCount))
+ excludedWriteIndex := filter.ByAliasExclude(
+ readAliasIndices,
+ []string{indexSet.WriteAliasName()},
+ )
+ finalIndices := filter.ByDate(
+ excludedWriteIndex,
+ getTimeReference(timeNow(), a.Unit, a.UnitCount),
+ )
if len(finalIndices) == 0 {
- a.Logger.Info("No indices to remove from alias", zap.String("readAliasName", readAliasName))
+ a.Logger.Info(
+ "No indices to remove from alias",
+ zap.String("readAliasName", readAliasName),
+ )
return nil
}
aliases := make([]client.Alias, 0, len(finalIndices))
- a.Logger.Info("About to remove indices", zap.String("readAliasName", readAliasName), zap.Int("indicesCount", len(finalIndices)))
+ a.Logger.Info(
+ "About to remove indices",
+ zap.String("readAliasName", readAliasName),
+ zap.Int("indicesCount", len(finalIndices)),
+ )
for _, index := range finalIndices {
aliases = append(aliases, client.Alias{
Index: index.Index,
Name: readAliasName,
})
- a.Logger.Info("To be removed", zap.String("index", index.Index), zap.String("creationTime", index.CreationTime.String()))
+ a.Logger.Info(
+ "To be removed",
+ zap.String("index", index.Index),
+ zap.String("creationTime", index.CreationTime.String()),
+ )
}
return a.IndicesClient.DeleteAlias(aliases)
diff --git a/cmd/es-rollover/app/lookback/action_test.go b/cmd/es-rollover/app/lookback/action_test.go
index 79b786a74e7..a20fed3b827 100644
--- a/cmd/es-rollover/app/lookback/action_test.go
+++ b/cmd/es-rollover/app/lookback/action_test.go
@@ -104,7 +104,8 @@ func TestLookBackAction(t *testing.T) {
{
name: "get indices error",
setupCallExpectations: func(indexClient *mocks.MockIndexAPI) {
- indexClient.On("GetJaegerIndices", "").Return(indices, errors.New("get indices error"))
+ indexClient.On("GetJaegerIndices", "").
+ Return(indices, errors.New("get indices error"))
},
config: Config{
Unit: "days",
@@ -119,7 +120,8 @@ func TestLookBackAction(t *testing.T) {
{
name: "empty indices",
setupCallExpectations: func(indexClient *mocks.MockIndexAPI) {
- indexClient.On("GetJaegerIndices", "").Return([]client.Index{}, nil)
+ indexClient.On("GetJaegerIndices", "").
+ Return([]client.Index{}, nil)
},
config: Config{
Unit: "days",
diff --git a/cmd/es-rollover/app/lookback/flags.go b/cmd/es-rollover/app/lookback/flags.go
index e7d1b8c2176..0086b63a36a 100644
--- a/cmd/es-rollover/app/lookback/flags.go
+++ b/cmd/es-rollover/app/lookback/flags.go
@@ -38,7 +38,11 @@ type Config struct {
// AddFlags adds flags for TLS to the FlagSet.
func (*Config) AddFlags(flags *flag.FlagSet) {
- flags.String(unit, defaultUnit, "used with lookback to remove indices from read alias e.g, days, weeks, months, years")
+ flags.String(
+ unit,
+ defaultUnit,
+ "used with lookback to remove indices from read alias e.g, days, weeks, months, years",
+ )
flags.Int(unitCount, defaultUnitCount, "count of UNITs")
}
diff --git a/cmd/es-rollover/app/lookback/time_reference.go b/cmd/es-rollover/app/lookback/time_reference.go
index 88b70f7b191..70a23ec39d5 100644
--- a/cmd/es-rollover/app/lookback/time_reference.go
+++ b/cmd/es-rollover/app/lookback/time_reference.go
@@ -16,26 +16,39 @@ package lookback
import "time"
-func getTimeReference(currentTime time.Time, units string, unitCount int) time.Time {
+func getTimeReference(
+ currentTime time.Time,
+ units string,
+ unitCount int,
+) time.Time {
switch units {
case "minutes":
- return currentTime.Truncate(time.Minute).Add(-time.Duration(unitCount) * time.Minute)
+ return currentTime.Truncate(time.Minute).
+ Add(-time.Duration(unitCount) * time.Minute)
case "hours":
- return currentTime.Truncate(time.Hour).Add(-time.Duration(unitCount) * time.Hour)
+ return currentTime.Truncate(time.Hour).
+ Add(-time.Duration(unitCount) * time.Hour)
case "days":
year, month, day := currentTime.Date()
- tomorrowMidnight := time.Date(year, month, day, 0, 0, 0, 0, currentTime.Location()).AddDate(0, 0, 1)
+ tomorrowMidnight := time.Date(year, month, day, 0, 0, 0, 0, currentTime.Location()).
+ AddDate(0, 0, 1)
return tomorrowMidnight.Add(-time.Hour * 24 * time.Duration(unitCount))
case "weeks":
year, month, day := currentTime.Date()
- tomorrowMidnight := time.Date(year, month, day, 0, 0, 0, 0, currentTime.Location()).AddDate(0, 0, 1)
- return tomorrowMidnight.Add(-time.Hour * 24 * time.Duration(7*unitCount))
+ tomorrowMidnight := time.Date(year, month, day, 0, 0, 0, 0, currentTime.Location()).
+ AddDate(0, 0, 1)
+ return tomorrowMidnight.Add(
+ -time.Hour * 24 * time.Duration(7*unitCount),
+ )
case "months":
year, month, day := currentTime.Date()
- return time.Date(year, month, day, 0, 0, 0, 0, currentTime.Location()).AddDate(0, -1*unitCount, 0)
+ return time.Date(year, month, day, 0, 0, 0, 0, currentTime.Location()).
+ AddDate(0, -1*unitCount, 0)
case "years":
year, month, day := currentTime.Date()
- return time.Date(year, month, day, 0, 0, 0, 0, currentTime.Location()).AddDate(-1*unitCount, 0, 0)
+ return time.Date(year, month, day, 0, 0, 0, 0, currentTime.Location()).
+ AddDate(-1*unitCount, 0, 0)
}
- return currentTime.Truncate(time.Second).Add(-time.Duration(unitCount) * time.Second)
+ return currentTime.Truncate(time.Second).
+ Add(-time.Duration(unitCount) * time.Second)
}
diff --git a/cmd/es-rollover/app/lookback/time_reference_test.go b/cmd/es-rollover/app/lookback/time_reference_test.go
index 21a5448d856..55df75a6784 100644
--- a/cmd/es-rollover/app/lookback/time_reference_test.go
+++ b/cmd/es-rollover/app/lookback/time_reference_test.go
@@ -31,22 +31,49 @@ func TestGetTimeReference(t *testing.T) {
expectedTime time.Time
}{
{
- name: "seconds unit",
- unit: "seconds",
- unitCount: 30,
- expectedTime: time.Date(2021, time.October, 10, 10, 9, 40, 0o0, time.UTC),
+ name: "seconds unit",
+ unit: "seconds",
+ unitCount: 30,
+ expectedTime: time.Date(
+ 2021,
+ time.October,
+ 10,
+ 10,
+ 9,
+ 40,
+ 0o0,
+ time.UTC,
+ ),
},
{
- name: "minutes unit",
- unit: "minutes",
- unitCount: 30,
- expectedTime: time.Date(2021, time.October, 10, 9, 40, 0o0, 0o0, time.UTC),
+ name: "minutes unit",
+ unit: "minutes",
+ unitCount: 30,
+ expectedTime: time.Date(
+ 2021,
+ time.October,
+ 10,
+ 9,
+ 40,
+ 0o0,
+ 0o0,
+ time.UTC,
+ ),
},
{
- name: "hours unit",
- unit: "hours",
- unitCount: 2,
- expectedTime: time.Date(2021, time.October, 10, 8, 0o0, 0o0, 0o0, time.UTC),
+ name: "hours unit",
+ unit: "hours",
+ unitCount: 2,
+ expectedTime: time.Date(
+ 2021,
+ time.October,
+ 10,
+ 8,
+ 0o0,
+ 0o0,
+ 0o0,
+ time.UTC,
+ ),
},
{
name: "days unit",
@@ -55,22 +82,49 @@ func TestGetTimeReference(t *testing.T) {
expectedTime: time.Date(2021, 10, 9, 0, 0, 0, 0, time.UTC),
},
{
- name: "weeks unit",
- unit: "weeks",
- unitCount: 2,
- expectedTime: time.Date(2021, time.September, 27, 0, 0, 0, 0, time.UTC),
+ name: "weeks unit",
+ unit: "weeks",
+ unitCount: 2,
+ expectedTime: time.Date(
+ 2021,
+ time.September,
+ 27,
+ 0,
+ 0,
+ 0,
+ 0,
+ time.UTC,
+ ),
},
{
- name: "months unit",
- unit: "months",
- unitCount: 2,
- expectedTime: time.Date(2021, time.August, 10, 0, 0, 0, 0, time.UTC),
+ name: "months unit",
+ unit: "months",
+ unitCount: 2,
+ expectedTime: time.Date(
+ 2021,
+ time.August,
+ 10,
+ 0,
+ 0,
+ 0,
+ 0,
+ time.UTC,
+ ),
},
{
- name: "years unit",
- unit: "years",
- unitCount: 2,
- expectedTime: time.Date(2019, time.October, 10, 0, 0, 0, 0, time.UTC),
+ name: "years unit",
+ unit: "years",
+ unitCount: 2,
+ expectedTime: time.Date(
+ 2019,
+ time.October,
+ 10,
+ 0,
+ 0,
+ 0,
+ 0,
+ time.UTC,
+ ),
},
}
diff --git a/cmd/es-rollover/app/rollover/action.go b/cmd/es-rollover/app/rollover/action.go
index 39ef2a4f8cb..20ddafe24b9 100644
--- a/cmd/es-rollover/app/rollover/action.go
+++ b/cmd/es-rollover/app/rollover/action.go
@@ -30,7 +30,12 @@ type Action struct {
// Do the rollover action
func (a *Action) Do() error {
- rolloverIndices := app.RolloverIndices(a.Config.Archive, a.Config.SkipDependencies, a.Config.AdaptiveSampling, a.Config.IndexPrefix)
+ rolloverIndices := app.RolloverIndices(
+ a.Config.Archive,
+ a.Config.SkipDependencies,
+ a.Config.AdaptiveSampling,
+ a.Config.IndexPrefix,
+ )
for _, indexName := range rolloverIndices {
if err := a.rollover(indexName); err != nil {
return err
diff --git a/cmd/es-rollover/app/rollover/action_test.go b/cmd/es-rollover/app/rollover/action_test.go
index 9aa760ed256..89f1717f6ad 100644
--- a/cmd/es-rollover/app/rollover/action_test.go
+++ b/cmd/es-rollover/app/rollover/action_test.go
@@ -35,7 +35,13 @@ func TestRolloverAction(t *testing.T) {
},
}
- aliasToCreate := []client.Alias{{Index: "jaeger-read-span", Name: "jaeger-span-archive-read", IsWriteIndex: false}}
+ aliasToCreate := []client.Alias{
+ {
+ Index: "jaeger-read-span",
+ Name: "jaeger-span-archive-read",
+ IsWriteIndex: false,
+ },
+ }
type testCase struct {
name string
conditions string
@@ -57,7 +63,8 @@ func TestRolloverAction(t *testing.T) {
setupCallExpectations: func(indexClient *mocks.MockIndexAPI, test *testCase) {
indexClient.On("GetJaegerIndices", "").Return(test.indices, test.getJaegerIndicesErr)
indexClient.On("CreateAlias", aliasToCreate).Return(test.createAliasErr)
- indexClient.On("Rollover", "jaeger-span-archive-write", map[string]any{"max_age": "2d"}).Return(test.rolloverErr)
+ indexClient.On("Rollover", "jaeger-span-archive-write", map[string]any{"max_age": "2d"}).
+ Return(test.rolloverErr)
},
},
{
@@ -74,7 +81,8 @@ func TestRolloverAction(t *testing.T) {
},
setupCallExpectations: func(indexClient *mocks.MockIndexAPI, test *testCase) {
indexClient.On("GetJaegerIndices", "").Return(test.indices, test.getJaegerIndicesErr)
- indexClient.On("Rollover", "jaeger-span-archive-write", map[string]any{"max_age": "2d"}).Return(test.rolloverErr)
+ indexClient.On("Rollover", "jaeger-span-archive-write", map[string]any{"max_age": "2d"}).
+ Return(test.rolloverErr)
},
},
{
@@ -84,7 +92,8 @@ func TestRolloverAction(t *testing.T) {
getJaegerIndicesErr: errors.New("unable to get indices"),
indices: readIndices,
setupCallExpectations: func(indexClient *mocks.MockIndexAPI, test *testCase) {
- indexClient.On("Rollover", "jaeger-span-archive-write", map[string]any{"max_age": "2d"}).Return(test.rolloverErr)
+ indexClient.On("Rollover", "jaeger-span-archive-write", map[string]any{"max_age": "2d"}).
+ Return(test.rolloverErr)
indexClient.On("GetJaegerIndices", "").Return(test.indices, test.getJaegerIndicesErr)
},
},
@@ -95,7 +104,8 @@ func TestRolloverAction(t *testing.T) {
rolloverErr: errors.New("unable to rollover"),
indices: readIndices,
setupCallExpectations: func(indexClient *mocks.MockIndexAPI, test *testCase) {
- indexClient.On("Rollover", "jaeger-span-archive-write", map[string]any{"max_age": "2d"}).Return(test.rolloverErr)
+ indexClient.On("Rollover", "jaeger-span-archive-write", map[string]any{"max_age": "2d"}).
+ Return(test.rolloverErr)
},
},
{
@@ -107,7 +117,8 @@ func TestRolloverAction(t *testing.T) {
setupCallExpectations: func(indexClient *mocks.MockIndexAPI, test *testCase) {
indexClient.On("GetJaegerIndices", "").Return(test.indices, test.getJaegerIndicesErr)
indexClient.On("CreateAlias", aliasToCreate).Return(test.createAliasErr)
- indexClient.On("Rollover", "jaeger-span-archive-write", map[string]any{"max_age": "2d"}).Return(test.rolloverErr)
+ indexClient.On("Rollover", "jaeger-span-archive-write", map[string]any{"max_age": "2d"}).
+ Return(test.rolloverErr)
},
},
{
diff --git a/cmd/es-rollover/app/rollover/flags.go b/cmd/es-rollover/app/rollover/flags.go
index 3b3d9123bda..f131eaa676e 100644
--- a/cmd/es-rollover/app/rollover/flags.go
+++ b/cmd/es-rollover/app/rollover/flags.go
@@ -35,7 +35,11 @@ type Config struct {
// AddFlags adds flags for TLS to the FlagSet.
func (*Config) AddFlags(flags *flag.FlagSet) {
- flags.String(conditions, defaultRollbackCondition, "conditions used to rollover to a new write index")
+ flags.String(
+ conditions,
+ defaultRollbackCondition,
+ "conditions used to rollover to a new write index",
+ )
}
// InitFromViper initializes config from viper.Viper.
diff --git a/cmd/es-rollover/main.go b/cmd/es-rollover/main.go
index f1585942df8..476bc37cd02 100644
--- a/cmd/es-rollover/main.go
+++ b/cmd/es-rollover/main.go
@@ -150,7 +150,11 @@ func main() {
}
}
-func addSubCommand(v *viper.Viper, rootCmd, cmd *cobra.Command, addFlags func(*flag.FlagSet)) {
+func addSubCommand(
+ v *viper.Viper,
+ rootCmd, cmd *cobra.Command,
+ addFlags func(*flag.FlagSet),
+) {
rootCmd.AddCommand(cmd)
config.AddFlags(
v,
@@ -159,7 +163,11 @@ func addSubCommand(v *viper.Viper, rootCmd, cmd *cobra.Command, addFlags func(*f
)
}
-func addPersistentFlags(v *viper.Viper, rootCmd *cobra.Command, inits ...func(*flag.FlagSet)) {
+func addPersistentFlags(
+ v *viper.Viper,
+ rootCmd *cobra.Command,
+ inits ...func(*flag.FlagSet),
+) {
flagSet := new(flag.FlagSet)
for i := range inits {
inits[i](flagSet)
diff --git a/cmd/esmapping-generator/app/renderer/render.go b/cmd/esmapping-generator/app/renderer/render.go
index 74bdfa3cb66..debcf0200ae 100644
--- a/cmd/esmapping-generator/app/renderer/render.go
+++ b/cmd/esmapping-generator/app/renderer/render.go
@@ -30,7 +30,10 @@ var supportedMappings = map[string]struct{}{
}
// GetMappingAsString returns rendered index templates as string
-func GetMappingAsString(builder es.TemplateBuilder, opt *app.Options) (string, error) {
+func GetMappingAsString(
+ builder es.TemplateBuilder,
+ opt *app.Options,
+) (string, error) {
enableILM, err := strconv.ParseBool(opt.UseILM)
if err != nil {
return "", err
diff --git a/cmd/esmapping-generator/app/renderer/render_test.go b/cmd/esmapping-generator/app/renderer/render_test.go
index e3e43f4beb7..1fb7271001e 100644
--- a/cmd/esmapping-generator/app/renderer/render_test.go
+++ b/cmd/esmapping-generator/app/renderer/render_test.go
@@ -36,7 +36,11 @@ func TestIsValidOption(t *testing.T) {
}{
{name: "span mapping", arg: "jaeger-span", expectedValue: true},
{name: "service mapping", arg: "jaeger-service", expectedValue: true},
- {name: "Invalid mapping", arg: "dependency-service", expectedValue: false},
+ {
+ name: "Invalid mapping",
+ arg: "dependency-service",
+ expectedValue: false,
+ },
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
@@ -62,21 +66,25 @@ func Test_getMappingAsString(t *testing.T) {
},
{
name: "Parse bool error", args: app.Options{Mapping: "jaeger-span", EsVersion: 7, Shards: 5, Replicas: 1, IndexPrefix: "test", UseILM: "foo", ILMPolicyName: "jaeger-test-policy"},
- wantErr: errors.New("strconv.ParseBool: parsing \"foo\": invalid syntax"),
+ wantErr: errors.New(
+ "strconv.ParseBool: parsing \"foo\": invalid syntax",
+ ),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Prepare
mockTemplateApplier := &mocks.TemplateApplier{}
- mockTemplateApplier.On("Execute", mock.Anything, mock.Anything).Return(
- func(wr io.Writer, data any) error {
- wr.Write([]byte(tt.want))
- return nil
- },
- )
+ mockTemplateApplier.On("Execute", mock.Anything, mock.Anything).
+ Return(
+ func(wr io.Writer, data any) error {
+ wr.Write([]byte(tt.want))
+ return nil
+ },
+ )
mockTemplateBuilder := &mocks.TemplateBuilder{}
- mockTemplateBuilder.On("Parse", mock.Anything).Return(mockTemplateApplier, tt.wantErr)
+ mockTemplateBuilder.On("Parse", mock.Anything).
+ Return(mockTemplateApplier, tt.wantErr)
// Test
got, err := GetMappingAsString(mockTemplateBuilder, &tt.args)
diff --git a/cmd/esmapping-generator/main.go b/cmd/esmapping-generator/main.go
index d0cc9ccc910..3a6d36775c5 100644
--- a/cmd/esmapping-generator/main.go
+++ b/cmd/esmapping-generator/main.go
@@ -36,10 +36,15 @@ func main() {
Long: `Jaeger esmapping-generator renders passed templates with provided values and prints rendered output to stdout`,
Run: func(cmd *cobra.Command, args []string) {
if !renderer.IsValidOption(options.Mapping) {
- logger.Fatal("please pass either 'jaeger-service' or 'jaeger-span' as argument")
+ logger.Fatal(
+ "please pass either 'jaeger-service' or 'jaeger-span' as argument",
+ )
}
- parsedMapping, err := renderer.GetMappingAsString(es.TextTemplateBuilder{}, &options)
+ parsedMapping, err := renderer.GetMappingAsString(
+ es.TextTemplateBuilder{},
+ &options,
+ )
if err != nil {
logger.Fatal(err.Error())
}
diff --git a/cmd/ingester/app/builder/builder.go b/cmd/ingester/app/builder/builder.go
index d89a2964ed3..1261e069509 100644
--- a/cmd/ingester/app/builder/builder.go
+++ b/cmd/ingester/app/builder/builder.go
@@ -30,7 +30,12 @@ import (
)
// CreateConsumer creates a new span consumer for the ingester
-func CreateConsumer(logger *zap.Logger, metricsFactory metrics.Factory, spanWriter spanstore.Writer, options app.Options) (*consumer.Consumer, error) {
+func CreateConsumer(
+ logger *zap.Logger,
+ metricsFactory metrics.Factory,
+ spanWriter spanstore.Writer,
+ options app.Options,
+) (*consumer.Consumer, error) {
var unmarshaller kafka.Unmarshaller
switch options.Encoding {
case kafka.EncodingJSON:
@@ -40,8 +45,11 @@ func CreateConsumer(logger *zap.Logger, metricsFactory metrics.Factory, spanWrit
case kafka.EncodingZipkinThrift:
unmarshaller = kafka.NewZipkinThriftUnmarshaller()
default:
- return nil, fmt.Errorf(`encoding '%s' not recognised, use one of ("%s")`,
- options.Encoding, strings.Join(kafka.AllEncodings, "\", \""))
+ return nil, fmt.Errorf(
+ `encoding '%s' not recognised, use one of ("%s")`,
+ options.Encoding,
+ strings.Join(kafka.AllEncodings, "\", \""),
+ )
}
spParams := processor.SpanProcessorParams{
diff --git a/cmd/ingester/app/consumer/committing_processor.go b/cmd/ingester/app/consumer/committing_processor.go
index d4223430766..8318e6b7a4c 100644
--- a/cmd/ingester/app/consumer/committing_processor.go
+++ b/cmd/ingester/app/consumer/committing_processor.go
@@ -32,7 +32,10 @@ type offsetMarker interface {
}
// NewCommittingProcessor returns a processor that commits message offsets to Kafka
-func NewCommittingProcessor(processor processor.SpanProcessor, marker offsetMarker) processor.SpanProcessor {
+func NewCommittingProcessor(
+ processor processor.SpanProcessor,
+ marker offsetMarker,
+) processor.SpanProcessor {
return &comittingProcessor{
processor: processor,
marker: marker,
diff --git a/cmd/ingester/app/consumer/committing_processor_test.go b/cmd/ingester/app/consumer/committing_processor_test.go
index 71531e8298c..60e858855f9 100644
--- a/cmd/ingester/app/consumer/committing_processor_test.go
+++ b/cmd/ingester/app/consumer/committing_processor_test.go
@@ -70,7 +70,10 @@ func (fakeProcessorMessage) Value() []byte {
}
func TestNewCommittingProcessorErrorNoKafkaMessage(t *testing.T) {
- committingProcessor := NewCommittingProcessor(&mocks.SpanProcessor{}, &fakeOffsetMarker{})
+ committingProcessor := NewCommittingProcessor(
+ &mocks.SpanProcessor{},
+ &fakeOffsetMarker{},
+ )
require.Error(t, committingProcessor.Process(fakeProcessorMessage{}))
}
diff --git a/cmd/ingester/app/consumer/consumer.go b/cmd/ingester/app/consumer/consumer.go
index 65d90f8ff9a..b1f98998f7a 100644
--- a/cmd/ingester/app/consumer/consumer.go
+++ b/cmd/ingester/app/consumer/consumer.go
@@ -60,7 +60,11 @@ type consumerState struct {
// New is a constructor for a Consumer
func New(params Params) (*Consumer, error) {
- deadlockDetector := newDeadlockDetector(params.MetricsFactory, params.Logger, params.DeadlockCheckInterval)
+ deadlockDetector := newDeadlockDetector(
+ params.MetricsFactory,
+ params.Logger,
+ params.DeadlockCheckInterval,
+ )
return &Consumer{
metricsFactory: params.MetricsFactory,
logger: params.Logger,
@@ -81,7 +85,9 @@ func (c *Consumer) Start() {
c.logger.Info("Starting main loop")
for pc := range c.internalConsumer.Partitions() {
c.partitionMapLock.Lock()
- c.partitionIDToState[pc.Partition()] = &consumerState{partitionConsumer: pc}
+ c.partitionIDToState[pc.Partition()] = &consumerState{
+ partitionConsumer: pc,
+ }
c.partitionMapLock.Unlock()
c.partitionMetrics(pc.Topic(), pc.Partition()).startCounter.Inc(1)
@@ -109,7 +115,10 @@ func (c *Consumer) Close() error {
// handleMessages handles incoming Kafka messages on a channel
func (c *Consumer) handleMessages(pc sc.PartitionConsumer) {
- c.logger.Info("Starting message handler", zap.Int32("partition", pc.Partition()))
+ c.logger.Info(
+ "Starting message handler",
+ zap.Int32("partition", pc.Partition()),
+ )
c.partitionMapLock.Lock()
c.partitionsHeld++
c.partitionsHeldGauge.Update(c.partitionsHeld)
@@ -127,49 +136,83 @@ func (c *Consumer) handleMessages(pc sc.PartitionConsumer) {
var msgProcessor processor.SpanProcessor
- deadlockDetector := c.deadlockDetector.startMonitoringForPartition(pc.Partition())
+ deadlockDetector := c.deadlockDetector.startMonitoringForPartition(
+ pc.Partition(),
+ )
defer deadlockDetector.close()
for {
select {
case msg, ok := <-pc.Messages():
if !ok {
- c.logger.Info("Message channel closed. ", zap.Int32("partition", pc.Partition()))
+ c.logger.Info(
+ "Message channel closed. ",
+ zap.Int32("partition", pc.Partition()),
+ )
return
}
c.logger.Debug("Got msg", zap.Any("msg", msg))
msgMetrics.counter.Inc(1)
msgMetrics.offsetGauge.Update(msg.Offset)
- msgMetrics.lagGauge.Update(pc.HighWaterMarkOffset() - msg.Offset - 1)
+ msgMetrics.lagGauge.Update(
+ pc.HighWaterMarkOffset() - msg.Offset - 1,
+ )
deadlockDetector.incrementMsgCount()
if msgProcessor == nil {
- msgProcessor = c.processorFactory.new(pc.Topic(), pc.Partition(), msg.Offset-1)
+ msgProcessor = c.processorFactory.new(
+ pc.Topic(),
+ pc.Partition(),
+ msg.Offset-1,
+ )
// revive:disable-next-line defer
defer msgProcessor.Close()
}
err := msgProcessor.Process(saramaMessageWrapper{msg})
if err != nil {
- c.logger.Error("Failed to process a Kafka message", zap.Error(err), zap.Int32("partition", msg.Partition), zap.Int64("offset", msg.Offset))
+ c.logger.Error(
+ "Failed to process a Kafka message",
+ zap.Error(err),
+ zap.Int32("partition", msg.Partition),
+ zap.Int64("offset", msg.Offset),
+ )
}
case <-deadlockDetector.closePartitionChannel():
- c.logger.Info("Closing partition due to inactivity", zap.Int32("partition", pc.Partition()))
+ c.logger.Info(
+ "Closing partition due to inactivity",
+ zap.Int32("partition", pc.Partition()),
+ )
return
}
}
}
func (c *Consumer) closePartition(partitionConsumer sc.PartitionConsumer) {
- c.logger.Info("Closing partition consumer", zap.Int32("partition", partitionConsumer.Partition()))
+ c.logger.Info(
+ "Closing partition consumer",
+ zap.Int32("partition", partitionConsumer.Partition()),
+ )
partitionConsumer.Close() // blocks until messages channel is drained
- c.partitionMetrics(partitionConsumer.Topic(), partitionConsumer.Partition()).closeCounter.Inc(1)
- c.logger.Info("Closed partition consumer", zap.Int32("partition", partitionConsumer.Partition()))
+ c.partitionMetrics(
+ partitionConsumer.Topic(),
+ partitionConsumer.Partition(),
+ ).closeCounter.Inc(
+ 1,
+ )
+ c.logger.Info(
+ "Closed partition consumer",
+ zap.Int32("partition", partitionConsumer.Partition()),
+ )
}
// handleErrors handles incoming Kafka consumer errors on a channel
-func (c *Consumer) handleErrors(topic string, partition int32, errChan <-chan *sarama.ConsumerError) {
+func (c *Consumer) handleErrors(
+ topic string,
+ partition int32,
+ errChan <-chan *sarama.ConsumerError,
+) {
c.logger.Info("Starting error handler", zap.Int32("partition", partition))
defer c.doneWg.Done()
diff --git a/cmd/ingester/app/consumer/consumer_metrics.go b/cmd/ingester/app/consumer/consumer_metrics.go
index cf6efba4ddf..2440a57923e 100644
--- a/cmd/ingester/app/consumer/consumer_metrics.go
+++ b/cmd/ingester/app/consumer/consumer_metrics.go
@@ -51,24 +51,37 @@ func (c *Consumer) namespace(topic string, partition int32) metrics.Factory {
func (c *Consumer) newMsgMetrics(topic string, partition int32) msgMetrics {
f := c.namespace(topic, partition)
return msgMetrics{
- counter: f.Counter(metrics.Options{Name: "messages", Tags: nil}),
- offsetGauge: f.Gauge(metrics.Options{Name: "current-offset", Tags: nil}),
- lagGauge: f.Gauge(metrics.Options{Name: "offset-lag", Tags: nil}),
+ counter: f.Counter(metrics.Options{Name: "messages", Tags: nil}),
+ offsetGauge: f.Gauge(
+ metrics.Options{Name: "current-offset", Tags: nil},
+ ),
+ lagGauge: f.Gauge(metrics.Options{Name: "offset-lag", Tags: nil}),
}
}
func (c *Consumer) newErrMetrics(topic string, partition int32) errMetrics {
- return errMetrics{errCounter: c.namespace(topic, partition).Counter(metrics.Options{Name: "errors", Tags: nil})}
+ return errMetrics{
+ errCounter: c.namespace(topic, partition).
+ Counter(metrics.Options{Name: "errors", Tags: nil}),
+ }
}
-func (c *Consumer) partitionMetrics(topic string, partition int32) partitionMetrics {
+func (c *Consumer) partitionMetrics(
+ topic string,
+ partition int32,
+) partitionMetrics {
f := c.namespace(topic, partition)
return partitionMetrics{
- closeCounter: f.Counter(metrics.Options{Name: "partition-close", Tags: nil}),
- startCounter: f.Counter(metrics.Options{Name: "partition-start", Tags: nil}),
+ closeCounter: f.Counter(
+ metrics.Options{Name: "partition-close", Tags: nil},
+ ),
+ startCounter: f.Counter(
+ metrics.Options{Name: "partition-start", Tags: nil},
+ ),
}
}
func partitionsHeldGauge(metricsFactory metrics.Factory) metrics.Gauge {
- return metricsFactory.Namespace(metrics.NSOptions{Name: consumerNamespace, Tags: nil}).Gauge(metrics.Options{Name: "partitions-held", Tags: nil})
+ return metricsFactory.Namespace(metrics.NSOptions{Name: consumerNamespace, Tags: nil}).
+ Gauge(metrics.Options{Name: "partitions-held", Tags: nil})
}
diff --git a/cmd/ingester/app/consumer/consumer_test.go b/cmd/ingester/app/consumer/consumer_test.go
index 51ceda49b9f..812c56a76d7 100644
--- a/cmd/ingester/app/consumer/consumer_test.go
+++ b/cmd/ingester/app/consumer/consumer_test.go
@@ -68,7 +68,10 @@ func (s partitionConsumerWrapper) Topic() string {
return s.topic
}
-func newSaramaClusterConsumer(saramaPartitionConsumer sarama.PartitionConsumer, mc *smocks.PartitionConsumer) *kmocks.Consumer {
+func newSaramaClusterConsumer(
+ saramaPartitionConsumer sarama.PartitionConsumer,
+ mc *smocks.PartitionConsumer,
+) *kmocks.Consumer {
pcha := make(chan cluster.PartitionConsumer, 1)
pcha <- &partitionConsumerWrapper{
topic: topic,
@@ -81,7 +84,8 @@ func newSaramaClusterConsumer(saramaPartitionConsumer sarama.PartitionConsumer,
mc.Close()
close(pcha)
})
- saramaClusterConsumer.On("MarkPartitionOffset", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil)
+ saramaClusterConsumer.On("MarkPartitionOffset", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
+ Return(nil)
return saramaClusterConsumer
}
@@ -116,7 +120,14 @@ func TestSaramaConsumerWrapper_MarkPartitionOffset(t *testing.T) {
metadata := "meatbag"
sc.On("MarkPartitionOffset", topic, partition, msgOffset, metadata).Return()
sc.MarkPartitionOffset(topic, partition, msgOffset, metadata)
- sc.AssertCalled(t, "MarkPartitionOffset", topic, partition, msgOffset, metadata)
+ sc.AssertCalled(
+ t,
+ "MarkPartitionOffset",
+ topic,
+ partition,
+ msgOffset,
+ metadata,
+ )
}
func TestSaramaConsumerWrapper_start_Messages(t *testing.T) {
@@ -127,19 +138,30 @@ func TestSaramaConsumerWrapper_start_Messages(t *testing.T) {
isProcessed := sync.WaitGroup{}
isProcessed.Add(1)
mp := &pmocks.SpanProcessor{}
- mp.On("Process", saramaMessageWrapper{msg}).Return(func(msg processor.Message) error {
- isProcessed.Done()
- return nil
- })
+ mp.On("Process", saramaMessageWrapper{msg}).
+ Return(func(msg processor.Message) error {
+ isProcessed.Done()
+ return nil
+ })
saramaConsumer := smocks.NewConsumer(t, &sarama.Config{})
mc := saramaConsumer.ExpectConsumePartition(topic, partition, msgOffset)
mc.ExpectMessagesDrainedOnClose()
- saramaPartitionConsumer, e := saramaConsumer.ConsumePartition(topic, partition, msgOffset)
+ saramaPartitionConsumer, e := saramaConsumer.ConsumePartition(
+ topic,
+ partition,
+ msgOffset,
+ )
require.NoError(t, e)
- undertest := newConsumer(t, localFactory, topic, mp, newSaramaClusterConsumer(saramaPartitionConsumer, mc))
+ undertest := newConsumer(
+ t,
+ localFactory,
+ topic,
+ mp,
+ newSaramaClusterConsumer(saramaPartitionConsumer, mc),
+ )
undertest.partitionIDToState = map[int32]*consumerState{
partition: {
@@ -163,8 +185,11 @@ func TestSaramaConsumerWrapper_start_Messages(t *testing.T) {
mp.AssertExpectations(t)
// Ensure that the partition consumer was updated in the map
- assert.Equal(t, saramaPartitionConsumer.HighWaterMarkOffset(),
- undertest.partitionIDToState[partition].partitionConsumer.HighWaterMarkOffset())
+ assert.Equal(
+ t,
+ saramaPartitionConsumer.HighWaterMarkOffset(),
+ undertest.partitionIDToState[partition].partitionConsumer.HighWaterMarkOffset(),
+ )
undertest.Close()
localFactory.AssertCounterMetrics(t, metricstest.ExpectedMetric{
@@ -210,10 +235,20 @@ func TestSaramaConsumerWrapper_start_Errors(t *testing.T) {
mc := saramaConsumer.ExpectConsumePartition(topic, partition, msgOffset)
mc.ExpectErrorsDrainedOnClose()
- saramaPartitionConsumer, e := saramaConsumer.ConsumePartition(topic, partition, msgOffset)
+ saramaPartitionConsumer, e := saramaConsumer.ConsumePartition(
+ topic,
+ partition,
+ msgOffset,
+ )
require.NoError(t, e)
- undertest := newConsumer(t, localFactory, topic, &pmocks.SpanProcessor{}, newSaramaClusterConsumer(saramaPartitionConsumer, mc))
+ undertest := newConsumer(
+ t,
+ localFactory,
+ topic,
+ &pmocks.SpanProcessor{},
+ newSaramaClusterConsumer(saramaPartitionConsumer, mc),
+ )
undertest.Start()
mc.YieldError(errors.New("Daisy, Daisy"))
@@ -249,11 +284,25 @@ func TestHandleClosePartition(t *testing.T) {
saramaConsumer := smocks.NewConsumer(t, &sarama.Config{})
mc := saramaConsumer.ExpectConsumePartition(topic, partition, msgOffset)
mc.ExpectErrorsDrainedOnClose()
- saramaPartitionConsumer, e := saramaConsumer.ConsumePartition(topic, partition, msgOffset)
+ saramaPartitionConsumer, e := saramaConsumer.ConsumePartition(
+ topic,
+ partition,
+ msgOffset,
+ )
require.NoError(t, e)
- undertest := newConsumer(t, metricsFactory, topic, mp, newSaramaClusterConsumer(saramaPartitionConsumer, mc))
- undertest.deadlockDetector = newDeadlockDetector(metricsFactory, undertest.logger, 200*time.Millisecond)
+ undertest := newConsumer(
+ t,
+ metricsFactory,
+ topic,
+ mp,
+ newSaramaClusterConsumer(saramaPartitionConsumer, mc),
+ )
+ undertest.deadlockDetector = newDeadlockDetector(
+ metricsFactory,
+ undertest.logger,
+ 200*time.Millisecond,
+ )
undertest.Start()
defer undertest.Close()
diff --git a/cmd/ingester/app/consumer/deadlock_detector.go b/cmd/ingester/app/consumer/deadlock_detector.go
index 7e8885a08f6..9d20dc241fd 100644
--- a/cmd/ingester/app/consumer/deadlock_detector.go
+++ b/cmd/ingester/app/consumer/deadlock_detector.go
@@ -61,14 +61,21 @@ type allPartitionsDeadlockDetector struct {
disabled bool
}
-func newDeadlockDetector(metricsFactory metrics.Factory, logger *zap.Logger, interval time.Duration) deadlockDetector {
+func newDeadlockDetector(
+ metricsFactory metrics.Factory,
+ logger *zap.Logger,
+ interval time.Duration,
+) deadlockDetector {
panicFunc := func(partition int32) {
- metricsFactory.Counter(metrics.Options{Name: "deadlockdetector.panic-issued", Tags: map[string]string{"partition": strconv.Itoa(int(partition))}}).Inc(1)
+ metricsFactory.Counter(metrics.Options{Name: "deadlockdetector.panic-issued", Tags: map[string]string{"partition": strconv.Itoa(int(partition))}}).
+ Inc(1)
time.Sleep(time.Second) // Allow time to flush metric
- logger.Panic("No messages processed in the last check interval, possible deadlock, exiting. "+
- "This behavior can be disabled with --ingester.deadlockInterval=0 flag.",
- zap.Int32("partition", partition))
+ logger.Panic(
+ "No messages processed in the last check interval, possible deadlock, exiting. "+
+ "This behavior can be disabled with --ingester.deadlockInterval=0 flag.",
+ zap.Int32("partition", partition),
+ )
}
return deadlockDetector{
@@ -79,7 +86,9 @@ func newDeadlockDetector(metricsFactory metrics.Factory, logger *zap.Logger, int
}
}
-func (s *deadlockDetector) startMonitoringForPartition(partition int32) *partitionDeadlockDetector {
+func (s *deadlockDetector) startMonitoringForPartition(
+ partition int32,
+) *partitionDeadlockDetector {
var msgConsumed uint64
w := &partitionDeadlockDetector{
msgConsumed: &msgConsumed,
@@ -103,20 +112,27 @@ func (s *deadlockDetector) startMonitoringForPartition(partition int32) *partiti
return w
}
-func (s *deadlockDetector) monitorForPartition(w *partitionDeadlockDetector, partition int32) {
+func (s *deadlockDetector) monitorForPartition(
+ w *partitionDeadlockDetector,
+ partition int32,
+) {
ticker := time.NewTicker(s.interval)
defer ticker.Stop()
for {
select {
case <-w.done:
- s.logger.Info("Closing ticker routine", zap.Int32("partition", partition))
+ s.logger.Info(
+ "Closing ticker routine",
+ zap.Int32("partition", partition),
+ )
return
case <-ticker.C:
if atomic.LoadUint64(w.msgConsumed) == 0 {
select {
case w.closePartition <- struct{}{}:
- s.metricsFactory.Counter(metrics.Options{Name: "deadlockdetector.close-signalled", Tags: map[string]string{"partition": strconv.Itoa(int(partition))}}).Inc(1)
+ s.metricsFactory.Counter(metrics.Options{Name: "deadlockdetector.close-signalled", Tags: map[string]string{"partition": strconv.Itoa(int(partition))}}).
+ Inc(1)
s.logger.Warn("Signalling partition close due to inactivity", zap.Int32("partition", partition))
default:
// If closePartition is blocked, the consumer might have deadlocked - kill the process
@@ -190,7 +206,10 @@ func (w *partitionDeadlockDetector) close() {
if w.disabled {
return
}
- w.logger.Debug("Closing deadlock detector", zap.Int32("partition", w.partition))
+ w.logger.Debug(
+ "Closing deadlock detector",
+ zap.Int32("partition", w.partition),
+ )
w.done <- struct{}{}
}
diff --git a/cmd/ingester/app/consumer/offset/manager.go b/cmd/ingester/app/consumer/offset/manager.go
index b1e6c019135..ab0b87d67af 100644
--- a/cmd/ingester/app/consumer/offset/manager.go
+++ b/cmd/ingester/app/consumer/offset/manager.go
@@ -63,12 +63,16 @@ func NewManager(
"partition": strconv.Itoa(int(partition)),
}
return &Manager{
- markOffsetFunction: markOffset,
- close: make(chan struct{}),
- offsetCommitCount: factory.Counter(metrics.Options{Name: "offset-commits-total", Tags: tags}),
- lastCommittedOffset: factory.Gauge(metrics.Options{Name: "last-committed-offset", Tags: tags}),
- list: newConcurrentList(minOffset),
- minOffset: minOffset,
+ markOffsetFunction: markOffset,
+ close: make(chan struct{}),
+ offsetCommitCount: factory.Counter(
+ metrics.Options{Name: "offset-commits-total", Tags: tags},
+ ),
+ lastCommittedOffset: factory.Gauge(
+ metrics.Options{Name: "last-committed-offset", Tags: tags},
+ ),
+ list: newConcurrentList(minOffset),
+ minOffset: minOffset,
}
}
diff --git a/cmd/ingester/app/consumer/offset/manager_test.go b/cmd/ingester/app/consumer/offset/manager_test.go
index 74ec07e70da..f8d4db57bcf 100644
--- a/cmd/ingester/app/consumer/offset/manager_test.go
+++ b/cmd/ingester/app/consumer/offset/manager_test.go
@@ -47,8 +47,16 @@ func TestHandleReset(t *testing.T) {
assert.Equal(t, offset, captureOffset)
cnt, g := m.Snapshot()
- assert.Equal(t, int64(1), cnt["offset-commits-total|partition=1|topic=test_topic"])
- assert.Equal(t, int64(offset), g["last-committed-offset|partition=1|topic=test_topic"])
+ assert.Equal(
+ t,
+ int64(1),
+ cnt["offset-commits-total|partition=1|topic=test_topic"],
+ )
+ assert.Equal(
+ t,
+ int64(offset),
+ g["last-committed-offset|partition=1|topic=test_topic"],
+ )
}
func TestCache(t *testing.T) {
@@ -57,7 +65,13 @@ func TestCache(t *testing.T) {
fakeMarker := func(offset int64) {
assert.Fail(t, "Shouldn't mark cached offset")
}
- manager := NewManager(offset, fakeMarker, "test_topic", 1, metrics.NullFactory)
+ manager := NewManager(
+ offset,
+ fakeMarker,
+ "test_topic",
+ 1,
+ metrics.NullFactory,
+ )
manager.Start()
time.Sleep(resetInterval + 50)
manager.MarkOffset(offset)
diff --git a/cmd/ingester/app/consumer/processor_factory.go b/cmd/ingester/app/consumer/processor_factory.go
index a4e09584679..cd2b2da48e7 100644
--- a/cmd/ingester/app/consumer/processor_factory.go
+++ b/cmd/ingester/app/consumer/processor_factory.go
@@ -47,7 +47,9 @@ type ProcessorFactory struct {
}
// NewProcessorFactory constructs a new ProcessorFactory
-func NewProcessorFactory(params ProcessorFactoryParams) (*ProcessorFactory, error) {
+func NewProcessorFactory(
+ params ProcessorFactoryParams,
+) (*ProcessorFactory, error) {
return &ProcessorFactory{
consumer: params.SaramaConsumer,
metricsFactory: params.Factory,
@@ -58,16 +60,29 @@ func NewProcessorFactory(params ProcessorFactoryParams) (*ProcessorFactory, erro
}, nil
}
-func (c *ProcessorFactory) new(topic string, partition int32, minOffset int64) processor.SpanProcessor {
+func (c *ProcessorFactory) new(
+ topic string,
+ partition int32,
+ minOffset int64,
+) processor.SpanProcessor {
c.logger.Info("Creating new processors", zap.Int32("partition", partition))
markOffset := func(offset int64) {
c.consumer.MarkPartitionOffset(topic, partition, offset, "")
}
- om := offset.NewManager(minOffset, markOffset, topic, partition, c.metricsFactory)
-
- retryProcessor := decorator.NewRetryingProcessor(c.metricsFactory, c.baseProcessor, c.retryOptions...)
+ om := offset.NewManager(
+ minOffset,
+ markOffset,
+ topic,
+ partition,
+ c.metricsFactory,
+ )
+
+ retryProcessor := decorator.NewRetryingProcessor(
+ c.metricsFactory,
+ c.baseProcessor,
+ c.retryOptions...)
cp := NewCommittingProcessor(retryProcessor, om)
spanProcessor := processor.NewDecoratedProcessor(c.metricsFactory, cp)
pp := processor.NewParallelProcessor(spanProcessor, c.parallelism, c.logger)
@@ -90,7 +105,10 @@ type startedProcessor struct {
processor startProcessor
}
-func newStartedProcessor(parallelProcessor startProcessor, services ...service) processor.SpanProcessor {
+func newStartedProcessor(
+ parallelProcessor startProcessor,
+ services ...service,
+) processor.SpanProcessor {
s := &startedProcessor{
services: services,
processor: parallelProcessor,
diff --git a/cmd/ingester/app/consumer/processor_factory_test.go b/cmd/ingester/app/consumer/processor_factory_test.go
index 6fd944bc07e..971cff4968f 100644
--- a/cmd/ingester/app/consumer/processor_factory_test.go
+++ b/cmd/ingester/app/consumer/processor_factory_test.go
@@ -37,7 +37,8 @@ func Test_NewFactory(t *testing.T) {
func Test_new(t *testing.T) {
mockConsumer := &kmocks.Consumer{}
- mockConsumer.On("MarkPartitionOffset", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil)
+ mockConsumer.On("MarkPartitionOffset", mock.Anything, mock.Anything, mock.Anything, mock.Anything).
+ Return(nil)
topic := "coelacanth"
partition := int32(21)
@@ -63,7 +64,14 @@ func Test_new(t *testing.T) {
// This sleep is greater than offset manager's resetInterval to allow it a chance to
// call MarkPartitionOffset.
time.Sleep(150 * time.Millisecond)
- mockConsumer.AssertCalled(t, "MarkPartitionOffset", topic, partition, offset+1, "")
+ mockConsumer.AssertCalled(
+ t,
+ "MarkPartitionOffset",
+ topic,
+ partition,
+ offset+1,
+ "",
+ )
}
type fakeService struct {
diff --git a/cmd/ingester/app/flags.go b/cmd/ingester/app/flags.go
index ac4cbd79ea8..759508a6566 100644
--- a/cmd/ingester/app/flags.go
+++ b/cmd/ingester/app/flags.go
@@ -90,13 +90,15 @@ func AddFlags(flagSet *flag.FlagSet) {
flagSet.Duration(
ConfigPrefix+SuffixDeadlockInterval,
DefaultDeadlockInterval,
- "Interval to check for deadlocks. If no messages gets processed in given time, ingester app will exit. Value of 0 disables deadlock check.")
+ "Interval to check for deadlocks. If no messages gets processed in given time, ingester app will exit. Value of 0 disables deadlock check.",
+ )
// Authentication flags
flagSet.String(
KafkaConsumerConfigPrefix+SuffixBrokers,
DefaultBroker,
- "The comma-separated list of kafka brokers. i.e. '127.0.0.1:9092,0.0.0:1234'")
+ "The comma-separated list of kafka brokers. i.e. '127.0.0.1:9092,0.0.0:1234'",
+ )
flagSet.String(
KafkaConsumerConfigPrefix+SuffixTopic,
DefaultTopic,
@@ -116,29 +118,42 @@ func AddFlags(flagSet *flag.FlagSet) {
flagSet.String(
KafkaConsumerConfigPrefix+SuffixEncoding,
DefaultEncoding,
- fmt.Sprintf(`The encoding of spans ("%s") consumed from kafka`, strings.Join(kafka.AllEncodings, "\", \"")))
+ fmt.Sprintf(
+ `The encoding of spans ("%s") consumed from kafka`,
+ strings.Join(kafka.AllEncodings, "\", \""),
+ ),
+ )
flagSet.String(
KafkaConsumerConfigPrefix+SuffixRackID,
"",
- "Rack identifier for this client. This can be any string value which indicates where this client is located. It corresponds with the broker config `broker.rack`")
+ "Rack identifier for this client. This can be any string value which indicates where this client is located. It corresponds with the broker config `broker.rack`",
+ )
flagSet.Int(
KafkaConsumerConfigPrefix+SuffixFetchMaxMessageBytes,
DefaultFetchMaxMessageBytes,
- "The maximum number of message bytes to fetch from the broker in a single request. So you must be sure this is at least as large as your largest message.")
+ "The maximum number of message bytes to fetch from the broker in a single request. So you must be sure this is at least as large as your largest message.",
+ )
auth.AddFlags(KafkaConsumerConfigPrefix, flagSet)
}
// InitFromViper initializes Builder with properties from viper
func (o *Options) InitFromViper(v *viper.Viper) {
- o.Brokers = strings.Split(stripWhiteSpace(v.GetString(KafkaConsumerConfigPrefix+SuffixBrokers)), ",")
+ o.Brokers = strings.Split(
+ stripWhiteSpace(v.GetString(KafkaConsumerConfigPrefix+SuffixBrokers)),
+ ",",
+ )
o.Topic = v.GetString(KafkaConsumerConfigPrefix + SuffixTopic)
o.GroupID = v.GetString(KafkaConsumerConfigPrefix + SuffixGroupID)
o.ClientID = v.GetString(KafkaConsumerConfigPrefix + SuffixClientID)
- o.ProtocolVersion = v.GetString(KafkaConsumerConfigPrefix + SuffixProtocolVersion)
+ o.ProtocolVersion = v.GetString(
+ KafkaConsumerConfigPrefix + SuffixProtocolVersion,
+ )
o.Encoding = v.GetString(KafkaConsumerConfigPrefix + SuffixEncoding)
o.RackID = v.GetString(KafkaConsumerConfigPrefix + SuffixRackID)
- o.FetchMaxMessageBytes = v.GetInt32(KafkaConsumerConfigPrefix + SuffixFetchMaxMessageBytes)
+ o.FetchMaxMessageBytes = v.GetInt32(
+ KafkaConsumerConfigPrefix + SuffixFetchMaxMessageBytes,
+ )
o.Parallelism = v.GetInt(ConfigPrefix + SuffixParallelism)
o.DeadlockInterval = v.GetDuration(ConfigPrefix + SuffixDeadlockInterval)
diff --git a/cmd/ingester/app/flags_test.go b/cmd/ingester/app/flags_test.go
index bb6cf549014..dae8e9a4574 100644
--- a/cmd/ingester/app/flags_test.go
+++ b/cmd/ingester/app/flags_test.go
@@ -59,31 +59,58 @@ func TestOptionsWithFlags(t *testing.T) {
}
func TestTLSFlags(t *testing.T) {
- kerb := auth.KerberosConfig{ServiceName: "kafka", ConfigPath: "/etc/krb5.conf", KeyTabPath: "/etc/security/kafka.keytab"}
+ kerb := auth.KerberosConfig{
+ ServiceName: "kafka",
+ ConfigPath: "/etc/krb5.conf",
+ KeyTabPath: "/etc/security/kafka.keytab",
+ }
plain := auth.PlainTextConfig{Username: "", Password: "", Mechanism: "PLAIN"}
tests := []struct {
flags []string
expected auth.AuthenticationConfig
}{
{
- flags: []string{},
- expected: auth.AuthenticationConfig{Authentication: "none", Kerberos: kerb, PlainText: plain},
+ flags: []string{},
+ expected: auth.AuthenticationConfig{
+ Authentication: "none",
+ Kerberos: kerb,
+ PlainText: plain,
+ },
},
{
- flags: []string{"--kafka.consumer.authentication=foo"},
- expected: auth.AuthenticationConfig{Authentication: "foo", Kerberos: kerb, PlainText: plain},
+ flags: []string{"--kafka.consumer.authentication=foo"},
+ expected: auth.AuthenticationConfig{
+ Authentication: "foo",
+ Kerberos: kerb,
+ PlainText: plain,
+ },
},
{
- flags: []string{"--kafka.consumer.authentication=kerberos", "--kafka.consumer.tls.enabled=true"},
- expected: auth.AuthenticationConfig{Authentication: "kerberos", Kerberos: kerb, TLS: tlscfg.Options{Enabled: true}, PlainText: plain},
+ flags: []string{"--kafka.consumer.authentication=kerberos", "--kafka.consumer.tls.enabled=true"},
+ expected: auth.AuthenticationConfig{
+ Authentication: "kerberos",
+ Kerberos: kerb,
+ TLS: tlscfg.Options{Enabled: true},
+ PlainText: plain,
+ },
},
{
- flags: []string{"--kafka.consumer.authentication=tls"},
- expected: auth.AuthenticationConfig{Authentication: "tls", Kerberos: kerb, TLS: tlscfg.Options{Enabled: true}, PlainText: plain},
+ flags: []string{"--kafka.consumer.authentication=tls"},
+ expected: auth.AuthenticationConfig{
+ Authentication: "tls",
+ Kerberos: kerb,
+ TLS: tlscfg.Options{Enabled: true},
+ PlainText: plain,
+ },
},
{
- flags: []string{"--kafka.consumer.authentication=tls", "--kafka.consumer.tls.enabled=false"},
- expected: auth.AuthenticationConfig{Authentication: "tls", Kerberos: kerb, TLS: tlscfg.Options{Enabled: true}, PlainText: plain},
+ flags: []string{"--kafka.consumer.authentication=tls", "--kafka.consumer.tls.enabled=false"},
+ expected: auth.AuthenticationConfig{
+ Authentication: "tls",
+ Kerberos: kerb,
+ TLS: tlscfg.Options{Enabled: true},
+ PlainText: plain,
+ },
},
}
diff --git a/cmd/ingester/app/processor/decorator/retry.go b/cmd/ingester/app/processor/decorator/retry.go
index 70733d0f741..460de8a74dc 100644
--- a/cmd/ingester/app/processor/decorator/retry.go
+++ b/cmd/ingester/app/processor/decorator/retry.go
@@ -90,7 +90,11 @@ func PropagateError(b bool) RetryOption {
// NewRetryingProcessor returns a processor that retries failures using an exponential backoff
// with jitter.
-func NewRetryingProcessor(f metrics.Factory, processor processor.SpanProcessor, opts ...RetryOption) processor.SpanProcessor {
+func NewRetryingProcessor(
+ f metrics.Factory,
+ processor processor.SpanProcessor,
+ opts ...RetryOption,
+) processor.SpanProcessor {
options := defaultOpts
for _, opt := range opts {
opt(&options)
@@ -98,10 +102,14 @@ func NewRetryingProcessor(f metrics.Factory, processor processor.SpanProcessor,
m := f.Namespace(metrics.NSOptions{Name: "span-processor", Tags: nil})
return &retryDecorator{
- retryAttempts: m.Counter(metrics.Options{Name: "retry-attempts", Tags: nil}),
- exhausted: m.Counter(metrics.Options{Name: "retry-exhausted", Tags: nil}),
- processor: processor,
- options: options,
+ retryAttempts: m.Counter(
+ metrics.Options{Name: "retry-attempts", Tags: nil},
+ ),
+ exhausted: m.Counter(
+ metrics.Options{Name: "retry-exhausted", Tags: nil},
+ ),
+ processor: processor,
+ options: options,
}
}
diff --git a/cmd/ingester/app/processor/metrics_decorator.go b/cmd/ingester/app/processor/metrics_decorator.go
index 2983d2f6400..c6173d172bb 100644
--- a/cmd/ingester/app/processor/metrics_decorator.go
+++ b/cmd/ingester/app/processor/metrics_decorator.go
@@ -29,7 +29,10 @@ type metricsDecorator struct {
}
// NewDecoratedProcessor returns a processor with metrics
-func NewDecoratedProcessor(f metrics.Factory, processor SpanProcessor) SpanProcessor {
+func NewDecoratedProcessor(
+ f metrics.Factory,
+ processor SpanProcessor,
+) SpanProcessor {
m := f.Namespace(metrics.NSOptions{Name: "span-processor", Tags: nil})
return &metricsDecorator{
errors: m.Counter(metrics.Options{Name: "errors", Tags: nil}),
diff --git a/cmd/ingester/app/processor/parallel_processor.go b/cmd/ingester/app/processor/parallel_processor.go
index 60885a134b3..1aff073c585 100644
--- a/cmd/ingester/app/processor/parallel_processor.go
+++ b/cmd/ingester/app/processor/parallel_processor.go
@@ -48,7 +48,10 @@ func NewParallelProcessor(
// Start begins processing queued messages
func (k *ParallelProcessor) Start() {
- k.logger.Debug("Spawning goroutines to process messages", zap.Int("num_routines", k.numRoutines))
+ k.logger.Debug(
+ "Spawning goroutines to process messages",
+ zap.Int("num_routines", k.numRoutines),
+ )
for i := 0; i < k.numRoutines; i++ {
k.wg.Add(1)
go func() {
diff --git a/cmd/ingester/app/processor/span_processor.go b/cmd/ingester/app/processor/span_processor.go
index 4817103384b..fdb8d2228b1 100644
--- a/cmd/ingester/app/processor/span_processor.go
+++ b/cmd/ingester/app/processor/span_processor.go
@@ -56,7 +56,8 @@ func NewSpanProcessor(params SpanProcessorParams) *KafkaSpanProcessor {
return &KafkaSpanProcessor{
unmarshaller: params.Unmarshaller,
writer: params.Writer,
- sanitizer: sanitizer.NewChainedSanitizer(sanitizer.NewStandardSanitizers()...),
+ sanitizer: sanitizer.NewChainedSanitizer(
+ sanitizer.NewStandardSanitizers()...),
}
}
diff --git a/cmd/ingester/app/processor/span_processor_test.go b/cmd/ingester/app/processor/span_processor_test.go
index 40b433a36c9..195c7d0c8ed 100644
--- a/cmd/ingester/app/processor/span_processor_test.go
+++ b/cmd/ingester/app/processor/span_processor_test.go
@@ -54,7 +54,11 @@ func TestSpanProcessor_Process(t *testing.T) {
Return(nil).
Run(func(args mock.Arguments) {
span := args[1].(*model.Span)
- assert.NotNil(t, span.Process, "sanitizer must fix Process=nil data issue")
+ assert.NotNil(
+ t,
+ span.Process,
+ "sanitizer must fix Process=nil data issue",
+ )
})
require.NoError(t, processor.Process(message))
diff --git a/cmd/ingester/main.go b/cmd/ingester/main.go
index c4680edda68..7383a7646d4 100644
--- a/cmd/ingester/main.go
+++ b/cmd/ingester/main.go
@@ -42,7 +42,9 @@ import (
func main() {
svc := flags.NewService(ports.IngesterAdminHTTP)
- storageFactory, err := storage.NewFactory(storage.FactoryConfigFromEnvAndCLI(os.Args, os.Stderr))
+ storageFactory, err := storage.NewFactory(
+ storage.FactoryConfigFromEnvAndCLI(os.Args, os.Stderr),
+ )
if err != nil {
log.Fatalf("Cannot initialize storage factory: %v", err)
}
@@ -57,8 +59,12 @@ func main() {
return err
}
logger := svc.Logger // shortcut
- baseFactory := svc.MetricsFactory.Namespace(metrics.NSOptions{Name: "jaeger"})
- metricsFactory := baseFactory.Namespace(metrics.NSOptions{Name: "ingester"})
+ baseFactory := svc.MetricsFactory.Namespace(
+ metrics.NSOptions{Name: "jaeger"},
+ )
+ metricsFactory := baseFactory.Namespace(
+ metrics.NSOptions{Name: "ingester"},
+ )
version.NewInfoMetrics(metricsFactory)
storageFactory.InitFromViper(v, logger)
@@ -72,7 +78,12 @@ func main() {
options := app.Options{}
options.InitFromViper(v)
- consumer, err := builder.CreateConsumer(logger, metricsFactory, spanWriter, options)
+ consumer, err := builder.CreateConsumer(
+ logger,
+ metricsFactory,
+ spanWriter,
+ options,
+ )
if err != nil {
logger.Fatal("Unable to create consumer", zap.Error(err))
}
@@ -80,7 +91,10 @@ func main() {
svc.RunAndThen(func() {
if err := options.TLS.Close(); err != nil {
- logger.Error("Failed to close TLS certificates watcher", zap.Error(err))
+ logger.Error(
+ "Failed to close TLS certificates watcher",
+ zap.Error(err),
+ )
}
if err = consumer.Close(); err != nil {
logger.Error("Failed to close consumer", zap.Error(err))
@@ -88,11 +102,17 @@ func main() {
if closer, ok := spanWriter.(io.Closer); ok {
err := closer.Close()
if err != nil {
- logger.Error("Failed to close span writer", zap.Error(err))
+ logger.Error(
+ "Failed to close span writer",
+ zap.Error(err),
+ )
}
}
if err := storageFactory.Close(); err != nil {
- logger.Error("Failed to close storage factory", zap.Error(err))
+ logger.Error(
+ "Failed to close storage factory",
+ zap.Error(err),
+ )
}
})
return nil
diff --git a/cmd/internal/docs/command.go b/cmd/internal/docs/command.go
index 47b554ce57b..7567c3cf474 100644
--- a/cmd/internal/docs/command.go
+++ b/cmd/internal/docs/command.go
@@ -54,7 +54,11 @@ func Command(v *viper.Viper) *cobra.Command {
case "yaml":
return doc.GenYamlTree(cmd, dir)
default:
- return fmt.Errorf("undefined value of %v, possible values are: %v", formatFlag, formats)
+ return fmt.Errorf(
+ "undefined value of %v, possible values are: %v",
+ formatFlag,
+ formats,
+ )
}
},
}
diff --git a/cmd/internal/docs/command_test.go b/cmd/internal/docs/command_test.go
index d25dbd8e532..4599a32a6e8 100644
--- a/cmd/internal/docs/command_test.go
+++ b/cmd/internal/docs/command_test.go
@@ -37,7 +37,10 @@ func TestOutputFormats(t *testing.T) {
{file: "docs.1", flag: "--format=man"},
{file: "docs.rst", flag: "--format=rst"},
{file: "docs.yaml", flag: "--format=yaml"},
- {flag: "--format=foo", err: "undefined value of format, possible values are: [md man rst yaml]"},
+ {
+ flag: "--format=foo",
+ err: "undefined value of format, possible values are: [md man rst yaml]",
+ },
}
for _, test := range tests {
v := viper.New()
diff --git a/cmd/internal/env/command.go b/cmd/internal/env/command.go
index c2984d71e2d..f3e2cb468ec 100644
--- a/cmd/internal/env/command.go
+++ b/cmd/internal/env/command.go
@@ -101,7 +101,10 @@ func Command() *cobra.Command {
strings.Join(metrics.AllStorageTypes, ", "),
),
)
- long := fmt.Sprintf(longTemplate, strings.ReplaceAll(fs.FlagUsagesWrapped(0), " --", "\n"))
+ long := fmt.Sprintf(
+ longTemplate,
+ strings.ReplaceAll(fs.FlagUsagesWrapped(0), " --", "\n"),
+ )
return &cobra.Command{
Use: "env",
Short: "Help about environment variables.",
diff --git a/cmd/internal/flags/admin.go b/cmd/internal/flags/admin.go
index ea4df675a04..c06f7a34614 100644
--- a/cmd/internal/flags/admin.go
+++ b/cmd/internal/flags/admin.go
@@ -78,7 +78,15 @@ func (s *AdminServer) setLogger(logger *zap.Logger) {
// AddFlags registers CLI flags.
func (s *AdminServer) AddFlags(flagSet *flag.FlagSet) {
- flagSet.String(adminHTTPHostPort, s.adminHostPort, fmt.Sprintf("The host:port (e.g. 127.0.0.1%s or %s) for the admin server, including health check, /metrics, etc.", s.adminHostPort, s.adminHostPort))
+ flagSet.String(
+ adminHTTPHostPort,
+ s.adminHostPort,
+ fmt.Sprintf(
+ "The host:port (e.g. 127.0.0.1%s or %s) for the admin server, including health check, /metrics, etc.",
+ s.adminHostPort,
+ s.adminHostPort,
+ ),
+ )
tlsAdminHTTPFlagsConfig.AddFlags(flagSet)
}
@@ -93,7 +101,9 @@ func (s *AdminServer) initFromViper(v *viper.Viper, logger *zap.Logger) error {
return fmt.Errorf("failed to parse admin server TLS options: %w", err)
}
if tlsAdminHTTP.Enabled {
- tlsCfg, err := tlsAdminHTTP.Config(s.logger) // This checks if the certificates are correctly provided
+ tlsCfg, err := tlsAdminHTTP.Config(
+ s.logger,
+ ) // This checks if the certificates are correctly provided
if err != nil {
return err
}
@@ -127,7 +137,10 @@ func (s *AdminServer) Serve() error {
}
func (s *AdminServer) serveWithListener(l net.Listener) {
- s.logger.Info("Mounting health check on admin server", zap.String("route", "/"))
+ s.logger.Info(
+ "Mounting health check on admin server",
+ zap.String("route", "/"),
+ )
s.mux.Handle("/", s.hc.Handler())
version.RegisterHandler(s.mux, s.logger)
s.registerPprofHandlers()
@@ -141,7 +154,10 @@ func (s *AdminServer) serveWithListener(l net.Listener) {
if s.tlsCfg != nil {
s.server.TLSConfig = s.tlsCfg
}
- s.logger.Info("Starting admin HTTP server", zap.String("http-addr", s.adminHostPort))
+ s.logger.Info(
+ "Starting admin HTTP server",
+ zap.String("http-addr", s.adminHostPort),
+ )
go func() {
var err error
if s.tlsCfg != nil {
diff --git a/cmd/internal/flags/admin_test.go b/cmd/internal/flags/admin_test.go
index 52b58b87a7a..1fb86f6acd3 100644
--- a/cmd/internal/flags/admin_test.go
+++ b/cmd/internal/flags/admin_test.go
@@ -51,7 +51,12 @@ func TestAdminServerHandlesPortZero(t *testing.T) {
defer adminServer.Close()
message := logs.FilterMessage("Admin server started")
- assert.Equal(t, 1, message.Len(), "Expected Admin server started log message.")
+ assert.Equal(
+ t,
+ 1,
+ message.Len(),
+ "Expected Admin server started log message.",
+ )
onlyEntry := message.All()[0]
hostPort := onlyEntry.ContextMap()["http.host-port"].(string)
@@ -81,7 +86,11 @@ func TestAdminFailToServe(t *testing.T) {
adminServer.serveWithListener(l)
defer adminServer.Close()
- waitForEqual(t, healthcheck.Broken, func() any { return adminServer.HC().Get() })
+ waitForEqual(
+ t,
+ healthcheck.Broken,
+ func() any { return adminServer.HC().Get() },
+ )
logEntries := logs.TakeAll()
var matchedEntry string
@@ -132,7 +141,9 @@ func TestAdminServerTLS(t *testing.T) {
for _, test := range testCases {
t.Run(test.name, func(t *testing.T) {
- adminServer := NewAdminServer(fmt.Sprintf(":%d", ports.CollectorAdminHTTP))
+ adminServer := NewAdminServer(
+ fmt.Sprintf(":%d", ports.CollectorAdminHTTP),
+ )
v, command := config.Viperize(adminServer.AddFlags)
err := command.ParseFlags(test.serverTLSFlags)
@@ -149,7 +160,12 @@ func TestAdminServerTLS(t *testing.T) {
clientTLSCfg, err0 := test.clientTLS.Config(zap.NewNop())
require.NoError(t, err0)
dialer := &net.Dialer{Timeout: 2 * time.Second}
- conn, clientError := tls.DialWithDialer(dialer, "tcp", fmt.Sprintf("localhost:%d", ports.CollectorAdminHTTP), clientTLSCfg)
+ conn, clientError := tls.DialWithDialer(
+ dialer,
+ "tcp",
+ fmt.Sprintf("localhost:%d", ports.CollectorAdminHTTP),
+ clientTLSCfg,
+ )
require.NoError(t, clientError)
require.NoError(t, conn.Close())
@@ -159,7 +175,9 @@ func TestAdminServerTLS(t *testing.T) {
},
}
- response, requestError := client.Get(fmt.Sprintf("https://localhost:%d", ports.CollectorAdminHTTP))
+ response, requestError := client.Get(
+ fmt.Sprintf("https://localhost:%d", ports.CollectorAdminHTTP),
+ )
require.NoError(t, requestError)
require.NotNil(t, response)
})
diff --git a/cmd/internal/flags/flags.go b/cmd/internal/flags/flags.go
index 272ad8dd4fe..af3026d4f8f 100644
--- a/cmd/internal/flags/flags.go
+++ b/cmd/internal/flags/flags.go
@@ -34,7 +34,11 @@ const (
// AddConfigFileFlag adds flags for ExternalConfFlags
func AddConfigFileFlag(flagSet *flag.FlagSet) {
- flagSet.String(configFile, "", "Configuration file in JSON, TOML, YAML, HCL, or Java properties formats (default none). See spf13/viper for precedence.")
+ flagSet.String(
+ configFile,
+ "",
+ "Configuration file in JSON, TOML, YAML, HCL, or Java properties formats (default none). See spf13/viper for precedence.",
+ )
}
// TryLoadConfigFile initializes viper with config file specified as flag
@@ -59,7 +63,12 @@ func ParseJaegerTags(jaegerTags string) map[string]string {
for _, p := range tagPairs {
kv := strings.SplitN(p, "=", 2)
if len(kv) != 2 {
- panic(fmt.Sprintf("invalid Jaeger tag pair %q, expected key=value", p))
+ panic(
+ fmt.Sprintf(
+ "invalid Jaeger tag pair %q, expected key=value",
+ p,
+ ),
+ )
}
k, v := strings.TrimSpace(kv[0]), strings.TrimSpace(kv[1])
@@ -103,13 +112,21 @@ type logging struct {
// AddFlags adds flags for SharedFlags
func AddFlags(flagSet *flag.FlagSet) {
- flagSet.String(spanStorageType, "", "(deprecated) please use SPAN_STORAGE_TYPE environment variable. Run this binary with the 'env' command for help.")
+ flagSet.String(
+ spanStorageType,
+ "",
+ "(deprecated) please use SPAN_STORAGE_TYPE environment variable. Run this binary with the 'env' command for help.",
+ )
AddLoggingFlag(flagSet)
}
// AddLoggingFlag adds logging flag for SharedFlags
func AddLoggingFlag(flagSet *flag.FlagSet) {
- flagSet.String(logLevel, "info", "Minimal allowed log Level. For more levels see https://github.com/uber-go/zap")
+ flagSet.String(
+ logLevel,
+ "info",
+ "Minimal allowed log Level. For more levels see https://github.com/uber-go/zap",
+ )
}
// InitFromViper initializes SharedFlags with properties from viper
@@ -119,7 +136,10 @@ func (flags *SharedFlags) InitFromViper(v *viper.Viper) *SharedFlags {
}
// NewLogger returns logger based on configuration in SharedFlags
-func (flags *SharedFlags) NewLogger(conf zap.Config, options ...zap.Option) (*zap.Logger, error) {
+func (flags *SharedFlags) NewLogger(
+ conf zap.Config,
+ options ...zap.Option,
+) (*zap.Logger, error) {
var level zapcore.Level
err := (&level).UnmarshalText([]byte(flags.Logging.Level))
if err != nil {
diff --git a/cmd/internal/flags/service.go b/cmd/internal/flags/service.go
index 88ae89166c5..3966a837082 100644
--- a/cmd/internal/flags/service.go
+++ b/cmd/internal/flags/service.go
@@ -107,13 +107,19 @@ func (s *Service) Start(v *viper.Viper) error {
}
if h := metricsBuilder.Handler(); h != nil {
route := metricsBuilder.HTTPRoute
- s.Logger.Info("Mounting metrics handler on admin server", zap.String("route", route))
+ s.Logger.Info(
+ "Mounting metrics handler on admin server",
+ zap.String("route", route),
+ )
s.Admin.Handle(route, h)
}
// Mount expvar routes on different backends
if metricsBuilder.Backend != "expvar" {
- s.Logger.Info("Mounting expvar handler on admin server", zap.String("route", "/debug/vars"))
+ s.Logger.Info(
+ "Mounting expvar handler on admin server",
+ zap.String("route", "/debug/vars"),
+ )
s.Admin.Handle("/debug/vars", expvar.Handler())
}
diff --git a/cmd/internal/flags/service_test.go b/cmd/internal/flags/service_test.go
index 0eaf8a10325..d874755fbb2 100644
--- a/cmd/internal/flags/service_test.go
+++ b/cmd/internal/flags/service_test.go
@@ -58,8 +58,11 @@ func TestStartErrors(t *testing.T) {
expErr: "cannot create metrics factory",
},
{
- name: "bad admin TLS",
- flags: []string{"--admin.http.tls.enabled=true", "--admin.http.tls.cert=invalid-cert"},
+ name: "bad admin TLS",
+ flags: []string{
+ "--admin.http.tls.enabled=true",
+ "--admin.http.tls.cert=invalid-cert",
+ },
expErr: "cannot initialize admin server",
},
{
@@ -92,9 +95,17 @@ func TestStartErrors(t *testing.T) {
}
go s.RunAndThen(shutdown)
- waitForEqual(t, healthcheck.Ready, func() any { return s.HC().Get() })
+ waitForEqual(
+ t,
+ healthcheck.Ready,
+ func() any { return s.HC().Get() },
+ )
s.HC().Set(healthcheck.Unavailable)
- waitForEqual(t, healthcheck.Unavailable, func() any { return s.HC().Get() })
+ waitForEqual(
+ t,
+ healthcheck.Unavailable,
+ func() any { return s.HC().Get() },
+ )
s.signalsChannel <- os.Interrupt
waitForEqual(t, true, func() any { return stopped.Load() })
diff --git a/cmd/internal/printconfig/command.go b/cmd/internal/printconfig/command.go
index 4cb83d5a7c0..598d659ef67 100644
--- a/cmd/internal/printconfig/command.go
+++ b/cmd/internal/printconfig/command.go
@@ -16,11 +16,19 @@ func printDivider(cmd *cobra.Command, n int) {
fmt.Fprint(cmd.OutOrStdout(), strings.Repeat("-", n), "\n")
}
-func printConfigurations(cmd *cobra.Command, v *viper.Viper, includeEmpty bool) {
+func printConfigurations(
+ cmd *cobra.Command,
+ v *viper.Viper,
+ includeEmpty bool,
+) {
keys := v.AllKeys()
sort.Strings(keys)
- maxKeyLength, maxValueLength := len("Configuration Option Name"), len("Value")
+ maxKeyLength, maxValueLength := len(
+ "Configuration Option Name",
+ ), len(
+ "Value",
+ )
maxSourceLength := len("user-assigned")
for _, key := range keys {
value := v.GetString(key)
@@ -70,7 +78,8 @@ func Command(v *viper.Viper) *cobra.Command {
return nil
},
}
- cmd.Flags().BoolVarP(&allFlag, "all", "a", false, "Print all configuration options including those with empty values")
+ cmd.Flags().
+ BoolVarP(&allFlag, "all", "a", false, "Print all configuration options including those with empty values")
return cmd
}
diff --git a/cmd/internal/printconfig/command_test.go b/cmd/internal/printconfig/command_test.go
index b02ca23b2d0..dd4b77265d0 100644
--- a/cmd/internal/printconfig/command_test.go
+++ b/cmd/internal/printconfig/command_test.go
@@ -50,7 +50,11 @@ func addFlags(flagSet *flag.FlagSet) {
flagSet.String(testPluginConfigurationFile, "", "")
flagSet.String(testPluginLogLevel, defaultTestPluginLogLevel, "")
flagSet.String(testRemoteServer, "", "")
- flagSet.Duration(testRemoteConnectionTimeout, defaultTestConnectionTimeout, "")
+ flagSet.Duration(
+ testRemoteConnectionTimeout,
+ defaultTestConnectionTimeout,
+ "",
+ )
}
func setConfig(t *testing.T) *viper.Viper {
diff --git a/cmd/internal/status/command.go b/cmd/internal/status/command.go
index a3aef682f13..974d72aec86 100644
--- a/cmd/internal/status/command.go
+++ b/cmd/internal/status/command.go
@@ -50,7 +50,10 @@ func Command(v *viper.Viper, adminPort int) *cobra.Command {
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
if resp.StatusCode != http.StatusOK {
- return fmt.Errorf("abnormal value of http status code: %v", resp.StatusCode)
+ return fmt.Errorf(
+ "abnormal value of http status code: %v",
+ resp.StatusCode,
+ )
}
return nil
},
@@ -63,7 +66,10 @@ func Command(v *viper.Viper, adminPort int) *cobra.Command {
func flags(flagSet *flag.FlagSet, adminPort int) *flag.FlagSet {
adminPortStr := ports.PortToHostPort(adminPort)
flagSet.String(statusHTTPHostPort, adminPortStr, fmt.Sprintf(
- "The host:port (e.g. 127.0.0.1%s or %s) for the health check", adminPortStr, adminPortStr))
+ "The host:port (e.g. 127.0.0.1%s or %s) for the health check",
+ adminPortStr,
+ adminPortStr,
+ ))
return flagSet
}
diff --git a/cmd/internal/status/command_test.go b/cmd/internal/status/command_test.go
index 16dcad59080..3beb91dfd36 100644
--- a/cmd/internal/status/command_test.go
+++ b/cmd/internal/status/command_test.go
@@ -41,7 +41,11 @@ func TestReady(t *testing.T) {
defer ts.Close()
v := viper.New()
cmd := Command(v, 80)
- cmd.ParseFlags([]string{"--status.http.host-port=" + strings.TrimPrefix(ts.URL, "http://")})
+ cmd.ParseFlags(
+ []string{
+ "--status.http.host-port=" + strings.TrimPrefix(ts.URL, "http://"),
+ },
+ )
err := cmd.Execute()
require.NoError(t, err)
}
@@ -51,7 +55,9 @@ func TestOnlyPortConfig(t *testing.T) {
defer ts.Close()
v := viper.New()
cmd := Command(v, 80)
- cmd.ParseFlags([]string{"--status.http.host-port=:" + strings.Split(ts.URL, ":")[len(strings.Split(ts.URL, ":"))-1]})
+ cmd.ParseFlags(
+ []string{"--status.http.host-port=:" + strings.Split(ts.URL, ":")[len(strings.Split(ts.URL, ":"))-1]},
+ )
err := cmd.Execute()
require.NoError(t, err)
}
@@ -61,7 +67,11 @@ func TestUnready(t *testing.T) {
defer ts.Close()
v := viper.New()
cmd := Command(v, 80)
- cmd.ParseFlags([]string{"--status.http.host-port=" + strings.TrimPrefix(ts.URL, "http://")})
+ cmd.ParseFlags(
+ []string{
+ "--status.http.host-port=" + strings.TrimPrefix(ts.URL, "http://"),
+ },
+ )
err := cmd.Execute()
require.Error(t, err)
}
diff --git a/cmd/jaeger/internal/command.go b/cmd/jaeger/internal/command.go
index b53e22e4307..f7e887115cb 100644
--- a/cmd/jaeger/internal/command.go
+++ b/cmd/jaeger/internal/command.go
@@ -57,11 +57,18 @@ func checkConfigAndRun(
) error {
configFlag := cmd.Flag("config")
if !configFlag.Changed {
- log.Print("No '--config' flags detected, using default All-in-One configuration with memory storage.")
- log.Print("To customize All-in-One behavior, pass a proper configuration.")
+ log.Print(
+ "No '--config' flags detected, using default All-in-One configuration with memory storage.",
+ )
+ log.Print(
+ "To customize All-in-One behavior, pass a proper configuration.",
+ )
data, err := getCfg("all-in-one.yaml")
if err != nil {
- return fmt.Errorf("cannot read embedded all-in-one configuration: %w", err)
+ return fmt.Errorf(
+ "cannot read embedded all-in-one configuration: %w",
+ err,
+ )
}
configFlag.Value.Set("yaml:" + string(data))
}
diff --git a/cmd/jaeger/internal/components_test.go b/cmd/jaeger/internal/components_test.go
index 02916f28f04..dadc34b61dd 100644
--- a/cmd/jaeger/internal/components_test.go
+++ b/cmd/jaeger/internal/components_test.go
@@ -77,7 +77,9 @@ func TestGetOtelcolFactories(t *testing.T) {
}
}
-func mockFactoryMap[FACTORY component.Factory](err error) func(factories ...FACTORY) (map[component.Type]FACTORY, error) {
+func mockFactoryMap[FACTORY component.Factory](
+ err error,
+) func(factories ...FACTORY) (map[component.Type]FACTORY, error) {
return func(factories ...FACTORY) (map[component.Type]FACTORY, error) {
return nil, err
}
diff --git a/cmd/jaeger/internal/exporters/storageexporter/exporter.go b/cmd/jaeger/internal/exporters/storageexporter/exporter.go
index 70f682f290a..11035245d19 100644
--- a/cmd/jaeger/internal/exporters/storageexporter/exporter.go
+++ b/cmd/jaeger/internal/exporters/storageexporter/exporter.go
@@ -23,14 +23,20 @@ type storageExporter struct {
spanWriter spanstore.Writer
}
-func newExporter(config *Config, otel component.TelemetrySettings) *storageExporter {
+func newExporter(
+ config *Config,
+ otel component.TelemetrySettings,
+) *storageExporter {
return &storageExporter{
config: config,
logger: otel.Logger,
}
}
-func (exp *storageExporter) start(_ context.Context, host component.Host) error {
+func (exp *storageExporter) start(
+ _ context.Context,
+ host component.Host,
+) error {
f, err := jaegerstorage.GetStorageFactory(exp.config.TraceStorage, host)
if err != nil {
return fmt.Errorf("cannot find storage factory: %w", err)
@@ -48,10 +54,16 @@ func (*storageExporter) close(_ context.Context) error {
return nil
}
-func (exp *storageExporter) pushTraces(ctx context.Context, td ptrace.Traces) error {
+func (exp *storageExporter) pushTraces(
+ ctx context.Context,
+ td ptrace.Traces,
+) error {
batches, err := otlp2jaeger.ProtoFromTraces(td)
if err != nil {
- return fmt.Errorf("cannot transform OTLP traces to Jaeger format: %w", err)
+ return fmt.Errorf(
+ "cannot transform OTLP traces to Jaeger format: %w",
+ err,
+ )
}
var errs []error
for _, batch := range batches {
diff --git a/cmd/jaeger/internal/exporters/storageexporter/exporter_test.go b/cmd/jaeger/internal/exporters/storageexporter/exporter_test.go
index 1934231c943..b8e5b8c56e3 100644
--- a/cmd/jaeger/internal/exporters/storageexporter/exporter_test.go
+++ b/cmd/jaeger/internal/exporters/storageexporter/exporter_test.go
@@ -49,7 +49,10 @@ func (host storageHost) ReportFatalError(err error) {
host.t.Fatal(err)
}
-func (storageHost) GetFactory(_ component.Kind, _ component.Type) component.Factory {
+func (storageHost) GetFactory(
+ _ component.Kind,
+ _ component.Type,
+) component.Factory {
return nil
}
@@ -92,11 +95,15 @@ func TestExporter(t *testing.T) {
err := config.Validate()
require.NoError(t, err)
- tracesExporter, err := exporterFactory.CreateTracesExporter(ctx, exporter.CreateSettings{
- ID: ID,
- TelemetrySettings: telemetrySettings,
- BuildInfo: component.NewDefaultBuildInfo(),
- }, config)
+ tracesExporter, err := exporterFactory.CreateTracesExporter(
+ ctx,
+ exporter.CreateSettings{
+ ID: ID,
+ TelemetrySettings: telemetrySettings,
+ BuildInfo: component.NewDefaultBuildInfo(),
+ },
+ config,
+ )
require.NoError(t, err)
host := makeStorageExtension(t, memstoreName)
@@ -127,7 +134,10 @@ func TestExporter(t *testing.T) {
require.NoError(t, err)
spanReader, err := storageFactory.CreateSpanReader()
require.NoError(t, err)
- requiredTraceID := model.NewTraceID(0, 1) // 00000000000000000000000000000001
+ requiredTraceID := model.NewTraceID(
+ 0,
+ 1,
+ ) // 00000000000000000000000000000001
requiredTrace, err := spanReader.GetTrace(ctx, requiredTraceID)
require.NoError(t, err)
assert.Equal(t, spanID.String(), requiredTrace.Spans[0].SpanID.String())
@@ -151,6 +161,8 @@ func makeStorageExtension(t *testing.T, memstoreName string) storageHost {
err = storageExtension.Start(context.Background(), host)
require.NoError(t, err)
- t.Cleanup(func() { require.NoError(t, storageExtension.Shutdown(context.Background())) })
+ t.Cleanup(
+ func() { require.NoError(t, storageExtension.Shutdown(context.Background())) },
+ )
return host
}
diff --git a/cmd/jaeger/internal/exporters/storageexporter/factory.go b/cmd/jaeger/internal/exporters/storageexporter/factory.go
index 2638a949dbe..ca848bc673a 100644
--- a/cmd/jaeger/internal/exporters/storageexporter/factory.go
+++ b/cmd/jaeger/internal/exporters/storageexporter/factory.go
@@ -24,7 +24,10 @@ func NewFactory() exporter.Factory {
return exporter.NewFactory(
componentType,
createDefaultConfig,
- exporter.WithTraces(createTracesExporter, component.StabilityLevelDevelopment),
+ exporter.WithTraces(
+ createTracesExporter,
+ component.StabilityLevelDevelopment,
+ ),
)
}
@@ -32,12 +35,21 @@ func createDefaultConfig() component.Config {
return &Config{}
}
-func createTracesExporter(ctx context.Context, set exporter.CreateSettings, config component.Config) (exporter.Traces, error) {
+func createTracesExporter(
+ ctx context.Context,
+ set exporter.CreateSettings,
+ config component.Config,
+) (exporter.Traces, error) {
cfg := config.(*Config)
ex := newExporter(cfg, set.TelemetrySettings)
- return exporterhelper.NewTracesExporter(ctx, set, cfg,
+ return exporterhelper.NewTracesExporter(
+ ctx,
+ set,
+ cfg,
ex.pushTraces,
- exporterhelper.WithCapabilities(consumer.Capabilities{MutatesData: false}),
+ exporterhelper.WithCapabilities(
+ consumer.Capabilities{MutatesData: false},
+ ),
// Disable Timeout/RetryOnFailure and SendingQueue
exporterhelper.WithTimeout(exporterhelper.TimeoutSettings{Timeout: 0}),
exporterhelper.WithRetry(configretry.BackOffConfig{Enabled: false}),
diff --git a/cmd/jaeger/internal/extension/jaegerquery/config.go b/cmd/jaeger/internal/extension/jaegerquery/config.go
index e5640c2710b..307ba16b091 100644
--- a/cmd/jaeger/internal/extension/jaegerquery/config.go
+++ b/cmd/jaeger/internal/extension/jaegerquery/config.go
@@ -20,8 +20,8 @@ type Config struct {
TraceStoragePrimary string `valid:"required" mapstructure:"trace_storage"`
TraceStorageArchive string `valid:"optional" mapstructure:"trace_storage_archive"`
- confighttp.ServerConfig `mapstructure:",squash"`
- Tenancy tenancy.Options `mapstructure:"multi_tenancy"`
+ confighttp.ServerConfig ` mapstructure:",squash"`
+ Tenancy tenancy.Options ` mapstructure:"multi_tenancy"`
}
func (cfg *Config) Validate() error {
diff --git a/cmd/jaeger/internal/extension/jaegerquery/factory.go b/cmd/jaeger/internal/extension/jaegerquery/factory.go
index fcaaf2e6b3e..07384e5fc30 100644
--- a/cmd/jaeger/internal/extension/jaegerquery/factory.go
+++ b/cmd/jaeger/internal/extension/jaegerquery/factory.go
@@ -20,7 +20,12 @@ var componentType = component.MustNewType("jaeger_query")
var ID = component.NewID(componentType)
func NewFactory() extension.Factory {
- return extension.NewFactory(componentType, createDefaultConfig, createExtension, component.StabilityLevelBeta)
+ return extension.NewFactory(
+ componentType,
+ createDefaultConfig,
+ createExtension,
+ component.StabilityLevelBeta,
+ )
}
func createDefaultConfig() component.Config {
@@ -32,6 +37,10 @@ func createDefaultConfig() component.Config {
}
// createExtension creates the extension based on this config.
-func createExtension(_ context.Context, set extension.CreateSettings, cfg component.Config) (extension.Extension, error) {
+func createExtension(
+ _ context.Context,
+ set extension.CreateSettings,
+ cfg component.Config,
+) (extension.Extension, error) {
return newServer(cfg.(*Config), set.TelemetrySettings), nil
}
diff --git a/cmd/jaeger/internal/extension/jaegerquery/server.go b/cmd/jaeger/internal/extension/jaegerquery/server.go
index 9a07f1089bf..a2e8adf3a0c 100644
--- a/cmd/jaeger/internal/extension/jaegerquery/server.go
+++ b/cmd/jaeger/internal/extension/jaegerquery/server.go
@@ -47,9 +47,16 @@ func (*server) Dependencies() []component.ID {
}
func (s *server) Start(ctx context.Context, host component.Host) error {
- f, err := jaegerstorage.GetStorageFactory(s.config.TraceStoragePrimary, host)
+ f, err := jaegerstorage.GetStorageFactory(
+ s.config.TraceStoragePrimary,
+ host,
+ )
if err != nil {
- return fmt.Errorf("cannot find primary storage %s: %w", s.config.TraceStoragePrimary, err)
+ return fmt.Errorf(
+ "cannot find primary storage %s: %w",
+ s.config.TraceStoragePrimary,
+ err,
+ )
}
spanReader, err := f.CreateSpanReader()
@@ -103,13 +110,19 @@ func (s *server) Start(ctx context.Context, host component.Host) error {
return nil
}
-func (s *server) addArchiveStorage(opts *querysvc.QueryServiceOptions, host component.Host) error {
+func (s *server) addArchiveStorage(
+ opts *querysvc.QueryServiceOptions,
+ host component.Host,
+) error {
if s.config.TraceStorageArchive == "" {
s.logger.Info("Archive storage not configured")
return nil
}
- f, err := jaegerstorage.GetStorageFactory(s.config.TraceStorageArchive, host)
+ f, err := jaegerstorage.GetStorageFactory(
+ s.config.TraceStorageArchive,
+ host,
+ )
if err != nil {
return fmt.Errorf("cannot find archive storage factory: %w", err)
}
diff --git a/cmd/jaeger/internal/extension/jaegerquery/server_test.go b/cmd/jaeger/internal/extension/jaegerquery/server_test.go
index cbf8d2ceaca..72bed6bf3af 100644
--- a/cmd/jaeger/internal/extension/jaegerquery/server_test.go
+++ b/cmd/jaeger/internal/extension/jaegerquery/server_test.go
@@ -90,7 +90,10 @@ func (host storageHost) GetExtensions() map[component.ID]component.Component {
}
}
-func (storageHost) GetFactory(_ component.Kind, _ component.Type) component.Factory {
+func (storageHost) GetFactory(
+ _ component.Kind,
+ _ component.Type,
+) component.Factory {
return nil
}
@@ -160,7 +163,10 @@ func TestServerStart(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
telemetrySettings := component.TelemetrySettings{
- Logger: zaptest.NewLogger(t, zaptest.WrapOptions(zap.AddCaller())),
+ Logger: zaptest.NewLogger(
+ t,
+ zaptest.WrapOptions(zap.AddCaller()),
+ ),
}
server := newServer(tt.config, telemetrySettings)
err := server.Start(context.Background(), host)
diff --git a/cmd/jaeger/internal/extension/jaegerstorage/extension.go b/cmd/jaeger/internal/extension/jaegerstorage/extension.go
index 59a1680cb34..1882ad173d4 100644
--- a/cmd/jaeger/internal/extension/jaegerstorage/extension.go
+++ b/cmd/jaeger/internal/extension/jaegerstorage/extension.go
@@ -38,7 +38,10 @@ type storageExt struct {
}
// GetStorageFactory locates the extension in Host and retrieves a storage factory from it with the given name.
-func GetStorageFactory(name string, host component.Host) (storage.Factory, error) {
+func GetStorageFactory(
+ name string,
+ host component.Host,
+) (storage.Factory, error) {
var comp component.Component
for id, ext := range host.GetExtensions() {
if id.Type() == componentType {
@@ -62,7 +65,10 @@ func GetStorageFactory(name string, host component.Host) (storage.Factory, error
return f, nil
}
-func newStorageExt(config *Config, otel component.TelemetrySettings) *storageExt {
+func newStorageExt(
+ config *Config,
+ otel component.TelemetrySettings,
+) *storageExt {
return &storageExt{
config: config,
logger: otel.Logger,
@@ -77,10 +83,17 @@ type starter[Config any, Factory storage.Factory] struct {
builder func(Config, metrics.Factory, *zap.Logger) (Factory, error)
}
-func (s *starter[Config, Factory]) build(_ context.Context, _ component.Host) error {
+func (s *starter[Config, Factory]) build(
+ _ context.Context,
+ _ component.Host,
+) error {
for name, cfg := range s.cfg {
if _, ok := s.ext.factories[name]; ok {
- return fmt.Errorf("duplicate %s storage name %s", s.storageKind, name)
+ return fmt.Errorf(
+ "duplicate %s storage name %s",
+ s.storageKind,
+ name,
+ )
}
factory, err := s.builder(
cfg,
@@ -88,7 +101,12 @@ func (s *starter[Config, Factory]) build(_ context.Context, _ component.Host) er
s.ext.logger.With(zap.String("storage_name", name)),
)
if err != nil {
- return fmt.Errorf("failed to initialize %s storage %s: %w", s.storageKind, name, err)
+ return fmt.Errorf(
+ "failed to initialize %s storage %s: %w",
+ s.storageKind,
+ name,
+ err,
+ )
}
s.ext.factories[name] = factory
}
diff --git a/cmd/jaeger/internal/extension/jaegerstorage/extension_test.go b/cmd/jaeger/internal/extension/jaegerstorage/extension_test.go
index 4a50b002303..1b4415dc707 100644
--- a/cmd/jaeger/internal/extension/jaegerstorage/extension_test.go
+++ b/cmd/jaeger/internal/extension/jaegerstorage/extension_test.go
@@ -43,7 +43,13 @@ func (host storageHost) ReportFatalError(err error) {
host.t.Fatal(err)
}
-func (storageHost) GetFactory(_ component.Kind, _ component.Type) component.Factory { return nil }
+func (storageHost) GetFactory(
+ _ component.Kind,
+ _ component.Type,
+) component.Factory {
+ return nil
+}
+
func (storageHost) GetExporters() map[component.DataType]map[component.ID]component.Component {
return nil
}
@@ -52,7 +58,10 @@ type errorFactory struct {
closeErr error
}
-func (errorFactory) Initialize(metricsFactory metrics.Factory, logger *zap.Logger) error {
+func (errorFactory) Initialize(
+ metricsFactory metrics.Factory,
+ logger *zap.Logger,
+) error {
panic("not implemented")
}
@@ -87,7 +96,10 @@ func TestStorageExtensionNameConflict(t *testing.T) {
"foo": {},
},
})
- err := storageExtension.Start(context.Background(), componenttest.NewNopHost())
+ err := storageExtension.Start(
+ context.Background(),
+ componenttest.NewNopHost(),
+ )
require.ErrorContains(t, err, "duplicate")
}
@@ -160,9 +172,11 @@ func TestESStorageExtension(t *testing.T) {
}
}
`)
- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- w.Write(mockEsServerResponse)
- }))
+ server := httptest.NewServer(
+ http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ w.Write(mockEsServerResponse)
+ }),
+ )
defer server.Close()
storageExtension := makeStorageExtenion(t, &Config{
Elasticsearch: map[string]esCfg.Configuration{
@@ -217,7 +231,10 @@ func makeStorageExtenion(t *testing.T, config *Config) component.Component {
return storageExtension
}
-func startStorageExtension(t *testing.T, memstoreName string) component.Component {
+func startStorageExtension(
+ t *testing.T,
+ memstoreName string,
+) component.Component {
config := &Config{
Memory: map[string]memoryCfg.Configuration{
memstoreName: {MaxTraces: 10000},
@@ -226,7 +243,10 @@ func startStorageExtension(t *testing.T, memstoreName string) component.Componen
require.NoError(t, config.Validate())
storageExtension := makeStorageExtenion(t, config)
- err := storageExtension.Start(context.Background(), componenttest.NewNopHost())
+ err := storageExtension.Start(
+ context.Background(),
+ componenttest.NewNopHost(),
+ )
require.NoError(t, err)
t.Cleanup(func() {
require.NoError(t, storageExtension.Shutdown(context.Background()))
diff --git a/cmd/jaeger/internal/extension/jaegerstorage/factory.go b/cmd/jaeger/internal/extension/jaegerstorage/factory.go
index aef19427e12..db6a9052750 100644
--- a/cmd/jaeger/internal/extension/jaegerstorage/factory.go
+++ b/cmd/jaeger/internal/extension/jaegerstorage/factory.go
@@ -30,6 +30,10 @@ func createDefaultConfig() component.Config {
}
// createExtension creates the extension based on this config.
-func createExtension(_ context.Context, set extension.CreateSettings, cfg component.Config) (extension.Extension, error) {
+func createExtension(
+ _ context.Context,
+ set extension.CreateSettings,
+ cfg component.Config,
+) (extension.Extension, error) {
return newStorageExt(cfg.(*Config), set.TelemetrySettings), nil
}
diff --git a/cmd/jaeger/internal/integration/e2e_integration.go b/cmd/jaeger/internal/integration/e2e_integration.go
index 9b803050904..b473956a5eb 100644
--- a/cmd/jaeger/internal/integration/e2e_integration.go
+++ b/cmd/jaeger/internal/integration/e2e_integration.go
@@ -47,7 +47,10 @@ type E2EStorageIntegration struct {
func (s *E2EStorageIntegration) e2eInitialize(t *testing.T, storage string) {
logger := zaptest.NewLogger(t, zaptest.WrapOptions(zap.AddCaller()))
configFile := createStorageCleanerConfig(t, s.ConfigFile, storage)
- t.Logf("Starting Jaeger-v2 in the background with config file %s", configFile)
+ t.Logf(
+ "Starting Jaeger-v2 in the background with config file %s",
+ configFile,
+ )
outFile, err := os.OpenFile(
filepath.Join(t.TempDir(), "jaeger_output_logs.txt"),
@@ -124,7 +127,11 @@ func (s *E2EStorageIntegration) e2eCleanUp(t *testing.T) {
require.NoError(t, s.SpanWriter.(io.Closer).Close())
}
-func createStorageCleanerConfig(t *testing.T, configFile string, storage string) string {
+func createStorageCleanerConfig(
+ t *testing.T,
+ configFile string,
+ storage string,
+) string {
data, err := os.ReadFile(configFile)
require.NoError(t, err)
var config map[string]any
@@ -133,14 +140,19 @@ func createStorageCleanerConfig(t *testing.T, configFile string, storage string)
service, ok := config["service"].(map[string]any)
require.True(t, ok)
- service["extensions"] = append(service["extensions"].([]any), "storage_cleaner")
+ service["extensions"] = append(
+ service["extensions"].([]any),
+ "storage_cleaner",
+ )
extensions, ok := config["extensions"].(map[string]any)
require.True(t, ok)
query, ok := extensions["jaeger_query"].(map[string]any)
require.True(t, ok)
trace_storage := query["trace_storage"].(string)
- extensions["storage_cleaner"] = map[string]string{"trace_storage": trace_storage}
+ extensions["storage_cleaner"] = map[string]string{
+ "trace_storage": trace_storage,
+ }
jaegerStorage, ok := extensions["jaeger_storage"].(map[string]any)
require.True(t, ok)
@@ -174,8 +186,17 @@ func createStorageCleanerConfig(t *testing.T, configFile string, storage string)
}
func purge(t *testing.T) {
- addr := fmt.Sprintf("http://0.0.0.0:%s%s", storagecleaner.Port, storagecleaner.URL)
- r, err := http.NewRequestWithContext(context.Background(), http.MethodPost, addr, nil)
+ addr := fmt.Sprintf(
+ "http://0.0.0.0:%s%s",
+ storagecleaner.Port,
+ storagecleaner.URL,
+ )
+ r, err := http.NewRequestWithContext(
+ context.Background(),
+ http.MethodPost,
+ addr,
+ nil,
+ )
require.NoError(t, err)
client := &http.Client{}
diff --git a/cmd/jaeger/internal/integration/es_test.go b/cmd/jaeger/internal/integration/es_test.go
index 92b9f0c79e0..fa713f8e491 100644
--- a/cmd/jaeger/internal/integration/es_test.go
+++ b/cmd/jaeger/internal/integration/es_test.go
@@ -15,8 +15,11 @@ func TestESStorage(t *testing.T) {
s := &E2EStorageIntegration{
ConfigFile: "../../config-elasticsearch.yaml",
StorageIntegration: integration.StorageIntegration{
- CleanUp: purge,
- Fixtures: integration.LoadAndParseQueryTestCases(t, "fixtures/queries_es.json"),
+ CleanUp: purge,
+ Fixtures: integration.LoadAndParseQueryTestCases(
+ t,
+ "fixtures/queries_es.json",
+ ),
GetOperationsMissingSpanKind: true,
},
}
diff --git a/cmd/jaeger/internal/integration/os_test.go b/cmd/jaeger/internal/integration/os_test.go
index a5d3e945214..d4de50cee78 100644
--- a/cmd/jaeger/internal/integration/os_test.go
+++ b/cmd/jaeger/internal/integration/os_test.go
@@ -14,8 +14,11 @@ func TestOSStorage(t *testing.T) {
s := &E2EStorageIntegration{
ConfigFile: "../../config-opensearch.yaml",
StorageIntegration: integration.StorageIntegration{
- CleanUp: purge,
- Fixtures: integration.LoadAndParseQueryTestCases(t, "fixtures/queries_es.json"),
+ CleanUp: purge,
+ Fixtures: integration.LoadAndParseQueryTestCases(
+ t,
+ "fixtures/queries_es.json",
+ ),
GetOperationsMissingSpanKind: true,
},
}
diff --git a/cmd/jaeger/internal/integration/receivers/storagereceiver/config.go b/cmd/jaeger/internal/integration/receivers/storagereceiver/config.go
index e9319b8991d..db74c06d9a9 100644
--- a/cmd/jaeger/internal/integration/receivers/storagereceiver/config.go
+++ b/cmd/jaeger/internal/integration/receivers/storagereceiver/config.go
@@ -11,7 +11,7 @@ import (
type Config struct {
TraceStorage string `valid:"required" mapstructure:"trace_storage"`
- PullInterval time.Duration `mapstructure:"pull_interval"`
+ PullInterval time.Duration ` mapstructure:"pull_interval"`
}
func (cfg *Config) Validate() error {
diff --git a/cmd/jaeger/internal/integration/receivers/storagereceiver/config_test.go b/cmd/jaeger/internal/integration/receivers/storagereceiver/config_test.go
index a347c276450..2e26d109293 100644
--- a/cmd/jaeger/internal/integration/receivers/storagereceiver/config_test.go
+++ b/cmd/jaeger/internal/integration/receivers/storagereceiver/config_test.go
@@ -56,7 +56,11 @@ func TestLoadConfig(t *testing.T) {
require.NoError(t, component.UnmarshalConfig(sub, cfg))
if tt.expectedErr != nil {
- require.ErrorContains(t, component.ValidateConfig(cfg), tt.expectedErr.Error())
+ require.ErrorContains(
+ t,
+ component.ValidateConfig(cfg),
+ tt.expectedErr.Error(),
+ )
} else {
require.NoError(t, component.ValidateConfig(cfg))
assert.Equal(t, tt.expected, cfg)
diff --git a/cmd/jaeger/internal/integration/receivers/storagereceiver/factory.go b/cmd/jaeger/internal/integration/receivers/storagereceiver/factory.go
index 9163583b102..dbfda8f04c0 100644
--- a/cmd/jaeger/internal/integration/receivers/storagereceiver/factory.go
+++ b/cmd/jaeger/internal/integration/receivers/storagereceiver/factory.go
@@ -21,7 +21,10 @@ func NewFactory() receiver.Factory {
return receiver.NewFactory(
componentType,
createDefaultConfig,
- receiver.WithTraces(createTracesReceiver, component.StabilityLevelDevelopment),
+ receiver.WithTraces(
+ createTracesReceiver,
+ component.StabilityLevelDevelopment,
+ ),
)
}
@@ -29,7 +32,12 @@ func createDefaultConfig() component.Config {
return &Config{}
}
-func createTracesReceiver(ctx context.Context, set receiver.CreateSettings, config component.Config, nextConsumer consumer.Traces) (receiver.Traces, error) {
+func createTracesReceiver(
+ ctx context.Context,
+ set receiver.CreateSettings,
+ config component.Config,
+ nextConsumer consumer.Traces,
+) (receiver.Traces, error) {
cfg := config.(*Config)
return newTracesReceiver(cfg, set, nextConsumer)
diff --git a/cmd/jaeger/internal/integration/receivers/storagereceiver/factory_test.go b/cmd/jaeger/internal/integration/receivers/storagereceiver/factory_test.go
index a697a1ec4aa..49d223c0539 100644
--- a/cmd/jaeger/internal/integration/receivers/storagereceiver/factory_test.go
+++ b/cmd/jaeger/internal/integration/receivers/storagereceiver/factory_test.go
@@ -22,7 +22,12 @@ func TestCreateDefaultConfig(t *testing.T) {
func TestCreateTracesReceiver(t *testing.T) {
cfg := createDefaultConfig().(*Config)
f := NewFactory()
- r, err := f.CreateTracesReceiver(context.Background(), receivertest.NewNopCreateSettings(), cfg, nil)
+ r, err := f.CreateTracesReceiver(
+ context.Background(),
+ receivertest.NewNopCreateSettings(),
+ cfg,
+ nil,
+ )
require.NoError(t, err)
assert.NotNil(t, r)
}
diff --git a/cmd/jaeger/internal/integration/receivers/storagereceiver/receiver.go b/cmd/jaeger/internal/integration/receivers/storagereceiver/receiver.go
index 1e8400660ca..ef0bc24d4d5 100644
--- a/cmd/jaeger/internal/integration/receivers/storagereceiver/receiver.go
+++ b/cmd/jaeger/internal/integration/receivers/storagereceiver/receiver.go
@@ -32,7 +32,11 @@ type consumedTrace struct {
spanIDs map[model.SpanID]struct{}
}
-func newTracesReceiver(config *Config, set receiver.CreateSettings, nextConsumer consumer.Traces) (*storageReceiver, error) {
+func newTracesReceiver(
+ config *Config,
+ set receiver.CreateSettings,
+ nextConsumer consumer.Traces,
+) (*storageReceiver, error) {
return &storageReceiver{
config: config,
settings: set,
@@ -41,7 +45,10 @@ func newTracesReceiver(config *Config, set receiver.CreateSettings, nextConsumer
}, nil
}
-func (r *storageReceiver) Start(ctx context.Context, host component.Host) error {
+func (r *storageReceiver) Start(
+ ctx context.Context,
+ host component.Host,
+) error {
f, err := jaegerstorage.GetStorageFactory(r.config.TraceStorage, host)
if err != nil {
return fmt.Errorf("cannot find storage factory: %w", err)
@@ -67,13 +74,19 @@ func (r *storageReceiver) consumeLoop(ctx context.Context) error {
for {
services, err := r.spanReader.GetServices(ctx)
if err != nil {
- r.settings.Logger.Error("Failed to get services from consumer", zap.Error(err))
+ r.settings.Logger.Error(
+ "Failed to get services from consumer",
+ zap.Error(err),
+ )
return err
}
for _, svc := range services {
if err := r.consumeTraces(ctx, svc); err != nil {
- r.settings.Logger.Error("Failed to consume traces from consumer", zap.Error(err))
+ r.settings.Logger.Error(
+ "Failed to consume traces from consumer",
+ zap.Error(err),
+ )
}
}
@@ -87,7 +100,10 @@ func (r *storageReceiver) consumeLoop(ctx context.Context) error {
}
}
-func (r *storageReceiver) consumeTraces(ctx context.Context, serviceName string) error {
+func (r *storageReceiver) consumeTraces(
+ ctx context.Context,
+ serviceName string,
+) error {
endTime := time.Now()
traces, err := r.spanReader.FindTraces(ctx, &spanstore.TraceQueryParameters{
ServiceName: serviceName,
@@ -111,7 +127,11 @@ func (r *storageReceiver) consumeTraces(ctx context.Context, serviceName string)
return nil
}
-func (r *storageReceiver) consumeSpans(ctx context.Context, tc *consumedTrace, spans []*model.Span) error {
+func (r *storageReceiver) consumeSpans(
+ ctx context.Context,
+ tc *consumedTrace,
+ spans []*model.Span,
+) error {
// Spans are consumed one at a time because we don't know whether all spans
// in a trace have been completely exported
for _, span := range spans {
diff --git a/cmd/jaeger/internal/integration/receivers/storagereceiver/receiver_test.go b/cmd/jaeger/internal/integration/receivers/storagereceiver/receiver_test.go
index 393d2082e48..42789a5baae 100644
--- a/cmd/jaeger/internal/integration/receivers/storagereceiver/receiver_test.go
+++ b/cmd/jaeger/internal/integration/receivers/storagereceiver/receiver_test.go
@@ -152,7 +152,8 @@ func TestReceiver_GetServiceError(t *testing.T) {
receiveName: "external-storage",
}
withReceiver(r, func(r *receiverTest) {
- r.reader.On("GetServices", mock.AnythingOfType("*context.cancelCtx")).Return([]string{}, errors.New("mocked error"))
+ r.reader.On("GetServices", mock.AnythingOfType("*context.cancelCtx")).
+ Return([]string{}, errors.New("mocked error"))
r.factory.On("CreateSpanReader").Return(r.reader, nil)
r.receiver.spanReader = r.reader
r.reportStatus = func(se *component.StatusEvent) {
@@ -176,7 +177,8 @@ func TestReceiver_Start(t *testing.T) {
receiveInterval: 50 * time.Millisecond,
}
withReceiver(r, func(r *receiverTest) {
- r.reader.On("GetServices", mock.AnythingOfType("*context.cancelCtx")).Return([]string{}, nil)
+ r.reader.On("GetServices", mock.AnythingOfType("*context.cancelCtx")).
+ Return([]string{}, nil)
r.factory.On("CreateSpanReader").Return(r.reader, nil)
require.NoError(t, r.receiver.Start(context.Background(), r.host))
@@ -252,7 +254,8 @@ func TestReceiver_StartConsume(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
reader := new(spanStoreMocks.Reader)
- reader.On("GetServices", mock.AnythingOfType("*context.cancelCtx")).Return(test.services, nil)
+ reader.On("GetServices", mock.AnythingOfType("*context.cancelCtx")).
+ Return(test.services, nil)
reader.On(
"FindTraces",
mock.AnythingOfType("*context.cancelCtx"),
diff --git a/cmd/jaeger/internal/integration/span_reader.go b/cmd/jaeger/internal/integration/span_reader.go
index 14db12312b4..9dd0c75798f 100644
--- a/cmd/jaeger/internal/integration/span_reader.go
+++ b/cmd/jaeger/internal/integration/span_reader.go
@@ -66,7 +66,10 @@ func unwrapNotFoundErr(err error) error {
return err
}
-func (r *spanReader) GetTrace(ctx context.Context, traceID model.TraceID) (*model.Trace, error) {
+func (r *spanReader) GetTrace(
+ ctx context.Context,
+ traceID model.TraceID,
+) (*model.Trace, error) {
stream, err := r.client.GetTrace(ctx, &api_v2.GetTraceRequest{
TraceID: traceID,
})
@@ -84,7 +87,9 @@ func (r *spanReader) GetTrace(ctx context.Context, traceID model.TraceID) (*mode
}
// r.logger.Info(fmt.Sprintf("GetTrace received %d spans (total %d)", len(received.Spans), len(spans)))
}
- r.logger.Info(fmt.Sprintf("GetTraces received a total of %d spans", len(spans)))
+ r.logger.Info(
+ fmt.Sprintf("GetTraces received a total of %d spans", len(spans)),
+ )
return &model.Trace{
Spans: spans,
@@ -100,7 +105,10 @@ func (r *spanReader) GetServices(ctx context.Context) ([]string, error) {
return res.Services, nil
}
-func (r *spanReader) GetOperations(ctx context.Context, query spanstore.OperationQueryParameters) ([]spanstore.Operation, error) {
+func (r *spanReader) GetOperations(
+ ctx context.Context,
+ query spanstore.OperationQueryParameters,
+) ([]spanstore.Operation, error) {
var operations []spanstore.Operation
res, err := r.client.GetOperations(ctx, &api_v2.GetOperationsRequest{
Service: query.ServiceName,
@@ -120,11 +128,17 @@ func (r *spanReader) GetOperations(ctx context.Context, query spanstore.Operatio
return operations, nil
}
-func (r *spanReader) FindTraces(ctx context.Context, query *spanstore.TraceQueryParameters) ([]*model.Trace, error) {
+func (r *spanReader) FindTraces(
+ ctx context.Context,
+ query *spanstore.TraceQueryParameters,
+) ([]*model.Trace, error) {
var traces []*model.Trace
if query.NumTraces > math.MaxInt32 {
- return traces, fmt.Errorf("NumTraces must not greater than %d", math.MaxInt32)
+ return traces, fmt.Errorf(
+ "NumTraces must not greater than %d",
+ math.MaxInt32,
+ )
}
stream, err := r.client.FindTraces(ctx, &api_v2.FindTracesRequest{
Query: &api_v2.TraceQueryParameters{
@@ -156,9 +170,17 @@ func (r *spanReader) FindTraces(ctx context.Context, query *spanstore.TraceQuery
spanMaps[traceID] = append(spanMaps[traceID], &received.Spans[i])
}
totalSpans += len(received.Spans)
- r.logger.Info(fmt.Sprintf("FindTraces received %d spans (total %d)", len(received.Spans), totalSpans))
+ r.logger.Info(
+ fmt.Sprintf(
+ "FindTraces received %d spans (total %d)",
+ len(received.Spans),
+ totalSpans,
+ ),
+ )
}
- r.logger.Info(fmt.Sprintf("FindTraces received a total of %d spans", totalSpans))
+ r.logger.Info(
+ fmt.Sprintf("FindTraces received a total of %d spans", totalSpans),
+ )
for _, spans := range spanMaps {
traces = append(traces, &model.Trace{
@@ -168,6 +190,9 @@ func (r *spanReader) FindTraces(ctx context.Context, query *spanstore.TraceQuery
return traces, nil
}
-func (*spanReader) FindTraceIDs(ctx context.Context, query *spanstore.TraceQueryParameters) ([]model.TraceID, error) {
+func (*spanReader) FindTraceIDs(
+ ctx context.Context,
+ query *spanstore.TraceQueryParameters,
+) ([]model.TraceID, error) {
panic("not implemented")
}
diff --git a/cmd/jaeger/internal/integration/span_writer.go b/cmd/jaeger/internal/integration/span_writer.go
index 60c817cdf0e..de6f3810196 100644
--- a/cmd/jaeger/internal/integration/span_writer.go
+++ b/cmd/jaeger/internal/integration/span_writer.go
@@ -48,7 +48,11 @@ func createSpanWriter(logger *zap.Logger, port int) (*spanWriter, error) {
set := exportertest.NewNopCreateSettings()
set.Logger = logger
- exporter, err := factory.CreateTracesExporter(context.Background(), set, cfg)
+ exporter, err := factory.CreateTracesExporter(
+ context.Background(),
+ set,
+ cfg,
+ )
if err != nil {
return nil, err
}
diff --git a/cmd/jaeger/internal/integration/storagecleaner/config.go b/cmd/jaeger/internal/integration/storagecleaner/config.go
index 5b4c9d30812..02e3aba21d9 100644
--- a/cmd/jaeger/internal/integration/storagecleaner/config.go
+++ b/cmd/jaeger/internal/integration/storagecleaner/config.go
@@ -9,7 +9,7 @@ import (
type Config struct {
TraceStorage string `valid:"required" mapstructure:"trace_storage"`
- Port string `mapstructure:"port"`
+ Port string ` mapstructure:"port"`
}
func (cfg *Config) Validate() error {
diff --git a/cmd/jaeger/internal/integration/storagecleaner/extension.go b/cmd/jaeger/internal/integration/storagecleaner/extension.go
index cdc7b0988c8..c638a59d781 100644
--- a/cmd/jaeger/internal/integration/storagecleaner/extension.go
+++ b/cmd/jaeger/internal/integration/storagecleaner/extension.go
@@ -34,7 +34,10 @@ type storageCleaner struct {
settings component.TelemetrySettings
}
-func newStorageCleaner(config *Config, telemetrySettings component.TelemetrySettings) *storageCleaner {
+func newStorageCleaner(
+ config *Config,
+ telemetrySettings component.TelemetrySettings,
+) *storageCleaner {
return &storageCleaner{
config: config,
settings: telemetrySettings,
@@ -42,15 +45,25 @@ func newStorageCleaner(config *Config, telemetrySettings component.TelemetrySett
}
func (c *storageCleaner) Start(ctx context.Context, host component.Host) error {
- storageFactory, err := jaegerstorage.GetStorageFactory(c.config.TraceStorage, host)
+ storageFactory, err := jaegerstorage.GetStorageFactory(
+ c.config.TraceStorage,
+ host,
+ )
if err != nil {
- return fmt.Errorf("cannot find storage factory '%s': %w", c.config.TraceStorage, err)
+ return fmt.Errorf(
+ "cannot find storage factory '%s': %w",
+ c.config.TraceStorage,
+ err,
+ )
}
purgeStorage := func(httpContext context.Context) error {
purger, ok := storageFactory.(storage.Purger)
if !ok {
- return fmt.Errorf("storage %s does not implement Purger interface", c.config.TraceStorage)
+ return fmt.Errorf(
+ "storage %s does not implement Purger interface",
+ c.config.TraceStorage,
+ )
}
if err := purger.Purge(httpContext); err != nil {
return fmt.Errorf("error purging storage: %w", err)
@@ -75,7 +88,8 @@ func (c *storageCleaner) Start(ctx context.Context, host component.Host) error {
ReadHeaderTimeout: 3 * time.Second,
}
go func() {
- if err := c.server.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
+ if err := c.server.ListenAndServe(); err != nil &&
+ !errors.Is(err, http.ErrServerClosed) {
err = fmt.Errorf("error starting cleaner server: %w", err)
c.settings.ReportStatus(component.NewFatalErrorEvent(err))
}
diff --git a/cmd/jaeger/internal/integration/storagecleaner/extension_test.go b/cmd/jaeger/internal/integration/storagecleaner/extension_test.go
index 068a58ed131..621fd503471 100644
--- a/cmd/jaeger/internal/integration/storagecleaner/extension_test.go
+++ b/cmd/jaeger/internal/integration/storagecleaner/extension_test.go
@@ -142,5 +142,9 @@ func TestStorageExtensionStartError(t *testing.T) {
assert.Eventually(t, func() bool {
return startStatus.Load() != nil
}, 5*time.Second, 100*time.Millisecond)
- require.Contains(t, startStatus.Load().Err().Error(), "error starting cleaner server")
+ require.Contains(
+ t,
+ startStatus.Load().Err().Error(),
+ "error starting cleaner server",
+ )
}
diff --git a/cmd/jaeger/internal/integration/storagecleaner/factory_test.go b/cmd/jaeger/internal/integration/storagecleaner/factory_test.go
index 7b1ec51d8f3..8af76ed6cdf 100644
--- a/cmd/jaeger/internal/integration/storagecleaner/factory_test.go
+++ b/cmd/jaeger/internal/integration/storagecleaner/factory_test.go
@@ -22,7 +22,11 @@ func TestCreateDefaultConfig(t *testing.T) {
func TestCreateExtension(t *testing.T) {
cfg := createDefaultConfig().(*Config)
f := NewFactory()
- r, err := f.CreateExtension(context.Background(), extensiontest.NewNopCreateSettings(), cfg)
+ r, err := f.CreateExtension(
+ context.Background(),
+ extensiontest.NewNopCreateSettings(),
+ cfg,
+ )
require.NoError(t, err)
assert.NotNil(t, r)
}
diff --git a/cmd/query/app/additional_headers_handler.go b/cmd/query/app/additional_headers_handler.go
index de423921696..37d2375a174 100644
--- a/cmd/query/app/additional_headers_handler.go
+++ b/cmd/query/app/additional_headers_handler.go
@@ -18,7 +18,10 @@ import (
"net/http"
)
-func additionalHeadersHandler(h http.Handler, additionalHeaders http.Header) http.Handler {
+func additionalHeadersHandler(
+ h http.Handler,
+ additionalHeaders http.Header,
+) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
header := w.Header()
for key, values := range additionalHeaders {
diff --git a/cmd/query/app/additional_headers_test.go b/cmd/query/app/additional_headers_test.go
index 68db5ba7b60..527b63561f3 100644
--- a/cmd/query/app/additional_headers_test.go
+++ b/cmd/query/app/additional_headers_test.go
@@ -27,12 +27,17 @@ func TestAdditionalHeadersHandler(t *testing.T) {
additionalHeaders := http.Header{}
additionalHeaders.Add("Access-Control-Allow-Origin", "https://mozilla.org")
additionalHeaders.Add("Access-Control-Expose-Headers", "X-My-Custom-Header")
- additionalHeaders.Add("Access-Control-Expose-Headers", "X-Another-Custom-Header")
+ additionalHeaders.Add(
+ "Access-Control-Expose-Headers",
+ "X-Another-Custom-Header",
+ )
additionalHeaders.Add("Access-Control-Request-Headers", "field1, field2")
- emptyHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- w.Write([]byte{})
- })
+ emptyHandler := http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ w.Write([]byte{})
+ },
+ )
handler := additionalHeadersHandler(emptyHandler, additionalHeaders)
server := httptest.NewServer(handler)
diff --git a/cmd/query/app/apiv3/gateway_test.go b/cmd/query/app/apiv3/gateway_test.go
index 745ea2c643d..7f5aa5318fd 100644
--- a/cmd/query/app/apiv3/gateway_test.go
+++ b/cmd/query/app/apiv3/gateway_test.go
@@ -73,7 +73,12 @@ func (gw *testGateway) execRequest(t *testing.T, url string) ([]byte, int) {
func (*testGateway) verifySnapshot(t *testing.T, body []byte) []byte {
// reformat JSON body with indentation, to make diffing easier
var data any
- require.NoError(t, json.Unmarshal(body, &data), "response: %s", string(body))
+ require.NoError(
+ t,
+ json.Unmarshal(body, &data),
+ "response: %s",
+ string(body),
+ )
body, err := json.MarshalIndent(data, "", " ")
require.NoError(t, err)
@@ -84,7 +89,12 @@ func (*testGateway) verifySnapshot(t *testing.T, body []byte) []byte {
}
snapshot, err := os.ReadFile(snapshotFile)
require.NoError(t, err)
- assert.Equal(t, string(snapshot), string(body), "comparing against stored snapshot. Use REGENERATE_SNAPSHOTS=true to rebuild snapshots.")
+ assert.Equal(
+ t,
+ string(snapshot),
+ string(body),
+ "comparing against stored snapshot. Use REGENERATE_SNAPSHOTS=true to rebuild snapshots.",
+ )
return body
}
@@ -124,7 +134,9 @@ func runGatewayTests(
}
func (gw *testGateway) runGatewayGetServices(t *testing.T) {
- gw.reader.On("GetServices", matchContext).Return([]string{"foo"}, nil).Once()
+ gw.reader.On("GetServices", matchContext).
+ Return([]string{"foo"}, nil).
+ Once()
body, statusCode := gw.execRequest(t, "/api/v3/services")
require.Equal(t, http.StatusOK, statusCode)
@@ -136,12 +148,19 @@ func (gw *testGateway) runGatewayGetServices(t *testing.T) {
}
func (gw *testGateway) runGatewayGetOperations(t *testing.T) {
- qp := spanstore.OperationQueryParameters{ServiceName: "foo", SpanKind: "server"}
+ qp := spanstore.OperationQueryParameters{
+ ServiceName: "foo",
+ SpanKind: "server",
+ }
gw.reader.
On("GetOperations", matchContext, qp).
- Return([]spanstore.Operation{{Name: "get_users", SpanKind: "server"}}, nil).Once()
+ Return([]spanstore.Operation{{Name: "get_users", SpanKind: "server"}}, nil).
+ Once()
- body, statusCode := gw.execRequest(t, "/api/v3/operations?service=foo&span_kind=server")
+ body, statusCode := gw.execRequest(
+ t,
+ "/api/v3/operations?service=foo&span_kind=server",
+ )
require.Equal(t, http.StatusOK, statusCode)
body = gw.verifySnapshot(t, body)
@@ -167,7 +186,11 @@ func (gw *testGateway) runGatewayFindTraces(t *testing.T) {
gw.getTracesAndVerify(t, "/api/v3/traces?"+q.Encode(), traceID)
}
-func (gw *testGateway) getTracesAndVerify(t *testing.T, url string, expectedTraceID model.TraceID) {
+func (gw *testGateway) getTracesAndVerify(
+ t *testing.T,
+ url string,
+ expectedTraceID model.TraceID,
+) {
body, statusCode := gw.execRequest(t, url)
require.Equal(t, http.StatusOK, statusCode, "response=%s", string(body))
body = gw.verifySnapshot(t, body)
@@ -176,6 +199,12 @@ func (gw *testGateway) getTracesAndVerify(t *testing.T, url string, expectedTrac
parseResponse(t, body, &response)
td := response.Result.ToTraces()
assert.EqualValues(t, 1, td.SpanCount())
- traceID := td.ResourceSpans().At(0).ScopeSpans().At(0).Spans().At(0).TraceID()
+ traceID := td.ResourceSpans().
+ At(0).
+ ScopeSpans().
+ At(0).
+ Spans().
+ At(0).
+ TraceID()
assert.Equal(t, expectedTraceID.String(), traceID.String())
}
diff --git a/cmd/query/app/apiv3/grpc_handler.go b/cmd/query/app/apiv3/grpc_handler.go
index b71a72fe32b..cd125ac21bc 100644
--- a/cmd/query/app/apiv3/grpc_handler.go
+++ b/cmd/query/app/apiv3/grpc_handler.go
@@ -37,7 +37,10 @@ type Handler struct {
var _ api_v3.QueryServiceServer = (*Handler)(nil)
// GetTrace implements api_v3.QueryServiceServer's GetTrace
-func (h *Handler) GetTrace(request *api_v3.GetTraceRequest, stream api_v3.QueryService_GetTraceServer) error {
+func (h *Handler) GetTrace(
+ request *api_v3.GetTraceRequest,
+ stream api_v3.QueryService_GetTraceServer,
+) error {
traceID, err := model.TraceIDFromString(request.GetTraceId())
if err != nil {
return fmt.Errorf("malform trace ID: %w", err)
@@ -56,7 +59,10 @@ func (h *Handler) GetTrace(request *api_v3.GetTraceRequest, stream api_v3.QueryS
}
// FindTraces implements api_v3.QueryServiceServer's FindTraces
-func (h *Handler) FindTraces(request *api_v3.FindTracesRequest, stream api_v3.QueryService_FindTracesServer) error {
+func (h *Handler) FindTraces(
+ request *api_v3.FindTracesRequest,
+ stream api_v3.QueryService_FindTracesServer,
+) error {
query := request.GetQuery()
if query == nil {
return status.Errorf(codes.InvalidArgument, "missing query")
@@ -117,7 +123,10 @@ func (h *Handler) FindTraces(request *api_v3.FindTracesRequest, stream api_v3.Qu
}
// GetServices implements api_v3.QueryServiceServer's GetServices
-func (h *Handler) GetServices(ctx context.Context, _ *api_v3.GetServicesRequest) (*api_v3.GetServicesResponse, error) {
+func (h *Handler) GetServices(
+ ctx context.Context,
+ _ *api_v3.GetServicesRequest,
+) (*api_v3.GetServicesResponse, error) {
services, err := h.QueryService.GetServices(ctx)
if err != nil {
return nil, err
@@ -128,7 +137,10 @@ func (h *Handler) GetServices(ctx context.Context, _ *api_v3.GetServicesRequest)
}
// GetOperations implements api_v3.QueryService's GetOperations
-func (h *Handler) GetOperations(ctx context.Context, request *api_v3.GetOperationsRequest) (*api_v3.GetOperationsResponse, error) {
+func (h *Handler) GetOperations(
+ ctx context.Context,
+ request *api_v3.GetOperationsRequest,
+) (*api_v3.GetOperationsResponse, error) {
operations, err := h.QueryService.GetOperations(ctx, spanstore.OperationQueryParameters{
ServiceName: request.GetService(),
SpanKind: request.GetSpanKind(),
diff --git a/cmd/query/app/apiv3/grpc_handler_test.go b/cmd/query/app/apiv3/grpc_handler_test.go
index bc59d3b2317..c5f86aea36f 100644
--- a/cmd/query/app/apiv3/grpc_handler_test.go
+++ b/cmd/query/app/apiv3/grpc_handler_test.go
@@ -118,9 +118,12 @@ func TestGetTraceStorageError(t *testing.T) {
tsc.reader.On("GetTrace", matchContext, matchTraceID).Return(
nil, fmt.Errorf("storage_error")).Once()
- getTraceStream, err := tsc.client.GetTrace(context.Background(), &api_v3.GetTraceRequest{
- TraceId: "156",
- })
+ getTraceStream, err := tsc.client.GetTrace(
+ context.Background(),
+ &api_v3.GetTraceRequest{
+ TraceId: "156",
+ },
+ )
require.NoError(t, err)
recv, err := getTraceStream.Recv()
require.Error(t, err)
@@ -135,9 +138,12 @@ func TestGetTraceTraceIDError(t *testing.T) {
Spans: []*model.Span{},
}, nil).Once()
- getTraceStream, err := tsc.client.GetTrace(context.Background(), &api_v3.GetTraceRequest{
- TraceId: "Z",
- })
+ getTraceStream, err := tsc.client.GetTrace(
+ context.Background(),
+ &api_v3.GetTraceRequest{
+ TraceId: "Z",
+ },
+ )
require.NoError(t, err)
recv, err := getTraceStream.Recv()
require.Error(t, err)
@@ -147,28 +153,33 @@ func TestGetTraceTraceIDError(t *testing.T) {
func TestFindTraces(t *testing.T) {
tsc := newTestServerClient(t)
- tsc.reader.On("FindTraces", matchContext, mock.AnythingOfType("*spanstore.TraceQueryParameters")).Return(
- []*model.Trace{
- {
- Spans: []*model.Span{
- {
- OperationName: "name",
+ tsc.reader.On("FindTraces", matchContext, mock.AnythingOfType("*spanstore.TraceQueryParameters")).
+ Return(
+ []*model.Trace{
+ {
+ Spans: []*model.Span{
+ {
+ OperationName: "name",
+ },
},
},
+ }, nil).
+ Once()
+
+ responseStream, err := tsc.client.FindTraces(
+ context.Background(),
+ &api_v3.FindTracesRequest{
+ Query: &api_v3.TraceQueryParameters{
+ ServiceName: "myservice",
+ OperationName: "opname",
+ Attributes: map[string]string{"foo": "bar"},
+ StartTimeMin: &types.Timestamp{},
+ StartTimeMax: &types.Timestamp{},
+ DurationMin: &types.Duration{},
+ DurationMax: &types.Duration{},
},
- }, nil).Once()
-
- responseStream, err := tsc.client.FindTraces(context.Background(), &api_v3.FindTracesRequest{
- Query: &api_v3.TraceQueryParameters{
- ServiceName: "myservice",
- OperationName: "opname",
- Attributes: map[string]string{"foo": "bar"},
- StartTimeMin: &types.Timestamp{},
- StartTimeMax: &types.Timestamp{},
- DurationMin: &types.Duration{},
- DurationMax: &types.Duration{},
},
- })
+ )
require.NoError(t, err)
recv, err := responseStream.Recv()
require.NoError(t, err)
@@ -178,39 +189,54 @@ func TestFindTraces(t *testing.T) {
func TestFindTracesQueryNil(t *testing.T) {
tsc := newTestServerClient(t)
- responseStream, err := tsc.client.FindTraces(context.Background(), &api_v3.FindTracesRequest{})
+ responseStream, err := tsc.client.FindTraces(
+ context.Background(),
+ &api_v3.FindTracesRequest{},
+ )
require.NoError(t, err)
recv, err := responseStream.Recv()
require.Error(t, err)
assert.Contains(t, err.Error(), "missing query")
assert.Nil(t, recv)
- responseStream, err = tsc.client.FindTraces(context.Background(), &api_v3.FindTracesRequest{
- Query: &api_v3.TraceQueryParameters{
- StartTimeMin: nil,
- StartTimeMax: nil,
+ responseStream, err = tsc.client.FindTraces(
+ context.Background(),
+ &api_v3.FindTracesRequest{
+ Query: &api_v3.TraceQueryParameters{
+ StartTimeMin: nil,
+ StartTimeMax: nil,
+ },
},
- })
+ )
require.NoError(t, err)
recv, err = responseStream.Recv()
require.Error(t, err)
- assert.Contains(t, err.Error(), "start time min and max are required parameters")
+ assert.Contains(
+ t,
+ err.Error(),
+ "start time min and max are required parameters",
+ )
assert.Nil(t, recv)
}
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()
-
- responseStream, err := tsc.client.FindTraces(context.Background(), &api_v3.FindTracesRequest{
- Query: &api_v3.TraceQueryParameters{
- StartTimeMin: &types.Timestamp{},
- StartTimeMax: &types.Timestamp{},
- DurationMin: &types.Duration{},
- DurationMax: &types.Duration{},
+ tsc.reader.On("FindTraces", matchContext, mock.AnythingOfType("*spanstore.TraceQueryParameters")).
+ Return(
+ nil, fmt.Errorf("storage_error"), nil).
+ Once()
+
+ responseStream, err := tsc.client.FindTraces(
+ context.Background(),
+ &api_v3.FindTracesRequest{
+ Query: &api_v3.TraceQueryParameters{
+ StartTimeMin: &types.Timestamp{},
+ StartTimeMax: &types.Timestamp{},
+ DurationMin: &types.Duration{},
+ DurationMax: &types.Duration{},
+ },
},
- })
+ )
require.NoError(t, err)
recv, err := responseStream.Recv()
require.Error(t, err)
@@ -223,7 +249,10 @@ func TestGetServices(t *testing.T) {
tsc.reader.On("GetServices", matchContext).Return(
[]string{"foo"}, nil).Once()
- response, err := tsc.client.GetServices(context.Background(), &api_v3.GetServicesRequest{})
+ response, err := tsc.client.GetServices(
+ context.Background(),
+ &api_v3.GetServicesRequest{},
+ )
require.NoError(t, err)
assert.Equal(t, []string{"foo"}, response.GetServices())
}
@@ -233,7 +262,10 @@ func TestGetServicesStorageError(t *testing.T) {
tsc.reader.On("GetServices", matchContext).Return(
nil, fmt.Errorf("storage_error")).Once()
- response, err := tsc.client.GetServices(context.Background(), &api_v3.GetServicesRequest{})
+ response, err := tsc.client.GetServices(
+ context.Background(),
+ &api_v3.GetServicesRequest{},
+ )
require.Error(t, err)
assert.Contains(t, err.Error(), "storage_error")
assert.Nil(t, response)
@@ -241,14 +273,19 @@ func TestGetServicesStorageError(t *testing.T) {
func TestGetOperations(t *testing.T) {
tsc := newTestServerClient(t)
- tsc.reader.On("GetOperations", matchContext, mock.AnythingOfType("spanstore.OperationQueryParameters")).Return(
- []spanstore.Operation{
- {
- Name: "get_users",
- },
- }, nil).Once()
+ tsc.reader.On("GetOperations", matchContext, mock.AnythingOfType("spanstore.OperationQueryParameters")).
+ Return(
+ []spanstore.Operation{
+ {
+ Name: "get_users",
+ },
+ }, nil).
+ Once()
- response, err := tsc.client.GetOperations(context.Background(), &api_v3.GetOperationsRequest{})
+ response, err := tsc.client.GetOperations(
+ context.Background(),
+ &api_v3.GetOperationsRequest{},
+ )
require.NoError(t, err)
assert.Equal(t, []*api_v3.Operation{
{
@@ -259,10 +296,15 @@ 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()
-
- response, err := tsc.client.GetOperations(context.Background(), &api_v3.GetOperationsRequest{})
+ tsc.reader.On("GetOperations", matchContext, mock.AnythingOfType("spanstore.OperationQueryParameters")).
+ Return(
+ nil, fmt.Errorf("storage_error")).
+ Once()
+
+ response, err := tsc.client.GetOperations(
+ context.Background(),
+ &api_v3.GetOperationsRequest{},
+ )
require.Error(t, err)
assert.Contains(t, err.Error(), "storage_error")
assert.Nil(t, response)
diff --git a/cmd/query/app/apiv3/http_gateway.go b/cmd/query/app/apiv3/http_gateway.go
index 16f01cbdb10..fa1e787b4e7 100644
--- a/cmd/query/app/apiv3/http_gateway.go
+++ b/cmd/query/app/apiv3/http_gateway.go
@@ -57,7 +57,8 @@ func (h *HTTPGateway) RegisterRoutes(router *mux.Router) {
h.addRoute(router, h.getTrace, routeGetTrace).Methods(http.MethodGet)
h.addRoute(router, h.findTraces, routeFindTraces).Methods(http.MethodGet)
h.addRoute(router, h.getServices, routeGetServices).Methods(http.MethodGet)
- h.addRoute(router, h.getOperations, routeGetOperations).Methods(http.MethodGet)
+ h.addRoute(router, h.getOperations, routeGetOperations).
+ Methods(http.MethodGet)
}
// addRoute adds a new endpoint to the router with given path and handler function.
@@ -81,7 +82,11 @@ func (h *HTTPGateway) addRoute(
// tryHandleError checks if the passed error is not nil and handles it by writing
// an error response to the client. Otherwise it returns false.
-func (h *HTTPGateway) tryHandleError(w http.ResponseWriter, err error, statusCode int) bool {
+func (h *HTTPGateway) tryHandleError(
+ w http.ResponseWriter,
+ err error,
+ statusCode int,
+) bool {
if err == nil {
return false
}
@@ -103,11 +108,19 @@ func (h *HTTPGateway) tryHandleError(w http.ResponseWriter, err error, statusCod
}
// tryParamError is similar to tryHandleError but specifically for reporting malformed params.
-func (h *HTTPGateway) tryParamError(w http.ResponseWriter, err error, paramName string) bool {
+func (h *HTTPGateway) tryParamError(
+ w http.ResponseWriter,
+ err error,
+ paramName string,
+) bool {
if err == nil {
return false
}
- return h.tryHandleError(w, fmt.Errorf("malformed parameter %s: %w", paramName, err), http.StatusBadRequest)
+ return h.tryHandleError(
+ w,
+ fmt.Errorf("malformed parameter %s: %w", paramName, err),
+ http.StatusBadRequest,
+ )
}
func (h *HTTPGateway) returnSpans(spans []*model.Span, w http.ResponseWriter) {
@@ -131,7 +144,10 @@ func (h *HTTPGateway) returnSpansTestable(
h.marshalResponse(response, w)
}
-func (*HTTPGateway) marshalResponse(response proto.Message, w http.ResponseWriter) {
+func (*HTTPGateway) marshalResponse(
+ response proto.Message,
+ w http.ResponseWriter,
+) {
_ = new(jsonpb.Marshaler).Marshal(w, response)
}
@@ -167,7 +183,10 @@ func (h *HTTPGateway) findTraces(w http.ResponseWriter, r *http.Request) {
h.returnSpans(spans, w)
}
-func (h *HTTPGateway) parseFindTracesQuery(q url.Values, w http.ResponseWriter) (*spanstore.TraceQueryParameters, bool) {
+func (h *HTTPGateway) parseFindTracesQuery(
+ q url.Values,
+ w http.ResponseWriter,
+) (*spanstore.TraceQueryParameters, bool) {
queryParams := &spanstore.TraceQueryParameters{
ServiceName: q.Get(paramServiceName),
OperationName: q.Get(paramOperationName),
@@ -244,5 +263,8 @@ func (h *HTTPGateway) getOperations(w http.ResponseWriter, r *http.Request) {
SpanKind: operations[i].SpanKind,
}
}
- h.marshalResponse(&api_v3.GetOperationsResponse{Operations: apiOperations}, w)
+ h.marshalResponse(
+ &api_v3.GetOperationsResponse{Operations: apiOperations},
+ w,
+ )
}
diff --git a/cmd/query/app/apiv3/http_gateway_test.go b/cmd/query/app/apiv3/http_gateway_test.go
index edffadb485d..a9a6ae59223 100644
--- a/cmd/query/app/apiv3/http_gateway_test.go
+++ b/cmd/query/app/apiv3/http_gateway_test.go
@@ -98,16 +98,28 @@ func TestHTTPGatewayTryHandleError(t *testing.T) {
assert.False(t, gw.tryHandleError(nil, nil, 0), "returns false if no error")
w := httptest.NewRecorder()
- assert.True(t, gw.tryHandleError(w, spanstore.ErrTraceNotFound, 0), "returns true if error")
+ assert.True(
+ t,
+ gw.tryHandleError(w, spanstore.ErrTraceNotFound, 0),
+ "returns true if error",
+ )
assert.Equal(t, http.StatusNotFound, w.Code, "sets status code to 404")
logger, log := testutils.NewLogger()
gw.Logger = logger
w = httptest.NewRecorder()
const e = "some err"
- assert.True(t, gw.tryHandleError(w, fmt.Errorf(e), http.StatusInternalServerError))
+ assert.True(
+ t,
+ gw.tryHandleError(w, fmt.Errorf(e), http.StatusInternalServerError),
+ )
assert.Contains(t, log.String(), e, "logs error if status code is 500")
- assert.Contains(t, string(w.Body.String()), e, "writes error message to body")
+ assert.Contains(
+ t,
+ string(w.Body.String()),
+ e,
+ "writes error message to body",
+ )
}
func TestHTTPGatewayOTLPError(t *testing.T) {
@@ -176,7 +188,11 @@ func mockFindQueries() (url.Values, *spanstore.TraceQueryParameters) {
func TestHTTPGatewayFindTracesErrors(t *testing.T) {
goodTimeV := time.Now()
goodTime := goodTimeV.Format(time.RFC3339Nano)
- timeRangeErr := fmt.Sprintf("%s and %s are required", paramTimeMin, paramTimeMax)
+ timeRangeErr := fmt.Sprintf(
+ "%s and %s are required",
+ paramTimeMin,
+ paramTimeMax,
+ )
testCases := []struct {
name string
params map[string]string
@@ -197,28 +213,46 @@ func TestHTTPGatewayFindTracesErrors(t *testing.T) {
expErr: timeRangeErr,
},
{
- name: "bax min time",
- params: map[string]string{paramTimeMin: "NaN", paramTimeMax: goodTime},
+ name: "bax min time",
+ params: map[string]string{
+ paramTimeMin: "NaN",
+ paramTimeMax: goodTime,
+ },
expErr: paramTimeMin,
},
{
- name: "bax max time",
- params: map[string]string{paramTimeMin: goodTime, paramTimeMax: "NaN"},
+ name: "bax max time",
+ params: map[string]string{
+ paramTimeMin: goodTime,
+ paramTimeMax: "NaN",
+ },
expErr: paramTimeMax,
},
{
- name: "bad num_traces",
- params: map[string]string{paramTimeMin: goodTime, paramTimeMax: goodTime, paramNumTraces: "NaN"},
+ name: "bad num_traces",
+ params: map[string]string{
+ paramTimeMin: goodTime,
+ paramTimeMax: goodTime,
+ paramNumTraces: "NaN",
+ },
expErr: paramNumTraces,
},
{
- name: "bad min duration",
- params: map[string]string{paramTimeMin: goodTime, paramTimeMax: goodTime, paramDurationMin: "NaN"},
+ name: "bad min duration",
+ params: map[string]string{
+ paramTimeMin: goodTime,
+ paramTimeMax: goodTime,
+ paramDurationMin: "NaN",
+ },
expErr: paramDurationMin,
},
{
- name: "bad max duration",
- params: map[string]string{paramTimeMin: goodTime, paramTimeMax: goodTime, paramDurationMax: "NaN"},
+ name: "bad max duration",
+ params: map[string]string{
+ paramTimeMin: goodTime,
+ paramTimeMax: goodTime,
+ paramDurationMax: "NaN",
+ },
expErr: paramDurationMax,
},
}
@@ -228,7 +262,11 @@ func TestHTTPGatewayFindTracesErrors(t *testing.T) {
for k, v := range tc.params {
q.Set(k, v)
}
- r, err := http.NewRequest(http.MethodGet, "/api/v3/traces?"+q.Encode(), nil)
+ r, err := http.NewRequest(
+ http.MethodGet,
+ "/api/v3/traces?"+q.Encode(),
+ nil,
+ )
require.NoError(t, err)
w := httptest.NewRecorder()
@@ -240,7 +278,11 @@ func TestHTTPGatewayFindTracesErrors(t *testing.T) {
t.Run("span reader error", func(t *testing.T) {
q, qp := mockFindQueries()
const simErr = "simulated error"
- r, err := http.NewRequest(http.MethodGet, "/api/v3/traces?"+q.Encode(), nil)
+ r, err := http.NewRequest(
+ http.MethodGet,
+ "/api/v3/traces?"+q.Encode(),
+ nil,
+ )
require.NoError(t, err)
w := httptest.NewRecorder()
@@ -272,13 +314,20 @@ func TestHTTPGatewayGetServicesErrors(t *testing.T) {
func TestHTTPGatewayGetOperationsErrors(t *testing.T) {
gw := setupHTTPGatewayNoServer(t, "", tenancy.Options{})
- qp := spanstore.OperationQueryParameters{ServiceName: "foo", SpanKind: "server"}
+ qp := spanstore.OperationQueryParameters{
+ ServiceName: "foo",
+ SpanKind: "server",
+ }
const simErr = "simulated error"
gw.reader.
On("GetOperations", matchContext, qp).
Return(nil, fmt.Errorf(simErr)).Once()
- r, err := http.NewRequest(http.MethodGet, "/api/v3/operations?service=foo&span_kind=server", nil)
+ r, err := http.NewRequest(
+ http.MethodGet,
+ "/api/v3/operations?service=foo&span_kind=server",
+ nil,
+ )
require.NoError(t, err)
w := httptest.NewRecorder()
gw.router.ServeHTTP(w, r)
@@ -302,7 +351,11 @@ func TestHTTPGatewayTenancyRejection(t *testing.T) {
},
}, nil).Once()
- req, err := http.NewRequest(http.MethodGet, gw.url+"/api/v3/traces/123", nil)
+ req, err := http.NewRequest(
+ http.MethodGet,
+ gw.url+"/api/v3/traces/123",
+ nil,
+ )
require.NoError(t, err)
req.Header.Set("Content-Type", "application/json")
// We don't set tenant header
@@ -311,7 +364,13 @@ func TestHTTPGatewayTenancyRejection(t *testing.T) {
body, err := io.ReadAll(response.Body)
require.NoError(t, err)
require.NoError(t, response.Body.Close())
- require.Equal(t, http.StatusUnauthorized, response.StatusCode, "response=%s", string(body))
+ require.Equal(
+ t,
+ http.StatusUnauthorized,
+ response.StatusCode,
+ "response=%s",
+ string(body),
+ )
// Try again with tenant header set
tm := tenancy.NewManager(&tenancyOptions)
diff --git a/cmd/query/app/default_params.go b/cmd/query/app/default_params.go
index 58104493879..30910fbe081 100644
--- a/cmd/query/app/default_params.go
+++ b/cmd/query/app/default_params.go
@@ -28,5 +28,7 @@ var (
defaultMetricsQueryLookbackDuration = time.Hour
defaultMetricsQueryStepDuration = 5 * time.Second
defaultMetricsQueryRateDuration = 10 * time.Minute
- defaultMetricsSpanKinds = []string{metrics.SpanKind_SPAN_KIND_SERVER.String()}
+ defaultMetricsSpanKinds = []string{
+ metrics.SpanKind_SPAN_KIND_SERVER.String(),
+ }
)
diff --git a/cmd/query/app/flags.go b/cmd/query/app/flags.go
index c2b7d823900..7f668804858 100644
--- a/cmd/query/app/flags.go
+++ b/cmd/query/app/flags.go
@@ -104,22 +104,45 @@ type QueryOptions struct {
// AddFlags adds flags for QueryOptions
func AddFlags(flagSet *flag.FlagSet) {
- flagSet.Var(&config.StringSlice{}, queryAdditionalHeaders, `Additional HTTP response headers. Can be specified multiple times. Format: "Key: Value"`)
- flagSet.String(queryHTTPHostPort, ports.PortToHostPort(ports.QueryHTTP), "The host:port (e.g. 127.0.0.1:14268 or :14268) of the query's HTTP server")
- flagSet.String(queryGRPCHostPort, ports.PortToHostPort(ports.QueryGRPC), "The host:port (e.g. 127.0.0.1:14250 or :14250) of the query's gRPC server")
- flagSet.String(queryBasePath, "/", "The base path for all HTTP routes, e.g. /jaeger; useful when running behind a reverse proxy. See https://github.com/jaegertracing/jaeger/blob/main/examples/reverse-proxy/README.md")
+ flagSet.Var(
+ &config.StringSlice{},
+ queryAdditionalHeaders,
+ `Additional HTTP response headers. Can be specified multiple times. Format: "Key: Value"`,
+ )
+ flagSet.String(
+ queryHTTPHostPort,
+ ports.PortToHostPort(ports.QueryHTTP),
+ "The host:port (e.g. 127.0.0.1:14268 or :14268) of the query's HTTP server",
+ )
+ flagSet.String(
+ queryGRPCHostPort,
+ ports.PortToHostPort(ports.QueryGRPC),
+ "The host:port (e.g. 127.0.0.1:14250 or :14250) of the query's gRPC server",
+ )
+ flagSet.String(
+ queryBasePath,
+ "/",
+ "The base path for all HTTP routes, e.g. /jaeger; useful when running behind a reverse proxy. See https://github.com/jaegertracing/jaeger/blob/main/examples/reverse-proxy/README.md",
+ )
flagSet.String(queryStaticFiles, "", "The directory path override for the static assets for the UI")
flagSet.Bool(queryLogStaticAssetsAccess, false, "Log when static assets are accessed (for debugging)")
flagSet.String(queryUIConfig, "", "The path to the UI configuration file in JSON format")
flagSet.Bool(queryTokenPropagation, false, "Allow propagation of bearer token to be used by storage plugins")
- flagSet.Duration(queryMaxClockSkewAdjust, 0, "The maximum delta by which span timestamps may be adjusted in the UI due to clock skew; set to 0s to disable clock skew adjustments")
+ flagSet.Duration(
+ queryMaxClockSkewAdjust,
+ 0,
+ "The maximum delta by which span timestamps may be adjusted in the UI due to clock skew; set to 0s to disable clock skew adjustments",
+ )
flagSet.Bool(queryEnableTracing, false, "Enables emitting jaeger-query traces")
tlsGRPCFlagsConfig.AddFlags(flagSet)
tlsHTTPFlagsConfig.AddFlags(flagSet)
}
// InitFromViper initializes QueryOptions with properties from viper
-func (qOpts *QueryOptions) InitFromViper(v *viper.Viper, logger *zap.Logger) (*QueryOptions, error) {
+func (qOpts *QueryOptions) InitFromViper(
+ v *viper.Viper,
+ logger *zap.Logger,
+) (*QueryOptions, error) {
qOpts.HTTPHostPort = v.GetString(queryHTTPHostPort)
qOpts.GRPCHostPort = v.GetString(queryGRPCHostPort)
tlsGrpc, err := tlsGRPCFlagsConfig.InitFromViper(v)
@@ -142,7 +165,11 @@ func (qOpts *QueryOptions) InitFromViper(v *viper.Viper, logger *zap.Logger) (*Q
stringSlice := v.GetStringSlice(queryAdditionalHeaders)
headers, err := stringSliceAsHeader(stringSlice)
if err != nil {
- logger.Error("Failed to parse headers", zap.Strings("slice", stringSlice), zap.Error(err))
+ logger.Error(
+ "Failed to parse headers",
+ zap.Strings("slice", stringSlice),
+ zap.Error(err),
+ )
} else {
qOpts.AdditionalHeaders = headers
}
@@ -152,13 +179,17 @@ func (qOpts *QueryOptions) InitFromViper(v *viper.Viper, logger *zap.Logger) (*Q
}
// BuildQueryServiceOptions creates a QueryServiceOptions struct with appropriate adjusters and archive config
-func (qOpts *QueryOptions) BuildQueryServiceOptions(storageFactory storage.Factory, logger *zap.Logger) *querysvc.QueryServiceOptions {
+func (qOpts *QueryOptions) BuildQueryServiceOptions(
+ storageFactory storage.Factory,
+ logger *zap.Logger,
+) *querysvc.QueryServiceOptions {
opts := &querysvc.QueryServiceOptions{}
if !opts.InitArchiveStorage(storageFactory, logger) {
logger.Info("Archive storage not initialized")
}
- opts.Adjuster = adjuster.Sequence(querysvc.StandardAdjusters(qOpts.MaxClockSkewAdjust)...)
+ opts.Adjuster = adjuster.Sequence(
+ querysvc.StandardAdjusters(qOpts.MaxClockSkewAdjust)...)
return opts
}
diff --git a/cmd/query/app/flags_test.go b/cmd/query/app/flags_test.go
index 507c6ad7438..a3824011da3 100644
--- a/cmd/query/app/flags_test.go
+++ b/cmd/query/app/flags_test.go
@@ -79,7 +79,11 @@ func TestStringSliceAsHeader(t *testing.T) {
parsedHeaders, err := stringSliceAsHeader(headers)
assert.Equal(t, []string{"https://mozilla.org"}, parsedHeaders["Access-Control-Allow-Origin"])
- assert.Equal(t, []string{"X-My-Custom-Header", "X-Another-Custom-Header"}, parsedHeaders["Access-Control-Expose-Headers"])
+ assert.Equal(
+ t,
+ []string{"X-My-Custom-Header", "X-Another-Custom-Header"},
+ parsedHeaders["Access-Control-Expose-Headers"],
+ )
require.NoError(t, err)
malformedHeaders := append(headers, "this is not a valid header")
@@ -116,8 +120,10 @@ func TestBuildQueryServiceOptions(t *testing.T) {
&mocks.ArchiveFactory{},
}
- comboFactory.ArchiveFactory.On("CreateArchiveSpanReader").Return(&spanstore_mocks.Reader{}, nil)
- comboFactory.ArchiveFactory.On("CreateArchiveSpanWriter").Return(&spanstore_mocks.Writer{}, nil)
+ comboFactory.ArchiveFactory.On("CreateArchiveSpanReader").
+ Return(&spanstore_mocks.Reader{}, nil)
+ comboFactory.ArchiveFactory.On("CreateArchiveSpanWriter").
+ Return(&spanstore_mocks.Writer{}, nil)
qSvcOpts = qOpts.BuildQueryServiceOptions(comboFactory, zap.NewNop())
assert.NotNil(t, qSvcOpts)
@@ -137,10 +143,14 @@ func TestQueryOptionsPortAllocationFromFlags(t *testing.T) {
}{
{
// Default behavior. Dedicated host-port is used for both HTTP and GRPC endpoints
- name: "No host-port flags specified, both GRPC and HTTP TLS disabled",
- flagsArray: []string{},
- expectedHTTPHostPort: ports.PortToHostPort(ports.QueryHTTP), // fallback in viper
- expectedGRPCHostPort: ports.PortToHostPort(ports.QueryGRPC), // fallback in viper
+ name: "No host-port flags specified, both GRPC and HTTP TLS disabled",
+ flagsArray: []string{},
+ expectedHTTPHostPort: ports.PortToHostPort(
+ ports.QueryHTTP,
+ ), // fallback in viper
+ expectedGRPCHostPort: ports.PortToHostPort(
+ ports.QueryGRPC,
+ ), // fallback in viper
},
{
// If any one host-port is specified, and TLS is disabled, fallback to ports defined in viper
@@ -149,7 +159,9 @@ func TestQueryOptionsPortAllocationFromFlags(t *testing.T) {
"--query.http-server.host-port=127.0.0.1:8081",
},
expectedHTTPHostPort: "127.0.0.1:8081",
- expectedGRPCHostPort: ports.PortToHostPort(ports.QueryGRPC), // fallback in viper
+ expectedGRPCHostPort: ports.PortToHostPort(
+ ports.QueryGRPC,
+ ), // fallback in viper
},
{
// Allows usage of common host-ports. Flags allow this irrespective of TLS status
@@ -190,7 +202,11 @@ func TestQueryOptions_FailedTLSFlags(t *testing.T) {
require.NoError(t, err)
_, err = new(QueryOptions).InitFromViper(v, zap.NewNop())
require.Error(t, err)
- assert.Contains(t, err.Error(), "failed to process "+test+" TLS options")
+ assert.Contains(
+ t,
+ err.Error(),
+ "failed to process "+test+" TLS options",
+ )
})
}
}
diff --git a/cmd/query/app/grpc_handler.go b/cmd/query/app/grpc_handler.go
index 670050f5ba9..a3e3914a259 100644
--- a/cmd/query/app/grpc_handler.go
+++ b/cmd/query/app/grpc_handler.go
@@ -41,11 +41,26 @@ const (
)
var (
- errGRPCMetricsQueryDisabled = status.Error(codes.Unimplemented, "metrics querying is currently disabled")
- errNilRequest = status.Error(codes.InvalidArgument, "a nil argument is not allowed")
- errUninitializedTraceID = status.Error(codes.InvalidArgument, "uninitialized TraceID is not allowed")
- errMissingServiceNames = status.Error(codes.InvalidArgument, "please provide at least one service name")
- errMissingQuantile = status.Error(codes.InvalidArgument, "please provide a quantile between (0, 1]")
+ errGRPCMetricsQueryDisabled = status.Error(
+ codes.Unimplemented,
+ "metrics querying is currently disabled",
+ )
+ errNilRequest = status.Error(
+ codes.InvalidArgument,
+ "a nil argument is not allowed",
+ )
+ errUninitializedTraceID = status.Error(
+ codes.InvalidArgument,
+ "uninitialized TraceID is not allowed",
+ )
+ errMissingServiceNames = status.Error(
+ codes.InvalidArgument,
+ "please provide at least one service name",
+ )
+ errMissingQuantile = status.Error(
+ codes.InvalidArgument,
+ "please provide a quantile between (0, 1]",
+ )
)
// GRPCHandler implements the gRPC endpoint of the query service.
@@ -93,7 +108,10 @@ func NewGRPCHandler(queryService *querysvc.QueryService,
var _ api_v2.QueryServiceServer = (*GRPCHandler)(nil)
// GetTrace is the gRPC handler to fetch traces based on trace-id.
-func (g *GRPCHandler) GetTrace(r *api_v2.GetTraceRequest, stream api_v2.QueryService_GetTraceServer) error {
+func (g *GRPCHandler) GetTrace(
+ r *api_v2.GetTraceRequest,
+ stream api_v2.QueryService_GetTraceServer,
+) error {
if r == nil {
return errNilRequest
}
@@ -102,18 +120,29 @@ func (g *GRPCHandler) GetTrace(r *api_v2.GetTraceRequest, stream api_v2.QuerySer
}
trace, err := g.queryService.GetTrace(stream.Context(), r.TraceID)
if errors.Is(err, spanstore.ErrTraceNotFound) {
- g.logger.Warn(msgTraceNotFound, zap.Stringer("id", r.TraceID), zap.Error(err))
+ g.logger.Warn(
+ msgTraceNotFound,
+ zap.Stringer("id", r.TraceID),
+ zap.Error(err),
+ )
return status.Errorf(codes.NotFound, "%s: %v", msgTraceNotFound, err)
}
if err != nil {
g.logger.Error("failed to fetch spans from the backend", zap.Error(err))
- return status.Errorf(codes.Internal, "failed to fetch spans from the backend: %v", err)
+ return status.Errorf(
+ codes.Internal,
+ "failed to fetch spans from the backend: %v",
+ err,
+ )
}
return g.sendSpanChunks(trace.Spans, stream.Send)
}
// ArchiveTrace is the gRPC handler to archive traces.
-func (g *GRPCHandler) ArchiveTrace(ctx context.Context, r *api_v2.ArchiveTraceRequest) (*api_v2.ArchiveTraceResponse, error) {
+func (g *GRPCHandler) ArchiveTrace(
+ ctx context.Context,
+ r *api_v2.ArchiveTraceRequest,
+) (*api_v2.ArchiveTraceResponse, error) {
if r == nil {
return nil, errNilRequest
}
@@ -122,19 +151,35 @@ func (g *GRPCHandler) ArchiveTrace(ctx context.Context, r *api_v2.ArchiveTraceRe
}
err := g.queryService.ArchiveTrace(ctx, r.TraceID)
if errors.Is(err, spanstore.ErrTraceNotFound) {
- g.logger.Warn(msgTraceNotFound, zap.Stringer("id", r.TraceID), zap.Error(err))
- return nil, status.Errorf(codes.NotFound, "%s: %v", msgTraceNotFound, err)
+ g.logger.Warn(
+ msgTraceNotFound,
+ zap.Stringer("id", r.TraceID),
+ zap.Error(err),
+ )
+ return nil, status.Errorf(
+ codes.NotFound,
+ "%s: %v",
+ msgTraceNotFound,
+ err,
+ )
}
if err != nil {
g.logger.Error("failed to archive trace", zap.Error(err))
- return nil, status.Errorf(codes.Internal, "failed to archive trace: %v", err)
+ return nil, status.Errorf(
+ codes.Internal,
+ "failed to archive trace: %v",
+ err,
+ )
}
return &api_v2.ArchiveTraceResponse{}, nil
}
// FindTraces is the gRPC handler to fetch traces based on TraceQueryParameters.
-func (g *GRPCHandler) FindTraces(r *api_v2.FindTracesRequest, stream api_v2.QueryService_FindTracesServer) error {
+func (g *GRPCHandler) FindTraces(
+ r *api_v2.FindTracesRequest,
+ stream api_v2.QueryService_FindTracesServer,
+) error {
if r == nil {
return errNilRequest
}
@@ -155,7 +200,11 @@ func (g *GRPCHandler) FindTraces(r *api_v2.FindTracesRequest, stream api_v2.Quer
traces, err := g.queryService.FindTraces(stream.Context(), &queryParams)
if err != nil {
g.logger.Error("failed when searching for traces", zap.Error(err))
- return status.Errorf(codes.Internal, "failed when searching for traces: %v", err)
+ return status.Errorf(
+ codes.Internal,
+ "failed when searching for traces: %v",
+ err,
+ )
}
for _, trace := range traces {
if err := g.sendSpanChunks(trace.Spans, stream.Send); err != nil {
@@ -165,7 +214,10 @@ func (g *GRPCHandler) FindTraces(r *api_v2.FindTracesRequest, stream api_v2.Quer
return nil
}
-func (g *GRPCHandler) sendSpanChunks(spans []*model.Span, sendFn func(*api_v2.SpansResponseChunk) error) error {
+func (g *GRPCHandler) sendSpanChunks(
+ spans []*model.Span,
+ sendFn func(*api_v2.SpansResponseChunk) error,
+) error {
chunk := make([]model.Span, 0, len(spans))
for i := 0; i < len(spans); i += maxSpanCountInChunk {
chunk = chunk[:0]
@@ -181,11 +233,18 @@ func (g *GRPCHandler) sendSpanChunks(spans []*model.Span, sendFn func(*api_v2.Sp
}
// GetServices is the gRPC handler to fetch services.
-func (g *GRPCHandler) GetServices(ctx context.Context, r *api_v2.GetServicesRequest) (*api_v2.GetServicesResponse, error) {
+func (g *GRPCHandler) GetServices(
+ ctx context.Context,
+ r *api_v2.GetServicesRequest,
+) (*api_v2.GetServicesResponse, error) {
services, err := g.queryService.GetServices(ctx)
if err != nil {
g.logger.Error("failed to fetch services", zap.Error(err))
- return nil, status.Errorf(codes.Internal, "failed to fetch services: %v", err)
+ return nil, status.Errorf(
+ codes.Internal,
+ "failed to fetch services: %v",
+ err,
+ )
}
return &api_v2.GetServicesResponse{Services: services}, nil
@@ -199,13 +258,20 @@ func (g *GRPCHandler) GetOperations(
if r == nil {
return nil, errNilRequest
}
- operations, err := g.queryService.GetOperations(ctx, spanstore.OperationQueryParameters{
- ServiceName: r.Service,
- SpanKind: r.SpanKind,
- })
+ operations, err := g.queryService.GetOperations(
+ ctx,
+ spanstore.OperationQueryParameters{
+ ServiceName: r.Service,
+ SpanKind: r.SpanKind,
+ },
+ )
if err != nil {
g.logger.Error("failed to fetch operations", zap.Error(err))
- return nil, status.Errorf(codes.Internal, "failed to fetch operations: %v", err)
+ return nil, status.Errorf(
+ codes.Internal,
+ "failed to fetch operations: %v",
+ err,
+ )
}
result := make([]*api_v2.Operation, len(operations))
@@ -223,7 +289,10 @@ func (g *GRPCHandler) GetOperations(
}
// GetDependencies is the gRPC handler to fetch dependencies.
-func (g *GRPCHandler) GetDependencies(ctx context.Context, r *api_v2.GetDependenciesRequest) (*api_v2.GetDependenciesResponse, error) {
+func (g *GRPCHandler) GetDependencies(
+ ctx context.Context,
+ r *api_v2.GetDependenciesRequest,
+) (*api_v2.GetDependenciesResponse, error) {
if r == nil {
return nil, errNilRequest
}
@@ -231,20 +300,34 @@ func (g *GRPCHandler) GetDependencies(ctx context.Context, r *api_v2.GetDependen
startTime := r.StartTime
endTime := r.EndTime
if startTime == (time.Time{}) || endTime == (time.Time{}) {
- return nil, status.Errorf(codes.InvalidArgument, "StartTime and EndTime must be initialized.")
+ return nil, status.Errorf(
+ codes.InvalidArgument,
+ "StartTime and EndTime must be initialized.",
+ )
}
- dependencies, err := g.queryService.GetDependencies(ctx, startTime, endTime.Sub(startTime))
+ dependencies, err := g.queryService.GetDependencies(
+ ctx,
+ startTime,
+ endTime.Sub(startTime),
+ )
if err != nil {
g.logger.Error("failed to fetch dependencies", zap.Error(err))
- return nil, status.Errorf(codes.Internal, "failed to fetch dependencies: %v", err)
+ return nil, status.Errorf(
+ codes.Internal,
+ "failed to fetch dependencies: %v",
+ err,
+ )
}
return &api_v2.GetDependenciesResponse{Dependencies: dependencies}, nil
}
// GetLatencies is the gRPC handler to fetch latency metrics.
-func (g *GRPCHandler) GetLatencies(ctx context.Context, r *metrics.GetLatenciesRequest) (*metrics.GetMetricsResponse, error) {
+func (g *GRPCHandler) GetLatencies(
+ ctx context.Context,
+ r *metrics.GetLatenciesRequest,
+) (*metrics.GetMetricsResponse, error) {
bqp, err := g.newBaseQueryParameters(r)
if err := g.handleErr("failed to build parameters", err); err != nil {
return nil, err
@@ -265,7 +348,10 @@ func (g *GRPCHandler) GetLatencies(ctx context.Context, r *metrics.GetLatenciesR
}
// GetCallRates is the gRPC handler to fetch call rate metrics.
-func (g *GRPCHandler) GetCallRates(ctx context.Context, r *metrics.GetCallRatesRequest) (*metrics.GetMetricsResponse, error) {
+func (g *GRPCHandler) GetCallRates(
+ ctx context.Context,
+ r *metrics.GetCallRatesRequest,
+) (*metrics.GetMetricsResponse, error) {
bqp, err := g.newBaseQueryParameters(r)
if err := g.handleErr("failed to build parameters", err); err != nil {
return nil, err
@@ -281,7 +367,10 @@ func (g *GRPCHandler) GetCallRates(ctx context.Context, r *metrics.GetCallRatesR
}
// GetErrorRates is the gRPC handler to fetch error rate metrics.
-func (g *GRPCHandler) GetErrorRates(ctx context.Context, r *metrics.GetErrorRatesRequest) (*metrics.GetMetricsResponse, error) {
+func (g *GRPCHandler) GetErrorRates(
+ ctx context.Context,
+ r *metrics.GetErrorRatesRequest,
+) (*metrics.GetMetricsResponse, error) {
bqp, err := g.newBaseQueryParameters(r)
if err := g.handleErr("failed to build parameters", err); err != nil {
return nil, err
@@ -297,7 +386,10 @@ func (g *GRPCHandler) GetErrorRates(ctx context.Context, r *metrics.GetErrorRate
}
// GetMinStepDuration is the gRPC handler to fetch the minimum step duration supported by the underlying metrics store.
-func (g *GRPCHandler) GetMinStepDuration(ctx context.Context, _ *metrics.GetMinStepDurationRequest) (*metrics.GetMinStepDurationResponse, error) {
+func (g *GRPCHandler) GetMinStepDuration(
+ ctx context.Context,
+ _ *metrics.GetMinStepDurationRequest,
+) (*metrics.GetMinStepDurationResponse, error) {
minStep, err := g.metricsQueryService.GetMinStepDuration(ctx, &metricsstore.MinStepDurationQueryParameters{})
if err := g.handleErr("failed to fetch min step duration", err); err != nil {
return nil, err
@@ -323,7 +415,9 @@ func (g *GRPCHandler) handleErr(msg string, err error) error {
return status.Errorf(codes.Internal, "%s: %v", msg, err)
}
-func (g *GRPCHandler) newBaseQueryParameters(r any) (bqp metricsstore.BaseQueryParameters, err error) {
+func (g *GRPCHandler) newBaseQueryParameters(
+ r any,
+) (bqp metricsstore.BaseQueryParameters, err error) {
if r == nil {
return bqp, errNilRequest
}
diff --git a/cmd/query/app/grpc_handler_test.go b/cmd/query/app/grpc_handler_test.go
index 697f6aeb8b0..f95030518dd 100644
--- a/cmd/query/app/grpc_handler_test.go
+++ b/cmd/query/app/grpc_handler_test.go
@@ -145,13 +145,25 @@ type grpcClient struct {
conn *grpc.ClientConn
}
-func newGRPCServer(t *testing.T, q *querysvc.QueryService, mq querysvc.MetricsQueryService, logger *zap.Logger, tracer *jtracer.JTracer, tenancyMgr *tenancy.Manager) (*grpc.Server, net.Addr) {
+func newGRPCServer(
+ t *testing.T,
+ q *querysvc.QueryService,
+ mq querysvc.MetricsQueryService,
+ logger *zap.Logger,
+ tracer *jtracer.JTracer,
+ tenancyMgr *tenancy.Manager,
+) (*grpc.Server, net.Addr) {
lis, _ := net.Listen("tcp", ":0")
var grpcOpts []grpc.ServerOption
if tenancyMgr.Enabled {
- grpcOpts = append(grpcOpts,
- grpc.StreamInterceptor(tenancy.NewGuardingStreamInterceptor(tenancyMgr)),
- grpc.UnaryInterceptor(tenancy.NewGuardingUnaryInterceptor(tenancyMgr)),
+ grpcOpts = append(
+ grpcOpts,
+ grpc.StreamInterceptor(
+ tenancy.NewGuardingStreamInterceptor(tenancyMgr),
+ ),
+ grpc.UnaryInterceptor(
+ tenancy.NewGuardingUnaryInterceptor(tenancyMgr),
+ ),
)
}
grpcServer := grpc.NewServer(grpcOpts...)
@@ -174,7 +186,10 @@ func newGRPCServer(t *testing.T, q *querysvc.QueryService, mq querysvc.MetricsQu
}
func newGRPCClient(t *testing.T, addr string) *grpcClient {
- conn, err := grpc.NewClient(addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
+ conn, err := grpc.NewClient(
+ addr,
+ grpc.WithTransportCredentials(insecure.NewCredentials()),
+ )
require.NoError(t, err)
return &grpcClient{
@@ -198,8 +213,15 @@ func withMetricsQuery() testOption {
}
}
-func withServerAndClient(t *testing.T, actualTest func(server *grpcServer, client *grpcClient), options ...testOption) {
- server := initializeTenantedTestServerGRPCWithOptions(t, &tenancy.Manager{}, options...)
+func withServerAndClient(
+ t *testing.T,
+ actualTest func(server *grpcServer, client *grpcClient),
+ options ...testOption,
+) {
+ server := initializeTenantedTestServerGRPCWithOptions(
+ t,
+ &tenancy.Manager{},
+ options...)
client := newGRPCClient(t, server.lisAddr.String())
defer server.server.Stop()
defer client.conn.Close()
@@ -210,11 +232,15 @@ func withServerAndClient(t *testing.T, actualTest func(server *grpcServer, clien
func TestGetTraceSuccessGRPC(t *testing.T) {
withServerAndClient(t, func(server *grpcServer, client *grpcClient) {
server.spanReader.On("GetTrace", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("model.TraceID")).
- Return(mockTrace, nil).Once()
+ Return(mockTrace, nil).
+ Once()
- res, err := client.GetTrace(context.Background(), &api_v2.GetTraceRequest{
- TraceID: mockTraceID,
- })
+ res, err := client.GetTrace(
+ context.Background(),
+ &api_v2.GetTraceRequest{
+ TraceID: mockTraceID,
+ },
+ )
spanResChunk, _ := res.Recv()
@@ -233,11 +259,15 @@ func assertGRPCError(t *testing.T, err error, code codes.Code, msg string) {
func TestGetTraceEmptyTraceIDFailure_GRPC(t *testing.T) {
withServerAndClient(t, func(server *grpcServer, client *grpcClient) {
server.spanReader.On("GetTrace", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("model.TraceID")).
- Return(mockTrace, nil).Once()
+ Return(mockTrace, nil).
+ Once()
- res, err := client.GetTrace(context.Background(), &api_v2.GetTraceRequest{
- TraceID: model.TraceID{},
- })
+ res, err := client.GetTrace(
+ context.Background(),
+ &api_v2.GetTraceRequest{
+ TraceID: model.TraceID{},
+ },
+ )
require.NoError(t, err)
@@ -250,15 +280,24 @@ func TestGetTraceEmptyTraceIDFailure_GRPC(t *testing.T) {
func TestGetTraceDBFailureGRPC(t *testing.T) {
withServerAndClient(t, func(server *grpcServer, client *grpcClient) {
server.spanReader.On("GetTrace", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("model.TraceID")).
- Return(nil, errStorageGRPC).Once()
+ Return(nil, errStorageGRPC).
+ Once()
- res, err := client.GetTrace(context.Background(), &api_v2.GetTraceRequest{
- TraceID: mockTraceID,
- })
+ res, err := client.GetTrace(
+ context.Background(),
+ &api_v2.GetTraceRequest{
+ TraceID: mockTraceID,
+ },
+ )
require.NoError(t, err)
spanResChunk, err := res.Recv()
- assertGRPCError(t, err, codes.Internal, "failed to fetch spans from the backend")
+ assertGRPCError(
+ t,
+ err,
+ codes.Internal,
+ "failed to fetch spans from the backend",
+ )
assert.Nil(t, spanResChunk)
})
}
@@ -266,14 +305,19 @@ func TestGetTraceDBFailureGRPC(t *testing.T) {
func TestGetTraceNotFoundGRPC(t *testing.T) {
withServerAndClient(t, func(server *grpcServer, client *grpcClient) {
server.spanReader.On("GetTrace", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("model.TraceID")).
- Return(nil, spanstore.ErrTraceNotFound).Once()
+ Return(nil, spanstore.ErrTraceNotFound).
+ Once()
server.archiveSpanReader.On("GetTrace", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("model.TraceID")).
- Return(nil, spanstore.ErrTraceNotFound).Once()
+ Return(nil, spanstore.ErrTraceNotFound).
+ Once()
- res, err := client.GetTrace(context.Background(), &api_v2.GetTraceRequest{
- TraceID: mockTraceID,
- })
+ res, err := client.GetTrace(
+ context.Background(),
+ &api_v2.GetTraceRequest{
+ TraceID: mockTraceID,
+ },
+ )
require.NoError(t, err)
spanResChunk, err := res.Recv()
assertGRPCError(t, err, codes.NotFound, "trace not found")
@@ -291,13 +335,18 @@ func TestGetTraceNilRequestOnHandlerGRPC(t *testing.T) {
func TestArchiveTraceSuccessGRPC(t *testing.T) {
withServerAndClient(t, func(server *grpcServer, client *grpcClient) {
server.spanReader.On("GetTrace", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("model.TraceID")).
- Return(mockTrace, nil).Once()
+ Return(mockTrace, nil).
+ Once()
server.archiveSpanWriter.On("WriteSpan", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("*model.Span")).
- Return(nil).Times(2)
+ Return(nil).
+ Times(2)
- _, err := client.ArchiveTrace(context.Background(), &api_v2.ArchiveTraceRequest{
- TraceID: mockTraceID,
- })
+ _, err := client.ArchiveTrace(
+ context.Background(),
+ &api_v2.ArchiveTraceRequest{
+ TraceID: mockTraceID,
+ },
+ )
require.NoError(t, err)
})
@@ -306,13 +355,18 @@ func TestArchiveTraceSuccessGRPC(t *testing.T) {
func TestArchiveTraceNotFoundGRPC(t *testing.T) {
withServerAndClient(t, func(server *grpcServer, client *grpcClient) {
server.spanReader.On("GetTrace", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("model.TraceID")).
- Return(nil, spanstore.ErrTraceNotFound).Once()
+ Return(nil, spanstore.ErrTraceNotFound).
+ Once()
server.archiveSpanReader.On("GetTrace", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("model.TraceID")).
- Return(nil, spanstore.ErrTraceNotFound).Once()
+ Return(nil, spanstore.ErrTraceNotFound).
+ Once()
- _, err := client.ArchiveTrace(context.Background(), &api_v2.ArchiveTraceRequest{
- TraceID: mockTraceID,
- })
+ _, err := client.ArchiveTrace(
+ context.Background(),
+ &api_v2.ArchiveTraceRequest{
+ TraceID: mockTraceID,
+ },
+ )
assertGRPCError(t, err, codes.NotFound, "trace not found")
})
@@ -320,9 +374,12 @@ func TestArchiveTraceNotFoundGRPC(t *testing.T) {
func TestArchiveTraceEmptyTraceFailureGRPC(t *testing.T) {
withServerAndClient(t, func(server *grpcServer, client *grpcClient) {
- _, err := client.ArchiveTrace(context.Background(), &api_v2.ArchiveTraceRequest{
- TraceID: model.TraceID{},
- })
+ _, err := client.ArchiveTrace(
+ context.Background(),
+ &api_v2.ArchiveTraceRequest{
+ TraceID: model.TraceID{},
+ },
+ )
require.ErrorIs(t, err, errUninitializedTraceID)
})
}
@@ -337,13 +394,18 @@ func TestArchiveTraceNilRequestOnHandlerGRPC(t *testing.T) {
func TestArchiveTraceFailureGRPC(t *testing.T) {
withServerAndClient(t, func(server *grpcServer, client *grpcClient) {
server.spanReader.On("GetTrace", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("model.TraceID")).
- Return(mockTrace, nil).Once()
+ Return(mockTrace, nil).
+ Once()
server.archiveSpanWriter.On("WriteSpan", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("*model.Span")).
- Return(errStorageGRPC).Times(2)
+ Return(errStorageGRPC).
+ Times(2)
- _, err := client.ArchiveTrace(context.Background(), &api_v2.ArchiveTraceRequest{
- TraceID: mockTraceID,
- })
+ _, err := client.ArchiveTrace(
+ context.Background(),
+ &api_v2.ArchiveTraceRequest{
+ TraceID: mockTraceID,
+ },
+ )
assertGRPCError(t, err, codes.Internal, "failed to archive trace")
})
@@ -352,7 +414,8 @@ func TestArchiveTraceFailureGRPC(t *testing.T) {
func TestFindTracesSuccessGRPC(t *testing.T) {
withServerAndClient(t, func(server *grpcServer, client *grpcClient) {
server.spanReader.On("FindTraces", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("*spanstore.TraceQueryParameters")).
- Return([]*model.Trace{mockTraceGRPC}, nil).Once()
+ Return([]*model.Trace{mockTraceGRPC}, nil).
+ Once()
// Trace query parameters.
queryParams := &api_v2.TraceQueryParameters{
@@ -361,9 +424,12 @@ func TestFindTracesSuccessGRPC(t *testing.T) {
StartTimeMin: time.Now().Add(time.Duration(-10) * time.Minute),
StartTimeMax: time.Now(),
}
- res, err := client.FindTraces(context.Background(), &api_v2.FindTracesRequest{
- Query: queryParams,
- })
+ res, err := client.FindTraces(
+ context.Background(),
+ &api_v2.FindTracesRequest{
+ Query: queryParams,
+ },
+ )
spanResChunk, _ := res.Recv()
require.NoError(t, err)
@@ -379,7 +445,8 @@ func TestFindTracesSuccessGRPC(t *testing.T) {
func TestFindTracesSuccess_SpanStreamingGRPC(t *testing.T) {
withServerAndClient(t, func(server *grpcServer, client *grpcClient) {
server.spanReader.On("FindTraces", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("*spanstore.TraceQueryParameters")).
- Return([]*model.Trace{mockLargeTraceGRPC}, nil).Once()
+ Return([]*model.Trace{mockLargeTraceGRPC}, nil).
+ Once()
// Trace query parameters.
queryParams := &api_v2.TraceQueryParameters{
@@ -388,9 +455,12 @@ func TestFindTracesSuccess_SpanStreamingGRPC(t *testing.T) {
StartTimeMin: time.Now().Add(time.Duration(-10) * time.Minute),
StartTimeMax: time.Now(),
}
- res, err := client.FindTraces(context.Background(), &api_v2.FindTracesRequest{
- Query: queryParams,
- })
+ res, err := client.FindTraces(
+ context.Background(),
+ &api_v2.FindTracesRequest{
+ Query: queryParams,
+ },
+ )
require.NoError(t, err)
spanResChunk, err := res.Recv()
@@ -405,9 +475,12 @@ func TestFindTracesSuccess_SpanStreamingGRPC(t *testing.T) {
func TestFindTracesMissingQuery_GRPC(t *testing.T) {
withServerAndClient(t, func(server *grpcServer, client *grpcClient) {
- res, err := client.FindTraces(context.Background(), &api_v2.FindTracesRequest{
- Query: nil,
- })
+ res, err := client.FindTraces(
+ context.Background(),
+ &api_v2.FindTracesRequest{
+ Query: nil,
+ },
+ )
require.NoError(t, err)
spanResChunk, err := res.Recv()
@@ -421,7 +494,8 @@ func TestFindTracesFailure_GRPC(t *testing.T) {
mockErrorGRPC := fmt.Errorf("whatsamattayou")
server.spanReader.On("FindTraces", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("*spanstore.TraceQueryParameters")).
- Return(nil, mockErrorGRPC).Once()
+ Return(nil, mockErrorGRPC).
+ Once()
// Trace query parameters.
queryParams := &api_v2.TraceQueryParameters{
@@ -431,9 +505,12 @@ func TestFindTracesFailure_GRPC(t *testing.T) {
StartTimeMax: time.Now(),
}
- res, err := client.FindTraces(context.Background(), &api_v2.FindTracesRequest{
- Query: queryParams,
- })
+ res, err := client.FindTraces(
+ context.Background(),
+ &api_v2.FindTracesRequest{
+ Query: queryParams,
+ },
+ )
require.NoError(t, err)
spanResChunk, err := res.Recv()
@@ -452,9 +529,14 @@ func TestFindTracesNilRequestOnHandlerGRPC(t *testing.T) {
func TestGetServicesSuccessGRPC(t *testing.T) {
withServerAndClient(t, func(server *grpcServer, client *grpcClient) {
expectedServices := []string{"trifle", "bling"}
- server.spanReader.On("GetServices", mock.AnythingOfType("*context.valueCtx")).Return(expectedServices, nil).Once()
+ server.spanReader.On("GetServices", mock.AnythingOfType("*context.valueCtx")).
+ Return(expectedServices, nil).
+ Once()
- res, err := client.GetServices(context.Background(), &api_v2.GetServicesRequest{})
+ res, err := client.GetServices(
+ context.Background(),
+ &api_v2.GetServicesRequest{},
+ )
require.NoError(t, err)
actualServices := res.Services
assert.Equal(t, expectedServices, actualServices)
@@ -463,8 +545,13 @@ func TestGetServicesSuccessGRPC(t *testing.T) {
func TestGetServicesFailureGRPC(t *testing.T) {
withServerAndClient(t, func(server *grpcServer, client *grpcClient) {
- server.spanReader.On("GetServices", mock.AnythingOfType("*context.valueCtx")).Return(nil, errStorageGRPC).Once()
- _, err := client.GetServices(context.Background(), &api_v2.GetServicesRequest{})
+ server.spanReader.On("GetServices", mock.AnythingOfType("*context.valueCtx")).
+ Return(nil, errStorageGRPC).
+ Once()
+ _, err := client.GetServices(
+ context.Background(),
+ &api_v2.GetServicesRequest{},
+ )
assertGRPCError(t, err, codes.Internal, "failed to fetch services")
})
@@ -483,9 +570,12 @@ func TestGetOperationsSuccessGRPC(t *testing.T) {
spanstore.OperationQueryParameters{ServiceName: "abc/trifle"},
).Return(expectedOperations, nil).Once()
- res, err := client.GetOperations(context.Background(), &api_v2.GetOperationsRequest{
- Service: "abc/trifle",
- })
+ res, err := client.GetOperations(
+ context.Background(),
+ &api_v2.GetOperationsRequest{
+ Service: "abc/trifle",
+ },
+ )
require.NoError(t, err)
assert.Equal(t, len(expectedOperations), len(res.Operations))
for i, actualOp := range res.Operations {
@@ -503,9 +593,12 @@ func TestGetOperationsFailureGRPC(t *testing.T) {
spanstore.OperationQueryParameters{ServiceName: "trifle"},
).Return(nil, errStorageGRPC).Once()
- _, err := client.GetOperations(context.Background(), &api_v2.GetOperationsRequest{
- Service: "trifle",
- })
+ _, err := client.GetOperations(
+ context.Background(),
+ &api_v2.GetOperationsRequest{
+ Service: "trifle",
+ },
+ )
assertGRPCError(t, err, codes.Internal, "failed to fetch operations")
})
@@ -520,15 +613,23 @@ func TestGetOperationsNilRequestOnHandlerGRPC(t *testing.T) {
func TestGetDependenciesSuccessGRPC(t *testing.T) {
withServerAndClient(t, func(server *grpcServer, client *grpcClient) {
- expectedDependencies := []model.DependencyLink{{Parent: "killer", Child: "queen", CallCount: 12}}
+ expectedDependencies := []model.DependencyLink{
+ {Parent: "killer", Child: "queen", CallCount: 12},
+ }
endTs := time.Now().UTC()
server.depReader.On("GetDependencies", endTs.Add(time.Duration(-1)*defaultDependencyLookbackDuration), defaultDependencyLookbackDuration).
- Return(expectedDependencies, nil).Times(1)
-
- res, err := client.GetDependencies(context.Background(), &api_v2.GetDependenciesRequest{
- StartTime: endTs.Add(time.Duration(-1) * defaultDependencyLookbackDuration),
- EndTime: endTs,
- })
+ Return(expectedDependencies, nil).
+ Times(1)
+
+ res, err := client.GetDependencies(
+ context.Background(),
+ &api_v2.GetDependenciesRequest{
+ StartTime: endTs.Add(
+ time.Duration(-1) * defaultDependencyLookbackDuration,
+ ),
+ EndTime: endTs,
+ },
+ )
require.NoError(t, err)
assert.Equal(t, expectedDependencies, res.Dependencies)
})
@@ -538,12 +639,18 @@ func TestGetDependenciesFailureGRPC(t *testing.T) {
withServerAndClient(t, func(server *grpcServer, client *grpcClient) {
endTs := time.Now().UTC()
server.depReader.On("GetDependencies", endTs.Add(time.Duration(-1)*defaultDependencyLookbackDuration), defaultDependencyLookbackDuration).
- Return(nil, errStorageGRPC).Times(1)
-
- _, err := client.GetDependencies(context.Background(), &api_v2.GetDependenciesRequest{
- StartTime: endTs.Add(time.Duration(-1) * defaultDependencyLookbackDuration),
- EndTime: endTs,
- })
+ Return(nil, errStorageGRPC).
+ Times(1)
+
+ _, err := client.GetDependencies(
+ context.Background(),
+ &api_v2.GetDependenciesRequest{
+ StartTime: endTs.Add(
+ time.Duration(-1) * defaultDependencyLookbackDuration,
+ ),
+ EndTime: endTs,
+ },
+ )
assertGRPCError(t, err, codes.Internal, "failed to fetch dependencies")
})
@@ -561,10 +668,13 @@ func TestGetDependenciesFailureUninitializedTimeGRPC(t *testing.T) {
for _, input := range timeInputs {
withServerAndClient(t, func(server *grpcServer, client *grpcClient) {
- _, err := client.GetDependencies(context.Background(), &api_v2.GetDependenciesRequest{
- StartTime: input.startTime,
- EndTime: input.endTime,
- })
+ _, err := client.GetDependencies(
+ context.Background(),
+ &api_v2.GetDependenciesRequest{
+ StartTime: input.startTime,
+ EndTime: input.endTime,
+ },
+ )
require.Error(t, err)
})
@@ -629,7 +739,8 @@ func TestGetMetricsSuccessGRPC(t *testing.T) {
expectedMetrics := &metrics.MetricFamily{Name: "foo"}
m := server.metricsQueryService.(*metricsmocks.Reader)
m.On(tc.mockMethod, mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType(tc.mockParamType)).
- Return(expectedMetrics, nil).Once()
+ Return(expectedMetrics, nil).
+ Once()
res, err := tc.testFn(client)
require.NoError(t, err)
@@ -672,7 +783,12 @@ func TestGetMetricsReaderDisabledGRPC(t *testing.T) {
require.Error(t, err)
assert.Nil(t, res)
- assertGRPCError(t, err, codes.Unimplemented, "metrics querying is currently disabled")
+ assertGRPCError(
+ t,
+ err,
+ codes.Unimplemented,
+ "metrics querying is currently disabled",
+ )
})
}
})
@@ -699,7 +815,8 @@ func TestGetMetricsUseDefaultParamsGRPC(t *testing.T) {
}
m := server.metricsQueryService.(*metricsmocks.Reader)
m.On("GetCallRates", mock.AnythingOfType("*context.valueCtx"), expectedParams).
- Return(expectedMetrics, nil).Once()
+ Return(expectedMetrics, nil).
+ Once()
res, err := client.GetCallRates(context.Background(), request)
require.NoError(t, err)
@@ -740,7 +857,8 @@ func TestGetMetricsOverrideDefaultParamsGRPC(t *testing.T) {
}
m := server.metricsQueryService.(*metricsmocks.Reader)
m.On("GetCallRates", mock.AnythingOfType("*context.valueCtx"), expectedParams).
- Return(expectedMetrics, nil).Once()
+ Return(expectedMetrics, nil).
+ Once()
res, err := client.GetCallRates(context.Background(), request)
require.NoError(t, err)
@@ -787,7 +905,8 @@ func TestGetMetricsFailureGRPC(t *testing.T) {
t.Run(tc.mockMethod, func(t *testing.T) {
m := server.metricsQueryService.(*metricsmocks.Reader)
m.On(tc.mockMethod, mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType(tc.mockParamType)).
- Return(nil, errStorageGRPC).Once()
+ Return(nil, errStorageGRPC).
+ Once()
res, err := tc.testFn(client)
require.Nil(t, res)
@@ -803,9 +922,13 @@ func TestGetMinStepDurationSuccessGRPC(t *testing.T) {
withServerAndClient(t, func(server *grpcServer, client *grpcClient) {
m := server.metricsQueryService.(*metricsmocks.Reader)
m.On("GetMinStepDuration", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("*metricsstore.MinStepDurationQueryParameters")).
- Return(time.Hour, nil).Once()
+ Return(time.Hour, nil).
+ Once()
- res, err := client.GetMinStepDuration(context.Background(), &metrics.GetMinStepDurationRequest{})
+ res, err := client.GetMinStepDuration(
+ context.Background(),
+ &metrics.GetMinStepDurationRequest{},
+ )
require.NoError(t, err)
require.Equal(t, time.Hour, res.MinStep)
}, withMetricsQuery())
@@ -815,13 +938,22 @@ func TestGetMinStepDurationFailureGRPC(t *testing.T) {
withServerAndClient(t, func(server *grpcServer, client *grpcClient) {
m := server.metricsQueryService.(*metricsmocks.Reader)
m.On("GetMinStepDuration", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("*metricsstore.MinStepDurationQueryParameters")).
- Return(time.Duration(0), errStorageGRPC).Once()
+ Return(time.Duration(0), errStorageGRPC).
+ Once()
- res, err := client.GetMinStepDuration(context.Background(), &metrics.GetMinStepDurationRequest{})
+ res, err := client.GetMinStepDuration(
+ context.Background(),
+ &metrics.GetMinStepDurationRequest{},
+ )
require.Nil(t, res)
require.Error(t, err)
- assertGRPCError(t, err, codes.Internal, "failed to fetch min step duration: storage error")
+ assertGRPCError(
+ t,
+ err,
+ codes.Internal,
+ "failed to fetch min step duration: storage error",
+ )
}, withMetricsQuery())
}
@@ -897,7 +1029,11 @@ func TestMetricsQueryNilRequestGRPC(t *testing.T) {
require.EqualError(t, err, errNilRequest.Error())
}
-func initializeTenantedTestServerGRPCWithOptions(t *testing.T, tm *tenancy.Manager, options ...testOption) *grpcServer {
+func initializeTenantedTestServerGRPCWithOptions(
+ t *testing.T,
+ tm *tenancy.Manager,
+ options ...testOption,
+) *grpcServer {
archiveSpanReader := &spanstoremocks.Reader{}
archiveSpanWriter := &spanstoremocks.Writer{}
@@ -925,7 +1061,14 @@ func initializeTenantedTestServerGRPCWithOptions(t *testing.T, tm *tenancy.Manag
logger := zap.NewNop()
tracer := jtracer.NoOp()
- server, addr := newGRPCServer(t, q, tqs.metricsQueryService, logger, tracer, tm)
+ server, addr := newGRPCServer(
+ t,
+ q,
+ tqs.metricsQueryService,
+ logger,
+ tracer,
+ tm,
+ )
return &grpcServer{
server: server,
@@ -938,7 +1081,12 @@ func initializeTenantedTestServerGRPCWithOptions(t *testing.T, tm *tenancy.Manag
}
}
-func withTenantedServerAndClient(t *testing.T, tm *tenancy.Manager, actualTest func(server *grpcServer, client *grpcClient), options ...testOption) {
+func withTenantedServerAndClient(
+ t *testing.T,
+ tm *tenancy.Manager,
+ actualTest func(server *grpcServer, client *grpcClient),
+ options ...testOption,
+) {
server := initializeTenantedTestServerGRPCWithOptions(t, tm, options...)
client := newGRPCClient(t, server.lisAddr.String())
defer server.server.Stop()
@@ -949,7 +1097,11 @@ func withTenantedServerAndClient(t *testing.T, tm *tenancy.Manager, actualTest f
// withOutgoingMetadata returns a Context with metadata for a server to receive
// revive:disable-next-line context-as-argument
-func withOutgoingMetadata(t *testing.T, ctx context.Context, headerName, headerValue string) context.Context {
+func withOutgoingMetadata(
+ t *testing.T,
+ ctx context.Context,
+ headerName, headerValue string,
+) context.Context {
t.Helper()
md := metadata.New(map[string]string{headerName: headerValue})
@@ -962,34 +1114,54 @@ func TestSearchTenancyGRPC(t *testing.T) {
})
withTenantedServerAndClient(t, tm, func(server *grpcServer, client *grpcClient) {
server.spanReader.On("GetTrace", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("model.TraceID")).
- Return(mockTrace, nil).Once()
+ Return(mockTrace, nil).
+ Once()
// First try without tenancy header
- res, err := client.GetTrace(context.Background(), &api_v2.GetTraceRequest{
- TraceID: mockTraceID,
- })
+ res, err := client.GetTrace(
+ context.Background(),
+ &api_v2.GetTraceRequest{
+ TraceID: mockTraceID,
+ },
+ )
require.NoError(t, err, "could not initiate GetTraceRequest")
spanResChunk, err := res.Recv()
- assertGRPCError(t, err, codes.Unauthenticated, "missing tenant header")
+ assertGRPCError(
+ t,
+ err,
+ codes.Unauthenticated,
+ "missing tenant header",
+ )
assert.Nil(t, spanResChunk)
// Next try with tenancy
res, err = client.GetTrace(
- withOutgoingMetadata(t, context.Background(), tm.Header, "acme"),
+ withOutgoingMetadata(
+ t,
+ context.Background(),
+ tm.Header,
+ "acme",
+ ),
&api_v2.GetTraceRequest{
TraceID: mockTraceID,
- })
+ },
+ )
spanResChunk, _ = res.Recv()
- require.NoError(t, err, "expecting gRPC to succeed with any tenancy header")
+ require.NoError(
+ t,
+ err,
+ "expecting gRPC to succeed with any tenancy header",
+ )
require.NotNil(t, spanResChunk)
require.NotNil(t, spanResChunk.Spans)
require.Equal(t, len(mockTrace.Spans), len(spanResChunk.Spans))
assert.Equal(t, mockTraceID, spanResChunk.Spans[0].TraceID)
- })
+ },
+ )
}
func TestServicesTenancyGRPC(t *testing.T) {
@@ -998,14 +1170,27 @@ func TestServicesTenancyGRPC(t *testing.T) {
})
withTenantedServerAndClient(t, tm, func(server *grpcServer, client *grpcClient) {
expectedServices := []string{"trifle", "bling"}
- server.spanReader.On("GetServices", mock.AnythingOfType("*context.valueCtx")).Return(expectedServices, nil).Once()
+ server.spanReader.On("GetServices", mock.AnythingOfType("*context.valueCtx")).
+ Return(expectedServices, nil).
+ Once()
// First try without tenancy header
- _, err := client.GetServices(context.Background(), &api_v2.GetServicesRequest{})
- assertGRPCError(t, err, codes.Unauthenticated, "missing tenant header")
+ _, err := client.GetServices(
+ context.Background(),
+ &api_v2.GetServicesRequest{},
+ )
+ assertGRPCError(
+ t,
+ err,
+ codes.Unauthenticated,
+ "missing tenant header",
+ )
// Next try with tenancy
- res, err := client.GetServices(withOutgoingMetadata(t, context.Background(), tm.Header, "acme"), &api_v2.GetServicesRequest{})
+ res, err := client.GetServices(
+ withOutgoingMetadata(t, context.Background(), tm.Header, "acme"),
+ &api_v2.GetServicesRequest{},
+ )
require.NoError(t, err, "expecting gRPC to succeed with any tenancy header")
assert.Equal(t, expectedServices, res.Services)
})
@@ -1019,7 +1204,8 @@ func TestSearchTenancyGRPCExplicitList(t *testing.T) {
})
withTenantedServerAndClient(t, tm, func(server *grpcServer, client *grpcClient) {
server.spanReader.On("GetTrace", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("model.TraceID")).
- Return(mockTrace, nil).Once()
+ Return(mockTrace, nil).
+ Once()
for _, tc := range []struct {
name string
@@ -1068,18 +1254,32 @@ func TestSearchTenancyGRPCExplicitList(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
ctx := context.Background()
if tc.tenancyHeader != "" {
- ctx = withOutgoingMetadata(t, context.Background(), tc.tenancyHeader, tc.tenant)
+ ctx = withOutgoingMetadata(
+ t,
+ context.Background(),
+ tc.tenancyHeader,
+ tc.tenant,
+ )
}
res, err := client.GetTrace(ctx, &api_v2.GetTraceRequest{
TraceID: mockTraceID,
})
- require.NoError(t, err, "could not initiate GetTraceRequest")
+ require.NoError(
+ t,
+ err,
+ "could not initiate GetTraceRequest",
+ )
spanResChunk, err := res.Recv()
if tc.wantErr {
- assertGRPCError(t, err, tc.failureCode, tc.failureMessage)
+ assertGRPCError(
+ t,
+ err,
+ tc.failureCode,
+ tc.failureMessage,
+ )
assert.Nil(t, spanResChunk)
} else {
require.NoError(t, err, "expecting gRPC to succeed")
@@ -1090,80 +1290,112 @@ func TestSearchTenancyGRPCExplicitList(t *testing.T) {
}
})
}
- })
+ },
+ )
}
func TestTenancyContextFlowGRPC(t *testing.T) {
tm := tenancy.NewManager(&tenancy.Options{
Enabled: true,
})
- withTenantedServerAndClient(t, tm, func(server *grpcServer, client *grpcClient) {
- // Mock a storage backend with tenant 'acme' and 'megacorp'
- allExpectedResults := map[string]struct {
- expectedServices []string
- expectedTrace *model.Trace
- expectedTraceErr error
- }{
- "acme": {[]string{"trifle", "bling"}, mockTrace, nil},
- "megacorp": {[]string{"grapefruit"}, nil, errStorageGRPC},
- }
-
- addTenantedGetServices := func(mockReader *spanstoremocks.Reader, tenant string, expectedServices []string) {
- mockReader.On("GetServices", mock.MatchedBy(func(v any) bool {
- ctx, ok := v.(context.Context)
- if !ok {
- return false
- }
- if tenancy.GetTenant(ctx) != tenant {
- return false
- }
- return true
- })).Return(expectedServices, nil).Once()
- }
- addTenantedGetTrace := func(mockReader *spanstoremocks.Reader, tenant string, trace *model.Trace, err error) {
- mockReader.On("GetTrace", mock.MatchedBy(func(v any) bool {
- ctx, ok := v.(context.Context)
- if !ok {
- return false
- }
- if tenancy.GetTenant(ctx) != tenant {
- return false
- }
- return true
- }), mock.AnythingOfType("model.TraceID")).Return(trace, err).Once()
- }
-
- for tenant, expected := range allExpectedResults {
- addTenantedGetServices(server.spanReader, tenant, expected.expectedServices)
- addTenantedGetTrace(server.spanReader, tenant, expected.expectedTrace, expected.expectedTraceErr)
- }
-
- for tenant, expected := range allExpectedResults {
- t.Run(tenant, func(t *testing.T) {
- // Test context propagation to Unary method.
- resGetServices, err := client.GetServices(withOutgoingMetadata(t, context.Background(), tm.Header, tenant), &api_v2.GetServicesRequest{})
- require.NoError(t, err, "expecting gRPC to succeed with %q tenancy header", tenant)
- assert.Equal(t, expected.expectedServices, resGetServices.Services)
-
- // Test context propagation to Streaming method.
- resGetTrace, err := client.GetTrace(withOutgoingMetadata(t, context.Background(), tm.Header, tenant),
- &api_v2.GetTraceRequest{
- TraceID: mockTraceID,
- })
- require.NoError(t, err)
- spanResChunk, err := resGetTrace.Recv()
-
- if expected.expectedTrace != nil {
- assert.Equal(t, expected.expectedTrace.Spans[0].TraceID, spanResChunk.Spans[0].TraceID)
- }
- if expected.expectedTraceErr != nil {
- assert.Contains(t, err.Error(), expected.expectedTraceErr.Error())
- }
- })
- }
+ withTenantedServerAndClient(
+ t,
+ tm,
+ func(server *grpcServer, client *grpcClient) {
+ // Mock a storage backend with tenant 'acme' and 'megacorp'
+ allExpectedResults := map[string]struct {
+ expectedServices []string
+ expectedTrace *model.Trace
+ expectedTraceErr error
+ }{
+ "acme": {[]string{"trifle", "bling"}, mockTrace, nil},
+ "megacorp": {[]string{"grapefruit"}, nil, errStorageGRPC},
+ }
+
+ addTenantedGetServices := func(mockReader *spanstoremocks.Reader, tenant string, expectedServices []string) {
+ mockReader.On("GetServices", mock.MatchedBy(func(v any) bool {
+ ctx, ok := v.(context.Context)
+ if !ok {
+ return false
+ }
+ if tenancy.GetTenant(ctx) != tenant {
+ return false
+ }
+ return true
+ })).Return(expectedServices, nil).Once()
+ }
+ addTenantedGetTrace := func(mockReader *spanstoremocks.Reader, tenant string, trace *model.Trace, err error) {
+ mockReader.On("GetTrace", mock.MatchedBy(func(v any) bool {
+ ctx, ok := v.(context.Context)
+ if !ok {
+ return false
+ }
+ if tenancy.GetTenant(ctx) != tenant {
+ return false
+ }
+ return true
+ }), mock.AnythingOfType("model.TraceID")).Return(trace, err).Once()
+ }
+
+ for tenant, expected := range allExpectedResults {
+ addTenantedGetServices(
+ server.spanReader,
+ tenant,
+ expected.expectedServices,
+ )
+ addTenantedGetTrace(
+ server.spanReader,
+ tenant,
+ expected.expectedTrace,
+ expected.expectedTraceErr,
+ )
+ }
+
+ for tenant, expected := range allExpectedResults {
+ t.Run(tenant, func(t *testing.T) {
+ // Test context propagation to Unary method.
+ resGetServices, err := client.GetServices(
+ withOutgoingMetadata(t, context.Background(), tm.Header, tenant),
+ &api_v2.GetServicesRequest{},
+ )
+ require.NoError(t, err, "expecting gRPC to succeed with %q tenancy header", tenant)
+ assert.Equal(t, expected.expectedServices, resGetServices.Services)
+
+ // Test context propagation to Streaming method.
+ resGetTrace, err := client.GetTrace(
+ withOutgoingMetadata(
+ t,
+ context.Background(),
+ tm.Header,
+ tenant,
+ ),
+ &api_v2.GetTraceRequest{
+ TraceID: mockTraceID,
+ },
+ )
+ require.NoError(t, err)
+ spanResChunk, err := resGetTrace.Recv()
+
+ if expected.expectedTrace != nil {
+ assert.Equal(
+ t,
+ expected.expectedTrace.Spans[0].TraceID,
+ spanResChunk.Spans[0].TraceID,
+ )
+ }
+ if expected.expectedTraceErr != nil {
+ assert.Contains(
+ t,
+ err.Error(),
+ expected.expectedTraceErr.Error(),
+ )
+ }
+ })
+ }
- server.spanReader.AssertExpectations(t)
- })
+ server.spanReader.AssertExpectations(t)
+ },
+ )
}
func TestNewGRPCHandlerWithEmptyOptions(t *testing.T) {
diff --git a/cmd/query/app/handler_archive_test.go b/cmd/query/app/handler_archive_test.go
index 9b48941d0cb..f7edeef7939 100644
--- a/cmd/query/app/handler_archive_test.go
+++ b/cmd/query/app/handler_archive_test.go
@@ -32,7 +32,8 @@ import (
func TestGetArchivedTrace_NotFound(t *testing.T) {
mockReader := &spanstoremocks.Reader{}
mockReader.On("GetTrace", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("model.TraceID")).
- Return(nil, spanstore.ErrTraceNotFound).Once()
+ Return(nil, spanstore.ErrTraceNotFound).
+ Once()
for _, tc := range []struct {
name string
reader spanstore.Reader
@@ -50,10 +51,13 @@ func TestGetArchivedTrace_NotFound(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
withTestServer(func(ts *testServer) {
ts.spanReader.On("GetTrace", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("model.TraceID")).
- Return(nil, spanstore.ErrTraceNotFound).Once()
+ Return(nil, spanstore.ErrTraceNotFound).
+ Once()
var response structuredResponse
err := getJSON(ts.server.URL+"/api/traces/"+mockTraceID.String(), &response)
- require.EqualError(t, err,
+ require.EqualError(
+ t,
+ err,
`404 error from server: {"data":null,"total":0,"limit":0,"offset":0,"errors":[{"code":404,"msg":"trace not found"}]}`+"\n",
)
}, querysvc.QueryServiceOptions{ArchiveSpanReader: tc.reader}) // nil is ok
@@ -65,13 +69,18 @@ func TestGetArchivedTraceSuccess(t *testing.T) {
traceID := model.NewTraceID(0, 123456)
mockReader := &spanstoremocks.Reader{}
mockReader.On("GetTrace", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("model.TraceID")).
- Return(mockTrace, nil).Once()
+ Return(mockTrace, nil).
+ Once()
withTestServer(func(ts *testServer) {
// make main reader return NotFound
ts.spanReader.On("GetTrace", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("model.TraceID")).
- Return(nil, spanstore.ErrTraceNotFound).Once()
+ Return(nil, spanstore.ErrTraceNotFound).
+ Once()
var response structuredTraceResponse
- err := getJSON(ts.server.URL+"/api/traces/"+mockTraceID.String(), &response)
+ err := getJSON(
+ ts.server.URL+"/api/traces/"+mockTraceID.String(),
+ &response,
+ )
require.NoError(t, err)
assert.Empty(t, response.Errors)
assert.Len(t, response.Traces, 1)
@@ -83,7 +92,11 @@ func TestGetArchivedTraceSuccess(t *testing.T) {
func TestArchiveTrace_BadTraceID(t *testing.T) {
withTestServer(func(ts *testServer) {
var response structuredResponse
- err := postJSON(ts.server.URL+"/api/archive/badtraceid", []string{}, &response)
+ err := postJSON(
+ ts.server.URL+"/api/archive/badtraceid",
+ []string{},
+ &response,
+ )
require.Error(t, err)
}, querysvc.QueryServiceOptions{})
}
@@ -92,16 +105,22 @@ func TestArchiveTrace_BadTraceID(t *testing.T) {
func TestArchiveTrace_TraceNotFound(t *testing.T) {
mockReader := &spanstoremocks.Reader{}
mockReader.On("GetTrace", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("model.TraceID")).
- Return(nil, spanstore.ErrTraceNotFound).Once()
+ Return(nil, spanstore.ErrTraceNotFound).
+ Once()
mockWriter := &spanstoremocks.Writer{}
// Not actually going to write the trace, so no need to define mockWriter action
withTestServer(func(ts *testServer) {
// make main reader return NotFound
ts.spanReader.On("GetTrace", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("model.TraceID")).
- Return(nil, spanstore.ErrTraceNotFound).Once()
+ Return(nil, spanstore.ErrTraceNotFound).
+ Once()
var response structuredResponse
err := postJSON(ts.server.URL+"/api/archive/"+mockTraceID.String(), []string{}, &response)
- require.EqualError(t, err, `404 error from server: {"data":null,"total":0,"limit":0,"offset":0,"errors":[{"code":404,"msg":"trace not found"}]}`+"\n")
+ require.EqualError(
+ t,
+ err,
+ `404 error from server: {"data":null,"total":0,"limit":0,"offset":0,"errors":[{"code":404,"msg":"trace not found"}]}`+"\n",
+ )
}, querysvc.QueryServiceOptions{ArchiveSpanReader: mockReader, ArchiveSpanWriter: mockWriter})
}
@@ -109,19 +128,29 @@ func TestArchiveTrace_NoStorage(t *testing.T) {
withTestServer(func(ts *testServer) {
var response structuredResponse
err := postJSON(ts.server.URL+"/api/archive/"+mockTraceID.String(), []string{}, &response)
- require.EqualError(t, err, `500 error from server: {"data":null,"total":0,"limit":0,"offset":0,"errors":[{"code":500,"msg":"archive span storage was not configured"}]}`+"\n")
+ require.EqualError(
+ t,
+ err,
+ `500 error from server: {"data":null,"total":0,"limit":0,"offset":0,"errors":[{"code":500,"msg":"archive span storage was not configured"}]}`+"\n",
+ )
}, querysvc.QueryServiceOptions{})
}
func TestArchiveTrace_Success(t *testing.T) {
mockWriter := &spanstoremocks.Writer{}
mockWriter.On("WriteSpan", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("*model.Span")).
- Return(nil).Times(2)
+ Return(nil).
+ Times(2)
withTestServer(func(ts *testServer) {
ts.spanReader.On("GetTrace", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("model.TraceID")).
- Return(mockTrace, nil).Once()
+ Return(mockTrace, nil).
+ Once()
var response structuredResponse
- err := postJSON(ts.server.URL+"/api/archive/"+mockTraceID.String(), []string{}, &response)
+ err := postJSON(
+ ts.server.URL+"/api/archive/"+mockTraceID.String(),
+ []string{},
+ &response,
+ )
require.NoError(t, err)
}, querysvc.QueryServiceOptions{ArchiveSpanWriter: mockWriter})
}
@@ -129,12 +158,18 @@ func TestArchiveTrace_Success(t *testing.T) {
func TestArchiveTrace_WriteErrors(t *testing.T) {
mockWriter := &spanstoremocks.Writer{}
mockWriter.On("WriteSpan", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("*model.Span")).
- Return(errors.New("cannot save")).Times(2)
+ Return(errors.New("cannot save")).
+ Times(2)
withTestServer(func(ts *testServer) {
ts.spanReader.On("GetTrace", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("model.TraceID")).
- Return(mockTrace, nil).Once()
+ Return(mockTrace, nil).
+ Once()
var response structuredResponse
err := postJSON(ts.server.URL+"/api/archive/"+mockTraceID.String(), []string{}, &response)
- require.EqualError(t, err, `500 error from server: {"data":null,"total":0,"limit":0,"offset":0,"errors":[{"code":500,"msg":"cannot save\ncannot save"}]}`+"\n")
+ require.EqualError(
+ t,
+ err,
+ `500 error from server: {"data":null,"total":0,"limit":0,"offset":0,"errors":[{"code":500,"msg":"cannot save\ncannot save"}]}`+"\n",
+ )
}, querysvc.QueryServiceOptions{ArchiveSpanWriter: mockWriter})
}
diff --git a/cmd/query/app/handler_deps_test.go b/cmd/query/app/handler_deps_test.go
index 50394e4c429..8bbdd1b0152 100644
--- a/cmd/query/app/handler_deps_test.go
+++ b/cmd/query/app/handler_deps_test.go
@@ -303,7 +303,10 @@ func TestFilterDependencies(t *testing.T) {
}
for _, test := range tests {
- actual := handler.filterDependenciesByService(test.dependencies, test.service)
+ actual := handler.filterDependenciesByService(
+ test.dependencies,
+ test.service,
+ )
assert.Equal(t, test.expected, actual, test.description, test.service)
}
}
@@ -311,12 +314,19 @@ func TestFilterDependencies(t *testing.T) {
func TestGetDependenciesSuccess(t *testing.T) {
ts := initializeTestServer()
defer ts.server.Close()
- expectedDependencies := []model.DependencyLink{{Parent: "killer", Child: "queen", CallCount: 12}}
+ expectedDependencies := []model.DependencyLink{
+ {Parent: "killer", Child: "queen", CallCount: 12},
+ }
endTs := time.Unix(0, 1476374248550*millisToNanosMultiplier)
- ts.dependencyReader.On("GetDependencies", endTs, defaultDependencyLookbackDuration).Return(expectedDependencies, nil).Times(1)
+ ts.dependencyReader.On("GetDependencies", endTs, defaultDependencyLookbackDuration).
+ Return(expectedDependencies, nil).
+ Times(1)
var response structuredResponse
- err := getJSON(ts.server.URL+"/api/dependencies?endTs=1476374248550&service=queen", &response)
+ err := getJSON(
+ ts.server.URL+"/api/dependencies?endTs=1476374248550&service=queen",
+ &response,
+ )
assert.NotEmpty(t, response.Data)
data := response.Data.([]any)[0]
actual := data.(map[string]any)
@@ -330,10 +340,15 @@ func TestGetDependenciesCassandraFailure(t *testing.T) {
ts := initializeTestServer()
defer ts.server.Close()
endTs := time.Unix(0, 1476374248550*millisToNanosMultiplier)
- ts.dependencyReader.On("GetDependencies", endTs, defaultDependencyLookbackDuration).Return(nil, errStorage).Times(1)
+ ts.dependencyReader.On("GetDependencies", endTs, defaultDependencyLookbackDuration).
+ Return(nil, errStorage).
+ Times(1)
var response structuredResponse
- err := getJSON(ts.server.URL+"/api/dependencies?endTs=1476374248550&service=testing", &response)
+ err := getJSON(
+ ts.server.URL+"/api/dependencies?endTs=1476374248550&service=testing",
+ &response,
+ )
require.Error(t, err)
}
@@ -342,7 +357,10 @@ func TestGetDependenciesEndTimeParsingFailure(t *testing.T) {
defer ts.server.Close()
var response structuredResponse
- err := getJSON(ts.server.URL+"/api/dependencies?endTs=shazbot&service=testing", &response)
+ err := getJSON(
+ ts.server.URL+"/api/dependencies?endTs=shazbot&service=testing",
+ &response,
+ )
require.Error(t, err)
}
@@ -351,6 +369,9 @@ func TestGetDependenciesLookbackParsingFailure(t *testing.T) {
defer ts.server.Close()
var response structuredResponse
- err := getJSON(ts.server.URL+"/api/dependencies?endTs=1476374248550&service=testing&lookback=shazbot", &response)
+ err := getJSON(
+ ts.server.URL+"/api/dependencies?endTs=1476374248550&service=testing&lookback=shazbot",
+ &response,
+ )
require.Error(t, err)
}
diff --git a/cmd/query/app/handler_options.go b/cmd/query/app/handler_options.go
index 853a41a2222..fd060bc11ae 100644
--- a/cmd/query/app/handler_options.go
+++ b/cmd/query/app/handler_options.go
@@ -55,7 +55,9 @@ func (handlerOptions) Prefix(prefix string) HandlerOption {
}
// QueryLookbackDuration creates a HandlerOption that initializes lookback duration
-func (handlerOptions) QueryLookbackDuration(queryLookbackDuration time.Duration) HandlerOption {
+func (handlerOptions) QueryLookbackDuration(
+ queryLookbackDuration time.Duration,
+) HandlerOption {
return func(apiHandler *APIHandler) {
apiHandler.queryParser.traceQueryLookbackDuration = queryLookbackDuration
}
@@ -69,7 +71,9 @@ func (handlerOptions) Tracer(tracer *jtracer.JTracer) HandlerOption {
}
// MetricsQueryService creates a HandlerOption that initializes MetricsQueryService.
-func (handlerOptions) MetricsQueryService(mqs querysvc.MetricsQueryService) HandlerOption {
+func (handlerOptions) MetricsQueryService(
+ mqs querysvc.MetricsQueryService,
+) HandlerOption {
return func(apiHandler *APIHandler) {
apiHandler.metricsQueryService = mqs
}
diff --git a/cmd/query/app/http_handler.go b/cmd/query/app/http_handler.go
index 5f217118610..1fe4f8b8c2b 100644
--- a/cmd/query/app/http_handler.go
+++ b/cmd/query/app/http_handler.go
@@ -94,7 +94,11 @@ type APIHandler struct {
}
// NewAPIHandler returns an APIHandler
-func NewAPIHandler(queryService *querysvc.QueryService, tm *tenancy.Manager, options ...HandlerOption) *APIHandler {
+func NewAPIHandler(
+ queryService *querysvc.QueryService,
+ tm *tenancy.Manager,
+ options ...HandlerOption,
+) *APIHandler {
aH := &APIHandler{
queryService: queryService,
queryParser: queryParser{
@@ -121,20 +125,28 @@ func NewAPIHandler(queryService *querysvc.QueryService, tm *tenancy.Manager, opt
// RegisterRoutes registers routes for this handler on the given router
func (aH *APIHandler) RegisterRoutes(router *mux.Router) {
- aH.handleFunc(router, aH.getTrace, "/traces/{%s}", traceIDParam).Methods(http.MethodGet)
- aH.handleFunc(router, aH.archiveTrace, "/archive/{%s}", traceIDParam).Methods(http.MethodPost)
+ aH.handleFunc(router, aH.getTrace, "/traces/{%s}", traceIDParam).
+ Methods(http.MethodGet)
+ aH.handleFunc(router, aH.archiveTrace, "/archive/{%s}", traceIDParam).
+ Methods(http.MethodPost)
aH.handleFunc(router, aH.search, "/traces").Methods(http.MethodGet)
aH.handleFunc(router, aH.getServices, "/services").Methods(http.MethodGet)
// TODO change the UI to use this endpoint. Requires ?service= parameter.
- aH.handleFunc(router, aH.getOperations, "/operations").Methods(http.MethodGet)
+ aH.handleFunc(router, aH.getOperations, "/operations").
+ Methods(http.MethodGet)
// TODO - remove this when UI catches up
- aH.handleFunc(router, aH.getOperationsLegacy, "/services/{%s}/operations", serviceParam).Methods(http.MethodGet)
- aH.handleFunc(router, aH.transformOTLP, "/transform").Methods(http.MethodPost)
- aH.handleFunc(router, aH.dependencies, "/dependencies").Methods(http.MethodGet)
- aH.handleFunc(router, aH.latencies, "/metrics/latencies").Methods(http.MethodGet)
+ aH.handleFunc(router, aH.getOperationsLegacy, "/services/{%s}/operations", serviceParam).
+ Methods(http.MethodGet)
+ aH.handleFunc(router, aH.transformOTLP, "/transform").
+ Methods(http.MethodPost)
+ aH.handleFunc(router, aH.dependencies, "/dependencies").
+ Methods(http.MethodGet)
+ aH.handleFunc(router, aH.latencies, "/metrics/latencies").
+ Methods(http.MethodGet)
aH.handleFunc(router, aH.calls, "/metrics/calls").Methods(http.MethodGet)
aH.handleFunc(router, aH.errors, "/metrics/errors").Methods(http.MethodGet)
- aH.handleFunc(router, aH.minStep, "/metrics/minstep").Methods(http.MethodGet)
+ aH.handleFunc(router, aH.minStep, "/metrics/minstep").
+ Methods(http.MethodGet)
}
func (aH *APIHandler) handleFunc(
@@ -172,7 +184,10 @@ func (aH *APIHandler) getServices(w http.ResponseWriter, r *http.Request) {
aH.writeJSON(w, r, &structuredRes)
}
-func (aH *APIHandler) getOperationsLegacy(w http.ResponseWriter, r *http.Request) {
+func (aH *APIHandler) getOperationsLegacy(
+ w http.ResponseWriter,
+ r *http.Request,
+) {
vars := mux.Vars(r)
// given how getOperationsLegacy is bound to URL route, serviceParam cannot be empty
service, _ := url.QueryUnescape(vars[serviceParam])
@@ -214,14 +229,21 @@ func (aH *APIHandler) transformOTLP(w http.ResponseWriter, r *http.Request) {
func (aH *APIHandler) getOperations(w http.ResponseWriter, r *http.Request) {
service := r.FormValue(serviceParam)
if service == "" {
- if aH.handleError(w, errServiceParameterRequired, http.StatusBadRequest) {
+ if aH.handleError(
+ w,
+ errServiceParameterRequired,
+ http.StatusBadRequest,
+ ) {
return
}
}
spanKind := r.FormValue(spanKindParam)
operations, err := aH.queryService.GetOperations(
r.Context(),
- spanstore.OperationQueryParameters{ServiceName: service, SpanKind: spanKind},
+ spanstore.OperationQueryParameters{
+ ServiceName: service,
+ SpanKind: spanKind,
+ },
)
if aH.handleError(w, err, http.StatusInternalServerError) {
@@ -250,7 +272,10 @@ func (aH *APIHandler) search(w http.ResponseWriter, r *http.Request) {
var uiErrors []structuredError
var tracesFromStorage []*model.Trace
if len(tQuery.traceIDs) > 0 {
- tracesFromStorage, uiErrors, err = aH.tracesByIDs(r.Context(), tQuery.traceIDs)
+ tracesFromStorage, uiErrors, err = aH.tracesByIDs(
+ r.Context(),
+ tQuery.traceIDs,
+ )
if aH.handleError(w, err, http.StatusInternalServerError) {
return
}
@@ -265,7 +290,11 @@ func (aH *APIHandler) search(w http.ResponseWriter, r *http.Request) {
aH.writeJSON(w, r, structuredRes)
}
-func (aH *APIHandler) tracesToResponse(traces []*model.Trace, adjust bool, uiErrors []structuredError) *structuredResponse {
+func (aH *APIHandler) tracesToResponse(
+ traces []*model.Trace,
+ adjust bool,
+ uiErrors []structuredError,
+) *structuredResponse {
uiTraces := make([]*ui.Trace, len(traces))
for i, v := range traces {
uiTrace, uiErr := aH.convertModelToUI(v, adjust)
@@ -281,7 +310,10 @@ func (aH *APIHandler) tracesToResponse(traces []*model.Trace, adjust bool, uiErr
}
}
-func (aH *APIHandler) tracesByIDs(ctx context.Context, traceIDs []model.TraceID) ([]*model.Trace, []structuredError, error) {
+func (aH *APIHandler) tracesByIDs(
+ ctx context.Context,
+ traceIDs []model.TraceID,
+) ([]*model.Trace, []structuredError, error) {
var traceErrors []structuredError
retMe := make([]*model.Trace, 0, len(traceIDs))
for _, traceID := range traceIDs {
@@ -307,12 +339,19 @@ func (aH *APIHandler) dependencies(w http.ResponseWriter, r *http.Request) {
}
service := r.FormValue(serviceParam)
- dependencies, err := aH.queryService.GetDependencies(r.Context(), dqp.endTs, dqp.lookback)
+ dependencies, err := aH.queryService.GetDependencies(
+ r.Context(),
+ dqp.endTs,
+ dqp.lookback,
+ )
if aH.handleError(w, err, http.StatusInternalServerError) {
return
}
- filteredDependencies := aH.filterDependenciesByService(dependencies, service)
+ filteredDependencies := aH.filterDependenciesByService(
+ dependencies,
+ service,
+ )
structuredRes := structuredResponse{
Data: aH.deduplicateDependencies(filteredDependencies),
}
@@ -322,35 +361,54 @@ func (aH *APIHandler) dependencies(w http.ResponseWriter, r *http.Request) {
func (aH *APIHandler) latencies(w http.ResponseWriter, r *http.Request) {
q, err := strconv.ParseFloat(r.FormValue(quantileParam), 64)
if err != nil {
- aH.handleError(w, newParseError(err, quantileParam), http.StatusBadRequest)
+ aH.handleError(
+ w,
+ newParseError(err, quantileParam),
+ http.StatusBadRequest,
+ )
return
}
- aH.metrics(w, r, func(ctx context.Context, baseParams metricsstore.BaseQueryParameters) (*metrics.MetricFamily, error) {
- return aH.metricsQueryService.GetLatencies(ctx, &metricsstore.LatenciesQueryParameters{
- BaseQueryParameters: baseParams,
- Quantile: q,
- })
- })
+ aH.metrics(
+ w,
+ r,
+ func(ctx context.Context, baseParams metricsstore.BaseQueryParameters) (*metrics.MetricFamily, error) {
+ return aH.metricsQueryService.GetLatencies(ctx, &metricsstore.LatenciesQueryParameters{
+ BaseQueryParameters: baseParams,
+ Quantile: q,
+ })
+ },
+ )
}
func (aH *APIHandler) calls(w http.ResponseWriter, r *http.Request) {
- aH.metrics(w, r, func(ctx context.Context, baseParams metricsstore.BaseQueryParameters) (*metrics.MetricFamily, error) {
- return aH.metricsQueryService.GetCallRates(ctx, &metricsstore.CallRateQueryParameters{
- BaseQueryParameters: baseParams,
- })
- })
+ aH.metrics(
+ w,
+ r,
+ func(ctx context.Context, baseParams metricsstore.BaseQueryParameters) (*metrics.MetricFamily, error) {
+ return aH.metricsQueryService.GetCallRates(ctx, &metricsstore.CallRateQueryParameters{
+ BaseQueryParameters: baseParams,
+ })
+ },
+ )
}
func (aH *APIHandler) errors(w http.ResponseWriter, r *http.Request) {
- aH.metrics(w, r, func(ctx context.Context, baseParams metricsstore.BaseQueryParameters) (*metrics.MetricFamily, error) {
- return aH.metricsQueryService.GetErrorRates(ctx, &metricsstore.ErrorRateQueryParameters{
- BaseQueryParameters: baseParams,
- })
- })
+ aH.metrics(
+ w,
+ r,
+ func(ctx context.Context, baseParams metricsstore.BaseQueryParameters) (*metrics.MetricFamily, error) {
+ return aH.metricsQueryService.GetErrorRates(ctx, &metricsstore.ErrorRateQueryParameters{
+ BaseQueryParameters: baseParams,
+ })
+ },
+ )
}
func (aH *APIHandler) minStep(w http.ResponseWriter, r *http.Request) {
- minStep, err := aH.metricsQueryService.GetMinStepDuration(r.Context(), &metricsstore.MinStepDurationQueryParameters{})
+ minStep, err := aH.metricsQueryService.GetMinStepDuration(
+ r.Context(),
+ &metricsstore.MinStepDurationQueryParameters{},
+ )
if aH.handleError(w, err, http.StatusInternalServerError) {
return
}
@@ -361,7 +419,11 @@ func (aH *APIHandler) minStep(w http.ResponseWriter, r *http.Request) {
aH.writeJSON(w, r, &structuredRes)
}
-func (aH *APIHandler) metrics(w http.ResponseWriter, r *http.Request, getMetrics func(context.Context, metricsstore.BaseQueryParameters) (*metrics.MetricFamily, error)) {
+func (aH *APIHandler) metrics(
+ w http.ResponseWriter,
+ r *http.Request,
+ getMetrics func(context.Context, metricsstore.BaseQueryParameters) (*metrics.MetricFamily, error),
+) {
requestParams, err := aH.queryParser.parseMetricsQueryParams(r)
if aH.handleError(w, err, http.StatusBadRequest) {
return
@@ -373,7 +435,10 @@ func (aH *APIHandler) metrics(w http.ResponseWriter, r *http.Request, getMetrics
aH.writeJSON(w, r, m)
}
-func (aH *APIHandler) convertModelToUI(trace *model.Trace, adjust bool) (*ui.Trace, *structuredError) {
+func (aH *APIHandler) convertModelToUI(
+ trace *model.Trace,
+ adjust bool,
+) (*ui.Trace, *structuredError) {
var errs []error
if adjust {
var err error
@@ -393,7 +458,9 @@ func (aH *APIHandler) convertModelToUI(trace *model.Trace, adjust bool) (*ui.Tra
return uiTrace, uiError
}
-func (*APIHandler) deduplicateDependencies(dependencies []model.DependencyLink) []ui.DependencyLink {
+func (*APIHandler) deduplicateDependencies(
+ dependencies []model.DependencyLink,
+) []ui.DependencyLink {
type Key struct {
parent string
child string
@@ -406,7 +473,10 @@ func (*APIHandler) deduplicateDependencies(dependencies []model.DependencyLink)
result := make([]ui.DependencyLink, 0, len(links))
for k, v := range links {
- result = append(result, ui.DependencyLink{Parent: k.parent, Child: k.child, CallCount: v})
+ result = append(
+ result,
+ ui.DependencyLink{Parent: k.parent, Child: k.child, CallCount: v},
+ )
}
return result
@@ -430,7 +500,10 @@ func (*APIHandler) filterDependenciesByService(
}
// Parses trace ID from URL like /traces/{trace-id}
-func (aH *APIHandler) parseTraceID(w http.ResponseWriter, r *http.Request) (model.TraceID, bool) {
+func (aH *APIHandler) parseTraceID(
+ w http.ResponseWriter,
+ r *http.Request,
+) (model.TraceID, bool) {
vars := mux.Vars(r)
traceIDVar := vars[traceIDParam]
traceID, err := model.TraceIDFromString(traceIDVar)
@@ -458,7 +531,11 @@ func (aH *APIHandler) getTrace(w http.ResponseWriter, r *http.Request) {
}
var uiErrors []structuredError
- structuredRes := aH.tracesToResponse([]*model.Trace{trace}, shouldAdjust(r), uiErrors)
+ structuredRes := aH.tracesToResponse(
+ []*model.Trace{trace},
+ shouldAdjust(r),
+ uiErrors,
+ )
aH.writeJSON(w, r, structuredRes)
}
@@ -493,7 +570,11 @@ func (aH *APIHandler) archiveTrace(w http.ResponseWriter, r *http.Request) {
aH.writeJSON(w, r, &structuredRes)
}
-func (aH *APIHandler) handleError(w http.ResponseWriter, err error, statusCode int) bool {
+func (aH *APIHandler) handleError(
+ w http.ResponseWriter,
+ err error,
+ statusCode int,
+) bool {
if err == nil {
return false
}
@@ -516,7 +597,11 @@ func (aH *APIHandler) handleError(w http.ResponseWriter, err error, statusCode i
return true
}
-func (aH *APIHandler) writeJSON(w http.ResponseWriter, r *http.Request, response any) {
+func (aH *APIHandler) writeJSON(
+ w http.ResponseWriter,
+ r *http.Request,
+ response any,
+) {
prettyPrintValue := r.FormValue(prettyPrintParam)
prettyPrint := prettyPrintValue != "" && prettyPrintValue != "false"
@@ -530,7 +615,11 @@ func (aH *APIHandler) writeJSON(w http.ResponseWriter, r *http.Request, response
w.Header().Set("Content-Type", "application/json")
if err := marshal(w, response); err != nil {
- aH.handleError(w, fmt.Errorf("failed writing HTTP response: %w", err), http.StatusInternalServerError)
+ aH.handleError(
+ w,
+ fmt.Errorf("failed writing HTTP response: %w", err),
+ http.StatusInternalServerError,
+ )
}
}
diff --git a/cmd/query/app/http_handler_test.go b/cmd/query/app/http_handler_test.go
index 00d8dcf87d8..a70309cc497 100644
--- a/cmd/query/app/http_handler_test.go
+++ b/cmd/query/app/http_handler_test.go
@@ -102,7 +102,10 @@ type structuredTraceResponse struct {
Errors []structuredError `json:"errors"`
}
-func initializeTestServerWithHandler(queryOptions querysvc.QueryServiceOptions, options ...HandlerOption) *testServer {
+func initializeTestServerWithHandler(
+ queryOptions querysvc.QueryServiceOptions,
+ options ...HandlerOption,
+) *testServer {
return initializeTestServerWithOptions(
&tenancy.Manager{},
queryOptions,
@@ -112,14 +115,20 @@ func initializeTestServerWithHandler(queryOptions querysvc.QueryServiceOptions,
// add options for test coverage
HandlerOptions.Prefix(defaultAPIPrefix),
HandlerOptions.BasePath("/"),
- HandlerOptions.QueryLookbackDuration(defaultTraceQueryLookbackDuration),
+ HandlerOptions.QueryLookbackDuration(
+ defaultTraceQueryLookbackDuration,
+ ),
},
options...,
)...,
)
}
-func initializeTestServerWithOptions(tenancyMgr *tenancy.Manager, queryOptions querysvc.QueryServiceOptions, options ...HandlerOption) *testServer {
+func initializeTestServerWithOptions(
+ tenancyMgr *tenancy.Manager,
+ queryOptions querysvc.QueryServiceOptions,
+ options ...HandlerOption,
+) *testServer {
readStorage := &spanstoremocks.Reader{}
dependencyStorage := &depsmocks.Reader{}
qs := querysvc.NewQueryService(readStorage, dependencyStorage, queryOptions)
@@ -127,7 +136,9 @@ func initializeTestServerWithOptions(tenancyMgr *tenancy.Manager, queryOptions q
handler := NewAPIHandler(qs, tenancyMgr, options...)
handler.RegisterRoutes(r)
return &testServer{
- server: httptest.NewServer(tenancy.ExtractTenantHTTPHandler(tenancyMgr, r)),
+ server: httptest.NewServer(
+ tenancy.ExtractTenantHTTPHandler(tenancyMgr, r),
+ ),
spanReader: readStorage,
dependencyReader: dependencyStorage,
handler: handler,
@@ -135,7 +146,9 @@ func initializeTestServerWithOptions(tenancyMgr *tenancy.Manager, queryOptions q
}
func initializeTestServer(options ...HandlerOption) *testServer {
- return initializeTestServerWithHandler(querysvc.QueryServiceOptions{}, options...)
+ return initializeTestServerWithHandler(
+ querysvc.QueryServiceOptions{},
+ options...)
}
type testServer struct {
@@ -145,8 +158,15 @@ type testServer struct {
server *httptest.Server
}
-func withTestServer(doTest func(s *testServer), queryOptions querysvc.QueryServiceOptions, options ...HandlerOption) {
- ts := initializeTestServerWithOptions(&tenancy.Manager{}, queryOptions, options...)
+func withTestServer(
+ doTest func(s *testServer),
+ queryOptions querysvc.QueryServiceOptions,
+ options ...HandlerOption,
+) {
+ ts := initializeTestServerWithOptions(
+ &tenancy.Manager{},
+ queryOptions,
+ options...)
defer ts.server.Close()
doTest(ts)
}
@@ -155,7 +175,8 @@ func TestGetTraceSuccess(t *testing.T) {
ts := initializeTestServer()
defer ts.server.Close()
ts.spanReader.On("GetTrace", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("model.TraceID")).
- Return(mockTrace, nil).Once()
+ Return(mockTrace, nil).
+ Once()
var response structuredResponse
err := getJSON(ts.server.URL+`/api/traces/123456`, &response)
@@ -175,7 +196,11 @@ type testLogger struct {
func (testLogger) Enabled(zapcore.Level) bool { return true }
func (l testLogger) With([]zapcore.Field) zapcore.Core { return l }
func (testLogger) Sync() error { return nil }
-func (l testLogger) Check(e zapcore.Entry, ce *zapcore.CheckedEntry) *zapcore.CheckedEntry {
+
+func (l testLogger) Check(
+ e zapcore.Entry,
+ ce *zapcore.CheckedEntry,
+) *zapcore.CheckedEntry {
return ce.AddCore(e, l)
}
@@ -190,15 +215,27 @@ func TestLogOnServerError(t *testing.T) {
}
readStorage := &spanstoremocks.Reader{}
dependencyStorage := &depsmocks.Reader{}
- qs := querysvc.NewQueryService(readStorage, dependencyStorage, querysvc.QueryServiceOptions{})
+ qs := querysvc.NewQueryService(
+ readStorage,
+ dependencyStorage,
+ querysvc.QueryServiceOptions{},
+ )
apiHandlerOptions := []HandlerOption{
HandlerOptions.Logger(zap.New(l)),
}
h := NewAPIHandler(qs, &tenancy.Manager{}, apiHandlerOptions...)
e := errors.New("test error")
- h.handleError(&httptest.ResponseRecorder{}, e, http.StatusInternalServerError)
+ h.handleError(
+ &httptest.ResponseRecorder{},
+ e,
+ http.StatusInternalServerError,
+ )
require.Len(t, *l.logs, 1)
- assert.Equal(t, "HTTP handler, Internal Server Error", (*l.logs)[0].e.Message)
+ assert.Equal(
+ t,
+ "HTTP handler, Internal Server Error",
+ (*l.logs)[0].e.Message,
+ )
assert.Len(t, (*l.logs)[0].f, 1)
assert.Equal(t, e, (*l.logs)[0].f[0].Interface)
}
@@ -285,7 +322,10 @@ func TestGetTrace(t *testing.T) {
numSpanRefs int
}{
{suffix: "", numSpanRefs: 0},
- {suffix: "?raw=true", numSpanRefs: 1}, // bad span reference is not filtered out
+ {
+ suffix: "?raw=true",
+ numSpanRefs: 1,
+ }, // bad span reference is not filtered out
{suffix: "?raw=false", numSpanRefs: 0},
}
@@ -325,15 +365,28 @@ func TestGetTrace(t *testing.T) {
defer ts.server.Close()
ts.spanReader.On("GetTrace", mock.AnythingOfType("*context.valueCtx"), model.NewTraceID(0, 0x123456abc)).
- Return(makeMockTrace(t), nil).Once()
+ Return(makeMockTrace(t), nil).
+ Once()
var response structuredResponse
- err := getJSON(ts.server.URL+`/api/traces/123456aBC`+testCase.suffix, &response) // trace ID in mixed lower/upper case
+ err := getJSON(
+ ts.server.URL+`/api/traces/123456aBC`+testCase.suffix,
+ &response,
+ ) // trace ID in mixed lower/upper case
require.NoError(t, err)
assert.Empty(t, response.Errors)
- assert.Len(t, exporter.GetSpans(), 1, "HTTP request was traced and span reported")
- assert.Equal(t, "/api/traces/{traceID}", exporter.GetSpans()[0].Name)
+ assert.Len(
+ t,
+ exporter.GetSpans(),
+ 1,
+ "HTTP request was traced and span reported",
+ )
+ assert.Equal(
+ t,
+ "/api/traces/{traceID}",
+ exporter.GetSpans()[0].Name,
+ )
traces := extractTraces(t, &response)
assert.Len(t, traces[0].Spans, 2)
@@ -346,7 +399,8 @@ func TestGetTraceDBFailure(t *testing.T) {
ts := initializeTestServer()
defer ts.server.Close()
ts.spanReader.On("GetTrace", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("model.TraceID")).
- Return(nil, errStorage).Once()
+ Return(nil, errStorage).
+ Once()
var response structuredResponse
err := getJSON(ts.server.URL+`/api/traces/123456`, &response)
@@ -357,7 +411,8 @@ func TestGetTraceNotFound(t *testing.T) {
ts := initializeTestServer()
defer ts.server.Close()
ts.spanReader.On("GetTrace", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("model.TraceID")).
- Return(nil, spanstore.ErrTraceNotFound).Once()
+ Return(nil, spanstore.ErrTraceNotFound).
+ Once()
var response structuredResponse
err := getJSON(ts.server.URL+`/api/traces/123456`, &response)
@@ -367,14 +422,17 @@ func TestGetTraceNotFound(t *testing.T) {
func TestGetTraceAdjustmentFailure(t *testing.T) {
ts := initializeTestServerWithHandler(
querysvc.QueryServiceOptions{
- Adjuster: adjuster.Func(func(trace *model.Trace) (*model.Trace, error) {
- return trace, errAdjustment
- }),
+ Adjuster: adjuster.Func(
+ func(trace *model.Trace) (*model.Trace, error) {
+ return trace, errAdjustment
+ },
+ ),
},
)
defer ts.server.Close()
ts.spanReader.On("GetTrace", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("model.TraceID")).
- Return(mockTrace, nil).Once()
+ Return(mockTrace, nil).
+ Once()
var response structuredResponse
err := getJSON(ts.server.URL+`/api/traces/123456`, &response)
@@ -396,10 +454,14 @@ func TestSearchSuccess(t *testing.T) {
ts := initializeTestServer()
defer ts.server.Close()
ts.spanReader.On("FindTraces", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("*spanstore.TraceQueryParameters")).
- Return([]*model.Trace{mockTrace}, nil).Once()
+ Return([]*model.Trace{mockTrace}, nil).
+ Once()
var response structuredResponse
- err := getJSON(ts.server.URL+`/api/traces?service=service&start=0&end=0&operation=operation&limit=200&minDuration=20ms`, &response)
+ err := getJSON(
+ ts.server.URL+`/api/traces?service=service&start=0&end=0&operation=operation&limit=200&minDuration=20ms`,
+ &response,
+ )
require.NoError(t, err)
assert.Empty(t, response.Errors)
}
@@ -408,7 +470,8 @@ func TestSearchByTraceIDSuccess(t *testing.T) {
ts := initializeTestServer()
defer ts.server.Close()
ts.spanReader.On("GetTrace", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("model.TraceID")).
- Return(mockTrace, nil).Twice()
+ Return(mockTrace, nil).
+ Twice()
var response structuredResponse
err := getJSON(ts.server.URL+`/api/traces?traceID=1&traceID=2`, &response)
@@ -419,14 +482,19 @@ func TestSearchByTraceIDSuccess(t *testing.T) {
func TestSearchByTraceIDSuccessWithArchive(t *testing.T) {
archiveReadMock := &spanstoremocks.Reader{}
- ts := initializeTestServerWithOptions(&tenancy.Manager{}, querysvc.QueryServiceOptions{
- ArchiveSpanReader: archiveReadMock,
- })
+ ts := initializeTestServerWithOptions(
+ &tenancy.Manager{},
+ querysvc.QueryServiceOptions{
+ ArchiveSpanReader: archiveReadMock,
+ },
+ )
defer ts.server.Close()
ts.spanReader.On("GetTrace", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("model.TraceID")).
- Return(nil, spanstore.ErrTraceNotFound).Twice()
+ Return(nil, spanstore.ErrTraceNotFound).
+ Twice()
archiveReadMock.On("GetTrace", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("model.TraceID")).
- Return(mockTrace, nil).Twice()
+ Return(mockTrace, nil).
+ Twice()
var response structuredResponse
err := getJSON(ts.server.URL+`/api/traces?traceID=1&traceID=2`, &response)
@@ -439,13 +507,18 @@ func TestSearchByTraceIDNotFound(t *testing.T) {
ts := initializeTestServer()
defer ts.server.Close()
ts.spanReader.On("GetTrace", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("model.TraceID")).
- Return(nil, spanstore.ErrTraceNotFound).Once()
+ Return(nil, spanstore.ErrTraceNotFound).
+ Once()
var response structuredResponse
err := getJSON(ts.server.URL+`/api/traces?traceID=1`, &response)
require.NoError(t, err)
assert.Len(t, response.Errors, 1)
- assert.Equal(t, structuredError{Msg: "trace not found", TraceID: ui.TraceID("0000000000000001")}, response.Errors[0])
+ assert.Equal(
+ t,
+ structuredError{Msg: "trace not found", TraceID: ui.TraceID("0000000000000001")},
+ response.Errors[0],
+ )
}
func TestSearchByTraceIDFailure(t *testing.T) {
@@ -453,7 +526,8 @@ func TestSearchByTraceIDFailure(t *testing.T) {
defer ts.server.Close()
whatsamattayou := "https://youtu.be/WrKFOCg13QQ"
ts.spanReader.On("GetTrace", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("model.TraceID")).
- Return(nil, fmt.Errorf(whatsamattayou)).Once()
+ Return(nil, fmt.Errorf(whatsamattayou)).
+ Once()
var response structuredResponse
err := getJSON(ts.server.URL+`/api/traces?traceID=1`, &response)
@@ -464,16 +538,22 @@ func TestSearchModelConversionFailure(t *testing.T) {
ts := initializeTestServerWithOptions(
&tenancy.Manager{},
querysvc.QueryServiceOptions{
- Adjuster: adjuster.Func(func(trace *model.Trace) (*model.Trace, error) {
- return trace, errAdjustment
- }),
+ Adjuster: adjuster.Func(
+ func(trace *model.Trace) (*model.Trace, error) {
+ return trace, errAdjustment
+ },
+ ),
},
)
defer ts.server.Close()
ts.spanReader.On("FindTraces", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("*spanstore.TraceQueryParameters")).
- Return([]*model.Trace{mockTrace}, nil).Once()
+ Return([]*model.Trace{mockTrace}, nil).
+ Once()
var response structuredResponse
- err := getJSON(ts.server.URL+`/api/traces?service=service&start=0&end=0&operation=operation&limit=200&minDuration=20ms`, &response)
+ err := getJSON(
+ ts.server.URL+`/api/traces?service=service&start=0&end=0&operation=operation&limit=200&minDuration=20ms`,
+ &response,
+ )
require.NoError(t, err)
assert.Len(t, response.Errors, 1)
assert.EqualValues(t, errAdjustment.Error(), response.Errors[0].Msg)
@@ -483,10 +563,14 @@ func TestSearchDBFailure(t *testing.T) {
ts := initializeTestServer()
defer ts.server.Close()
ts.spanReader.On("FindTraces", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("*spanstore.TraceQueryParameters")).
- Return(nil, fmt.Errorf("whatsamattayou")).Once()
+ Return(nil, fmt.Errorf("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)
+ err := getJSON(
+ ts.server.URL+`/api/traces?service=service&start=0&end=0&operation=operation&limit=200&minDuration=20ms`,
+ &response,
+ )
require.EqualError(t, err, parsedError(500, "whatsamattayou"))
}
@@ -501,7 +585,10 @@ func TestSearchFailures(t *testing.T) {
},
{
`/api/traces?service=service&start=0&end=0&operation=operation&maxDuration=10ms&limit=200&minDuration=20ms`,
- parsedError(400, "'maxDuration' should be greater than 'minDuration'"),
+ parsedError(
+ 400,
+ "'maxDuration' should be greater than 'minDuration'",
+ ),
},
}
for _, test := range tests {
@@ -513,7 +600,8 @@ func testIndividualSearchFailures(t *testing.T, urlStr, errMsg string) {
ts := initializeTestServer()
defer ts.server.Close()
ts.spanReader.On("Query", mock.AnythingOfType("spanstore.TraceQueryParameters")).
- Return([]*model.Trace{}, nil).Once()
+ Return([]*model.Trace{}, nil).
+ Once()
var response structuredResponse
err := getJSON(ts.server.URL+urlStr, &response)
@@ -524,7 +612,9 @@ func TestGetServicesSuccess(t *testing.T) {
ts := initializeTestServer()
defer ts.server.Close()
expectedServices := []string{"trifle", "bling"}
- ts.spanReader.On("GetServices", mock.AnythingOfType("*context.valueCtx")).Return(expectedServices, nil).Once()
+ ts.spanReader.On("GetServices", mock.AnythingOfType("*context.valueCtx")).
+ Return(expectedServices, nil).
+ Once()
var response structuredResponse
err := getJSON(ts.server.URL+"/api/services", &response)
@@ -539,7 +629,9 @@ func TestGetServicesSuccess(t *testing.T) {
func TestGetServicesStorageFailure(t *testing.T) {
ts := initializeTestServer()
defer ts.server.Close()
- ts.spanReader.On("GetServices", mock.AnythingOfType("*context.valueCtx")).Return(nil, errStorage).Once()
+ ts.spanReader.On("GetServices", mock.AnythingOfType("*context.valueCtx")).
+ Return(nil, errStorage).
+ Once()
var response structuredResponse
err := getJSON(ts.server.URL+"/api/services", &response)
@@ -549,7 +641,10 @@ func TestGetServicesStorageFailure(t *testing.T) {
func TestGetOperationsSuccess(t *testing.T) {
ts := initializeTestServer()
defer ts.server.Close()
- expectedOperations := []spanstore.Operation{{Name: ""}, {Name: "get", SpanKind: "server"}}
+ expectedOperations := []spanstore.Operation{
+ {Name: ""},
+ {Name: "get", SpanKind: "server"},
+ }
ts.spanReader.On(
"GetOperations",
mock.AnythingOfType("*context.valueCtx"),
@@ -567,7 +662,10 @@ func TestGetOperationsSuccess(t *testing.T) {
Errors []structuredError `json:"errors"`
}
- err := getJSON(ts.server.URL+"/api/operations?service=abc%2Ftrifle&spanKind=server", &response)
+ err := getJSON(
+ ts.server.URL+"/api/operations?service=abc%2Ftrifle&spanKind=server",
+ &response,
+ )
require.NoError(t, err)
assert.Equal(t, len(expectedOperations), len(response.Operations))
for i, op := range response.Operations {
@@ -591,7 +689,10 @@ func TestGetOperationsStorageFailure(t *testing.T) {
ts.spanReader.On(
"GetOperations",
mock.AnythingOfType("*context.valueCtx"),
- mock.AnythingOfType("spanstore.OperationQueryParameters")).Return(nil, errStorage).Once()
+ mock.AnythingOfType(
+ "spanstore.OperationQueryParameters",
+ ),
+ ).Return(nil, errStorage).Once()
var response structuredResponse
err := getJSON(ts.server.URL+"/api/operations?service=trifle", &response)
@@ -611,10 +712,16 @@ func TestGetOperationsLegacySuccess(t *testing.T) {
ts.spanReader.On(
"GetOperations",
mock.AnythingOfType("*context.valueCtx"),
- mock.AnythingOfType("spanstore.OperationQueryParameters")).Return(expectedOperations, nil).Once()
+ mock.AnythingOfType(
+ "spanstore.OperationQueryParameters",
+ ),
+ ).Return(expectedOperations, nil).Once()
var response structuredResponse
- err := getJSON(ts.server.URL+"/api/services/abc%2Ftrifle/operations", &response)
+ err := getJSON(
+ ts.server.URL+"/api/services/abc%2Ftrifle/operations",
+ &response,
+ )
require.NoError(t, err)
assert.ElementsMatch(t, expectedOperationNames, response.Data.([]any))
@@ -626,7 +733,10 @@ func TestGetOperationsLegacyStorageFailure(t *testing.T) {
ts.spanReader.On(
"GetOperations",
mock.AnythingOfType("*context.valueCtx"),
- mock.AnythingOfType("spanstore.OperationQueryParameters")).Return(nil, errStorage).Once()
+ mock.AnythingOfType(
+ "spanstore.OperationQueryParameters",
+ ),
+ ).Return(nil, errStorage).Once()
var response structuredResponse
err := getJSON(ts.server.URL+"/api/services/trifle/operations", &response)
require.Error(t, err)
@@ -645,7 +755,8 @@ func TestTransformOTLPSuccess(t *testing.T) {
inFile, err := os.Open("./fixture/otlp2jaeger-in.json")
require.NoError(t, err)
- resp, err := ts.server.Client().Post(ts.server.URL+"/api/transform", "application/json", inFile)
+ resp, err := ts.server.Client().
+ Post(ts.server.URL+"/api/transform", "application/json", inFile)
require.NoError(t, err)
responseBytes, err := io.ReadAll(resp.Body)
@@ -663,8 +774,10 @@ func TestTransformOTLPSuccess(t *testing.T) {
func TestTransformOTLPReadError(t *testing.T) {
withTestServer(func(ts *testServer) {
bytesReader := &IoReaderMock{}
- bytesReader.On("Read", mock.AnythingOfType("[]uint8")).Return(0, errors.New("Mocked error"))
- _, err := ts.server.Client().Post(ts.server.URL+"/api/transform", "application/json", bytesReader)
+ bytesReader.On("Read", mock.AnythingOfType("[]uint8")).
+ Return(0, errors.New("Mocked error"))
+ _, err := ts.server.Client().
+ Post(ts.server.URL+"/api/transform", "application/json", bytesReader)
require.Error(t, err)
}, querysvc.QueryServiceOptions{})
}
@@ -880,7 +993,11 @@ func getJSON(url string, out any) error {
return getJSONCustomHeaders(url, make(map[string]string), out)
}
-func getJSONCustomHeaders(url string, additionalHeaders map[string]string, out any) error {
+func getJSONCustomHeaders(
+ url string,
+ additionalHeaders map[string]string,
+ out any,
+) error {
req, err := http.NewRequest(http.MethodGet, url, nil)
if err != nil {
return err
@@ -903,7 +1020,11 @@ func postJSON(url string, req any, out any) error {
}
// execJSON executes an http request against a server and parses response as JSON
-func execJSON(req *http.Request, additionalHeaders map[string]string, out any) error {
+func execJSON(
+ req *http.Request,
+ additionalHeaders map[string]string,
+ out any,
+) error {
req.Header.Add("Accept", "application/json")
for k, v := range additionalHeaders {
req.Header.Add(k, v)
@@ -939,7 +1060,12 @@ func execJSON(req *http.Request, additionalHeaders map[string]string, out any) e
// Generates a JSON response that the server should produce given a certain error code and error.
func parsedError(code int, err string) string {
- return fmt.Sprintf(`%d error from server: {"data":null,"total":0,"limit":0,"offset":0,"errors":[{"code":%d,"msg":"%s"}]}`+"\n", code, code, err)
+ return fmt.Sprintf(
+ `%d error from server: {"data":null,"total":0,"limit":0,"offset":0,"errors":[{"code":%d,"msg":"%s"}]}`+"\n",
+ code,
+ code,
+ err,
+ )
}
func TestSearchTenancyHTTP(t *testing.T) {
@@ -951,7 +1077,8 @@ func TestSearchTenancyHTTP(t *testing.T) {
querysvc.QueryServiceOptions{})
defer ts.server.Close()
ts.spanReader.On("GetTrace", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("model.TraceID")).
- Return(mockTrace, nil).Twice()
+ Return(mockTrace, nil).
+ Twice()
var response structuredResponse
err := getJSON(ts.server.URL+`/api/traces?traceID=1&traceID=2`, &response)
@@ -978,9 +1105,14 @@ func TestSearchTenancyRejectionHTTP(t *testing.T) {
querysvc.QueryServiceOptions{})
defer ts.server.Close()
ts.spanReader.On("GetTrace", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("model.TraceID")).
- Return(mockTrace, nil).Twice()
+ Return(mockTrace, nil).
+ Twice()
- req, err := http.NewRequest(http.MethodGet, ts.server.URL+`/api/traces?traceID=1&traceID=2`, nil)
+ req, err := http.NewRequest(
+ http.MethodGet,
+ ts.server.URL+`/api/traces?traceID=1&traceID=2`,
+ nil,
+ )
require.NoError(t, err)
req.Header.Add("Accept", "application/json")
// We don't set tenant header
diff --git a/cmd/query/app/internal/api_v3/traces.go b/cmd/query/app/internal/api_v3/traces.go
index 7090f099689..cb669fda924 100644
--- a/cmd/query/app/internal/api_v3/traces.go
+++ b/cmd/query/app/internal/api_v3/traces.go
@@ -44,7 +44,10 @@ func (td *TracesData) MarshalJSONPB(*jsonpb.Marshaler) ([]byte, error) {
}
// UnmarshalJSONPB implements gogocodec.CustomType.
-func (td *TracesData) UnmarshalJSONPB(_ *jsonpb.Unmarshaler, data []byte) error {
+func (td *TracesData) UnmarshalJSONPB(
+ _ *jsonpb.Unmarshaler,
+ data []byte,
+) error {
t, err := new(ptrace.JSONUnmarshaler).UnmarshalTraces(data)
if err != nil {
return err
diff --git a/cmd/query/app/json_marshaler.go b/cmd/query/app/json_marshaler.go
index 4a75de6c4d6..f8030132a93 100644
--- a/cmd/query/app/json_marshaler.go
+++ b/cmd/query/app/json_marshaler.go
@@ -48,7 +48,10 @@ func newStructJSONMarshaler(prettyPrint bool) jsonMarshaler {
return func(w io.Writer, response any) error {
resp, err := marshaler(response)
if err != nil {
- return fmt.Errorf("failed marshalling HTTP response to JSON: %w", err)
+ return fmt.Errorf(
+ "failed marshalling HTTP response to JSON: %w",
+ err,
+ )
}
_, err = w.Write(resp)
return err
diff --git a/cmd/query/app/query_parser.go b/cmd/query/app/query_parser.go
index 4e781977085..c44337f4496 100644
--- a/cmd/query/app/query_parser.go
+++ b/cmd/query/app/query_parser.go
@@ -47,10 +47,17 @@ const (
)
var (
- errMaxDurationGreaterThanMin = fmt.Errorf("'%s' should be greater than '%s'", maxDurationParam, minDurationParam)
+ errMaxDurationGreaterThanMin = fmt.Errorf(
+ "'%s' should be greater than '%s'",
+ maxDurationParam,
+ minDurationParam,
+ )
// errServiceParameterRequired occurs when no service name is defined.
- errServiceParameterRequired = fmt.Errorf("parameter '%s' is required", serviceParam)
+ errServiceParameterRequired = fmt.Errorf(
+ "parameter '%s' is required",
+ serviceParam,
+ )
jaegerToOtelSpanKind = map[string]string{
"unspecified": metrics.SpanKind_SPAN_KIND_UNSPECIFIED.String(),
@@ -124,7 +131,9 @@ func newDurationUnitsParser(units time.Duration) durationParser {
// key := strValue
// keyValue := strValue ':' strValue
// tags :== 'tags=' jsonMap
-func (p *queryParser) parseTraceQueryParams(r *http.Request) (*traceQueryParameters, error) {
+func (p *queryParser) parseTraceQueryParams(
+ r *http.Request,
+) (*traceQueryParameters, error) {
service := r.FormValue(serviceParam)
operation := r.FormValue(operationParam)
@@ -197,13 +206,20 @@ func (p *queryParser) parseTraceQueryParams(r *http.Request) (*traceQueryParamet
// The dependencies API does not operate on the latency space, instead its timestamps are just time range selections,
// and the typical backend granularity of those is on the order of 15min or more. As such, microseconds aren't
// useful in this domain and milliseconds are sufficient for both times and durations.
-func (p *queryParser) parseDependenciesQueryParams(r *http.Request) (dqp dependenciesQueryParameters, err error) {
+func (p *queryParser) parseDependenciesQueryParams(
+ r *http.Request,
+) (dqp dependenciesQueryParameters, err error) {
dqp.endTs, err = p.parseTime(r, endTsParam, time.Millisecond)
if err != nil {
return dqp, err
}
- dqp.lookback, err = parseDuration(r, lookbackParam, newDurationUnitsParser(time.Millisecond), defaultDependencyLookbackDuration)
+ dqp.lookback, err = parseDuration(
+ r,
+ lookbackParam,
+ newDurationUnitsParser(time.Millisecond),
+ defaultDependencyLookbackDuration,
+ )
return dqp, err
}
@@ -243,11 +259,16 @@ func (p *queryParser) parseDependenciesQueryParams(r *http.Request) (dqp depende
// spanKinds ::= spanKind | spanKind '&' spanKinds
// spanKind ::= 'spanKind=' spanKindType
// spanKindType ::= "unspecified" | "internal" | "server" | "client" | "producer" | "consumer"
-func (p *queryParser) parseMetricsQueryParams(r *http.Request) (bqp metricsstore.BaseQueryParameters, err error) {
+func (p *queryParser) parseMetricsQueryParams(
+ r *http.Request,
+) (bqp metricsstore.BaseQueryParameters, err error) {
query := r.URL.Query()
services, ok := query[serviceParam]
if !ok {
- return bqp, newParseError(errors.New("please provide at least one service name"), serviceParam)
+ return bqp, newParseError(
+ errors.New("please provide at least one service name"),
+ serviceParam,
+ )
}
bqp.ServiceNames = services
@@ -255,7 +276,11 @@ func (p *queryParser) parseMetricsQueryParams(r *http.Request) (bqp metricsstore
if err != nil {
return bqp, err
}
- bqp.SpanKinds, err = parseSpanKinds(r, spanKindParam, defaultMetricsSpanKinds)
+ bqp.SpanKinds, err = parseSpanKinds(
+ r,
+ spanKindParam,
+ defaultMetricsSpanKinds,
+ )
if err != nil {
return bqp, err
}
@@ -264,15 +289,30 @@ func (p *queryParser) parseMetricsQueryParams(r *http.Request) (bqp metricsstore
return bqp, err
}
parser := newDurationUnitsParser(time.Millisecond)
- lookback, err := parseDuration(r, lookbackParam, parser, defaultMetricsQueryLookbackDuration)
+ lookback, err := parseDuration(
+ r,
+ lookbackParam,
+ parser,
+ defaultMetricsQueryLookbackDuration,
+ )
if err != nil {
return bqp, err
}
- step, err := parseDuration(r, stepParam, parser, defaultMetricsQueryStepDuration)
+ step, err := parseDuration(
+ r,
+ stepParam,
+ parser,
+ defaultMetricsQueryStepDuration,
+ )
if err != nil {
return bqp, err
}
- ratePer, err := parseDuration(r, rateParam, parser, defaultMetricsQueryRateDuration)
+ ratePer, err := parseDuration(
+ r,
+ rateParam,
+ parser,
+ defaultMetricsQueryRateDuration,
+ )
if err != nil {
return bqp, err
}
@@ -285,7 +325,11 @@ func (p *queryParser) parseMetricsQueryParams(r *http.Request) (bqp metricsstore
// parseTime parses the time parameter of an HTTP request that is represented the number of "units" since epoch.
// If the time parameter is empty, the current time will be returned.
-func (p *queryParser) parseTime(r *http.Request, paramName string, units time.Duration) (time.Time, error) {
+func (p *queryParser) parseTime(
+ r *http.Request,
+ paramName string,
+ units time.Duration,
+) (time.Time, error) {
formValue := r.FormValue(paramName)
if formValue == "" {
if paramName == startTimeParam {
@@ -302,7 +346,12 @@ func (p *queryParser) parseTime(r *http.Request, paramName string, units time.Du
// parseDuration parses the duration parameter of an HTTP request using the provided durationParser.
// If the duration parameter is empty, the given defaultDuration will be returned.
-func parseDuration(r *http.Request, paramName string, parse durationParser, defaultDuration time.Duration) (time.Duration, error) {
+func parseDuration(
+ r *http.Request,
+ paramName string,
+ parse durationParser,
+ defaultDuration time.Duration,
+) (time.Duration, error) {
formValue := r.FormValue(paramName)
if formValue == "" {
return defaultDuration, nil
@@ -344,7 +393,11 @@ func parseBool(r *http.Request, paramName string) (b bool, err error) {
// - "SPAN_KIND_CLIENT"
// - "SPAN_KIND_PRODUCER"
// - "SPAN_KIND_CONSUMER"
-func parseSpanKinds(r *http.Request, paramName string, defaultSpanKinds []string) ([]string, error) {
+func parseSpanKinds(
+ r *http.Request,
+ paramName string,
+ defaultSpanKinds []string,
+) ([]string, error) {
query := r.URL.Query()
jaegerSpanKinds, ok := query[paramName]
if !ok {
@@ -362,7 +415,10 @@ func mapSpanKindsToOpenTelemetry(spanKinds []string) ([]string, error) {
for i, spanKind := range spanKinds {
v, ok := jaegerToOtelSpanKind[spanKind]
if !ok {
- return otelSpanKinds, fmt.Errorf("unsupported span kind: '%s'", spanKind)
+ return otelSpanKinds, fmt.Errorf(
+ "unsupported span kind: '%s'",
+ spanKind,
+ )
}
otelSpanKinds[i] = v
}
@@ -381,19 +437,28 @@ func (*queryParser) validateQuery(traceQuery *traceQueryParameters) error {
return nil
}
-func (*queryParser) parseTags(simpleTags []string, jsonTags []string) (map[string]string, error) {
+func (*queryParser) parseTags(
+ simpleTags []string,
+ jsonTags []string,
+) (map[string]string, error) {
retMe := make(map[string]string)
for _, tag := range simpleTags {
keyAndValue := strings.Split(tag, ":")
if l := len(keyAndValue); l <= 1 {
- return nil, fmt.Errorf("malformed 'tag' parameter, expecting key:value, received: %s", tag)
+ return nil, fmt.Errorf(
+ "malformed 'tag' parameter, expecting key:value, received: %s",
+ tag,
+ )
}
retMe[keyAndValue[0]] = strings.Join(keyAndValue[1:], ":")
}
for _, tags := range jsonTags {
var fromJSON map[string]string
if err := json.Unmarshal([]byte(tags), &fromJSON); err != nil {
- return nil, fmt.Errorf("malformed 'tags' parameter, cannot unmarshal JSON: %w", err)
+ return nil, fmt.Errorf(
+ "malformed 'tags' parameter, cannot unmarshal JSON: %w",
+ err,
+ )
}
for k, v := range fromJSON {
retMe[k] = v
diff --git a/cmd/query/app/query_parser_test.go b/cmd/query/app/query_parser_test.go
index e75d448a144..a1b00bb7e2b 100644
--- a/cmd/query/app/query_parser_test.go
+++ b/cmd/query/app/query_parser_test.go
@@ -45,10 +45,26 @@ func TestParseTraceQuery(t *testing.T) {
{"x?service=service&start=string", errParseInt, nil},
{"x?service=service&end=string", errParseInt, nil},
{"x?service=service&limit=string", errParseInt, nil},
- {"x?service=service&start=0&end=0&operation=operation&limit=200&minDuration=20", `unable to parse param 'minDuration': time: missing unit in duration "?20"?$`, nil},
- {"x?service=service&start=0&end=0&operation=operation&limit=200&minDuration=20s&maxDuration=30", `unable to parse param 'maxDuration': time: missing unit in duration "?30"?$`, nil},
- {"x?service=service&start=0&end=0&operation=operation&limit=200&tag=k:v&tag=x:y&tag=k&log=k:v&log=k", `malformed 'tag' parameter, expecting key:value, received: k`, nil},
- {"x?service=service&start=0&end=0&operation=operation&limit=200&minDuration=25s&maxDuration=1s", `'maxDuration' should be greater than 'minDuration'`, nil},
+ {
+ "x?service=service&start=0&end=0&operation=operation&limit=200&minDuration=20",
+ `unable to parse param 'minDuration': time: missing unit in duration "?20"?$`,
+ nil,
+ },
+ {
+ "x?service=service&start=0&end=0&operation=operation&limit=200&minDuration=20s&maxDuration=30",
+ `unable to parse param 'maxDuration': time: missing unit in duration "?30"?$`,
+ nil,
+ },
+ {
+ "x?service=service&start=0&end=0&operation=operation&limit=200&tag=k:v&tag=x:y&tag=k&log=k:v&log=k",
+ `malformed 'tag' parameter, expecting key:value, received: k`,
+ nil,
+ },
+ {
+ "x?service=service&start=0&end=0&operation=operation&limit=200&minDuration=25s&maxDuration=1s",
+ `'maxDuration' should be greater than 'minDuration'`,
+ nil,
+ },
{
"x?service=service&start=0&end=0&operation=operation&limit=200&tag=k:v&tag=x:y", noErr,
&traceQueryParameters{
@@ -63,7 +79,11 @@ func TestParseTraceQuery(t *testing.T) {
},
},
// tags=JSON with a non-string value 123
- {`x?service=service&start=0&end=0&operation=operation&limit=200&tag=k:v&tags={"x":123}`, "malformed 'tags' parameter, cannot unmarshal JSON: json: cannot unmarshal number into Go value of type string", nil},
+ {
+ `x?service=service&start=0&end=0&operation=operation&limit=200&tag=k:v&tags={"x":123}`,
+ "malformed 'tags' parameter, cannot unmarshal JSON: json: cannot unmarshal number into Go value of type string",
+ nil,
+ },
// tags=JSON
{
`x?service=service&start=0&end=0&operation=operation&limit=200&tag=k:v&tags={"x":"y"}`, noErr,
@@ -199,7 +219,11 @@ func TestParseBool(t *testing.T) {
{"0", false},
} {
t.Run(tc.input, func(t *testing.T) {
- request, err := http.NewRequest(http.MethodGet, "x?service=foo&groupByOperation="+tc.input, nil)
+ request, err := http.NewRequest(
+ http.MethodGet,
+ "x?service=foo&groupByOperation="+tc.input,
+ nil,
+ )
require.NoError(t, err)
timeNow := time.Now()
parser := &queryParser{
@@ -215,7 +239,11 @@ func TestParseBool(t *testing.T) {
}
func TestParseDuration(t *testing.T) {
- request, err := http.NewRequest(http.MethodGet, "x?service=foo&step=1000", nil)
+ request, err := http.NewRequest(
+ http.MethodGet,
+ "x?service=foo&step=1000",
+ nil,
+ )
require.NoError(t, err)
parser := &queryParser{
timeNow: time.Now,
@@ -226,7 +254,11 @@ func TestParseDuration(t *testing.T) {
}
func TestParseRepeatedServices(t *testing.T) {
- request, err := http.NewRequest(http.MethodGet, "x?service=foo&service=bar", nil)
+ request, err := http.NewRequest(
+ http.MethodGet,
+ "x?service=foo&service=bar",
+ nil,
+ )
require.NoError(t, err)
parser := &queryParser{
timeNow: time.Now,
diff --git a/cmd/query/app/querysvc/query_service.go b/cmd/query/app/querysvc/query_service.go
index 2144928acb2..2ff18a7f185 100644
--- a/cmd/query/app/querysvc/query_service.go
+++ b/cmd/query/app/querysvc/query_service.go
@@ -28,7 +28,9 @@ import (
"github.com/jaegertracing/jaeger/storage/spanstore"
)
-var errNoArchiveSpanStorage = errors.New("archive span storage was not configured")
+var errNoArchiveSpanStorage = errors.New(
+ "archive span storage was not configured",
+)
const (
defaultMaxClockSkewAdjust = time.Second
@@ -56,7 +58,11 @@ type QueryService struct {
}
// NewQueryService returns a new QueryService.
-func NewQueryService(spanReader spanstore.Reader, dependencyReader dependencystore.Reader, options QueryServiceOptions) *QueryService {
+func NewQueryService(
+ spanReader spanstore.Reader,
+ dependencyReader dependencystore.Reader,
+ options QueryServiceOptions,
+) *QueryService {
qsvc := &QueryService{
spanReader: spanReader,
dependencyReader: dependencyReader,
@@ -64,13 +70,17 @@ func NewQueryService(spanReader spanstore.Reader, dependencyReader dependencysto
}
if qsvc.options.Adjuster == nil {
- qsvc.options.Adjuster = adjuster.Sequence(StandardAdjusters(defaultMaxClockSkewAdjust)...)
+ qsvc.options.Adjuster = adjuster.Sequence(
+ StandardAdjusters(defaultMaxClockSkewAdjust)...)
}
return qsvc
}
// GetTrace is the queryService implementation of spanstore.Reader.GetTrace
-func (qs QueryService) GetTrace(ctx context.Context, traceID model.TraceID) (*model.Trace, error) {
+func (qs QueryService) GetTrace(
+ ctx context.Context,
+ traceID model.TraceID,
+) (*model.Trace, error) {
trace, err := qs.spanReader.GetTrace(ctx, traceID)
if errors.Is(err, spanstore.ErrTraceNotFound) {
if qs.options.ArchiveSpanReader == nil {
@@ -95,12 +105,18 @@ func (qs QueryService) GetOperations(
}
// FindTraces is the queryService implementation of spanstore.Reader.FindTraces
-func (qs QueryService) FindTraces(ctx context.Context, query *spanstore.TraceQueryParameters) ([]*model.Trace, error) {
+func (qs QueryService) FindTraces(
+ ctx context.Context,
+ query *spanstore.TraceQueryParameters,
+) ([]*model.Trace, error) {
return qs.spanReader.FindTraces(ctx, query)
}
// ArchiveTrace is the queryService utility to archive traces.
-func (qs QueryService) ArchiveTrace(ctx context.Context, traceID model.TraceID) error {
+func (qs QueryService) ArchiveTrace(
+ ctx context.Context,
+ traceID model.TraceID,
+) error {
if qs.options.ArchiveSpanWriter == nil {
return errNoArchiveSpanStorage
}
@@ -125,7 +141,11 @@ func (qs QueryService) Adjust(trace *model.Trace) (*model.Trace, error) {
}
// GetDependencies implements dependencystore.Reader.GetDependencies
-func (qs QueryService) GetDependencies(ctx context.Context, endTs time.Time, lookback time.Duration) ([]model.DependencyLink, error) {
+func (qs QueryService) GetDependencies(
+ ctx context.Context,
+ endTs time.Time,
+ lookback time.Duration,
+) ([]model.DependencyLink, error) {
return qs.dependencyReader.GetDependencies(ctx, endTs, lookback)
}
@@ -137,15 +157,22 @@ func (qs QueryService) GetCapabilities() StorageCapabilities {
}
// InitArchiveStorage tries to initialize archive storage reader/writer if storage factory supports them.
-func (opts *QueryServiceOptions) InitArchiveStorage(storageFactory storage.Factory, logger *zap.Logger) bool {
+func (opts *QueryServiceOptions) InitArchiveStorage(
+ storageFactory storage.Factory,
+ logger *zap.Logger,
+) bool {
archiveFactory, ok := storageFactory.(storage.ArchiveFactory)
if !ok {
logger.Info("Archive storage not supported by the factory")
return false
}
reader, err := archiveFactory.CreateArchiveSpanReader()
- if errors.Is(err, storage.ErrArchiveStorageNotConfigured) || errors.Is(err, storage.ErrArchiveStorageNotSupported) {
- logger.Info("Archive storage not created", zap.String("reason", err.Error()))
+ if errors.Is(err, storage.ErrArchiveStorageNotConfigured) ||
+ errors.Is(err, storage.ErrArchiveStorageNotSupported) {
+ logger.Info(
+ "Archive storage not created",
+ zap.String("reason", err.Error()),
+ )
return false
}
if err != nil {
@@ -153,8 +180,12 @@ func (opts *QueryServiceOptions) InitArchiveStorage(storageFactory storage.Facto
return false
}
writer, err := archiveFactory.CreateArchiveSpanWriter()
- if errors.Is(err, storage.ErrArchiveStorageNotConfigured) || errors.Is(err, storage.ErrArchiveStorageNotSupported) {
- logger.Info("Archive storage not created", zap.String("reason", err.Error()))
+ if errors.Is(err, storage.ErrArchiveStorageNotConfigured) ||
+ errors.Is(err, storage.ErrArchiveStorageNotSupported) {
+ logger.Info(
+ "Archive storage not created",
+ zap.String("reason", err.Error()),
+ )
return false
}
if err != nil {
diff --git a/cmd/query/app/querysvc/query_service_test.go b/cmd/query/app/querysvc/query_service_test.go
index 41231993930..9c4f1ecc74b 100644
--- a/cmd/query/app/querysvc/query_service_test.go
+++ b/cmd/query/app/querysvc/query_service_test.go
@@ -90,9 +90,11 @@ func withArchiveSpanWriter() testOption {
func withAdjuster() testOption {
return func(tqs *testQueryService, options *QueryServiceOptions) {
- options.Adjuster = adjuster.Func(func(trace *model.Trace) (*model.Trace, error) {
- return trace, errAdjustment
- })
+ options.Adjuster = adjuster.Func(
+ func(trace *model.Trace) (*model.Trace, error) {
+ return trace, errAdjustment
+ },
+ )
}
}
@@ -119,11 +121,15 @@ func initializeTestService(optionAppliers ...testOption) *testQueryService {
func TestGetTraceSuccess(t *testing.T) {
tqs := initializeTestService()
tqs.spanReader.On("GetTrace", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("model.TraceID")).
- Return(mockTrace, nil).Once()
+ Return(mockTrace, nil).
+ Once()
type contextKey string
ctx := context.Background()
- res, err := tqs.queryService.GetTrace(context.WithValue(ctx, contextKey("foo"), "bar"), mockTraceID)
+ res, err := tqs.queryService.GetTrace(
+ context.WithValue(ctx, contextKey("foo"), "bar"),
+ mockTraceID,
+ )
require.NoError(t, err)
assert.Equal(t, res, mockTrace)
}
@@ -132,11 +138,15 @@ func TestGetTraceSuccess(t *testing.T) {
func TestGetTraceNotFound(t *testing.T) {
tqs := initializeTestService()
tqs.spanReader.On("GetTrace", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("model.TraceID")).
- Return(nil, spanstore.ErrTraceNotFound).Once()
+ Return(nil, spanstore.ErrTraceNotFound).
+ Once()
type contextKey string
ctx := context.Background()
- _, err := tqs.queryService.GetTrace(context.WithValue(ctx, contextKey("foo"), "bar"), mockTraceID)
+ _, err := tqs.queryService.GetTrace(
+ context.WithValue(ctx, contextKey("foo"), "bar"),
+ mockTraceID,
+ )
assert.Equal(t, err, spanstore.ErrTraceNotFound)
}
@@ -144,13 +154,18 @@ func TestGetTraceNotFound(t *testing.T) {
func TestGetTraceFromArchiveStorage(t *testing.T) {
tqs := initializeTestService(withArchiveSpanReader())
tqs.spanReader.On("GetTrace", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("model.TraceID")).
- Return(nil, spanstore.ErrTraceNotFound).Once()
+ Return(nil, spanstore.ErrTraceNotFound).
+ Once()
tqs.archiveSpanReader.On("GetTrace", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("model.TraceID")).
- Return(mockTrace, nil).Once()
+ Return(mockTrace, nil).
+ Once()
type contextKey string
ctx := context.Background()
- res, err := tqs.queryService.GetTrace(context.WithValue(ctx, contextKey("foo"), "bar"), mockTraceID)
+ res, err := tqs.queryService.GetTrace(
+ context.WithValue(ctx, contextKey("foo"), "bar"),
+ mockTraceID,
+ )
require.NoError(t, err)
assert.Equal(t, res, mockTrace)
}
@@ -159,11 +174,15 @@ func TestGetTraceFromArchiveStorage(t *testing.T) {
func TestGetServices(t *testing.T) {
tqs := initializeTestService()
expectedServices := []string{"trifle", "bling"}
- tqs.spanReader.On("GetServices", mock.AnythingOfType("*context.valueCtx")).Return(expectedServices, nil).Once()
+ tqs.spanReader.On("GetServices", mock.AnythingOfType("*context.valueCtx")).
+ Return(expectedServices, nil).
+ Once()
type contextKey string
ctx := context.Background()
- actualServices, err := tqs.queryService.GetServices(context.WithValue(ctx, contextKey("foo"), "bar"))
+ actualServices, err := tqs.queryService.GetServices(
+ context.WithValue(ctx, contextKey("foo"), "bar"),
+ )
require.NoError(t, err)
assert.Equal(t, expectedServices, actualServices)
}
@@ -171,8 +190,13 @@ func TestGetServices(t *testing.T) {
// Test QueryService.GetOperations() for success.
func TestGetOperations(t *testing.T) {
tqs := initializeTestService()
- expectedOperations := []spanstore.Operation{{Name: "", SpanKind: ""}, {Name: "get", SpanKind: ""}}
- operationQuery := spanstore.OperationQueryParameters{ServiceName: "abc/trifle"}
+ expectedOperations := []spanstore.Operation{
+ {Name: "", SpanKind: ""},
+ {Name: "get", SpanKind: ""},
+ }
+ operationQuery := spanstore.OperationQueryParameters{
+ ServiceName: "abc/trifle",
+ }
tqs.spanReader.On(
"GetOperations",
mock.AnythingOfType("*context.valueCtx"),
@@ -181,7 +205,10 @@ func TestGetOperations(t *testing.T) {
type contextKey string
ctx := context.Background()
- actualOperations, err := tqs.queryService.GetOperations(context.WithValue(ctx, contextKey("foo"), "bar"), operationQuery)
+ actualOperations, err := tqs.queryService.GetOperations(
+ context.WithValue(ctx, contextKey("foo"), "bar"),
+ operationQuery,
+ )
require.NoError(t, err)
assert.Equal(t, expectedOperations, actualOperations)
}
@@ -190,7 +217,8 @@ func TestGetOperations(t *testing.T) {
func TestFindTraces(t *testing.T) {
tqs := initializeTestService()
tqs.spanReader.On("FindTraces", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("*spanstore.TraceQueryParameters")).
- Return([]*model.Trace{mockTrace}, nil).Once()
+ Return([]*model.Trace{mockTrace}, nil).
+ Once()
type contextKey string
ctx := context.Background()
@@ -202,7 +230,10 @@ func TestFindTraces(t *testing.T) {
DurationMin: duration,
NumTraces: 200,
}
- traces, err := tqs.queryService.FindTraces(context.WithValue(ctx, contextKey("foo"), "bar"), params)
+ traces, err := tqs.queryService.FindTraces(
+ context.WithValue(ctx, contextKey("foo"), "bar"),
+ params,
+ )
require.NoError(t, err)
assert.Len(t, traces, 1)
}
@@ -213,21 +244,32 @@ func TestArchiveTraceNoOptions(t *testing.T) {
type contextKey string
ctx := context.Background()
- err := tqs.queryService.ArchiveTrace(context.WithValue(ctx, contextKey("foo"), "bar"), mockTraceID)
+ err := tqs.queryService.ArchiveTrace(
+ context.WithValue(ctx, contextKey("foo"), "bar"),
+ mockTraceID,
+ )
assert.Equal(t, errNoArchiveSpanStorage, err)
}
// Test QueryService.ArchiveTrace() with ArchiveSpanWriter but invalid traceID.
func TestArchiveTraceWithInvalidTraceID(t *testing.T) {
- tqs := initializeTestService(withArchiveSpanReader(), withArchiveSpanWriter())
+ tqs := initializeTestService(
+ withArchiveSpanReader(),
+ withArchiveSpanWriter(),
+ )
tqs.spanReader.On("GetTrace", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("model.TraceID")).
- Return(nil, spanstore.ErrTraceNotFound).Once()
+ Return(nil, spanstore.ErrTraceNotFound).
+ Once()
tqs.archiveSpanReader.On("GetTrace", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("model.TraceID")).
- Return(nil, spanstore.ErrTraceNotFound).Once()
+ Return(nil, spanstore.ErrTraceNotFound).
+ Once()
type contextKey string
ctx := context.Background()
- err := tqs.queryService.ArchiveTrace(context.WithValue(ctx, contextKey("foo"), "bar"), mockTraceID)
+ err := tqs.queryService.ArchiveTrace(
+ context.WithValue(ctx, contextKey("foo"), "bar"),
+ mockTraceID,
+ )
assert.Equal(t, spanstore.ErrTraceNotFound, err)
}
@@ -235,13 +277,18 @@ func TestArchiveTraceWithInvalidTraceID(t *testing.T) {
func TestArchiveTraceWithArchiveWriterError(t *testing.T) {
tqs := initializeTestService(withArchiveSpanWriter())
tqs.spanReader.On("GetTrace", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("model.TraceID")).
- Return(mockTrace, nil).Once()
+ Return(mockTrace, nil).
+ Once()
tqs.archiveSpanWriter.On("WriteSpan", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("*model.Span")).
- Return(errors.New("cannot save")).Times(2)
+ Return(errors.New("cannot save")).
+ Times(2)
type contextKey string
ctx := context.Background()
- joinErr := tqs.queryService.ArchiveTrace(context.WithValue(ctx, contextKey("foo"), "bar"), mockTraceID)
+ joinErr := tqs.queryService.ArchiveTrace(
+ context.WithValue(ctx, contextKey("foo"), "bar"),
+ mockTraceID,
+ )
// There are two spans in the mockTrace, ArchiveTrace should return a wrapped error.
require.EqualError(t, joinErr, "cannot save\ncannot save")
}
@@ -250,13 +297,18 @@ func TestArchiveTraceWithArchiveWriterError(t *testing.T) {
func TestArchiveTraceSuccess(t *testing.T) {
tqs := initializeTestService(withArchiveSpanWriter())
tqs.spanReader.On("GetTrace", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("model.TraceID")).
- Return(mockTrace, nil).Once()
+ Return(mockTrace, nil).
+ Once()
tqs.archiveSpanWriter.On("WriteSpan", mock.AnythingOfType("*context.valueCtx"), mock.AnythingOfType("*model.Span")).
- Return(nil).Times(2)
+ Return(nil).
+ Times(2)
type contextKey string
ctx := context.Background()
- err := tqs.queryService.ArchiveTrace(context.WithValue(ctx, contextKey("foo"), "bar"), mockTraceID)
+ err := tqs.queryService.ArchiveTrace(
+ context.WithValue(ctx, contextKey("foo"), "bar"),
+ mockTraceID,
+ )
require.NoError(t, err)
}
@@ -280,9 +332,15 @@ func TestGetDependencies(t *testing.T) {
},
}
endTs := time.Unix(0, 1476374248550*millisToNanosMultiplier)
- tqs.depsReader.On("GetDependencies", endTs, defaultDependencyLookbackDuration).Return(expectedDependencies, nil).Times(1)
-
- actualDependencies, err := tqs.queryService.GetDependencies(context.Background(), time.Unix(0, 1476374248550*millisToNanosMultiplier), defaultDependencyLookbackDuration)
+ tqs.depsReader.On("GetDependencies", endTs, defaultDependencyLookbackDuration).
+ Return(expectedDependencies, nil).
+ Times(1)
+
+ actualDependencies, err := tqs.queryService.GetDependencies(
+ context.Background(),
+ time.Unix(0, 1476374248550*millisToNanosMultiplier),
+ defaultDependencyLookbackDuration,
+ )
require.NoError(t, err)
assert.Equal(t, expectedDependencies, actualDependencies)
}
@@ -293,16 +351,27 @@ func TestGetCapabilities(t *testing.T) {
expectedStorageCapabilities := StorageCapabilities{
ArchiveStorage: false,
}
- assert.Equal(t, expectedStorageCapabilities, tqs.queryService.GetCapabilities())
+ assert.Equal(
+ t,
+ expectedStorageCapabilities,
+ tqs.queryService.GetCapabilities(),
+ )
}
func TestGetCapabilitiesWithSupportsArchive(t *testing.T) {
- tqs := initializeTestService(withArchiveSpanReader(), withArchiveSpanWriter())
+ tqs := initializeTestService(
+ withArchiveSpanReader(),
+ withArchiveSpanWriter(),
+ )
expectedStorageCapabilities := StorageCapabilities{
ArchiveStorage: true,
}
- assert.Equal(t, expectedStorageCapabilities, tqs.queryService.GetCapabilities())
+ assert.Equal(
+ t,
+ expectedStorageCapabilities,
+ tqs.queryService.GetCapabilities(),
+ )
}
type fakeStorageFactory1 struct{}
@@ -315,14 +384,21 @@ type fakeStorageFactory2 struct {
wErr error
}
-func (*fakeStorageFactory1) Initialize(metricsFactory metrics.Factory, logger *zap.Logger) error {
+func (*fakeStorageFactory1) Initialize(
+ metricsFactory metrics.Factory,
+ logger *zap.Logger,
+) error {
return nil
}
-func (*fakeStorageFactory1) CreateSpanReader() (spanstore.Reader, error) { return nil, nil }
-func (*fakeStorageFactory1) CreateSpanWriter() (spanstore.Writer, error) { return nil, nil }
+
+func (*fakeStorageFactory1) CreateSpanReader() (spanstore.Reader, error) { return nil, nil }
+
+func (*fakeStorageFactory1) CreateSpanWriter() (spanstore.Writer, error) { return nil, nil }
+
func (*fakeStorageFactory1) CreateDependencyReader() (dependencystore.Reader, error) { return nil, nil }
func (f *fakeStorageFactory2) CreateArchiveSpanReader() (spanstore.Reader, error) { return f.r, f.rErr }
+
func (f *fakeStorageFactory2) CreateArchiveSpanWriter() (spanstore.Writer, error) { return f.w, f.wErr }
var (
diff --git a/cmd/query/app/server.go b/cmd/query/app/server.go
index 8e1af7662c3..8dbb584a6de 100644
--- a/cmd/query/app/server.go
+++ b/cmd/query/app/server.go
@@ -67,7 +67,15 @@ type Server struct {
}
// NewServer creates and initializes Server
-func NewServer(logger *zap.Logger, healthCheck *healthcheck.HealthCheck, querySvc *querysvc.QueryService, metricsQuerySvc querysvc.MetricsQueryService, options *QueryOptions, tm *tenancy.Manager, tracer *jtracer.JTracer) (*Server, error) {
+func NewServer(
+ logger *zap.Logger,
+ healthCheck *healthcheck.HealthCheck,
+ querySvc *querysvc.QueryService,
+ metricsQuerySvc querysvc.MetricsQueryService,
+ options *QueryOptions,
+ tm *tenancy.Manager,
+ tracer *jtracer.JTracer,
+) (*Server, error) {
_, httpPort, err := net.SplitHostPort(options.HTTPHostPort)
if err != nil {
return nil, fmt.Errorf("invalid HTTP server host:port: %w", err)
@@ -78,15 +86,31 @@ func NewServer(logger *zap.Logger, healthCheck *healthcheck.HealthCheck, querySv
}
if (options.TLSHTTP.Enabled || options.TLSGRPC.Enabled) && (grpcPort == httpPort) {
- return nil, errors.New("server with TLS enabled can not use same host ports for gRPC and HTTP. Use dedicated HTTP and gRPC host ports instead")
+ return nil, errors.New(
+ "server with TLS enabled can not use same host ports for gRPC and HTTP. Use dedicated HTTP and gRPC host ports instead",
+ )
}
- grpcServer, err := createGRPCServer(querySvc, metricsQuerySvc, options, tm, logger, tracer)
+ grpcServer, err := createGRPCServer(
+ querySvc,
+ metricsQuerySvc,
+ options,
+ tm,
+ logger,
+ tracer,
+ )
if err != nil {
return nil, err
}
- httpServer, err := createHTTPServer(querySvc, metricsQuerySvc, options, tm, tracer, logger)
+ httpServer, err := createHTTPServer(
+ querySvc,
+ metricsQuerySvc,
+ options,
+ tm,
+ tracer,
+ logger,
+ )
if err != nil {
return nil, err
}
@@ -103,7 +127,14 @@ func NewServer(logger *zap.Logger, healthCheck *healthcheck.HealthCheck, querySv
}, nil
}
-func createGRPCServer(querySvc *querysvc.QueryService, metricsQuerySvc querysvc.MetricsQueryService, options *QueryOptions, tm *tenancy.Manager, logger *zap.Logger, tracer *jtracer.JTracer) (*grpc.Server, error) {
+func createGRPCServer(
+ querySvc *querysvc.QueryService,
+ metricsQuerySvc querysvc.MetricsQueryService,
+ options *QueryOptions,
+ tm *tenancy.Manager,
+ logger *zap.Logger,
+ tracer *jtracer.JTracer,
+) (*grpc.Server, error) {
var grpcOpts []grpc.ServerOption
if options.TLSGRPC.Enabled {
@@ -134,10 +165,16 @@ func createGRPCServer(querySvc *querysvc.QueryService, metricsQuerySvc querysvc.
api_v2.RegisterQueryServiceServer(server, handler)
metrics.RegisterMetricsQueryServiceServer(server, handler)
- api_v3.RegisterQueryServiceServer(server, &apiv3.Handler{QueryService: querySvc})
+ api_v3.RegisterQueryServiceServer(
+ server,
+ &apiv3.Handler{QueryService: querySvc},
+ )
healthServer.SetServingStatus("jaeger.api_v2.QueryService", grpc_health_v1.HealthCheckResponse_SERVING)
- healthServer.SetServingStatus("jaeger.api_v2.metrics.MetricsQueryService", grpc_health_v1.HealthCheckResponse_SERVING)
+ healthServer.SetServingStatus(
+ "jaeger.api_v2.metrics.MetricsQueryService",
+ grpc_health_v1.HealthCheckResponse_SERVING,
+ )
healthServer.SetServingStatus("jaeger.api_v3.QueryService", grpc_health_v1.HealthCheckResponse_SERVING)
grpc_health_v1.RegisterHealthServer(server, healthServer)
@@ -200,14 +237,21 @@ func createHTTPServer(
}
if queryOpts.TLSHTTP.Enabled {
- tlsCfg, err := queryOpts.TLSHTTP.Config(logger) // This checks if the certificates are correctly provided
+ tlsCfg, err := queryOpts.TLSHTTP.Config(
+ logger,
+ ) // This checks if the certificates are correctly provided
if err != nil {
return nil, err
}
server.TLSConfig = tlsCfg
}
- server.staticHandlerCloser = RegisterStaticHandler(r, logger, queryOpts, querySvc.GetCapabilities())
+ server.staticHandlerCloser = RegisterStaticHandler(
+ r,
+ logger,
+ queryOpts,
+ querySvc.GetCapabilities(),
+ )
return server, nil
}
@@ -262,8 +306,14 @@ func (s *Server) initListener() (cmux.CMux, error) {
cmuxServer := cmux.New(s.conn)
s.grpcConn = cmuxServer.MatchWithWriters(
- cmux.HTTP2MatchHeaderFieldSendSettings("content-type", "application/grpc"),
- cmux.HTTP2MatchHeaderFieldSendSettings("content-type", "application/grpc+proto"),
+ cmux.HTTP2MatchHeaderFieldSendSettings(
+ "content-type",
+ "application/grpc",
+ ),
+ cmux.HTTP2MatchHeaderFieldSendSettings(
+ "content-type",
+ "application/grpc+proto",
+ ),
)
s.httpConn = cmuxServer.Match(cmux.Any())
@@ -297,17 +347,26 @@ func (s *Server) Start() error {
s.bgFinished.Add(1)
go func() {
- s.logger.Info("Starting HTTP server", zap.Int("port", httpPort), zap.String("addr", s.queryOptions.HTTPHostPort))
+ s.logger.Info(
+ "Starting HTTP server",
+ zap.Int("port", httpPort),
+ zap.String("addr", s.queryOptions.HTTPHostPort),
+ )
var err error
if s.queryOptions.TLSHTTP.Enabled {
err = s.httpServer.ServeTLS(s.httpConn, "", "")
} else {
err = s.httpServer.Serve(s.httpConn)
}
- if err != nil && !errors.Is(err, http.ErrServerClosed) && !errors.Is(err, cmux.ErrListenerClosed) && !errors.Is(err, cmux.ErrServerClosed) {
+ if err != nil && !errors.Is(err, http.ErrServerClosed) && !errors.Is(err, cmux.ErrListenerClosed) &&
+ !errors.Is(err, cmux.ErrServerClosed) {
s.logger.Error("Could not start HTTP server", zap.Error(err))
}
- s.logger.Info("HTTP server stopped", zap.Int("port", httpPort), zap.String("addr", s.queryOptions.HTTPHostPort))
+ s.logger.Info(
+ "HTTP server stopped",
+ zap.Int("port", httpPort),
+ zap.String("addr", s.queryOptions.HTTPHostPort),
+ )
s.healthCheck.Set(healthcheck.Unavailable)
s.bgFinished.Done()
}()
@@ -315,12 +374,20 @@ func (s *Server) Start() error {
// Start GRPC server concurrently
s.bgFinished.Add(1)
go func() {
- s.logger.Info("Starting GRPC server", zap.Int("port", grpcPort), zap.String("addr", s.queryOptions.GRPCHostPort))
+ s.logger.Info(
+ "Starting GRPC server",
+ zap.Int("port", grpcPort),
+ zap.String("addr", s.queryOptions.GRPCHostPort),
+ )
if err := s.grpcServer.Serve(s.grpcConn); err != nil {
s.logger.Error("Could not start GRPC server", zap.Error(err))
}
- s.logger.Info("GRPC server stopped", zap.Int("port", grpcPort), zap.String("addr", s.queryOptions.GRPCHostPort))
+ s.logger.Info(
+ "GRPC server stopped",
+ zap.Int("port", grpcPort),
+ zap.String("addr", s.queryOptions.GRPCHostPort),
+ )
s.healthCheck.Set(healthcheck.Unavailable)
s.bgFinished.Done()
}()
@@ -329,12 +396,23 @@ func (s *Server) Start() error {
if !s.separatePorts {
s.bgFinished.Add(1)
go func() {
- s.logger.Info("Starting CMUX server", zap.Int("port", tcpPort), zap.String("addr", s.queryOptions.HTTPHostPort))
+ s.logger.Info(
+ "Starting CMUX server",
+ zap.Int("port", tcpPort),
+ zap.String("addr", s.queryOptions.HTTPHostPort),
+ )
err := cmuxServer.Serve()
// TODO: find a way to avoid string comparison. Even though cmux has ErrServerClosed, it's not returned here.
- if err != nil && !strings.Contains(err.Error(), "use of closed network connection") {
- s.logger.Error("Could not start multiplexed server", zap.Error(err))
+ if err != nil &&
+ !strings.Contains(
+ err.Error(),
+ "use of closed network connection",
+ ) {
+ s.logger.Error(
+ "Could not start multiplexed server",
+ zap.Error(err),
+ )
}
s.healthCheck.Set(healthcheck.Unavailable)
s.bgFinished.Done()
diff --git a/cmd/query/app/server_test.go b/cmd/query/app/server_test.go
index 83cc081c026..220c805ff7e 100644
--- a/cmd/query/app/server_test.go
+++ b/cmd/query/app/server_test.go
@@ -67,9 +67,20 @@ func TestCreateTLSServerSinglePortError(t *testing.T) {
ClientCAPath: testCertKeyLocation + "/example-CA-cert.pem",
}
- _, err := NewServer(zaptest.NewLogger(t), healthcheck.New(), &querysvc.QueryService{}, nil,
- &QueryOptions{HTTPHostPort: ":8080", GRPCHostPort: ":8080", TLSGRPC: tlsCfg, TLSHTTP: tlsCfg},
- tenancy.NewManager(&tenancy.Options{}), jtracer.NoOp())
+ _, err := NewServer(
+ zaptest.NewLogger(t),
+ healthcheck.New(),
+ &querysvc.QueryService{},
+ nil,
+ &QueryOptions{
+ HTTPHostPort: ":8080",
+ GRPCHostPort: ":8080",
+ TLSGRPC: tlsCfg,
+ TLSHTTP: tlsCfg,
+ },
+ tenancy.NewManager(&tenancy.Options{}),
+ jtracer.NoOp(),
+ )
require.Error(t, err)
}
@@ -81,9 +92,19 @@ func TestCreateTLSGrpcServerError(t *testing.T) {
ClientCAPath: "invalid/path",
}
- _, err := NewServer(zaptest.NewLogger(t), healthcheck.New(), &querysvc.QueryService{}, nil,
- &QueryOptions{HTTPHostPort: ":8080", GRPCHostPort: ":8081", TLSGRPC: tlsCfg},
- tenancy.NewManager(&tenancy.Options{}), jtracer.NoOp())
+ _, err := NewServer(
+ zaptest.NewLogger(t),
+ healthcheck.New(),
+ &querysvc.QueryService{},
+ nil,
+ &QueryOptions{
+ HTTPHostPort: ":8080",
+ GRPCHostPort: ":8081",
+ TLSGRPC: tlsCfg,
+ },
+ tenancy.NewManager(&tenancy.Options{}),
+ jtracer.NoOp(),
+ )
require.Error(t, err)
}
@@ -95,9 +116,19 @@ func TestCreateTLSHttpServerError(t *testing.T) {
ClientCAPath: "invalid/path",
}
- _, err := NewServer(zaptest.NewLogger(t), healthcheck.New(), &querysvc.QueryService{}, nil,
- &QueryOptions{HTTPHostPort: ":8080", GRPCHostPort: ":8081", TLSHTTP: tlsCfg},
- tenancy.NewManager(&tenancy.Options{}), jtracer.NoOp())
+ _, err := NewServer(
+ zaptest.NewLogger(t),
+ healthcheck.New(),
+ &querysvc.QueryService{},
+ nil,
+ &QueryOptions{
+ HTTPHostPort: ":8080",
+ GRPCHostPort: ":8081",
+ TLSHTTP: tlsCfg,
+ },
+ tenancy.NewManager(&tenancy.Options{}),
+ jtracer.NoOp(),
+ )
require.Error(t, err)
}
@@ -295,8 +326,13 @@ func makeQuerySvc() *fakeQueryService {
spanReader := &spanstoremocks.Reader{}
dependencyReader := &depsmocks.Reader{}
expectedServices := []string{"test"}
- spanReader.On("GetServices", mock.AnythingOfType("*context.valueCtx")).Return(expectedServices, nil)
- qs := querysvc.NewQueryService(spanReader, dependencyReader, querysvc.QueryServiceOptions{})
+ spanReader.On("GetServices", mock.AnythingOfType("*context.valueCtx")).
+ Return(expectedServices, nil)
+ qs := querysvc.NewQueryService(
+ spanReader,
+ dependencyReader,
+ querysvc.QueryServiceOptions{},
+ )
return &fakeQueryService{
qs: qs,
spanReader: spanReader,
@@ -344,10 +380,16 @@ func TestServerHTTPTLS(t *testing.T) {
}
serverOptions := &QueryOptions{
- GRPCHostPort: ports.GetAddressFromCLIOptions(ports.QueryGRPC, ""),
- HTTPHostPort: ports.GetAddressFromCLIOptions(ports.QueryHTTP, ""),
- TLSHTTP: test.TLS,
- TLSGRPC: tlsGrpc,
+ GRPCHostPort: ports.GetAddressFromCLIOptions(
+ ports.QueryGRPC,
+ "",
+ ),
+ HTTPHostPort: ports.GetAddressFromCLIOptions(
+ ports.QueryHTTP,
+ "",
+ ),
+ TLSHTTP: test.TLS,
+ TLSGRPC: tlsGrpc,
QueryOptionsBase: QueryOptionsBase{
BearerTokenPropagation: true,
},
@@ -356,9 +398,15 @@ func TestServerHTTPTLS(t *testing.T) {
flagsSvc.Logger = zaptest.NewLogger(t)
querySvc := makeQuerySvc()
- server, err := NewServer(flagsSvc.Logger, flagsSvc.HC(), querySvc.qs,
- nil, serverOptions, tenancy.NewManager(&tenancy.Options{}),
- jtracer.NoOp())
+ server, err := NewServer(
+ flagsSvc.Logger,
+ flagsSvc.HC(),
+ querySvc.qs,
+ nil,
+ serverOptions,
+ tenancy.NewManager(&tenancy.Options{}),
+ jtracer.NoOp(),
+ )
require.NoError(t, err)
require.NoError(t, server.Start())
t.Cleanup(func() {
@@ -376,7 +424,12 @@ func TestServerHTTPTLS(t *testing.T) {
require.NoError(t, err0)
dialer := &net.Dialer{Timeout: 2 * time.Second}
- conn, err1 := tls.DialWithDialer(dialer, "tcp", "localhost:"+fmt.Sprintf("%d", ports.QueryHTTP), clientTLSCfg)
+ conn, err1 := tls.DialWithDialer(
+ dialer,
+ "tcp",
+ "localhost:"+fmt.Sprintf("%d", ports.QueryHTTP),
+ clientTLSCfg,
+ )
clientError = err1
clientClose = nil
if conn != nil {
@@ -406,9 +459,15 @@ func TestServerHTTPTLS(t *testing.T) {
TLSClientConfig: clientTLSCfg,
},
}
- querySvc.spanReader.On("FindTraces", mock.Anything, mock.Anything).Return([]*model.Trace{mockTrace}, nil).Once()
+ querySvc.spanReader.On("FindTraces", mock.Anything, mock.Anything).
+ Return([]*model.Trace{mockTrace}, nil).
+ Once()
queryString := "/api/traces?service=service&start=0&end=0&operation=operation&limit=200&minDuration=20ms"
- req, err := http.NewRequest(http.MethodGet, "https://localhost:"+fmt.Sprintf("%d", ports.QueryHTTP)+queryString, nil)
+ req, err := http.NewRequest(
+ http.MethodGet,
+ "https://localhost:"+fmt.Sprintf("%d", ports.QueryHTTP)+queryString,
+ nil,
+ )
require.NoError(t, err)
req.Header.Add("Accept", "application/json")
@@ -427,7 +486,11 @@ func TestServerHTTPTLS(t *testing.T) {
}
}
-func newGRPCClientWithTLS(t *testing.T, addr string, creds credentials.TransportCredentials) *grpcClient {
+func newGRPCClientWithTLS(
+ t *testing.T,
+ addr string,
+ creds credentials.TransportCredentials,
+) *grpcClient {
var conn *grpc.ClientConn
var err error
@@ -481,10 +544,16 @@ func TestServerGRPCTLS(t *testing.T) {
tlsHttp = enabledTLSCfg
}
serverOptions := &QueryOptions{
- GRPCHostPort: ports.GetAddressFromCLIOptions(ports.QueryGRPC, ""),
- HTTPHostPort: ports.GetAddressFromCLIOptions(ports.QueryHTTP, ""),
- TLSHTTP: tlsHttp,
- TLSGRPC: test.TLS,
+ GRPCHostPort: ports.GetAddressFromCLIOptions(
+ ports.QueryGRPC,
+ "",
+ ),
+ HTTPHostPort: ports.GetAddressFromCLIOptions(
+ ports.QueryHTTP,
+ "",
+ ),
+ TLSHTTP: tlsHttp,
+ TLSGRPC: test.TLS,
QueryOptionsBase: QueryOptionsBase{
BearerTokenPropagation: true,
},
@@ -493,9 +562,15 @@ func TestServerGRPCTLS(t *testing.T) {
flagsSvc.Logger = zaptest.NewLogger(t)
querySvc := makeQuerySvc()
- server, err := NewServer(flagsSvc.Logger, flagsSvc.HC(), querySvc.qs,
- nil, serverOptions, tenancy.NewManager(&tenancy.Options{}),
- jtracer.NoOp())
+ server, err := NewServer(
+ flagsSvc.Logger,
+ flagsSvc.HC(),
+ querySvc.qs,
+ nil,
+ serverOptions,
+ tenancy.NewManager(&tenancy.Options{}),
+ jtracer.NoOp(),
+ )
require.NoError(t, err)
require.NoError(t, server.Start())
t.Cleanup(func() {
@@ -508,7 +583,11 @@ func TestServerGRPCTLS(t *testing.T) {
require.NoError(t, err0)
defer test.clientTLS.Close()
creds := credentials.NewTLS(clientTLSCfg)
- client = newGRPCClientWithTLS(t, ports.PortToHostPort(ports.QueryGRPC), creds)
+ client = newGRPCClientWithTLS(
+ t,
+ ports.PortToHostPort(ports.QueryGRPC),
+ creds,
+ )
} else {
client = newGRPCClientWithTLS(t, ports.PortToHostPort(ports.QueryGRPC), nil)
}
@@ -517,11 +596,17 @@ func TestServerGRPCTLS(t *testing.T) {
})
// using generous timeout since grpc.NewClient no longer does a handshake.
- ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
+ ctx, cancel := context.WithTimeout(
+ context.Background(),
+ 30*time.Second,
+ )
defer cancel()
flagsSvc.Logger.Info("calling client.GetServices()")
- res, clientError := client.GetServices(ctx, &api_v2.GetServicesRequest{})
+ res, clientError := client.GetServices(
+ ctx,
+ &api_v2.GetServicesRequest{},
+ )
flagsSvc.Logger.Info("returned from GetServices()")
if test.expectClientError {
@@ -535,7 +620,11 @@ func TestServerGRPCTLS(t *testing.T) {
}
func TestServerBadHostPort(t *testing.T) {
- _, err := NewServer(zaptest.NewLogger(t), healthcheck.New(), &querysvc.QueryService{}, nil,
+ _, err := NewServer(
+ zaptest.NewLogger(t),
+ healthcheck.New(),
+ &querysvc.QueryService{},
+ nil,
&QueryOptions{
HTTPHostPort: "8080", // bad string, not :port
GRPCHostPort: "127.0.0.1:8081",
@@ -544,10 +633,15 @@ func TestServerBadHostPort(t *testing.T) {
},
},
tenancy.NewManager(&tenancy.Options{}),
- jtracer.NoOp())
+ jtracer.NoOp(),
+ )
require.Error(t, err)
- _, err = NewServer(zaptest.NewLogger(t), healthcheck.New(), &querysvc.QueryService{}, nil,
+ _, err = NewServer(
+ zaptest.NewLogger(t),
+ healthcheck.New(),
+ &querysvc.QueryService{},
+ nil,
&QueryOptions{
HTTPHostPort: "127.0.0.1:8081",
GRPCHostPort: "9123", // bad string, not :port
@@ -556,7 +650,8 @@ func TestServerBadHostPort(t *testing.T) {
},
},
tenancy.NewManager(&tenancy.Options{}),
- jtracer.NoOp())
+ jtracer.NoOp(),
+ )
require.Error(t, err)
}
@@ -638,7 +733,12 @@ func TestServerGracefulExit(t *testing.T) {
flagsSvc := flags.NewService(ports.QueryAdminHTTP)
zapCore, logs := observer.New(zap.ErrorLevel)
- assert.Equal(t, 0, logs.Len(), "Expected initial ObservedLogs to have zero length.")
+ assert.Equal(
+ t,
+ 0,
+ logs.Len(),
+ "Expected initial ObservedLogs to have zero length.",
+ )
flagsSvc.Logger = zap.New(zapCore)
hostPort := ports.PortToHostPort(ports.QueryAdminHTTP)
@@ -686,7 +786,12 @@ func TestServerHandlesPortZero(t *testing.T) {
defer server.Close()
message := logs.FilterMessage("Query server started")
- assert.Equal(t, 1, message.Len(), "Expected 'Query server started' log message.")
+ assert.Equal(
+ t,
+ 1,
+ message.Len(),
+ "Expected 'Query server started' log message.",
+ )
onlyEntry := message.All()[0]
port := onlyEntry.ContextMap()["port"].(int64)
@@ -734,9 +839,18 @@ func TestServerHTTPTenancy(t *testing.T) {
}
tenancyMgr := tenancy.NewManager(&serverOptions.Tenancy)
querySvc := makeQuerySvc()
- querySvc.spanReader.On("FindTraces", mock.Anything, mock.Anything).Return([]*model.Trace{mockTrace}, nil).Once()
- server, err := NewServer(zaptest.NewLogger(t), healthcheck.New(), querySvc.qs,
- nil, serverOptions, tenancyMgr, jtracer.NoOp())
+ querySvc.spanReader.On("FindTraces", mock.Anything, mock.Anything).
+ Return([]*model.Trace{mockTrace}, nil).
+ Once()
+ server, err := NewServer(
+ zaptest.NewLogger(t),
+ healthcheck.New(),
+ querySvc.qs,
+ nil,
+ serverOptions,
+ tenancyMgr,
+ jtracer.NoOp(),
+ )
require.NoError(t, err)
require.NoError(t, server.Start())
t.Cleanup(func() {
@@ -745,11 +859,19 @@ func TestServerHTTPTenancy(t *testing.T) {
for _, test := range testCases {
t.Run(test.name, func(t *testing.T) {
- conn, clientError := net.DialTimeout("tcp", "localhost:8080", 2*time.Second)
+ conn, clientError := net.DialTimeout(
+ "tcp",
+ "localhost:8080",
+ 2*time.Second,
+ )
require.NoError(t, clientError)
queryString := "/api/traces?service=service&start=0&end=0&operation=operation&limit=200&minDuration=20ms"
- req, err := http.NewRequest(http.MethodGet, "http://localhost:8080"+queryString, nil)
+ req, err := http.NewRequest(
+ http.MethodGet,
+ "http://localhost:8080"+queryString,
+ nil,
+ )
if test.tenant != "" {
req.Header.Add(tenancyMgr.Header, test.tenant)
}
diff --git a/cmd/query/app/static_handler.go b/cmd/query/app/static_handler.go
index ee27fe9dbe4..0bc53105d8d 100644
--- a/cmd/query/app/static_handler.go
+++ b/cmd/query/app/static_handler.go
@@ -38,15 +38,28 @@ import (
var (
// The following patterns are searched and replaced in the index.html as a way of customizing the UI.
- configPattern = regexp.MustCompile("JAEGER_CONFIG *= *DEFAULT_CONFIG;")
- configJsPattern = regexp.MustCompile(`(?im)^\s*\/\/\s*JAEGER_CONFIG_JS.*\n.*`)
- versionPattern = regexp.MustCompile("JAEGER_VERSION *= *DEFAULT_VERSION;")
- compabilityPattern = regexp.MustCompile("JAEGER_STORAGE_CAPABILITIES *= *DEFAULT_STORAGE_CAPABILITIES;")
- basePathPattern = regexp.MustCompile(` 0 {
return traces
}
h.logger.Info("Could not retrieve trace from query service")
- h.logger.Info(fmt.Sprintf("Waiting %v for traces", h.getTracesSleepDuration))
+ h.logger.Info(
+ fmt.Sprintf("Waiting %v for traces", h.getTracesSleepDuration),
+ )
time.Sleep(h.getTracesSleepDuration)
}
return nil
}
-func (h *TraceHandler) createTrace(service string, request *traceRequest) error {
+func (h *TraceHandler) createTrace(
+ service string,
+ request *traceRequest,
+) error {
url := h.getClientURL(service) + "/create_traces"
// NB. json.Marshal cannot error no matter what traceRequest we give it
@@ -244,12 +305,19 @@ func (h *TraceHandler) createTrace(service string, request *traceRequest) error
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
- return fmt.Errorf("retrieved %d status code from client service", resp.StatusCode)
+ return fmt.Errorf(
+ "retrieved %d status code from client service",
+ resp.StatusCode,
+ )
}
return nil
}
-func (h *TraceHandler) createTraceRequest(samplerType string, operation string, count int) *traceRequest {
+func (h *TraceHandler) createTraceRequest(
+ samplerType string,
+ operation string,
+ count int,
+) *traceRequest {
return &traceRequest{
Type: samplerType,
Operation: operation,
@@ -260,7 +328,11 @@ func (h *TraceHandler) createTraceRequest(samplerType string, operation string,
func validateTracesWithCount(expected *traceRequest, actual []*ui.Trace) error {
if expected.Count != len(actual) {
- return fmt.Errorf("expected %d trace(s), got %d", expected.Count, len(actual))
+ return fmt.Errorf(
+ "expected %d trace(s), got %d",
+ expected.Count,
+ len(actual),
+ )
}
return validateTraces(expected, actual)
}
@@ -279,7 +351,10 @@ func validateTraces(expected *traceRequest, actual []*ui.Trace) error {
}
// The real trace has more tags than the tags we sent in, make sure our tags were created
-func expectedTagsExist(expected map[string]string, actual map[string]string) bool {
+func expectedTagsExist(
+ expected map[string]string,
+ actual map[string]string,
+) bool {
for k, v := range expected {
value, ok := actual[k]
if !ok || value != v {
diff --git a/crossdock/services/tracehandler_test.go b/crossdock/services/tracehandler_test.go
index 60bae0cba3f..74b157c6fa8 100644
--- a/crossdock/services/tracehandler_test.go
+++ b/crossdock/services/tracehandler_test.go
@@ -38,7 +38,9 @@ import (
var testTrace = ui.Trace{
TraceID: ui.TraceID("0"),
- Spans: []ui.Span{{Tags: []ui.KeyValue{{Key: "k", Value: "v", Type: ui.StringType}}}},
+ Spans: []ui.Span{
+ {Tags: []ui.KeyValue{{Key: "k", Value: "v", Type: ui.StringType}}},
+ },
}
func TestCreateTraceRequest(t *testing.T) {
@@ -53,8 +55,14 @@ func TestCreateTraceRequest(t *testing.T) {
func TestExpectedTagsExist(t *testing.T) {
actual := map[string]string{"key": "value"}
assert.True(t, expectedTagsExist(actual, actual))
- assert.False(t, expectedTagsExist(map[string]string{"key": "value1"}, actual))
- assert.False(t, expectedTagsExist(map[string]string{"key1": "value1"}, actual))
+ assert.False(
+ t,
+ expectedTagsExist(map[string]string{"key": "value1"}, actual),
+ )
+ assert.False(
+ t,
+ expectedTagsExist(map[string]string{"key1": "value1"}, actual),
+ )
}
func TestConvertTagsIntoMap(t *testing.T) {
@@ -103,7 +111,12 @@ func TestRunTest(t *testing.T) {
}
handler := &TraceHandler{}
for _, test := range tests {
- err := handler.runTest("service", &test.request, test.f, validateTracesWithCount)
+ err := handler.runTest(
+ "service",
+ &test.request,
+ test.f,
+ validateTracesWithCount,
+ )
if test.shouldErr {
require.Error(t, err)
} else {
@@ -148,7 +161,11 @@ func TestValidateTracesWithCount(t *testing.T) {
Spans: []ui.Span{
{
Tags: []ui.KeyValue{
- {Key: "key", Type: ui.StringType, Value: "value"},
+ {
+ Key: "key",
+ Type: ui.StringType,
+ Value: "value",
+ },
},
},
},
@@ -157,13 +174,20 @@ func TestValidateTracesWithCount(t *testing.T) {
errMsg: "expected tags not found",
},
{
- expected: traceRequest{Tags: map[string]string{"key": "value"}, Count: 1},
+ expected: traceRequest{
+ Tags: map[string]string{"key": "value"},
+ Count: 1,
+ },
actual: []*ui.Trace{
{
Spans: []ui.Span{
{
Tags: []ui.KeyValue{
- {Key: "key", Type: ui.StringType, Value: "value"},
+ {
+ Key: "key",
+ Type: ui.StringType,
+ Value: "value",
+ },
},
},
},
@@ -244,11 +268,14 @@ func TestTraceHandlerGetTraces(t *testing.T) {
handler := NewTraceHandler(query, nil, zap.NewNop())
handler.getTracesSleepDuration = time.Millisecond
- query.On("GetTraces", "crossdock-go", "op", mock.Anything).Return(nil, errors.New("queryError")).Times(10)
+ query.On("GetTraces", "crossdock-go", "op", mock.Anything).
+ Return(nil, errors.New("queryError")).
+ Times(10)
traces := handler.getTraces("go", "op", nil)
assert.Nil(t, traces)
- query.On("GetTraces", "crossdock-go", "op", mock.Anything).Return([]*ui.Trace{{TraceID: ui.TraceID("0")}}, nil)
+ query.On("GetTraces", "crossdock-go", "op", mock.Anything).
+ Return([]*ui.Trace{{TraceID: ui.TraceID("0")}}, nil)
traces = handler.getTraces("go", "op", nil)
assert.Len(t, traces, 1)
}
@@ -312,7 +339,11 @@ func TestValidateAdaptiveSamplingTraces(t *testing.T) {
Spans: []ui.Span{
{
Tags: []ui.KeyValue{
- {Key: "sampler.param", Type: ui.StringType, Value: "0.0203"},
+ {
+ Key: "sampler.param",
+ Type: ui.StringType,
+ Value: "0.0203",
+ },
},
},
},
@@ -327,8 +358,16 @@ func TestValidateAdaptiveSamplingTraces(t *testing.T) {
Spans: []ui.Span{
{
Tags: []ui.KeyValue{
- {Key: "sampler.param", Type: ui.StringType, Value: "not_float"},
- {Key: "sampler.type", Type: ui.StringType, Value: "probabilistic"},
+ {
+ Key: "sampler.param",
+ Type: ui.StringType,
+ Value: "not_float",
+ },
+ {
+ Key: "sampler.type",
+ Type: ui.StringType,
+ Value: "probabilistic",
+ },
},
},
},
@@ -343,8 +382,16 @@ func TestValidateAdaptiveSamplingTraces(t *testing.T) {
Spans: []ui.Span{
{
Tags: []ui.KeyValue{
- {Key: "sampler.param", Type: ui.StringType, Value: "0.003"},
- {Key: "sampler.type", Type: ui.StringType, Value: "const"},
+ {
+ Key: "sampler.param",
+ Type: ui.StringType,
+ Value: "0.003",
+ },
+ {
+ Key: "sampler.type",
+ Type: ui.StringType,
+ Value: "const",
+ },
},
},
},
@@ -359,8 +406,16 @@ func TestValidateAdaptiveSamplingTraces(t *testing.T) {
Spans: []ui.Span{
{
Tags: []ui.KeyValue{
- {Key: "sampler.param", Type: ui.StringType, Value: "0.001"},
- {Key: "sampler.type", Type: ui.StringType, Value: "probabilistic"},
+ {
+ Key: "sampler.param",
+ Type: ui.StringType,
+ Value: "0.001",
+ },
+ {
+ Key: "sampler.type",
+ Type: ui.StringType,
+ Value: "probabilistic",
+ },
},
},
},
@@ -375,8 +430,16 @@ func TestValidateAdaptiveSamplingTraces(t *testing.T) {
Spans: []ui.Span{
{
Tags: []ui.KeyValue{
- {Key: "sampler.param", Type: ui.StringType, Value: "0.02314"},
- {Key: "sampler.type", Type: ui.StringType, Value: "probabilistic"},
+ {
+ Key: "sampler.param",
+ Type: ui.StringType,
+ Value: "0.02314",
+ },
+ {
+ Key: "sampler.type",
+ Type: ui.StringType,
+ Value: "probabilistic",
+ },
},
},
},
@@ -442,14 +505,20 @@ func TestAdaptiveSamplingTestInternal(t *testing.T) {
getTracesSleepDuration: time.Millisecond,
}
- agent.On("GetSamplingRate", "svc", "op").Return(test.samplingRate, test.getSamplingRateErr)
+ agent.On("GetSamplingRate", "svc", "op").
+ Return(test.samplingRate, test.getSamplingRateErr)
if test.shouldGetTracesErr {
- query.On("GetTraces", "crossdock-svc", "op", mock.Anything).Return(nil, errors.New("queryError")).Times(10)
+ query.On("GetTraces", "crossdock-svc", "op", mock.Anything).
+ Return(nil, errors.New("queryError")).
+ Times(10)
} else {
query.On("GetTraces", "crossdock-svc", "op", mock.Anything).Return([]*ui.Trace{&testTrace}, nil)
}
- _, err := handler.adaptiveSamplingTest("svc", &traceRequest{Operation: "op"})
+ _, err := handler.adaptiveSamplingTest(
+ "svc",
+ &traceRequest{Operation: "op"},
+ )
if test.errMsg != "" {
require.EqualError(t, err, test.errMsg)
} else {
@@ -481,13 +550,16 @@ func TestEndToEndTest(t *testing.T) {
}
// The query service fails to fetch traces
- query.On("GetTraces", "crossdock-go", mock.AnythingOfType("string"), mock.Anything).Return(nil, errors.New("queryError")).Times(10)
+ query.On("GetTraces", "crossdock-go", mock.AnythingOfType("string"), mock.Anything).
+ Return(nil, errors.New("queryError")).
+ Times(10)
handler.EndToEndTest(cT)
cT.AssertNumberOfCalls(t, "Errorf", 2)
// The query service returns a trace
- query.On("GetTraces", "crossdock-go", mock.AnythingOfType("string"), mock.Anything).Return([]*ui.Trace{&testTrace}, nil)
+ query.On("GetTraces", "crossdock-go", mock.AnythingOfType("string"), mock.Anything).
+ Return([]*ui.Trace{&testTrace}, nil)
handler.getTags = func() map[string]string {
return map[string]string{"k": "v"}
}
@@ -523,7 +595,8 @@ func TestAdaptiveSamplingTest(t *testing.T) {
cT.On("Successf", mock.AnythingOfType("string"), mock.Anything)
// Test with Agent only returning defaultProbabilities
- agent.On("GetSamplingRate", "go", mock.AnythingOfType("string")).Return(defaultProbabilities[0], nil)
+ agent.On("GetSamplingRate", "go", mock.AnythingOfType("string")).
+ Return(defaultProbabilities[0], nil)
handler.AdaptiveSamplingTest(cT)
cT.AssertNumberOfCalls(t, "Errorf", 1)
@@ -531,8 +604,16 @@ func TestAdaptiveSamplingTest(t *testing.T) {
Spans: []ui.Span{
{
Tags: []ui.KeyValue{
- {Key: "sampler.param", Type: ui.StringType, Value: "0.02314"},
- {Key: "sampler.type", Type: ui.StringType, Value: "probabilistic"},
+ {
+ Key: "sampler.param",
+ Type: ui.StringType,
+ Value: "0.02314",
+ },
+ {
+ Key: "sampler.type",
+ Type: ui.StringType,
+ Value: "probabilistic",
+ },
{Key: "adaptive", Type: ui.StringType, Value: "sampling"},
},
},
@@ -541,9 +622,11 @@ func TestAdaptiveSamplingTest(t *testing.T) {
agent = &mocks.AgentService{}
handler.agent = agent
- agent.On("GetSamplingRate", "go", mock.AnythingOfType("string")).Return(0.222, nil)
+ agent.On("GetSamplingRate", "go", mock.AnythingOfType("string")).
+ Return(0.222, nil)
// The query service returns an adaptive sampled trace
- query.On("GetTraces", "crossdock-go", mock.AnythingOfType("string"), mock.Anything).Return([]*ui.Trace{&adaptiveSamplingTrace}, nil)
+ query.On("GetTraces", "crossdock-go", mock.AnythingOfType("string"), mock.Anything).
+ Return([]*ui.Trace{&adaptiveSamplingTrace}, nil)
handler.AdaptiveSamplingTest(cT)
cT.AssertNumberOfCalls(t, "Successf", 1)
}
diff --git a/examples/hotrod/cmd/flags.go b/examples/hotrod/cmd/flags.go
index 9b59bd2e948..b9294c4dfb5 100644
--- a/examples/hotrod/cmd/flags.go
+++ b/examples/hotrod/cmd/flags.go
@@ -39,21 +39,31 @@ var (
// used by root command
func addFlags(cmd *cobra.Command) {
- cmd.PersistentFlags().StringVarP(&otelExporter, "otel-exporter", "x", "otlp", "OpenTelemetry exporter (otlp|stdout)")
+ cmd.PersistentFlags().
+ StringVarP(&otelExporter, "otel-exporter", "x", "otlp", "OpenTelemetry exporter (otlp|stdout)")
- cmd.PersistentFlags().DurationVarP(&fixDBConnDelay, "fix-db-query-delay", "D", 300*time.Millisecond, "Average latency of MySQL DB query")
- cmd.PersistentFlags().BoolVarP(&fixDBConnDisableMutex, "fix-disable-db-conn-mutex", "M", false, "Disables the mutex guarding db connection")
- cmd.PersistentFlags().IntVarP(&fixRouteWorkerPoolSize, "fix-route-worker-pool-size", "W", 3, "Default worker pool size")
+ cmd.PersistentFlags().
+ DurationVarP(&fixDBConnDelay, "fix-db-query-delay", "D", 300*time.Millisecond, "Average latency of MySQL DB query")
+ cmd.PersistentFlags().
+ BoolVarP(&fixDBConnDisableMutex, "fix-disable-db-conn-mutex", "M", false, "Disables the mutex guarding db connection")
+ cmd.PersistentFlags().
+ IntVarP(&fixRouteWorkerPoolSize, "fix-route-worker-pool-size", "W", 3, "Default worker pool size")
// Add flags to choose ports for services
- cmd.PersistentFlags().IntVarP(&customerPort, "customer-service-port", "c", 8081, "Port for customer service")
- cmd.PersistentFlags().IntVarP(&driverPort, "driver-service-port", "d", 8082, "Port for driver service")
- cmd.PersistentFlags().IntVarP(&frontendPort, "frontend-service-port", "f", 8080, "Port for frontend service")
- cmd.PersistentFlags().IntVarP(&routePort, "route-service-port", "r", 8083, "Port for routing service")
+ cmd.PersistentFlags().
+ IntVarP(&customerPort, "customer-service-port", "c", 8081, "Port for customer service")
+ cmd.PersistentFlags().
+ IntVarP(&driverPort, "driver-service-port", "d", 8082, "Port for driver service")
+ cmd.PersistentFlags().
+ IntVarP(&frontendPort, "frontend-service-port", "f", 8080, "Port for frontend service")
+ cmd.PersistentFlags().
+ IntVarP(&routePort, "route-service-port", "r", 8083, "Port for routing service")
// Flag for serving frontend at custom basepath url
cmd.PersistentFlags().StringVarP(&basepath, "basepath", "b", "", `Basepath for frontend service(default "/")`)
- cmd.PersistentFlags().StringVarP(&jaegerUI, "jaeger-ui", "j", "http://localhost:16686", "Address of Jaeger UI to create [find trace] links")
+ cmd.PersistentFlags().
+ StringVarP(&jaegerUI, "jaeger-ui", "j", "http://localhost:16686", "Address of Jaeger UI to create [find trace] links")
- cmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Enables debug logging")
+ cmd.PersistentFlags().
+ BoolVarP(&verbose, "verbose", "v", false, "Enables debug logging")
}
diff --git a/examples/hotrod/cmd/frontend.go b/examples/hotrod/cmd/frontend.go
index 4f176426891..691b0f6615f 100644
--- a/examples/hotrod/cmd/frontend.go
+++ b/examples/hotrod/cmd/frontend.go
@@ -33,10 +33,22 @@ var frontendCmd = &cobra.Command{
Short: "Starts Frontend service",
Long: `Starts Frontend service.`,
RunE: func(cmd *cobra.Command, args []string) error {
- options.FrontendHostPort = net.JoinHostPort("0.0.0.0", strconv.Itoa(frontendPort))
- options.DriverHostPort = net.JoinHostPort("0.0.0.0", strconv.Itoa(driverPort))
- options.CustomerHostPort = net.JoinHostPort("0.0.0.0", strconv.Itoa(customerPort))
- options.RouteHostPort = net.JoinHostPort("0.0.0.0", strconv.Itoa(routePort))
+ options.FrontendHostPort = net.JoinHostPort(
+ "0.0.0.0",
+ strconv.Itoa(frontendPort),
+ )
+ options.DriverHostPort = net.JoinHostPort(
+ "0.0.0.0",
+ strconv.Itoa(driverPort),
+ )
+ options.CustomerHostPort = net.JoinHostPort(
+ "0.0.0.0",
+ strconv.Itoa(customerPort),
+ )
+ options.RouteHostPort = net.JoinHostPort(
+ "0.0.0.0",
+ strconv.Itoa(routePort),
+ )
options.Basepath = basepath
options.JaegerUI = jaegerUI
diff --git a/examples/hotrod/cmd/root.go b/examples/hotrod/cmd/root.go
index 7db0b0bda83..0d6f00c6689 100644
--- a/examples/hotrod/cmd/root.go
+++ b/examples/hotrod/cmd/root.go
@@ -63,15 +63,25 @@ func onInitialize() {
zap.AddCallerSkip(1),
}
if !verbose {
- zapOptions = append(zapOptions,
- zap.IncreaseLevel(zap.LevelEnablerFunc(func(l zapcore.Level) bool { return l != zapcore.DebugLevel })),
+ zapOptions = append(
+ zapOptions,
+ zap.IncreaseLevel(
+ zap.LevelEnablerFunc(
+ func(l zapcore.Level) bool { return l != zapcore.DebugLevel },
+ ),
+ ),
)
}
logger, _ = zap.NewDevelopment(zapOptions...)
- metricsFactory = prometheus.New().Namespace(metrics.NSOptions{Name: "hotrod", Tags: nil})
+ metricsFactory = prometheus.New().
+ Namespace(metrics.NSOptions{Name: "hotrod", Tags: nil})
if config.MySQLGetDelay != fixDBConnDelay {
- logger.Info("fix: overriding MySQL query delay", zap.Duration("old", config.MySQLGetDelay), zap.Duration("new", fixDBConnDelay))
+ logger.Info(
+ "fix: overriding MySQL query delay",
+ zap.Duration("old", config.MySQLGetDelay),
+ zap.Duration("new", fixDBConnDelay),
+ )
config.MySQLGetDelay = fixDBConnDelay
}
if fixDBConnDisableMutex {
@@ -79,28 +89,52 @@ func onInitialize() {
config.MySQLMutexDisabled = true
}
if config.RouteWorkerPoolSize != fixRouteWorkerPoolSize {
- logger.Info("fix: overriding route worker pool size", zap.Int("old", config.RouteWorkerPoolSize), zap.Int("new", fixRouteWorkerPoolSize))
+ logger.Info(
+ "fix: overriding route worker pool size",
+ zap.Int("old", config.RouteWorkerPoolSize),
+ zap.Int("new", fixRouteWorkerPoolSize),
+ )
config.RouteWorkerPoolSize = fixRouteWorkerPoolSize
}
if customerPort != 8081 {
- logger.Info("changing customer service port", zap.Int("old", 8081), zap.Int("new", customerPort))
+ logger.Info(
+ "changing customer service port",
+ zap.Int("old", 8081),
+ zap.Int("new", customerPort),
+ )
}
if driverPort != 8082 {
- logger.Info("changing driver service port", zap.Int("old", 8082), zap.Int("new", driverPort))
+ logger.Info(
+ "changing driver service port",
+ zap.Int("old", 8082),
+ zap.Int("new", driverPort),
+ )
}
if frontendPort != 8080 {
- logger.Info("changing frontend service port", zap.Int("old", 8080), zap.Int("new", frontendPort))
+ logger.Info(
+ "changing frontend service port",
+ zap.Int("old", 8080),
+ zap.Int("new", frontendPort),
+ )
}
if routePort != 8083 {
- logger.Info("changing route service port", zap.Int("old", 8083), zap.Int("new", routePort))
+ logger.Info(
+ "changing route service port",
+ zap.Int("old", 8083),
+ zap.Int("new", routePort),
+ )
}
if basepath != "" {
- logger.Info("changing basepath for frontend", zap.String("old", "/"), zap.String("new", basepath))
+ logger.Info(
+ "changing basepath for frontend",
+ zap.String("old", "/"),
+ zap.String("new", basepath),
+ )
}
}
diff --git a/examples/hotrod/pkg/log/spanlogger.go b/examples/hotrod/pkg/log/spanlogger.go
index 98d0f3fce1a..dbb2f204f3a 100644
--- a/examples/hotrod/pkg/log/spanlogger.go
+++ b/examples/hotrod/pkg/log/spanlogger.go
@@ -55,7 +55,11 @@ func (sl spanLogger) Fatal(msg string, fields ...zapcore.Field) {
// With creates a child logger, and optionally adds some context fields to that logger.
func (sl spanLogger) With(fields ...zapcore.Field) Logger {
- return spanLogger{logger: sl.logger.With(fields...), span: sl.span, spanFields: sl.spanFields}
+ return spanLogger{
+ logger: sl.logger.With(fields...),
+ span: sl.span,
+ spanFields: sl.spanFields,
+ }
}
func (sl spanLogger) logToSpan(level, msg string, fields ...zapcore.Field) {
@@ -78,12 +82,18 @@ type bridgeFieldEncoder struct {
pairs []attribute.KeyValue
}
-func (e *bridgeFieldEncoder) AddArray(key string, marshaler zapcore.ArrayMarshaler) error {
+func (e *bridgeFieldEncoder) AddArray(
+ key string,
+ marshaler zapcore.ArrayMarshaler,
+) error {
e.pairs = append(e.pairs, attribute.String(key, fmt.Sprint(marshaler)))
return nil
}
-func (e *bridgeFieldEncoder) AddObject(key string, marshaler zapcore.ObjectMarshaler) error {
+func (e *bridgeFieldEncoder) AddObject(
+ key string,
+ marshaler zapcore.ObjectMarshaler,
+) error {
e.pairs = append(e.pairs, attribute.String(key, fmt.Sprint(marshaler)))
return nil
}
@@ -172,5 +182,10 @@ func (e *bridgeFieldEncoder) AddUintptr(key string, value uintptr) {
e.pairs = append(e.pairs, attribute.String(key, fmt.Sprint(value)))
}
-func (*bridgeFieldEncoder) AddReflected(key string, value any) error { return nil }
-func (*bridgeFieldEncoder) OpenNamespace(key string) {}
+func (*bridgeFieldEncoder) AddReflected(
+ key string,
+ value any,
+) error {
+ return nil
+}
+func (*bridgeFieldEncoder) OpenNamespace(key string) {}
diff --git a/examples/hotrod/pkg/tracing/http.go b/examples/hotrod/pkg/tracing/http.go
index bab10ec75f8..a2dbe690c9c 100644
--- a/examples/hotrod/pkg/tracing/http.go
+++ b/examples/hotrod/pkg/tracing/http.go
@@ -46,7 +46,12 @@ func NewHTTPClient(tp trace.TracerProvider) *HTTPClient {
// GetJSON executes HTTP GET against specified url and tried to parse
// the response into out object.
-func (c *HTTPClient) GetJSON(ctx context.Context, endpoint string, url string, out any) error {
+func (c *HTTPClient) GetJSON(
+ ctx context.Context,
+ endpoint string,
+ url string,
+ out any,
+) error {
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
return err
diff --git a/examples/hotrod/pkg/tracing/init.go b/examples/hotrod/pkg/tracing/init.go
index 994cb22dddb..c34541f244b 100644
--- a/examples/hotrod/pkg/tracing/init.go
+++ b/examples/hotrod/pkg/tracing/init.go
@@ -43,7 +43,12 @@ import (
var once sync.Once
// InitOTEL initializes OpenTelemetry SDK.
-func InitOTEL(serviceName string, exporterType string, metricsFactory metrics.Factory, logger log.Factory) trace.TracerProvider {
+func InitOTEL(
+ serviceName string,
+ exporterType string,
+ metricsFactory metrics.Factory,
+ logger log.Factory,
+) trace.TracerProvider {
once.Do(func() {
otel.SetTextMapPropagator(
propagation.NewCompositeTextMapPropagator(
@@ -54,11 +59,15 @@ func InitOTEL(serviceName string, exporterType string, metricsFactory metrics.Fa
exp, err := createOtelExporter(exporterType)
if err != nil {
- logger.Bg().Fatal("cannot create exporter", zap.String("exporterType", exporterType), zap.Error(err))
+ logger.Bg().
+ Fatal("cannot create exporter", zap.String("exporterType", exporterType), zap.Error(err))
}
logger.Bg().Debug("using " + exporterType + " trace exporter")
- rpcmetricsObserver := rpcmetrics.NewObserver(metricsFactory, rpcmetrics.DefaultNameNormalizer)
+ rpcmetricsObserver := rpcmetrics.NewObserver(
+ metricsFactory,
+ rpcmetrics.DefaultNameNormalizer,
+ )
res, err := resource.New(
context.Background(),
@@ -73,17 +82,24 @@ func InitOTEL(serviceName string, exporterType string, metricsFactory metrics.Fa
}
tp := sdktrace.NewTracerProvider(
- sdktrace.WithBatcher(exp, sdktrace.WithBatchTimeout(1000*time.Millisecond)),
+ sdktrace.WithBatcher(
+ exp,
+ sdktrace.WithBatchTimeout(1000*time.Millisecond),
+ ),
sdktrace.WithSpanProcessor(rpcmetricsObserver),
sdktrace.WithResource(res),
)
- logger.Bg().Debug("Created OTEL tracer", zap.String("service-name", serviceName))
+ logger.Bg().
+ Debug("Created OTEL tracer", zap.String("service-name", serviceName))
return tp
}
// withSecure instructs the client to use HTTPS scheme, instead of hotrod's desired default HTTP
func withSecure() bool {
- return strings.HasPrefix(os.Getenv("OTEL_EXPORTER_OTLP_ENDPOINT"), "https://") ||
+ return strings.HasPrefix(
+ os.Getenv("OTEL_EXPORTER_OTLP_ENDPOINT"),
+ "https://",
+ ) ||
strings.ToLower(os.Getenv("OTEL_EXPORTER_OTLP_INSECURE")) == "false"
}
@@ -92,7 +108,9 @@ func createOtelExporter(exporterType string) (sdktrace.SpanExporter, error) {
var err error
switch exporterType {
case "jaeger":
- return nil, errors.New("jaeger exporter is no longer supported, please use otlp")
+ return nil, errors.New(
+ "jaeger exporter is no longer supported, please use otlp",
+ )
case "otlp":
var opts []otlptracehttp.Option
if !withSecure() {
diff --git a/examples/hotrod/pkg/tracing/mux.go b/examples/hotrod/pkg/tracing/mux.go
index d003f8f11c3..a32bdcab6cc 100644
--- a/examples/hotrod/pkg/tracing/mux.go
+++ b/examples/hotrod/pkg/tracing/mux.go
@@ -27,7 +27,11 @@ import (
)
// NewServeMux creates a new TracedServeMux.
-func NewServeMux(copyBaggage bool, tracer trace.TracerProvider, logger log.Factory) *TracedServeMux {
+func NewServeMux(
+ copyBaggage bool,
+ tracer trace.TracerProvider,
+ logger log.Factory,
+) *TracedServeMux {
return &TracedServeMux{
mux: http.NewServeMux(),
copyBaggage: copyBaggage,
@@ -46,7 +50,8 @@ type TracedServeMux struct {
// Handle implements http.ServeMux#Handle, which is used to register new handler.
func (tm *TracedServeMux) Handle(pattern string, handler http.Handler) {
- tm.logger.Bg().Debug("registering traced handler", zap.String("endpoint", pattern))
+ tm.logger.Bg().
+ Debug("registering traced handler", zap.String("endpoint", pattern))
middleware := otelhttp.NewHandler(
otelhttp.WithRouteTag(pattern, traceResponseHandler(handler)),
diff --git a/examples/hotrod/pkg/tracing/rpcmetrics/endpoints.go b/examples/hotrod/pkg/tracing/rpcmetrics/endpoints.go
index 7ca73bfa18b..7950a8050c4 100644
--- a/examples/hotrod/pkg/tracing/rpcmetrics/endpoints.go
+++ b/examples/hotrod/pkg/tracing/rpcmetrics/endpoints.go
@@ -25,7 +25,10 @@ type normalizedEndpoints struct {
mux sync.RWMutex
}
-func newNormalizedEndpoints(maxSize int, normalizer NameNormalizer) *normalizedEndpoints {
+func newNormalizedEndpoints(
+ maxSize int,
+ normalizer NameNormalizer,
+) *normalizedEndpoints {
return &normalizedEndpoints{
maxSize: maxSize,
normalizer: normalizer,
diff --git a/examples/hotrod/pkg/tracing/rpcmetrics/metrics.go b/examples/hotrod/pkg/tracing/rpcmetrics/metrics.go
index 561615f35e9..8e65659cba6 100644
--- a/examples/hotrod/pkg/tracing/rpcmetrics/metrics.go
+++ b/examples/hotrod/pkg/tracing/rpcmetrics/metrics.go
@@ -83,9 +83,15 @@ func newMetricsByEndpoint(
maxNumberOfEndpoints int,
) *MetricsByEndpoint {
return &MetricsByEndpoint{
- metricsFactory: metricsFactory,
- endpoints: newNormalizedEndpoints(maxNumberOfEndpoints, normalizer),
- metricsByEndpoint: make(map[string]*Metrics, maxNumberOfEndpoints+1), // +1 for "other"
+ metricsFactory: metricsFactory,
+ endpoints: newNormalizedEndpoints(
+ maxNumberOfEndpoints,
+ normalizer,
+ ),
+ metricsByEndpoint: make(
+ map[string]*Metrics,
+ maxNumberOfEndpoints+1,
+ ), // +1 for "other"
}
}
diff --git a/examples/hotrod/pkg/tracing/rpcmetrics/metrics_test.go b/examples/hotrod/pkg/tracing/rpcmetrics/metrics_test.go
index 3db618115c4..bbdbfbbaffc 100644
--- a/examples/hotrod/pkg/tracing/rpcmetrics/metrics_test.go
+++ b/examples/hotrod/pkg/tracing/rpcmetrics/metrics_test.go
@@ -54,9 +54,22 @@ func TestMetricsByEndpoint(t *testing.T) {
m.RequestCountSuccess.Inc(1)
}
- met.AssertCounterMetrics(t,
- metricstest.ExpectedMetric{Name: "requests", Tags: endpointTags("abc1", "error", "false"), Value: 3},
- metricstest.ExpectedMetric{Name: "requests", Tags: endpointTags("abc3", "error", "false"), Value: 1},
- metricstest.ExpectedMetric{Name: "requests", Tags: endpointTags("other", "error", "false"), Value: 2},
+ met.AssertCounterMetrics(
+ t,
+ metricstest.ExpectedMetric{
+ Name: "requests",
+ Tags: endpointTags("abc1", "error", "false"),
+ Value: 3,
+ },
+ metricstest.ExpectedMetric{
+ Name: "requests",
+ Tags: endpointTags("abc3", "error", "false"),
+ Value: 1,
+ },
+ metricstest.ExpectedMetric{
+ Name: "requests",
+ Tags: endpointTags("other", "error", "false"),
+ Value: 2,
+ },
)
}
diff --git a/examples/hotrod/pkg/tracing/rpcmetrics/observer.go b/examples/hotrod/pkg/tracing/rpcmetrics/observer.go
index 2b14077a10d..3412c7cf766 100644
--- a/examples/hotrod/pkg/tracing/rpcmetrics/observer.go
+++ b/examples/hotrod/pkg/tracing/rpcmetrics/observer.go
@@ -38,7 +38,10 @@ type Observer struct {
}
// NewObserver creates a new observer that can emit RPC metrics.
-func NewObserver(metricsFactory metrics.Factory, normalizer NameNormalizer) *Observer {
+func NewObserver(
+ metricsFactory metrics.Factory,
+ normalizer NameNormalizer,
+) *Observer {
return &Observer{
metricsByEndpoint: newMetricsByEndpoint(
metricsFactory,
diff --git a/examples/hotrod/pkg/tracing/rpcmetrics/observer_test.go b/examples/hotrod/pkg/tracing/rpcmetrics/observer_test.go
index 27fbb84722e..93dae6641a9 100644
--- a/examples/hotrod/pkg/tracing/rpcmetrics/observer_test.go
+++ b/examples/hotrod/pkg/tracing/rpcmetrics/observer_test.go
@@ -68,7 +68,11 @@ func TestObserver(t *testing.T) {
}{
{name: "local-span", spanKind: trace.SpanKindInternal},
{name: "get-user", spanKind: trace.SpanKindServer},
- {name: "get-user", spanKind: trace.SpanKindServer, opNameOverride: "get-user-override"},
+ {
+ name: "get-user",
+ spanKind: trace.SpanKindServer,
+ opNameOverride: "get-user-override",
+ },
{name: "get-user", spanKind: trace.SpanKindServer, err: true},
{name: "get-user-client", spanKind: trace.SpanKindClient},
}
@@ -88,18 +92,47 @@ func TestObserver(t *testing.T) {
span.End(finishOptions)
}
- testTracer.metrics.AssertCounterMetrics(t,
- u.ExpectedMetric{Name: "requests", Tags: endpointTags("local_span", "error", "false"), Value: 0},
- u.ExpectedMetric{Name: "requests", Tags: endpointTags("get_user", "error", "false"), Value: 1},
- u.ExpectedMetric{Name: "requests", Tags: endpointTags("get_user", "error", "true"), Value: 1},
- u.ExpectedMetric{Name: "requests", Tags: endpointTags("get_user_override", "error", "false"), Value: 1},
- u.ExpectedMetric{Name: "requests", Tags: endpointTags("get_user_client", "error", "false"), Value: 0},
+ testTracer.metrics.AssertCounterMetrics(
+ t,
+ u.ExpectedMetric{
+ Name: "requests",
+ Tags: endpointTags("local_span", "error", "false"),
+ Value: 0,
+ },
+ u.ExpectedMetric{
+ Name: "requests",
+ Tags: endpointTags("get_user", "error", "false"),
+ Value: 1,
+ },
+ u.ExpectedMetric{
+ Name: "requests",
+ Tags: endpointTags("get_user", "error", "true"),
+ Value: 1,
+ },
+ u.ExpectedMetric{
+ Name: "requests",
+ Tags: endpointTags("get_user_override", "error", "false"),
+ Value: 1,
+ },
+ u.ExpectedMetric{
+ Name: "requests",
+ Tags: endpointTags("get_user_client", "error", "false"),
+ Value: 0,
+ },
)
// TODO something wrong with string generation, .P99 should not be appended to the tag
// as a result we cannot use u.AssertGaugeMetrics
_, g := testTracer.metrics.Snapshot()
- assert.EqualValues(t, 51, g["request_latency|endpoint=get_user|error=false.P99"])
- assert.EqualValues(t, 51, g["request_latency|endpoint=get_user|error=true.P99"])
+ assert.EqualValues(
+ t,
+ 51,
+ g["request_latency|endpoint=get_user|error=false.P99"],
+ )
+ assert.EqualValues(
+ t,
+ 51,
+ g["request_latency|endpoint=get_user|error=true.P99"],
+ )
})
}
@@ -122,7 +155,11 @@ func TestTags(t *testing.T) {
testCases = append(testCases, tagTestCase{
attr: semconv.HTTPResponseStatusCode(i),
metrics: []u.ExpectedMetric{
- {Name: "http_requests", Value: 1, Tags: tags("status_code", fmt.Sprintf("%dxx", i/100))},
+ {
+ Name: "http_requests",
+ Value: 1,
+ Tags: tags("status_code", fmt.Sprintf("%dxx", i/100)),
+ },
},
})
}
@@ -131,19 +168,24 @@ func TestTags(t *testing.T) {
for i := range testCase.metrics {
testCase.metrics[i].Tags["endpoint"] = "span"
}
- t.Run(fmt.Sprintf("%s-%v", testCase.attr.Key, testCase.attr.Value), func(t *testing.T) {
- withTestTracer(func(testTracer *testTracer) {
- _, span := testTracer.tracer.Start(
- context.Background(),
- "span", trace.WithSpanKind(trace.SpanKindServer),
- )
- span.SetAttributes(testCase.attr)
- if testCase.err {
- span.SetStatus(codes.Error, "An error occurred")
- }
- span.End()
- testTracer.metrics.AssertCounterMetrics(t, testCase.metrics...)
- })
- })
+ t.Run(
+ fmt.Sprintf("%s-%v", testCase.attr.Key, testCase.attr.Value),
+ func(t *testing.T) {
+ withTestTracer(func(testTracer *testTracer) {
+ _, span := testTracer.tracer.Start(
+ context.Background(),
+ "span", trace.WithSpanKind(trace.SpanKindServer),
+ )
+ span.SetAttributes(testCase.attr)
+ if testCase.err {
+ span.SetStatus(codes.Error, "An error occurred")
+ }
+ span.End()
+ testTracer.metrics.AssertCounterMetrics(
+ t,
+ testCase.metrics...)
+ })
+ },
+ )
}
}
diff --git a/examples/hotrod/services/customer/client.go b/examples/hotrod/services/customer/client.go
index 56f0cb96e5f..b8b960097d3 100644
--- a/examples/hotrod/services/customer/client.go
+++ b/examples/hotrod/services/customer/client.go
@@ -34,7 +34,11 @@ type Client struct {
}
// NewClient creates a new customer.Client
-func NewClient(tracer trace.TracerProvider, logger log.Factory, hostPort string) *Client {
+func NewClient(
+ tracer trace.TracerProvider,
+ logger log.Factory,
+ hostPort string,
+) *Client {
return &Client{
logger: logger,
client: tracing.NewHTTPClient(tracer),
@@ -44,7 +48,8 @@ func NewClient(tracer trace.TracerProvider, logger log.Factory, hostPort string)
// Get implements customer.Interface#Get as an RPC
func (c *Client) Get(ctx context.Context, customerID int) (*Customer, error) {
- c.logger.For(ctx).Info("Getting customer", zap.Int("customer_id", customerID))
+ c.logger.For(ctx).
+ Info("Getting customer", zap.Int("customer_id", customerID))
url := fmt.Sprintf("http://"+c.hostPort+"/customer?customer=%d", customerID)
var customer Customer
diff --git a/examples/hotrod/services/customer/database.go b/examples/hotrod/services/customer/database.go
index 67247a11de0..acd24e6e0ff 100644
--- a/examples/hotrod/services/customer/database.go
+++ b/examples/hotrod/services/customer/database.go
@@ -73,9 +73,14 @@ func newDatabase(tracer trace.Tracer, logger log.Factory) *database {
}
func (d *database) Get(ctx context.Context, customerID int) (*Customer, error) {
- d.logger.For(ctx).Info("Loading customer", zap.Int("customer_id", customerID))
+ d.logger.For(ctx).
+ Info("Loading customer", zap.Int("customer_id", customerID))
- ctx, span := d.tracer.Start(ctx, "SQL SELECT", trace.WithSpanKind(trace.SpanKindClient))
+ ctx, span := d.tracer.Start(
+ ctx,
+ "SQL SELECT",
+ trace.WithSpanKind(trace.SpanKindClient),
+ )
span.SetAttributes(
semconv.PeerServiceKey.String("mysql"),
attribute.
diff --git a/examples/hotrod/services/customer/server.go b/examples/hotrod/services/customer/server.go
index e353c20f96e..3b89f01893a 100644
--- a/examples/hotrod/services/customer/server.go
+++ b/examples/hotrod/services/customer/server.go
@@ -39,13 +39,24 @@ type Server struct {
}
// NewServer creates a new customer.Server
-func NewServer(hostPort string, otelExporter string, metricsFactory metrics.Factory, logger log.Factory) *Server {
+func NewServer(
+ hostPort string,
+ otelExporter string,
+ metricsFactory metrics.Factory,
+ logger log.Factory,
+) *Server {
return &Server{
hostPort: hostPort,
- tracer: tracing.InitOTEL("customer", otelExporter, metricsFactory, logger),
- logger: logger,
+ tracer: tracing.InitOTEL(
+ "customer",
+ otelExporter,
+ metricsFactory,
+ logger,
+ ),
+ logger: logger,
database: newDatabase(
- tracing.InitOTEL("mysql", otelExporter, metricsFactory, logger).Tracer("mysql"),
+ tracing.InitOTEL("mysql", otelExporter, metricsFactory, logger).
+ Tracer("mysql"),
logger.With(zap.String("component", "mysql")),
),
}
@@ -71,20 +82,33 @@ func (s *Server) createServeMux() http.Handler {
func (s *Server) customer(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
- s.logger.For(ctx).Info("HTTP request received", zap.String("method", r.Method), zap.Stringer("url", r.URL))
- if err := r.ParseForm(); httperr.HandleError(w, err, http.StatusBadRequest) {
+ s.logger.For(ctx).
+ Info("HTTP request received", zap.String("method", r.Method), zap.Stringer("url", r.URL))
+ if err := r.ParseForm(); httperr.HandleError(
+ w,
+ err,
+ http.StatusBadRequest,
+ ) {
s.logger.For(ctx).Error("bad request", zap.Error(err))
return
}
customer := r.Form.Get("customer")
if customer == "" {
- http.Error(w, "Missing required 'customer' parameter", http.StatusBadRequest)
+ http.Error(
+ w,
+ "Missing required 'customer' parameter",
+ http.StatusBadRequest,
+ )
return
}
customerID, err := strconv.Atoi(customer)
if err != nil {
- http.Error(w, "Parameter 'customer' is not an integer", http.StatusBadRequest)
+ http.Error(
+ w,
+ "Parameter 'customer' is not an integer",
+ http.StatusBadRequest,
+ )
return
}
diff --git a/examples/hotrod/services/driver/client.go b/examples/hotrod/services/driver/client.go
index bc83cabbf92..62de2403232 100644
--- a/examples/hotrod/services/driver/client.go
+++ b/examples/hotrod/services/driver/client.go
@@ -35,10 +35,19 @@ type Client struct {
}
// NewClient creates a new driver.Client
-func NewClient(tracerProvider trace.TracerProvider, logger log.Factory, hostPort string) *Client {
- conn, err := grpc.NewClient(hostPort,
+func NewClient(
+ tracerProvider trace.TracerProvider,
+ logger log.Factory,
+ hostPort string,
+) *Client {
+ conn, err := grpc.NewClient(
+ hostPort,
grpc.WithTransportCredentials(insecure.NewCredentials()),
- grpc.WithStatsHandler(otelgrpc.NewClientHandler(otelgrpc.WithTracerProvider(tracerProvider))),
+ grpc.WithStatsHandler(
+ otelgrpc.NewClientHandler(
+ otelgrpc.WithTracerProvider(tracerProvider),
+ ),
+ ),
)
if err != nil {
logger.Bg().Fatal("Cannot create gRPC connection", zap.Error(err))
@@ -52,11 +61,18 @@ func NewClient(tracerProvider trace.TracerProvider, logger log.Factory, hostPort
}
// FindNearest implements driver.Interface#FindNearest as an RPC
-func (c *Client) FindNearest(ctx context.Context, location string) ([]Driver, error) {
- c.logger.For(ctx).Info("Finding nearest drivers", zap.String("location", location))
+func (c *Client) FindNearest(
+ ctx context.Context,
+ location string,
+) ([]Driver, error) {
+ c.logger.For(ctx).
+ Info("Finding nearest drivers", zap.String("location", location))
ctx, cancel := context.WithTimeout(ctx, 1*time.Second)
defer cancel()
- response, err := c.client.FindNearest(ctx, &DriverLocationRequest{Location: location})
+ response, err := c.client.FindNearest(
+ ctx,
+ &DriverLocationRequest{Location: location},
+ )
if err != nil {
return nil, err
}
diff --git a/examples/hotrod/services/driver/redis.go b/examples/hotrod/services/driver/redis.go
index 004d4c18996..478960cd25f 100644
--- a/examples/hotrod/services/driver/redis.go
+++ b/examples/hotrod/services/driver/redis.go
@@ -41,7 +41,11 @@ type Redis struct {
errorSimulator
}
-func newRedis(otelExporter string, metricsFactory metrics.Factory, logger log.Factory) *Redis {
+func newRedis(
+ otelExporter string,
+ metricsFactory metrics.Factory,
+ logger log.Factory,
+) *Redis {
tp := tracing.InitOTEL("redis-manual", otelExporter, metricsFactory, logger)
return &Redis{
tracer: tp.Tracer("redis-manual"),
@@ -51,7 +55,11 @@ func newRedis(otelExporter string, metricsFactory metrics.Factory, logger log.Fa
// FindDriverIDs finds IDs of drivers who are near the location.
func (r *Redis) FindDriverIDs(ctx context.Context, location string) []string {
- ctx, span := r.tracer.Start(ctx, "FindDriverIDs", trace.WithSpanKind(trace.SpanKindClient))
+ ctx, span := r.tracer.Start(
+ ctx,
+ "FindDriverIDs",
+ trace.WithSpanKind(trace.SpanKindClient),
+ )
span.SetAttributes(attribute.Key("param.driver.location").String(location))
defer span.End()
@@ -68,8 +76,15 @@ func (r *Redis) FindDriverIDs(ctx context.Context, location string) []string {
}
// GetDriver returns driver and the current car location
-func (r *Redis) GetDriver(ctx context.Context, driverID string) (Driver, error) {
- ctx, span := r.tracer.Start(ctx, "GetDriver", trace.WithSpanKind(trace.SpanKindClient))
+func (r *Redis) GetDriver(
+ ctx context.Context,
+ driverID string,
+) (Driver, error) {
+ ctx, span := r.tracer.Start(
+ ctx,
+ "GetDriver",
+ trace.WithSpanKind(trace.SpanKindClient),
+ )
span.SetAttributes(attribute.Key("param.driverID").String(driverID))
defer span.End()
@@ -78,7 +93,8 @@ func (r *Redis) GetDriver(ctx context.Context, driverID string) (Driver, error)
if err := r.checkError(); err != nil {
span.RecordError(err)
span.SetStatus(codes.Error, "An error occurred")
- r.logger.For(ctx).Error("redis timeout", zap.String("driver_id", driverID), zap.Error(err))
+ r.logger.For(ctx).
+ Error("redis timeout", zap.String("driver_id", driverID), zap.Error(err))
return Driver{}, err
}
diff --git a/examples/hotrod/services/driver/server.go b/examples/hotrod/services/driver/server.go
index 9773ab5d14b..b42992239d3 100644
--- a/examples/hotrod/services/driver/server.go
+++ b/examples/hotrod/services/driver/server.go
@@ -40,10 +40,24 @@ type Server struct {
var _ DriverServiceServer = (*Server)(nil)
// NewServer creates a new driver.Server
-func NewServer(hostPort string, otelExporter string, metricsFactory metrics.Factory, logger log.Factory) *Server {
- tracerProvider := tracing.InitOTEL("driver", otelExporter, metricsFactory, logger)
+func NewServer(
+ hostPort string,
+ otelExporter string,
+ metricsFactory metrics.Factory,
+ logger log.Factory,
+) *Server {
+ tracerProvider := tracing.InitOTEL(
+ "driver",
+ otelExporter,
+ metricsFactory,
+ logger,
+ )
server := grpc.NewServer(
- grpc.StatsHandler(otelgrpc.NewServerHandler(otelgrpc.WithTracerProvider(tracerProvider))),
+ grpc.StatsHandler(
+ otelgrpc.NewServerHandler(
+ otelgrpc.WithTracerProvider(tracerProvider),
+ ),
+ ),
)
return &Server{
hostPort: hostPort,
@@ -60,7 +74,8 @@ func (s *Server) Run() error {
s.logger.Bg().Fatal("Unable to create http listener", zap.Error(err))
}
RegisterDriverServiceServer(s.server, s)
- s.logger.Bg().Info("Starting", zap.String("address", s.hostPort), zap.String("type", "gRPC"))
+ s.logger.Bg().
+ Info("Starting", zap.String("address", s.hostPort), zap.String("type", "gRPC"))
err = s.server.Serve(lis)
if err != nil {
s.logger.Bg().Fatal("Unable to start gRPC server", zap.Error(err))
@@ -69,8 +84,12 @@ func (s *Server) Run() error {
}
// FindNearest implements gRPC driver interface
-func (s *Server) FindNearest(ctx context.Context, location *DriverLocationRequest) (*DriverLocationResponse, error) {
- s.logger.For(ctx).Info("Searching for nearby drivers", zap.String("location", location.Location))
+func (s *Server) FindNearest(
+ ctx context.Context,
+ location *DriverLocationRequest,
+) (*DriverLocationResponse, error) {
+ s.logger.For(ctx).
+ Info("Searching for nearby drivers", zap.String("location", location.Location))
driverIDs := s.redis.FindDriverIDs(ctx, location.Location)
locations := make([]*DriverLocation, len(driverIDs))
@@ -82,10 +101,12 @@ func (s *Server) FindNearest(ctx context.Context, location *DriverLocationReques
if err == nil {
break
}
- s.logger.For(ctx).Error("Retrying GetDriver after error", zap.Int("retry_no", i+1), zap.Error(err))
+ s.logger.For(ctx).
+ Error("Retrying GetDriver after error", zap.Int("retry_no", i+1), zap.Error(err))
}
if err != nil {
- s.logger.For(ctx).Error("Failed to get driver after 3 attempts", zap.Error(err))
+ s.logger.For(ctx).
+ Error("Failed to get driver after 3 attempts", zap.Error(err))
return nil, err
}
locations[i] = &DriverLocation{
diff --git a/examples/hotrod/services/frontend/best_eta.go b/examples/hotrod/services/frontend/best_eta.go
index 58c6bdbcc55..1a7358614a0 100644
--- a/examples/hotrod/services/frontend/best_eta.go
+++ b/examples/hotrod/services/frontend/best_eta.go
@@ -48,7 +48,11 @@ type Response struct {
ETA time.Duration
}
-func newBestETA(tracer trace.TracerProvider, logger log.Factory, options ConfigOptions) *bestETA {
+func newBestETA(
+ tracer trace.TracerProvider,
+ logger log.Factory,
+ options ConfigOptions,
+) *bestETA {
return &bestETA{
customer: customer.NewClient(
tracer,
@@ -70,7 +74,10 @@ func newBestETA(tracer trace.TracerProvider, logger log.Factory, options ConfigO
}
}
-func (eta *bestETA) Get(ctx context.Context, customerID int) (*Response, error) {
+func (eta *bestETA) Get(
+ ctx context.Context,
+ customerID int,
+) (*Response, error) {
customer, err := eta.customer.Get(ctx, customerID)
if err != nil {
return nil, err
@@ -79,7 +86,8 @@ func (eta *bestETA) Get(ctx context.Context, customerID int) (*Response, error)
m, err := baggage.NewMember("customer", customer.Name)
if err != nil {
- eta.logger.For(ctx).Error("cannot create baggage member", zap.Error(err))
+ eta.logger.For(ctx).
+ Error("cannot create baggage member", zap.Error(err))
}
bag := baggage.FromContext(ctx)
bag, err = bag.SetMember(m)
@@ -111,7 +119,8 @@ func (eta *bestETA) Get(ctx context.Context, customerID int) (*Response, error)
return nil, errors.New("no routes found")
}
- eta.logger.For(ctx).Info("Dispatch successful", zap.String("driver", resp.Driver), zap.String("eta", resp.ETA.String()))
+ eta.logger.For(ctx).
+ Info("Dispatch successful", zap.String("driver", resp.Driver), zap.String("eta", resp.ETA.String()))
return resp, nil
}
@@ -122,7 +131,11 @@ type routeResult struct {
}
// getRoutes calls Route service for each (customer, driver) pair
-func (eta *bestETA) getRoutes(ctx context.Context, customer *customer.Customer, drivers []driver.Driver) []routeResult {
+func (eta *bestETA) getRoutes(
+ ctx context.Context,
+ customer *customer.Customer,
+ drivers []driver.Driver,
+) []routeResult {
results := make([]routeResult, 0, len(drivers))
wg := sync.WaitGroup{}
routesLock := sync.Mutex{}
@@ -131,7 +144,11 @@ func (eta *bestETA) getRoutes(ctx context.Context, customer *customer.Customer,
driver := dd // capture loop var
// Use worker pool to (potentially) execute requests in parallel
eta.pool.Execute(func() {
- route, err := eta.route.FindRoute(ctx, driver.Location, customer.Location)
+ route, err := eta.route.FindRoute(
+ ctx,
+ driver.Location,
+ customer.Location,
+ )
routesLock.Lock()
results = append(results, routeResult{
driver: driver.DriverID,
diff --git a/examples/hotrod/services/frontend/server.go b/examples/hotrod/services/frontend/server.go
index 65bf9bd5f99..0749b89e30f 100644
--- a/examples/hotrod/services/frontend/server.go
+++ b/examples/hotrod/services/frontend/server.go
@@ -60,7 +60,11 @@ type ConfigOptions struct {
}
// NewServer creates a new frontend.Server
-func NewServer(options ConfigOptions, tracer trace.TracerProvider, logger log.Factory) *Server {
+func NewServer(
+ options ConfigOptions,
+ tracer trace.TracerProvider,
+ logger log.Factory,
+) *Server {
return &Server{
hostPort: options.FrontendHostPort,
tracer: tracer,
@@ -75,7 +79,8 @@ func NewServer(options ConfigOptions, tracer trace.TracerProvider, logger log.Fa
// Run starts the frontend server
func (s *Server) Run() error {
mux := s.createServeMux()
- s.logger.Bg().Info("Starting", zap.String("address", "http://"+path.Join(s.hostPort, s.basepath)))
+ s.logger.Bg().
+ Info("Starting", zap.String("address", "http://"+path.Join(s.hostPort, s.basepath)))
server := &http.Server{
Addr: s.hostPort,
Handler: mux,
@@ -104,20 +109,33 @@ func (s *Server) config(w http.ResponseWriter, r *http.Request) {
func (s *Server) dispatch(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
- s.logger.For(ctx).Info("HTTP request received", zap.String("method", r.Method), zap.Stringer("url", r.URL))
- if err := r.ParseForm(); httperr.HandleError(w, err, http.StatusBadRequest) {
+ s.logger.For(ctx).
+ Info("HTTP request received", zap.String("method", r.Method), zap.Stringer("url", r.URL))
+ if err := r.ParseForm(); httperr.HandleError(
+ w,
+ err,
+ http.StatusBadRequest,
+ ) {
s.logger.For(ctx).Error("bad request", zap.Error(err))
return
}
customer := r.Form.Get("customer")
if customer == "" {
- http.Error(w, "Missing required 'customer' parameter", http.StatusBadRequest)
+ http.Error(
+ w,
+ "Missing required 'customer' parameter",
+ http.StatusBadRequest,
+ )
return
}
customerID, err := strconv.Atoi(customer)
if err != nil {
- http.Error(w, "Parameter 'customer' is not an integer", http.StatusBadRequest)
+ http.Error(
+ w,
+ "Parameter 'customer' is not an integer",
+ http.StatusBadRequest,
+ )
return
}
@@ -131,10 +149,15 @@ func (s *Server) dispatch(w http.ResponseWriter, r *http.Request) {
s.writeResponse(response, w, r)
}
-func (s *Server) writeResponse(response any, w http.ResponseWriter, r *http.Request) {
+func (s *Server) writeResponse(
+ response any,
+ w http.ResponseWriter,
+ r *http.Request,
+) {
data, err := json.Marshal(response)
if httperr.HandleError(w, err, http.StatusInternalServerError) {
- s.logger.For(r.Context()).Error("cannot marshal response", zap.Error(err))
+ s.logger.For(r.Context()).
+ Error("cannot marshal response", zap.Error(err))
return
}
diff --git a/examples/hotrod/services/route/client.go b/examples/hotrod/services/route/client.go
index 7c58f76e1dc..8fe039148d1 100644
--- a/examples/hotrod/services/route/client.go
+++ b/examples/hotrod/services/route/client.go
@@ -34,7 +34,11 @@ type Client struct {
}
// NewClient creates a new route.Client
-func NewClient(tracer trace.TracerProvider, logger log.Factory, hostPort string) *Client {
+func NewClient(
+ tracer trace.TracerProvider,
+ logger log.Factory,
+ hostPort string,
+) *Client {
return &Client{
logger: logger,
client: tracing.NewHTTPClient(tracer),
@@ -43,8 +47,12 @@ func NewClient(tracer trace.TracerProvider, logger log.Factory, hostPort string)
}
// FindRoute implements route.Interface#FindRoute as an RPC
-func (c *Client) FindRoute(ctx context.Context, pickup, dropoff string) (*Route, error) {
- c.logger.For(ctx).Info("Finding route", zap.String("pickup", pickup), zap.String("dropoff", dropoff))
+func (c *Client) FindRoute(
+ ctx context.Context,
+ pickup, dropoff string,
+) (*Route, error) {
+ c.logger.For(ctx).
+ Info("Finding route", zap.String("pickup", pickup), zap.String("dropoff", dropoff))
v := url.Values{}
v.Set("pickup", pickup)
diff --git a/examples/hotrod/services/route/server.go b/examples/hotrod/services/route/server.go
index 2cea77ce8e7..9c6c768530b 100644
--- a/examples/hotrod/services/route/server.go
+++ b/examples/hotrod/services/route/server.go
@@ -41,7 +41,11 @@ type Server struct {
}
// NewServer creates a new route.Server
-func NewServer(hostPort string, tracer trace.TracerProvider, logger log.Factory) *Server {
+func NewServer(
+ hostPort string,
+ tracer trace.TracerProvider,
+ logger log.Factory,
+) *Server {
return &Server{
hostPort: hostPort,
tracer: tracer,
@@ -75,21 +79,34 @@ func movedToFrontend(w http.ResponseWriter, r *http.Request) {
func (s *Server) route(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
- s.logger.For(ctx).Info("HTTP request received", zap.String("method", r.Method), zap.Stringer("url", r.URL))
- if err := r.ParseForm(); httperr.HandleError(w, err, http.StatusBadRequest) {
+ s.logger.For(ctx).
+ Info("HTTP request received", zap.String("method", r.Method), zap.Stringer("url", r.URL))
+ if err := r.ParseForm(); httperr.HandleError(
+ w,
+ err,
+ http.StatusBadRequest,
+ ) {
s.logger.For(ctx).Error("bad request", zap.Error(err))
return
}
pickup := r.Form.Get("pickup")
if pickup == "" {
- http.Error(w, "Missing required 'pickup' parameter", http.StatusBadRequest)
+ http.Error(
+ w,
+ "Missing required 'pickup' parameter",
+ http.StatusBadRequest,
+ )
return
}
dropoff := r.Form.Get("dropoff")
if dropoff == "" {
- http.Error(w, "Missing required 'dropoff' parameter", http.StatusBadRequest)
+ http.Error(
+ w,
+ "Missing required 'dropoff' parameter",
+ http.StatusBadRequest,
+ )
return
}
diff --git a/internal/jaegerclientenv2otel/envvars.go b/internal/jaegerclientenv2otel/envvars.go
index 758649ebe67..4a88c464361 100644
--- a/internal/jaegerclientenv2otel/envvars.go
+++ b/internal/jaegerclientenv2otel/envvars.go
@@ -51,7 +51,8 @@ func MapJaegerToOtelEnvVars(logger *zap.Logger) {
continue
}
if otelname == "" {
- logger.Sugar().Infof("Ignoring deprecated Jaeger SDK env var %s, as there is no equivalent in OpenTelemetry", jname)
+ logger.Sugar().
+ Infof("Ignoring deprecated Jaeger SDK env var %s, as there is no equivalent in OpenTelemetry", jname)
} else {
os.Setenv(otelname, val)
logger.Sugar().Infof("Replacing deprecated Jaeger SDK env var %s with OpenTelemetry env var %s", jname, otelname)
diff --git a/internal/jaegerclientenv2otel/envvars_test.go b/internal/jaegerclientenv2otel/envvars_test.go
index 80ad2afa600..aca6aa97a73 100644
--- a/internal/jaegerclientenv2otel/envvars_test.go
+++ b/internal/jaegerclientenv2otel/envvars_test.go
@@ -32,7 +32,11 @@ func TestMapJaegerToOtelEnvVars(t *testing.T) {
MapJaegerToOtelEnvVars(logger)
assert.Equal(t, "user", os.Getenv("OTEL_EXPORTER_JAEGER_USER"))
- assert.Contains(t, buffer.String(), "Replacing deprecated Jaeger SDK env var JAEGER_USER with OpenTelemetry env var OTEL_EXPORTER_JAEGER_USER")
+ assert.Contains(
+ t,
+ buffer.String(),
+ "Replacing deprecated Jaeger SDK env var JAEGER_USER with OpenTelemetry env var OTEL_EXPORTER_JAEGER_USER",
+ )
assert.Contains(t, buffer.String(), "Ignoring deprecated Jaeger SDK env var JAEGER_TAGS")
}
diff --git a/internal/metrics/metricsbuilder/builder.go b/internal/metrics/metricsbuilder/builder.go
index 4bd71304f08..553225ab50a 100644
--- a/internal/metrics/metricsbuilder/builder.go
+++ b/internal/metrics/metricsbuilder/builder.go
@@ -49,11 +49,13 @@ func AddFlags(flags *flag.FlagSet) {
flags.String(
metricsBackend,
defaultMetricsBackend,
- "Defines which metrics backend to use for metrics reporting: prometheus or none")
+ "Defines which metrics backend to use for metrics reporting: prometheus or none",
+ )
flags.String(
metricsHTTPRoute,
defaultMetricsRoute,
- "Defines the route of HTTP endpoint for metrics backends that support scraping")
+ "Defines the route of HTTP endpoint for metrics backends that support scraping",
+ )
}
// InitFromViper initializes Builder with properties retrieved from Viper.
@@ -66,10 +68,16 @@ func (b *Builder) InitFromViper(v *viper.Viper) *Builder {
// CreateMetricsFactory creates a metrics factory based on the configured type of the backend.
// If the metrics backend supports HTTP endpoint for scraping, it is stored in the builder and
// can be later added by RegisterHandler function.
-func (b *Builder) CreateMetricsFactory(namespace string) (metrics.Factory, error) {
+func (b *Builder) CreateMetricsFactory(
+ namespace string,
+) (metrics.Factory, error) {
if b.Backend == "prometheus" {
- metricsFactory := jprom.New().Namespace(metrics.NSOptions{Name: namespace, Tags: nil})
- b.handler = promhttp.HandlerFor(prometheus.DefaultGatherer, promhttp.HandlerOpts{DisableCompression: true})
+ metricsFactory := jprom.New().
+ Namespace(metrics.NSOptions{Name: namespace, Tags: nil})
+ b.handler = promhttp.HandlerFor(
+ prometheus.DefaultGatherer,
+ promhttp.HandlerOpts{DisableCompression: true},
+ )
return metricsFactory, nil
}
if b.Backend == "none" || b.Backend == "" {
diff --git a/internal/metrics/prometheus/cache.go b/internal/metrics/prometheus/cache.go
index d5bf7ec6789..a365546c31c 100644
--- a/internal/metrics/prometheus/cache.go
+++ b/internal/metrics/prometheus/cache.go
@@ -39,7 +39,10 @@ func newVectorCache(registerer prometheus.Registerer) *vectorCache {
}
}
-func (c *vectorCache) getOrMakeCounterVec(opts prometheus.CounterOpts, labelNames []string) *prometheus.CounterVec {
+func (c *vectorCache) getOrMakeCounterVec(
+ opts prometheus.CounterOpts,
+ labelNames []string,
+) *prometheus.CounterVec {
c.lock.Lock()
defer c.lock.Unlock()
@@ -53,7 +56,10 @@ func (c *vectorCache) getOrMakeCounterVec(opts prometheus.CounterOpts, labelName
return cv
}
-func (c *vectorCache) getOrMakeGaugeVec(opts prometheus.GaugeOpts, labelNames []string) *prometheus.GaugeVec {
+func (c *vectorCache) getOrMakeGaugeVec(
+ opts prometheus.GaugeOpts,
+ labelNames []string,
+) *prometheus.GaugeVec {
c.lock.Lock()
defer c.lock.Unlock()
@@ -67,7 +73,10 @@ func (c *vectorCache) getOrMakeGaugeVec(opts prometheus.GaugeOpts, labelNames []
return gv
}
-func (c *vectorCache) getOrMakeHistogramVec(opts prometheus.HistogramOpts, labelNames []string) *prometheus.HistogramVec {
+func (c *vectorCache) getOrMakeHistogramVec(
+ opts prometheus.HistogramOpts,
+ labelNames []string,
+) *prometheus.HistogramVec {
c.lock.Lock()
defer c.lock.Unlock()
diff --git a/internal/metrics/prometheus/factory.go b/internal/metrics/prometheus/factory.go
index bb4a296ce95..e22c155ed78 100644
--- a/internal/metrics/prometheus/factory.go
+++ b/internal/metrics/prometheus/factory.go
@@ -115,7 +115,11 @@ func New(opts ...Option) *Factory {
nil) // tags
}
-func newFactory(parent *Factory, scope string, tags map[string]string) *Factory {
+func newFactory(
+ parent *Factory,
+ scope string,
+ tags map[string]string,
+) *Factory {
return &Factory{
cache: parent.cache,
buckets: parent.buckets,
@@ -194,7 +198,9 @@ func asFloatBuckets(buckets []time.Duration) []float64 {
}
// Histogram implements Histogram of metrics.Factory.
-func (f *Factory) Histogram(options metrics.HistogramOptions) metrics.Histogram {
+func (f *Factory) Histogram(
+ options metrics.HistogramOptions,
+) metrics.Histogram {
help := strings.TrimSpace(options.Help)
if len(help) == 0 {
help = options.Name
@@ -244,7 +250,9 @@ type timer struct {
}
func (t *timer) Record(v time.Duration) {
- t.histogram.Observe(float64(v.Nanoseconds()) / float64(time.Second/time.Nanosecond))
+ t.histogram.Observe(
+ float64(v.Nanoseconds()) / float64(time.Second/time.Nanosecond),
+ )
}
type histogram struct {
@@ -289,7 +297,10 @@ func (*Factory) tagNames(tags map[string]string) []string {
return ret
}
-func (*Factory) tagsAsLabelValues(labels []string, tags map[string]string) []string {
+func (*Factory) tagsAsLabelValues(
+ labels []string,
+ tags map[string]string,
+) []string {
ret := make([]string, 0, len(tags))
for _, l := range labels {
ret = append(ret, tags[l])
diff --git a/internal/metrics/prometheus/factory_test.go b/internal/metrics/prometheus/factory_test.go
index 5aa2eaa3409..1f392155a27 100644
--- a/internal/metrics/prometheus/factory_test.go
+++ b/internal/metrics/prometheus/factory_test.go
@@ -35,7 +35,10 @@ func TestOptions(t *testing.T) {
func TestSeparator(t *testing.T) {
registry := prometheus.NewPedanticRegistry()
- f1 := promMetrics.New(promMetrics.WithRegisterer(registry), promMetrics.WithSeparator(promMetrics.SeparatorColon))
+ f1 := promMetrics.New(
+ promMetrics.WithRegisterer(registry),
+ promMetrics.WithSeparator(promMetrics.SeparatorColon),
+ )
c1 := f1.Namespace(metrics.NSOptions{
Name: "bender",
}).Counter(metrics.Options{
@@ -46,7 +49,12 @@ func TestSeparator(t *testing.T) {
c1.Inc(1)
snapshot, err := registry.Gather()
require.NoError(t, err)
- m1 := findMetric(t, snapshot, "bender:rodriguez_total", map[string]string{"a": "b"})
+ m1 := findMetric(
+ t,
+ snapshot,
+ "bender:rodriguez_total",
+ map[string]string{"a": "b"},
+ )
assert.EqualValues(t, 1, m1.GetCounter().GetValue(), "%+v", m1)
}
@@ -85,10 +93,20 @@ func TestCounter(t *testing.T) {
assert.EqualValues(t, "Help message", snapshot[0].GetHelp())
- m1 := findMetric(t, snapshot, "bender_rodriguez_total", map[string]string{"a": "b", "x": "y"})
+ m1 := findMetric(
+ t,
+ snapshot,
+ "bender_rodriguez_total",
+ map[string]string{"a": "b", "x": "y"},
+ )
assert.EqualValues(t, 3, m1.GetCounter().GetValue(), "%+v", m1)
- m2 := findMetric(t, snapshot, "bender_rodriguez_total", map[string]string{"a": "b", "x": "z"})
+ m2 := findMetric(
+ t,
+ snapshot,
+ "bender_rodriguez_total",
+ map[string]string{"a": "b", "x": "z"},
+ )
assert.EqualValues(t, 7, m2.GetCounter().GetValue(), "%+v", m2)
}
@@ -142,10 +160,20 @@ func TestGauge(t *testing.T) {
assert.EqualValues(t, "Help message", snapshot[0].GetHelp())
- m1 := findMetric(t, snapshot, "bender_rodriguez", map[string]string{"a": "b", "x": "y"})
+ m1 := findMetric(
+ t,
+ snapshot,
+ "bender_rodriguez",
+ map[string]string{"a": "b", "x": "y"},
+ )
assert.EqualValues(t, 2, m1.GetGauge().GetValue(), "%+v", m1)
- m2 := findMetric(t, snapshot, "bender_rodriguez", map[string]string{"a": "b", "x": "z"})
+ m2 := findMetric(
+ t,
+ snapshot,
+ "bender_rodriguez",
+ map[string]string{"a": "b", "x": "z"},
+ )
assert.EqualValues(t, 4, m2.GetGauge().GetValue(), "%+v", m2)
}
@@ -199,7 +227,12 @@ func TestTimer(t *testing.T) {
assert.EqualValues(t, "Help message", snapshot[0].GetHelp())
- m1 := findMetric(t, snapshot, "bender_rodriguez", map[string]string{"a": "b", "x": "y"})
+ m1 := findMetric(
+ t,
+ snapshot,
+ "bender_rodriguez",
+ map[string]string{"a": "b", "x": "y"},
+ )
assert.EqualValues(t, 2, m1.GetHistogram().GetSampleCount(), "%+v", m1)
assert.EqualValues(t, 3, m1.GetHistogram().GetSampleSum(), "%+v", m1)
for _, bucket := range m1.GetHistogram().GetBucket() {
@@ -213,7 +246,12 @@ func TestTimer(t *testing.T) {
}
}
- m2 := findMetric(t, snapshot, "bender_rodriguez", map[string]string{"a": "b", "x": "z"})
+ m2 := findMetric(
+ t,
+ snapshot,
+ "bender_rodriguez",
+ map[string]string{"a": "b", "x": "z"},
+ )
assert.EqualValues(t, 2, m2.GetHistogram().GetSampleCount(), "%+v", m2)
assert.EqualValues(t, 7, m2.GetHistogram().GetSampleSum(), "%+v", m2)
for _, bucket := range m2.GetHistogram().GetBucket() {
@@ -245,7 +283,10 @@ func TestTimerDefaultHelp(t *testing.T) {
func TestTimerCustomBuckets(t *testing.T) {
registry := prometheus.NewPedanticRegistry()
- f1 := promMetrics.New(promMetrics.WithRegisterer(registry), promMetrics.WithBuckets([]float64{1.5}))
+ f1 := promMetrics.New(
+ promMetrics.WithRegisterer(registry),
+ promMetrics.WithBuckets([]float64{1.5}),
+ )
// dot and dash in the metric name will be replaced with underscore
t1 := f1.Timer(metrics.TimerOptions{
Name: "bender.bending-rodriguez",
@@ -258,7 +299,12 @@ func TestTimerCustomBuckets(t *testing.T) {
snapshot, err := registry.Gather()
require.NoError(t, err)
- m1 := findMetric(t, snapshot, "bender_bending_rodriguez", map[string]string{"x": "y"})
+ m1 := findMetric(
+ t,
+ snapshot,
+ "bender_bending_rodriguez",
+ map[string]string{"x": "y"},
+ )
assert.EqualValues(t, 2, m1.GetHistogram().GetSampleCount(), "%+v", m1)
assert.EqualValues(t, 3, m1.GetHistogram().GetSampleSum(), "%+v", m1)
assert.Len(t, m1.GetHistogram().GetBucket(), 2)
@@ -266,7 +312,10 @@ func TestTimerCustomBuckets(t *testing.T) {
func TestTimerDefaultBuckets(t *testing.T) {
registry := prometheus.NewPedanticRegistry()
- f1 := promMetrics.New(promMetrics.WithRegisterer(registry), promMetrics.WithBuckets([]float64{1.5, 2}))
+ f1 := promMetrics.New(
+ promMetrics.WithRegisterer(registry),
+ promMetrics.WithBuckets([]float64{1.5, 2}),
+ )
// dot and dash in the metric name will be replaced with underscore
t1 := f1.Timer(metrics.TimerOptions{
Name: "bender.bending-rodriguez",
@@ -279,7 +328,12 @@ func TestTimerDefaultBuckets(t *testing.T) {
snapshot, err := registry.Gather()
require.NoError(t, err)
- m1 := findMetric(t, snapshot, "bender_bending_rodriguez", map[string]string{"x": "y"})
+ m1 := findMetric(
+ t,
+ snapshot,
+ "bender_bending_rodriguez",
+ map[string]string{"x": "y"},
+ )
assert.EqualValues(t, 2, m1.GetHistogram().GetSampleCount(), "%+v", m1)
assert.EqualValues(t, 3, m1.GetHistogram().GetSampleSum(), "%+v", m1)
assert.Len(t, m1.GetHistogram().GetBucket(), 2)
@@ -320,7 +374,12 @@ func TestHistogram(t *testing.T) {
assert.EqualValues(t, "Help message", snapshot[0].GetHelp())
- m1 := findMetric(t, snapshot, "bender_rodriguez", map[string]string{"a": "b", "x": "y"})
+ m1 := findMetric(
+ t,
+ snapshot,
+ "bender_rodriguez",
+ map[string]string{"a": "b", "x": "y"},
+ )
assert.EqualValues(t, 2, m1.GetHistogram().GetSampleCount(), "%+v", m1)
assert.EqualValues(t, 3, m1.GetHistogram().GetSampleSum(), "%+v", m1)
for _, bucket := range m1.GetHistogram().GetBucket() {
@@ -334,7 +393,12 @@ func TestHistogram(t *testing.T) {
}
}
- m2 := findMetric(t, snapshot, "bender_rodriguez", map[string]string{"a": "b", "x": "z"})
+ m2 := findMetric(
+ t,
+ snapshot,
+ "bender_rodriguez",
+ map[string]string{"a": "b", "x": "z"},
+ )
assert.EqualValues(t, 2, m2.GetHistogram().GetSampleCount(), "%+v", m2)
assert.EqualValues(t, 7, m2.GetHistogram().GetSampleSum(), "%+v", m2)
for _, bucket := range m2.GetHistogram().GetBucket() {
@@ -379,7 +443,12 @@ func TestHistogramCustomBuckets(t *testing.T) {
snapshot, err := registry.Gather()
require.NoError(t, err)
- m1 := findMetric(t, snapshot, "bender_bending_rodriguez", map[string]string{"x": "y"})
+ m1 := findMetric(
+ t,
+ snapshot,
+ "bender_bending_rodriguez",
+ map[string]string{"x": "y"},
+ )
assert.EqualValues(t, 2, m1.GetHistogram().GetSampleCount(), "%+v", m1)
assert.EqualValues(t, 3, m1.GetHistogram().GetSampleSum(), "%+v", m1)
assert.Len(t, m1.GetHistogram().GetBucket(), 1)
@@ -387,7 +456,10 @@ func TestHistogramCustomBuckets(t *testing.T) {
func TestHistogramDefaultBuckets(t *testing.T) {
registry := prometheus.NewPedanticRegistry()
- f1 := promMetrics.New(promMetrics.WithRegisterer(registry), promMetrics.WithBuckets([]float64{1.5}))
+ f1 := promMetrics.New(
+ promMetrics.WithRegisterer(registry),
+ promMetrics.WithBuckets([]float64{1.5}),
+ )
// dot and dash in the metric name will be replaced with underscore
t1 := f1.Histogram(metrics.HistogramOptions{
Name: "bender.bending-rodriguez",
@@ -400,20 +472,35 @@ func TestHistogramDefaultBuckets(t *testing.T) {
snapshot, err := registry.Gather()
require.NoError(t, err)
- m1 := findMetric(t, snapshot, "bender_bending_rodriguez", map[string]string{"x": "y"})
+ m1 := findMetric(
+ t,
+ snapshot,
+ "bender_bending_rodriguez",
+ map[string]string{"x": "y"},
+ )
assert.EqualValues(t, 2, m1.GetHistogram().GetSampleCount(), "%+v", m1)
assert.EqualValues(t, 3, m1.GetHistogram().GetSampleSum(), "%+v", m1)
assert.Len(t, m1.GetHistogram().GetBucket(), 1)
}
-func findMetric(t *testing.T, snapshot []*promModel.MetricFamily, name string, tags map[string]string) *promModel.Metric {
+func findMetric(
+ t *testing.T,
+ snapshot []*promModel.MetricFamily,
+ name string,
+ tags map[string]string,
+) *promModel.Metric {
for _, mf := range snapshot {
if mf.GetName() != name {
continue
}
for _, m := range mf.GetMetric() {
if len(m.GetLabel()) != len(tags) {
- t.Fatalf("Mismatching labels for metric %v: want %v, have %v", name, tags, m.GetLabel())
+ t.Fatalf(
+ "Mismatching labels for metric %v: want %v, have %v",
+ name,
+ tags,
+ m.GetLabel(),
+ )
}
match := true
for _, l := range m.GetLabel() {
diff --git a/internal/metricstest/keys.go b/internal/metricstest/keys.go
index 7b7a2dfb5ef..5471916a916 100644
--- a/internal/metricstest/keys.go
+++ b/internal/metricstest/keys.go
@@ -22,7 +22,12 @@ import (
// GetKey converts name+tags into a single string of the form
// "name|tag1=value1|...|tagN=valueN", where tag names are
// sorted alphabetically.
-func GetKey(name string, tags map[string]string, tagsSep string, tagKVSep string) string {
+func GetKey(
+ name string,
+ tags map[string]string,
+ tagsSep string,
+ tagKVSep string,
+) string {
keys := make([]string, 0, len(tags))
for k := range tags {
keys = append(keys, k)
diff --git a/internal/metricstest/local.go b/internal/metricstest/local.go
index 7036b9ae3a7..5ab9832c98d 100644
--- a/internal/metricstest/local.go
+++ b/internal/metricstest/local.go
@@ -123,7 +123,11 @@ func (b *Backend) IncCounter(name string, tags map[string]string, delta int64) {
}
// UpdateGauge updates the value of a gauge
-func (b *Backend) UpdateGauge(name string, tags map[string]string, value int64) {
+func (b *Backend) UpdateGauge(
+ name string,
+ tags map[string]string,
+ value int64,
+) {
name = GetKey(name, tags, b.TagsSep, b.TagKVSep)
b.gm.Lock()
defer b.gm.Unlock()
@@ -137,7 +141,11 @@ func (b *Backend) UpdateGauge(name string, tags map[string]string, value int64)
}
// RecordHistogram records a timing duration
-func (b *Backend) RecordHistogram(name string, tags map[string]string, v float64) {
+func (b *Backend) RecordHistogram(
+ name string,
+ tags map[string]string,
+ v float64,
+) {
name = GetKey(name, tags, b.TagsSep, b.TagKVSep)
histogram := b.findOrCreateHistogram(name)
histogram.Lock()
@@ -153,7 +161,12 @@ func (b *Backend) findOrCreateHistogram(name string) *localBackendHistogram {
}
t := &localBackendHistogram{
- hist: hdrhistogram.NewWindowed(5, 0, int64((5*time.Minute)/time.Millisecond), 1),
+ hist: hdrhistogram.NewWindowed(
+ 5,
+ 0,
+ int64((5*time.Minute)/time.Millisecond),
+ 1,
+ ),
}
b.histograms[name] = t
return t
@@ -165,7 +178,11 @@ type localBackendHistogram struct {
}
// RecordTimer records a timing duration
-func (b *Backend) RecordTimer(name string, tags map[string]string, d time.Duration) {
+func (b *Backend) RecordTimer(
+ name string,
+ tags map[string]string,
+ d time.Duration,
+) {
name = GetKey(name, tags, b.TagsSep, b.TagKVSep)
timer := b.findOrCreateTimer(name)
timer.Lock()
@@ -181,7 +198,12 @@ func (b *Backend) findOrCreateTimer(name string) *localBackendTimer {
}
t := &localBackendTimer{
- hist: hdrhistogram.NewWindowed(5, 0, int64((5*time.Minute)/time.Millisecond), 1),
+ hist: hdrhistogram.NewWindowed(
+ 5,
+ 0,
+ int64((5*time.Minute)/time.Millisecond),
+ 1,
+ ),
}
b.timers[name] = t
return t
@@ -373,7 +395,9 @@ func (l *Factory) Gauge(options metrics.Options) metrics.Gauge {
}
// Histogram returns a local stats histogram.
-func (l *Factory) Histogram(options metrics.HistogramOptions) metrics.Histogram {
+func (l *Factory) Histogram(
+ options metrics.HistogramOptions,
+) metrics.Histogram {
return &localHistogram{
stats{
name: l.newNamespace(options.Name),
diff --git a/internal/metricstest/metricstest.go b/internal/metricstest/metricstest.go
index 530b3985f9e..d0965233a16 100644
--- a/internal/metricstest/metricstest.go
+++ b/internal/metricstest/metricstest.go
@@ -31,24 +31,38 @@ type ExpectedMetric struct {
// TODO do something similar for Timers
// AssertCounterMetrics checks if counter metrics exist.
-func (f *Factory) AssertCounterMetrics(t *testing.T, expectedMetrics ...ExpectedMetric) {
+func (f *Factory) AssertCounterMetrics(
+ t *testing.T,
+ expectedMetrics ...ExpectedMetric,
+) {
counters, _ := f.Snapshot()
assertMetrics(t, counters, expectedMetrics...)
}
// AssertGaugeMetrics checks if gauge metrics exist.
-func (f *Factory) AssertGaugeMetrics(t *testing.T, expectedMetrics ...ExpectedMetric) {
+func (f *Factory) AssertGaugeMetrics(
+ t *testing.T,
+ expectedMetrics ...ExpectedMetric,
+) {
_, gauges := f.Snapshot()
assertMetrics(t, gauges, expectedMetrics...)
}
-func assertMetrics(t *testing.T, actualMetrics map[string]int64, expectedMetrics ...ExpectedMetric) {
+func assertMetrics(
+ t *testing.T,
+ actualMetrics map[string]int64,
+ expectedMetrics ...ExpectedMetric,
+) {
for _, expected := range expectedMetrics {
key := GetKey(expected.Name, expected.Tags, "|", "=")
- assert.EqualValues(t,
+ assert.EqualValues(
+ t,
expected.Value,
actualMetrics[key],
- "expected metric name=%s tags: %+v; got: %+v", expected.Name, expected.Tags, actualMetrics,
+ "expected metric name=%s tags: %+v; got: %+v",
+ expected.Name,
+ expected.Tags,
+ actualMetrics,
)
}
}
diff --git a/internal/metricstest/metricstest_test.go b/internal/metricstest/metricstest_test.go
index c2654a5ee43..f80f26f3411 100644
--- a/internal/metricstest/metricstest_test.go
+++ b/internal/metricstest/metricstest_test.go
@@ -24,6 +24,12 @@ func TestAssertMetrics(t *testing.T) {
f.IncCounter("counter", tags, 1)
f.UpdateGauge("gauge", tags, 11)
- f.AssertCounterMetrics(t, ExpectedMetric{Name: "counter", Tags: tags, Value: 1})
- f.AssertGaugeMetrics(t, ExpectedMetric{Name: "gauge", Tags: tags, Value: 11})
+ f.AssertCounterMetrics(
+ t,
+ ExpectedMetric{Name: "counter", Tags: tags, Value: 1},
+ )
+ f.AssertGaugeMetrics(
+ t,
+ ExpectedMetric{Name: "gauge", Tags: tags, Value: 11},
+ )
}
diff --git a/internal/tracegen/config.go b/internal/tracegen/config.go
index e32d8f22897..437f36d6f4b 100644
--- a/internal/tracegen/config.go
+++ b/internal/tracegen/config.go
@@ -53,11 +53,26 @@ func (c *Config) Flags(fs *flag.FlagSet) {
fs.IntVar(&c.AttrValues, "attr-values", 1000, "Number of distinct values to allow for each attribute")
fs.BoolVar(&c.Debug, "debug", false, "Whether to set DEBUG flag on the spans to force sampling")
fs.BoolVar(&c.Firehose, "firehose", false, "Whether to set FIREHOSE flag on the spans to skip indexing")
- fs.DurationVar(&c.Pause, "pause", time.Microsecond, "How long to sleep before finishing each span. If set to 0s then a fake 123µs duration is used.")
+ fs.DurationVar(
+ &c.Pause,
+ "pause",
+ time.Microsecond,
+ "How long to sleep before finishing each span. If set to 0s then a fake 123µs duration is used.",
+ )
fs.DurationVar(&c.Duration, "duration", 0, "For how long to run the test if greater than 0s (overrides -traces).")
fs.StringVar(&c.Service, "service", "tracegen", "Service name prefix to use")
- fs.IntVar(&c.Services, "services", 1, "Number of unique suffixes to add to service name when generating traces, e.g. tracegen-01 (but only one service per trace)")
- fs.StringVar(&c.TraceExporter, "trace-exporter", "otlp-http", "Trace exporter (otlp/otlp-http|otlp-grpc|stdout). Exporters can be additionally configured via environment variables, see https://github.com/jaegertracing/jaeger/blob/main/cmd/tracegen/README.md")
+ fs.IntVar(
+ &c.Services,
+ "services",
+ 1,
+ "Number of unique suffixes to add to service name when generating traces, e.g. tracegen-01 (but only one service per trace)",
+ )
+ fs.StringVar(
+ &c.TraceExporter,
+ "trace-exporter",
+ "otlp-http",
+ "Trace exporter (otlp/otlp-http|otlp-grpc|stdout). Exporters can be additionally configured via environment variables, see https://github.com/jaegertracing/jaeger/blob/main/cmd/tracegen/README.md",
+ )
}
// Run executes the test scenario.
diff --git a/internal/tracegen/config_test.go b/internal/tracegen/config_test.go
index 4b938531696..747c744f923 100644
--- a/internal/tracegen/config_test.go
+++ b/internal/tracegen/config_test.go
@@ -24,9 +24,11 @@ func Test_Run(t *testing.T) {
expectedErr error
}{
{
- name: "Empty config",
- config: &Config{},
- expectedErr: errors.New("either `traces` or `duration` must be greater than 0"),
+ name: "Empty config",
+ config: &Config{},
+ expectedErr: errors.New(
+ "either `traces` or `duration` must be greater than 0",
+ ),
},
{
name: "Non-empty config",
diff --git a/internal/tracegen/worker.go b/internal/tracegen/worker.go
index 4911f548cd6..b8161276c30 100644
--- a/internal/tracegen/worker.go
+++ b/internal/tracegen/worker.go
@@ -91,7 +91,11 @@ func (w *worker) simulateOneTrace(tracer trace.Tracer) {
}
}
-func (w *worker) simulateChildSpans(ctx context.Context, start time.Time, tracer trace.Tracer) {
+func (w *worker) simulateChildSpans(
+ ctx context.Context,
+ start time.Time,
+ tracer trace.Tracer,
+) {
for c := 0; c < w.ChildSpans; c++ {
var attrs []attribute.KeyValue
for a := 0; a < w.Attributes; a++ {
diff --git a/model/adjuster/adjuster_test.go b/model/adjuster/adjuster_test.go
index 079e16c8f79..e86274bbfb0 100644
--- a/model/adjuster/adjuster_test.go
+++ b/model/adjuster/adjuster_test.go
@@ -50,7 +50,12 @@ func TestSequences(t *testing.T) {
lastSpanID: 2,
},
{
- adjuster: adjuster.FailFastSequence(adj, failingAdj, adj, failingAdj),
+ adjuster: adjuster.FailFastSequence(
+ adj,
+ failingAdj,
+ adj,
+ failingAdj,
+ ),
err: adjErr.Error(),
lastSpanID: 1,
},
@@ -63,7 +68,12 @@ func TestSequences(t *testing.T) {
adjTrace, err := testCase.adjuster.Adjust(&trace)
assert.Equal(t, span, adjTrace.Spans[0], "same trace & span returned")
- assert.EqualValues(t, testCase.lastSpanID, span.SpanID, "expect span ID to be incremented")
+ assert.EqualValues(
+ t,
+ testCase.lastSpanID,
+ span.SpanID,
+ "expect span ID to be incremented",
+ )
require.EqualError(t, err, testCase.err)
}
}
diff --git a/model/adjuster/bad_span_references.go b/model/adjuster/bad_span_references.go
index 1fb05fdec9f..95b7a35fba9 100644
--- a/model/adjuster/bad_span_references.go
+++ b/model/adjuster/bad_span_references.go
@@ -48,7 +48,13 @@ func (s spanReferenceAdjuster) adjust(span *model.Span) *model.Span {
references := make([]model.SpanRef, 0, len(span.References)-1)
for i := range span.References {
if !s.valid(&span.References[i]) {
- span.Warnings = append(span.Warnings, fmt.Sprintf("Invalid span reference removed %+v", span.References[i]))
+ span.Warnings = append(
+ span.Warnings,
+ fmt.Sprintf(
+ "Invalid span reference removed %+v",
+ span.References[i],
+ ),
+ )
continue
}
references = append(references, span.References[i])
diff --git a/model/adjuster/bad_span_references_test.go b/model/adjuster/bad_span_references_test.go
index 8b0e5881ab1..b6b8816c1b1 100644
--- a/model/adjuster/bad_span_references_test.go
+++ b/model/adjuster/bad_span_references_test.go
@@ -45,5 +45,9 @@ func TestSpanReferencesAdjuster(t *testing.T) {
assert.Empty(t, trace.Spans[0].References)
assert.Empty(t, trace.Spans[1].References)
assert.Len(t, trace.Spans[2].References, 2)
- assert.Contains(t, trace.Spans[2].Warnings[0], "Invalid span reference removed")
+ assert.Contains(
+ t,
+ trace.Spans[2].Warnings[0],
+ "Invalid span reference removed",
+ )
}
diff --git a/model/adjuster/clockskew.go b/model/adjuster/clockskew.go
index cb656093f7c..edf9fc8ab21 100644
--- a/model/adjuster/clockskew.go
+++ b/model/adjuster/clockskew.go
@@ -149,7 +149,10 @@ func (a *clockSkewAdjuster) adjustNode(n *node, parent *node, skew clockSkew) {
}
}
-func (*clockSkewAdjuster) calculateSkew(child *node, parent *node) time.Duration {
+func (*clockSkewAdjuster) calculateSkew(
+ child *node,
+ parent *node,
+) time.Duration {
parentDuration := parent.span.Duration
childDuration := child.span.Duration
parentEndTime := parent.span.StartTime.Add(parent.span.Duration)
@@ -165,7 +168,8 @@ func (*clockSkewAdjuster) calculateSkew(child *node, parent *node) time.Duration
}
return 0
}
- if !child.span.StartTime.Before(parent.span.StartTime) && !childEndTime.After(parentEndTime) {
+ if !child.span.StartTime.Before(parent.span.StartTime) &&
+ !childEndTime.After(parentEndTime) {
// child already fits within the parent span, do not adjust
return 0
}
@@ -182,16 +186,25 @@ func (a *clockSkewAdjuster) adjustTimestamps(n *node, skew clockSkew) {
if absDuration(skew.delta) > a.maxDelta {
if a.maxDelta == 0 {
- n.span.Warnings = append(n.span.Warnings, fmt.Sprintf(warningSkewAdjustDisabled, skew.delta))
+ n.span.Warnings = append(
+ n.span.Warnings,
+ fmt.Sprintf(warningSkewAdjustDisabled, skew.delta),
+ )
return
}
- n.span.Warnings = append(n.span.Warnings, fmt.Sprintf(warningMaxDeltaExceeded, a.maxDelta, skew.delta))
+ n.span.Warnings = append(
+ n.span.Warnings,
+ fmt.Sprintf(warningMaxDeltaExceeded, a.maxDelta, skew.delta),
+ )
return
}
n.span.StartTime = n.span.StartTime.Add(skew.delta)
- n.span.Warnings = append(n.span.Warnings, fmt.Sprintf("This span's timestamps were adjusted by %v", skew.delta))
+ n.span.Warnings = append(
+ n.span.Warnings,
+ fmt.Sprintf("This span's timestamps were adjusted by %v", skew.delta),
+ )
for i := range n.span.Logs {
n.span.Logs[i].Timestamp = n.span.Logs[i].Timestamp.Add(skew.delta)
diff --git a/model/adjuster/clockskew_test.go b/model/adjuster/clockskew_test.go
index 56cd906fe64..4075a73c239 100644
--- a/model/adjuster/clockskew_test.go
+++ b/model/adjuster/clockskew_test.go
@@ -51,17 +51,24 @@ func TestClockSkewAdjuster(t *testing.T) {
for _, log := range spanProto.logs {
logs = append(logs, model.Log{
Timestamp: toTime(log),
- Fields: []model.KeyValue{model.String("event", "some event")},
+ Fields: []model.KeyValue{
+ model.String("event", "some event"),
+ },
})
}
traceID := model.NewTraceID(0, 1)
span := &model.Span{
- TraceID: traceID,
- SpanID: model.NewSpanID(uint64(spanProto.id)),
- References: []model.SpanRef{model.NewChildOfRef(traceID, model.NewSpanID(uint64(spanProto.parent)))},
- StartTime: toTime(spanProto.startTime),
- Duration: toDuration(spanProto.duration),
- Logs: logs,
+ TraceID: traceID,
+ SpanID: model.NewSpanID(uint64(spanProto.id)),
+ References: []model.SpanRef{
+ model.NewChildOfRef(
+ traceID,
+ model.NewSpanID(uint64(spanProto.parent)),
+ ),
+ },
+ StartTime: toTime(spanProto.startTime),
+ Duration: toDuration(spanProto.duration),
+ Logs: logs,
Process: &model.Process{
ServiceName: spanProto.host,
Tags: []model.KeyValue{
@@ -83,7 +90,14 @@ func TestClockSkewAdjuster(t *testing.T) {
{
description: "single span with bad parent",
trace: []spanProto{
- {id: 1, parent: 99, startTime: 0, duration: 100, host: "a", adjusted: 0},
+ {
+ id: 1,
+ parent: 99,
+ startTime: 0,
+ duration: 100,
+ host: "a",
+ adjusted: 0,
+ },
},
err: "invalid parent span IDs=0000000000000063; skipping clock skew adjustment", // 99 == 0x63
},
@@ -96,44 +110,128 @@ func TestClockSkewAdjuster(t *testing.T) {
{
description: "two spans with the same ID",
trace: []spanProto{
- {id: 1, parent: 0, startTime: 0, duration: 100, host: "a", adjusted: 0},
- {id: 1, parent: 0, startTime: 0, duration: 100, host: "a", adjusted: 0},
+ {
+ id: 1,
+ parent: 0,
+ startTime: 0,
+ duration: 100,
+ host: "a",
+ adjusted: 0,
+ },
+ {
+ id: 1,
+ parent: 0,
+ startTime: 0,
+ duration: 100,
+ host: "a",
+ adjusted: 0,
+ },
},
err: "duplicate span IDs; skipping clock skew adjustment",
},
{
description: "parent-child on the same host",
trace: []spanProto{
- {id: 1, parent: 0, startTime: 0, duration: 100, host: "a", adjusted: 0},
- {id: 2, parent: 1, startTime: 10, duration: 50, host: "a", adjusted: 10},
+ {
+ id: 1,
+ parent: 0,
+ startTime: 0,
+ duration: 100,
+ host: "a",
+ adjusted: 0,
+ },
+ {
+ id: 2,
+ parent: 1,
+ startTime: 10,
+ duration: 50,
+ host: "a",
+ adjusted: 10,
+ },
},
},
{
description: "do not adjust parent-child on the same host",
trace: []spanProto{
- {id: 1, parent: 0, startTime: 10, duration: 100, host: "a", adjusted: 10},
- {id: 2, parent: 1, startTime: 0, duration: 50, host: "a", adjusted: 0},
+ {
+ id: 1,
+ parent: 0,
+ startTime: 10,
+ duration: 100,
+ host: "a",
+ adjusted: 10,
+ },
+ {
+ id: 2,
+ parent: 1,
+ startTime: 0,
+ duration: 50,
+ host: "a",
+ adjusted: 0,
+ },
},
},
{
description: "do not adjust child that fits inside parent",
trace: []spanProto{
- {id: 1, parent: 0, startTime: 10, duration: 100, host: "a", adjusted: 10},
- {id: 2, parent: 1, startTime: 20, duration: 50, host: "b", adjusted: 20},
+ {
+ id: 1,
+ parent: 0,
+ startTime: 10,
+ duration: 100,
+ host: "a",
+ adjusted: 10,
+ },
+ {
+ id: 2,
+ parent: 1,
+ startTime: 20,
+ duration: 50,
+ host: "b",
+ adjusted: 20,
+ },
},
},
{
description: "do not adjust child that is longer than parent",
trace: []spanProto{
- {id: 1, parent: 0, startTime: 10, duration: 100, host: "a", adjusted: 10},
- {id: 2, parent: 1, startTime: 20, duration: 150, host: "b", adjusted: 20},
+ {
+ id: 1,
+ parent: 0,
+ startTime: 10,
+ duration: 100,
+ host: "a",
+ adjusted: 10,
+ },
+ {
+ id: 2,
+ parent: 1,
+ startTime: 20,
+ duration: 150,
+ host: "b",
+ adjusted: 20,
+ },
},
},
{
description: "do not apply positive adjustment due to max skew adjustment",
trace: []spanProto{
- {id: 1, parent: 0, startTime: 10, duration: 100, host: "a", adjusted: 10},
- {id: 2, parent: 1, startTime: 0, duration: 50, host: "b", adjusted: 0},
+ {
+ id: 1,
+ parent: 0,
+ startTime: 10,
+ duration: 100,
+ host: "a",
+ adjusted: 10,
+ },
+ {
+ id: 2,
+ parent: 1,
+ startTime: 0,
+ duration: 50,
+ host: "b",
+ adjusted: 0,
+ },
},
maxAdjust: 10 * time.Millisecond,
err: "max clock skew adjustment delta of 10ms exceeded; not applying calculated delta of 35ms",
@@ -141,8 +239,22 @@ func TestClockSkewAdjuster(t *testing.T) {
{
description: "do not apply negative adjustment due to max skew adjustment",
trace: []spanProto{
- {id: 1, parent: 0, startTime: 10, duration: 100, host: "a", adjusted: 10},
- {id: 2, parent: 1, startTime: 80, duration: 50, host: "b", adjusted: 80},
+ {
+ id: 1,
+ parent: 0,
+ startTime: 10,
+ duration: 100,
+ host: "a",
+ adjusted: 10,
+ },
+ {
+ id: 2,
+ parent: 1,
+ startTime: 80,
+ duration: 50,
+ host: "b",
+ adjusted: 80,
+ },
},
maxAdjust: 10 * time.Millisecond,
err: "max clock skew adjustment delta of 10ms exceeded; not applying calculated delta of -45ms",
@@ -150,15 +262,36 @@ func TestClockSkewAdjuster(t *testing.T) {
{
description: "do not apply adjustment due to disabled adjustment",
trace: []spanProto{
- {id: 1, parent: 0, startTime: 10, duration: 100, host: "a", adjusted: 10},
- {id: 2, parent: 1, startTime: 0, duration: 50, host: "b", adjusted: 0},
+ {
+ id: 1,
+ parent: 0,
+ startTime: 10,
+ duration: 100,
+ host: "a",
+ adjusted: 10,
+ },
+ {
+ id: 2,
+ parent: 1,
+ startTime: 0,
+ duration: 50,
+ host: "b",
+ adjusted: 0,
+ },
},
err: "clock skew adjustment disabled; not applying calculated delta of 35ms",
},
{
description: "adjust child starting before parent",
trace: []spanProto{
- {id: 1, parent: 0, startTime: 10, duration: 100, host: "a", adjusted: 10},
+ {
+ id: 1,
+ parent: 0,
+ startTime: 10,
+ duration: 100,
+ host: "a",
+ adjusted: 10,
+ },
// latency = (100-50) / 2 = 25
// delta = (10 - 0) + latency = 35
{
@@ -171,18 +304,46 @@ func TestClockSkewAdjuster(t *testing.T) {
{
description: "adjust child starting before parent even if it is longer",
trace: []spanProto{
- {id: 1, parent: 0, startTime: 10, duration: 100, host: "a", adjusted: 10},
- {id: 2, parent: 1, startTime: 0, duration: 150, host: "b", adjusted: 10},
+ {
+ id: 1,
+ parent: 0,
+ startTime: 10,
+ duration: 100,
+ host: "a",
+ adjusted: 10,
+ },
+ {
+ id: 2,
+ parent: 1,
+ startTime: 0,
+ duration: 150,
+ host: "b",
+ adjusted: 10,
+ },
},
maxAdjust: time.Second,
},
{
description: "adjust child ending after parent but being shorter",
trace: []spanProto{
- {id: 1, parent: 0, startTime: 10, duration: 100, host: "a", adjusted: 10},
+ {
+ id: 1,
+ parent: 0,
+ startTime: 10,
+ duration: 100,
+ host: "a",
+ adjusted: 10,
+ },
// latency: (100 - 70) / 2 = 15
// new child start time: 10 + latency = 25, delta = -25
- {id: 2, parent: 1, startTime: 50, duration: 70, host: "b", adjusted: 25},
+ {
+ id: 2,
+ parent: 1,
+ startTime: 50,
+ duration: 70,
+ host: "b",
+ adjusted: 25,
+ },
// same host 'b', so same delta = -25
// new start time: 60 + delta = 35
{
@@ -227,8 +388,13 @@ func TestClockSkewAdjuster(t *testing.T) {
"adjusted start time of span[ID = %d]", id)
for i, logTs := range proto.adjustedLogs {
assert.Equal(
- t, toTime(logTs), span.Logs[i].Timestamp,
- "adjusted log timestamp of span[ID = %d], log[%d]", id, i)
+ t,
+ toTime(logTs),
+ span.Logs[i].Timestamp,
+ "adjusted log timestamp of span[ID = %d], log[%d]",
+ id,
+ i,
+ )
}
}
})
@@ -244,8 +410,20 @@ func TestHostKey(t *testing.T) {
{tag: model.String("ipv4", "1.2.3.4"), hostKey: ""},
{tag: model.Int64("ip", int64(1<<24|2<<16|3<<8|4)), hostKey: "1.2.3.4"},
{tag: model.Binary("ip", []byte{1, 2, 3, 4}), hostKey: "1.2.3.4"},
- {tag: model.Binary("ip", []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, 1, 2, 3, 4}), hostKey: "1.2.3.4"},
- {tag: model.Binary("ip", []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4}), hostKey: "::102:304"},
+ {
+ tag: model.Binary(
+ "ip",
+ []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, 1, 2, 3, 4},
+ ),
+ hostKey: "1.2.3.4",
+ },
+ {
+ tag: model.Binary(
+ "ip",
+ []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4},
+ ),
+ hostKey: "::102:304",
+ },
{tag: model.Binary("ip", []byte{1, 2, 3, 4, 5}), hostKey: ""},
{tag: model.Float64("ip", 123.4), hostKey: ""},
}
diff --git a/model/adjuster/ip_tag_test.go b/model/adjuster/ip_tag_test.go
index f3984ad2e40..eee2fe718ce 100644
--- a/model/adjuster/ip_tag_test.go
+++ b/model/adjuster/ip_tag_test.go
@@ -66,5 +66,9 @@ func TestIPTagAdjuster(t *testing.T) {
model.String("ip", "1.2.3.4"), // sorted
model.String("ip", "not integer"),
}
- assert.Equal(t, expectedProcessTags, model.KeyValues(trace.Spans[0].Process.Tags))
+ assert.Equal(
+ t,
+ expectedProcessTags,
+ model.KeyValues(trace.Spans[0].Process.Tags),
+ )
}
diff --git a/model/adjuster/otel_tag_test.go b/model/adjuster/otel_tag_test.go
index 95bd37333ca..2c12284274e 100644
--- a/model/adjuster/otel_tag_test.go
+++ b/model/adjuster/otel_tag_test.go
@@ -35,7 +35,10 @@ func TestOTelTagAdjuster(t *testing.T) {
span: &model.Span{
Tags: model.KeyValues{
model.String("random_key", "random_value"),
- model.String(string(semconv.OTelLibraryNameKey), "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"),
+ model.String(
+ string(semconv.OTelLibraryNameKey),
+ "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp",
+ ),
model.String(string(semconv.OTelLibraryVersionKey), "0.45.0"),
model.String("another_key", "another_value"),
},
@@ -50,7 +53,10 @@ func TestOTelTagAdjuster(t *testing.T) {
},
Process: &model.Process{
Tags: model.KeyValues{
- model.String(string(semconv.OTelLibraryNameKey), "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"),
+ model.String(
+ string(semconv.OTelLibraryNameKey),
+ "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp",
+ ),
model.String(string(semconv.OTelLibraryVersionKey), "0.45.0"),
},
},
@@ -86,11 +92,20 @@ func TestOTelTagAdjuster(t *testing.T) {
trace, err := OTelTagAdjuster().Adjust(trace)
require.NoError(t, err)
assert.Equal(t, testCase.expected.Tags, trace.Spans[0].Tags)
- assert.Equal(t, testCase.expected.Process.Tags, trace.Spans[0].Process.Tags)
+ assert.Equal(
+ t,
+ testCase.expected.Process.Tags,
+ trace.Spans[0].Process.Tags,
+ )
newTag := model.String("new_key", "new_value")
beforeTags[0] = newTag
- assert.Equal(t, newTag, testCase.span.Tags[0], "span.Tags still points to the same underlying array")
+ assert.Equal(
+ t,
+ newTag,
+ testCase.span.Tags[0],
+ "span.Tags still points to the same underlying array",
+ )
})
}
}
diff --git a/model/adjuster/parent_reference_test.go b/model/adjuster/parent_reference_test.go
index bf53ed2765d..51f2a029afd 100644
--- a/model/adjuster/parent_reference_test.go
+++ b/model/adjuster/parent_reference_test.go
@@ -77,9 +77,17 @@ func TestParentReference(t *testing.T) {
expected: []model.SpanRef{childOf(a), followsFrom(b)},
},
{
- name: "remote, local, local follows - keep order",
- incoming: []model.SpanRef{followsFrom(b), followsFrom2(a), followsFrom(a)},
- expected: []model.SpanRef{followsFrom2(a), followsFrom(b), followsFrom(a)},
+ name: "remote, local, local follows - keep order",
+ incoming: []model.SpanRef{
+ followsFrom(b),
+ followsFrom2(a),
+ followsFrom(a),
+ },
+ expected: []model.SpanRef{
+ followsFrom2(a),
+ followsFrom(b),
+ followsFrom(a),
+ },
},
{
name: "remote child, local follows",
@@ -92,9 +100,17 @@ func TestParentReference(t *testing.T) {
expected: []model.SpanRef{childOf(a), followsFrom(a), childOf(b)},
},
{
- name: "remote follows, local follows, local child",
- incoming: []model.SpanRef{followsFrom(b), followsFrom(a), childOf(a)},
- expected: []model.SpanRef{childOf(a), followsFrom(a), followsFrom(b)},
+ name: "remote follows, local follows, local child",
+ incoming: []model.SpanRef{
+ followsFrom(b),
+ followsFrom(a),
+ childOf(a),
+ },
+ expected: []model.SpanRef{
+ childOf(a),
+ followsFrom(a),
+ followsFrom(b),
+ },
},
}
for _, testCase := range testCases {
diff --git a/model/adjuster/sort_log_fields_test.go b/model/adjuster/sort_log_fields_test.go
index 2a5b6841a8c..7edb77e1d0f 100644
--- a/model/adjuster/sort_log_fields_test.go
+++ b/model/adjuster/sort_log_fields_test.go
@@ -31,7 +31,10 @@ func TestSortLogFields(t *testing.T) {
}{
{
fields: model.KeyValues{
- model.String("event", "some event"), // event already in the first position, and no other fields
+ model.String(
+ "event",
+ "some event",
+ ), // event already in the first position, and no other fields
},
expected: model.KeyValues{
model.String("event", "some event"),
@@ -92,6 +95,10 @@ func TestSortLogFields(t *testing.T) {
}
trace, err := SortLogFields().Adjust(trace)
require.NoError(t, err)
- assert.Equal(t, testCase.expected, model.KeyValues(trace.Spans[0].Logs[0].Fields))
+ assert.Equal(
+ t,
+ testCase.expected,
+ model.KeyValues(trace.Spans[0].Logs[0].Fields),
+ )
}
}
diff --git a/model/adjuster/span_id_deduper.go b/model/adjuster/span_id_deduper.go
index 03f9b987cd0..e4e2e23816d 100644
--- a/model/adjuster/span_id_deduper.go
+++ b/model/adjuster/span_id_deduper.go
@@ -85,7 +85,9 @@ func (d *spanIDDeduper) dedupeSpanIDs() {
continue
}
oldToNewSpanIDs[span.SpanID] = newID
- span.ReplaceParentID(span.SpanID) // previously shared ID is the new parent
+ span.ReplaceParentID(
+ span.SpanID,
+ ) // previously shared ID is the new parent
span.SpanID = newID
}
}
@@ -94,7 +96,9 @@ func (d *spanIDDeduper) dedupeSpanIDs() {
// swapParentIDs corrects ParentSpanID of all spans that are children of the server
// spans whose IDs we deduped.
-func (d *spanIDDeduper) swapParentIDs(oldToNewSpanIDs map[model.SpanID]model.SpanID) {
+func (d *spanIDDeduper) swapParentIDs(
+ oldToNewSpanIDs map[model.SpanID]model.SpanID,
+) {
for _, span := range d.trace.Spans {
if parentID, ok := oldToNewSpanIDs[span.ParentSpanID()]; ok {
if span.SpanID != parentID {
diff --git a/model/adjuster/span_id_deduper_test.go b/model/adjuster/span_id_deduper_test.go
index 0dc86433263..eb91f061dd1 100644
--- a/model/adjuster/span_id_deduper_test.go
+++ b/model/adjuster/span_id_deduper_test.go
@@ -55,9 +55,11 @@ func newTrace() *model.Trace {
},
{
// some other span, child of server span
- TraceID: traceID,
- SpanID: anotherSpanID,
- References: []model.SpanRef{model.NewChildOfRef(traceID, clientSpanID)},
+ TraceID: traceID,
+ SpanID: anotherSpanID,
+ References: []model.SpanRef{
+ model.NewChildOfRef(traceID, clientSpanID),
+ },
},
},
}
@@ -70,15 +72,40 @@ func TestSpanIDDeduperTriggered(t *testing.T) {
require.NoError(t, err)
clientSpan := trace.Spans[0]
- assert.Equal(t, clientSpanID, clientSpan.SpanID, "client span ID should not change")
+ assert.Equal(
+ t,
+ clientSpanID,
+ clientSpan.SpanID,
+ "client span ID should not change",
+ )
serverSpan := trace.Spans[1]
- assert.Equal(t, clientSpanID+1, serverSpan.SpanID, "server span ID should be reassigned")
- assert.Equal(t, clientSpan.SpanID, serverSpan.ParentSpanID(), "client span should be server span's parent")
+ assert.Equal(
+ t,
+ clientSpanID+1,
+ serverSpan.SpanID,
+ "server span ID should be reassigned",
+ )
+ assert.Equal(
+ t,
+ clientSpan.SpanID,
+ serverSpan.ParentSpanID(),
+ "client span should be server span's parent",
+ )
thirdSpan := trace.Spans[2]
- assert.Equal(t, anotherSpanID, thirdSpan.SpanID, "3rd span ID should not change")
- assert.Equal(t, serverSpan.SpanID, thirdSpan.ParentSpanID(), "server span should be 3rd span's parent")
+ assert.Equal(
+ t,
+ anotherSpanID,
+ thirdSpan.SpanID,
+ "3rd span ID should not change",
+ )
+ assert.Equal(
+ t,
+ serverSpan.SpanID,
+ thirdSpan.ParentSpanID(),
+ "server span should be 3rd span's parent",
+ )
}
func TestSpanIDDeduperNotTriggered(t *testing.T) {
@@ -91,24 +118,48 @@ func TestSpanIDDeduperNotTriggered(t *testing.T) {
serverSpanID := clientSpanID // for better readability
serverSpan := trace.Spans[0]
- assert.Equal(t, serverSpanID, serverSpan.SpanID, "server span ID should be unchanged")
+ assert.Equal(
+ t,
+ serverSpanID,
+ serverSpan.SpanID,
+ "server span ID should be unchanged",
+ )
thirdSpan := trace.Spans[1]
- assert.Equal(t, anotherSpanID, thirdSpan.SpanID, "3rd span ID should not change")
- assert.Equal(t, serverSpan.SpanID, thirdSpan.ParentSpanID(), "server span should be 3rd span's parent")
+ assert.Equal(
+ t,
+ anotherSpanID,
+ thirdSpan.SpanID,
+ "3rd span ID should not change",
+ )
+ assert.Equal(
+ t,
+ serverSpan.SpanID,
+ thirdSpan.ParentSpanID(),
+ "server span should be 3rd span's parent",
+ )
}
func TestSpanIDDeduperError(t *testing.T) {
trace := newTrace()
maxID := int64(-1)
- assert.Equal(t, maxSpanID, model.NewSpanID(uint64(maxID)), "maxSpanID must be 2^64-1")
+ assert.Equal(
+ t,
+ maxSpanID,
+ model.NewSpanID(uint64(maxID)),
+ "maxSpanID must be 2^64-1",
+ )
deduper := &spanIDDeduper{trace: trace}
deduper.groupSpansByID()
deduper.maxUsedID = maxSpanID - 1
deduper.dedupeSpanIDs()
if assert.Len(t, trace.Spans[1].Warnings, 1) {
- assert.Equal(t, "cannot assign unique span ID, too many spans in the trace", trace.Spans[1].Warnings[0])
+ assert.Equal(
+ t,
+ "cannot assign unique span ID, too many spans in the trace",
+ trace.Spans[1].Warnings[0],
+ )
}
}
diff --git a/model/converter/json/from_domain.go b/model/converter/json/from_domain.go
index 677f96bb386..b9fbd665e68 100644
--- a/model/converter/json/from_domain.go
+++ b/model/converter/json/from_domain.go
@@ -82,7 +82,10 @@ func (fd fromDomain) convertSpanInternal(span *model.Span) json.Span {
}
}
-func (fd fromDomain) convertSpan(span *model.Span, processID json.ProcessID) json.Span {
+func (fd fromDomain) convertSpan(
+ span *model.Span,
+ processID json.ProcessID,
+) json.Span {
s := fd.convertSpanInternal(span)
s.ProcessID = processID
s.Warnings = span.Warnings
@@ -146,7 +149,9 @@ func (fromDomain) convertKeyValues(keyValues model.KeyValues) []json.KeyValue {
return out
}
-func (fromDomain) convertKeyValuesString(keyValues model.KeyValues) []json.KeyValue {
+func (fromDomain) convertKeyValuesString(
+ keyValues model.KeyValues,
+) []json.KeyValue {
out := make([]json.KeyValue, len(keyValues))
for i, kv := range keyValues {
out[i] = json.KeyValue{
@@ -169,7 +174,9 @@ func (fd fromDomain) convertLogs(logs []model.Log) []json.Log {
return out
}
-func (fd fromDomain) convertProcesses(processes map[string]*model.Process) map[json.ProcessID]json.Process {
+func (fd fromDomain) convertProcesses(
+ processes map[string]*model.Process,
+) map[json.ProcessID]json.Process {
out := make(map[json.ProcessID]json.Process)
for key, process := range processes {
out[json.ProcessID(key)] = fd.convertProcess(process)
@@ -185,7 +192,9 @@ func (fd fromDomain) convertProcess(process *model.Process) json.Process {
}
// DependenciesFromDomain converts []model.DependencyLink into []json.DependencyLink format.
-func DependenciesFromDomain(dependencyLinks []model.DependencyLink) []json.DependencyLink {
+func DependenciesFromDomain(
+ dependencyLinks []model.DependencyLink,
+) []json.DependencyLink {
retMe := make([]json.DependencyLink, 0, len(dependencyLinks))
for _, dependencyLink := range dependencyLinks {
retMe = append(
diff --git a/model/converter/json/from_domain_test.go b/model/converter/json/from_domain_test.go
index 7d507caf894..be5499db561 100644
--- a/model/converter/json/from_domain_test.go
+++ b/model/converter/json/from_domain_test.go
@@ -125,7 +125,13 @@ func loadFixtures(t *testing.T, i int, processEmbedded bool) ([]byte, []byte) {
return inStr, outStr
}
-func testJSONEncoding(t *testing.T, i int, expectedStr []byte, object any, processEmbedded bool) {
+func testJSONEncoding(
+ t *testing.T,
+ i int,
+ expectedStr []byte,
+ object any,
+ processEmbedded bool,
+) {
buf := &bytes.Buffer{}
enc := json.NewEncoder(buf)
enc.SetIndent("", " ")
diff --git a/model/converter/json/json_span_compare_test.go b/model/converter/json/json_span_compare_test.go
index 9ff632ad09a..4a7e8bac9f6 100644
--- a/model/converter/json/json_span_compare_test.go
+++ b/model/converter/json/json_span_compare_test.go
@@ -27,7 +27,11 @@ import (
esJson "github.com/jaegertracing/jaeger/model/json"
)
-func CompareJSONSpans(t *testing.T, expected *esJson.Span, actual *esJson.Span) {
+func CompareJSONSpans(
+ t *testing.T,
+ expected *esJson.Span,
+ actual *esJson.Span,
+) {
sortJSONSpan(expected)
sortJSONSpan(actual)
@@ -59,9 +63,14 @@ func sortJSONTags(tags []esJson.KeyValue) {
type JSONLogByTimestamp []esJson.Log
-func (t JSONLogByTimestamp) Len() int { return len(t) }
-func (t JSONLogByTimestamp) Swap(i, j int) { t[i], t[j] = t[j], t[i] }
-func (t JSONLogByTimestamp) Less(i, j int) bool { return t[i].Timestamp < t[j].Timestamp }
+func (t JSONLogByTimestamp) Len() int { return len(t) }
+func (t JSONLogByTimestamp) Swap(i, j int) { t[i], t[j] = t[j], t[i] }
+
+func (t JSONLogByTimestamp) Less(
+ i, j int,
+) bool {
+ return t[i].Timestamp < t[j].Timestamp
+}
func sortJSONLogs(logs []esJson.Log) {
sort.Sort(JSONLogByTimestamp(logs))
diff --git a/model/converter/json/sampling.go b/model/converter/json/sampling.go
index b124114b6a5..c19b0527d41 100644
--- a/model/converter/json/sampling.go
+++ b/model/converter/json/sampling.go
@@ -25,7 +25,9 @@ import (
// SamplingStrategyResponseToJSON defines the official way to generate
// a JSON response from /sampling endpoints.
-func SamplingStrategyResponseToJSON(protoObj *api_v2.SamplingStrategyResponse) (string, error) {
+func SamplingStrategyResponseToJSON(
+ protoObj *api_v2.SamplingStrategyResponse,
+) (string, error) {
// For backwards compatibility with Thrift-to-JSON encoding,
// we want the output to include "strategyType":"PROBABILISTIC" when appropriate.
// However, due to design oversight, the enum value for PROBABILISTIC is 0, so
@@ -49,7 +51,9 @@ func SamplingStrategyResponseToJSON(protoObj *api_v2.SamplingStrategyResponse) (
}
// SamplingStrategyResponseFromJSON is the official way to parse strategy in JSON.
-func SamplingStrategyResponseFromJSON(json []byte) (*api_v2.SamplingStrategyResponse, error) {
+func SamplingStrategyResponseFromJSON(
+ json []byte,
+) (*api_v2.SamplingStrategyResponse, error) {
var obj api_v2.SamplingStrategyResponse
if err := jsonpb.Unmarshal(bytes.NewReader(json), &obj); err != nil {
return nil, err
diff --git a/model/converter/json/sampling_test.go b/model/converter/json/sampling_test.go
index dede2aad91e..57782ec2838 100644
--- a/model/converter/json/sampling_test.go
+++ b/model/converter/json/sampling_test.go
@@ -79,7 +79,10 @@ func TestSamplingStrategyResponseToJSON(t *testing.T) {
})
}
-func compareProtoAndThriftJSON(t *testing.T, thriftObj *api_v1.SamplingStrategyResponse) {
+func compareProtoAndThriftJSON(
+ t *testing.T,
+ thriftObj *api_v1.SamplingStrategyResponse,
+) {
protoObj, err := thriftconv.ConvertSamplingResponseToDomain(thriftObj)
require.NoError(t, err)
@@ -108,5 +111,9 @@ func TestSamplingStrategyResponseFromJSON(t *testing.T) {
s2, err := SamplingStrategyResponseFromJSON([]byte(json))
require.NoError(t, err)
assert.Equal(t, s1.GetStrategyType(), s2.GetStrategyType())
- assert.EqualValues(t, s1.GetProbabilisticSampling(), s2.GetProbabilisticSampling())
+ assert.EqualValues(
+ t,
+ s1.GetProbabilisticSampling(),
+ s2.GetProbabilisticSampling(),
+ )
}
diff --git a/model/converter/thrift/jaeger/from_domain.go b/model/converter/thrift/jaeger/from_domain.go
index 6f8b85863d9..f4b7331e669 100644
--- a/model/converter/thrift/jaeger/from_domain.go
+++ b/model/converter/thrift/jaeger/from_domain.go
@@ -100,7 +100,9 @@ func (domainToJaegerTransformer) keyValueToTag(kv *model.KeyValue) *jaeger.Tag {
return errTag
}
-func (d domainToJaegerTransformer) convertKeyValuesToTags(kvs model.KeyValues) []*jaeger.Tag {
+func (d domainToJaegerTransformer) convertKeyValuesToTags(
+ kvs model.KeyValues,
+) []*jaeger.Tag {
jaegerTags := make([]*jaeger.Tag, len(kvs))
for idx, kv := range kvs {
jaegerTags[idx] = d.keyValueToTag(&kv)
@@ -119,7 +121,9 @@ func (d domainToJaegerTransformer) convertLogs(logs []model.Log) []*jaeger.Log {
return jaegerLogs
}
-func (domainToJaegerTransformer) convertSpanRefs(refs []model.SpanRef) []*jaeger.SpanRef {
+func (domainToJaegerTransformer) convertSpanRefs(
+ refs []model.SpanRef,
+) []*jaeger.SpanRef {
jaegerSpanRefs := make([]*jaeger.SpanRef, len(refs))
for idx, ref := range refs {
jaegerSpanRefs[idx] = &jaeger.SpanRef{
@@ -132,7 +136,9 @@ func (domainToJaegerTransformer) convertSpanRefs(refs []model.SpanRef) []*jaeger
return jaegerSpanRefs
}
-func (d domainToJaegerTransformer) transformSpan(span *model.Span) *jaeger.Span {
+func (d domainToJaegerTransformer) transformSpan(
+ span *model.Span,
+) *jaeger.Span {
tags := d.convertKeyValuesToTags(span.Tags)
logs := d.convertLogs(span.Logs)
refs := d.convertSpanRefs(span.References)
diff --git a/model/converter/thrift/jaeger/sampling_from_domain.go b/model/converter/thrift/jaeger/sampling_from_domain.go
index c776072cd19..44fd3f2d1f0 100644
--- a/model/converter/thrift/jaeger/sampling_from_domain.go
+++ b/model/converter/thrift/jaeger/sampling_from_domain.go
@@ -23,7 +23,9 @@ import (
)
// ConvertSamplingResponseFromDomain converts proto sampling response to its thrift representation.
-func ConvertSamplingResponseFromDomain(r *api_v2.SamplingStrategyResponse) (*sampling.SamplingStrategyResponse, error) {
+func ConvertSamplingResponseFromDomain(
+ r *api_v2.SamplingStrategyResponse,
+) (*sampling.SamplingStrategyResponse, error) {
typ, err := convertStrategyTypeFromDomain(r.GetStrategyType())
if err != nil {
return nil, err
@@ -33,32 +35,46 @@ func ConvertSamplingResponseFromDomain(r *api_v2.SamplingStrategyResponse) (*sam
return nil, err
}
thriftResp := &sampling.SamplingStrategyResponse{
- StrategyType: typ,
- ProbabilisticSampling: convertProbabilisticFromDomain(r.GetProbabilisticSampling()),
- RateLimitingSampling: rl,
- OperationSampling: convertPerOperationFromDomain(r.GetOperationSampling()),
+ StrategyType: typ,
+ ProbabilisticSampling: convertProbabilisticFromDomain(
+ r.GetProbabilisticSampling(),
+ ),
+ RateLimitingSampling: rl,
+ OperationSampling: convertPerOperationFromDomain(
+ r.GetOperationSampling(),
+ ),
}
return thriftResp, nil
}
-func convertProbabilisticFromDomain(s *api_v2.ProbabilisticSamplingStrategy) *sampling.ProbabilisticSamplingStrategy {
+func convertProbabilisticFromDomain(
+ s *api_v2.ProbabilisticSamplingStrategy,
+) *sampling.ProbabilisticSamplingStrategy {
if s == nil {
return nil
}
- return &sampling.ProbabilisticSamplingStrategy{SamplingRate: s.GetSamplingRate()}
+ return &sampling.ProbabilisticSamplingStrategy{
+ SamplingRate: s.GetSamplingRate(),
+ }
}
-func convertRateLimitingFromDomain(s *api_v2.RateLimitingSamplingStrategy) (*sampling.RateLimitingSamplingStrategy, error) {
+func convertRateLimitingFromDomain(
+ s *api_v2.RateLimitingSamplingStrategy,
+) (*sampling.RateLimitingSamplingStrategy, error) {
if s == nil {
return nil, nil
}
if s.MaxTracesPerSecond > math.MaxInt16 {
return nil, errors.New("maxTracesPerSecond is higher than int16")
}
- return &sampling.RateLimitingSamplingStrategy{MaxTracesPerSecond: int16(s.GetMaxTracesPerSecond())}, nil
+ return &sampling.RateLimitingSamplingStrategy{
+ MaxTracesPerSecond: int16(s.GetMaxTracesPerSecond()),
+ }, nil
}
-func convertPerOperationFromDomain(s *api_v2.PerOperationSamplingStrategies) *sampling.PerOperationSamplingStrategies {
+func convertPerOperationFromDomain(
+ s *api_v2.PerOperationSamplingStrategies,
+) *sampling.PerOperationSamplingStrategies {
if s == nil {
return nil
}
@@ -70,30 +86,41 @@ func convertPerOperationFromDomain(s *api_v2.PerOperationSamplingStrategies) *sa
perOp := s.GetPerOperationStrategies()
// Default to empty array so that json.Marshal returns [] instead of null (Issue #3891).
- r.PerOperationStrategies = make([]*sampling.OperationSamplingStrategy, len(perOp))
+ r.PerOperationStrategies = make(
+ []*sampling.OperationSamplingStrategy,
+ len(perOp),
+ )
for i, k := range perOp {
r.PerOperationStrategies[i] = convertOperationFromDomain(k)
}
return r
}
-func convertOperationFromDomain(s *api_v2.OperationSamplingStrategy) *sampling.OperationSamplingStrategy {
+func convertOperationFromDomain(
+ s *api_v2.OperationSamplingStrategy,
+) *sampling.OperationSamplingStrategy {
if s == nil {
return nil
}
return &sampling.OperationSamplingStrategy{
- Operation: s.GetOperation(),
- ProbabilisticSampling: convertProbabilisticFromDomain(s.GetProbabilisticSampling()),
+ Operation: s.GetOperation(),
+ ProbabilisticSampling: convertProbabilisticFromDomain(
+ s.GetProbabilisticSampling(),
+ ),
}
}
-func convertStrategyTypeFromDomain(s api_v2.SamplingStrategyType) (sampling.SamplingStrategyType, error) {
+func convertStrategyTypeFromDomain(
+ s api_v2.SamplingStrategyType,
+) (sampling.SamplingStrategyType, error) {
switch s {
case api_v2.SamplingStrategyType_PROBABILISTIC:
return sampling.SamplingStrategyType_PROBABILISTIC, nil
case api_v2.SamplingStrategyType_RATE_LIMITING:
return sampling.SamplingStrategyType_RATE_LIMITING, nil
default:
- return sampling.SamplingStrategyType_PROBABILISTIC, errors.New("could not convert sampling strategy type")
+ return sampling.SamplingStrategyType_PROBABILISTIC, errors.New(
+ "could not convert sampling strategy type",
+ )
}
}
diff --git a/model/converter/thrift/jaeger/sampling_from_domain_test.go b/model/converter/thrift/jaeger/sampling_from_domain_test.go
index c133456e019..46cbb809bb8 100644
--- a/model/converter/thrift/jaeger/sampling_from_domain_test.go
+++ b/model/converter/thrift/jaeger/sampling_from_domain_test.go
@@ -31,8 +31,14 @@ func TestConvertStrategyTypeFromDomain(t *testing.T) {
in api_v2.SamplingStrategyType
err string
}{
- {expected: sampling.SamplingStrategyType_PROBABILISTIC, in: api_v2.SamplingStrategyType_PROBABILISTIC},
- {expected: sampling.SamplingStrategyType_RATE_LIMITING, in: api_v2.SamplingStrategyType_RATE_LIMITING},
+ {
+ expected: sampling.SamplingStrategyType_PROBABILISTIC,
+ in: api_v2.SamplingStrategyType_PROBABILISTIC,
+ },
+ {
+ expected: sampling.SamplingStrategyType_RATE_LIMITING,
+ in: api_v2.SamplingStrategyType_RATE_LIMITING,
+ },
{in: 44, err: "could not convert sampling strategy type"},
}
for _, test := range tests {
@@ -51,7 +57,10 @@ func TestConvertProbabilisticFromDomain(t *testing.T) {
in *api_v2.ProbabilisticSamplingStrategy
expected *sampling.ProbabilisticSamplingStrategy
}{
- {in: &api_v2.ProbabilisticSamplingStrategy{SamplingRate: 21}, expected: &sampling.ProbabilisticSamplingStrategy{SamplingRate: 21}},
+ {
+ in: &api_v2.ProbabilisticSamplingStrategy{SamplingRate: 21},
+ expected: &sampling.ProbabilisticSamplingStrategy{SamplingRate: 21},
+ },
{},
}
for _, test := range tests {
@@ -66,8 +75,14 @@ func TestConvertRateLimitingFromDomain(t *testing.T) {
expected *sampling.RateLimitingSamplingStrategy
err string
}{
- {in: &api_v2.RateLimitingSamplingStrategy{MaxTracesPerSecond: 21}, expected: &sampling.RateLimitingSamplingStrategy{MaxTracesPerSecond: 21}},
- {in: &api_v2.RateLimitingSamplingStrategy{MaxTracesPerSecond: math.MaxInt32}, err: "maxTracesPerSecond is higher than int16"},
+ {
+ in: &api_v2.RateLimitingSamplingStrategy{MaxTracesPerSecond: 21},
+ expected: &sampling.RateLimitingSamplingStrategy{MaxTracesPerSecond: 21},
+ },
+ {
+ in: &api_v2.RateLimitingSamplingStrategy{MaxTracesPerSecond: math.MaxInt32},
+ err: "maxTracesPerSecond is higher than int16",
+ },
{},
}
for _, test := range tests {
@@ -87,10 +102,19 @@ func TestConvertOperationStrategyFromDomain(t *testing.T) {
in *api_v2.OperationSamplingStrategy
expected *sampling.OperationSamplingStrategy
}{
- {in: &api_v2.OperationSamplingStrategy{Operation: "foo"}, expected: &sampling.OperationSamplingStrategy{Operation: "foo"}},
{
- in: &api_v2.OperationSamplingStrategy{Operation: "foo", ProbabilisticSampling: &api_v2.ProbabilisticSamplingStrategy{SamplingRate: 2}},
- expected: &sampling.OperationSamplingStrategy{Operation: "foo", ProbabilisticSampling: &sampling.ProbabilisticSamplingStrategy{SamplingRate: 2}},
+ in: &api_v2.OperationSamplingStrategy{Operation: "foo"},
+ expected: &sampling.OperationSamplingStrategy{Operation: "foo"},
+ },
+ {
+ in: &api_v2.OperationSamplingStrategy{
+ Operation: "foo",
+ ProbabilisticSampling: &api_v2.ProbabilisticSamplingStrategy{SamplingRate: 2},
+ },
+ expected: &sampling.OperationSamplingStrategy{
+ Operation: "foo",
+ ProbabilisticSampling: &sampling.ProbabilisticSamplingStrategy{SamplingRate: 2},
+ },
},
{},
}
@@ -109,15 +133,23 @@ func TestConvertPerOperationStrategyFromDomain(t *testing.T) {
{
in: &api_v2.PerOperationSamplingStrategies{
DefaultSamplingProbability: 15.2, DefaultUpperBoundTracesPerSecond: a, DefaultLowerBoundTracesPerSecond: 2,
- PerOperationStrategies: []*api_v2.OperationSamplingStrategy{{Operation: "fao"}},
+ PerOperationStrategies: []*api_v2.OperationSamplingStrategy{
+ {Operation: "fao"},
+ },
},
expected: &sampling.PerOperationSamplingStrategies{
DefaultSamplingProbability: 15.2, DefaultUpperBoundTracesPerSecond: &a, DefaultLowerBoundTracesPerSecond: 2,
- PerOperationStrategies: []*sampling.OperationSamplingStrategy{{Operation: "fao"}},
+ PerOperationStrategies: []*sampling.OperationSamplingStrategy{
+ {Operation: "fao"},
+ },
},
},
{
- in: &api_v2.PerOperationSamplingStrategies{DefaultSamplingProbability: 15.2, DefaultUpperBoundTracesPerSecond: a, DefaultLowerBoundTracesPerSecond: 2},
+ in: &api_v2.PerOperationSamplingStrategies{
+ DefaultSamplingProbability: 15.2,
+ DefaultUpperBoundTracesPerSecond: a,
+ DefaultLowerBoundTracesPerSecond: 2,
+ },
expected: &sampling.PerOperationSamplingStrategies{
DefaultSamplingProbability: 15.2, DefaultUpperBoundTracesPerSecond: &a, DefaultLowerBoundTracesPerSecond: 2,
PerOperationStrategies: []*sampling.OperationSamplingStrategy{},
@@ -136,12 +168,21 @@ func TestConvertSamplingResponseFromDomain(t *testing.T) {
expected *sampling.SamplingStrategyResponse
err string
}{
- {in: &api_v2.SamplingStrategyResponse{StrategyType: 55}, err: "could not convert sampling strategy type"},
{
- in: &api_v2.SamplingStrategyResponse{StrategyType: api_v2.SamplingStrategyType_PROBABILISTIC, RateLimitingSampling: &api_v2.RateLimitingSamplingStrategy{MaxTracesPerSecond: math.MaxInt32}},
+ in: &api_v2.SamplingStrategyResponse{StrategyType: 55},
+ err: "could not convert sampling strategy type",
+ },
+ {
+ in: &api_v2.SamplingStrategyResponse{
+ StrategyType: api_v2.SamplingStrategyType_PROBABILISTIC,
+ RateLimitingSampling: &api_v2.RateLimitingSamplingStrategy{MaxTracesPerSecond: math.MaxInt32},
+ },
err: "maxTracesPerSecond is higher than int16",
},
- {in: &api_v2.SamplingStrategyResponse{StrategyType: api_v2.SamplingStrategyType_PROBABILISTIC}, expected: &sampling.SamplingStrategyResponse{StrategyType: sampling.SamplingStrategyType_PROBABILISTIC}},
+ {
+ in: &api_v2.SamplingStrategyResponse{StrategyType: api_v2.SamplingStrategyType_PROBABILISTIC},
+ expected: &sampling.SamplingStrategyResponse{StrategyType: sampling.SamplingStrategyType_PROBABILISTIC},
+ },
}
for _, test := range tests {
r, err := ConvertSamplingResponseFromDomain(test.in)
diff --git a/model/converter/thrift/jaeger/sampling_to_domain.go b/model/converter/thrift/jaeger/sampling_to_domain.go
index 876e50a4a83..71f56c88c90 100644
--- a/model/converter/thrift/jaeger/sampling_to_domain.go
+++ b/model/converter/thrift/jaeger/sampling_to_domain.go
@@ -22,7 +22,9 @@ import (
)
// ConvertSamplingResponseToDomain converts thrift sampling response to its proto representation.
-func ConvertSamplingResponseToDomain(r *sampling.SamplingStrategyResponse) (*api_v2.SamplingStrategyResponse, error) {
+func ConvertSamplingResponseToDomain(
+ r *sampling.SamplingStrategyResponse,
+) (*api_v2.SamplingStrategyResponse, error) {
if r == nil {
return nil, nil
}
@@ -31,37 +33,58 @@ func ConvertSamplingResponseToDomain(r *sampling.SamplingStrategyResponse) (*api
return nil, err
}
response := &api_v2.SamplingStrategyResponse{
- StrategyType: t,
- ProbabilisticSampling: convertProbabilisticToDomain(r.GetProbabilisticSampling()),
- RateLimitingSampling: convertRateLimitingToDomain(r.GetRateLimitingSampling()),
- OperationSampling: convertPerOperationToDomain(r.GetOperationSampling()),
+ StrategyType: t,
+ ProbabilisticSampling: convertProbabilisticToDomain(
+ r.GetProbabilisticSampling(),
+ ),
+ RateLimitingSampling: convertRateLimitingToDomain(
+ r.GetRateLimitingSampling(),
+ ),
+ OperationSampling: convertPerOperationToDomain(
+ r.GetOperationSampling(),
+ ),
}
return response, nil
}
-func convertRateLimitingToDomain(s *sampling.RateLimitingSamplingStrategy) *api_v2.RateLimitingSamplingStrategy {
+func convertRateLimitingToDomain(
+ s *sampling.RateLimitingSamplingStrategy,
+) *api_v2.RateLimitingSamplingStrategy {
if s == nil {
return nil
}
- return &api_v2.RateLimitingSamplingStrategy{MaxTracesPerSecond: int32(s.GetMaxTracesPerSecond())}
+ return &api_v2.RateLimitingSamplingStrategy{
+ MaxTracesPerSecond: int32(s.GetMaxTracesPerSecond()),
+ }
}
-func convertProbabilisticToDomain(s *sampling.ProbabilisticSamplingStrategy) *api_v2.ProbabilisticSamplingStrategy {
+func convertProbabilisticToDomain(
+ s *sampling.ProbabilisticSamplingStrategy,
+) *api_v2.ProbabilisticSamplingStrategy {
if s == nil {
return nil
}
- return &api_v2.ProbabilisticSamplingStrategy{SamplingRate: s.GetSamplingRate()}
+ return &api_v2.ProbabilisticSamplingStrategy{
+ SamplingRate: s.GetSamplingRate(),
+ }
}
-func convertPerOperationToDomain(s *sampling.PerOperationSamplingStrategies) *api_v2.PerOperationSamplingStrategies {
+func convertPerOperationToDomain(
+ s *sampling.PerOperationSamplingStrategies,
+) *api_v2.PerOperationSamplingStrategies {
if s == nil {
return nil
}
- poss := make([]*api_v2.OperationSamplingStrategy, len(s.PerOperationStrategies))
+ poss := make(
+ []*api_v2.OperationSamplingStrategy,
+ len(s.PerOperationStrategies),
+ )
for i, pos := range s.PerOperationStrategies {
poss[i] = &api_v2.OperationSamplingStrategy{
- Operation: pos.Operation,
- ProbabilisticSampling: convertProbabilisticToDomain(pos.GetProbabilisticSampling()),
+ Operation: pos.Operation,
+ ProbabilisticSampling: convertProbabilisticToDomain(
+ pos.GetProbabilisticSampling(),
+ ),
}
}
return &api_v2.PerOperationSamplingStrategies{
@@ -72,13 +95,17 @@ func convertPerOperationToDomain(s *sampling.PerOperationSamplingStrategies) *ap
}
}
-func convertStrategyTypeToDomain(t sampling.SamplingStrategyType) (api_v2.SamplingStrategyType, error) {
+func convertStrategyTypeToDomain(
+ t sampling.SamplingStrategyType,
+) (api_v2.SamplingStrategyType, error) {
switch t {
case sampling.SamplingStrategyType_PROBABILISTIC:
return api_v2.SamplingStrategyType_PROBABILISTIC, nil
case sampling.SamplingStrategyType_RATE_LIMITING:
return api_v2.SamplingStrategyType_RATE_LIMITING, nil
default:
- return api_v2.SamplingStrategyType_PROBABILISTIC, errors.New("could not convert sampling strategy type")
+ return api_v2.SamplingStrategyType_PROBABILISTIC, errors.New(
+ "could not convert sampling strategy type",
+ )
}
}
diff --git a/model/converter/thrift/jaeger/sampling_to_domain_test.go b/model/converter/thrift/jaeger/sampling_to_domain_test.go
index 9e69faba2b1..e656c3699c5 100644
--- a/model/converter/thrift/jaeger/sampling_to_domain_test.go
+++ b/model/converter/thrift/jaeger/sampling_to_domain_test.go
@@ -31,8 +31,14 @@ func TestConvertStrategyTypeToDomain(t *testing.T) {
expected api_v2.SamplingStrategyType
err error
}{
- {in: sampling.SamplingStrategyType_PROBABILISTIC, expected: api_v2.SamplingStrategyType_PROBABILISTIC},
- {in: sampling.SamplingStrategyType_RATE_LIMITING, expected: api_v2.SamplingStrategyType_RATE_LIMITING},
+ {
+ in: sampling.SamplingStrategyType_PROBABILISTIC,
+ expected: api_v2.SamplingStrategyType_PROBABILISTIC,
+ },
+ {
+ in: sampling.SamplingStrategyType_RATE_LIMITING,
+ expected: api_v2.SamplingStrategyType_RATE_LIMITING,
+ },
{in: 44, err: errors.New("could not convert sampling strategy type")},
}
for _, test := range tests {
@@ -51,7 +57,10 @@ func TestConvertProbabilisticToDomain(t *testing.T) {
expected *api_v2.ProbabilisticSamplingStrategy
in *sampling.ProbabilisticSamplingStrategy
}{
- {expected: &api_v2.ProbabilisticSamplingStrategy{SamplingRate: 21}, in: &sampling.ProbabilisticSamplingStrategy{SamplingRate: 21}},
+ {
+ expected: &api_v2.ProbabilisticSamplingStrategy{SamplingRate: 21},
+ in: &sampling.ProbabilisticSamplingStrategy{SamplingRate: 21},
+ },
{},
}
for _, test := range tests {
@@ -65,7 +74,10 @@ func TestConvertRateLimitingToDomain(t *testing.T) {
expected *api_v2.RateLimitingSamplingStrategy
in *sampling.RateLimitingSamplingStrategy
}{
- {expected: &api_v2.RateLimitingSamplingStrategy{MaxTracesPerSecond: 21}, in: &sampling.RateLimitingSamplingStrategy{MaxTracesPerSecond: 21}},
+ {
+ expected: &api_v2.RateLimitingSamplingStrategy{MaxTracesPerSecond: 21},
+ in: &sampling.RateLimitingSamplingStrategy{MaxTracesPerSecond: 21},
+ },
{},
}
for _, test := range tests {
@@ -83,11 +95,15 @@ func TestConvertPerOperationStrategyToDomain(t *testing.T) {
{
expected: &api_v2.PerOperationSamplingStrategies{
DefaultSamplingProbability: 15.2, DefaultUpperBoundTracesPerSecond: a, DefaultLowerBoundTracesPerSecond: 2,
- PerOperationStrategies: []*api_v2.OperationSamplingStrategy{{Operation: "fao"}},
+ PerOperationStrategies: []*api_v2.OperationSamplingStrategy{
+ {Operation: "fao"},
+ },
},
in: &sampling.PerOperationSamplingStrategies{
DefaultSamplingProbability: 15.2, DefaultUpperBoundTracesPerSecond: &a, DefaultLowerBoundTracesPerSecond: 2,
- PerOperationStrategies: []*sampling.OperationSamplingStrategy{{Operation: "fao"}},
+ PerOperationStrategies: []*sampling.OperationSamplingStrategy{
+ {Operation: "fao"},
+ },
},
},
{},
@@ -105,7 +121,10 @@ func TestConvertSamplingResponseToDomain(t *testing.T) {
err string
}{
{in: &sampling.SamplingStrategyResponse{StrategyType: 55}, err: "could not convert sampling strategy type"},
- {expected: &api_v2.SamplingStrategyResponse{StrategyType: api_v2.SamplingStrategyType_PROBABILISTIC}, in: &sampling.SamplingStrategyResponse{StrategyType: sampling.SamplingStrategyType_PROBABILISTIC}},
+ {
+ expected: &api_v2.SamplingStrategyResponse{StrategyType: api_v2.SamplingStrategyType_PROBABILISTIC},
+ in: &sampling.SamplingStrategyResponse{StrategyType: sampling.SamplingStrategyType_PROBABILISTIC},
+ },
{},
}
for _, test := range tests {
diff --git a/model/converter/thrift/jaeger/to_domain.go b/model/converter/thrift/jaeger/to_domain.go
index 5f3838bc397..ba2a8928b62 100644
--- a/model/converter/thrift/jaeger/to_domain.go
+++ b/model/converter/thrift/jaeger/to_domain.go
@@ -43,7 +43,10 @@ func ToDomainProcess(jProcess *jaeger.Process) *model.Process {
type toDomain struct{}
-func (td toDomain) ToDomain(jSpans []*jaeger.Span, jProcess *jaeger.Process) []*model.Span {
+func (td toDomain) ToDomain(
+ jSpans []*jaeger.Span,
+ jProcess *jaeger.Process,
+) []*model.Span {
spans := make([]*model.Span, len(jSpans))
mProcess := td.getProcess(jProcess)
for i, jSpan := range jSpans {
@@ -52,13 +55,22 @@ func (td toDomain) ToDomain(jSpans []*jaeger.Span, jProcess *jaeger.Process) []*
return spans
}
-func (td toDomain) ToDomainSpan(jSpan *jaeger.Span, jProcess *jaeger.Process) *model.Span {
+func (td toDomain) ToDomainSpan(
+ jSpan *jaeger.Span,
+ jProcess *jaeger.Process,
+) *model.Span {
mProcess := td.getProcess(jProcess)
return td.transformSpan(jSpan, mProcess)
}
-func (td toDomain) transformSpan(jSpan *jaeger.Span, mProcess *model.Process) *model.Span {
- traceID := model.NewTraceID(uint64(jSpan.TraceIdHigh), uint64(jSpan.TraceIdLow))
+func (td toDomain) transformSpan(
+ jSpan *jaeger.Span,
+ mProcess *model.Process,
+) *model.Span {
+ traceID := model.NewTraceID(
+ uint64(jSpan.TraceIdHigh),
+ uint64(jSpan.TraceIdLow),
+ )
// allocate extra space for future append operation
tags := td.getTags(jSpan.Tags, 1)
refs := td.getReferences(jSpan.References)
@@ -92,8 +104,11 @@ func (toDomain) getReferences(jRefs []*jaeger.SpanRef) []model.SpanRef {
for idx, jRef := range jRefs {
mRefs[idx] = model.SpanRef{
RefType: model.SpanRefType(int(jRef.RefType)),
- TraceID: model.NewTraceID(uint64(jRef.TraceIdHigh), uint64(jRef.TraceIdLow)),
- SpanID: model.NewSpanID(uint64(jRef.SpanId)),
+ TraceID: model.NewTraceID(
+ uint64(jRef.TraceIdHigh),
+ uint64(jRef.TraceIdLow),
+ ),
+ SpanID: model.NewSpanID(uint64(jRef.SpanId)),
}
}
diff --git a/model/converter/thrift/jaeger/to_domain_test.go b/model/converter/thrift/jaeger/to_domain_test.go
index 8d43bdf8c61..789ff1d5b04 100644
--- a/model/converter/thrift/jaeger/to_domain_test.go
+++ b/model/converter/thrift/jaeger/to_domain_test.go
@@ -101,17 +101,28 @@ func TestUnknownJaegerType(t *testing.T) {
VType: 999,
Key: "sneh",
})
- expected := model.String("sneh", "Unknown VType: Tag({Key:sneh VType: VStr: VDouble: VBool: VLong: VBinary:[]})")
+ expected := model.String(
+ "sneh",
+ "Unknown VType: Tag({Key:sneh VType: VStr: VDouble: VBool: VLong: VBinary:[]})",
+ )
assert.Equal(t, expected, mkv)
}
func TestToDomain_ToDomainProcess(t *testing.T) {
- p := ToDomainProcess(&jaeger.Process{ServiceName: "foo", Tags: []*jaeger.Tag{{Key: "foo", VType: jaeger.TagType_BOOL}}})
+ p := ToDomainProcess(
+ &jaeger.Process{ServiceName: "foo", Tags: []*jaeger.Tag{{Key: "foo", VType: jaeger.TagType_BOOL}}},
+ )
assert.Equal(t, &model.Process{ServiceName: "foo", Tags: []model.KeyValue{{Key: "foo", VType: model.BoolType}}}, p)
}
func TestToDomain_ToDomainSpanProcessNull(t *testing.T) {
tm := time.Unix(158, 0)
- s := ToDomainSpan(&jaeger.Span{OperationName: "foo", StartTime: int64(model.TimeAsEpochMicroseconds(tm))}, nil)
+ s := ToDomainSpan(
+ &jaeger.Span{
+ OperationName: "foo",
+ StartTime: int64(model.TimeAsEpochMicroseconds(tm)),
+ },
+ nil,
+ )
assert.Equal(t, &model.Span{OperationName: "foo", StartTime: tm.UTC()}, s)
}
diff --git a/model/converter/thrift/zipkin/deserialize.go b/model/converter/thrift/zipkin/deserialize.go
index 821cf3914fb..23fe382f55e 100644
--- a/model/converter/thrift/zipkin/deserialize.go
+++ b/model/converter/thrift/zipkin/deserialize.go
@@ -36,12 +36,17 @@ func SerializeThrift(ctx context.Context, spans []*zipkincore.Span) []byte {
}
// DeserializeThrift decodes Thrift bytes to a list of spans.
-func DeserializeThrift(ctx context.Context, b []byte) ([]*zipkincore.Span, error) {
+func DeserializeThrift(
+ ctx context.Context,
+ b []byte,
+) ([]*zipkincore.Span, error) {
buffer := thrift.NewTMemoryBuffer()
buffer.Write(b)
transport := thrift.NewTBinaryProtocolConf(buffer, &thrift.TConfiguration{})
- _, size, err := transport.ReadListBegin(ctx) // Ignore the returned element type
+ _, size, err := transport.ReadListBegin(
+ ctx,
+ ) // Ignore the returned element type
if err != nil {
return nil, err
}
diff --git a/model/converter/thrift/zipkin/to_domain.go b/model/converter/thrift/zipkin/to_domain.go
index a75255e9eb6..fe7e9fe7d72 100644
--- a/model/converter/thrift/zipkin/to_domain.go
+++ b/model/converter/thrift/zipkin/to_domain.go
@@ -107,7 +107,9 @@ func (td toDomain) ToDomain(zSpans []*zipkincore.Span) (*model.Trace, error) {
return trace, errors.Join(errs...)
}
-func (td toDomain) ToDomainSpans(zSpan *zipkincore.Span) ([]*model.Span, error) {
+func (td toDomain) ToDomainSpans(
+ zSpan *zipkincore.Span,
+) ([]*model.Span, error) {
jSpans := td.transformSpan(zSpan)
jProcess, err := td.generateProcess(zSpan)
for _, jSpan := range jSpans {
@@ -116,7 +118,10 @@ func (td toDomain) ToDomainSpans(zSpan *zipkincore.Span) ([]*model.Span, error)
return jSpans, err
}
-func (toDomain) findAnnotation(zSpan *zipkincore.Span, value string) *zipkincore.Annotation {
+func (toDomain) findAnnotation(
+ zSpan *zipkincore.Span,
+ value string,
+) *zipkincore.Annotation {
for _, ann := range zSpan.Annotations {
if ann.Value == value {
return ann
@@ -171,10 +176,14 @@ func (td toDomain) transformSpan(zSpan *zipkincore.Span) []*model.Span {
}
// if the first span is a client span we create server span and vice-versa.
if result[0].IsRPCClient() {
- s.Tags = []model.KeyValue{model.String(keySpanKind, trace.SpanKindServer.String())}
+ s.Tags = []model.KeyValue{
+ model.String(keySpanKind, trace.SpanKindServer.String()),
+ }
s.StartTime = model.EpochMicrosecondsAsTime(uint64(sr.Timestamp))
if ss := td.findAnnotation(zSpan, zipkincore.SERVER_SEND); ss != nil {
- s.Duration = model.MicrosecondsAsDuration(uint64(ss.Timestamp - sr.Timestamp))
+ s.Duration = model.MicrosecondsAsDuration(
+ uint64(ss.Timestamp - sr.Timestamp),
+ )
}
} else {
s.Tags = []model.KeyValue{model.String(keySpanKind, trace.SpanKindClient.String())}
@@ -198,7 +207,9 @@ func (toDomain) getFlags(zSpan *zipkincore.Span) model.Flags {
}
// Get a correct start time to use for the span if it's not set directly
-func (td toDomain) getStartTimeAndDuration(zSpan *zipkincore.Span) (timestamp, duration int64) {
+func (td toDomain) getStartTimeAndDuration(
+ zSpan *zipkincore.Span,
+) (timestamp, duration int64) {
timestamp = zSpan.GetTimestamp()
duration = zSpan.GetDuration()
if timestamp == 0 {
@@ -223,7 +234,9 @@ func (td toDomain) getStartTimeAndDuration(zSpan *zipkincore.Span) (timestamp, d
// generateProcess takes a Zipkin Span and produces a model.Process.
// An optional error may also be returned, but it is not fatal.
-func (td toDomain) generateProcess(zSpan *zipkincore.Span) (*model.Process, error) {
+func (td toDomain) generateProcess(
+ zSpan *zipkincore.Span,
+) (*model.Process, error) {
tags := td.getTags(zSpan.BinaryAnnotations, td.isProcessTag)
for i, tag := range tags {
tags[i].Key = processTagAnnotations[tag.Key]
@@ -236,14 +249,17 @@ func (td toDomain) generateProcess(zSpan *zipkincore.Span) (*model.Process, erro
return model.NewProcess(serviceName, tags), err
}
-func (td toDomain) findServiceNameAndIP(zSpan *zipkincore.Span) (string, int32, error) {
+func (td toDomain) findServiceNameAndIP(
+ zSpan *zipkincore.Span,
+) (string, int32, error) {
for _, a := range zSpan.Annotations {
if td.isCoreAnnotation(a) && a.Host != nil && a.Host.ServiceName != "" {
return a.Host.ServiceName, a.Host.Ipv4, nil
}
}
for _, a := range zSpan.BinaryAnnotations {
- if a.Key == zipkincore.LOCAL_COMPONENT && a.Host != nil && a.Host.ServiceName != "" {
+ if a.Key == zipkincore.LOCAL_COMPONENT && a.Host != nil &&
+ a.Host.ServiceName != "" {
return a.Host.ServiceName, a.Host.Ipv4, nil
}
}
@@ -270,18 +286,25 @@ func (toDomain) isCoreAnnotation(annotation *zipkincore.Annotation) bool {
return ok
}
-func (toDomain) isProcessTag(binaryAnnotation *zipkincore.BinaryAnnotation) bool {
+func (toDomain) isProcessTag(
+ binaryAnnotation *zipkincore.BinaryAnnotation,
+) bool {
_, ok := processTagAnnotations[binaryAnnotation.Key]
return ok
}
-func (td toDomain) isSpanTag(binaryAnnotation *zipkincore.BinaryAnnotation) bool {
+func (td toDomain) isSpanTag(
+ binaryAnnotation *zipkincore.BinaryAnnotation,
+) bool {
return !td.isProcessTag(binaryAnnotation)
}
type tagPredicate func(*zipkincore.BinaryAnnotation) bool
-func (td toDomain) getTags(binAnnotations []*zipkincore.BinaryAnnotation, tagInclude tagPredicate) []model.KeyValue {
+func (td toDomain) getTags(
+ binAnnotations []*zipkincore.BinaryAnnotation,
+ tagInclude tagPredicate,
+) []model.KeyValue {
// this will be memory intensive due to how slices work, and it's specifically because we have to filter out
// some binary annotations. improvement here would be just collecting the indices in binAnnotations we want.
var retMe []model.KeyValue
@@ -294,13 +317,19 @@ func (td toDomain) getTags(binAnnotations []*zipkincore.BinaryAnnotation, tagInc
value := string(annotation.Value)
tag := model.String(component, value)
retMe = append(retMe, tag)
- case zipkincore.SERVER_ADDR, zipkincore.CLIENT_ADDR, zipkincore.MESSAGE_ADDR:
+ case zipkincore.SERVER_ADDR,
+ zipkincore.CLIENT_ADDR,
+ zipkincore.MESSAGE_ADDR:
retMe = td.getPeerTags(annotation.Host, retMe)
default:
tag, err := td.transformBinaryAnnotation(annotation)
if err != nil {
encoded := base64.StdEncoding.EncodeToString(annotation.Value)
- errMsg := fmt.Sprintf("Cannot parse Zipkin value %s: %v", encoded, err)
+ errMsg := fmt.Sprintf(
+ "Cannot parse Zipkin value %s: %v",
+ encoded,
+ err,
+ )
tag = model.String(annotation.Key, errMsg)
}
retMe = append(retMe, tag)
@@ -309,7 +338,9 @@ func (td toDomain) getTags(binAnnotations []*zipkincore.BinaryAnnotation, tagInc
return retMe
}
-func (toDomain) transformBinaryAnnotation(binaryAnnotation *zipkincore.BinaryAnnotation) (model.KeyValue, error) {
+func (toDomain) transformBinaryAnnotation(
+ binaryAnnotation *zipkincore.BinaryAnnotation,
+) (model.KeyValue, error) {
switch binaryAnnotation.AnnotationType {
case zipkincore.AnnotationType_BOOL:
vBool := bytes.Equal(binaryAnnotation.Value, trueByteSlice)
@@ -341,9 +372,15 @@ func (toDomain) transformBinaryAnnotation(binaryAnnotation *zipkincore.BinaryAnn
}
return model.Int64(binaryAnnotation.Key, int64(i)), nil
case zipkincore.AnnotationType_STRING:
- return model.String(binaryAnnotation.Key, string(binaryAnnotation.Value)), nil
+ return model.String(
+ binaryAnnotation.Key,
+ string(binaryAnnotation.Value),
+ ), nil
}
- return model.KeyValue{}, fmt.Errorf("unknown zipkin annotation type: %d", binaryAnnotation.AnnotationType)
+ return model.KeyValue{}, fmt.Errorf(
+ "unknown zipkin annotation type: %d",
+ binaryAnnotation.AnnotationType,
+ )
}
func bytesToNumber(b []byte, number any) error {
@@ -372,7 +409,9 @@ func (td toDomain) getLogs(annotations []*zipkincore.Annotation) []model.Log {
return retMe
}
-func (toDomain) getLogFields(annotation *zipkincore.Annotation) []model.KeyValue {
+func (toDomain) getLogFields(
+ annotation *zipkincore.Annotation,
+) []model.KeyValue {
var logFields map[string]string
// Since Zipkin format does not support kv-logging, some clients encode those Logs
// as annotations with JSON value. Therefore, we try JSON decoding first.
@@ -388,7 +427,9 @@ func (toDomain) getLogFields(annotation *zipkincore.Annotation) []model.KeyValue
return []model.KeyValue{model.String(DefaultLogFieldKey, annotation.Value)}
}
-func (toDomain) getSpanKindTag(annotations []*zipkincore.Annotation) (model.KeyValue, bool) {
+func (toDomain) getSpanKindTag(
+ annotations []*zipkincore.Annotation,
+) (model.KeyValue, bool) {
for _, a := range annotations {
if spanKind, ok := coreAnnotations[a.Value]; ok {
return model.String(keySpanKind, spanKind), true
@@ -397,7 +438,10 @@ func (toDomain) getSpanKindTag(annotations []*zipkincore.Annotation) (model.KeyV
return model.KeyValue{}, false
}
-func (toDomain) getPeerTags(endpoint *zipkincore.Endpoint, tags []model.KeyValue) []model.KeyValue {
+func (toDomain) getPeerTags(
+ endpoint *zipkincore.Endpoint,
+ tags []model.KeyValue,
+) []model.KeyValue {
if endpoint == nil {
return tags
}
diff --git a/model/converter/thrift/zipkin/to_domain_test.go b/model/converter/thrift/zipkin/to_domain_test.go
index 986f33598b9..d214434f345 100644
--- a/model/converter/thrift/zipkin/to_domain_test.go
+++ b/model/converter/thrift/zipkin/to_domain_test.go
@@ -77,7 +77,11 @@ func TestToDomain(t *testing.T) {
func TestToDomainNoServiceNameError(t *testing.T) {
zSpans := getZipkinSpans(t, `[{ "trace_id": -1, "id": 31 }]`)
trace, err := ToDomain(zSpans)
- require.EqualError(t, err, "cannot find service name in Zipkin span [traceID=ffffffffffffffff, spanID=1f]")
+ require.EqualError(
+ t,
+ err,
+ "cannot find service name in Zipkin span [traceID=ffffffffffffffff, spanID=1f]",
+ )
assert.Len(t, trace.Spans, 1)
assert.Equal(t, "unknown-service-name", trace.Spans[0].Process.ServiceName)
}
@@ -181,8 +185,17 @@ func TestValidateBase64Values(t *testing.T) {
assert.Equal(t, "MDk=", numberToBase64(int16(12345)))
assert.Equal(t, "AAAwOQ==", numberToBase64(int32(12345)))
assert.Equal(t, "AAAAAAAAMDk=", numberToBase64(int64(12345)))
- assert.Equal(t, "QMgcgAAAAAA=", numberToBase64(int64(math.Float64bits(12345))))
- assert.Equal(t, int64(4668012349850910720), int64(math.Float64bits(12345)), "sanity check")
+ assert.Equal(
+ t,
+ "QMgcgAAAAAA=",
+ numberToBase64(int64(math.Float64bits(12345))),
+ )
+ assert.Equal(
+ t,
+ int64(4668012349850910720),
+ int64(math.Float64bits(12345)),
+ "sanity check",
+ )
}
func loadZipkinSpans(t *testing.T, file string) []*z.Span {
diff --git a/model/hash_test.go b/model/hash_test.go
index d62e033f893..a9f7074cf94 100644
--- a/model/hash_test.go
+++ b/model/hash_test.go
@@ -37,7 +37,10 @@ type mockHashWwiter struct {
func (w *mockHashWwiter) Write(data []byte) (int, error) {
if len(w.answers) == 0 {
- return 0, fmt.Errorf("no answer registered for call with data=%+v", data)
+ return 0, fmt.Errorf(
+ "no answer registered for call with data=%+v",
+ data,
+ )
}
answer := w.answers[0]
w.answers = w.answers[1:]
diff --git a/model/ids.go b/model/ids.go
index 3ffd6412e5e..d5c8c7483a1 100644
--- a/model/ids.go
+++ b/model/ids.go
@@ -60,7 +60,10 @@ func TraceIDFromString(s string) (TraceID, error) {
var err error
switch {
case len(s) > 32:
- return TraceID{}, fmt.Errorf("TraceID cannot be longer than 32 hex characters: %s", s)
+ return TraceID{}, fmt.Errorf(
+ "TraceID cannot be longer than 32 hex characters: %s",
+ s,
+ )
case len(s) > 16:
hiLen := len(s) - 16
if hi, err = strconv.ParseUint(s[0:hiLen], 16, 64); err != nil {
@@ -94,12 +97,16 @@ func TraceIDFromBytes(data []byte) (TraceID, error) {
// MarshalText is called by encoding/json, which we do not want people to use.
func (TraceID) MarshalText() ([]byte, error) {
- return nil, fmt.Errorf("unsupported method TraceID.MarshalText; please use github.com/gogo/protobuf/jsonpb for marshalling")
+ return nil, fmt.Errorf(
+ "unsupported method TraceID.MarshalText; please use github.com/gogo/protobuf/jsonpb for marshalling",
+ )
}
// UnmarshalText is called by encoding/json, which we do not want people to use.
func (*TraceID) UnmarshalText(text []byte) error {
- return fmt.Errorf("unsupported method TraceID.UnmarshalText; please use github.com/gogo/protobuf/jsonpb for marshalling")
+ return fmt.Errorf(
+ "unsupported method TraceID.UnmarshalText; please use github.com/gogo/protobuf/jsonpb for marshalling",
+ )
}
// Size returns the size of this datum in protobuf. It is always 16 bytes.
@@ -150,7 +157,11 @@ func (t *TraceID) UnmarshalJSON(data []byte) error {
}
b, err := base64.StdEncoding.DecodeString(s)
if err != nil {
- return fmt.Errorf("cannot unmarshal TraceID from string '%s': %w", string(data), err)
+ return fmt.Errorf(
+ "cannot unmarshal TraceID from string '%s': %w",
+ string(data),
+ err,
+ )
}
return t.Unmarshal(b)
}
@@ -169,7 +180,12 @@ func (s SpanID) String() string {
// SpanIDFromString creates a SpanID from a hexadecimal string
func SpanIDFromString(s string) (SpanID, error) {
if len(s) > 16 {
- return SpanID(0), fmt.Errorf("SpanID cannot be longer than 16 hex characters: %s", s)
+ return SpanID(
+ 0,
+ ), fmt.Errorf(
+ "SpanID cannot be longer than 16 hex characters: %s",
+ s,
+ )
}
id, err := strconv.ParseUint(s, 16, 64)
if err != nil {
@@ -188,12 +204,16 @@ func SpanIDFromBytes(data []byte) (SpanID, error) {
// MarshalText is called by encoding/json, which we do not want people to use.
func (SpanID) MarshalText() ([]byte, error) {
- return nil, fmt.Errorf("unsupported method SpanID.MarshalText; please use github.com/gogo/protobuf/jsonpb for marshalling")
+ return nil, fmt.Errorf(
+ "unsupported method SpanID.MarshalText; please use github.com/gogo/protobuf/jsonpb for marshalling",
+ )
}
// UnmarshalText is called by encoding/json, which we do not want people to use.
func (*SpanID) UnmarshalText(text []byte) error {
- return fmt.Errorf("unsupported method SpanID.UnmarshalText; please use github.com/gogo/protobuf/jsonpb for marshalling")
+ return fmt.Errorf(
+ "unsupported method SpanID.UnmarshalText; please use github.com/gogo/protobuf/jsonpb for marshalling",
+ )
}
// Size returns the size of this datum in protobuf. It is always 8 bytes.
@@ -239,7 +259,11 @@ func (s *SpanID) UnmarshalJSON(data []byte) error {
}
b, err := base64.StdEncoding.DecodeString(str)
if err != nil {
- return fmt.Errorf("cannot unmarshal SpanID from string '%s': %w", string(data), err)
+ return fmt.Errorf(
+ "cannot unmarshal SpanID from string '%s': %w",
+ string(data),
+ err,
+ )
}
return s.Unmarshal(b)
}
diff --git a/model/ids_test.go b/model/ids_test.go
index d2bc31c529f..d7eb3039ae5 100644
--- a/model/ids_test.go
+++ b/model/ids_test.go
@@ -64,7 +64,10 @@ func TestTraceSpanIDMarshalProto(t *testing.T) {
}
for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
- ref1 := model.SpanRef{TraceID: model.NewTraceID(2, 3), SpanID: model.NewSpanID(11)}
+ ref1 := model.SpanRef{
+ TraceID: model.NewTraceID(2, 3),
+ SpanID: model.NewSpanID(11),
+ }
ref2 := prototest.SpanRef{
// TODO: would be cool to fuzz that test
TraceId: []byte{0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 3},
@@ -119,8 +122,14 @@ func TestTraceIDFromBytes(t *testing.T) {
data []byte
expected model.TraceID
}{
- {data: []byte{0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 3}, expected: model.NewTraceID(2, 3)},
- {data: []byte{0, 0, 0, 0, 0, 0, 0, 2}, expected: model.NewTraceID(0, 2)},
+ {
+ data: []byte{0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 3},
+ expected: model.NewTraceID(2, 3),
+ },
+ {
+ data: []byte{0, 0, 0, 0, 0, 0, 0, 2},
+ expected: model.NewTraceID(0, 2),
+ },
}
for _, test := range tests {
traceID, err := model.TraceIDFromBytes(test.data)
diff --git a/model/keyvalue_test.go b/model/keyvalue_test.go
index 87dfb72a036..f9cd1585163 100644
--- a/model/keyvalue_test.go
+++ b/model/keyvalue_test.go
@@ -78,9 +78,18 @@ func TestKeyValueIsLessAndEqual(t *testing.T) {
{name: "different int64 values", kv1: model.Int64("x", 123), kv2: model.Int64("x", 567)},
{name: "different float64 values", kv1: model.Float64("x", 123), kv2: model.Float64("x", 567)},
{name: "different blob length", kv1: model.Binary("x", []byte{1, 2}), kv2: model.Binary("x", []byte{1, 2, 3})},
- {name: "different blob values", kv1: model.Binary("x", []byte{1, 2, 3}), kv2: model.Binary("x", []byte{1, 2, 4})},
+ {
+ name: "different blob values",
+ kv1: model.Binary("x", []byte{1, 2, 3}),
+ kv2: model.Binary("x", []byte{1, 2, 4}),
+ },
{name: "empty blob", kv1: model.Binary("x", nil), kv2: model.Binary("x", nil), equal: true},
- {name: "identical blob", kv1: model.Binary("x", []byte{1, 2, 3}), kv2: model.Binary("x", []byte{1, 2, 3}), equal: true},
+ {
+ name: "identical blob",
+ kv1: model.Binary("x", []byte{1, 2, 3}),
+ kv2: model.Binary("x", []byte{1, 2, 3}),
+ equal: true,
+ },
}
for _, tt := range testCases {
testCase := tt // capture loop var
@@ -122,15 +131,30 @@ func TestKeyValueAsStringAndValue(t *testing.T) {
strLossy string
val any
}{
- {name: "Bender is great!", kv: model.String("x", "Bender is great!"), str: "Bender is great!", val: "Bender is great!"},
+ {
+ name: "Bender is great!",
+ kv: model.String("x", "Bender is great!"),
+ str: "Bender is great!",
+ val: "Bender is great!",
+ },
{name: "false", kv: model.Bool("x", false), str: "false", val: false},
{name: "true", kv: model.Bool("x", true), str: "true", val: true},
{name: "3000", kv: model.Int64("x", 3000), str: "3000", val: int64(3000)},
{name: "-1947", kv: model.Int64("x", -1947), str: "-1947", val: int64(-1947)},
{name: "3.141592654", kv: model.Float64("x", 3.14159265359), str: "3.141592654", val: float64(3.14159265359)},
{name: "42656e646572", kv: model.Binary("x", []byte("Bender")), str: "42656e646572", val: []byte("Bender")},
- {name: "binary string", kv: model.Binary("x", []byte(longString)), str: expectedBinaryStr, val: []byte(longString)},
- {name: "binary string (lossy)", kv: model.Binary("x", []byte(longString)), strLossy: expectedBinaryStrLossy, val: []byte(longString)},
+ {
+ name: "binary string",
+ kv: model.Binary("x", []byte(longString)),
+ str: expectedBinaryStr,
+ val: []byte(longString),
+ },
+ {
+ name: "binary string (lossy)",
+ kv: model.Binary("x", []byte(longString)),
+ strLossy: expectedBinaryStrLossy,
+ val: []byte(longString),
+ },
}
for _, tt := range testCases {
testCase := tt // capture loop var
diff --git a/model/prototest/model_test.pb.go b/model/prototest/model_test.pb.go
index dd5aa163506..7a0e3fe95c8 100644
--- a/model/prototest/model_test.pb.go
+++ b/model/prototest/model_test.pb.go
@@ -85,8 +85,8 @@ type SpanRef struct {
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
- TraceId []byte `protobuf:"bytes,1,opt,name=trace_id,json=traceId,proto3" json:"trace_id,omitempty"`
- SpanId []byte `protobuf:"bytes,2,opt,name=span_id,json=spanId,proto3" json:"span_id,omitempty"`
+ TraceId []byte `protobuf:"bytes,1,opt,name=trace_id,json=traceId,proto3" json:"trace_id,omitempty"`
+ SpanId []byte `protobuf:"bytes,2,opt,name=span_id,json=spanId,proto3" json:"span_id,omitempty"`
RefType SpanRefType `protobuf:"varint,3,opt,name=ref_type,json=refType,proto3,enum=prototest.SpanRefType" json:"ref_type,omitempty"`
}
@@ -169,7 +169,9 @@ var (
func file_model_test_proto_rawDescGZIP() []byte {
file_model_test_proto_rawDescOnce.Do(func() {
- file_model_test_proto_rawDescData = protoimpl.X.CompressGZIP(file_model_test_proto_rawDescData)
+ file_model_test_proto_rawDescData = protoimpl.X.CompressGZIP(
+ file_model_test_proto_rawDescData,
+ )
})
return file_model_test_proto_rawDescData
}
diff --git a/model/sort.go b/model/sort.go
index b2556d8cc4c..6576c78b5d7 100644
--- a/model/sort.go
+++ b/model/sort.go
@@ -94,9 +94,14 @@ func sortTags(tags []KeyValue) {
type logByTimestamp []Log
-func (t logByTimestamp) Len() int { return len(t) }
-func (t logByTimestamp) Swap(i, j int) { t[i], t[j] = t[j], t[i] }
-func (t logByTimestamp) Less(i, j int) bool { return t[i].Timestamp.Before(t[j].Timestamp) }
+func (t logByTimestamp) Len() int { return len(t) }
+func (t logByTimestamp) Swap(i, j int) { t[i], t[j] = t[j], t[i] }
+
+func (t logByTimestamp) Less(
+ i, j int,
+) bool {
+ return t[i].Timestamp.Before(t[j].Timestamp)
+}
func sortLogs(logs []Log) {
sort.Sort(logByTimestamp(logs))
diff --git a/model/span.go b/model/span.go
index 833763efe90..9d22104fced 100644
--- a/model/span.go
+++ b/model/span.go
@@ -165,7 +165,8 @@ func (s *Span) ParentSpanID() SpanID {
func (s *Span) ReplaceParentID(newParentID SpanID) {
oldParentID := s.ParentSpanID()
for i := range s.References {
- if s.References[i].SpanID == oldParentID && s.References[i].TraceID == s.TraceID {
+ if s.References[i].SpanID == oldParentID &&
+ s.References[i].TraceID == s.TraceID {
s.References[i].SpanID = newParentID
return
}
diff --git a/model/span_test.go b/model/span_test.go
index 920d23623c3..57d7c6cff5f 100644
--- a/model/span_test.go
+++ b/model/span_test.go
@@ -41,8 +41,18 @@ var testCasesTraceID = []struct {
{lo: 15, hex: "000000000000000f", b64: "AAAAAAAAAAAAAAAAAAAADw=="},
{lo: 31, hex: "000000000000001f", b64: "AAAAAAAAAAAAAAAAAAAAHw=="},
{lo: 257, hex: "0000000000000101", b64: "AAAAAAAAAAAAAAAAAAABAQ=="},
- {hi: 1, lo: 1, hex: "00000000000000010000000000000001", b64: "AAAAAAAAAAEAAAAAAAAAAQ=="},
- {hi: 257, lo: 1, hex: "00000000000001010000000000000001", b64: "AAAAAAAAAQEAAAAAAAAAAQ=="},
+ {
+ hi: 1,
+ lo: 1,
+ hex: "00000000000000010000000000000001",
+ b64: "AAAAAAAAAAEAAAAAAAAAAQ==",
+ },
+ {
+ hi: 257,
+ lo: 1,
+ hex: "00000000000001010000000000000001",
+ b64: "AAAAAAAAAQEAAAAAAAAAAQ==",
+ },
}
func TestTraceIDMarshalJSONPB(t *testing.T) {
@@ -50,7 +60,9 @@ func TestTraceIDMarshalJSONPB(t *testing.T) {
t.Run(testCase.hex, func(t *testing.T) {
expected := fmt.Sprintf(`{"traceId":"%s"}`, testCase.b64)
- ref := model.SpanRef{TraceID: model.NewTraceID(testCase.hi, testCase.lo)}
+ ref := model.SpanRef{
+ TraceID: model.NewTraceID(testCase.hi, testCase.lo),
+ }
out := new(bytes.Buffer)
err := new(jsonpb.Marshaler).Marshal(out, &ref)
require.NoError(t, err)
@@ -123,7 +135,10 @@ const keySpanKind = "span.kind"
func TestSpanIDMarshalJSON(t *testing.T) {
for _, testCase := range testCasesSpanID {
- expected := fmt.Sprintf(`{"traceId":"AAAAAAAAAAAAAAAAAAAAAA==","spanId":"%s"}`, testCase.b64)
+ expected := fmt.Sprintf(
+ `{"traceId":"AAAAAAAAAAAAAAAAAAAAAA==","spanId":"%s"}`,
+ testCase.b64,
+ )
t.Run(testCase.hex, func(t *testing.T) {
ref := model.SpanRef{SpanID: model.SpanID(testCase.id)}
out := new(bytes.Buffer)
@@ -312,10 +327,12 @@ func makeSpan(someKV model.KeyValue) *model.Span {
TraceID: traceID,
SpanID: model.NewSpanID(567),
OperationName: "hi",
- References: []model.SpanRef{model.NewChildOfRef(traceID, model.NewSpanID(123))},
- StartTime: time.Unix(0, 1000),
- Duration: 5000,
- Tags: model.KeyValues{someKV},
+ References: []model.SpanRef{
+ model.NewChildOfRef(traceID, model.NewSpanID(123)),
+ },
+ StartTime: time.Unix(0, 1000),
+ Duration: 5000,
+ Tags: model.KeyValues{someKV},
Logs: []model.Log{
{
Timestamp: time.Unix(0, 1000),
@@ -367,7 +384,10 @@ func BenchmarkBatchSerialization(b *testing.B) {
},
},
},
- Process: model.NewProcess("process1", []model.KeyValue{model.String("aaa", "bbb")}),
+ Process: model.NewProcess(
+ "process1",
+ []model.KeyValue{model.String("aaa", "bbb")},
+ ),
ProcessID: "156",
},
},
diff --git a/model/spanref.go b/model/spanref.go
index 92acc21e9a3..aa5e54bcadb 100644
--- a/model/spanref.go
+++ b/model/spanref.go
@@ -29,7 +29,11 @@ const (
// We no longer store ParentSpanID in the domain model, but the data in the database
// or other formats might still have these IDs without representing them in the References,
// so this converts parent IDs to canonical reference format.
-func MaybeAddParentSpanID(traceID TraceID, parentSpanID SpanID, refs []SpanRef) []SpanRef {
+func MaybeAddParentSpanID(
+ traceID TraceID,
+ parentSpanID SpanID,
+ refs []SpanRef,
+) []SpanRef {
if parentSpanID == 0 {
return refs
}
diff --git a/model/spanref_test.go b/model/spanref_test.go
index d605c86ca33..dd10035c7b5 100644
--- a/model/spanref_test.go
+++ b/model/spanref_test.go
@@ -38,7 +38,11 @@ func TestSpanRefTypeToFromJSON(t *testing.T) {
out := new(bytes.Buffer)
err := new(jsonpb.Marshaler).Marshal(out, &sr)
require.NoError(t, err)
- assert.Equal(t, `{"traceId":"AAAAAAAAAAAAAAAAAAAAQg==","spanId":"AAAAAAAAAEM=","refType":"FOLLOWS_FROM"}`, out.String())
+ assert.Equal(
+ t,
+ `{"traceId":"AAAAAAAAAAAAAAAAAAAAQg==","spanId":"AAAAAAAAAEM=","refType":"FOLLOWS_FROM"}`,
+ out.String(),
+ )
var sr2 model.SpanRef
require.NoError(t, jsonpb.Unmarshal(out, &sr2))
assert.Equal(t, sr, sr2)
@@ -52,16 +56,39 @@ func TestMaybeAddParentSpanID(t *testing.T) {
span := makeSpan(model.String("k", "v"))
assert.Equal(t, model.NewSpanID(123), span.ParentSpanID())
- span.References = model.MaybeAddParentSpanID(span.TraceID, model.NewSpanID(0), span.References)
+ span.References = model.MaybeAddParentSpanID(
+ span.TraceID,
+ model.NewSpanID(0),
+ span.References,
+ )
assert.Equal(t, model.NewSpanID(123), span.ParentSpanID())
- span.References = model.MaybeAddParentSpanID(span.TraceID, model.NewSpanID(123), span.References)
+ span.References = model.MaybeAddParentSpanID(
+ span.TraceID,
+ model.NewSpanID(123),
+ span.References,
+ )
assert.Equal(t, model.NewSpanID(123), span.ParentSpanID())
- span.References = model.MaybeAddParentSpanID(span.TraceID, model.NewSpanID(123), []model.SpanRef{})
+ span.References = model.MaybeAddParentSpanID(
+ span.TraceID,
+ model.NewSpanID(123),
+ []model.SpanRef{},
+ )
assert.Equal(t, model.NewSpanID(123), span.ParentSpanID())
- span.References = []model.SpanRef{model.NewChildOfRef(model.NewTraceID(42, 0), model.NewSpanID(789))}
- span.References = model.MaybeAddParentSpanID(span.TraceID, model.NewSpanID(123), span.References)
- assert.Equal(t, model.NewSpanID(123), span.References[0].SpanID, "parent added as first reference")
+ span.References = []model.SpanRef{
+ model.NewChildOfRef(model.NewTraceID(42, 0), model.NewSpanID(789)),
+ }
+ span.References = model.MaybeAddParentSpanID(
+ span.TraceID,
+ model.NewSpanID(123),
+ span.References,
+ )
+ assert.Equal(
+ t,
+ model.NewSpanID(123),
+ span.References[0].SpanID,
+ "parent added as first reference",
+ )
}
diff --git a/pkg/bearertoken/http.go b/pkg/bearertoken/http.go
index 8e264f9b444..93cfa4fc0e4 100644
--- a/pkg/bearertoken/http.go
+++ b/pkg/bearertoken/http.go
@@ -45,7 +45,9 @@ func PropagationHandler(logger *zap.Logger, h http.Handler) http.Handler {
// Treat the entire value as a token.
token = authHeaderValue
default:
- logger.Warn("Invalid authorization header value, skipping token propagation")
+ logger.Warn(
+ "Invalid authorization header value, skipping token propagation",
+ )
}
h.ServeHTTP(w, r.WithContext(ContextWithBearerToken(ctx, token)))
} else {
diff --git a/pkg/bearertoken/http_test.go b/pkg/bearertoken/http_test.go
index 52747a3c9b7..b88173e7094 100644
--- a/pkg/bearertoken/http_test.go
+++ b/pkg/bearertoken/http_test.go
@@ -60,12 +60,42 @@ func Test_PropagationHandler(t *testing.T) {
headerName string
handler func(stop *sync.WaitGroup) http.HandlerFunc
}{
- {name: "Bearer token", sendHeader: true, headerName: "Authorization", headerValue: "Bearer " + bearerToken, handler: validTokenHandler},
- {name: "Raw bearer token", sendHeader: true, headerName: "Authorization", headerValue: bearerToken, handler: validTokenHandler},
+ {
+ name: "Bearer token",
+ sendHeader: true,
+ headerName: "Authorization",
+ headerValue: "Bearer " + bearerToken,
+ handler: validTokenHandler,
+ },
+ {
+ name: "Raw bearer token",
+ sendHeader: true,
+ headerName: "Authorization",
+ headerValue: bearerToken,
+ handler: validTokenHandler,
+ },
{name: "No headerValue", sendHeader: false, headerName: "Authorization", handler: emptyHandler},
- {name: "Basic Auth", sendHeader: true, headerName: "Authorization", headerValue: "Basic " + bearerToken, handler: emptyHandler},
- {name: "X-Forwarded-Access-Token", headerName: "X-Forwarded-Access-Token", sendHeader: true, headerValue: "Bearer " + bearerToken, handler: validTokenHandler},
- {name: "Invalid header", headerName: "X-Forwarded-Access-Token", sendHeader: true, headerValue: "Bearer " + bearerToken + " another stuff", handler: emptyHandler},
+ {
+ name: "Basic Auth",
+ sendHeader: true,
+ headerName: "Authorization",
+ headerValue: "Basic " + bearerToken,
+ handler: emptyHandler,
+ },
+ {
+ name: "X-Forwarded-Access-Token",
+ headerName: "X-Forwarded-Access-Token",
+ sendHeader: true,
+ headerValue: "Bearer " + bearerToken,
+ handler: validTokenHandler,
+ },
+ {
+ name: "Invalid header",
+ headerName: "X-Forwarded-Access-Token",
+ sendHeader: true,
+ headerValue: "Bearer " + bearerToken + " another stuff",
+ handler: emptyHandler,
+ },
}
for _, testCase := range testCases {
diff --git a/pkg/bearertoken/transport_test.go b/pkg/bearertoken/transport_test.go
index 49a9acf900f..f4486f4920c 100644
--- a/pkg/bearertoken/transport_test.go
+++ b/pkg/bearertoken/transport_test.go
@@ -89,7 +89,12 @@ func TestRoundTripper(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
server := httptest.NewServer(nil)
defer server.Close()
- req, err := http.NewRequestWithContext(tc.requestContext, "GET", server.URL, nil)
+ req, err := http.NewRequestWithContext(
+ tc.requestContext,
+ "GET",
+ server.URL,
+ nil,
+ )
require.NoError(t, err)
tr := RoundTripper{
diff --git a/pkg/cache/lru.go b/pkg/cache/lru.go
index 0ffd0e63218..5160828d088 100644
--- a/pkg/cache/lru.go
+++ b/pkg/cache/lru.go
@@ -66,7 +66,8 @@ func (c *LRU) Get(key string) any {
}
cacheEntry := elt.Value.(*cacheEntry)
- if !cacheEntry.expiration.IsZero() && c.TimeNow().After(cacheEntry.expiration) {
+ if !cacheEntry.expiration.IsZero() &&
+ c.TimeNow().After(cacheEntry.expiration) {
// Entry has expired
if c.onEvict != nil {
c.onEvict(cacheEntry.key, cacheEntry.value)
@@ -90,7 +91,10 @@ func (c *LRU) Put(key string, value any) any {
// CompareAndSwap puts a new value associated with a given key if existing value matches oldValue.
// It returns itemInCache as the element in cache after the function is executed and replaced as true if value is replaced, false otherwise.
-func (c *LRU) CompareAndSwap(key string, oldValue, newValue any) (itemInCache any, replaced bool) {
+func (c *LRU) CompareAndSwap(
+ key string,
+ oldValue, newValue any,
+) (itemInCache any, replaced bool) {
c.mux.Lock()
defer c.mux.Unlock()
diff --git a/pkg/cassandra/config/config.go b/pkg/cassandra/config/config.go
index e898b74d6f6..97a93bc9933 100644
--- a/pkg/cassandra/config/config.go
+++ b/pkg/cassandra/config/config.go
@@ -31,21 +31,21 @@ import (
// Configuration describes the configuration properties needed to connect to a Cassandra cluster
type Configuration struct {
Servers []string `valid:"required,url" mapstructure:"servers"`
- Keyspace string `mapstructure:"keyspace"`
- LocalDC string `mapstructure:"local_dc"`
- ConnectionsPerHost int `mapstructure:"connections_per_host"`
- Timeout time.Duration `mapstructure:"-"`
- ConnectTimeout time.Duration `mapstructure:"connection_timeout"`
- ReconnectInterval time.Duration `mapstructure:"reconnect_interval"`
- SocketKeepAlive time.Duration `mapstructure:"socket_keep_alive"`
- MaxRetryAttempts int `mapstructure:"max_retry_attempts"`
- ProtoVersion int `mapstructure:"proto_version"`
- Consistency string `mapstructure:"consistency"`
- DisableCompression bool `mapstructure:"disable_compression"`
- Port int `mapstructure:"port"`
- Authenticator Authenticator `mapstructure:",squash"`
- DisableAutoDiscovery bool `mapstructure:"-"`
- TLS tlscfg.Options `mapstructure:"tls"`
+ Keyspace string ` mapstructure:"keyspace"`
+ LocalDC string ` mapstructure:"local_dc"`
+ ConnectionsPerHost int ` mapstructure:"connections_per_host"`
+ Timeout time.Duration ` mapstructure:"-"`
+ ConnectTimeout time.Duration ` mapstructure:"connection_timeout"`
+ ReconnectInterval time.Duration ` mapstructure:"reconnect_interval"`
+ SocketKeepAlive time.Duration ` mapstructure:"socket_keep_alive"`
+ MaxRetryAttempts int ` mapstructure:"max_retry_attempts"`
+ ProtoVersion int ` mapstructure:"proto_version"`
+ Consistency string ` mapstructure:"consistency"`
+ DisableCompression bool ` mapstructure:"disable_compression"`
+ Port int ` mapstructure:"port"`
+ Authenticator Authenticator ` mapstructure:",squash"`
+ DisableAutoDiscovery bool ` mapstructure:"-"`
+ TLS tlscfg.Options ` mapstructure:"tls"`
}
// Authenticator holds the authentication properties needed to connect to a Cassandra cluster
@@ -94,7 +94,9 @@ type SessionBuilder interface {
}
// NewSession creates a new Cassandra session
-func (c *Configuration) NewSession(logger *zap.Logger) (cassandra.Session, error) {
+func (c *Configuration) NewSession(
+ logger *zap.Logger,
+) (cassandra.Session, error) {
cluster, err := c.NewCluster(logger)
if err != nil {
return nil, err
@@ -107,7 +109,9 @@ func (c *Configuration) NewSession(logger *zap.Logger) (cassandra.Session, error
}
// NewCluster creates a new gocql cluster from the configuration
-func (c *Configuration) NewCluster(logger *zap.Logger) (*gocql.ClusterConfig, error) {
+func (c *Configuration) NewCluster(
+ logger *zap.Logger,
+) (*gocql.ClusterConfig, error) {
cluster := gocql.NewCluster(c.Servers...)
cluster.Keyspace = c.Keyspace
cluster.NumConns = c.ConnectionsPerHost
@@ -119,7 +123,9 @@ func (c *Configuration) NewCluster(logger *zap.Logger) (*gocql.ClusterConfig, er
cluster.ProtoVersion = c.ProtoVersion
}
if c.MaxRetryAttempts > 1 {
- cluster.RetryPolicy = &gocql.SimpleRetryPolicy{NumRetries: c.MaxRetryAttempts - 1}
+ cluster.RetryPolicy = &gocql.SimpleRetryPolicy{
+ NumRetries: c.MaxRetryAttempts - 1,
+ }
}
if c.Port != 0 {
cluster.Port = c.Port
@@ -139,9 +145,13 @@ func (c *Configuration) NewCluster(logger *zap.Logger) (*gocql.ClusterConfig, er
if c.LocalDC != "" {
fallbackHostSelectionPolicy = gocql.DCAwareRoundRobinPolicy(c.LocalDC)
}
- cluster.PoolConfig.HostSelectionPolicy = gocql.TokenAwareHostPolicy(fallbackHostSelectionPolicy, gocql.ShuffleReplicas())
+ cluster.PoolConfig.HostSelectionPolicy = gocql.TokenAwareHostPolicy(
+ fallbackHostSelectionPolicy,
+ gocql.ShuffleReplicas(),
+ )
- if c.Authenticator.Basic.Username != "" && c.Authenticator.Basic.Password != "" {
+ if c.Authenticator.Basic.Username != "" &&
+ c.Authenticator.Basic.Password != "" {
cluster.Authenticator = gocql.PasswordAuthenticator{
Username: c.Authenticator.Basic.Username,
Password: c.Authenticator.Basic.Password,
diff --git a/pkg/cassandra/gocql/testutils/udt_test.go b/pkg/cassandra/gocql/testutils/udt_test.go
index fcb2bac146e..ad999866860 100644
--- a/pkg/cassandra/gocql/testutils/udt_test.go
+++ b/pkg/cassandra/gocql/testutils/udt_test.go
@@ -19,7 +19,10 @@ type CustomUDT struct {
}
// MarshalUDT implements the gocql.UDTMarshaler interface.
-func (c *CustomUDT) MarshalUDT(name string, info gocql.TypeInfo) ([]byte, error) {
+func (c *CustomUDT) MarshalUDT(
+ name string,
+ info gocql.TypeInfo,
+) ([]byte, error) {
switch name {
case "Field1":
return gocql.Marshal(info, c.Field1)
@@ -31,7 +34,11 @@ func (c *CustomUDT) MarshalUDT(name string, info gocql.TypeInfo) ([]byte, error)
}
// UnmarshalUDT implements the gocql.UDTUnmarshaler interface.
-func (c *CustomUDT) UnmarshalUDT(name string, info gocql.TypeInfo, data []byte) error {
+func (c *CustomUDT) UnmarshalUDT(
+ name string,
+ info gocql.TypeInfo,
+ data []byte,
+) error {
switch name {
case "Field1":
return gocql.Unmarshal(info, data, &c.Field1)
diff --git a/pkg/cassandra/metrics/table.go b/pkg/cassandra/metrics/table.go
index 6df40c0c09e..3ce70efa765 100644
--- a/pkg/cassandra/metrics/table.go
+++ b/pkg/cassandra/metrics/table.go
@@ -34,7 +34,16 @@ type Table struct {
// NewTable takes a metrics scope and creates a table metrics struct
func NewTable(factory metrics.Factory, tableName string) *Table {
t := storageMetrics.WriteMetrics{}
- metrics.Init(&t, factory.Namespace(metrics.NSOptions{Name: "", Tags: map[string]string{"table": tableName}}), nil)
+ metrics.Init(
+ &t,
+ factory.Namespace(
+ metrics.NSOptions{
+ Name: "",
+ Tags: map[string]string{"table": tableName},
+ },
+ ),
+ nil,
+ )
return &Table{t}
}
@@ -46,7 +55,11 @@ func (t *Table) Exec(query cassandra.UpdateQuery, logger *zap.Logger) error {
if err != nil {
queryString := query.String()
if logger != nil {
- logger.Error("Failed to exec query", zap.String("query", queryString), zap.Error(err))
+ logger.Error(
+ "Failed to exec query",
+ zap.String("query", queryString),
+ zap.Error(err),
+ )
}
return fmt.Errorf("failed to Exec query '%s': %w", queryString, err)
}
diff --git a/pkg/clientcfg/clientcfghttp/cfgmgr.go b/pkg/clientcfg/clientcfghttp/cfgmgr.go
index 621162a36fe..18b4e6ff292 100644
--- a/pkg/clientcfg/clientcfghttp/cfgmgr.go
+++ b/pkg/clientcfg/clientcfghttp/cfgmgr.go
@@ -30,12 +30,18 @@ type ConfigManager struct {
}
// GetSamplingStrategy implements ClientConfigManager.GetSamplingStrategy.
-func (c *ConfigManager) GetSamplingStrategy(ctx context.Context, serviceName string) (*api_v2.SamplingStrategyResponse, error) {
+func (c *ConfigManager) GetSamplingStrategy(
+ ctx context.Context,
+ serviceName string,
+) (*api_v2.SamplingStrategyResponse, error) {
return c.SamplingStrategyStore.GetSamplingStrategy(ctx, serviceName)
}
// GetBaggageRestrictions implements ClientConfigManager.GetBaggageRestrictions.
-func (c *ConfigManager) GetBaggageRestrictions(ctx context.Context, serviceName string) ([]*baggage.BaggageRestriction, error) {
+func (c *ConfigManager) GetBaggageRestrictions(
+ ctx context.Context,
+ serviceName string,
+) ([]*baggage.BaggageRestriction, error) {
if c.BaggageManager == nil {
return nil, errors.New("baggage restrictions not implemented")
}
diff --git a/pkg/clientcfg/clientcfghttp/cfgmgr_test.go b/pkg/clientcfg/clientcfghttp/cfgmgr_test.go
index c5a7e2a9971..fbb777fa5b8 100644
--- a/pkg/clientcfg/clientcfghttp/cfgmgr_test.go
+++ b/pkg/clientcfg/clientcfghttp/cfgmgr_test.go
@@ -30,7 +30,10 @@ type mockSamplingStore struct {
samplingResponse *api_v2.SamplingStrategyResponse
}
-func (m *mockSamplingStore) GetSamplingStrategy(_ context.Context, serviceName string) (*api_v2.SamplingStrategyResponse, error) {
+func (m *mockSamplingStore) GetSamplingStrategy(
+ _ context.Context,
+ serviceName string,
+) (*api_v2.SamplingStrategyResponse, error) {
if m.samplingResponse == nil {
return nil, errors.New("no mock response provided")
}
@@ -45,7 +48,10 @@ type mockBaggageMgr struct {
baggageResponse []*baggage.BaggageRestriction
}
-func (m *mockBaggageMgr) GetBaggageRestrictions(_ context.Context, serviceName string) ([]*baggage.BaggageRestriction, error) {
+func (m *mockBaggageMgr) GetBaggageRestrictions(
+ _ context.Context,
+ serviceName string,
+) ([]*baggage.BaggageRestriction, error) {
if m.baggageResponse == nil {
return nil, errors.New("no mock response provided")
}
diff --git a/pkg/clientcfg/clientcfghttp/handler.go b/pkg/clientcfg/clientcfghttp/handler.go
index ab2cef08c5d..680501990a2 100644
--- a/pkg/clientcfg/clientcfghttp/handler.go
+++ b/pkg/clientcfg/clientcfghttp/handler.go
@@ -106,14 +106,22 @@ func (h *HTTPHandler) RegisterRoutes(router *mux.Router) {
router.HandleFunc(prefix+"/baggageRestrictions", func(w http.ResponseWriter, r *http.Request) {
h.serveBaggageHTTP(w, r)
- }).Methods(http.MethodGet)
+ }).
+ Methods(http.MethodGet)
}
-func (h *HTTPHandler) serviceFromRequest(w http.ResponseWriter, r *http.Request) (string, error) {
+func (h *HTTPHandler) serviceFromRequest(
+ w http.ResponseWriter,
+ r *http.Request,
+) (string, error) {
services := r.URL.Query()["service"]
if len(services) != 1 {
h.metrics.BadRequest.Inc(1)
- http.Error(w, "'service' parameter must be provided once", http.StatusBadRequest)
+ http.Error(
+ w,
+ "'service' parameter must be provided once",
+ http.StatusBadRequest,
+ )
return "", errBadRequest
}
return services[0], nil
@@ -137,10 +145,17 @@ func (h *HTTPHandler) serveSamplingHTTP(
if err != nil {
return
}
- resp, err := h.params.ConfigManager.GetSamplingStrategy(r.Context(), service)
+ resp, err := h.params.ConfigManager.GetSamplingStrategy(
+ r.Context(),
+ service,
+ )
if err != nil {
h.metrics.CollectorProxyFailures.Inc(1)
- http.Error(w, fmt.Sprintf("collector error: %+v", err), http.StatusInternalServerError)
+ http.Error(
+ w,
+ fmt.Sprintf("collector error: %+v", err),
+ http.StatusInternalServerError,
+ )
return
}
jsonBytes, err := encoder(resp)
@@ -153,11 +168,16 @@ func (h *HTTPHandler) serveSamplingHTTP(
}
}
-func (h *HTTPHandler) encodeThriftLegacy(strategy *api_v2.SamplingStrategyResponse) ([]byte, error) {
+func (h *HTTPHandler) encodeThriftLegacy(
+ strategy *api_v2.SamplingStrategyResponse,
+) ([]byte, error) {
tStrategy, err := t2p.ConvertSamplingResponseFromDomain(strategy)
if err != nil {
h.metrics.BadThriftFailures.Inc(1)
- return nil, fmt.Errorf("ConvertSamplingResponseFromDomain failed: %w", err)
+ return nil, fmt.Errorf(
+ "ConvertSamplingResponseFromDomain failed: %w",
+ err,
+ )
}
jsonBytes, err := json.Marshal(tStrategy)
if err != nil {
@@ -169,7 +189,9 @@ func (h *HTTPHandler) encodeThriftLegacy(strategy *api_v2.SamplingStrategyRespon
return jsonBytes, nil
}
-func (h *HTTPHandler) encodeProto(strategy *api_v2.SamplingStrategyResponse) ([]byte, error) {
+func (h *HTTPHandler) encodeProto(
+ strategy *api_v2.SamplingStrategyResponse,
+) ([]byte, error) {
str, err := p2json.SamplingStrategyResponseToJSON(strategy)
if err != nil {
h.metrics.BadProtoFailures.Inc(1)
@@ -184,10 +206,17 @@ func (h *HTTPHandler) serveBaggageHTTP(w http.ResponseWriter, r *http.Request) {
if err != nil {
return
}
- resp, err := h.params.ConfigManager.GetBaggageRestrictions(r.Context(), service)
+ resp, err := h.params.ConfigManager.GetBaggageRestrictions(
+ r.Context(),
+ service,
+ )
if err != nil {
h.metrics.CollectorProxyFailures.Inc(1)
- http.Error(w, fmt.Sprintf("collector error: %+v", err), http.StatusInternalServerError)
+ http.Error(
+ w,
+ fmt.Sprintf("collector error: %+v", err),
+ http.StatusInternalServerError,
+ )
return
}
// NB. it's literally impossible for this Marshal to fail
diff --git a/pkg/clientcfg/clientcfghttp/handler_test.go b/pkg/clientcfg/clientcfghttp/handler_test.go
index e08293b1d37..f6977bb3df6 100644
--- a/pkg/clientcfg/clientcfghttp/handler_test.go
+++ b/pkg/clientcfg/clientcfghttp/handler_test.go
@@ -84,66 +84,96 @@ func TestHTTPHandlerWithBasePath(t *testing.T) {
}
func testHTTPHandler(t *testing.T, basePath string) {
- withServer(basePath, rateLimiting(42), restrictions("luggage", 10), func(ts *testServer) {
- tests := []struct {
- endpoint string
- expOutput string
- }{
- {
- endpoint: "/",
- expOutput: `{"strategyType":1,"rateLimitingSampling":{"maxTracesPerSecond":42}}`,
- },
- {
- endpoint: "/sampling",
- expOutput: `{"strategyType":"RATE_LIMITING","rateLimitingSampling":{"maxTracesPerSecond":42}}`,
- },
- }
- for _, test := range tests {
- t.Run("endpoint="+test.endpoint, func(t *testing.T) {
- resp, err := http.Get(ts.server.URL + basePath + test.endpoint + "?service=Y")
- require.NoError(t, err)
- assert.Equal(t, http.StatusOK, resp.StatusCode)
- body, err := io.ReadAll(resp.Body)
- require.NoError(t, err)
- err = resp.Body.Close()
- require.NoError(t, err)
- assert.Equal(t, test.expOutput, string(body))
- if test.endpoint == "/" {
- objResp := &tSampling092.SamplingStrategyResponse{}
- require.NoError(t, json.Unmarshal(body, objResp))
- assert.EqualValues(t,
- ts.samplingStore.samplingResponse.GetStrategyType(),
- objResp.GetStrategyType())
- assert.EqualValues(t,
- ts.samplingStore.samplingResponse.GetRateLimitingSampling().GetMaxTracesPerSecond(),
- objResp.GetRateLimitingSampling().GetMaxTracesPerSecond())
- } else {
- objResp, err := p2json.SamplingStrategyResponseFromJSON(body)
+ withServer(
+ basePath,
+ rateLimiting(42),
+ restrictions("luggage", 10),
+ func(ts *testServer) {
+ tests := []struct {
+ endpoint string
+ expOutput string
+ }{
+ {
+ endpoint: "/",
+ expOutput: `{"strategyType":1,"rateLimitingSampling":{"maxTracesPerSecond":42}}`,
+ },
+ {
+ endpoint: "/sampling",
+ expOutput: `{"strategyType":"RATE_LIMITING","rateLimitingSampling":{"maxTracesPerSecond":42}}`,
+ },
+ }
+ for _, test := range tests {
+ t.Run("endpoint="+test.endpoint, func(t *testing.T) {
+ resp, err := http.Get(
+ ts.server.URL + basePath + test.endpoint + "?service=Y",
+ )
require.NoError(t, err)
- assert.EqualValues(t, ts.samplingStore.samplingResponse, objResp)
- }
- })
- }
+ assert.Equal(t, http.StatusOK, resp.StatusCode)
+ body, err := io.ReadAll(resp.Body)
+ require.NoError(t, err)
+ err = resp.Body.Close()
+ require.NoError(t, err)
+ assert.Equal(t, test.expOutput, string(body))
+ if test.endpoint == "/" {
+ objResp := &tSampling092.SamplingStrategyResponse{}
+ require.NoError(t, json.Unmarshal(body, objResp))
+ assert.EqualValues(t,
+ ts.samplingStore.samplingResponse.GetStrategyType(),
+ objResp.GetStrategyType())
+ assert.EqualValues(
+ t,
+ ts.samplingStore.samplingResponse.GetRateLimitingSampling().
+ GetMaxTracesPerSecond(),
+ objResp.GetRateLimitingSampling().
+ GetMaxTracesPerSecond(),
+ )
+ } else {
+ objResp, err := p2json.SamplingStrategyResponseFromJSON(body)
+ require.NoError(t, err)
+ assert.EqualValues(t, ts.samplingStore.samplingResponse, objResp)
+ }
+ })
+ }
- t.Run("request against endpoint /baggageRestrictions", func(t *testing.T) {
- resp, err := http.Get(ts.server.URL + basePath + "/baggageRestrictions?service=Y")
- require.NoError(t, err)
- assert.Equal(t, http.StatusOK, resp.StatusCode)
- body, err := io.ReadAll(resp.Body)
- resp.Body.Close()
- require.NoError(t, err)
- var objResp []*baggage.BaggageRestriction
- require.NoError(t, json.Unmarshal(body, &objResp))
- assert.EqualValues(t, ts.bgMgr.baggageResponse, objResp)
- })
+ t.Run(
+ "request against endpoint /baggageRestrictions",
+ func(t *testing.T) {
+ resp, err := http.Get(
+ ts.server.URL + basePath + "/baggageRestrictions?service=Y",
+ )
+ require.NoError(t, err)
+ assert.Equal(t, http.StatusOK, resp.StatusCode)
+ body, err := io.ReadAll(resp.Body)
+ resp.Body.Close()
+ require.NoError(t, err)
+ var objResp []*baggage.BaggageRestriction
+ require.NoError(t, json.Unmarshal(body, &objResp))
+ assert.EqualValues(t, ts.bgMgr.baggageResponse, objResp)
+ },
+ )
- // handler must emit metrics
- ts.metricsFactory.AssertCounterMetrics(t, []metricstest.ExpectedMetric{
- {Name: "http-server.requests", Tags: map[string]string{"type": "sampling"}, Value: 1},
- {Name: "http-server.requests", Tags: map[string]string{"type": "sampling-legacy"}, Value: 1},
- {Name: "http-server.requests", Tags: map[string]string{"type": "baggage"}, Value: 1},
- }...)
- })
+ // handler must emit metrics
+ ts.metricsFactory.AssertCounterMetrics(
+ t,
+ []metricstest.ExpectedMetric{
+ {
+ Name: "http-server.requests",
+ Tags: map[string]string{"type": "sampling"},
+ Value: 1,
+ },
+ {
+ Name: "http-server.requests",
+ Tags: map[string]string{"type": "sampling-legacy"},
+ Value: 1,
+ },
+ {
+ Name: "http-server.requests",
+ Tags: map[string]string{"type": "baggage"},
+ Value: 1,
+ },
+ }...)
+ },
+ )
}
func TestHTTPHandlerErrors(t *testing.T) {
@@ -162,7 +192,11 @@ func TestHTTPHandlerErrors(t *testing.T) {
statusCode: http.StatusBadRequest,
body: "'service' parameter must be provided once\n",
metrics: []metricstest.ExpectedMetric{
- {Name: "http-server.errors", Tags: map[string]string{"source": "all", "status": "4xx"}, Value: 1},
+ {
+ Name: "http-server.errors",
+ Tags: map[string]string{"source": "all", "status": "4xx"},
+ Value: 1,
+ },
},
},
{
@@ -171,7 +205,11 @@ func TestHTTPHandlerErrors(t *testing.T) {
statusCode: http.StatusBadRequest,
body: "'service' parameter must be provided once\n",
metrics: []metricstest.ExpectedMetric{
- {Name: "http-server.errors", Tags: map[string]string{"source": "all", "status": "4xx"}, Value: 1},
+ {
+ Name: "http-server.errors",
+ Tags: map[string]string{"source": "all", "status": "4xx"},
+ Value: 1,
+ },
},
},
{
@@ -180,7 +218,11 @@ func TestHTTPHandlerErrors(t *testing.T) {
statusCode: http.StatusBadRequest,
body: "'service' parameter must be provided once\n",
metrics: []metricstest.ExpectedMetric{
- {Name: "http-server.errors", Tags: map[string]string{"source": "all", "status": "4xx"}, Value: 1},
+ {
+ Name: "http-server.errors",
+ Tags: map[string]string{"source": "all", "status": "4xx"},
+ Value: 1,
+ },
},
},
{
@@ -189,7 +231,11 @@ func TestHTTPHandlerErrors(t *testing.T) {
statusCode: http.StatusInternalServerError,
body: "collector error: no mock response provided\n",
metrics: []metricstest.ExpectedMetric{
- {Name: "http-server.errors", Tags: map[string]string{"source": "collector-proxy", "status": "5xx"}, Value: 1},
+ {
+ Name: "http-server.errors",
+ Tags: map[string]string{"source": "collector-proxy", "status": "5xx"},
+ Value: 1,
+ },
},
},
{
@@ -198,7 +244,11 @@ func TestHTTPHandlerErrors(t *testing.T) {
statusCode: http.StatusInternalServerError,
body: "collector error: no mock response provided\n",
metrics: []metricstest.ExpectedMetric{
- {Name: "http-server.errors", Tags: map[string]string{"source": "collector-proxy", "status": "5xx"}, Value: 1},
+ {
+ Name: "http-server.errors",
+ Tags: map[string]string{"source": "collector-proxy", "status": "5xx"},
+ Value: 1,
+ },
},
},
{
@@ -208,67 +258,129 @@ func TestHTTPHandlerErrors(t *testing.T) {
statusCode: http.StatusInternalServerError,
body: "cannot marshall to JSON\n",
metrics: []metricstest.ExpectedMetric{
- {Name: "http-server.errors", Tags: map[string]string{"source": "thrift", "status": "5xx"}, Value: 1},
+ {
+ Name: "http-server.errors",
+ Tags: map[string]string{
+ "source": "thrift",
+ "status": "5xx",
+ },
+ Value: 1,
+ },
},
},
}
for _, tc := range testCases {
testCase := tc // capture loop var
t.Run(testCase.description, func(t *testing.T) {
- withServer("", testCase.mockSamplingResponse, testCase.mockBaggageResponse, func(ts *testServer) {
- resp, err := http.Get(ts.server.URL + testCase.url)
- require.NoError(t, err)
- assert.Equal(t, testCase.statusCode, resp.StatusCode)
- if testCase.body != "" {
- body, err := io.ReadAll(resp.Body)
+ withServer(
+ "",
+ testCase.mockSamplingResponse,
+ testCase.mockBaggageResponse,
+ func(ts *testServer) {
+ resp, err := http.Get(ts.server.URL + testCase.url)
require.NoError(t, err)
- assert.Equal(t, testCase.body, string(body))
- }
+ assert.Equal(t, testCase.statusCode, resp.StatusCode)
+ if testCase.body != "" {
+ body, err := io.ReadAll(resp.Body)
+ require.NoError(t, err)
+ assert.Equal(t, testCase.body, string(body))
+ }
- if len(testCase.metrics) > 0 {
- ts.metricsFactory.AssertCounterMetrics(t, testCase.metrics...)
- }
- })
+ if len(testCase.metrics) > 0 {
+ ts.metricsFactory.AssertCounterMetrics(
+ t,
+ testCase.metrics...)
+ }
+ },
+ )
})
}
t.Run("failure to write a response", func(t *testing.T) {
- withServer("", probabilistic(0.001), restrictions("luggage", 10), func(ts *testServer) {
- handler := ts.handler
+ withServer(
+ "",
+ probabilistic(0.001),
+ restrictions("luggage", 10),
+ func(ts *testServer) {
+ handler := ts.handler
- req := httptest.NewRequest("GET", "http://localhost:80/?service=X", nil)
- w := &mockWriter{header: make(http.Header)}
- handler.serveSamplingHTTP(w, req, handler.encodeThriftLegacy)
+ req := httptest.NewRequest(
+ "GET",
+ "http://localhost:80/?service=X",
+ nil,
+ )
+ w := &mockWriter{header: make(http.Header)}
+ handler.serveSamplingHTTP(w, req, handler.encodeThriftLegacy)
- ts.metricsFactory.AssertCounterMetrics(t,
- metricstest.ExpectedMetric{Name: "http-server.errors", Tags: map[string]string{"source": "write", "status": "5xx"}, Value: 1})
+ ts.metricsFactory.AssertCounterMetrics(
+ t,
+ metricstest.ExpectedMetric{
+ Name: "http-server.errors",
+ Tags: map[string]string{"source": "write", "status": "5xx"},
+ Value: 1,
+ },
+ )
- req = httptest.NewRequest("GET", "http://localhost:80/baggageRestrictions?service=X", nil)
- handler.serveBaggageHTTP(w, req)
+ req = httptest.NewRequest(
+ "GET",
+ "http://localhost:80/baggageRestrictions?service=X",
+ nil,
+ )
+ handler.serveBaggageHTTP(w, req)
- ts.metricsFactory.AssertCounterMetrics(t,
- metricstest.ExpectedMetric{Name: "http-server.errors", Tags: map[string]string{"source": "write", "status": "5xx"}, Value: 2})
- })
+ ts.metricsFactory.AssertCounterMetrics(
+ t,
+ metricstest.ExpectedMetric{
+ Name: "http-server.errors",
+ Tags: map[string]string{"source": "write", "status": "5xx"},
+ Value: 2,
+ },
+ )
+ })
})
}
func TestEncodeErrors(t *testing.T) {
withServer("", nil, nil, func(server *testServer) {
- _, err := server.handler.encodeThriftLegacy(&api_v2.SamplingStrategyResponse{
- StrategyType: -1,
- })
+ _, err := server.handler.encodeThriftLegacy(
+ &api_v2.SamplingStrategyResponse{
+ StrategyType: -1,
+ },
+ )
require.Error(t, err)
- assert.Contains(t, err.Error(), "ConvertSamplingResponseFromDomain failed")
- server.metricsFactory.AssertCounterMetrics(t, []metricstest.ExpectedMetric{
- {Name: "http-server.errors", Tags: map[string]string{"source": "thrift", "status": "5xx"}, Value: 1},
- }...)
+ assert.Contains(
+ t,
+ err.Error(),
+ "ConvertSamplingResponseFromDomain failed",
+ )
+ server.metricsFactory.AssertCounterMetrics(
+ t,
+ []metricstest.ExpectedMetric{
+ {
+ Name: "http-server.errors",
+ Tags: map[string]string{
+ "source": "thrift",
+ "status": "5xx",
+ },
+ Value: 1,
+ },
+ }...)
_, err = server.handler.encodeProto(nil)
require.Error(t, err)
assert.Contains(t, err.Error(), "SamplingStrategyResponseToJSON failed")
- server.metricsFactory.AssertCounterMetrics(t, []metricstest.ExpectedMetric{
- {Name: "http-server.errors", Tags: map[string]string{"source": "proto", "status": "5xx"}, Value: 1},
- }...)
+ server.metricsFactory.AssertCounterMetrics(
+ t,
+ []metricstest.ExpectedMetric{
+ {
+ Name: "http-server.errors",
+ Tags: map[string]string{
+ "source": "proto",
+ "status": "5xx",
+ },
+ Value: 1,
+ },
+ }...)
})
}
diff --git a/pkg/clientcfg/clientcfghttp/thrift-0.9.2/ttypes.go b/pkg/clientcfg/clientcfghttp/thrift-0.9.2/ttypes.go
index 530ac478d9e..d598cee275d 100644
--- a/pkg/clientcfg/clientcfghttp/thrift-0.9.2/ttypes.go
+++ b/pkg/clientcfg/clientcfghttp/thrift-0.9.2/ttypes.go
@@ -56,10 +56,18 @@ func SamplingStrategyTypeFromString(s string) (SamplingStrategyType, error) {
case "SamplingStrategyType_RATE_LIMITING":
return SamplingStrategyType_RATE_LIMITING, nil
}
- return SamplingStrategyType(0), fmt.Errorf("not a valid SamplingStrategyType string")
+ return SamplingStrategyType(
+ 0,
+ ), fmt.Errorf(
+ "not a valid SamplingStrategyType string",
+ )
}
-func SamplingStrategyTypePtr(v SamplingStrategyType) *SamplingStrategyType { return &v }
+func SamplingStrategyTypePtr(
+ v SamplingStrategyType,
+) *SamplingStrategyType {
+ return &v
+}
type ProbabilisticSamplingStrategy struct {
SamplingRate float64 `thrift:"samplingRate,1,required" json:"samplingRate"`
@@ -105,7 +113,9 @@ func (p *ProbabilisticSamplingStrategy) Read(iprot thrift.TProtocol) error {
return nil
}
-func (p *ProbabilisticSamplingStrategy) ReadField1(iprot thrift.TProtocol) error {
+func (p *ProbabilisticSamplingStrategy) ReadField1(
+ iprot thrift.TProtocol,
+) error {
if v, err := iprot.ReadDouble(context.Background()); err != nil {
return fmt.Errorf("error reading field 1: %s", err)
} else {
@@ -131,10 +141,16 @@ func (p *ProbabilisticSamplingStrategy) Write(oprot thrift.TProtocol) error {
return nil
}
-func (p *ProbabilisticSamplingStrategy) writeField1(oprot thrift.TProtocol) (err error) {
+func (p *ProbabilisticSamplingStrategy) writeField1(
+ oprot thrift.TProtocol,
+) (err error) {
ctx := context.Background()
if err := oprot.WriteFieldBegin(ctx, "samplingRate", thrift.DOUBLE, 1); err != nil {
- return fmt.Errorf("%T write field begin error 1:samplingRate: %s", p, err)
+ return fmt.Errorf(
+ "%T write field begin error 1:samplingRate: %s",
+ p,
+ err,
+ )
}
if err := oprot.WriteDouble(ctx, float64(p.SamplingRate)); err != nil {
return fmt.Errorf("%T.samplingRate (1) field write error: %s", p, err)
@@ -196,7 +212,9 @@ func (p *RateLimitingSamplingStrategy) Read(iprot thrift.TProtocol) error {
return nil
}
-func (p *RateLimitingSamplingStrategy) ReadField1(iprot thrift.TProtocol) error {
+func (p *RateLimitingSamplingStrategy) ReadField1(
+ iprot thrift.TProtocol,
+) error {
if v, err := iprot.ReadI16(context.Background()); err != nil {
return fmt.Errorf("error reading field 1: %s", err)
} else {
@@ -222,16 +240,30 @@ func (p *RateLimitingSamplingStrategy) Write(oprot thrift.TProtocol) error {
return nil
}
-func (p *RateLimitingSamplingStrategy) writeField1(oprot thrift.TProtocol) (err error) {
+func (p *RateLimitingSamplingStrategy) writeField1(
+ oprot thrift.TProtocol,
+) (err error) {
ctx := context.Background()
if err := oprot.WriteFieldBegin(ctx, "maxTracesPerSecond", thrift.I16, 1); err != nil {
- return fmt.Errorf("%T write field begin error 1:maxTracesPerSecond: %s", p, err)
+ return fmt.Errorf(
+ "%T write field begin error 1:maxTracesPerSecond: %s",
+ p,
+ err,
+ )
}
if err := oprot.WriteI16(ctx, int16(p.MaxTracesPerSecond)); err != nil {
- return fmt.Errorf("%T.maxTracesPerSecond (1) field write error: %s", p, err)
+ return fmt.Errorf(
+ "%T.maxTracesPerSecond (1) field write error: %s",
+ p,
+ err,
+ )
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
- return fmt.Errorf("%T write field end error 1:maxTracesPerSecond: %s", p, err)
+ return fmt.Errorf(
+ "%T write field end error 1:maxTracesPerSecond: %s",
+ p,
+ err,
+ )
}
return err
}
@@ -244,7 +276,7 @@ func (p *RateLimitingSamplingStrategy) String() string {
}
type OperationSamplingStrategy struct {
- Operation string `thrift:"operation,1,required" json:"operation"`
+ Operation string `thrift:"operation,1,required" json:"operation"`
ProbabilisticSampling *ProbabilisticSamplingStrategy `thrift:"probabilisticSampling,2,required" json:"probabilisticSampling"`
}
@@ -317,7 +349,11 @@ func (p *OperationSamplingStrategy) ReadField1(iprot thrift.TProtocol) error {
func (p *OperationSamplingStrategy) ReadField2(iprot thrift.TProtocol) error {
p.ProbabilisticSampling = &ProbabilisticSamplingStrategy{}
if err := p.ProbabilisticSampling.Read(iprot); err != nil {
- return fmt.Errorf("%T error reading struct: %s", p.ProbabilisticSampling, err)
+ return fmt.Errorf(
+ "%T error reading struct: %s",
+ p.ProbabilisticSampling,
+ err,
+ )
}
return nil
}
@@ -342,7 +378,9 @@ func (p *OperationSamplingStrategy) Write(oprot thrift.TProtocol) error {
return nil
}
-func (p *OperationSamplingStrategy) writeField1(oprot thrift.TProtocol) (err error) {
+func (p *OperationSamplingStrategy) writeField1(
+ oprot thrift.TProtocol,
+) (err error) {
ctx := context.Background()
if err := oprot.WriteFieldBegin(ctx, "operation", thrift.STRING, 1); err != nil {
return fmt.Errorf("%T write field begin error 1:operation: %s", p, err)
@@ -356,16 +394,30 @@ func (p *OperationSamplingStrategy) writeField1(oprot thrift.TProtocol) (err err
return err
}
-func (p *OperationSamplingStrategy) writeField2(oprot thrift.TProtocol) (err error) {
+func (p *OperationSamplingStrategy) writeField2(
+ oprot thrift.TProtocol,
+) (err error) {
ctx := context.Background()
if err := oprot.WriteFieldBegin(ctx, "probabilisticSampling", thrift.STRUCT, 2); err != nil {
- return fmt.Errorf("%T write field begin error 2:probabilisticSampling: %s", p, err)
+ return fmt.Errorf(
+ "%T write field begin error 2:probabilisticSampling: %s",
+ p,
+ err,
+ )
}
if err := p.ProbabilisticSampling.Write(oprot); err != nil {
- return fmt.Errorf("%T error writing struct: %s", p.ProbabilisticSampling, err)
+ return fmt.Errorf(
+ "%T error writing struct: %s",
+ p.ProbabilisticSampling,
+ err,
+ )
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
- return fmt.Errorf("%T write field end error 2:probabilisticSampling: %s", p, err)
+ return fmt.Errorf(
+ "%T write field end error 2:probabilisticSampling: %s",
+ p,
+ err,
+ )
}
return err
}
@@ -378,9 +430,9 @@ func (p *OperationSamplingStrategy) String() string {
}
type PerOperationSamplingStrategies struct {
- DefaultSamplingProbability float64 `thrift:"defaultSamplingProbability,1,required" json:"defaultSamplingProbability"`
+ DefaultSamplingProbability float64 `thrift:"defaultSamplingProbability,1,required" json:"defaultSamplingProbability"`
DefaultLowerBoundTracesPerSecond float64 `thrift:"defaultLowerBoundTracesPerSecond,2,required" json:"defaultLowerBoundTracesPerSecond"`
- PerOperationStrategies []*OperationSamplingStrategy `thrift:"perOperationStrategies,3,required" json:"perOperationStrategies"`
+ PerOperationStrategies []*OperationSamplingStrategy `thrift:"perOperationStrategies,3,required" json:"perOperationStrategies"`
}
func NewPerOperationSamplingStrategies() *PerOperationSamplingStrategies {
@@ -439,7 +491,9 @@ func (p *PerOperationSamplingStrategies) Read(iprot thrift.TProtocol) error {
return nil
}
-func (p *PerOperationSamplingStrategies) ReadField1(iprot thrift.TProtocol) error {
+func (p *PerOperationSamplingStrategies) ReadField1(
+ iprot thrift.TProtocol,
+) error {
if v, err := iprot.ReadDouble(context.Background()); err != nil {
return fmt.Errorf("error reading field 1: %s", err)
} else {
@@ -448,7 +502,9 @@ func (p *PerOperationSamplingStrategies) ReadField1(iprot thrift.TProtocol) erro
return nil
}
-func (p *PerOperationSamplingStrategies) ReadField2(iprot thrift.TProtocol) error {
+func (p *PerOperationSamplingStrategies) ReadField2(
+ iprot thrift.TProtocol,
+) error {
if v, err := iprot.ReadDouble(context.Background()); err != nil {
return fmt.Errorf("error reading field 2: %s", err)
} else {
@@ -457,7 +513,9 @@ func (p *PerOperationSamplingStrategies) ReadField2(iprot thrift.TProtocol) erro
return nil
}
-func (p *PerOperationSamplingStrategies) ReadField3(iprot thrift.TProtocol) error {
+func (p *PerOperationSamplingStrategies) ReadField3(
+ iprot thrift.TProtocol,
+) error {
ctx := context.Background()
_, size, err := iprot.ReadListBegin(ctx)
if err != nil {
@@ -501,38 +559,72 @@ func (p *PerOperationSamplingStrategies) Write(oprot thrift.TProtocol) error {
return nil
}
-func (p *PerOperationSamplingStrategies) writeField1(oprot thrift.TProtocol) (err error) {
+func (p *PerOperationSamplingStrategies) writeField1(
+ oprot thrift.TProtocol,
+) (err error) {
ctx := context.Background()
if err := oprot.WriteFieldBegin(ctx, "defaultSamplingProbability", thrift.DOUBLE, 1); err != nil {
- return fmt.Errorf("%T write field begin error 1:defaultSamplingProbability: %s", p, err)
+ return fmt.Errorf(
+ "%T write field begin error 1:defaultSamplingProbability: %s",
+ p,
+ err,
+ )
}
if err := oprot.WriteDouble(ctx, float64(p.DefaultSamplingProbability)); err != nil {
- return fmt.Errorf("%T.defaultSamplingProbability (1) field write error: %s", p, err)
+ return fmt.Errorf(
+ "%T.defaultSamplingProbability (1) field write error: %s",
+ p,
+ err,
+ )
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
- return fmt.Errorf("%T write field end error 1:defaultSamplingProbability: %s", p, err)
+ return fmt.Errorf(
+ "%T write field end error 1:defaultSamplingProbability: %s",
+ p,
+ err,
+ )
}
return err
}
-func (p *PerOperationSamplingStrategies) writeField2(oprot thrift.TProtocol) (err error) {
+func (p *PerOperationSamplingStrategies) writeField2(
+ oprot thrift.TProtocol,
+) (err error) {
ctx := context.Background()
if err := oprot.WriteFieldBegin(ctx, "defaultLowerBoundTracesPerSecond", thrift.DOUBLE, 2); err != nil {
- return fmt.Errorf("%T write field begin error 2:defaultLowerBoundTracesPerSecond: %s", p, err)
+ return fmt.Errorf(
+ "%T write field begin error 2:defaultLowerBoundTracesPerSecond: %s",
+ p,
+ err,
+ )
}
if err := oprot.WriteDouble(ctx, float64(p.DefaultLowerBoundTracesPerSecond)); err != nil {
- return fmt.Errorf("%T.defaultLowerBoundTracesPerSecond (2) field write error: %s", p, err)
+ return fmt.Errorf(
+ "%T.defaultLowerBoundTracesPerSecond (2) field write error: %s",
+ p,
+ err,
+ )
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
- return fmt.Errorf("%T write field end error 2:defaultLowerBoundTracesPerSecond: %s", p, err)
+ return fmt.Errorf(
+ "%T write field end error 2:defaultLowerBoundTracesPerSecond: %s",
+ p,
+ err,
+ )
}
return err
}
-func (p *PerOperationSamplingStrategies) writeField3(oprot thrift.TProtocol) (err error) {
+func (p *PerOperationSamplingStrategies) writeField3(
+ oprot thrift.TProtocol,
+) (err error) {
ctx := context.Background()
if err := oprot.WriteFieldBegin(ctx, "perOperationStrategies", thrift.LIST, 3); err != nil {
- return fmt.Errorf("%T write field begin error 3:perOperationStrategies: %s", p, err)
+ return fmt.Errorf(
+ "%T write field begin error 3:perOperationStrategies: %s",
+ p,
+ err,
+ )
}
if err := oprot.WriteListBegin(ctx, thrift.STRUCT, len(p.PerOperationStrategies)); err != nil {
return fmt.Errorf("error writing list begin: %s", err)
@@ -546,7 +638,11 @@ func (p *PerOperationSamplingStrategies) writeField3(oprot thrift.TProtocol) (er
return fmt.Errorf("error writing list end: %s", err)
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
- return fmt.Errorf("%T write field end error 3:perOperationStrategies: %s", p, err)
+ return fmt.Errorf(
+ "%T write field end error 3:perOperationStrategies: %s",
+ p,
+ err,
+ )
}
return err
}
@@ -561,8 +657,8 @@ func (p *PerOperationSamplingStrategies) String() string {
type SamplingStrategyResponse struct {
StrategyType SamplingStrategyType `thrift:"strategyType,1,required" json:"strategyType"`
ProbabilisticSampling *ProbabilisticSamplingStrategy `thrift:"probabilisticSampling,2" json:"probabilisticSampling"`
- RateLimitingSampling *RateLimitingSamplingStrategy `thrift:"rateLimitingSampling,3" json:"rateLimitingSampling"`
- OperationSampling *PerOperationSamplingStrategies `thrift:"operationSampling,4" json:"operationSampling"`
+ RateLimitingSampling *RateLimitingSamplingStrategy `thrift:"rateLimitingSampling,3" json:"rateLimitingSampling"`
+ OperationSampling *PerOperationSamplingStrategies `thrift:"operationSampling,4" json:"operationSampling"`
}
func NewSamplingStrategyResponse() *SamplingStrategyResponse {
@@ -669,7 +765,11 @@ func (p *SamplingStrategyResponse) ReadField1(iprot thrift.TProtocol) error {
func (p *SamplingStrategyResponse) ReadField2(iprot thrift.TProtocol) error {
p.ProbabilisticSampling = &ProbabilisticSamplingStrategy{}
if err := p.ProbabilisticSampling.Read(iprot); err != nil {
- return fmt.Errorf("%T error reading struct: %s", p.ProbabilisticSampling, err)
+ return fmt.Errorf(
+ "%T error reading struct: %s",
+ p.ProbabilisticSampling,
+ err,
+ )
}
return nil
}
@@ -677,7 +777,11 @@ func (p *SamplingStrategyResponse) ReadField2(iprot thrift.TProtocol) error {
func (p *SamplingStrategyResponse) ReadField3(iprot thrift.TProtocol) error {
p.RateLimitingSampling = &RateLimitingSamplingStrategy{}
if err := p.RateLimitingSampling.Read(iprot); err != nil {
- return fmt.Errorf("%T error reading struct: %s", p.RateLimitingSampling, err)
+ return fmt.Errorf(
+ "%T error reading struct: %s",
+ p.RateLimitingSampling,
+ err,
+ )
}
return nil
}
@@ -685,7 +789,11 @@ func (p *SamplingStrategyResponse) ReadField3(iprot thrift.TProtocol) error {
func (p *SamplingStrategyResponse) ReadField4(iprot thrift.TProtocol) error {
p.OperationSampling = &PerOperationSamplingStrategies{}
if err := p.OperationSampling.Read(iprot); err != nil {
- return fmt.Errorf("%T error reading struct: %s", p.OperationSampling, err)
+ return fmt.Errorf(
+ "%T error reading struct: %s",
+ p.OperationSampling,
+ err,
+ )
}
return nil
}
@@ -716,10 +824,16 @@ func (p *SamplingStrategyResponse) Write(oprot thrift.TProtocol) error {
return nil
}
-func (p *SamplingStrategyResponse) writeField1(oprot thrift.TProtocol) (err error) {
+func (p *SamplingStrategyResponse) writeField1(
+ oprot thrift.TProtocol,
+) (err error) {
ctx := context.Background()
if err := oprot.WriteFieldBegin(ctx, "strategyType", thrift.I32, 1); err != nil {
- return fmt.Errorf("%T write field begin error 1:strategyType: %s", p, err)
+ return fmt.Errorf(
+ "%T write field begin error 1:strategyType: %s",
+ p,
+ err,
+ )
}
if err := oprot.WriteI32(ctx, int32(p.StrategyType)); err != nil {
return fmt.Errorf("%T.strategyType (1) field write error: %s", p, err)
@@ -730,49 +844,91 @@ func (p *SamplingStrategyResponse) writeField1(oprot thrift.TProtocol) (err erro
return err
}
-func (p *SamplingStrategyResponse) writeField2(oprot thrift.TProtocol) (err error) {
+func (p *SamplingStrategyResponse) writeField2(
+ oprot thrift.TProtocol,
+) (err error) {
ctx := context.Background()
if p.IsSetProbabilisticSampling() {
if err := oprot.WriteFieldBegin(ctx, "probabilisticSampling", thrift.STRUCT, 2); err != nil {
- return fmt.Errorf("%T write field begin error 2:probabilisticSampling: %s", p, err)
+ return fmt.Errorf(
+ "%T write field begin error 2:probabilisticSampling: %s",
+ p,
+ err,
+ )
}
if err := p.ProbabilisticSampling.Write(oprot); err != nil {
- return fmt.Errorf("%T error writing struct: %s", p.ProbabilisticSampling, err)
+ return fmt.Errorf(
+ "%T error writing struct: %s",
+ p.ProbabilisticSampling,
+ err,
+ )
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
- return fmt.Errorf("%T write field end error 2:probabilisticSampling: %s", p, err)
+ return fmt.Errorf(
+ "%T write field end error 2:probabilisticSampling: %s",
+ p,
+ err,
+ )
}
}
return err
}
-func (p *SamplingStrategyResponse) writeField3(oprot thrift.TProtocol) (err error) {
+func (p *SamplingStrategyResponse) writeField3(
+ oprot thrift.TProtocol,
+) (err error) {
ctx := context.Background()
if p.IsSetRateLimitingSampling() {
if err := oprot.WriteFieldBegin(ctx, "rateLimitingSampling", thrift.STRUCT, 3); err != nil {
- return fmt.Errorf("%T write field begin error 3:rateLimitingSampling: %s", p, err)
+ return fmt.Errorf(
+ "%T write field begin error 3:rateLimitingSampling: %s",
+ p,
+ err,
+ )
}
if err := p.RateLimitingSampling.Write(oprot); err != nil {
- return fmt.Errorf("%T error writing struct: %s", p.RateLimitingSampling, err)
+ return fmt.Errorf(
+ "%T error writing struct: %s",
+ p.RateLimitingSampling,
+ err,
+ )
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
- return fmt.Errorf("%T write field end error 3:rateLimitingSampling: %s", p, err)
+ return fmt.Errorf(
+ "%T write field end error 3:rateLimitingSampling: %s",
+ p,
+ err,
+ )
}
}
return err
}
-func (p *SamplingStrategyResponse) writeField4(oprot thrift.TProtocol) (err error) {
+func (p *SamplingStrategyResponse) writeField4(
+ oprot thrift.TProtocol,
+) (err error) {
ctx := context.Background()
if p.IsSetOperationSampling() {
if err := oprot.WriteFieldBegin(ctx, "operationSampling", thrift.STRUCT, 4); err != nil {
- return fmt.Errorf("%T write field begin error 4:operationSampling: %s", p, err)
+ return fmt.Errorf(
+ "%T write field begin error 4:operationSampling: %s",
+ p,
+ err,
+ )
}
if err := p.OperationSampling.Write(oprot); err != nil {
- return fmt.Errorf("%T error writing struct: %s", p.OperationSampling, err)
+ return fmt.Errorf(
+ "%T error writing struct: %s",
+ p.OperationSampling,
+ err,
+ )
}
if err := oprot.WriteFieldEnd(ctx); err != nil {
- return fmt.Errorf("%T write field end error 4:operationSampling: %s", p, err)
+ return fmt.Errorf(
+ "%T write field end error 4:operationSampling: %s",
+ p,
+ err,
+ )
}
}
return err
diff --git a/pkg/config/config.go b/pkg/config/config.go
index 96290b6763d..1e9f16c9ff8 100644
--- a/pkg/config/config.go
+++ b/pkg/config/config.go
@@ -31,7 +31,11 @@ func Viperize(inits ...func(*flag.FlagSet)) (*viper.Viper, *cobra.Command) {
}
// AddFlags adds flags to command and viper and configures
-func AddFlags(v *viper.Viper, command *cobra.Command, inits ...func(*flag.FlagSet)) (*viper.Viper, *cobra.Command) {
+func AddFlags(
+ v *viper.Viper,
+ command *cobra.Command,
+ inits ...func(*flag.FlagSet),
+) (*viper.Viper, *cobra.Command) {
flagSet := new(flag.FlagSet)
for i := range inits {
inits[i](flagSet)
diff --git a/pkg/config/corscfg/flags.go b/pkg/config/corscfg/flags.go
index 7ccaffe7e1c..e3e2db99847 100644
--- a/pkg/config/corscfg/flags.go
+++ b/pkg/config/corscfg/flags.go
@@ -32,8 +32,16 @@ type Flags struct {
}
func (c Flags) AddFlags(flags *flag.FlagSet) {
- flags.String(c.Prefix+corsAllowedHeaders, "", "Comma-separated CORS allowed headers. See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers")
- flags.String(c.Prefix+corsAllowedOrigins, "", "Comma-separated CORS allowed origins. See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin")
+ flags.String(
+ c.Prefix+corsAllowedHeaders,
+ "",
+ "Comma-separated CORS allowed headers. See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers",
+ )
+ flags.String(
+ c.Prefix+corsAllowedOrigins,
+ "",
+ "Comma-separated CORS allowed origins. See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin",
+ )
}
func (c Flags) InitFromViper(v *viper.Viper) Options {
@@ -42,8 +50,14 @@ func (c Flags) InitFromViper(v *viper.Viper) Options {
allowedHeaders := v.GetString(c.Prefix + corsAllowedHeaders)
allowedOrigins := v.GetString(c.Prefix + corsAllowedOrigins)
- p.AllowedOrigins = strings.Split(strings.ReplaceAll(allowedOrigins, " ", ""), ",")
- p.AllowedHeaders = strings.Split(strings.ReplaceAll(allowedHeaders, " ", ""), ",")
+ p.AllowedOrigins = strings.Split(
+ strings.ReplaceAll(allowedOrigins, " ", ""),
+ ",",
+ )
+ p.AllowedHeaders = strings.Split(
+ strings.ReplaceAll(allowedHeaders, " ", ""),
+ ",",
+ )
return p
}
diff --git a/pkg/config/corscfg/flags_test.go b/pkg/config/corscfg/flags_test.go
index e772fbe3343..6af3479362e 100644
--- a/pkg/config/corscfg/flags_test.go
+++ b/pkg/config/corscfg/flags_test.go
@@ -43,8 +43,15 @@ func TestCORSFlags(t *testing.T) {
fmt.Println(corsOpts)
assert.Equal(t, Options{
- AllowedHeaders: []string{"Content-Type", "Accept", "X-Requested-With"},
- AllowedOrigins: []string{"http://example.domain.com", "http://*.domain.com"},
+ AllowedHeaders: []string{
+ "Content-Type",
+ "Accept",
+ "X-Requested-With",
+ },
+ AllowedOrigins: []string{
+ "http://example.domain.com",
+ "http://*.domain.com",
+ },
}, corsOpts)
})
}
diff --git a/pkg/config/tlscfg/cert_watcher.go b/pkg/config/tlscfg/cert_watcher.go
index 106249c3647..e8af9e98e83 100644
--- a/pkg/config/tlscfg/cert_watcher.go
+++ b/pkg/config/tlscfg/cert_watcher.go
@@ -49,13 +49,23 @@ type certWatcher struct {
var _ io.Closer = (*certWatcher)(nil)
-func newCertWatcher(opts Options, logger *zap.Logger, rootCAs, clientCAs *x509.CertPool) (*certWatcher, error) {
+func newCertWatcher(
+ opts Options,
+ logger *zap.Logger,
+ rootCAs, clientCAs *x509.CertPool,
+) (*certWatcher, error) {
var cert *tls.Certificate
if opts.CertPath != "" && opts.KeyPath != "" {
// load certs at startup to catch missing certs error early
- c, err := tls.LoadX509KeyPair(filepath.Clean(opts.CertPath), filepath.Clean(opts.KeyPath))
+ c, err := tls.LoadX509KeyPair(
+ filepath.Clean(opts.CertPath),
+ filepath.Clean(opts.KeyPath),
+ )
if err != nil {
- return nil, fmt.Errorf("failed to load server TLS cert and key: %w", err)
+ return nil, fmt.Errorf(
+ "failed to load server TLS cert and key: %w",
+ err,
+ )
}
cert = &c
}
@@ -104,10 +114,18 @@ func (w *certWatcher) watchCertPair() error {
return nil
}
w.Close()
- return fmt.Errorf("failed to watch key pair %s and %s: %w", w.opts.KeyPath, w.opts.CertPath, err)
+ return fmt.Errorf(
+ "failed to watch key pair %s and %s: %w",
+ w.opts.KeyPath,
+ w.opts.CertPath,
+ err,
+ )
}
-func (w *certWatcher) watchCert(certPath string, certPool *x509.CertPool) error {
+func (w *certWatcher) watchCert(
+ certPath string,
+ certPool *x509.CertPool,
+) error {
onCertChange := func() { w.onCertChange(certPath, certPool) }
watcher, err := fswatcher.New([]string{certPath}, onCertChange, w.logger)
@@ -120,7 +138,10 @@ func (w *certWatcher) watchCert(certPath string, certPool *x509.CertPool) error
}
func (w *certWatcher) onCertPairChange() {
- cert, err := tls.LoadX509KeyPair(filepath.Clean(w.opts.CertPath), filepath.Clean(w.opts.KeyPath))
+ cert, err := tls.LoadX509KeyPair(
+ filepath.Clean(w.opts.CertPath),
+ filepath.Clean(w.opts.KeyPath),
+ )
if err == nil {
w.mu.Lock()
w.cert = &cert
diff --git a/pkg/config/tlscfg/cert_watcher_test.go b/pkg/config/tlscfg/cert_watcher_test.go
index 045c43f00e8..14813ede2ec 100644
--- a/pkg/config/tlscfg/cert_watcher_test.go
+++ b/pkg/config/tlscfg/cert_watcher_test.go
@@ -40,7 +40,11 @@ const (
badCaCert = "./testdata/bad-CA-cert.txt"
)
-func copyToTempFile(t *testing.T, pattern string, filename string) (file *os.File, closeFn func()) {
+func copyToTempFile(
+ t *testing.T,
+ pattern string,
+ filename string,
+) (file *os.File, closeFn func()) {
tempFile, err := os.CreateTemp("", pattern+"_")
require.NoError(t, err)
@@ -94,14 +98,24 @@ func TestReloadKeyPair(t *testing.T) {
// Replace certificate part of the pair with client's cert, which should fail to load.
copyFile(t, certFile.Name(), clientCert)
- assertLogs(t, logObserver, logMsgPairNotReloaded, [][2]string{{"key", keyFile.Name()}, {"cert", certFile.Name()}})
+ assertLogs(
+ t,
+ logObserver,
+ logMsgPairNotReloaded,
+ [][2]string{{"key", keyFile.Name()}, {"cert", certFile.Name()}},
+ )
assert.Equal(t, &cert, watcher.certificate(), "key pair unchanged")
logObserver.TakeAll() // clean up logs
// Replace key part with client's private key. Valid pair, should reload.
copyFile(t, keyFile.Name(), clientKey)
- assertLogs(t, logObserver, logMsgPairReloaded, [][2]string{{"key", keyFile.Name()}, {"cert", certFile.Name()}})
+ assertLogs(
+ t,
+ logObserver,
+ logMsgPairReloaded,
+ [][2]string{{"key", keyFile.Name()}, {"cert", certFile.Name()}},
+ )
logObserver.TakeAll() // clean up logs
cert, err = tls.LoadX509KeyPair(filepath.Clean(clientCert), clientKey)
@@ -113,7 +127,11 @@ func TestReload_ca_certs(t *testing.T) {
// copy certs to temp so we can modify them
caFile, caFileCloseFn := copyToTempFile(t, "ca.crt", caCert)
defer caFileCloseFn()
- clientCaFile, clientCaFileClostFn := copyToTempFile(t, "client-ca.crt", caCert)
+ clientCaFile, clientCaFileClostFn := copyToTempFile(
+ t,
+ "client-ca.crt",
+ caCert,
+ )
defer clientCaFileClostFn()
zcore, logObserver := observer.New(zapcore.InfoLevel)
@@ -133,16 +151,36 @@ func TestReload_ca_certs(t *testing.T) {
copyFile(t, caFile.Name(), wrongCaCert)
copyFile(t, clientCaFile.Name(), wrongCaCert)
- assertLogs(t, logObserver, logMsgCertReloaded, [][2]string{{"cert", caFile.Name()}})
- assertLogs(t, logObserver, logMsgCertReloaded, [][2]string{{"cert", clientCaFile.Name()}})
+ assertLogs(
+ t,
+ logObserver,
+ logMsgCertReloaded,
+ [][2]string{{"cert", caFile.Name()}},
+ )
+ assertLogs(
+ t,
+ logObserver,
+ logMsgCertReloaded,
+ [][2]string{{"cert", clientCaFile.Name()}},
+ )
logObserver.TakeAll() // clean up logs
// update the content with invalid certs to trigger failed reload.
copyFile(t, caFile.Name(), badCaCert)
copyFile(t, clientCaFile.Name(), badCaCert)
- assertLogs(t, logObserver, logMsgCertNotReloaded, [][2]string{{"cert", caFile.Name()}})
- assertLogs(t, logObserver, logMsgCertNotReloaded, [][2]string{{"cert", clientCaFile.Name()}})
+ assertLogs(
+ t,
+ logObserver,
+ logMsgCertNotReloaded,
+ [][2]string{{"cert", caFile.Name()}},
+ )
+ assertLogs(
+ t,
+ logObserver,
+ logMsgCertNotReloaded,
+ [][2]string{{"cert", clientCaFile.Name()}},
+ )
}
func TestReload_err_cert_update(t *testing.T) {
@@ -167,7 +205,10 @@ func TestReload_err_cert_update(t *testing.T) {
defer watcher.Close()
require.NoError(t, err)
- serverCert, err := tls.LoadX509KeyPair(filepath.Clean(serverCert), filepath.Clean(serverKey))
+ serverCert, err := tls.LoadX509KeyPair(
+ filepath.Clean(serverCert),
+ filepath.Clean(serverKey),
+ )
require.NoError(t, err)
assert.Equal(t, &serverCert, watcher.certificate())
@@ -175,7 +216,12 @@ func TestReload_err_cert_update(t *testing.T) {
copyFile(t, certFile.Name(), badCaCert)
copyFile(t, keyFile.Name(), clientKey)
- assertLogs(t, logObserver, logMsgPairNotReloaded, [][2]string{{"key", opts.KeyPath}, {"cert", opts.CertPath}})
+ assertLogs(
+ t,
+ logObserver,
+ logMsgPairNotReloaded,
+ [][2]string{{"key", opts.KeyPath}, {"cert", opts.CertPath}},
+ )
assert.Equal(t, &serverCert, watcher.certificate(), "values unchanged")
}
@@ -195,11 +241,20 @@ func TestReload_kubernetes_secret_update(t *testing.T) {
err := os.Symlink("..timestamp-1", filepath.Join(mountDir, "..data"))
require.NoError(t, err)
- err = os.Symlink(filepath.Join("..data", "ca.crt"), filepath.Join(mountDir, "ca.crt"))
+ err = os.Symlink(
+ filepath.Join("..data", "ca.crt"),
+ filepath.Join(mountDir, "ca.crt"),
+ )
require.NoError(t, err)
- err = os.Symlink(filepath.Join("..data", "tls.crt"), filepath.Join(mountDir, "tls.crt"))
+ err = os.Symlink(
+ filepath.Join("..data", "tls.crt"),
+ filepath.Join(mountDir, "tls.crt"),
+ )
require.NoError(t, err)
- err = os.Symlink(filepath.Join("..data", "tls.key"), filepath.Join(mountDir, "tls.key"))
+ err = os.Symlink(
+ filepath.Join("..data", "tls.key"),
+ filepath.Join(mountDir, "tls.key"),
+ )
require.NoError(t, err)
timestamp1Dir := filepath.Join(mountDir, "..timestamp-1")
@@ -252,13 +307,26 @@ func TestReload_kubernetes_secret_update(t *testing.T) {
err = os.Symlink("..timestamp-2", filepath.Join(mountDir, "..data_tmp"))
require.NoError(t, err)
- os.Rename(filepath.Join(mountDir, "..data_tmp"), filepath.Join(mountDir, "..data"))
+ os.Rename(
+ filepath.Join(mountDir, "..data_tmp"),
+ filepath.Join(mountDir, "..data"),
+ )
require.NoError(t, err)
err = os.RemoveAll(timestamp1Dir)
require.NoError(t, err)
- assertLogs(t, logObserver, logMsgPairReloaded, [][2]string{{"key", opts.KeyPath}, {"cert", opts.CertPath}})
- assertLogs(t, logObserver, logMsgCertReloaded, [][2]string{{"cert", opts.CAPath}})
+ assertLogs(
+ t,
+ logObserver,
+ logMsgPairReloaded,
+ [][2]string{{"key", opts.KeyPath}, {"cert", opts.CertPath}},
+ )
+ assertLogs(
+ t,
+ logObserver,
+ logMsgCertReloaded,
+ [][2]string{{"cert", opts.CAPath}},
+ )
expectedCert, err = tls.LoadX509KeyPair(clientCert, clientKey)
require.NoError(t, err)
@@ -272,13 +340,26 @@ func TestReload_kubernetes_secret_update(t *testing.T) {
createTimestampDir(t, timestamp3Dir, caCert, serverCert, serverKey)
err = os.Symlink("..timestamp-3", filepath.Join(mountDir, "..data_tmp"))
require.NoError(t, err)
- os.Rename(filepath.Join(mountDir, "..data_tmp"), filepath.Join(mountDir, "..data"))
+ os.Rename(
+ filepath.Join(mountDir, "..data_tmp"),
+ filepath.Join(mountDir, "..data"),
+ )
require.NoError(t, err)
err = os.RemoveAll(timestamp2Dir)
require.NoError(t, err)
- assertLogs(t, logObserver, logMsgPairReloaded, [][2]string{{"key", opts.KeyPath}, {"cert", opts.CertPath}})
- assertLogs(t, logObserver, logMsgCertReloaded, [][2]string{{"cert", opts.CAPath}})
+ assertLogs(
+ t,
+ logObserver,
+ logMsgPairReloaded,
+ [][2]string{{"key", opts.KeyPath}, {"cert", opts.CertPath}},
+ )
+ assertLogs(
+ t,
+ logObserver,
+ logMsgCertReloaded,
+ [][2]string{{"cert", opts.CAPath}},
+ )
expectedCert, err = tls.LoadX509KeyPair(serverCert, serverKey)
require.NoError(t, err)
@@ -377,7 +458,11 @@ func assertLogs(t *testing.T,
// syncWrite ensures data is written to the given filename and flushed to disk.
// This ensures that any watchers looking for file system changes can be reliably alerted.
func syncWrite(filename string, data []byte, perm os.FileMode) error {
- f, err := os.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_TRUNC|os.O_SYNC, perm)
+ f, err := os.OpenFile(
+ filename,
+ os.O_WRONLY|os.O_CREATE|os.O_TRUNC|os.O_SYNC,
+ perm,
+ )
if err != nil {
return err
}
diff --git a/pkg/config/tlscfg/ciphersuites.go b/pkg/config/tlscfg/ciphersuites.go
index 4c71db9379b..c23a326df9c 100644
--- a/pkg/config/tlscfg/ciphersuites.go
+++ b/pkg/config/tlscfg/ciphersuites.go
@@ -42,7 +42,10 @@ func CipherSuiteNamesToIDs(cipherNames []string) ([]uint16, error) {
for _, cipher := range cipherNames {
intValue, ok := possibleCiphers[cipher]
if !ok {
- return nil, fmt.Errorf("cipher suite %s not supported or doesn't exist", cipher)
+ return nil, fmt.Errorf(
+ "cipher suite %s not supported or doesn't exist",
+ cipher,
+ )
}
ciphersIDs = append(ciphersIDs, intValue)
}
diff --git a/pkg/config/tlscfg/ciphersuites_test.go b/pkg/config/tlscfg/ciphersuites_test.go
index 3f41b4ae4b3..d2359112873 100644
--- a/pkg/config/tlscfg/ciphersuites_test.go
+++ b/pkg/config/tlscfg/ciphersuites_test.go
@@ -28,8 +28,18 @@ func TestCipherSuiteNamesToIDs(t *testing.T) {
}{
{
// Happy case
- flag: []string{"TLS_AES_128_GCM_SHA256", "TLS_AES_256_GCM_SHA384", "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA", "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384"},
- expected: []uint16{tls.TLS_AES_128_GCM_SHA256, tls.TLS_AES_256_GCM_SHA384, tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384},
+ flag: []string{
+ "TLS_AES_128_GCM_SHA256",
+ "TLS_AES_256_GCM_SHA384",
+ "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA",
+ "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384",
+ },
+ expected: []uint16{
+ tls.TLS_AES_128_GCM_SHA256,
+ tls.TLS_AES_256_GCM_SHA384,
+ tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
+ tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
+ },
expectedError: false,
},
{
@@ -46,8 +56,16 @@ func TestCipherSuiteNamesToIDs(t *testing.T) {
},
{
// Duplicated flag
- flag: []string{"TLS_AES_128_GCM_SHA256", "TLS_AES_256_GCM_SHA384", "TLS_AES_128_GCM_SHA256"},
- expected: []uint16{tls.TLS_AES_128_GCM_SHA256, tls.TLS_AES_256_GCM_SHA384, tls.TLS_AES_128_GCM_SHA256},
+ flag: []string{
+ "TLS_AES_128_GCM_SHA256",
+ "TLS_AES_256_GCM_SHA384",
+ "TLS_AES_128_GCM_SHA256",
+ },
+ expected: []uint16{
+ tls.TLS_AES_128_GCM_SHA256,
+ tls.TLS_AES_256_GCM_SHA384,
+ tls.TLS_AES_128_GCM_SHA256,
+ },
expectedError: false,
},
{
diff --git a/pkg/config/tlscfg/flags.go b/pkg/config/tlscfg/flags.go
index 96de6b7cf4e..10fc7edca4a 100644
--- a/pkg/config/tlscfg/flags.go
+++ b/pkg/config/tlscfg/flags.go
@@ -52,11 +52,31 @@ type ServerFlagsConfig struct {
// AddFlags adds flags for TLS to the FlagSet.
func (c ClientFlagsConfig) AddFlags(flags *flag.FlagSet) {
flags.Bool(c.Prefix+tlsEnabled, false, "Enable TLS when talking to the remote server(s)")
- flags.String(c.Prefix+tlsCA, "", "Path to a TLS CA (Certification Authority) file used to verify the remote server(s) (by default will use the system truststore)")
- flags.String(c.Prefix+tlsCert, "", "Path to a TLS Certificate file, used to identify this process to the remote server(s)")
- flags.String(c.Prefix+tlsKey, "", "Path to a TLS Private Key file, used to identify this process to the remote server(s)")
- flags.String(c.Prefix+tlsServerName, "", "Override the TLS server name we expect in the certificate of the remote server(s)")
- flags.Bool(c.Prefix+tlsSkipHostVerify, false, "(insecure) Skip server's certificate chain and host name verification")
+ flags.String(
+ c.Prefix+tlsCA,
+ "",
+ "Path to a TLS CA (Certification Authority) file used to verify the remote server(s) (by default will use the system truststore)",
+ )
+ flags.String(
+ c.Prefix+tlsCert,
+ "",
+ "Path to a TLS Certificate file, used to identify this process to the remote server(s)",
+ )
+ flags.String(
+ c.Prefix+tlsKey,
+ "",
+ "Path to a TLS Private Key file, used to identify this process to the remote server(s)",
+ )
+ flags.String(
+ c.Prefix+tlsServerName,
+ "",
+ "Override the TLS server name we expect in the certificate of the remote server(s)",
+ )
+ flags.Bool(
+ c.Prefix+tlsSkipHostVerify,
+ false,
+ "(insecure) Skip server's certificate chain and host name verification",
+ )
}
// AddFlags adds flags for TLS to the FlagSet.
@@ -64,12 +84,24 @@ func (c ServerFlagsConfig) AddFlags(flags *flag.FlagSet) {
flags.Bool(c.Prefix+tlsEnabled, false, "Enable TLS on the server")
flags.String(c.Prefix+tlsCert, "", "Path to a TLS Certificate file, used to identify this server to clients")
flags.String(c.Prefix+tlsKey, "", "Path to a TLS Private Key file, used to identify this server to clients")
- flags.String(c.Prefix+tlsClientCA, "", "Path to a TLS CA (Certification Authority) file used to verify certificates presented by clients (if unset, all clients are permitted)")
- flags.String(c.Prefix+tlsCipherSuites, "", "Comma-separated list of cipher suites for the server, values are from tls package constants (https://golang.org/pkg/crypto/tls/#pkg-constants).")
+ flags.String(
+ c.Prefix+tlsClientCA,
+ "",
+ "Path to a TLS CA (Certification Authority) file used to verify certificates presented by clients (if unset, all clients are permitted)",
+ )
+ flags.String(
+ c.Prefix+tlsCipherSuites,
+ "",
+ "Comma-separated list of cipher suites for the server, values are from tls package constants (https://golang.org/pkg/crypto/tls/#pkg-constants).",
+ )
flags.String(c.Prefix+tlsMinVersion, "", "Minimum TLS version supported (Possible values: 1.0, 1.1, 1.2, 1.3)")
flags.String(c.Prefix+tlsMaxVersion, "", "Maximum TLS version supported (Possible values: 1.0, 1.1, 1.2, 1.3)")
if c.EnableCertReloadInterval {
- flags.Duration(c.Prefix+tlsReloadInterval, 0, "The duration after which the certificate will be reloaded (0s means will not be reloaded)")
+ flags.Duration(
+ c.Prefix+tlsReloadInterval,
+ 0,
+ "The duration after which the certificate will be reloaded (0s means will not be reloaded)",
+ )
}
}
@@ -86,7 +118,11 @@ func (c ClientFlagsConfig) InitFromViper(v *viper.Viper) (Options, error) {
if !p.Enabled {
var empty Options
if !reflect.DeepEqual(&p, &empty) {
- return p, fmt.Errorf("%s.tls.* options cannot be used when %s is false", c.Prefix, c.Prefix+tlsEnabled)
+ return p, fmt.Errorf(
+ "%s.tls.* options cannot be used when %s is false",
+ c.Prefix,
+ c.Prefix+tlsEnabled,
+ )
}
}
@@ -101,7 +137,10 @@ func (c ServerFlagsConfig) InitFromViper(v *viper.Viper) (Options, error) {
p.KeyPath = v.GetString(c.Prefix + tlsKey)
p.ClientCAPath = v.GetString(c.Prefix + tlsClientCA)
if s := v.GetString(c.Prefix + tlsCipherSuites); s != "" {
- p.CipherSuites = strings.Split(stripWhiteSpace(v.GetString(c.Prefix+tlsCipherSuites)), ",")
+ p.CipherSuites = strings.Split(
+ stripWhiteSpace(v.GetString(c.Prefix+tlsCipherSuites)),
+ ",",
+ )
}
p.MinVersion = v.GetString(c.Prefix + tlsMinVersion)
p.MaxVersion = v.GetString(c.Prefix + tlsMaxVersion)
@@ -110,7 +149,11 @@ func (c ServerFlagsConfig) InitFromViper(v *viper.Viper) (Options, error) {
if !p.Enabled {
var empty Options
if !reflect.DeepEqual(&p, &empty) {
- return p, fmt.Errorf("%s.tls.* options cannot be used when %s is false", c.Prefix, c.Prefix+tlsEnabled)
+ return p, fmt.Errorf(
+ "%s.tls.* options cannot be used when %s is false",
+ c.Prefix,
+ c.Prefix+tlsEnabled,
+ )
}
}
diff --git a/pkg/config/tlscfg/flags_test.go b/pkg/config/tlscfg/flags_test.go
index be5adeb868a..d1ea34d969a 100644
--- a/pkg/config/tlscfg/flags_test.go
+++ b/pkg/config/tlscfg/flags_test.go
@@ -114,9 +114,12 @@ func TestServerFlags(t *testing.T) {
CertPath: "cert-file",
KeyPath: "key-file",
ClientCAPath: test.file,
- CipherSuites: []string{"TLS_AES_256_GCM_SHA384", "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA"},
- MinVersion: "1.2",
- MaxVersion: "1.3",
+ CipherSuites: []string{
+ "TLS_AES_256_GCM_SHA384",
+ "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA",
+ },
+ MinVersion: "1.2",
+ MaxVersion: "1.3",
}, tlsOpts)
})
}
@@ -215,7 +218,11 @@ func TestFailedTLSFlags(t *testing.T) {
require.NoError(t, err)
_, err = underTest.InitFromViper(v)
require.Error(t, err)
- require.EqualError(t, err, "prefix.tls.* options cannot be used when prefix.tls.enabled is false")
+ require.EqualError(
+ t,
+ err,
+ "prefix.tls.* options cannot be used when prefix.tls.enabled is false",
+ )
})
}
})
diff --git a/pkg/config/tlscfg/options.go b/pkg/config/tlscfg/options.go
index cae2fa6376f..ca2abbd0cdc 100644
--- a/pkg/config/tlscfg/options.go
+++ b/pkg/config/tlscfg/options.go
@@ -56,7 +56,10 @@ func (o *Options) Config(logger *zap.Logger) (*tls.Config, error) {
cipherSuiteIds, err := CipherSuiteNamesToIDs(o.CipherSuites)
if err != nil {
- return nil, fmt.Errorf("failed to get cipher suite ids from cipher suite names: %w", err)
+ return nil, fmt.Errorf(
+ "failed to get cipher suite ids from cipher suite names: %w",
+ err,
+ )
}
if o.MinVersion != "" {
@@ -75,7 +78,9 @@ func (o *Options) Config(logger *zap.Logger) (*tls.Config, error) {
if o.MinVersion != "" && o.MaxVersion != "" {
if minVersionId > maxVersionId {
- return nil, fmt.Errorf("minimum tls version can't be greater than maximum tls version")
+ return nil, fmt.Errorf(
+ "minimum tls version can't be greater than maximum tls version",
+ )
}
}
@@ -98,14 +103,21 @@ func (o *Options) Config(logger *zap.Logger) (*tls.Config, error) {
tlsCfg.ClientAuth = tls.RequireAndVerifyClientCert
}
- certWatcher, err := newCertWatcher(*o, logger, tlsCfg.RootCAs, tlsCfg.ClientCAs)
+ certWatcher, err := newCertWatcher(
+ *o,
+ logger,
+ tlsCfg.RootCAs,
+ tlsCfg.ClientCAs,
+ )
if err != nil {
return nil, err
}
o.certWatcher = certWatcher
if (o.CertPath == "" && o.KeyPath != "") || (o.CertPath != "" && o.KeyPath == "") {
- return nil, fmt.Errorf("for client auth via TLS, either both client certificate and key must be supplied, or neither")
+ return nil, fmt.Errorf(
+ "for client auth via TLS, either both client certificate and key must be supplied, or neither",
+ )
}
if o.CertPath != "" && o.KeyPath != "" {
tlsCfg.GetCertificate = func(*tls.ClientHelloInfo) (*tls.Certificate, error) {
diff --git a/pkg/config/tlscfg/options_test.go b/pkg/config/tlscfg/options_test.go
index 44ad205fdc0..71ee4bc01fc 100644
--- a/pkg/config/tlscfg/options_test.go
+++ b/pkg/config/tlscfg/options_test.go
@@ -48,8 +48,10 @@ func TestOptionsToConfig(t *testing.T) {
expectError: "fake system pool",
},
{
- name: "should load custom CA",
- options: Options{CAPath: testCertKeyLocation + "/example-CA-cert.pem"},
+ name: "should load custom CA",
+ options: Options{
+ CAPath: testCertKeyLocation + "/example-CA-cert.pem",
+ },
},
{
name: "should fail with invalid CA file path",
@@ -57,8 +59,10 @@ func TestOptionsToConfig(t *testing.T) {
expectError: "failed to load CA",
},
{
- name: "should fail with invalid CA file content",
- options: Options{CAPath: testCertKeyLocation + "/bad-CA-cert.txt"},
+ name: "should fail with invalid CA file content",
+ options: Options{
+ CAPath: testCertKeyLocation + "/bad-CA-cert.txt",
+ },
expectError: "failed to parse CA",
},
{
diff --git a/pkg/discovery/grpcresolver/grpc_resolver.go b/pkg/discovery/grpcresolver/grpc_resolver.go
index 852da1032ba..570e536f39f 100644
--- a/pkg/discovery/grpcresolver/grpc_resolver.go
+++ b/pkg/discovery/grpcresolver/grpc_resolver.go
@@ -73,7 +73,10 @@ func New(
logger: logger,
discoveryMinPeers: discoveryMinPeers,
salt: []byte(strconv.FormatInt(random.Int63(), 10)), // random salt for rendezvousHash
- scheme: strconv.FormatInt(seed, 36), // make random scheme which will be used when registering
+ scheme: strconv.FormatInt(
+ seed,
+ 36,
+ ), // make random scheme which will be used when registering
}
// Register the resolver with grpc so it's available for grpc.Dial
@@ -85,7 +88,11 @@ func New(
}
// Build returns itself for Resolver, because it's both a builder and a resolver.
-func (r *Resolver) Build(target resolver.Target, cc resolver.ClientConn, opts resolver.BuildOptions) (resolver.Resolver, error) {
+func (r *Resolver) Build(
+ target resolver.Target,
+ cc resolver.ClientConn,
+ opts resolver.BuildOptions,
+) (resolver.Resolver, error) {
r.cc = cc
// Update conn states if proactively updates already work
@@ -111,7 +118,10 @@ func (*Resolver) ResolveNow(o resolver.ResolveNowOptions) {}
func (r *Resolver) watcher() {
defer r.closing.Done()
for latestHostPorts := range r.discoCh {
- r.logger.Info("Received updates from notifier", zap.Strings("hostPorts", latestHostPorts))
+ r.logger.Info(
+ "Received updates from notifier",
+ zap.Strings("hostPorts", latestHostPorts),
+ )
r.updateAddresses(latestHostPorts)
}
}
diff --git a/pkg/discovery/grpcresolver/grpc_resolver_test.go b/pkg/discovery/grpcresolver/grpc_resolver_test.go
index 5488508fcfd..78c3bd5c352 100644
--- a/pkg/discovery/grpcresolver/grpc_resolver_test.go
+++ b/pkg/discovery/grpcresolver/grpc_resolver_test.go
@@ -44,7 +44,10 @@ type test struct {
addresses []string
}
-func (*testServer) EmptyCall(ctx context.Context, in *grpc_testing.Empty) (*grpc_testing.Empty, error) {
+func (*testServer) EmptyCall(
+ ctx context.Context,
+ in *grpc_testing.Empty,
+) (*grpc_testing.Empty, error) {
return &grpc_testing.Empty{}, nil
}
@@ -71,7 +74,10 @@ func startTestServers(t *testing.T, count int) *test {
s := grpc.NewServer()
grpc_testing.RegisterTestServiceServer(s, &testServer{})
testInstance.servers = append(testInstance.servers, s)
- testInstance.addresses = append(testInstance.addresses, lis.Addr().String())
+ testInstance.addresses = append(
+ testInstance.addresses,
+ lis.Addr().String(),
+ )
go func(s *grpc.Server, l net.Listener) {
s.Serve(l)
@@ -81,34 +87,61 @@ func startTestServers(t *testing.T, count int) *test {
return testInstance
}
-func makeSureConnectionsUp(t *testing.T, count int, testc grpc_testing.TestServiceClient) {
+func makeSureConnectionsUp(
+ t *testing.T,
+ count int,
+ testc grpc_testing.TestServiceClient,
+) {
var p peer.Peer
addrs := make(map[string]struct{})
// Make sure connections to all servers are up.
for si := 0; si < count; si++ {
connected := false
for i := 0; i < 3000; i++ { // 3000 * 10ms = 30s
- _, err := testc.EmptyCall(context.Background(), &grpc_testing.Empty{}, grpc.Peer(&p))
+ _, err := testc.EmptyCall(
+ context.Background(),
+ &grpc_testing.Empty{},
+ grpc.Peer(&p),
+ )
if err != nil {
continue
}
if _, ok := addrs[p.Addr.String()]; !ok {
addrs[p.Addr.String()] = struct{}{}
connected = true
- t.Logf("connected to peer #%d (%v) on iteration %d", si, p.Addr, i)
+ t.Logf(
+ "connected to peer #%d (%v) on iteration %d",
+ si,
+ p.Addr,
+ i,
+ )
break
}
time.Sleep(time.Millisecond * 10)
}
- assert.True(t, connected, "Connection #%d was still not up. Connections so far: %+v", si, addrs)
+ assert.True(
+ t,
+ connected,
+ "Connection #%d was still not up. Connections so far: %+v",
+ si,
+ addrs,
+ )
}
}
-func assertRoundRobinCall(t *testing.T, connections int, testc grpc_testing.TestServiceClient) {
+func assertRoundRobinCall(
+ t *testing.T,
+ connections int,
+ testc grpc_testing.TestServiceClient,
+) {
addrs := make(map[string]struct{})
var p peer.Peer
for i := 0; i < connections; i++ {
- _, err := testc.EmptyCall(context.Background(), &grpc_testing.Empty{}, grpc.Peer(&p))
+ _, err := testc.EmptyCall(
+ context.Background(),
+ &grpc_testing.Empty{},
+ grpc.Peer(&p),
+ )
require.NoError(t, err)
addrs[p.Addr.String()] = struct{}{}
}
@@ -148,7 +181,11 @@ func TestGRPCResolverRoundRobin(t *testing.T) {
t.Run(fmt.Sprintf("%+v", test), func(t *testing.T) {
res := New(notifier, discoverer, zap.NewNop(), test.minPeers)
- cc, err := grpc.NewClient(res.Scheme()+":///round_robin", grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithDefaultServiceConfig(GRPCServiceConfig))
+ cc, err := grpc.NewClient(
+ res.Scheme()+":///round_robin",
+ grpc.WithTransportCredentials(insecure.NewCredentials()),
+ grpc.WithDefaultServiceConfig(GRPCServiceConfig),
+ )
require.NoError(t, err, "could not dial using resolver's scheme")
defer cc.Close()
@@ -167,8 +204,18 @@ func TestGRPCResolverRoundRobin(t *testing.T) {
func TestRendezvousHash(t *testing.T) {
// Rendezvous Hash should return same subset with same addresses & salt string
- addresses := []string{"127.1.0.3:8080", "127.0.1.1:8080", "127.2.1.2:8080", "127.3.0.4:8080"}
- sameAddressesDifferentOrder := []string{"127.2.1.2:8080", "127.1.0.3:8080", "127.3.0.4:8080", "127.0.1.1:8080"}
+ addresses := []string{
+ "127.1.0.3:8080",
+ "127.0.1.1:8080",
+ "127.2.1.2:8080",
+ "127.3.0.4:8080",
+ }
+ sameAddressesDifferentOrder := []string{
+ "127.2.1.2:8080",
+ "127.1.0.3:8080",
+ "127.3.0.4:8080",
+ "127.0.1.1:8080",
+ }
notifier := &discovery.Dispatcher{}
discoverer := discovery.FixedDiscoverer{}
resolverInstance := New(notifier, discoverer, zap.NewNop(), 2)
diff --git a/pkg/es/client/client.go b/pkg/es/client/client.go
index b121af699c0..1a84a670b8b 100644
--- a/pkg/es/client/client.go
+++ b/pkg/es/client/client.go
@@ -75,7 +75,11 @@ func (c *Client) request(esRequest elasticRequest) ([]byte, error) {
var err error
if len(esRequest.body) > 0 {
reader = bytes.NewBuffer(esRequest.body)
- r, err = http.NewRequest(esRequest.method, fmt.Sprintf("%s/%s", c.Endpoint, esRequest.endpoint), reader)
+ r, err = http.NewRequest(
+ esRequest.method,
+ fmt.Sprintf("%s/%s", c.Endpoint, esRequest.endpoint),
+ reader,
+ )
} else {
r, err = http.NewRequest(esRequest.method, fmt.Sprintf("%s/%s", c.Endpoint, esRequest.endpoint), nil)
}
@@ -111,10 +115,22 @@ func (*Client) handleFailedRequest(res *http.Response) error {
if res.Body != nil {
bodyBytes, err := io.ReadAll(res.Body)
if err != nil {
- return newResponseError(fmt.Errorf("request failed and failed to read response body, status code: %d, %w", res.StatusCode, err), res.StatusCode, nil)
+ return newResponseError(
+ fmt.Errorf("request failed and failed to read response body, status code: %d, %w", res.StatusCode, err),
+ res.StatusCode,
+ nil,
+ )
}
body := string(bodyBytes)
- return newResponseError(fmt.Errorf("request failed, status code: %d, body: %s", res.StatusCode, body), res.StatusCode, bodyBytes)
+ return newResponseError(
+ fmt.Errorf("request failed, status code: %d, body: %s", res.StatusCode, body),
+ res.StatusCode,
+ bodyBytes,
+ )
}
- return newResponseError(fmt.Errorf("request failed, status code: %d", res.StatusCode), res.StatusCode, nil)
+ return newResponseError(
+ fmt.Errorf("request failed, status code: %d", res.StatusCode),
+ res.StatusCode,
+ nil,
+ )
}
diff --git a/pkg/es/client/cluster_client.go b/pkg/es/client/cluster_client.go
index 2a074ab0875..a88601465e5 100644
--- a/pkg/es/client/cluster_client.go
+++ b/pkg/es/client/cluster_client.go
@@ -57,7 +57,8 @@ func (c *ClusterClient) Version() (uint, error) {
if err != nil {
return 0, fmt.Errorf("invalid version format: %s", version[0])
}
- if strings.Contains(info.TagLine, "OpenSearch") && (major == 1 || major == 2) {
+ if strings.Contains(info.TagLine, "OpenSearch") &&
+ (major == 1 || major == 2) {
return 7, nil
}
return uint(major), nil
diff --git a/pkg/es/client/cluster_client_test.go b/pkg/es/client/cluster_client_test.go
index 57d0b65801e..6afaf469dd2 100644
--- a/pkg/es/client/cluster_client_test.go
+++ b/pkg/es/client/cluster_client_test.go
@@ -218,12 +218,20 @@ func TestVersion(t *testing.T) {
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
- testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
- assert.Equal(t, http.MethodGet, req.Method)
- assert.Equal(t, "Basic foobar", req.Header.Get("Authorization"))
- res.WriteHeader(test.responseCode)
- res.Write([]byte(test.response))
- }))
+ testServer := httptest.NewServer(
+ http.HandlerFunc(
+ func(res http.ResponseWriter, req *http.Request) {
+ assert.Equal(t, http.MethodGet, req.Method)
+ assert.Equal(
+ t,
+ "Basic foobar",
+ req.Header.Get("Authorization"),
+ )
+ res.WriteHeader(test.responseCode)
+ res.Write([]byte(test.response))
+ },
+ ),
+ )
defer testServer.Close()
c := &ClusterClient{
diff --git a/pkg/es/client/ilm_client_test.go b/pkg/es/client/ilm_client_test.go
index c19a0caef2e..d7ae067f204 100644
--- a/pkg/es/client/ilm_client_test.go
+++ b/pkg/es/client/ilm_client_test.go
@@ -51,13 +51,27 @@ func TestExists(t *testing.T) {
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
- testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
- assert.True(t, strings.HasSuffix(req.URL.String(), "_ilm/policy/jaeger-ilm-policy"))
- assert.Equal(t, http.MethodGet, req.Method)
- assert.Equal(t, "Basic foobar", req.Header.Get("Authorization"))
- res.WriteHeader(test.responseCode)
- res.Write([]byte(test.response))
- }))
+ testServer := httptest.NewServer(
+ http.HandlerFunc(
+ func(res http.ResponseWriter, req *http.Request) {
+ assert.True(
+ t,
+ strings.HasSuffix(
+ req.URL.String(),
+ "_ilm/policy/jaeger-ilm-policy",
+ ),
+ )
+ assert.Equal(t, http.MethodGet, req.Method)
+ assert.Equal(
+ t,
+ "Basic foobar",
+ req.Header.Get("Authorization"),
+ )
+ res.WriteHeader(test.responseCode)
+ res.Write([]byte(test.response))
+ },
+ ),
+ )
defer testServer.Close()
c := &ILMClient{
diff --git a/pkg/es/client/index_client.go b/pkg/es/client/index_client.go
index e98acba8c99..3621d33a878 100644
--- a/pkg/es/client/index_client.go
+++ b/pkg/es/client/index_client.go
@@ -68,8 +68,11 @@ func (i *IndicesClient) GetJaegerIndices(prefix string) ([]Index, error) {
prefix += "jaeger-*"
body, err := i.request(elasticRequest{
- endpoint: fmt.Sprintf("%s?flat_settings=true&filter_path=*.aliases,*.settings", prefix),
- method: http.MethodGet,
+ endpoint: fmt.Sprintf(
+ "%s?flat_settings=true&filter_path=*.aliases,*.settings",
+ prefix,
+ ),
+ method: http.MethodGet,
})
if err != nil {
return nil, fmt.Errorf("failed to query indices: %w", err)
@@ -81,7 +84,11 @@ func (i *IndicesClient) GetJaegerIndices(prefix string) ([]Index, error) {
}
var indicesInfo map[string]indexInfo
if err = json.Unmarshal(body, &indicesInfo); err != nil {
- return nil, fmt.Errorf("failed to query indices and unmarshall response body: %q: %w", body, err)
+ return nil, fmt.Errorf(
+ "failed to query indices and unmarshall response body: %q: %w",
+ body,
+ err,
+ )
}
var indices []Index
@@ -91,7 +98,11 @@ func (i *IndicesClient) GetJaegerIndices(prefix string) ([]Index, error) {
aliases[alias] = true
}
// ignoring error, ES should return valid date
- creationDate, _ := strconv.ParseInt(v.Settings["index.creation_date"], 10, 64)
+ creationDate, _ := strconv.ParseInt(
+ v.Settings["index.creation_date"],
+ 10,
+ 64,
+ )
indices = append(indices, Index{
Index: k,
@@ -105,14 +116,20 @@ func (i *IndicesClient) GetJaegerIndices(prefix string) ([]Index, error) {
// execute delete request
func (i *IndicesClient) indexDeleteRequest(concatIndices string) error {
_, err := i.request(elasticRequest{
- endpoint: fmt.Sprintf("%s?master_timeout=%ds", concatIndices, i.MasterTimeoutSeconds),
- method: http.MethodDelete,
+ endpoint: fmt.Sprintf(
+ "%s?master_timeout=%ds",
+ concatIndices,
+ i.MasterTimeoutSeconds,
+ ),
+ method: http.MethodDelete,
})
if err != nil {
var responseError ResponseError
if errors.As(err, &responseError) {
if responseError.StatusCode != http.StatusOK {
- return responseError.prefixMessage(fmt.Sprintf("failed to delete indices: %s", concatIndices))
+ return responseError.prefixMessage(
+ fmt.Sprintf("failed to delete indices: %s", concatIndices),
+ )
}
}
return fmt.Errorf("failed to delete indices: %w", err)
@@ -157,7 +174,9 @@ func (i *IndicesClient) CreateIndex(index string) error {
var responseError ResponseError
if errors.As(err, &responseError) {
if responseError.StatusCode != http.StatusOK {
- return responseError.prefixMessage(fmt.Sprintf("failed to create index: %s", index))
+ return responseError.prefixMessage(
+ fmt.Sprintf("failed to create index: %s", index),
+ )
}
}
return fmt.Errorf("failed to create index: %w", err)
@@ -172,7 +191,9 @@ func (i *IndicesClient) CreateAlias(aliases []Alias) error {
var responseError ResponseError
if errors.As(err, &responseError) {
if responseError.StatusCode != http.StatusOK {
- return responseError.prefixMessage(fmt.Sprintf("failed to create aliases: %s", i.aliasesString(aliases)))
+ return responseError.prefixMessage(
+ fmt.Sprintf("failed to create aliases: %s", i.aliasesString(aliases)),
+ )
}
}
return fmt.Errorf("failed to create aliases: %w", err)
@@ -187,7 +208,9 @@ func (i *IndicesClient) DeleteAlias(aliases []Alias) error {
var responseError ResponseError
if errors.As(err, &responseError) {
if responseError.StatusCode != http.StatusOK {
- return responseError.prefixMessage(fmt.Sprintf("failed to delete aliases: %s", i.aliasesString(aliases)))
+ return responseError.prefixMessage(
+ fmt.Sprintf("failed to delete aliases: %s", i.aliasesString(aliases)),
+ )
}
}
return fmt.Errorf("failed to delete aliases: %w", err)
@@ -198,7 +221,11 @@ func (i *IndicesClient) DeleteAlias(aliases []Alias) error {
func (*IndicesClient) aliasesString(aliases []Alias) string {
concatAliases := ""
for _, alias := range aliases {
- concatAliases += fmt.Sprintf("[index: %s, alias: %s],", alias.Index, alias.Name)
+ concatAliases += fmt.Sprintf(
+ "[index: %s, alias: %s],",
+ alias.Index,
+ alias.Name,
+ )
}
return strings.Trim(concatAliases, ",")
}
@@ -258,7 +285,9 @@ func (i IndicesClient) CreateTemplate(template, name string) error {
var responseError ResponseError
if errors.As(err, &responseError) {
if responseError.StatusCode != http.StatusOK {
- return responseError.prefixMessage(fmt.Sprintf("failed to create template: %s", name))
+ return responseError.prefixMessage(
+ fmt.Sprintf("failed to create template: %s", name),
+ )
}
}
return fmt.Errorf("failed to create template: %w", err)
@@ -267,7 +296,10 @@ func (i IndicesClient) CreateTemplate(template, name string) error {
}
// Rollover create a rollover for certain index/alias
-func (i IndicesClient) Rollover(rolloverTarget string, conditions map[string]any) error {
+func (i IndicesClient) Rollover(
+ rolloverTarget string,
+ conditions map[string]any,
+) error {
esReq := elasticRequest{
endpoint: fmt.Sprintf("%s/_rollover/", rolloverTarget),
method: http.MethodPost,
@@ -287,7 +319,12 @@ func (i IndicesClient) Rollover(rolloverTarget string, conditions map[string]any
var responseError ResponseError
if errors.As(err, &responseError) {
if responseError.StatusCode != http.StatusOK {
- return responseError.prefixMessage(fmt.Sprintf("failed to create rollover target: %s", rolloverTarget))
+ return responseError.prefixMessage(
+ fmt.Sprintf(
+ "failed to create rollover target: %s",
+ rolloverTarget,
+ ),
+ )
}
}
return fmt.Errorf("failed to create rollover: %w", err)
diff --git a/pkg/es/client/index_client_test.go b/pkg/es/client/index_client_test.go
index 57610fdd5d1..c9f7cd8f745 100644
--- a/pkg/es/client/index_client_test.go
+++ b/pkg/es/client/index_client_test.go
@@ -86,19 +86,31 @@ func TestClientGetIndices(t *testing.T) {
response: esIndexResponse,
indices: []Index{
{
- Index: "jaeger-service-2021-08-06",
- CreationTime: time.Unix(0, int64(time.Millisecond)*1628259381266),
- Aliases: map[string]bool{},
+ Index: "jaeger-service-2021-08-06",
+ CreationTime: time.Unix(
+ 0,
+ int64(time.Millisecond)*1628259381266,
+ ),
+ Aliases: map[string]bool{},
},
{
- Index: "jaeger-span-000001",
- CreationTime: time.Unix(0, int64(time.Millisecond)*1628259381326),
- Aliases: map[string]bool{"jaeger-span-read": true, "jaeger-span-write": true},
+ Index: "jaeger-span-000001",
+ CreationTime: time.Unix(
+ 0,
+ int64(time.Millisecond)*1628259381326,
+ ),
+ Aliases: map[string]bool{
+ "jaeger-span-read": true,
+ "jaeger-span-write": true,
+ },
},
{
- Index: "jaeger-span-2021-08-06",
- CreationTime: time.Unix(0, int64(time.Millisecond)*1628259381326),
- Aliases: map[string]bool{},
+ Index: "jaeger-span-2021-08-06",
+ CreationTime: time.Unix(
+ 0,
+ int64(time.Millisecond)*1628259381326,
+ ),
+ Aliases: map[string]bool{},
},
},
},
@@ -109,19 +121,31 @@ func TestClientGetIndices(t *testing.T) {
response: esIndexResponse,
indices: []Index{
{
- Index: "foo-jaeger-service-2021-08-06",
- CreationTime: time.Unix(0, int64(time.Millisecond)*1628259381266),
- Aliases: map[string]bool{},
+ Index: "foo-jaeger-service-2021-08-06",
+ CreationTime: time.Unix(
+ 0,
+ int64(time.Millisecond)*1628259381266,
+ ),
+ Aliases: map[string]bool{},
},
{
- Index: "foo-jaeger-span-000001",
- CreationTime: time.Unix(0, int64(time.Millisecond)*1628259381326),
- Aliases: map[string]bool{"jaeger-span-read": true, "jaeger-span-write": true},
+ Index: "foo-jaeger-span-000001",
+ CreationTime: time.Unix(
+ 0,
+ int64(time.Millisecond)*1628259381326,
+ ),
+ Aliases: map[string]bool{
+ "jaeger-span-read": true,
+ "jaeger-span-write": true,
+ },
},
{
- Index: "foo-jaeger-span-2021-08-06",
- CreationTime: time.Unix(0, int64(time.Millisecond)*1628259381326),
- Aliases: map[string]bool{},
+ Index: "foo-jaeger-span-2021-08-06",
+ CreationTime: time.Unix(
+ 0,
+ int64(time.Millisecond)*1628259381326,
+ ),
+ Aliases: map[string]bool{},
},
},
},
@@ -140,16 +164,25 @@ func TestClientGetIndices(t *testing.T) {
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
- testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
- res.WriteHeader(test.responseCode)
-
- response := test.response
- if test.errContains == "" {
- // Formatted string only applies to "success" response bodies.
- response = fmt.Sprintf(test.response, test.prefix, test.prefix, test.prefix)
- }
- res.Write([]byte(response))
- }))
+ testServer := httptest.NewServer(
+ http.HandlerFunc(
+ func(res http.ResponseWriter, req *http.Request) {
+ res.WriteHeader(test.responseCode)
+
+ response := test.response
+ if test.errContains == "" {
+ // Formatted string only applies to "success" response bodies.
+ response = fmt.Sprintf(
+ test.response,
+ test.prefix,
+ test.prefix,
+ test.prefix,
+ )
+ }
+ res.Write([]byte(response))
+ },
+ ),
+ )
defer testServer.Close()
c := &IndicesClient{
@@ -178,8 +211,14 @@ func TestClientGetIndices(t *testing.T) {
func getIndicesList(size int) []Index {
indicesList := []Index{}
for count := 1; count <= size/2; count++ {
- indicesList = append(indicesList, Index{Index: fmt.Sprintf("jaeger-span-%06d", count)})
- indicesList = append(indicesList, Index{Index: fmt.Sprintf("jaeger-service-%06d", count)})
+ indicesList = append(
+ indicesList,
+ Index{Index: fmt.Sprintf("jaeger-span-%06d", count)},
+ )
+ indicesList = append(
+ indicesList,
+ Index{Index: fmt.Sprintf("jaeger-service-%06d", count)},
+ )
}
return indicesList
}
@@ -243,28 +282,44 @@ func TestClientDeleteIndices(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
deletedIndicesCount := 0
apiTriggered := false
- testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
- apiTriggered = true
- assert.Equal(t, http.MethodDelete, req.Method)
- assert.Equal(t, "Basic foobar", req.Header.Get("Authorization"))
- assert.Equal(t, fmt.Sprintf("%ds", masterTimeoutSeconds), req.URL.Query().Get("master_timeout"))
- assert.LessOrEqual(t, len(req.URL.Path), maxURLPathLength)
-
- // removes leading '/' and trailing ','
- // example: /jaeger-span-000001, => jaeger-span-000001
- rawIndices := strings.TrimPrefix(req.URL.Path, "/")
- rawIndices = strings.TrimSuffix(rawIndices, ",")
-
- if len(test.indices) == 1 {
- assert.Equal(t, test.indices[0].Index, rawIndices)
- }
-
- deletedIndices := strings.Split(rawIndices, ",")
- deletedIndicesCount += len(deletedIndices)
-
- res.WriteHeader(test.responseCode)
- res.Write([]byte(test.response))
- }))
+ testServer := httptest.NewServer(
+ http.HandlerFunc(
+ func(res http.ResponseWriter, req *http.Request) {
+ apiTriggered = true
+ assert.Equal(t, http.MethodDelete, req.Method)
+ assert.Equal(
+ t,
+ "Basic foobar",
+ req.Header.Get("Authorization"),
+ )
+ assert.Equal(
+ t,
+ fmt.Sprintf("%ds", masterTimeoutSeconds),
+ req.URL.Query().Get("master_timeout"),
+ )
+ assert.LessOrEqual(
+ t,
+ len(req.URL.Path),
+ maxURLPathLength,
+ )
+
+ // removes leading '/' and trailing ','
+ // example: /jaeger-span-000001, => jaeger-span-000001
+ rawIndices := strings.TrimPrefix(req.URL.Path, "/")
+ rawIndices = strings.TrimSuffix(rawIndices, ",")
+
+ if len(test.indices) == 1 {
+ assert.Equal(t, test.indices[0].Index, rawIndices)
+ }
+
+ deletedIndices := strings.Split(rawIndices, ",")
+ deletedIndicesCount += len(deletedIndices)
+
+ res.WriteHeader(test.responseCode)
+ res.Write([]byte(test.response))
+ },
+ ),
+ )
defer testServer.Close()
c := &IndicesClient{
@@ -334,13 +389,24 @@ func TestClientCreateIndex(t *testing.T) {
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
- testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
- assert.True(t, strings.HasSuffix(req.URL.String(), "jaeger-span"))
- assert.Equal(t, http.MethodPut, req.Method)
- assert.Equal(t, "Basic foobar", req.Header.Get("Authorization"))
- res.WriteHeader(test.responseCode)
- res.Write([]byte(test.response))
- }))
+ testServer := httptest.NewServer(
+ http.HandlerFunc(
+ func(res http.ResponseWriter, req *http.Request) {
+ assert.True(
+ t,
+ strings.HasSuffix(req.URL.String(), "jaeger-span"),
+ )
+ assert.Equal(t, http.MethodPut, req.Method)
+ assert.Equal(
+ t,
+ "Basic foobar",
+ req.Header.Get("Authorization"),
+ )
+ res.WriteHeader(test.responseCode)
+ res.Write([]byte(test.response))
+ },
+ ),
+ )
defer testServer.Close()
c := &IndicesClient{
@@ -391,16 +457,27 @@ func TestClientCreateAliases(t *testing.T) {
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
- testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
- assert.True(t, strings.HasSuffix(req.URL.String(), "_aliases"))
- assert.Equal(t, http.MethodPost, req.Method)
- assert.Equal(t, "Basic foobar", req.Header.Get("Authorization"))
- body, err := io.ReadAll(req.Body)
- require.NoError(t, err)
- assert.Equal(t, expectedRequestBody, string(body))
- res.WriteHeader(test.responseCode)
- res.Write([]byte(test.response))
- }))
+ testServer := httptest.NewServer(
+ http.HandlerFunc(
+ func(res http.ResponseWriter, req *http.Request) {
+ assert.True(
+ t,
+ strings.HasSuffix(req.URL.String(), "_aliases"),
+ )
+ assert.Equal(t, http.MethodPost, req.Method)
+ assert.Equal(
+ t,
+ "Basic foobar",
+ req.Header.Get("Authorization"),
+ )
+ body, err := io.ReadAll(req.Body)
+ require.NoError(t, err)
+ assert.Equal(t, expectedRequestBody, string(body))
+ res.WriteHeader(test.responseCode)
+ res.Write([]byte(test.response))
+ },
+ ),
+ )
defer testServer.Close()
c := &IndicesClient{
@@ -451,16 +528,27 @@ func TestClientDeleteAliases(t *testing.T) {
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
- testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
- assert.True(t, strings.HasSuffix(req.URL.String(), "_aliases"))
- assert.Equal(t, http.MethodPost, req.Method)
- assert.Equal(t, "Basic foobar", req.Header.Get("Authorization"))
- body, err := io.ReadAll(req.Body)
- require.NoError(t, err)
- assert.Equal(t, expectedRequestBody, string(body))
- res.WriteHeader(test.responseCode)
- res.Write([]byte(test.response))
- }))
+ testServer := httptest.NewServer(
+ http.HandlerFunc(
+ func(res http.ResponseWriter, req *http.Request) {
+ assert.True(
+ t,
+ strings.HasSuffix(req.URL.String(), "_aliases"),
+ )
+ assert.Equal(t, http.MethodPost, req.Method)
+ assert.Equal(
+ t,
+ "Basic foobar",
+ req.Header.Get("Authorization"),
+ )
+ body, err := io.ReadAll(req.Body)
+ require.NoError(t, err)
+ assert.Equal(t, expectedRequestBody, string(body))
+ res.WriteHeader(test.responseCode)
+ res.Write([]byte(test.response))
+ },
+ ),
+ )
defer testServer.Close()
c := &IndicesClient{
@@ -509,22 +597,36 @@ func TestClientCreateTemplate(t *testing.T) {
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
- testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
- if req.URL.String() == "/" { // ES version check
- res.WriteHeader(http.StatusOK)
- res.Write([]byte(test.versionResp))
- return
- }
- assert.True(t, strings.HasSuffix(req.URL.String(), "_template/jaeger-template"))
- assert.Equal(t, http.MethodPut, req.Method)
- assert.Equal(t, "Basic foobar", req.Header.Get("Authorization"))
- body, err := io.ReadAll(req.Body)
- require.NoError(t, err)
- assert.Equal(t, templateContent, string(body))
-
- res.WriteHeader(test.responseCode)
- res.Write([]byte(test.response))
- }))
+ testServer := httptest.NewServer(
+ http.HandlerFunc(
+ func(res http.ResponseWriter, req *http.Request) {
+ if req.URL.String() == "/" { // ES version check
+ res.WriteHeader(http.StatusOK)
+ res.Write([]byte(test.versionResp))
+ return
+ }
+ assert.True(
+ t,
+ strings.HasSuffix(
+ req.URL.String(),
+ "_template/jaeger-template",
+ ),
+ )
+ assert.Equal(t, http.MethodPut, req.Method)
+ assert.Equal(
+ t,
+ "Basic foobar",
+ req.Header.Get("Authorization"),
+ )
+ body, err := io.ReadAll(req.Body)
+ require.NoError(t, err)
+ assert.Equal(t, templateContent, string(body))
+
+ res.WriteHeader(test.responseCode)
+ res.Write([]byte(test.response))
+ },
+ ),
+ )
defer testServer.Close()
c := &IndicesClient{
@@ -568,17 +670,31 @@ func TestRollover(t *testing.T) {
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
- testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) {
- assert.True(t, strings.HasSuffix(req.URL.String(), "jaeger-span/_rollover/"))
- assert.Equal(t, http.MethodPost, req.Method)
- assert.Equal(t, "Basic foobar", req.Header.Get("Authorization"))
- body, err := io.ReadAll(req.Body)
- require.NoError(t, err)
- assert.Equal(t, expectedRequestBody, string(body))
-
- res.WriteHeader(test.responseCode)
- res.Write([]byte(test.response))
- }))
+ testServer := httptest.NewServer(
+ http.HandlerFunc(
+ func(res http.ResponseWriter, req *http.Request) {
+ assert.True(
+ t,
+ strings.HasSuffix(
+ req.URL.String(),
+ "jaeger-span/_rollover/",
+ ),
+ )
+ assert.Equal(t, http.MethodPost, req.Method)
+ assert.Equal(
+ t,
+ "Basic foobar",
+ req.Header.Get("Authorization"),
+ )
+ body, err := io.ReadAll(req.Body)
+ require.NoError(t, err)
+ assert.Equal(t, expectedRequestBody, string(body))
+
+ res.WriteHeader(test.responseCode)
+ res.Write([]byte(test.response))
+ },
+ ),
+ )
defer testServer.Close()
c := &IndicesClient{
diff --git a/pkg/es/client/mocks/index_client.go b/pkg/es/client/mocks/index_client.go
index 1382b3e7f89..bb35939b24b 100644
--- a/pkg/es/client/mocks/index_client.go
+++ b/pkg/es/client/mocks/index_client.go
@@ -48,7 +48,11 @@ func (c *MockIndexAPI) CreateTemplate(template, name string) error {
ret := c.Called(template, name)
return ret.Error(0)
}
-func (c *MockIndexAPI) Rollover(rolloverTarget string, conditions map[string]interface{}) error {
+
+func (c *MockIndexAPI) Rollover(
+ rolloverTarget string,
+ conditions map[string]interface{},
+) error {
ret := c.Called(rolloverTarget, conditions)
return ret.Error(0)
}
diff --git a/pkg/es/config/config.go b/pkg/es/config/config.go
index 5738f0797b9..e93a73b1f79 100644
--- a/pkg/es/config/config.go
+++ b/pkg/es/config/config.go
@@ -46,10 +46,10 @@ import (
// Configuration describes the configuration properties needed to connect to an ElasticSearch cluster
type Configuration struct {
- Servers []string `mapstructure:"server_urls" valid:"required,url"`
+ Servers []string `mapstructure:"server_urls" valid:"required,url"`
RemoteReadClusters []string `mapstructure:"remote_read_clusters"`
Username string `mapstructure:"username"`
- Password string `mapstructure:"password" json:"-"`
+ Password string `mapstructure:"password" json:"-"`
TokenFilePath string `mapstructure:"token_file"`
PasswordFilePath string `mapstructure:"password_file"`
AllowTokenFromContext bool `mapstructure:"-"`
@@ -103,7 +103,11 @@ type TagsAsFields struct {
}
// NewClient creates a new ElasticSearch client
-func NewClient(c *Configuration, logger *zap.Logger, metricsFactory metrics.Factory) (es.Client, error) {
+func NewClient(
+ c *Configuration,
+ logger *zap.Logger,
+ metricsFactory metrics.Factory,
+) (es.Client, error) {
if len(c.Servers) < 1 {
return nil, errors.New("no servers specified")
}
@@ -136,8 +140,11 @@ func NewClient(c *Configuration, logger *zap.Logger, metricsFactory metrics.Fact
for _, it := range response.Items {
for key, val := range it {
if val.Error != nil {
- logger.Error("Elasticsearch part of bulk request failed", zap.String("map-key", key),
- zap.Reflect("response", val))
+ logger.Error(
+ "Elasticsearch part of bulk request failed",
+ zap.String("map-key", key),
+ zap.Reflect("response", val),
+ )
}
}
}
@@ -170,7 +177,8 @@ func NewClient(c *Configuration, logger *zap.Logger, metricsFactory metrics.Fact
if c.Version == 0 {
// Determine ElasticSearch Version
- pingResult, _, err := rawClient.Ping(c.Servers[0]).Do(context.Background())
+ pingResult, _, err := rawClient.Ping(c.Servers[0]).
+ Do(context.Background())
if err != nil {
return nil, err
}
@@ -181,11 +189,15 @@ func NewClient(c *Configuration, logger *zap.Logger, metricsFactory metrics.Fact
// OpenSearch is based on ES 7.x
if strings.Contains(pingResult.TagLine, "OpenSearch") {
if pingResult.Version.Number[0] == '1' {
- logger.Info("OpenSearch 1.x detected, using ES 7.x index mappings")
+ logger.Info(
+ "OpenSearch 1.x detected, using ES 7.x index mappings",
+ )
esVersion = 7
}
if pingResult.Version.Number[0] == '2' {
- logger.Info("OpenSearch 2.x detected, using ES 7.x index mappings")
+ logger.Info(
+ "OpenSearch 2.x detected, using ES 7.x index mappings",
+ )
esVersion = 7
}
}
@@ -201,10 +213,18 @@ func NewClient(c *Configuration, logger *zap.Logger, metricsFactory metrics.Fact
}
}
- return eswrapper.WrapESClient(rawClient, bulkProc, c.Version, rawClientV8), nil
+ return eswrapper.WrapESClient(
+ rawClient,
+ bulkProc,
+ c.Version,
+ rawClientV8,
+ ), nil
}
-func newElasticsearchV8(c *Configuration, logger *zap.Logger) (*esV8.Client, error) {
+func newElasticsearchV8(
+ c *Configuration,
+ logger *zap.Logger,
+) (*esV8.Client, error) {
var options esV8.Config
options.Addresses = c.Servers
options.Username = c.Username
@@ -346,7 +366,9 @@ func (c *Configuration) TagKeysAsFields() ([]string, error) {
}
// getConfigOptions wraps the configs to feed to the ElasticSearch client init
-func (c *Configuration) getConfigOptions(logger *zap.Logger) ([]elastic.ClientOptionFunc, error) {
+func (c *Configuration) getConfigOptions(
+ logger *zap.Logger,
+) ([]elastic.ClientOptionFunc, error) {
options := []elastic.ClientOptionFunc{
elastic.SetURL(c.Servers...), elastic.SetSniff(c.Sniffer),
// Disable health check when token from context is allowed, this is because at this time
@@ -391,7 +413,10 @@ func (c *Configuration) getConfigOptions(logger *zap.Logger) ([]elastic.ClientOp
return options, nil
}
-func addLoggerOptions(options []elastic.ClientOptionFunc, logLevel string) ([]elastic.ClientOptionFunc, error) {
+func addLoggerOptions(
+ options []elastic.ClientOptionFunc,
+ logLevel string,
+) ([]elastic.ClientOptionFunc, error) {
// Decouple ES logger from the log-level assigned to the parent application's log-level; otherwise, the least
// permissive log-level will dominate.
// e.g. --log-level=info and --es.log-level=debug would mute ES's debug logging and would require --log-level=debug
@@ -428,7 +453,10 @@ func addLoggerOptions(options []elastic.ClientOptionFunc, logLevel string) ([]el
}
// GetHTTPRoundTripper returns configured http.RoundTripper
-func GetHTTPRoundTripper(c *Configuration, logger *zap.Logger) (http.RoundTripper, error) {
+func GetHTTPRoundTripper(
+ c *Configuration,
+ logger *zap.Logger,
+) (http.RoundTripper, error) {
if c.TLS.Enabled {
ctlsConfig, err := c.TLS.Config(logger)
if err != nil {
@@ -457,7 +485,9 @@ func GetHTTPRoundTripper(c *Configuration, logger *zap.Logger) (http.RoundTrippe
token := ""
if c.TokenFilePath != "" {
if c.AllowTokenFromContext {
- logger.Warn("Token file and token propagation are both enabled, token from file won't be used")
+ logger.Warn(
+ "Token file and token propagation are both enabled, token from file won't be used",
+ )
}
tokenFromFile, err := loadTokenFromFile(c.TokenFilePath)
if err != nil {
diff --git a/pkg/es/errors.go b/pkg/es/errors.go
index d29c0e157e7..62064df834d 100644
--- a/pkg/es/errors.go
+++ b/pkg/es/errors.go
@@ -25,7 +25,12 @@ func DetailedError(err error) error {
if esErr.Details != nil && len(esErr.Details.RootCause) > 0 {
rc := esErr.Details.RootCause[0]
if rc != nil {
- return fmt.Errorf("%w: RootCause[%s [type=%s]]", err, rc.Reason, rc.Type)
+ return fmt.Errorf(
+ "%w: RootCause[%s [type=%s]]",
+ err,
+ rc.Reason,
+ rc.Type,
+ )
}
}
}
diff --git a/pkg/es/filter/alias.go b/pkg/es/filter/alias.go
index 631271f784e..b5ccdc99b32 100644
--- a/pkg/es/filter/alias.go
+++ b/pkg/es/filter/alias.go
@@ -34,7 +34,11 @@ func ByAliasExclude(indices []client.Index, aliases []string) []client.Index {
return filterByAliasWithOptions(indices, aliases, true)
}
-func filterByAliasWithOptions(indices []client.Index, aliases []string, exclude bool) []client.Index {
+func filterByAliasWithOptions(
+ indices []client.Index,
+ aliases []string,
+ exclude bool,
+) []client.Index {
var results []client.Index
for _, alias := range aliases {
for _, index := range indices {
@@ -50,7 +54,10 @@ func filterByAliasWithOptions(indices []client.Index, aliases []string, exclude
return results
}
-func exlude(indices []client.Index, exclusionList []client.Index) []client.Index {
+func exlude(
+ indices []client.Index,
+ exclusionList []client.Index,
+) []client.Index {
excludedIndices := make([]client.Index, 0, len(indices))
for _, idx := range indices {
if !contains(idx, exclusionList) {
diff --git a/pkg/es/filter/alias_test.go b/pkg/es/filter/alias_test.go
index e230f3e1232..3dbf9b0dee5 100644
--- a/pkg/es/filter/alias_test.go
+++ b/pkg/es/filter/alias_test.go
@@ -60,7 +60,10 @@ var indices = []client.Index{
}
func TestByAlias(t *testing.T) {
- filtered := ByAlias(indices, []string{"jaeger-span-read", "jaeger-span-other"})
+ filtered := ByAlias(
+ indices,
+ []string{"jaeger-span-read", "jaeger-span-other"},
+ )
expected := []client.Index{
{
Index: "jaeger-span-0001",
@@ -92,7 +95,10 @@ func TestByAlias(t *testing.T) {
}
func TestByAliasExclude(t *testing.T) {
- filtered := ByAliasExclude(indices, []string{"jaeger-span-read", "jaeger-span-other"})
+ filtered := ByAliasExclude(
+ indices,
+ []string{"jaeger-span-read", "jaeger-span-other"},
+ )
expected := []client.Index{
{
Index: "jaeger-span-0005",
diff --git a/pkg/es/filter/date_test.go b/pkg/es/filter/date_test.go
index 89f7054a69f..5fdba5d6769 100644
--- a/pkg/es/filter/date_test.go
+++ b/pkg/es/filter/date_test.go
@@ -65,8 +65,17 @@ func TestByDate(t *testing.T) {
},
},
{
- Index: "jaeger-span-0001",
- CreationTime: time.Date(2021, 10, 10, 12, 0o0, 0o0, 0o0, time.Local),
+ Index: "jaeger-span-0001",
+ CreationTime: time.Date(
+ 2021,
+ 10,
+ 10,
+ 12,
+ 0o0,
+ 0o0,
+ 0o0,
+ time.Local,
+ ),
Aliases: map[string]bool{
"jaeger-span-write": true,
"jaeger-span-read": true,
diff --git a/pkg/es/textTemplate_test.go b/pkg/es/textTemplate_test.go
index 2db810508a9..e9124cd8b37 100644
--- a/pkg/es/textTemplate_test.go
+++ b/pkg/es/textTemplate_test.go
@@ -35,5 +35,9 @@ func TestParse(t *testing.T) {
require.NoError(t, err)
err = parsedStr.Execute(writer, values)
require.NoError(t, err)
- assert.Equal(t, "Parse is a wrapper for text/template parse function.", writer.String())
+ assert.Equal(
+ t,
+ "Parse is a wrapper for text/template parse function.",
+ writer.String(),
+ )
}
diff --git a/pkg/es/wrapper/wrapper.go b/pkg/es/wrapper/wrapper.go
index 16e503020eb..52e4218b399 100644
--- a/pkg/es/wrapper/wrapper.go
+++ b/pkg/es/wrapper/wrapper.go
@@ -43,7 +43,12 @@ func (c ClientWrapper) GetVersion() uint {
}
// WrapESClient creates a ESClient out of *elastic.Client.
-func WrapESClient(client *elastic.Client, s *elastic.BulkProcessor, esVersion uint, clientV8 *esV8.Client) ClientWrapper {
+func WrapESClient(
+ client *elastic.Client,
+ s *elastic.BulkProcessor,
+ esVersion uint,
+ clientV8 *esV8.Client,
+) ClientWrapper {
return ClientWrapper{
client: client,
bulkService: s,
@@ -116,8 +121,12 @@ type IndicesExistsServiceWrapper struct {
}
// WrapESIndicesExistsService creates an ESIndicesExistsService out of *elastic.IndicesExistsService.
-func WrapESIndicesExistsService(indicesExistsService *elastic.IndicesExistsService) IndicesExistsServiceWrapper {
- return IndicesExistsServiceWrapper{indicesExistsService: indicesExistsService}
+func WrapESIndicesExistsService(
+ indicesExistsService *elastic.IndicesExistsService,
+) IndicesExistsServiceWrapper {
+ return IndicesExistsServiceWrapper{
+ indicesExistsService: indicesExistsService,
+ }
}
// Do calls this function to internal service.
@@ -133,17 +142,25 @@ type IndicesCreateServiceWrapper struct {
}
// WrapESIndicesCreateService creates an ESIndicesCreateService out of *elastic.IndicesCreateService.
-func WrapESIndicesCreateService(indicesCreateService *elastic.IndicesCreateService) IndicesCreateServiceWrapper {
- return IndicesCreateServiceWrapper{indicesCreateService: indicesCreateService}
+func WrapESIndicesCreateService(
+ indicesCreateService *elastic.IndicesCreateService,
+) IndicesCreateServiceWrapper {
+ return IndicesCreateServiceWrapper{
+ indicesCreateService: indicesCreateService,
+ }
}
// Body calls this function to internal service.
-func (c IndicesCreateServiceWrapper) Body(mapping string) es.IndicesCreateService {
+func (c IndicesCreateServiceWrapper) Body(
+ mapping string,
+) es.IndicesCreateService {
return WrapESIndicesCreateService(c.indicesCreateService.Body(mapping))
}
// Do calls this function to internal service.
-func (c IndicesCreateServiceWrapper) Do(ctx context.Context) (*elastic.IndicesCreateResult, error) {
+func (c IndicesCreateServiceWrapper) Do(
+ ctx context.Context,
+) (*elastic.IndicesCreateResult, error) {
return c.indicesCreateService.Do(ctx)
}
@@ -158,27 +175,43 @@ type IndicesDeleteServiceWrapper struct {
}
// WrapESIndicesDeleteService creates an ESIndicesDeleteService out of *elastic.IndicesDeleteService.
-func WrapESIndicesDeleteService(indicesDeleteService *elastic.IndicesDeleteService) IndicesDeleteServiceWrapper {
- return IndicesDeleteServiceWrapper{indicesDeleteService: indicesDeleteService}
+func WrapESIndicesDeleteService(
+ indicesDeleteService *elastic.IndicesDeleteService,
+) IndicesDeleteServiceWrapper {
+ return IndicesDeleteServiceWrapper{
+ indicesDeleteService: indicesDeleteService,
+ }
}
// Do calls this function to internal service.
-func (e IndicesDeleteServiceWrapper) Do(ctx context.Context) (*elastic.IndicesDeleteResponse, error) {
+func (e IndicesDeleteServiceWrapper) Do(
+ ctx context.Context,
+) (*elastic.IndicesDeleteResponse, error) {
return e.indicesDeleteService.Do(ctx)
}
// WrapESTemplateCreateService creates an TemplateCreateService out of *elastic.IndicesPutTemplateService.
-func WrapESTemplateCreateService(mappingCreateService *elastic.IndicesPutTemplateService) TemplateCreateServiceWrapper {
- return TemplateCreateServiceWrapper{mappingCreateService: mappingCreateService}
+func WrapESTemplateCreateService(
+ mappingCreateService *elastic.IndicesPutTemplateService,
+) TemplateCreateServiceWrapper {
+ return TemplateCreateServiceWrapper{
+ mappingCreateService: mappingCreateService,
+ }
}
// Body calls this function to internal service.
-func (c TemplateCreateServiceWrapper) Body(mapping string) es.TemplateCreateService {
- return WrapESTemplateCreateService(c.mappingCreateService.BodyString(mapping))
+func (c TemplateCreateServiceWrapper) Body(
+ mapping string,
+) es.TemplateCreateService {
+ return WrapESTemplateCreateService(
+ c.mappingCreateService.BodyString(mapping),
+ )
}
// Do calls this function to internal service.
-func (c TemplateCreateServiceWrapper) Do(ctx context.Context) (*elastic.IndicesPutTemplateResponse, error) {
+func (c TemplateCreateServiceWrapper) Do(
+ ctx context.Context,
+) (*elastic.IndicesPutTemplateResponse, error) {
return c.mappingCreateService.Do(ctx)
}
@@ -192,20 +225,35 @@ type TemplateCreatorWrapperV8 struct {
}
// Body adds mapping to the future request.
-func (c TemplateCreatorWrapperV8) Body(mapping string) es.TemplateCreateService {
+func (c TemplateCreatorWrapperV8) Body(
+ mapping string,
+) es.TemplateCreateService {
cc := c // clone
cc.templateMapping = mapping
return cc
}
// Do executes Put Template command.
-func (c TemplateCreatorWrapperV8) Do(ctx context.Context) (*elastic.IndicesPutTemplateResponse, error) {
- resp, err := c.indicesV8.PutIndexTemplate(c.templateName, strings.NewReader(c.templateMapping))
+func (c TemplateCreatorWrapperV8) Do(
+ ctx context.Context,
+) (*elastic.IndicesPutTemplateResponse, error) {
+ resp, err := c.indicesV8.PutIndexTemplate(
+ c.templateName,
+ strings.NewReader(c.templateMapping),
+ )
if err != nil {
- return nil, fmt.Errorf("error creating index template %s: %w", c.templateName, err)
+ return nil, fmt.Errorf(
+ "error creating index template %s: %w",
+ c.templateName,
+ err,
+ )
}
if resp.StatusCode != 200 {
- return nil, fmt.Errorf("error creating index template %s: %s", c.templateName, resp)
+ return nil, fmt.Errorf(
+ "error creating index template %s: %s",
+ c.templateName,
+ resp,
+ )
}
return nil, nil // no response expected by span writer
}
@@ -221,13 +269,21 @@ type IndexServiceWrapper struct {
}
// WrapESIndexService creates an ESIndexService out of *elastic.ESIndexService.
-func WrapESIndexService(indexService *elastic.BulkIndexRequest, bulkService *elastic.BulkProcessor, esVersion uint) IndexServiceWrapper {
+func WrapESIndexService(
+ indexService *elastic.BulkIndexRequest,
+ bulkService *elastic.BulkProcessor,
+ esVersion uint,
+) IndexServiceWrapper {
return IndexServiceWrapper{bulkIndexReq: indexService, bulkService: bulkService, esVersion: esVersion}
}
// Index calls this function to internal service.
func (i IndexServiceWrapper) Index(index string) es.IndexService {
- return WrapESIndexService(i.bulkIndexReq.Index(index), i.bulkService, i.esVersion)
+ return WrapESIndexService(
+ i.bulkIndexReq.Index(index),
+ i.bulkService,
+ i.esVersion,
+ )
}
// Type calls this function to internal service.
@@ -235,7 +291,11 @@ func (i IndexServiceWrapper) Type(typ string) es.IndexService {
if i.esVersion >= 7 {
return WrapESIndexService(i.bulkIndexReq, i.bulkService, i.esVersion)
}
- return WrapESIndexService(i.bulkIndexReq.Type(typ), i.bulkService, i.esVersion)
+ return WrapESIndexService(
+ i.bulkIndexReq.Type(typ),
+ i.bulkService,
+ i.esVersion,
+ )
}
// Add adds the request to bulk service
@@ -251,7 +311,9 @@ type SearchServiceWrapper struct {
}
// WrapESSearchService creates an ESSearchService out of *elastic.ESSearchService.
-func WrapESSearchService(searchService *elastic.SearchService) SearchServiceWrapper {
+func WrapESSearchService(
+ searchService *elastic.SearchService,
+) SearchServiceWrapper {
return SearchServiceWrapper{searchService: searchService}
}
@@ -261,13 +323,20 @@ func (s SearchServiceWrapper) Size(size int) es.SearchService {
}
// Aggregation calls this function to internal service.
-func (s SearchServiceWrapper) Aggregation(name string, aggregation elastic.Aggregation) es.SearchService {
+func (s SearchServiceWrapper) Aggregation(
+ name string,
+ aggregation elastic.Aggregation,
+) es.SearchService {
return WrapESSearchService(s.searchService.Aggregation(name, aggregation))
}
// IgnoreUnavailable calls this function to internal service.
-func (s SearchServiceWrapper) IgnoreUnavailable(ignoreUnavailable bool) es.SearchService {
- return WrapESSearchService(s.searchService.IgnoreUnavailable(ignoreUnavailable))
+func (s SearchServiceWrapper) IgnoreUnavailable(
+ ignoreUnavailable bool,
+) es.SearchService {
+ return WrapESSearchService(
+ s.searchService.IgnoreUnavailable(ignoreUnavailable),
+ )
}
// Query calls this function to internal service.
@@ -276,7 +345,9 @@ func (s SearchServiceWrapper) Query(query elastic.Query) es.SearchService {
}
// Do calls this function to internal service.
-func (s SearchServiceWrapper) Do(ctx context.Context) (*elastic.SearchResult, error) {
+func (s SearchServiceWrapper) Do(
+ ctx context.Context,
+) (*elastic.SearchResult, error) {
return s.searchService.Do(ctx)
}
@@ -286,21 +357,29 @@ type MultiSearchServiceWrapper struct {
}
// WrapESMultiSearchService creates an ESSearchService out of *elastic.ESSearchService.
-func WrapESMultiSearchService(multiSearchService *elastic.MultiSearchService) MultiSearchServiceWrapper {
+func WrapESMultiSearchService(
+ multiSearchService *elastic.MultiSearchService,
+) MultiSearchServiceWrapper {
return MultiSearchServiceWrapper{multiSearchService: multiSearchService}
}
// Add calls this function to internal service.
-func (s MultiSearchServiceWrapper) Add(requests ...*elastic.SearchRequest) es.MultiSearchService {
+func (s MultiSearchServiceWrapper) Add(
+ requests ...*elastic.SearchRequest,
+) es.MultiSearchService {
return WrapESMultiSearchService(s.multiSearchService.Add(requests...))
}
// Index calls this function to internal service.
-func (s MultiSearchServiceWrapper) Index(indices ...string) es.MultiSearchService {
+func (s MultiSearchServiceWrapper) Index(
+ indices ...string,
+) es.MultiSearchService {
return WrapESMultiSearchService(s.multiSearchService.Index(indices...))
}
// Do calls this function to internal service.
-func (s MultiSearchServiceWrapper) Do(ctx context.Context) (*elastic.MultiSearchResult, error) {
+func (s MultiSearchServiceWrapper) Do(
+ ctx context.Context,
+) (*elastic.MultiSearchResult, error) {
return s.multiSearchService.Do(ctx)
}
diff --git a/pkg/es/wrapper/wrapper_nolint.go b/pkg/es/wrapper/wrapper_nolint.go
index 3f076e252c7..437835f5ac8 100644
--- a/pkg/es/wrapper/wrapper_nolint.go
+++ b/pkg/es/wrapper/wrapper_nolint.go
@@ -26,5 +26,9 @@ func (i IndexServiceWrapper) Id(id string) es.IndexService {
// BodyJson calls this function to internal service.
func (i IndexServiceWrapper) BodyJson(body any) es.IndexService {
- return WrapESIndexService(i.bulkIndexReq.Doc(body), i.bulkService, i.esVersion)
+ return WrapESIndexService(
+ i.bulkIndexReq.Doc(body),
+ i.bulkService,
+ i.esVersion,
+ )
}
diff --git a/pkg/fswatcher/fswatcher.go b/pkg/fswatcher/fswatcher.go
index fa7ef7f8ca5..b366ebf12bf 100644
--- a/pkg/fswatcher/fswatcher.go
+++ b/pkg/fswatcher/fswatcher.go
@@ -57,7 +57,11 @@ type FSWatcher struct {
// indicate that the files were replaced, even if event.Name is not any of the
// files we are monitoring. We check the hashes of the files to detect if they
// were really changed.
-func New(filepaths []string, onChange func(), logger *zap.Logger) (*FSWatcher, error) {
+func New(
+ filepaths []string,
+ onChange func(),
+ logger *zap.Logger,
+) (*FSWatcher, error) {
watcher, err := fsnotify.NewWatcher()
if err != nil {
return nil, err
@@ -143,10 +147,17 @@ func (w *FSWatcher) Close() error {
}
// isModified returns true if the file has been modified since the last check.
-func (w *FSWatcher) isModified(filepath string, previousHash string) (bool, string) {
+func (w *FSWatcher) isModified(
+ filepath string,
+ previousHash string,
+) (bool, string) {
hash, err := hashFile(filepath)
if err != nil {
- w.logger.Warn("Unable to read the file", zap.String("file", filepath), zap.Error(err))
+ w.logger.Warn(
+ "Unable to read the file",
+ zap.String("file", filepath),
+ zap.Error(err),
+ )
return true, ""
}
return previousHash != hash, hash
diff --git a/pkg/fswatcher/fswatcher_test.go b/pkg/fswatcher/fswatcher_test.go
index 3bae95a2e44..5767f74c0a8 100644
--- a/pkg/fswatcher/fswatcher_test.go
+++ b/pkg/fswatcher/fswatcher_test.go
@@ -108,7 +108,11 @@ func TestFSWatcherWithMultipleFiles(t *testing.T) {
logger.Info("Change happens")
}
- w, err := New([]string{testFile1.Name(), testFile2.Name()}, onChange, logger)
+ w, err := New(
+ []string{testFile1.Name(), testFile2.Name()},
+ onChange,
+ logger,
+ )
require.NoError(t, err)
require.IsType(t, &FSWatcher{}, w)
defer w.Close()
@@ -143,16 +147,28 @@ func TestFSWatcherWithMultipleFiles(t *testing.T) {
return logObserver.FilterMessage("Received event").Len() > 0
},
"Unable to locate 'Received event' in log. All logs: %v", logObserver)
- assertLogs(t,
+ assertLogs(
+ t,
func() bool {
- return logObserver.FilterMessage("Unable to read the file").FilterField(zap.String("file", testFile1.Name())).Len() > 0
+ return logObserver.FilterMessage("Unable to read the file").
+ FilterField(zap.String("file", testFile1.Name())).
+ Len() >
+ 0
},
- "Unable to locate 'Unable to read the file' in log. All logs: %v", logObserver)
- assertLogs(t,
+ "Unable to locate 'Unable to read the file' in log. All logs: %v",
+ logObserver,
+ )
+ assertLogs(
+ t,
func() bool {
- return logObserver.FilterMessage("Unable to read the file").FilterField(zap.String("file", testFile2.Name())).Len() > 0
+ return logObserver.FilterMessage("Unable to read the file").
+ FilterField(zap.String("file", testFile2.Name())).
+ Len() >
+ 0
},
- "Unable to locate 'Unable to read the file' in log. All logs: %v", logObserver)
+ "Unable to locate 'Unable to read the file' in log. All logs: %v",
+ logObserver,
+ )
}
func TestFSWatcherWithSymlinkAndRepoChanges(t *testing.T) {
@@ -160,7 +176,10 @@ func TestFSWatcherWithSymlinkAndRepoChanges(t *testing.T) {
err := os.Symlink("..timestamp-1", filepath.Join(testDir, "..data"))
require.NoError(t, err)
- err = os.Symlink(filepath.Join("..data", "test.doc"), filepath.Join(testDir, "test.doc"))
+ err = os.Symlink(
+ filepath.Join("..data", "test.doc"),
+ filepath.Join(testDir, "test.doc"),
+ )
require.NoError(t, err)
timestamp1Dir := filepath.Join(testDir, "..timestamp-1")
@@ -171,7 +190,11 @@ func TestFSWatcherWithSymlinkAndRepoChanges(t *testing.T) {
onChange := func() {}
- w, err := New([]string{filepath.Join(testDir, "test.doc")}, onChange, logger)
+ w, err := New(
+ []string{filepath.Join(testDir, "test.doc")},
+ onChange,
+ logger,
+ )
require.NoError(t, err)
require.IsType(t, &FSWatcher{}, w)
defer w.Close()
@@ -182,7 +205,10 @@ func TestFSWatcherWithSymlinkAndRepoChanges(t *testing.T) {
err = os.Symlink("..timestamp-2", filepath.Join(testDir, "..data_tmp"))
require.NoError(t, err)
- os.Rename(filepath.Join(testDir, "..data_tmp"), filepath.Join(testDir, "..data"))
+ os.Rename(
+ filepath.Join(testDir, "..data_tmp"),
+ filepath.Join(testDir, "..data"),
+ )
require.NoError(t, err)
err = os.RemoveAll(timestamp1Dir)
require.NoError(t, err)
@@ -200,7 +226,10 @@ func TestFSWatcherWithSymlinkAndRepoChanges(t *testing.T) {
createTimestampDir(t, timestamp3Dir)
err = os.Symlink("..timestamp-3", filepath.Join(testDir, "..data_tmp"))
require.NoError(t, err)
- os.Rename(filepath.Join(testDir, "..data_tmp"), filepath.Join(testDir, "..data"))
+ os.Rename(
+ filepath.Join(testDir, "..data_tmp"),
+ filepath.Join(testDir, "..data"),
+ )
require.NoError(t, err)
err = os.RemoveAll(timestamp2Dir)
require.NoError(t, err)
@@ -220,7 +249,11 @@ func createTimestampDir(t *testing.T, dir string) {
err := os.MkdirAll(dir, 0o700)
require.NoError(t, err)
- err = os.WriteFile(filepath.Join(dir, "test.doc"), []byte("test data"), 0o600)
+ err = os.WriteFile(
+ filepath.Join(dir, "test.doc"),
+ []byte("test data"),
+ 0o600,
+ )
require.NoError(t, err)
}
@@ -232,7 +265,12 @@ func (df delayedFormat) String() string {
return fmt.Sprintf("%v", df.fn())
}
-func assertLogs(t *testing.T, f func() bool, errorMsg string, logObserver *observer.ObservedLogs) {
+func assertLogs(
+ t *testing.T,
+ f func() bool,
+ errorMsg string,
+ logObserver *observer.ObservedLogs,
+) {
assert.Eventuallyf(t, f,
10*time.Second, 10*time.Millisecond,
errorMsg,
diff --git a/pkg/gzipfs/gzip_test.go b/pkg/gzipfs/gzip_test.go
index a2902d7655f..3edde2ca82f 100644
--- a/pkg/gzipfs/gzip_test.go
+++ b/pkg/gzipfs/gzip_test.go
@@ -67,7 +67,16 @@ func TestFS(t *testing.T) {
expectedName: "foobar",
expectedSize: 11,
expectedContent: "hello world",
- expectedModTime: time.Date(1, 1, 1, 0, 0, 0, 0 /* nanos */, time.UTC),
+ expectedModTime: time.Date(
+ 1,
+ 1,
+ 1,
+ 0,
+ 0,
+ 0,
+ 0, /* nanos */
+ time.UTC,
+ ),
},
{
name: "compressed file",
@@ -76,7 +85,16 @@ func TestFS(t *testing.T) {
expectedName: "foobar.gz",
expectedSize: 38,
expectedContent: "", // actual gzipped payload is returned
- expectedModTime: time.Date(1, 1, 1, 0, 0, 0, 0 /* nanos */, time.UTC),
+ expectedModTime: time.Date(
+ 1,
+ 1,
+ 1,
+ 0,
+ 0,
+ 0,
+ 0, /* nanos */
+ time.UTC,
+ ),
},
{
name: "compressed file accessed without gz extension",
@@ -85,7 +103,16 @@ func TestFS(t *testing.T) {
expectedName: "foobaz",
expectedSize: 11,
expectedContent: "hello world",
- expectedModTime: time.Date(1, 1, 1, 0, 0, 0, 0 /* nanos */, time.UTC),
+ expectedModTime: time.Date(
+ 1,
+ 1,
+ 1,
+ 0,
+ 0,
+ 0,
+ 0, /* nanos */
+ time.UTC,
+ ),
},
{
name: "non-existing file",
diff --git a/pkg/healthcheck/handler.go b/pkg/healthcheck/handler.go
index b1860fa2349..130110a1584 100644
--- a/pkg/healthcheck/handler.go
+++ b/pkg/healthcheck/handler.go
@@ -106,7 +106,10 @@ func (hc *HealthCheck) Handler() http.Handler {
})
}
-func (*HealthCheck) createRespBody(state state, template healthCheckResponse) []byte {
+func (*HealthCheck) createRespBody(
+ state state,
+ template healthCheckResponse,
+) []byte {
resp := template // clone
if state.status == Ready {
resp.UpSince = state.upSince
diff --git a/pkg/healthcheck/handler_test.go b/pkg/healthcheck/handler_test.go
index dc26fd98433..ece68725bfe 100644
--- a/pkg/healthcheck/handler_test.go
+++ b/pkg/healthcheck/handler_test.go
@@ -49,12 +49,18 @@ func TestStatusSetGet(t *testing.T) {
hc.Ready()
assert.Equal(t, healthcheck.Ready, hc.Get())
- assert.Equal(t, map[string]string{"level": "info", "msg": "Health Check state change", "status": "ready"}, logBuf.JSONLine(0))
+ assert.Equal(
+ t,
+ map[string]string{"level": "info", "msg": "Health Check state change", "status": "ready"},
+ logBuf.JSONLine(0),
+ )
}
func TestHealthCheck_Handler_ContentType(t *testing.T) {
rec := httptest.NewRecorder()
- healthcheck.New().Handler().ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/", nil))
+ healthcheck.New().
+ Handler().
+ ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/", nil))
resp := rec.Result()
assert.Equal(t, "application/json", resp.Header.Get("Content-Type"))
diff --git a/pkg/healthcheck/internal_test.go b/pkg/healthcheck/internal_test.go
index be3624410c6..e527b612839 100644
--- a/pkg/healthcheck/internal_test.go
+++ b/pkg/healthcheck/internal_test.go
@@ -44,7 +44,10 @@ func TestHttpCall(t *testing.T) {
assert.Equal(t, "Server available", hr.StatusMsg)
// de-serialized timestamp loses monotonic clock value, so assert.Equals() doesn't work.
// https://github.com/stretchr/testify/issues/502
- if want, have := hc.getState().upSince, hr.UpSince; !assert.True(t, want.Equal(have)) {
+ if want, have := hc.getState().upSince, hr.UpSince; !assert.True(
+ t,
+ want.Equal(have),
+ ) {
t.Logf("want='%v', have='%v'", want, have)
}
assert.NotZero(t, hr.Uptime)
@@ -62,7 +65,10 @@ func TestHttpCall(t *testing.T) {
assert.Zero(t, hrNew.UpSince)
}
-func parseHealthCheckResponse(t *testing.T, resp *http.Response) healthCheckResponse {
+func parseHealthCheckResponse(
+ t *testing.T,
+ resp *http.Response,
+) healthCheckResponse {
body, err := io.ReadAll(resp.Body)
require.NoError(t, err)
var hr healthCheckResponse
diff --git a/pkg/httpmetrics/metrics.go b/pkg/httpmetrics/metrics.go
index 0db8cc5e47d..49764af496a 100644
--- a/pkg/httpmetrics/metrics.go
+++ b/pkg/httpmetrics/metrics.go
@@ -49,7 +49,11 @@ func (r *statusRecorder) WriteHeader(status int) {
//
// Do not use with HTTP endpoints that take parameters from URL path, such as `/user/{user_id}`,
// because they will result in high cardinality metrics.
-func Wrap(h http.Handler, metricsFactory metrics.Factory, logger *zap.Logger) http.Handler {
+func Wrap(
+ h http.Handler,
+ metricsFactory metrics.Factory,
+ logger *zap.Logger,
+) http.Handler {
timers := newRequestDurations(metricsFactory, logger)
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
start := time.Now()
@@ -91,7 +95,10 @@ type requestDurations struct {
fallback metrics.Timer
}
-func newRequestDurations(metricsFactory metrics.Factory, logger *zap.Logger) *requestDurations {
+func newRequestDurations(
+ metricsFactory metrics.Factory,
+ logger *zap.Logger,
+) *requestDurations {
r := &requestDurations{
timers: make(map[recordedRequestKey]metrics.Timer),
metrics: metricsFactory,
@@ -131,11 +138,17 @@ func (r *requestDurations) getTimer(cacheKey recordedRequestKey) metrics.Timer {
return timer
}
-func (r *requestDurations) buildTimer(metricsFactory metrics.Factory, key recordedRequestKey) (out metrics.Timer) {
+func (r *requestDurations) buildTimer(
+ metricsFactory metrics.Factory,
+ key recordedRequestKey,
+) (out metrics.Timer) {
// deal with https://github.com/jaegertracing/jaeger/issues/2944
defer func() {
if err := recover(); err != nil {
- r.logger.Error("panic in metrics factory trying to create a timer", zap.Any("error", err))
+ r.logger.Error(
+ "panic in metrics factory trying to create a timer",
+ zap.Any("error", err),
+ )
out = metrics.NullTimer
}
}()
diff --git a/pkg/httpmetrics/metrics_test.go b/pkg/httpmetrics/metrics_test.go
index b9c24455221..beaaf3ccd80 100644
--- a/pkg/httpmetrics/metrics_test.go
+++ b/pkg/httpmetrics/metrics_test.go
@@ -31,11 +31,15 @@ import (
)
func TestNewMetricsHandler(t *testing.T) {
- dummyHandlerFunc := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
- time.Sleep(time.Millisecond)
- w.WriteHeader(http.StatusAccepted)
- w.WriteHeader(http.StatusTeapot) // any subsequent statuses should be ignored
- })
+ dummyHandlerFunc := http.HandlerFunc(
+ func(w http.ResponseWriter, req *http.Request) {
+ time.Sleep(time.Millisecond)
+ w.WriteHeader(http.StatusAccepted)
+ w.WriteHeader(
+ http.StatusTeapot,
+ ) // any subsequent statuses should be ignored
+ },
+ )
mb := metricstest.NewFactory(time.Hour)
defer mb.Stop()
@@ -53,7 +57,10 @@ func TestNewMetricsHandler(t *testing.T) {
time.Sleep(15 * time.Millisecond)
}
- assert.Fail(t, "gauge hasn't been updated within a reasonable amount of time")
+ assert.Fail(
+ t,
+ "gauge hasn't been updated within a reasonable amount of time",
+ )
}
func TestMaxEntries(t *testing.T) {
@@ -74,11 +81,15 @@ func TestMaxEntries(t *testing.T) {
}
func TestIllegalPrometheusLabel(t *testing.T) {
- dummyHandlerFunc := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
- time.Sleep(time.Millisecond)
- w.WriteHeader(http.StatusAccepted)
- w.WriteHeader(http.StatusTeapot) // any subsequent statuses should be ignored
- })
+ dummyHandlerFunc := http.HandlerFunc(
+ func(w http.ResponseWriter, req *http.Request) {
+ time.Sleep(time.Millisecond)
+ w.WriteHeader(http.StatusAccepted)
+ w.WriteHeader(
+ http.StatusTeapot,
+ ) // any subsequent statuses should be ignored
+ },
+ )
mf := prometheus.New().Namespace(metrics.NSOptions{})
handler := Wrap(dummyHandlerFunc, mf, zap.NewNop())
diff --git a/pkg/jtracer/jtracer.go b/pkg/jtracer/jtracer.go
index fa5abe0c2a2..05cf4e3db1f 100644
--- a/pkg/jtracer/jtracer.go
+++ b/pkg/jtracer/jtracer.go
@@ -65,7 +65,10 @@ func NoOp() *JTracer {
}
// initOTEL initializes OTEL Tracer
-func initOTEL(ctx context.Context, svc string) (*sdktrace.TracerProvider, error) {
+func initOTEL(
+ ctx context.Context,
+ svc string,
+) (*sdktrace.TracerProvider, error) {
return initHelper(ctx, svc, otelExporter, otelResource)
}
diff --git a/pkg/jtracer/jtracer_test.go b/pkg/jtracer/jtracer_test.go
index 403bf241d91..fc2f717b70b 100644
--- a/pkg/jtracer/jtracer_test.go
+++ b/pkg/jtracer/jtracer_test.go
@@ -47,7 +47,8 @@ func TestNewHelperProviderError(t *testing.T) {
"svc",
func(ctx context.Context, svc string) (*sdktrace.TracerProvider, error) {
return nil, fakeErr
- })
+ },
+ )
require.Error(t, err)
require.EqualError(t, err, fakeErr.Error())
}
diff --git a/pkg/kafka/auth/config.go b/pkg/kafka/auth/config.go
index 8292792da3b..7f13e510c67 100644
--- a/pkg/kafka/auth/config.go
+++ b/pkg/kafka/auth/config.go
@@ -48,7 +48,10 @@ type AuthenticationConfig struct {
}
// SetConfiguration set configure authentication into sarama config structure
-func (config *AuthenticationConfig) SetConfiguration(saramaConfig *sarama.Config, logger *zap.Logger) error {
+func (config *AuthenticationConfig) SetConfiguration(
+ saramaConfig *sarama.Config,
+ logger *zap.Logger,
+) error {
authentication := strings.ToLower(config.Authentication)
if strings.Trim(authentication, " ") == "" {
authentication = none
@@ -70,21 +73,43 @@ func (config *AuthenticationConfig) SetConfiguration(saramaConfig *sarama.Config
case plaintext:
return setPlainTextConfiguration(&config.PlainText, saramaConfig)
default:
- return fmt.Errorf("Unknown/Unsupported authentication method %s to kafka cluster", config.Authentication)
+ return fmt.Errorf(
+ "Unknown/Unsupported authentication method %s to kafka cluster",
+ config.Authentication,
+ )
}
}
// InitFromViper loads authentication configuration from viper flags.
-func (config *AuthenticationConfig) InitFromViper(configPrefix string, v *viper.Viper) error {
+func (config *AuthenticationConfig) InitFromViper(
+ configPrefix string,
+ v *viper.Viper,
+) error {
config.Authentication = v.GetString(configPrefix + suffixAuthentication)
- config.Kerberos.ServiceName = v.GetString(configPrefix + kerberosPrefix + suffixKerberosServiceName)
- config.Kerberos.Realm = v.GetString(configPrefix + kerberosPrefix + suffixKerberosRealm)
- config.Kerberos.UseKeyTab = v.GetBool(configPrefix + kerberosPrefix + suffixKerberosUseKeyTab)
- config.Kerberos.Username = v.GetString(configPrefix + kerberosPrefix + suffixKerberosUsername)
- config.Kerberos.Password = v.GetString(configPrefix + kerberosPrefix + suffixKerberosPassword)
- config.Kerberos.ConfigPath = v.GetString(configPrefix + kerberosPrefix + suffixKerberosConfig)
- config.Kerberos.KeyTabPath = v.GetString(configPrefix + kerberosPrefix + suffixKerberosKeyTab)
- config.Kerberos.DisablePAFXFast = v.GetBool(configPrefix + kerberosPrefix + suffixKerberosDisablePAFXFAST)
+ config.Kerberos.ServiceName = v.GetString(
+ configPrefix + kerberosPrefix + suffixKerberosServiceName,
+ )
+ config.Kerberos.Realm = v.GetString(
+ configPrefix + kerberosPrefix + suffixKerberosRealm,
+ )
+ config.Kerberos.UseKeyTab = v.GetBool(
+ configPrefix + kerberosPrefix + suffixKerberosUseKeyTab,
+ )
+ config.Kerberos.Username = v.GetString(
+ configPrefix + kerberosPrefix + suffixKerberosUsername,
+ )
+ config.Kerberos.Password = v.GetString(
+ configPrefix + kerberosPrefix + suffixKerberosPassword,
+ )
+ config.Kerberos.ConfigPath = v.GetString(
+ configPrefix + kerberosPrefix + suffixKerberosConfig,
+ )
+ config.Kerberos.KeyTabPath = v.GetString(
+ configPrefix + kerberosPrefix + suffixKerberosKeyTab,
+ )
+ config.Kerberos.DisablePAFXFast = v.GetBool(
+ configPrefix + kerberosPrefix + suffixKerberosDisablePAFXFAST,
+ )
tlsClientConfig := tlscfg.ClientFlagsConfig{
Prefix: configPrefix,
@@ -99,8 +124,14 @@ func (config *AuthenticationConfig) InitFromViper(configPrefix string, v *viper.
config.TLS.Enabled = true
}
- config.PlainText.Username = v.GetString(configPrefix + plainTextPrefix + suffixPlainTextUsername)
- config.PlainText.Password = v.GetString(configPrefix + plainTextPrefix + suffixPlainTextPassword)
- config.PlainText.Mechanism = v.GetString(configPrefix + plainTextPrefix + suffixPlainTextMechanism)
+ config.PlainText.Username = v.GetString(
+ configPrefix + plainTextPrefix + suffixPlainTextUsername,
+ )
+ config.PlainText.Password = v.GetString(
+ configPrefix + plainTextPrefix + suffixPlainTextPassword,
+ )
+ config.PlainText.Mechanism = v.GetString(
+ configPrefix + plainTextPrefix + suffixPlainTextMechanism,
+ )
return nil
}
diff --git a/pkg/kafka/auth/kerberos.go b/pkg/kafka/auth/kerberos.go
index c8a83cdcdfb..7c3fec1d0a6 100644
--- a/pkg/kafka/auth/kerberos.go
+++ b/pkg/kafka/auth/kerberos.go
@@ -24,13 +24,16 @@ type KerberosConfig struct {
Realm string `mapstructure:"realm"`
UseKeyTab bool `mapstructure:"use_keytab"`
Username string `mapstructure:"username"`
- Password string `mapstructure:"password" json:"-"`
+ Password string `mapstructure:"password" json:"-"`
ConfigPath string `mapstructure:"config_file"`
KeyTabPath string `mapstructure:"keytab_file"`
DisablePAFXFast bool `mapstructure:"disable_pa_fx_fast"`
}
-func setKerberosConfiguration(config *KerberosConfig, saramaConfig *sarama.Config) {
+func setKerberosConfiguration(
+ config *KerberosConfig,
+ saramaConfig *sarama.Config,
+) {
saramaConfig.Net.SASL.Mechanism = sarama.SASLTypeGSSAPI
saramaConfig.Net.SASL.Enable = true
if config.UseKeyTab {
diff --git a/pkg/kafka/auth/options.go b/pkg/kafka/auth/options.go
index 5a484a13eca..4820ea4edb6 100644
--- a/pkg/kafka/auth/options.go
+++ b/pkg/kafka/auth/options.go
@@ -79,7 +79,8 @@ func addKerberosFlags(configPrefix string, flagSet *flag.FlagSet) {
flagSet.Bool(
configPrefix+kerberosPrefix+suffixKerberosUseKeyTab,
defaultKerberosUseKeyTab,
- "Use of keytab instead of password, if this is true, keytab file will be used instead of password")
+ "Use of keytab instead of password, if this is true, keytab file will be used instead of password",
+ )
flagSet.String(
configPrefix+kerberosPrefix+suffixKerberosKeyTab,
defaultKerberosKeyTab,
@@ -87,7 +88,8 @@ func addKerberosFlags(configPrefix string, flagSet *flag.FlagSet) {
flagSet.Bool(
configPrefix+kerberosPrefix+suffixKerberosDisablePAFXFAST,
defaultKerberosDisablePAFXFast,
- "Disable FAST negotiation when not supported by KDC's like Active Directory. See https://github.com/jcmturner/gokrb5/blob/master/USAGE.md#active-directory-kdc-and-fast-negotiation.")
+ "Disable FAST negotiation when not supported by KDC's like Active Directory. See https://github.com/jcmturner/gokrb5/blob/master/USAGE.md#active-directory-kdc-and-fast-negotiation.",
+ )
}
func addPlainTextFlags(configPrefix string, flagSet *flag.FlagSet) {
@@ -102,7 +104,8 @@ func addPlainTextFlags(configPrefix string, flagSet *flag.FlagSet) {
flagSet.String(
configPrefix+plainTextPrefix+suffixPlainTextMechanism,
defaultPlainTextMechanism,
- "The plaintext Mechanism for SASL/PLAIN authentication, e.g. 'SCRAM-SHA-256' or 'SCRAM-SHA-512' or 'PLAIN'")
+ "The plaintext Mechanism for SASL/PLAIN authentication, e.g. 'SCRAM-SHA-256' or 'SCRAM-SHA-512' or 'PLAIN'",
+ )
}
// AddFlags add configuration flags to a flagSet.
@@ -110,7 +113,10 @@ func AddFlags(configPrefix string, flagSet *flag.FlagSet) {
flagSet.String(
configPrefix+suffixAuthentication,
defaultAuthentication,
- "Authentication type used to authenticate with kafka cluster. e.g. "+strings.Join(authTypes, ", "),
+ "Authentication type used to authenticate with kafka cluster. e.g. "+strings.Join(
+ authTypes,
+ ", ",
+ ),
)
addKerberosFlags(configPrefix, flagSet)
diff --git a/pkg/kafka/auth/plaintext.go b/pkg/kafka/auth/plaintext.go
index 81d940bb130..24d0a2dc7ef 100644
--- a/pkg/kafka/auth/plaintext.go
+++ b/pkg/kafka/auth/plaintext.go
@@ -55,7 +55,7 @@ func (x *scramClient) Done() bool {
// PlainTextConfig describes the configuration properties needed for SASL/PLAIN with kafka
type PlainTextConfig struct {
Username string `mapstructure:"username"`
- Password string `mapstructure:"password" json:"-"`
+ Password string `mapstructure:"password" json:"-"`
Mechanism string `mapstructure:"mechanism"`
}
@@ -67,22 +67,32 @@ func clientGenFunc(hashFn scram.HashGeneratorFcn) func() sarama.SCRAMClient {
}
}
-func setPlainTextConfiguration(config *PlainTextConfig, saramaConfig *sarama.Config) error {
+func setPlainTextConfiguration(
+ config *PlainTextConfig,
+ saramaConfig *sarama.Config,
+) error {
saramaConfig.Net.SASL.Enable = true
saramaConfig.Net.SASL.User = config.Username
saramaConfig.Net.SASL.Password = config.Password
switch strings.ToUpper(config.Mechanism) {
case "SCRAM-SHA-256":
- saramaConfig.Net.SASL.SCRAMClientGeneratorFunc = clientGenFunc(scram.SHA256)
+ saramaConfig.Net.SASL.SCRAMClientGeneratorFunc = clientGenFunc(
+ scram.SHA256,
+ )
saramaConfig.Net.SASL.Mechanism = sarama.SASLTypeSCRAMSHA256
case "SCRAM-SHA-512":
- saramaConfig.Net.SASL.SCRAMClientGeneratorFunc = clientGenFunc(scram.SHA512)
+ saramaConfig.Net.SASL.SCRAMClientGeneratorFunc = clientGenFunc(
+ scram.SHA512,
+ )
saramaConfig.Net.SASL.Mechanism = sarama.SASLTypeSCRAMSHA512
case "PLAIN":
saramaConfig.Net.SASL.Mechanism = sarama.SASLTypePlaintext
default:
- return fmt.Errorf("config plaintext.mechanism error: %s, only support 'SCRAM-SHA-256' or 'SCRAM-SHA-512' or 'PLAIN'", config.Mechanism)
+ return fmt.Errorf(
+ "config plaintext.mechanism error: %s, only support 'SCRAM-SHA-256' or 'SCRAM-SHA-512' or 'PLAIN'",
+ config.Mechanism,
+ )
}
return nil
}
diff --git a/pkg/kafka/auth/tls.go b/pkg/kafka/auth/tls.go
index bdd743edcf1..8ccac562178 100644
--- a/pkg/kafka/auth/tls.go
+++ b/pkg/kafka/auth/tls.go
@@ -23,7 +23,11 @@ import (
"github.com/jaegertracing/jaeger/pkg/config/tlscfg"
)
-func setTLSConfiguration(config *tlscfg.Options, saramaConfig *sarama.Config, logger *zap.Logger) error {
+func setTLSConfiguration(
+ config *tlscfg.Options,
+ saramaConfig *sarama.Config,
+ logger *zap.Logger,
+) error {
if config.Enabled {
tlsConfig, err := config.Config(logger)
if err != nil {
diff --git a/pkg/kafka/consumer/config.go b/pkg/kafka/consumer/config.go
index 402ffeedd56..3f0072151bc 100644
--- a/pkg/kafka/consumer/config.go
+++ b/pkg/kafka/consumer/config.go
@@ -28,7 +28,12 @@ import (
// Consumer is an interface to features of Sarama that are necessary for the consumer
type Consumer interface {
Partitions() <-chan cluster.PartitionConsumer
- MarkPartitionOffset(topic string, partition int32, offset int64, metadata string)
+ MarkPartitionOffset(
+ topic string,
+ partition int32,
+ offset int64,
+ metadata string,
+ )
io.Closer
}
@@ -77,5 +82,10 @@ func (c *Configuration) NewConsumer(logger *zap.Logger) (Consumer, error) {
if c.InitialOffset != 0 {
saramaConfig.Consumer.Offsets.Initial = c.InitialOffset
}
- return cluster.NewConsumer(c.Brokers, c.GroupID, []string{c.Topic}, saramaConfig)
+ return cluster.NewConsumer(
+ c.Brokers,
+ c.GroupID,
+ []string{c.Topic},
+ saramaConfig,
+ )
}
diff --git a/pkg/kafka/producer/config.go b/pkg/kafka/producer/config.go
index 6e9cfa53cd1..b2e1398e650 100644
--- a/pkg/kafka/producer/config.go
+++ b/pkg/kafka/producer/config.go
@@ -44,7 +44,9 @@ type Configuration struct {
}
// NewProducer creates a new asynchronous kafka producer
-func (c *Configuration) NewProducer(logger *zap.Logger) (sarama.AsyncProducer, error) {
+func (c *Configuration) NewProducer(
+ logger *zap.Logger,
+) (sarama.AsyncProducer, error) {
saramaConfig := sarama.NewConfig()
saramaConfig.Producer.RequiredAcks = c.RequiredAcks
saramaConfig.Producer.Compression = c.Compression
diff --git a/pkg/metrics/metrics.go b/pkg/metrics/metrics.go
index a7954ded67d..3ee713f2b96 100644
--- a/pkg/metrics/metrics.go
+++ b/pkg/metrics/metrics.go
@@ -71,7 +71,10 @@ func Init(m any, factory Factory, globalTags map[string]string) error {
if len(tag) != 2 {
return fmt.Errorf(
"Field [%s]: Tag [%s] is not of the form key=value in 'tags' string [%s]",
- field.Name, tagPair, tagString)
+ field.Name,
+ tagPair,
+ tagString,
+ )
}
tags[tag[0]] = tag[1]
}
@@ -82,7 +85,8 @@ func Init(m any, factory Factory, globalTags map[string]string) error {
// TODO: Parse timer duration buckets
return fmt.Errorf(
"Field [%s]: Buckets are not currently initialized for timer metrics",
- field.Name)
+ field.Name,
+ )
case field.Type.AssignableTo(histogramPtrType):
bucketValues := strings.Split(bucketString, ",")
for _, bucket := range bucketValues {
@@ -90,14 +94,18 @@ func Init(m any, factory Factory, globalTags map[string]string) error {
if err != nil {
return fmt.Errorf(
"Field [%s]: Bucket [%s] could not be converted to float64 in 'buckets' string [%s]",
- field.Name, bucket, bucketString)
+ field.Name,
+ bucket,
+ bucketString,
+ )
}
buckets = append(buckets, b)
}
default:
return fmt.Errorf(
"Field [%s]: Buckets should only be defined for Timer and Histogram metric types",
- field.Name)
+ field.Name,
+ )
}
}
help := field.Tag.Get("help")
diff --git a/pkg/metrics/metrics_test.go b/pkg/metrics/metrics_test.go
index d9ca191c795..000f8cd4f8c 100644
--- a/pkg/metrics/metrics_test.go
+++ b/pkg/metrics/metrics_test.go
@@ -96,22 +96,38 @@ var (
)
func TestInitMetricsFailures(t *testing.T) {
- require.EqualError(t, metrics.Init(&noMetricTag, nil, nil), "Field NoMetricTag is missing a tag 'metric'")
-
- require.EqualError(t, metrics.Init(&badTags, nil, nil),
- "Field [BadTags]: Tag [noValue] is not of the form key=value in 'tags' string [1=one,noValue]")
+ require.EqualError(
+ t,
+ metrics.Init(&noMetricTag, nil, nil),
+ "Field NoMetricTag is missing a tag 'metric'",
+ )
+
+ require.EqualError(
+ t,
+ metrics.Init(&badTags, nil, nil),
+ "Field [BadTags]: Tag [noValue] is not of the form key=value in 'tags' string [1=one,noValue]",
+ )
require.EqualError(t, metrics.Init(&invalidMetricType, nil, nil),
"Field InvalidMetricType is not a pointer to timer, gauge, or counter")
- require.EqualError(t, metrics.Init(&badHistogramBucket, nil, nil),
- "Field [BadHistogramBucket]: Bucket [a] could not be converted to float64 in 'buckets' string [1,2,a,4]")
-
- require.EqualError(t, metrics.Init(&badTimerBucket, nil, nil),
- "Field [BadTimerBucket]: Buckets are not currently initialized for timer metrics")
-
- require.EqualError(t, metrics.Init(&invalidBuckets, nil, nil),
- "Field [InvalidBuckets]: Buckets should only be defined for Timer and Histogram metric types")
+ require.EqualError(
+ t,
+ metrics.Init(&badHistogramBucket, nil, nil),
+ "Field [BadHistogramBucket]: Bucket [a] could not be converted to float64 in 'buckets' string [1,2,a,4]",
+ )
+
+ require.EqualError(
+ t,
+ metrics.Init(&badTimerBucket, nil, nil),
+ "Field [BadTimerBucket]: Buckets are not currently initialized for timer metrics",
+ )
+
+ require.EqualError(
+ t,
+ metrics.Init(&invalidBuckets, nil, nil),
+ "Field [InvalidBuckets]: Buckets should only be defined for Timer and Histogram metric types",
+ )
}
func TestInitPanic(t *testing.T) {
diff --git a/pkg/normalizer/service_name_test.go b/pkg/normalizer/service_name_test.go
index 0a994498a2b..4e90fa47c64 100644
--- a/pkg/normalizer/service_name_test.go
+++ b/pkg/normalizer/service_name_test.go
@@ -25,8 +25,18 @@ import (
func TestServiceNameReplacer(t *testing.T) {
assert.Equal(t, "abc", ServiceName("ABC"), "lower case conversion")
- assert.Equal(t, "a_b_c__", ServiceName("a&b%c/:"), "disallowed runes to underscore")
- assert.Equal(t, "a_z_0123456789.", ServiceName("A_Z_0123456789."), "allowed runes")
+ assert.Equal(
+ t,
+ "a_b_c__",
+ ServiceName("a&b%c/:"),
+ "disallowed runes to underscore",
+ )
+ assert.Equal(
+ t,
+ "a_z_0123456789.",
+ ServiceName("A_Z_0123456789."),
+ "allowed runes",
+ )
}
func TestMain(m *testing.M) {
diff --git a/pkg/queue/bounded_queue.go b/pkg/queue/bounded_queue.go
index a0ef1f0abae..98130603dcf 100644
--- a/pkg/queue/bounded_queue.go
+++ b/pkg/queue/bounded_queue.go
@@ -61,7 +61,10 @@ func NewBoundedQueue(capacity int, onDroppedItem func(item any)) *BoundedQueue {
// StartConsumersWithFactory creates a given number of consumers consuming items
// from the queue in separate goroutines.
-func (q *BoundedQueue) StartConsumersWithFactory(num int, factory func() Consumer) {
+func (q *BoundedQueue) StartConsumersWithFactory(
+ num int,
+ factory func() Consumer,
+) {
q.workers = num
q.factory = factory
var startWG sync.WaitGroup
@@ -161,7 +164,10 @@ func (q *BoundedQueue) Capacity() int {
// StartLengthReporting starts a timer-based goroutine that periodically reports
// current queue length to a given metrics gauge.
-func (q *BoundedQueue) StartLengthReporting(reportPeriod time.Duration, gauge metrics.Gauge) {
+func (q *BoundedQueue) StartLengthReporting(
+ reportPeriod time.Duration,
+ gauge metrics.Gauge,
+) {
ticker := time.NewTicker(reportPeriod)
go func() {
defer ticker.Stop()
@@ -189,7 +195,11 @@ func (q *BoundedQueue) Resize(capacity int) bool {
// swap queues
// #nosec
- swapped := atomic.CompareAndSwapPointer((*unsafe.Pointer)(unsafe.Pointer(&q.items)), unsafe.Pointer(q.items), unsafe.Pointer(&queue))
+ swapped := atomic.CompareAndSwapPointer(
+ (*unsafe.Pointer)(unsafe.Pointer(&q.items)),
+ unsafe.Pointer(q.items),
+ unsafe.Pointer(&queue),
+ )
if swapped {
// start a new set of consumers, based on the information given previously
q.StartConsumersWithFactory(q.workers, q.factory)
diff --git a/pkg/queue/bounded_queue_test.go b/pkg/queue/bounded_queue_test.go
index b398d486425..368808dcc54 100644
--- a/pkg/queue/bounded_queue_test.go
+++ b/pkg/queue/bounded_queue_test.go
@@ -34,7 +34,10 @@ import (
// In this test we run a queue with capacity 1 and a single consumer.
// We want to test the overflow behavior, so we block the consumer
// by holding a startLock before submitting items to the queue.
-func helper(t *testing.T, startConsumers func(q *BoundedQueue, consumerFn func(item any))) {
+func helper(
+ t *testing.T,
+ startConsumers func(q *BoundedQueue, consumerFn func(item any)),
+) {
mFact := metricstest.NewFactory(0)
counter := mFact.Counter(metrics.Options{Name: "dropped", Tags: nil})
gauge := mFact.Gauge(metrics.Options{Name: "size", Tags: nil})
@@ -120,7 +123,10 @@ func TestBoundedQueue(t *testing.T) {
func TestBoundedQueueWithFactory(t *testing.T) {
helper(t, func(q *BoundedQueue, consumerFn func(item any)) {
- q.StartConsumersWithFactory(1, func() Consumer { return ConsumerFunc(consumerFn) })
+ q.StartConsumersWithFactory(
+ 1,
+ func() Consumer { return ConsumerFunc(consumerFn) },
+ )
})
}
@@ -161,7 +167,12 @@ func (s *consumerState) waitToConsumeOnce() {
time.Sleep(time.Millisecond)
}
}
- require.EqualValues(s.t, 1, atomic.LoadInt32(&s.consumedOnce), "expected to consumer once")
+ require.EqualValues(
+ s.t,
+ 1,
+ atomic.LoadInt32(&s.consumedOnce),
+ "expected to consumer once",
+ )
}
func (s *consumerState) assertConsumed(expected map[string]bool) {
@@ -212,13 +223,24 @@ func TestResizeUp(t *testing.T) {
assert.True(t, q.Produce("e")) // in process by the second consumer
secondConsumer.Wait()
- assert.True(t, q.Produce("f")) // in the new queue
- assert.True(t, q.Produce("g")) // in the new queue
- assert.False(t, q.Produce("h")) // the new queue has the capacity, but the sum of queues doesn't
+ assert.True(t, q.Produce("f")) // in the new queue
+ assert.True(t, q.Produce("g")) // in the new queue
+ assert.False(
+ t,
+ q.Produce("h"),
+ ) // the new queue has the capacity, but the sum of queues doesn't
assert.EqualValues(t, 4, q.Capacity())
- assert.EqualValues(t, q.Capacity(), q.Size()) // the combined queues are at the capacity right now
- assert.Len(t, *q.items, 2) // the new internal queue should have two items only
+ assert.EqualValues(
+ t,
+ q.Capacity(),
+ q.Size(),
+ ) // the combined queues are at the capacity right now
+ assert.Len(
+ t,
+ *q.items,
+ 2,
+ ) // the new internal queue should have two items only
released = true
releaseConsumers.Done()
@@ -261,8 +283,15 @@ func TestResizeDown(t *testing.T) {
assert.False(t, q.Produce("f")) // dropped
assert.EqualValues(t, 2, q.Capacity())
- assert.EqualValues(t, 4, q.Size()) // the queue will eventually drain, but it will live for a while over capacity
- assert.Empty(t, *q.items) // the new queue is empty, as the old queue is still full and over capacity
+ assert.EqualValues(
+ t,
+ 4,
+ q.Size(),
+ ) // the queue will eventually drain, but it will live for a while over capacity
+ assert.Empty(
+ t,
+ *q.items,
+ ) // the new queue is empty, as the old queue is still full and over capacity
released = true
releaseConsumers.Done()
diff --git a/pkg/recoveryhandler/zap.go b/pkg/recoveryhandler/zap.go
index 4303248dae1..fc73128cf31 100644
--- a/pkg/recoveryhandler/zap.go
+++ b/pkg/recoveryhandler/zap.go
@@ -34,7 +34,13 @@ func (z zapRecoveryWrapper) Println(args ...any) {
}
// NewRecoveryHandler returns an http.Handler that recovers on panics
-func NewRecoveryHandler(logger *zap.Logger, printStack bool) func(h http.Handler) http.Handler {
+func NewRecoveryHandler(
+ logger *zap.Logger,
+ printStack bool,
+) func(h http.Handler) http.Handler {
zWrapper := zapRecoveryWrapper{logger}
- return handlers.RecoveryHandler(handlers.RecoveryLogger(zWrapper), handlers.PrintRecoveryStack(printStack))
+ return handlers.RecoveryHandler(
+ handlers.RecoveryLogger(zWrapper),
+ handlers.PrintRecoveryStack(printStack),
+ )
}
diff --git a/pkg/recoveryhandler/zap_test.go b/pkg/recoveryhandler/zap_test.go
index eee6782d72a..3e23253998f 100644
--- a/pkg/recoveryhandler/zap_test.go
+++ b/pkg/recoveryhandler/zap_test.go
@@ -29,9 +29,11 @@ import (
func TestNewRecoveryHandler(t *testing.T) {
logger, log := testutils.NewLogger()
- handlerFunc := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
- panic("Unexpected error!")
- })
+ handlerFunc := http.HandlerFunc(
+ func(w http.ResponseWriter, req *http.Request) {
+ panic("Unexpected error!")
+ },
+ )
recovery := NewRecoveryHandler(logger, false)(handlerFunc)
req, err := http.NewRequest(http.MethodGet, "/subdir/asdf", nil)
diff --git a/pkg/tenancy/flags.go b/pkg/tenancy/flags.go
index 0a050c4a3ef..f256a5a4161 100644
--- a/pkg/tenancy/flags.go
+++ b/pkg/tenancy/flags.go
@@ -31,11 +31,20 @@ const (
// AddFlags adds flags for tenancy to the FlagSet.
func AddFlags(flags *flag.FlagSet) {
- flags.Bool(flagTenancyEnabled, false, "Enable tenancy header when receiving or querying")
+ flags.Bool(
+ flagTenancyEnabled,
+ false,
+ "Enable tenancy header when receiving or querying",
+ )
flags.String(flagTenancyHeader, "x-tenant", "HTTP header carrying tenant")
- flags.String(flagValidTenants, "",
- fmt.Sprintf("comma-separated list of allowed values for --%s header. (If not supplied, tenants are not restricted)",
- flagTenancyHeader))
+ flags.String(
+ flagValidTenants,
+ "",
+ fmt.Sprintf(
+ "comma-separated list of allowed values for --%s header. (If not supplied, tenants are not restricted)",
+ flagTenancyHeader,
+ ),
+ )
}
// InitFromViper creates tenancy.Options populated with values retrieved from Viper.
diff --git a/pkg/tenancy/grpc.go b/pkg/tenancy/grpc.go
index d17cfada1e0..d54b55028e3 100644
--- a/pkg/tenancy/grpc.go
+++ b/pkg/tenancy/grpc.go
@@ -38,7 +38,10 @@ func getValidTenant(ctx context.Context, tc *Manager) (string, error) {
tenant := GetTenant(ctx)
if tenant != "" {
if !tc.Valid(tenant) {
- return tenant, status.Errorf(codes.PermissionDenied, "unknown tenant")
+ return tenant, status.Errorf(
+ codes.PermissionDenied,
+ "unknown tenant",
+ )
}
return tenant, nil
}
@@ -46,7 +49,10 @@ func getValidTenant(ctx context.Context, tc *Manager) (string, error) {
// Handle case where tenant is in the context metadata
md, ok := metadata.FromIncomingContext(ctx)
if !ok {
- return "", status.Errorf(codes.PermissionDenied, "missing tenant header")
+ return "", status.Errorf(
+ codes.PermissionDenied,
+ "missing tenant header",
+ )
}
var err error
diff --git a/pkg/tenancy/grpc_test.go b/pkg/tenancy/grpc_test.go
index f4b8777f217..fd39579703b 100644
--- a/pkg/tenancy/grpc_test.go
+++ b/pkg/tenancy/grpc_test.go
@@ -39,40 +39,62 @@ func TestTenancyInterceptors(t *testing.T) {
errMsg: "rpc error: code = PermissionDenied desc = missing tenant header",
},
{
- name: "invalid tenant context",
- tenancyMgr: NewManager(&Options{Enabled: true, Tenants: []string{"megacorp"}}),
- ctx: WithTenant(context.Background(), "acme"),
- errMsg: "rpc error: code = PermissionDenied desc = unknown tenant",
+ name: "invalid tenant context",
+ tenancyMgr: NewManager(
+ &Options{Enabled: true, Tenants: []string{"megacorp"}},
+ ),
+ ctx: WithTenant(context.Background(), "acme"),
+ errMsg: "rpc error: code = PermissionDenied desc = unknown tenant",
},
{
- name: "valid tenant context",
- tenancyMgr: NewManager(&Options{Enabled: true, Tenants: []string{"acme"}}),
- ctx: WithTenant(context.Background(), "acme"),
- errMsg: "",
+ name: "valid tenant context",
+ tenancyMgr: NewManager(
+ &Options{Enabled: true, Tenants: []string{"acme"}},
+ ),
+ ctx: WithTenant(context.Background(), "acme"),
+ errMsg: "",
},
{
- name: "invalid tenant header",
- tenancyMgr: NewManager(&Options{Enabled: true, Tenants: []string{"megacorp"}}),
- ctx: metadata.NewIncomingContext(context.Background(), map[string][]string{"x-tenant": {"acme"}}),
- errMsg: "rpc error: code = PermissionDenied desc = unknown tenant",
+ name: "invalid tenant header",
+ tenancyMgr: NewManager(
+ &Options{Enabled: true, Tenants: []string{"megacorp"}},
+ ),
+ ctx: metadata.NewIncomingContext(
+ context.Background(),
+ map[string][]string{"x-tenant": {"acme"}},
+ ),
+ errMsg: "rpc error: code = PermissionDenied desc = unknown tenant",
},
{
- name: "missing tenant header",
- tenancyMgr: NewManager(&Options{Enabled: true, Tenants: []string{"megacorp"}}),
- ctx: metadata.NewIncomingContext(context.Background(), map[string][]string{}),
- errMsg: "rpc error: code = Unauthenticated desc = missing tenant header",
+ name: "missing tenant header",
+ tenancyMgr: NewManager(
+ &Options{Enabled: true, Tenants: []string{"megacorp"}},
+ ),
+ ctx: metadata.NewIncomingContext(
+ context.Background(),
+ map[string][]string{},
+ ),
+ errMsg: "rpc error: code = Unauthenticated desc = missing tenant header",
},
{
- name: "valid tenant header",
- tenancyMgr: NewManager(&Options{Enabled: true, Tenants: []string{"acme"}}),
- ctx: metadata.NewIncomingContext(context.Background(), map[string][]string{"x-tenant": {"acme"}}),
- errMsg: "",
+ name: "valid tenant header",
+ tenancyMgr: NewManager(
+ &Options{Enabled: true, Tenants: []string{"acme"}},
+ ),
+ ctx: metadata.NewIncomingContext(
+ context.Background(),
+ map[string][]string{"x-tenant": {"acme"}},
+ ),
+ errMsg: "",
},
{
name: "extra tenant header",
tenancyMgr: NewManager(&Options{Enabled: true, Tenants: []string{"acme"}}),
- ctx: metadata.NewIncomingContext(context.Background(), map[string][]string{"x-tenant": {"acme", "megacorp"}}),
- errMsg: "rpc error: code = PermissionDenied desc = extra tenant header",
+ ctx: metadata.NewIncomingContext(
+ context.Background(),
+ map[string][]string{"x-tenant": {"acme", "megacorp"}},
+ ),
+ errMsg: "rpc error: code = PermissionDenied desc = extra tenant header",
},
}
diff --git a/pkg/tenancy/http_test.go b/pkg/tenancy/http_test.go
index 4117bcb4b60..20b0282deee 100644
--- a/pkg/tenancy/http_test.go
+++ b/pkg/tenancy/http_test.go
@@ -29,7 +29,10 @@ type testHttpHandler struct {
reached bool
}
-func (thh *testHttpHandler) ServeHTTP(res http.ResponseWriter, req *http.Request) {
+func (thh *testHttpHandler) ServeHTTP(
+ res http.ResponseWriter,
+ req *http.Request,
+) {
thh.reached = true
}
@@ -59,8 +62,10 @@ func TestProgationHandler(t *testing.T) {
shouldReach: true,
},
{
- name: "unauthorized tenant",
- tenancyMgr: NewManager(&Options{Enabled: true, Tenants: []string{"megacorp"}}),
+ name: "unauthorized tenant",
+ tenancyMgr: NewManager(
+ &Options{Enabled: true, Tenants: []string{"megacorp"}},
+ ),
requestHeaders: map[string][]string{"x-tenant": {"acme"}},
shouldReach: false,
},
@@ -70,7 +75,11 @@ func TestProgationHandler(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
handler := &testHttpHandler{}
propH := ExtractTenantHTTPHandler(test.tenancyMgr, handler)
- req, err := http.NewRequest(http.MethodGet, "/", strings.NewReader(""))
+ req, err := http.NewRequest(
+ http.MethodGet,
+ "/",
+ strings.NewReader(""),
+ )
for k, vs := range test.requestHeaders {
for _, v := range vs {
req.Header.Add(k, v)
@@ -104,7 +113,11 @@ func TestMetadataAnnotator(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
- req, err := http.NewRequest(http.MethodGet, "/", strings.NewReader(""))
+ req, err := http.NewRequest(
+ http.MethodGet,
+ "/",
+ strings.NewReader(""),
+ )
for k, vs := range test.requestHeaders {
for _, v := range vs {
req.Header.Add(k, v)
diff --git a/pkg/testutils/leakcheck.go b/pkg/testutils/leakcheck.go
index 6b5988bbc4b..22715b420ad 100644
--- a/pkg/testutils/leakcheck.go
+++ b/pkg/testutils/leakcheck.go
@@ -25,19 +25,27 @@ import (
// This is necessary because glog starts a goroutine in the background that may not
// be stopped when the test finishes, leading to a detected but expected leak.
func IgnoreGlogFlushDaemonLeak() goleak.Option {
- return goleak.IgnoreTopFunction("github.com/golang/glog.(*fileSink).flushDaemon")
+ return goleak.IgnoreTopFunction(
+ "github.com/golang/glog.(*fileSink).flushDaemon",
+ )
}
// IgnoreOpenCensusWorkerLeak This prevent catching the leak generated by opencensus defaultWorker.Start which at the time is part of the package's init call.
// See https://github.com/jaegertracing/jaeger/pull/5055#discussion_r1438702168 for more context.
func IgnoreOpenCensusWorkerLeak() goleak.Option {
- return goleak.IgnoreTopFunction("go.opencensus.io/stats/view.(*worker).start")
+ return goleak.IgnoreTopFunction(
+ "go.opencensus.io/stats/view.(*worker).start",
+ )
}
// VerifyGoLeaks verifies that unit tests do not leak any goroutines.
// It should be called in TestMain.
func VerifyGoLeaks(m *testing.M) {
- goleak.VerifyTestMain(m, IgnoreGlogFlushDaemonLeak(), IgnoreOpenCensusWorkerLeak())
+ goleak.VerifyTestMain(
+ m,
+ IgnoreGlogFlushDaemonLeak(),
+ IgnoreOpenCensusWorkerLeak(),
+ )
}
// VerifyGoLeaksOnce verifies that a given unit test does not leak any goroutines.
@@ -47,5 +55,9 @@ func VerifyGoLeaks(m *testing.M) {
//
// defer testutils.VerifyGoLeaksOnce(t)
func VerifyGoLeaksOnce(t *testing.T) {
- goleak.VerifyNone(t, IgnoreGlogFlushDaemonLeak(), IgnoreOpenCensusWorkerLeak())
+ goleak.VerifyNone(
+ t,
+ IgnoreGlogFlushDaemonLeak(),
+ IgnoreOpenCensusWorkerLeak(),
+ )
}
diff --git a/pkg/testutils/logger.go b/pkg/testutils/logger.go
index 4ebef3b9dd3..bd1727c7504 100644
--- a/pkg/testutils/logger.go
+++ b/pkg/testutils/logger.go
@@ -106,7 +106,12 @@ func (b *Buffer) Write(p []byte) (int, error) {
// LogMatcher is a helper func that returns true if the subStr appears more than 'occurrences' times in the logs.
var LogMatcher = func(occurrences int, subStr string, logs []string) (bool, string) {
- errMsg := fmt.Sprintf("subStr '%s' does not occur %d time(s) in %v", subStr, occurrences, logs)
+ errMsg := fmt.Sprintf(
+ "subStr '%s' does not occur %d time(s) in %v",
+ subStr,
+ occurrences,
+ logs,
+ )
if len(logs) < occurrences {
return false, errMsg
}
diff --git a/pkg/testutils/logger_test.go b/pkg/testutils/logger_test.go
index d36d96fdcc9..e1c82cf9081 100644
--- a/pkg/testutils/logger_test.go
+++ b/pkg/testutils/logger_test.go
@@ -82,16 +82,36 @@ func TestLogMatcher(t *testing.T) {
expected bool
errMsg string
}{
- {occurrences: 1, expected: false, errMsg: "subStr '' does not occur 1 time(s) in []"},
+ {
+ occurrences: 1,
+ expected: false,
+ errMsg: "subStr '' does not occur 1 time(s) in []",
+ },
{occurrences: 1, subStr: "hi", logs: []string{"hi"}, expected: true},
- {occurrences: 3, subStr: "hi", logs: []string{"hi", "hi"}, expected: false, errMsg: "subStr 'hi' does not occur 3 time(s) in [hi hi]"},
+ {
+ occurrences: 3,
+ subStr: "hi",
+ logs: []string{"hi", "hi"},
+ expected: false,
+ errMsg: "subStr 'hi' does not occur 3 time(s) in [hi hi]",
+ },
{occurrences: 3, subStr: "hi", logs: []string{"hi", "hi", "hi"}, expected: true},
- {occurrences: 1, subStr: "hi", logs: []string{"bye", "bye"}, expected: false, errMsg: "subStr 'hi' does not occur 1 time(s) in [bye bye]"},
+ {
+ occurrences: 1,
+ subStr: "hi",
+ logs: []string{"bye", "bye"},
+ expected: false,
+ errMsg: "subStr 'hi' does not occur 1 time(s) in [bye bye]",
+ },
}
for i, tt := range tests {
test := tt
t.Run(fmt.Sprintf("%v", i), func(t *testing.T) {
- match, errMsg := LogMatcher(test.occurrences, test.subStr, test.logs)
+ match, errMsg := LogMatcher(
+ test.occurrences,
+ test.subStr,
+ test.logs,
+ )
assert.Equal(t, test.expected, match)
assert.Equal(t, test.errMsg, errMsg)
})
diff --git a/pkg/version/handler_test.go b/pkg/version/handler_test.go
index e737798f410..0f4085fdddb 100644
--- a/pkg/version/handler_test.go
+++ b/pkg/version/handler_test.go
@@ -29,7 +29,9 @@ func TestRegisterHandler(t *testing.T) {
commitSHA = "foobar"
latestVersion = "v1.2.3"
date = "2024-01-04"
- expectedJSON := []byte(`{"gitCommit":"foobar","gitVersion":"v1.2.3","buildDate":"2024-01-04"}`)
+ expectedJSON := []byte(
+ `{"gitCommit":"foobar","gitVersion":"v1.2.3","buildDate":"2024-01-04"}`,
+ )
mockLogger := zap.NewNop()
mux := http.NewServeMux()
diff --git a/plugin/metrics/disabled/reader.go b/plugin/metrics/disabled/reader.go
index 8b104b84c5b..fc843886514 100644
--- a/plugin/metrics/disabled/reader.go
+++ b/plugin/metrics/disabled/reader.go
@@ -44,21 +44,33 @@ func NewMetricsReader() (*MetricsReader, error) {
}
// GetLatencies gets the latency metrics for the given set of latency query parameters.
-func (*MetricsReader) GetLatencies(ctx context.Context, requestParams *metricsstore.LatenciesQueryParameters) (*metrics.MetricFamily, error) {
+func (*MetricsReader) GetLatencies(
+ ctx context.Context,
+ requestParams *metricsstore.LatenciesQueryParameters,
+) (*metrics.MetricFamily, error) {
return nil, ErrDisabled
}
// GetCallRates gets the call rate metrics for the given set of call rate query parameters.
-func (*MetricsReader) GetCallRates(ctx context.Context, requestParams *metricsstore.CallRateQueryParameters) (*metrics.MetricFamily, error) {
+func (*MetricsReader) GetCallRates(
+ ctx context.Context,
+ requestParams *metricsstore.CallRateQueryParameters,
+) (*metrics.MetricFamily, error) {
return nil, ErrDisabled
}
// GetErrorRates gets the error rate metrics for the given set of error rate query parameters.
-func (*MetricsReader) GetErrorRates(ctx context.Context, requestParams *metricsstore.ErrorRateQueryParameters) (*metrics.MetricFamily, error) {
+func (*MetricsReader) GetErrorRates(
+ ctx context.Context,
+ requestParams *metricsstore.ErrorRateQueryParameters,
+) (*metrics.MetricFamily, error) {
return nil, ErrDisabled
}
// GetMinStepDuration gets the minimum step duration (the smallest possible duration between two data points in a time series) supported.
-func (*MetricsReader) GetMinStepDuration(_ context.Context, _ *metricsstore.MinStepDurationQueryParameters) (time.Duration, error) {
+func (*MetricsReader) GetMinStepDuration(
+ _ context.Context,
+ _ *metricsstore.MinStepDurationQueryParameters,
+) (time.Duration, error) {
return 0, ErrDisabled
}
diff --git a/plugin/metrics/factory.go b/plugin/metrics/factory.go
index 48b54bc7866..c31f2d10433 100644
--- a/plugin/metrics/factory.go
+++ b/plugin/metrics/factory.go
@@ -63,14 +63,20 @@ func NewFactory(config FactoryConfig) (*Factory, error) {
return f, nil
}
-func (*Factory) getFactoryOfType(factoryType string) (storage.MetricsFactory, error) {
+func (*Factory) getFactoryOfType(
+ factoryType string,
+) (storage.MetricsFactory, error) {
switch factoryType {
case prometheusStorageType:
return prometheus.NewFactory(), nil
case disabledStorageType:
return disabled.NewFactory(), nil
}
- return nil, fmt.Errorf("unknown metrics type %q. Valid types are %v", factoryType, AllStorageTypes)
+ return nil, fmt.Errorf(
+ "unknown metrics type %q. Valid types are %v",
+ factoryType,
+ AllStorageTypes,
+ )
}
// Initialize implements storage.MetricsFactory.
@@ -85,7 +91,10 @@ func (f *Factory) Initialize(logger *zap.Logger) error {
func (f *Factory) CreateMetricsReader() (metricsstore.Reader, error) {
factory, ok := f.factories[f.MetricsStorageType]
if !ok {
- return nil, fmt.Errorf("no %q backend registered for metrics store", f.MetricsStorageType)
+ return nil, fmt.Errorf(
+ "no %q backend registered for metrics store",
+ f.MetricsStorageType,
+ )
}
return factory.CreateMetricsReader()
}
diff --git a/plugin/metrics/factory_test.go b/plugin/metrics/factory_test.go
index 0cacf652612..fdf78d2eea3 100644
--- a/plugin/metrics/factory_test.go
+++ b/plugin/metrics/factory_test.go
@@ -48,7 +48,11 @@ func TestUnsupportedMetricsStorageType(t *testing.T) {
f, err := NewFactory(withConfig("foo"))
require.Error(t, err)
assert.Nil(t, f)
- require.EqualError(t, err, `unknown metrics type "foo". Valid types are [prometheus]`)
+ require.EqualError(
+ t,
+ err,
+ `unknown metrics type "foo". Valid types are [prometheus]`,
+ )
}
func TestDisabledMetricsStorageType(t *testing.T) {
diff --git a/plugin/metrics/prometheus/factory.go b/plugin/metrics/prometheus/factory.go
index 60452061d67..748f914fbd5 100644
--- a/plugin/metrics/prometheus/factory.go
+++ b/plugin/metrics/prometheus/factory.go
@@ -52,7 +52,10 @@ func (f *Factory) AddFlags(flagSet *flag.FlagSet) {
// InitFromViper implements plugin.Configurable.
func (f *Factory) InitFromViper(v *viper.Viper, logger *zap.Logger) {
if err := f.options.InitFromViper(v); err != nil {
- logger.Panic("Failed to initialize metrics storage factory", zap.Error(err))
+ logger.Panic(
+ "Failed to initialize metrics storage factory",
+ zap.Error(err),
+ )
}
}
@@ -64,5 +67,9 @@ func (f *Factory) Initialize(logger *zap.Logger) error {
// CreateMetricsReader implements storage.MetricsFactory.
func (f *Factory) CreateMetricsReader() (metricsstore.Reader, error) {
- return prometheusstore.NewMetricsReader(f.options.Primary.Configuration, f.logger, f.tracer)
+ return prometheusstore.NewMetricsReader(
+ f.options.Primary.Configuration,
+ f.logger,
+ f.tracer,
+ )
}
diff --git a/plugin/metrics/prometheus/factory_test.go b/plugin/metrics/prometheus/factory_test.go
index db1374f280d..328ea78d6ff 100644
--- a/plugin/metrics/prometheus/factory_test.go
+++ b/plugin/metrics/prometheus/factory_test.go
@@ -59,32 +59,46 @@ func TestWithDefaultConfiguration(t *testing.T) {
}
func TestWithConfiguration(t *testing.T) {
- t.Run("still supports the deprecated spanmetrics processor", func(t *testing.T) {
- f := NewFactory()
- v, command := config.Viperize(f.AddFlags)
- err := command.ParseFlags([]string{
- "--prometheus.query.support-spanmetrics-connector=false",
- })
- require.NoError(t, err)
- f.InitFromViper(v, zap.NewNop())
- assert.False(t, f.options.Primary.SupportSpanmetricsConnector)
- })
- t.Run("with custom configuration and no space in token file path", func(t *testing.T) {
- f := NewFactory()
- v, command := config.Viperize(f.AddFlags)
- err := command.ParseFlags([]string{
- "--prometheus.server-url=http://localhost:1234",
- "--prometheus.connect-timeout=5s",
- "--prometheus.token-file=test/test_file.txt",
- "--prometheus.token-override-from-context=false",
- })
- require.NoError(t, err)
- f.InitFromViper(v, zap.NewNop())
- assert.Equal(t, "http://localhost:1234", f.options.Primary.ServerURL)
- assert.Equal(t, 5*time.Second, f.options.Primary.ConnectTimeout)
- assert.Equal(t, "test/test_file.txt", f.options.Primary.TokenFilePath)
- assert.False(t, f.options.Primary.TokenOverrideFromContext)
- })
+ t.Run(
+ "still supports the deprecated spanmetrics processor",
+ func(t *testing.T) {
+ f := NewFactory()
+ v, command := config.Viperize(f.AddFlags)
+ err := command.ParseFlags([]string{
+ "--prometheus.query.support-spanmetrics-connector=false",
+ })
+ require.NoError(t, err)
+ f.InitFromViper(v, zap.NewNop())
+ assert.False(t, f.options.Primary.SupportSpanmetricsConnector)
+ },
+ )
+ t.Run(
+ "with custom configuration and no space in token file path",
+ func(t *testing.T) {
+ f := NewFactory()
+ v, command := config.Viperize(f.AddFlags)
+ err := command.ParseFlags([]string{
+ "--prometheus.server-url=http://localhost:1234",
+ "--prometheus.connect-timeout=5s",
+ "--prometheus.token-file=test/test_file.txt",
+ "--prometheus.token-override-from-context=false",
+ })
+ require.NoError(t, err)
+ f.InitFromViper(v, zap.NewNop())
+ assert.Equal(
+ t,
+ "http://localhost:1234",
+ f.options.Primary.ServerURL,
+ )
+ assert.Equal(t, 5*time.Second, f.options.Primary.ConnectTimeout)
+ assert.Equal(
+ t,
+ "test/test_file.txt",
+ f.options.Primary.TokenFilePath,
+ )
+ assert.False(t, f.options.Primary.TokenOverrideFromContext)
+ },
+ )
t.Run("with space in token file path", func(t *testing.T) {
f := NewFactory()
v, command := config.Viperize(f.AddFlags)
@@ -141,7 +155,11 @@ func TestFailedTLSOptions(t *testing.T) {
defer func() {
r := recover()
t.Logf("%v", r)
- assert.Contains(t, logOut.Lines()[0], "failed to process Prometheus TLS options")
+ assert.Contains(
+ t,
+ logOut.Lines()[0],
+ "failed to process Prometheus TLS options",
+ )
}()
f.InitFromViper(v, logger)
diff --git a/plugin/metrics/prometheus/metricsstore/dbmodel/to_domain.go b/plugin/metrics/prometheus/metricsstore/dbmodel/to_domain.go
index 4694a2ef2f7..8a1b6c7d988 100644
--- a/plugin/metrics/prometheus/metricsstore/dbmodel/to_domain.go
+++ b/plugin/metrics/prometheus/metricsstore/dbmodel/to_domain.go
@@ -37,9 +37,15 @@ func New(spanNameLabel string) Translator {
}
// ToDomainMetricsFamily converts Prometheus' representation of metrics query results to Jaeger's.
-func (d Translator) ToDomainMetricsFamily(name, description string, mv model.Value) (*metrics.MetricFamily, error) {
+func (d Translator) ToDomainMetricsFamily(
+ name, description string,
+ mv model.Value,
+) (*metrics.MetricFamily, error) {
if mv.Type() != model.ValMatrix {
- return &metrics.MetricFamily{}, fmt.Errorf("unexpected metrics ValueType: %s", mv.Type())
+ return &metrics.MetricFamily{}, fmt.Errorf(
+ "unexpected metrics ValueType: %s",
+ mv.Type(),
+ )
}
return &metrics.MetricFamily{
Name: name,
@@ -101,10 +107,14 @@ func toDomainTimestamp(timeMs model.Time) *types.Timestamp {
// The gauge metric type is used because latency, call and error rates metrics do not consist of monotonically
// increasing values; rather, they are a series of any positive floating number which can fluctuate in any
// direction over time.
-func toDomainMetricPointValue(promVal model.SampleValue) *metrics.MetricPoint_GaugeValue {
+func toDomainMetricPointValue(
+ promVal model.SampleValue,
+) *metrics.MetricPoint_GaugeValue {
return &metrics.MetricPoint_GaugeValue{
GaugeValue: &metrics.GaugeValue{
- Value: &metrics.GaugeValue_DoubleValue{DoubleValue: float64(promVal)},
+ Value: &metrics.GaugeValue_DoubleValue{
+ DoubleValue: float64(promVal),
+ },
},
}
}
diff --git a/plugin/metrics/prometheus/metricsstore/dbmodel/to_domain_test.go b/plugin/metrics/prometheus/metricsstore/dbmodel/to_domain_test.go
index ad14ed3f4c2..014b6b9c524 100644
--- a/plugin/metrics/prometheus/metricsstore/dbmodel/to_domain_test.go
+++ b/plugin/metrics/prometheus/metricsstore/dbmodel/to_domain_test.go
@@ -31,13 +31,20 @@ func TestToDomainMetricsFamily(t *testing.T) {
promMetrics := model.Matrix{}
nowSec := time.Now().Unix()
promMetrics = append(promMetrics, &model.SampleStream{
- Metric: map[model.LabelName]model.LabelValue{"label_key": "label_value", "span_name": "span_name_value"},
+ Metric: map[model.LabelName]model.LabelValue{
+ "label_key": "label_value",
+ "span_name": "span_name_value",
+ },
Values: []model.SamplePair{
{Timestamp: model.Time(nowSec * 1000), Value: 1234},
},
})
translator := New("span_name")
- mf, err := translator.ToDomainMetricsFamily("the_metric_name", "the_metric_description", promMetrics)
+ mf, err := translator.ToDomainMetricsFamily(
+ "the_metric_name",
+ "the_metric_description",
+ promMetrics,
+ )
require.NoError(t, err)
assert.NotEmpty(t, mf)
@@ -66,13 +73,21 @@ func TestToDomainMetricsFamily(t *testing.T) {
},
},
}
- assert.Equal(t, []*metrics.MetricPoint{{Timestamp: &types.Timestamp{Seconds: nowSec}, Value: wantMpValue}}, mf.Metrics[0].MetricPoints)
+ assert.Equal(
+ t,
+ []*metrics.MetricPoint{{Timestamp: &types.Timestamp{Seconds: nowSec}, Value: wantMpValue}},
+ mf.Metrics[0].MetricPoints,
+ )
}
func TestUnexpectedMetricsFamilyType(t *testing.T) {
promMetrics := model.Vector{}
translator := New("span_name")
- mf, err := translator.ToDomainMetricsFamily("the_metric_name", "the_metric_description", promMetrics)
+ mf, err := translator.ToDomainMetricsFamily(
+ "the_metric_name",
+ "the_metric_description",
+ promMetrics,
+ )
assert.NotNil(t, mf)
assert.Empty(t, mf)
diff --git a/plugin/metrics/prometheus/metricsstore/reader.go b/plugin/metrics/prometheus/metricsstore/reader.go
index fc86bd02019..a5b503be2b0 100644
--- a/plugin/metrics/prometheus/metricsstore/reader.go
+++ b/plugin/metrics/prometheus/metricsstore/reader.go
@@ -75,7 +75,11 @@ type (
)
// NewMetricsReader returns a new MetricsReader.
-func NewMetricsReader(cfg config.Configuration, logger *zap.Logger, tracer trace.TracerProvider) (*MetricsReader, error) {
+func NewMetricsReader(
+ cfg config.Configuration,
+ logger *zap.Logger,
+ tracer trace.TracerProvider,
+) (*MetricsReader, error) {
logger.Info("Creating metrics reader", zap.Any("configuration", cfg))
roundTripper, err := getHTTPRoundTripper(&cfg, logger)
@@ -87,7 +91,10 @@ func NewMetricsReader(cfg config.Configuration, logger *zap.Logger, tracer trace
RoundTripper: roundTripper,
})
if err != nil {
- return nil, fmt.Errorf("failed to initialize prometheus client: %w", err)
+ return nil, fmt.Errorf(
+ "failed to initialize prometheus client: %w",
+ err,
+ )
}
operationLabel := "operation"
@@ -106,17 +113,26 @@ func NewMetricsReader(cfg config.Configuration, logger *zap.Logger, tracer trace
operationLabel: operationLabel,
}
- logger.Info("Prometheus reader initialized", zap.String("addr", cfg.ServerURL))
+ logger.Info(
+ "Prometheus reader initialized",
+ zap.String("addr", cfg.ServerURL),
+ )
return mr, nil
}
// GetLatencies gets the latency metrics for the given set of latency query parameters.
-func (m MetricsReader) GetLatencies(ctx context.Context, requestParams *metricsstore.LatenciesQueryParameters) (*metrics.MetricFamily, error) {
+func (m MetricsReader) GetLatencies(
+ ctx context.Context,
+ requestParams *metricsstore.LatenciesQueryParameters,
+) (*metrics.MetricFamily, error) {
metricsParams := metricsQueryParams{
BaseQueryParameters: requestParams.BaseQueryParameters,
groupByHistBucket: true,
metricName: "service_latencies",
- metricDesc: fmt.Sprintf("%.2fth quantile latency, grouped by service", requestParams.Quantile),
+ metricDesc: fmt.Sprintf(
+ "%.2fth quantile latency, grouped by service",
+ requestParams.Quantile,
+ ),
buildPromQuery: func(p promQueryParams) string {
return fmt.Sprintf(
// Note: p.spanKindFilter can be ""; trailing commas are okay within a timeseries selection.
@@ -159,7 +175,10 @@ func buildFullLatencyMetricName(cfg config.Configuration) string {
}
// GetCallRates gets the call rate metrics for the given set of call rate query parameters.
-func (m MetricsReader) GetCallRates(ctx context.Context, requestParams *metricsstore.CallRateQueryParameters) (*metrics.MetricFamily, error) {
+func (m MetricsReader) GetCallRates(
+ ctx context.Context,
+ requestParams *metricsstore.CallRateQueryParameters,
+) (*metrics.MetricFamily, error) {
metricsParams := metricsQueryParams{
BaseQueryParameters: requestParams.BaseQueryParameters,
metricName: "service_call_rate",
@@ -197,7 +216,10 @@ func buildFullCallsMetricName(cfg config.Configuration) string {
}
// GetErrorRates gets the error rate metrics for the given set of error rate query parameters.
-func (m MetricsReader) GetErrorRates(ctx context.Context, requestParams *metricsstore.ErrorRateQueryParameters) (*metrics.MetricFamily, error) {
+func (m MetricsReader) GetErrorRates(
+ ctx context.Context,
+ requestParams *metricsstore.ErrorRateQueryParameters,
+) (*metrics.MetricFamily, error) {
metricsParams := metricsQueryParams{
BaseQueryParameters: requestParams.BaseQueryParameters,
metricName: "service_error_rate",
@@ -206,8 +228,16 @@ func (m MetricsReader) GetErrorRates(ctx context.Context, requestParams *metrics
return fmt.Sprintf(
// Note: p.spanKindFilter can be ""; trailing commas are okay within a timeseries selection.
`sum(rate(%s{service_name =~ "%s", status_code = "STATUS_CODE_ERROR", %s}[%s])) by (%s) / sum(rate(%s{service_name =~ "%s", %s}[%s])) by (%s)`,
- m.callsMetricName, p.serviceFilter, p.spanKindFilter, p.rate, p.groupBy,
- m.callsMetricName, p.serviceFilter, p.spanKindFilter, p.rate, p.groupBy,
+ m.callsMetricName,
+ p.serviceFilter,
+ p.spanKindFilter,
+ p.rate,
+ p.groupBy,
+ m.callsMetricName,
+ p.serviceFilter,
+ p.spanKindFilter,
+ p.rate,
+ p.groupBy,
)
},
}
@@ -222,7 +252,10 @@ func (m MetricsReader) GetErrorRates(ctx context.Context, requestParams *metrics
// Check for the presence of call rate metrics to differentiate the absence of error rate from
// the absence of call rate metrics altogether.
- callMetrics, err := m.GetCallRates(ctx, &metricsstore.CallRateQueryParameters{BaseQueryParameters: requestParams.BaseQueryParameters})
+ callMetrics, err := m.GetCallRates(
+ ctx,
+ &metricsstore.CallRateQueryParameters{BaseQueryParameters: requestParams.BaseQueryParameters},
+ )
if err != nil {
return nil, fmt.Errorf("failed getting call metrics: %w", err)
}
@@ -236,7 +269,9 @@ func (m MetricsReader) GetErrorRates(ctx context.Context, requestParams *metrics
for _, cm := range callMetrics.Metrics {
zm := *cm
for i := 0; i < len(zm.MetricPoints); i++ {
- zm.MetricPoints[i].Value = &metrics.MetricPoint_GaugeValue{GaugeValue: &metrics.GaugeValue{Value: &metrics.GaugeValue_DoubleValue{DoubleValue: 0.0}}}
+ zm.MetricPoints[i].Value = &metrics.MetricPoint_GaugeValue{
+ GaugeValue: &metrics.GaugeValue{Value: &metrics.GaugeValue_DoubleValue{DoubleValue: 0.0}},
+ }
}
zeroErrorMetrics = append(zeroErrorMetrics, &zm)
}
@@ -246,14 +281,25 @@ func (m MetricsReader) GetErrorRates(ctx context.Context, requestParams *metrics
}
// GetMinStepDuration gets the minimum step duration (the smallest possible duration between two data points in a time series) supported.
-func (MetricsReader) GetMinStepDuration(_ context.Context, _ *metricsstore.MinStepDurationQueryParameters) (time.Duration, error) {
+func (MetricsReader) GetMinStepDuration(
+ _ context.Context,
+ _ *metricsstore.MinStepDurationQueryParameters,
+) (time.Duration, error) {
return minStep, nil
}
// executeQuery executes a query against a Prometheus-compliant metrics backend.
-func (m MetricsReader) executeQuery(ctx context.Context, p metricsQueryParams) (*metrics.MetricFamily, error) {
+func (m MetricsReader) executeQuery(
+ ctx context.Context,
+ p metricsQueryParams,
+) (*metrics.MetricFamily, error) {
if p.GroupByOperation {
- p.metricName = strings.Replace(p.metricName, "service", "service_operation", 1)
+ p.metricName = strings.Replace(
+ p.metricName,
+ "service",
+ "service_operation",
+ 1,
+ )
p.metricDesc += " & operation"
}
promQuery := m.buildPromQuery(p)
@@ -274,10 +320,20 @@ func (m MetricsReader) executeQuery(ctx context.Context, p metricsQueryParams) (
return &metrics.MetricFamily{}, err
}
if len(warnings) > 0 {
- m.logger.Warn("Warnings detected on Prometheus query", zap.Any("warnings", warnings), zap.String("query", promQuery), zap.Any("range", queryRange))
- }
-
- m.logger.Debug("Prometheus query results", zap.String("results", mv.String()), zap.String("query", promQuery), zap.Any("range", queryRange))
+ m.logger.Warn(
+ "Warnings detected on Prometheus query",
+ zap.Any("warnings", warnings),
+ zap.String("query", promQuery),
+ zap.Any("range", queryRange),
+ )
+ }
+
+ m.logger.Debug(
+ "Prometheus query results",
+ zap.String("results", mv.String()),
+ zap.String("query", promQuery),
+ zap.Any("range", queryRange),
+ )
return m.metricsTranslator.ToDomainMetricsFamily(
p.metricName,
@@ -298,7 +354,10 @@ func (m MetricsReader) buildPromQuery(metricsParams metricsQueryParams) string {
spanKindFilter := ""
if len(metricsParams.SpanKinds) > 0 {
- spanKindFilter = fmt.Sprintf(`span_kind =~ "%s"`, strings.Join(metricsParams.SpanKinds, "|"))
+ spanKindFilter = fmt.Sprintf(
+ `span_kind =~ "%s"`,
+ strings.Join(metricsParams.SpanKinds, "|"),
+ )
}
promParams := promQueryParams{
serviceFilter: strings.Join(metricsParams.ServiceNames, "|"),
@@ -322,7 +381,11 @@ func promqlDurationString(d *time.Duration) string {
return string(b)
}
-func startSpanForQuery(ctx context.Context, metricName, query string, tp trace.Tracer) (context.Context, trace.Span) {
+func startSpanForQuery(
+ ctx context.Context,
+ metricName, query string,
+ tp trace.Tracer,
+) (context.Context, trace.Span) {
ctx, span := tp.Start(ctx, metricName)
span.SetAttributes(
attribute.Key(semconv.DBStatementKey).String(query),
@@ -337,7 +400,10 @@ func logErrorToSpan(span trace.Span, err error) {
span.SetStatus(codes.Error, err.Error())
}
-func getHTTPRoundTripper(c *config.Configuration, logger *zap.Logger) (rt http.RoundTripper, err error) {
+func getHTTPRoundTripper(
+ c *config.Configuration,
+ logger *zap.Logger,
+) (rt http.RoundTripper, err error) {
var ctlsConfig *tls.Config
if c.TLS.Enabled {
if ctlsConfig, err = c.TLS.Config(logger); err != nil {
diff --git a/plugin/metrics/prometheus/metricsstore/reader_test.go b/plugin/metrics/prometheus/metricsstore/reader_test.go
index c5199a684ac..adafd1c99de 100644
--- a/plugin/metrics/prometheus/metricsstore/reader_test.go
+++ b/plugin/metrics/prometheus/metricsstore/reader_test.go
@@ -66,7 +66,9 @@ var defaultConfig = config.Configuration{
LatencyUnit: "ms",
}
-func tracerProvider(t *testing.T) (trace.TracerProvider, *tracetest.InMemoryExporter, func()) {
+func tracerProvider(
+ t *testing.T,
+) (trace.TracerProvider, *tracetest.InMemoryExporter, func()) {
exporter := tracetest.NewInMemoryExporter()
tp := sdktrace.NewTracerProvider(
sdktrace.WithSampler(sdktrace.AlwaysSample()),
@@ -138,9 +140,15 @@ func TestMetricsServerError(t *testing.T) {
},
}
- mockPrometheus := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- http.Error(w, "internal server error", http.StatusInternalServerError)
- }))
+ mockPrometheus := httptest.NewServer(
+ http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ http.Error(
+ w,
+ "internal server error",
+ http.StatusInternalServerError,
+ )
+ }),
+ )
defer mockPrometheus.Close()
logger := zap.NewNop()
@@ -156,7 +164,12 @@ func TestMetricsServerError(t *testing.T) {
assert.NotNil(t, m)
require.Error(t, err)
assert.Contains(t, err.Error(), "failed executing metrics query")
- require.Len(t, exp.GetSpans(), 1, "HTTP request was traced and span reported")
+ require.Len(
+ t,
+ exp.GetSpans(),
+ 1,
+ "HTTP request was traced and span reported",
+ )
assert.Equal(t, codes.Error, exp.GetSpans()[0].Status.Code)
}
@@ -252,13 +265,24 @@ func TestGetLatencies(t *testing.T) {
if tc.updateConfig != nil {
cfg = tc.updateConfig(cfg)
}
- reader, mockPrometheus := prepareMetricsReaderAndServer(t, cfg, tc.wantPromQlQuery, nil, tracer)
+ reader, mockPrometheus := prepareMetricsReaderAndServer(
+ t,
+ cfg,
+ tc.wantPromQlQuery,
+ nil,
+ tracer,
+ )
defer mockPrometheus.Close()
m, err := reader.GetLatencies(context.Background(), ¶ms)
require.NoError(t, err)
assertMetrics(t, m, tc.wantLabels, tc.wantName, tc.wantDescription)
- assert.Len(t, exp.GetSpans(), 1, "HTTP request was traced and span reported")
+ assert.Len(
+ t,
+ exp.GetSpans(),
+ 1,
+ "HTTP request was traced and span reported",
+ )
})
}
}
@@ -352,13 +376,24 @@ func TestGetCallRates(t *testing.T) {
if tc.updateConfig != nil {
cfg = tc.updateConfig(cfg)
}
- reader, mockPrometheus := prepareMetricsReaderAndServer(t, cfg, tc.wantPromQlQuery, nil, tracer)
+ reader, mockPrometheus := prepareMetricsReaderAndServer(
+ t,
+ cfg,
+ tc.wantPromQlQuery,
+ nil,
+ tracer,
+ )
defer mockPrometheus.Close()
m, err := reader.GetCallRates(context.Background(), ¶ms)
require.NoError(t, err)
assertMetrics(t, m, tc.wantLabels, tc.wantName, tc.wantDescription)
- assert.Len(t, exp.GetSpans(), 1, "HTTP request was traced and span reported")
+ assert.Len(
+ t,
+ exp.GetSpans(),
+ 1,
+ "HTTP request was traced and span reported",
+ )
})
}
}
@@ -477,13 +512,24 @@ func TestGetErrorRates(t *testing.T) {
if tc.updateConfig != nil {
cfg = tc.updateConfig(cfg)
}
- reader, mockPrometheus := prepareMetricsReaderAndServer(t, cfg, tc.wantPromQlQuery, nil, tracer)
+ reader, mockPrometheus := prepareMetricsReaderAndServer(
+ t,
+ cfg,
+ tc.wantPromQlQuery,
+ nil,
+ tracer,
+ )
defer mockPrometheus.Close()
m, err := reader.GetErrorRates(context.Background(), ¶ms)
require.NoError(t, err)
assertMetrics(t, m, tc.wantLabels, tc.wantName, tc.wantDescription)
- assert.Len(t, exp.GetSpans(), 1, "HTTP request was traced and span reported")
+ assert.Len(
+ t,
+ exp.GetSpans(),
+ 1,
+ "HTTP request was traced and span reported",
+ )
})
}
}
@@ -506,22 +552,29 @@ func TestGetErrorRatesZero(t *testing.T) {
`span_kind =~ "SPAN_KIND_SERVER"}[10m])) by (service_name)`
)
wantPromQLQueries := []string{queryErrorRate, queryCallRate}
- responses := []string{"testdata/empty_response.json", "testdata/service_datapoint_response.json"}
+ responses := []string{
+ "testdata/empty_response.json",
+ "testdata/service_datapoint_response.json",
+ }
var callCount int
- mockPrometheus := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- body, _ := io.ReadAll(r.Body)
- defer r.Body.Close()
+ mockPrometheus := httptest.NewServer(
+ http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ body, _ := io.ReadAll(r.Body)
+ defer r.Body.Close()
- u, err := url.Parse("http://" + r.Host + r.RequestURI + "?" + string(body))
- require.NoError(t, err)
+ u, err := url.Parse(
+ "http://" + r.Host + r.RequestURI + "?" + string(body),
+ )
+ require.NoError(t, err)
- q := u.Query()
- promQuery := q.Get("query")
- assert.Equal(t, wantPromQLQueries[callCount], promQuery)
- sendResponse(t, w, responses[callCount])
- callCount++
- }))
+ q := u.Query()
+ promQuery := q.Get("query")
+ assert.Equal(t, wantPromQLQueries[callCount], promQuery)
+ sendResponse(t, w, responses[callCount])
+ callCount++
+ }),
+ )
logger := zap.NewNop()
address := mockPrometheus.Listener.Addr().String()
@@ -548,7 +601,12 @@ func TestGetErrorRatesZero(t *testing.T) {
actualVal := mps[0].Value.(*metrics.MetricPoint_GaugeValue).GaugeValue.Value.(*metrics.GaugeValue_DoubleValue).DoubleValue
assert.Zero(t, actualVal)
assert.Equal(t, int64(1620351786), mps[0].Timestamp.GetSeconds())
- assert.Len(t, exp.GetSpans(), 2, "expected an error rate query and a call rate query to be made")
+ assert.Len(
+ t,
+ exp.GetSpans(),
+ 2,
+ "expected an error rate query and a call rate query to be made",
+ )
}
func TestGetErrorRatesNull(t *testing.T) {
@@ -569,22 +627,29 @@ func TestGetErrorRatesNull(t *testing.T) {
`span_kind =~ "SPAN_KIND_SERVER"}[10m])) by (service_name)`
)
wantPromQLQueries := []string{queryErrorRate, queryCallRate}
- responses := []string{"testdata/empty_response.json", "testdata/empty_response.json"}
+ responses := []string{
+ "testdata/empty_response.json",
+ "testdata/empty_response.json",
+ }
var callCount int
- mockPrometheus := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- body, _ := io.ReadAll(r.Body)
- defer r.Body.Close()
+ mockPrometheus := httptest.NewServer(
+ http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ body, _ := io.ReadAll(r.Body)
+ defer r.Body.Close()
- u, err := url.Parse("http://" + r.Host + r.RequestURI + "?" + string(body))
- require.NoError(t, err)
+ u, err := url.Parse(
+ "http://" + r.Host + r.RequestURI + "?" + string(body),
+ )
+ require.NoError(t, err)
- q := u.Query()
- promQuery := q.Get("query")
- assert.Equal(t, wantPromQLQueries[callCount], promQuery)
- sendResponse(t, w, responses[callCount])
- callCount++
- }))
+ q := u.Query()
+ promQuery := q.Get("query")
+ assert.Equal(t, wantPromQLQueries[callCount], promQuery)
+ sendResponse(t, w, responses[callCount])
+ callCount++
+ }),
+ )
logger := zap.NewNop()
address := mockPrometheus.Listener.Addr().String()
@@ -601,7 +666,12 @@ func TestGetErrorRatesNull(t *testing.T) {
m, err := reader.GetErrorRates(context.Background(), ¶ms)
require.NoError(t, err)
assert.Empty(t, m.Metrics, "expect no error data available")
- assert.Len(t, exp.GetSpans(), 2, "expected an error rate query and a call rate query to be made")
+ assert.Len(
+ t,
+ exp.GetSpans(),
+ 2,
+ "expected an error rate query and a call rate query to be made",
+ )
}
func TestGetErrorRatesErrors(t *testing.T) {
@@ -624,10 +694,12 @@ func TestGetErrorRatesErrors(t *testing.T) {
} {
t.Run(tc.name, func(t *testing.T) {
params := metricsstore.ErrorRateQueryParameters{
- BaseQueryParameters: buildTestBaseQueryParametersFrom(metricsTestCase{
- serviceNames: []string{"emailservice"},
- spanKinds: []string{"SPAN_KIND_SERVER"},
- }),
+ BaseQueryParameters: buildTestBaseQueryParametersFrom(
+ metricsTestCase{
+ serviceNames: []string{"emailservice"},
+ spanKinds: []string{"SPAN_KIND_SERVER"},
+ },
+ ),
}
tracer, _, closer := tracerProvider(t)
defer closer()
@@ -640,36 +712,43 @@ func TestGetErrorRatesErrors(t *testing.T) {
`span_kind =~ "SPAN_KIND_SERVER"}[10m])) by (service_name)`
)
wantPromQLQueries := []string{queryErrorRate, queryCallRate}
- responses := []string{"testdata/empty_response.json", "testdata/service_datapoint_response.json"}
+ responses := []string{
+ "testdata/empty_response.json",
+ "testdata/service_datapoint_response.json",
+ }
var callCount int
- mockPrometheus := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- body, _ := io.ReadAll(r.Body)
- defer r.Body.Close()
-
- u, err := url.Parse("http://" + r.Host + r.RequestURI + "?" + string(body))
- require.NoError(t, err)
-
- q := u.Query()
- promQuery := q.Get("query")
- assert.Equal(t, wantPromQLQueries[callCount], promQuery)
-
- switch promQuery {
- case queryErrorRate:
- if tc.failErrorRateQuery {
- w.WriteHeader(http.StatusInternalServerError)
- } else {
- sendResponse(t, w, responses[callCount])
- }
- case queryCallRate:
- if tc.failCallRateQuery {
- w.WriteHeader(http.StatusInternalServerError)
- } else {
- sendResponse(t, w, responses[callCount])
+ mockPrometheus := httptest.NewServer(
+ http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ body, _ := io.ReadAll(r.Body)
+ defer r.Body.Close()
+
+ u, err := url.Parse(
+ "http://" + r.Host + r.RequestURI + "?" + string(body),
+ )
+ require.NoError(t, err)
+
+ q := u.Query()
+ promQuery := q.Get("query")
+ assert.Equal(t, wantPromQLQueries[callCount], promQuery)
+
+ switch promQuery {
+ case queryErrorRate:
+ if tc.failErrorRateQuery {
+ w.WriteHeader(http.StatusInternalServerError)
+ } else {
+ sendResponse(t, w, responses[callCount])
+ }
+ case queryCallRate:
+ if tc.failCallRateQuery {
+ w.WriteHeader(http.StatusInternalServerError)
+ } else {
+ sendResponse(t, w, responses[callCount])
+ }
}
- }
- callCount++
- }))
+ callCount++
+ }),
+ )
logger := zap.NewNop()
address := mockPrometheus.Listener.Addr().String()
@@ -708,17 +787,30 @@ func TestInvalidLatencyUnit(t *testing.T) {
func TestWarningResponse(t *testing.T) {
params := metricsstore.ErrorRateQueryParameters{
- BaseQueryParameters: buildTestBaseQueryParametersFrom(metricsTestCase{serviceNames: []string{"foo"}}),
+ BaseQueryParameters: buildTestBaseQueryParametersFrom(
+ metricsTestCase{serviceNames: []string{"foo"}},
+ ),
}
tracer, exp, closer := tracerProvider(t)
defer closer()
- reader, mockPrometheus := prepareMetricsReaderAndServer(t, config.Configuration{}, "", []string{"warning0", "warning1"}, tracer)
+ reader, mockPrometheus := prepareMetricsReaderAndServer(
+ t,
+ config.Configuration{},
+ "",
+ []string{"warning0", "warning1"},
+ tracer,
+ )
defer mockPrometheus.Close()
m, err := reader.GetErrorRates(context.Background(), ¶ms)
require.NoError(t, err)
assert.NotNil(t, m)
- assert.Len(t, exp.GetSpans(), 2, "expected an error rate query and a call rate query to be made")
+ assert.Len(
+ t,
+ exp.GetSpans(),
+ 2,
+ "expected an error rate query and a call rate query to be made",
+ )
}
type fakePromServer struct {
@@ -806,7 +898,10 @@ func TestGetRoundTripperTokenFile(t *testing.T) {
server := newFakePromServer(t)
defer server.Close()
- ctx := bearertoken.ContextWithBearerToken(context.Background(), "tokenFromRequest")
+ ctx := bearertoken.ContextWithBearerToken(
+ context.Background(),
+ "tokenFromRequest",
+ )
req, err := http.NewRequestWithContext(
ctx,
http.MethodGet,
@@ -840,7 +935,10 @@ func TestGetRoundTripperTokenFromContext(t *testing.T) {
server := newFakePromServer(t)
defer server.Close()
- ctx := bearertoken.ContextWithBearerToken(context.Background(), "tokenFromRequest")
+ ctx := bearertoken.ContextWithBearerToken(
+ context.Background(),
+ "tokenFromRequest",
+ )
req, err := http.NewRequestWithContext(
ctx,
http.MethodGet,
@@ -882,29 +980,37 @@ func TestInvalidCertFile(t *testing.T) {
assert.Nil(t, reader)
}
-func startMockPrometheusServer(t *testing.T, wantPromQlQuery string, wantWarnings []string) *httptest.Server {
- return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- if len(wantWarnings) > 0 {
- sendResponse(t, w, "testdata/warning_response.json")
- return
- }
+func startMockPrometheusServer(
+ t *testing.T,
+ wantPromQlQuery string,
+ wantWarnings []string,
+) *httptest.Server {
+ return httptest.NewServer(
+ http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ if len(wantWarnings) > 0 {
+ sendResponse(t, w, "testdata/warning_response.json")
+ return
+ }
- body, _ := io.ReadAll(r.Body)
- defer r.Body.Close()
+ body, _ := io.ReadAll(r.Body)
+ defer r.Body.Close()
- u, err := url.Parse("http://" + r.Host + r.RequestURI + "?" + string(body))
- require.NoError(t, err)
+ u, err := url.Parse(
+ "http://" + r.Host + r.RequestURI + "?" + string(body),
+ )
+ require.NoError(t, err)
- q := u.Query()
- promQuery := q.Get("query")
- assert.Equal(t, wantPromQlQuery, promQuery)
+ q := u.Query()
+ promQuery := q.Get("query")
+ assert.Equal(t, wantPromQlQuery, promQuery)
- mockResponsePayloadFile := "testdata/service_datapoint_response.json"
- if strings.Contains(promQuery, "by (service_name,operation") {
- mockResponsePayloadFile = "testdata/service_operation_datapoint_response.json"
- }
- sendResponse(t, w, mockResponsePayloadFile)
- }))
+ mockResponsePayloadFile := "testdata/service_datapoint_response.json"
+ if strings.Contains(promQuery, "by (service_name,operation") {
+ mockResponsePayloadFile = "testdata/service_operation_datapoint_response.json"
+ }
+ sendResponse(t, w, mockResponsePayloadFile)
+ }),
+ )
}
func sendResponse(t *testing.T, w http.ResponseWriter, responseFile string) {
@@ -915,7 +1021,9 @@ func sendResponse(t *testing.T, w http.ResponseWriter, responseFile string) {
require.NoError(t, err)
}
-func buildTestBaseQueryParametersFrom(tc metricsTestCase) metricsstore.BaseQueryParameters {
+func buildTestBaseQueryParametersFrom(
+ tc metricsTestCase,
+) metricsstore.BaseQueryParameters {
endTime := time.Now()
lookback := time.Minute
step := time.Millisecond
@@ -932,7 +1040,13 @@ func buildTestBaseQueryParametersFrom(tc metricsTestCase) metricsstore.BaseQuery
}
}
-func prepareMetricsReaderAndServer(t *testing.T, config config.Configuration, wantPromQlQuery string, wantWarnings []string, tracer trace.TracerProvider) (metricsstore.Reader, *httptest.Server) {
+func prepareMetricsReaderAndServer(
+ t *testing.T,
+ config config.Configuration,
+ wantPromQlQuery string,
+ wantWarnings []string,
+ tracer trace.TracerProvider,
+) (metricsstore.Reader, *httptest.Server) {
mockPrometheus := startMockPrometheusServer(t, wantPromQlQuery, wantWarnings)
logger := zap.NewNop()
@@ -947,7 +1061,12 @@ func prepareMetricsReaderAndServer(t *testing.T, config config.Configuration, wa
return reader, mockPrometheus
}
-func assertMetrics(t *testing.T, gotMetrics *metrics.MetricFamily, wantLabels map[string]string, wantName, wantDescription string) {
+func assertMetrics(
+ t *testing.T,
+ gotMetrics *metrics.MetricFamily,
+ wantLabels map[string]string,
+ wantName, wantDescription string,
+) {
assert.Len(t, gotMetrics.Metrics, 1)
assert.Equal(t, wantName, gotMetrics.Name)
assert.Equal(t, wantDescription, gotMetrics.Help)
diff --git a/plugin/metrics/prometheus/options.go b/plugin/metrics/prometheus/options.go
index db516bc24f3..c739c4aa753 100644
--- a/plugin/metrics/prometheus/options.go
+++ b/plugin/metrics/prometheus/options.go
@@ -53,7 +53,7 @@ const (
)
type namespaceConfig struct {
- config.Configuration `mapstructure:",squash"`
+ config.Configuration ` mapstructure:",squash"`
namespace string
}
@@ -90,32 +90,43 @@ func (opt *Options) AddFlags(flagSet *flag.FlagSet) {
"The Prometheus server's URL, must include the protocol scheme e.g. http://localhost:9090")
flagSet.Duration(nsConfig.namespace+suffixConnectTimeout, defaultConnectTimeout,
"The period to wait for a connection to Prometheus when executing queries.")
- flagSet.String(nsConfig.namespace+suffixTokenFilePath, defaultTokenFilePath,
- "The path to a file containing the bearer token which will be included when executing queries against the Prometheus API.")
+ flagSet.String(
+ nsConfig.namespace+suffixTokenFilePath,
+ defaultTokenFilePath,
+ "The path to a file containing the bearer token which will be included when executing queries against the Prometheus API.",
+ )
flagSet.Bool(nsConfig.namespace+suffixOverrideFromContext, true,
"Whether the bearer token should be overridden from context (incoming request)")
flagSet.Bool(
nsConfig.namespace+suffixSupportSpanmetricsConnector,
defaultSupportSpanmetricsConnector,
- deprecatedSpanMetricsProcessor+" Controls whether the metrics queries should match the OpenTelemetry Collector's spanmetrics connector naming (when true) or spanmetrics processor naming (when false).")
+ deprecatedSpanMetricsProcessor+" Controls whether the metrics queries should match the OpenTelemetry Collector's spanmetrics connector naming (when true) or spanmetrics processor naming (when false).",
+ )
flagSet.String(nsConfig.namespace+suffixMetricNamespace, defaultMetricNamespace,
`The metric namespace that is prefixed to the metric name. A '.' separator will be added between `+
- `the namespace and the metric name.`)
- flagSet.String(nsConfig.namespace+suffixLatencyUnit, defaultLatencyUnit,
+ `the namespace and the metric name.`,
+ )
+ flagSet.String(
+ nsConfig.namespace+suffixLatencyUnit,
+ defaultLatencyUnit,
`The units used for the "latency" histogram. It can be either "ms" or "s" and should be consistent with the `+
`histogram unit value set in the spanmetrics connector (see: `+
`https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/connector/spanmetricsconnector#configurations). `+
- `This also helps jaeger-query determine the metric name when querying for "latency" metrics.`)
+ `This also helps jaeger-query determine the metric name when querying for "latency" metrics.`,
+ )
flagSet.Bool(nsConfig.namespace+suffixNormalizeCalls, defaultNormalizeCalls,
`Whether to normalize the "calls" metric name according to `+
`https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/pkg/translator/prometheus/README.md. `+
`For example: `+
`"calls" (not normalized) -> "calls_total" (normalized), `)
- flagSet.Bool(nsConfig.namespace+suffixNormalizeDuration, defaultNormalizeDuration,
+ flagSet.Bool(
+ nsConfig.namespace+suffixNormalizeDuration,
+ defaultNormalizeDuration,
`Whether to normalize the "duration" metric name according to `+
`https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/pkg/translator/prometheus/README.md. `+
`For example: `+
- `"duration_bucket" (not normalized) -> "duration_milliseconds_bucket (normalized)"`)
+ `"duration_bucket" (not normalized) -> "duration_milliseconds_bucket (normalized)"`,
+ )
nsConfig.getTLSFlagsConfig().AddFlags(flagSet)
}
@@ -123,23 +134,34 @@ func (opt *Options) AddFlags(flagSet *flag.FlagSet) {
// InitFromViper initializes the options struct with values from Viper.
func (opt *Options) InitFromViper(v *viper.Viper) error {
cfg := &opt.Primary
- cfg.ServerURL = stripWhiteSpace(v.GetString(cfg.namespace + suffixServerURL))
+ cfg.ServerURL = stripWhiteSpace(
+ v.GetString(cfg.namespace + suffixServerURL),
+ )
cfg.ConnectTimeout = v.GetDuration(cfg.namespace + suffixConnectTimeout)
cfg.TokenFilePath = v.GetString(cfg.namespace + suffixTokenFilePath)
- cfg.SupportSpanmetricsConnector = v.GetBool(cfg.namespace + suffixSupportSpanmetricsConnector)
+ cfg.SupportSpanmetricsConnector = v.GetBool(
+ cfg.namespace + suffixSupportSpanmetricsConnector,
+ )
if !cfg.SupportSpanmetricsConnector {
- log.Printf("using Spanmetrics Processor's metrics naming conventions " + deprecatedSpanMetricsProcessor)
+ log.Printf(
+ "using Spanmetrics Processor's metrics naming conventions " + deprecatedSpanMetricsProcessor,
+ )
}
cfg.MetricNamespace = v.GetString(cfg.namespace + suffixMetricNamespace)
cfg.LatencyUnit = v.GetString(cfg.namespace + suffixLatencyUnit)
cfg.NormalizeCalls = v.GetBool(cfg.namespace + suffixNormalizeCalls)
cfg.NormalizeDuration = v.GetBool(cfg.namespace + suffixNormalizeDuration)
- cfg.TokenOverrideFromContext = v.GetBool(cfg.namespace + suffixOverrideFromContext)
+ cfg.TokenOverrideFromContext = v.GetBool(
+ cfg.namespace + suffixOverrideFromContext,
+ )
isValidUnit := map[string]bool{"ms": true, "s": true}
if _, ok := isValidUnit[cfg.LatencyUnit]; !ok {
- return fmt.Errorf(`duration-unit must be one of "ms" or "s", not %q`, cfg.LatencyUnit)
+ return fmt.Errorf(
+ `duration-unit must be one of "ms" or "s", not %q`,
+ cfg.LatencyUnit,
+ )
}
var err error
diff --git a/plugin/pkg/distributedlock/cassandra/lock.go b/plugin/pkg/distributedlock/cassandra/lock.go
index 9a5887895f5..12c1488b3fb 100644
--- a/plugin/pkg/distributedlock/cassandra/lock.go
+++ b/plugin/pkg/distributedlock/cassandra/lock.go
@@ -55,9 +55,13 @@ func (l *Lock) Acquire(resource string, ttl time.Duration) (bool, error) {
}
ttlSec := int(ttl.Seconds())
var name, owner string
- applied, err := l.session.Query(cqlInsertLock, resource, l.tenantID, ttlSec).ScanCAS(&name, &owner)
+ applied, err := l.session.Query(cqlInsertLock, resource, l.tenantID, ttlSec).
+ ScanCAS(&name, &owner)
if err != nil {
- return false, fmt.Errorf("failed to acquire resource lock due to cassandra error: %w", err)
+ return false, fmt.Errorf(
+ "failed to acquire resource lock due to cassandra error: %w",
+ err,
+ )
}
if applied {
// The lock was successfully created
@@ -66,7 +70,10 @@ 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, fmt.Errorf("failed to extend lease on resource lock: %w", err)
+ return false, fmt.Errorf(
+ "failed to extend lease on resource lock: %w",
+ err,
+ )
}
return true, nil
}
@@ -76,22 +83,30 @@ func (l *Lock) Acquire(resource string, ttl time.Duration) (bool, error) {
// Forfeit forfeits an existing lease around a given resource.
func (l *Lock) Forfeit(resource string) (bool, error) {
var name, owner string
- applied, err := l.session.Query(cqlDeleteLock, resource, l.tenantID).ScanCAS(&name, &owner)
+ applied, err := l.session.Query(cqlDeleteLock, resource, l.tenantID).
+ ScanCAS(&name, &owner)
if err != nil {
- return false, fmt.Errorf("failed to forfeit resource lock due to cassandra error: %w", err)
+ 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, fmt.Errorf("failed to forfeit resource lock: %w", errLockOwnership)
+ 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.
func (l *Lock) extendLease(resource string, ttl time.Duration) error {
ttlSec := int(ttl.Seconds())
var owner string
- applied, err := l.session.Query(cqlUpdateLock, ttlSec, l.tenantID, resource, l.tenantID).ScanCAS(&owner)
+ applied, err := l.session.Query(cqlUpdateLock, ttlSec, l.tenantID, resource, l.tenantID).
+ ScanCAS(&owner)
if err != nil {
return err
}
diff --git a/plugin/pkg/distributedlock/cassandra/lock_test.go b/plugin/pkg/distributedlock/cassandra/lock_test.go
index 65a33d580e7..bc604b9db6f 100644
--- a/plugin/pkg/distributedlock/cassandra/lock_test.go
+++ b/plugin/pkg/distributedlock/cassandra/lock_test.go
@@ -79,7 +79,8 @@ func TestExtendLease(t *testing.T) {
t.Run(testCase.caption, func(t *testing.T) {
withCQLLock(func(s *cqlLockTest) {
query := &mocks.Query{}
- query.On("ScanCAS", matchEverything()).Return(testCase.applied, testCase.errScan)
+ query.On("ScanCAS", matchEverything()).
+ Return(testCase.applied, testCase.errScan)
var args []any
captureArgs := mock.MatchedBy(func(v []any) bool {
@@ -87,7 +88,8 @@ func TestExtendLease(t *testing.T) {
return true
})
- s.session.On("Query", mock.AnythingOfType("string"), captureArgs).Return(query)
+ s.session.On("Query", mock.AnythingOfType("string"), captureArgs).
+ Return(query)
err := s.lock.extendLease(samplingLock, time.Second*60)
if testCase.expectedErrMsg == "" {
require.NoError(t, err)
@@ -173,11 +175,15 @@ func TestAcquire(t *testing.T) {
}
return mock.MatchedBy(scanFunc)
}
- firstQuery.On("ScanCAS", scanMatcher()).Return(testCase.insertLockApplied, testCase.errScan)
- secondQuery.On("ScanCAS", matchEverything()).Return(testCase.updateLockApplied, nil)
+ firstQuery.On("ScanCAS", scanMatcher()).
+ Return(testCase.insertLockApplied, testCase.errScan)
+ secondQuery.On("ScanCAS", matchEverything()).
+ Return(testCase.updateLockApplied, nil)
- s.session.On("Query", stringMatcher("INSERT INTO leases"), matchEverything()).Return(firstQuery)
- s.session.On("Query", stringMatcher("UPDATE leases"), matchEverything()).Return(secondQuery)
+ s.session.On("Query", stringMatcher("INSERT INTO leases"), matchEverything()).
+ Return(firstQuery)
+ s.session.On("Query", stringMatcher("UPDATE leases"), matchEverything()).
+ Return(secondQuery)
acquired, err := s.lock.Acquire(samplingLock, 0)
if testCase.expectedErrMsg == "" {
require.NoError(t, err)
@@ -226,7 +232,8 @@ func TestForfeit(t *testing.T) {
t.Run(testCase.caption, func(t *testing.T) {
withCQLLock(func(s *cqlLockTest) {
query := &mocks.Query{}
- query.On("ScanCAS", matchEverything()).Return(testCase.applied, testCase.errScan)
+ query.On("ScanCAS", matchEverything()).
+ Return(testCase.applied, testCase.errScan)
var args []any
captureArgs := mock.MatchedBy(func(v []any) bool {
@@ -234,7 +241,8 @@ func TestForfeit(t *testing.T) {
return true
})
- s.session.On("Query", mock.AnythingOfType("string"), captureArgs).Return(query)
+ s.session.On("Query", mock.AnythingOfType("string"), captureArgs).
+ Return(query)
applied, err := s.lock.Forfeit(samplingLock)
if testCase.expectedErrMsg == "" {
require.NoError(t, err)
diff --git a/plugin/sampling/calculationstrategy/interface.go b/plugin/sampling/calculationstrategy/interface.go
index e24924440d3..77d1fd323f5 100644
--- a/plugin/sampling/calculationstrategy/interface.go
+++ b/plugin/sampling/calculationstrategy/interface.go
@@ -16,13 +16,17 @@ package calculationstrategy
// ProbabilityCalculator calculates the new probability given the current and target QPS
type ProbabilityCalculator interface {
- Calculate(targetQPS, curQPS, prevProbability float64) (newProbability float64)
+ Calculate(
+ targetQPS, curQPS, prevProbability float64,
+ ) (newProbability float64)
}
// CalculateFunc wraps a function of appropriate signature and makes a ProbabilityCalculator from it.
type CalculateFunc func(targetQPS, curQPS, prevProbability float64) (newProbability float64)
// Calculate implements Calculator interface.
-func (c CalculateFunc) Calculate(targetQPS, curQPS, prevProbability float64) float64 {
+func (c CalculateFunc) Calculate(
+ targetQPS, curQPS, prevProbability float64,
+) float64 {
return c(targetQPS, curQPS, prevProbability)
}
diff --git a/plugin/sampling/calculationstrategy/percentage_increase_capped_calculator.go b/plugin/sampling/calculationstrategy/percentage_increase_capped_calculator.go
index 3a8f73a2d3a..db83e5525e7 100644
--- a/plugin/sampling/calculationstrategy/percentage_increase_capped_calculator.go
+++ b/plugin/sampling/calculationstrategy/percentage_increase_capped_calculator.go
@@ -33,7 +33,9 @@ type PercentageIncreaseCappedCalculator struct {
}
// NewPercentageIncreaseCappedCalculator returns a new percentage increase capped calculator.
-func NewPercentageIncreaseCappedCalculator(percentageIncreaseCap float64) PercentageIncreaseCappedCalculator {
+func NewPercentageIncreaseCappedCalculator(
+ percentageIncreaseCap float64,
+) PercentageIncreaseCappedCalculator {
if percentageIncreaseCap == 0 {
percentageIncreaseCap = defaultPercentageIncreaseCap
}
@@ -43,7 +45,9 @@ func NewPercentageIncreaseCappedCalculator(percentageIncreaseCap float64) Percen
}
// Calculate calculates the new probability.
-func (c PercentageIncreaseCappedCalculator) Calculate(targetQPS, curQPS, prevProbability float64) float64 {
+func (c PercentageIncreaseCappedCalculator) Calculate(
+ targetQPS, curQPS, prevProbability float64,
+) float64 {
factor := targetQPS / curQPS
newProbability := prevProbability * factor
// If curQPS is lower than the targetQPS, we need to increase the probability slowly to
diff --git a/plugin/sampling/calculationstrategy/percentage_increase_capped_calculator_test.go b/plugin/sampling/calculationstrategy/percentage_increase_capped_calculator_test.go
index bd9b9b5de45..62900630426 100644
--- a/plugin/sampling/calculationstrategy/percentage_increase_capped_calculator_test.go
+++ b/plugin/sampling/calculationstrategy/percentage_increase_capped_calculator_test.go
@@ -34,7 +34,17 @@ func TestPercentageIncreaseCappedCalculator(t *testing.T) {
{1.0, 0.8, 0.1, 0.125, "test3"},
}
for _, tt := range tests {
- probability := calculator.Calculate(tt.targetQPS, tt.curQPS, tt.oldProbability)
- assert.InDelta(t, tt.expectedProbability, probability, 0.0001, tt.testName)
+ probability := calculator.Calculate(
+ tt.targetQPS,
+ tt.curQPS,
+ tt.oldProbability,
+ )
+ assert.InDelta(
+ t,
+ tt.expectedProbability,
+ probability,
+ 0.0001,
+ tt.testName,
+ )
}
}
diff --git a/plugin/sampling/leaderelection/leader_election.go b/plugin/sampling/leaderelection/leader_election.go
index 531326f526d..122218c4e65 100644
--- a/plugin/sampling/leaderelection/leader_election.go
+++ b/plugin/sampling/leaderelection/leader_election.go
@@ -55,7 +55,11 @@ type ElectionParticipantOptions struct {
}
// NewElectionParticipant returns a ElectionParticipant which attempts to become leader.
-func NewElectionParticipant(lock dl.Lock, resourceName string, options ElectionParticipantOptions) *DistributedElectionParticipant {
+func NewElectionParticipant(
+ lock dl.Lock,
+ resourceName string,
+ options ElectionParticipantOptions,
+) *DistributedElectionParticipant {
return &DistributedElectionParticipant{
ElectionParticipantOptions: options,
lock: lock,
diff --git a/plugin/sampling/leaderelection/leader_election_test.go b/plugin/sampling/leaderelection/leader_election_test.go
index 50ee42c60af..26e78c85589 100644
--- a/plugin/sampling/leaderelection/leader_election_test.go
+++ b/plugin/sampling/leaderelection/leader_election_test.go
@@ -48,7 +48,13 @@ func TestAcquireLock(t *testing.T) {
{isLeader: true, acquiredLock: false, err: errTestLock, expectedInterval: leaderInterval, expectedError: true},
{isLeader: true, acquiredLock: false, err: nil, expectedInterval: followerInterval, expectedError: false},
{isLeader: false, acquiredLock: false, err: nil, expectedInterval: followerInterval, expectedError: false},
- {isLeader: false, acquiredLock: false, err: errTestLock, expectedInterval: followerInterval, expectedError: true},
+ {
+ isLeader: false,
+ acquiredLock: false,
+ err: errTestLock,
+ expectedInterval: followerInterval,
+ expectedError: true,
+ },
{isLeader: false, acquiredLock: true, err: nil, expectedInterval: leaderInterval, expectedError: false},
}
@@ -56,7 +62,8 @@ func TestAcquireLock(t *testing.T) {
t.Run(fmt.Sprintf("%v", i), func(t *testing.T) {
logger, logBuffer := testutils.NewLogger()
mockLock := &lmocks.Lock{}
- mockLock.On("Acquire", "sampling_lock", followerInterval).Return(test.acquiredLock, test.err)
+ mockLock.On("Acquire", "sampling_lock", followerInterval).
+ Return(test.acquiredLock, test.err)
p := &DistributedElectionParticipant{
ElectionParticipantOptions: ElectionParticipantOptions{
@@ -70,7 +77,11 @@ func TestAcquireLock(t *testing.T) {
p.setLeader(test.isLeader)
assert.Equal(t, test.expectedInterval, p.acquireLock())
- match, errMsg := testutils.LogMatcher(1, acquireLockErrMsg, logBuffer.Lines())
+ match, errMsg := testutils.LogMatcher(
+ 1,
+ acquireLockErrMsg,
+ logBuffer.Lines(),
+ )
assert.Equal(t, test.expectedError, match, errMsg)
})
}
@@ -79,13 +90,17 @@ func TestAcquireLock(t *testing.T) {
func TestRunAcquireLockLoopFollowerOnly(t *testing.T) {
logger, logBuffer := testutils.NewLogger()
mockLock := &lmocks.Lock{}
- mockLock.On("Acquire", "sampling_lock", time.Duration(5*time.Millisecond)).Return(false, errTestLock)
+ mockLock.On("Acquire", "sampling_lock", time.Duration(5*time.Millisecond)).
+ Return(false, errTestLock)
- p := NewElectionParticipant(mockLock, "sampling_lock", ElectionParticipantOptions{
- LeaderLeaseRefreshInterval: time.Millisecond,
- FollowerLeaseRefreshInterval: 5 * time.Millisecond,
- Logger: logger,
- },
+ p := NewElectionParticipant(
+ mockLock,
+ "sampling_lock",
+ ElectionParticipantOptions{
+ LeaderLeaseRefreshInterval: time.Millisecond,
+ FollowerLeaseRefreshInterval: 5 * time.Millisecond,
+ Logger: logger,
+ },
)
defer func() {
@@ -101,7 +116,11 @@ func TestRunAcquireLockLoopFollowerOnly(t *testing.T) {
}
time.Sleep(time.Millisecond)
}
- match, errMsg := testutils.LogMatcher(2, expectedErrorMsg, logBuffer.Lines())
+ match, errMsg := testutils.LogMatcher(
+ 2,
+ expectedErrorMsg,
+ logBuffer.Lines(),
+ )
assert.True(t, match, errMsg)
assert.False(t, p.IsLeader())
}
diff --git a/plugin/sampling/strategystore/adaptive/aggregator.go b/plugin/sampling/strategystore/adaptive/aggregator.go
index f933be71cf6..26069754926 100644
--- a/plugin/sampling/strategystore/adaptive/aggregator.go
+++ b/plugin/sampling/strategystore/adaptive/aggregator.go
@@ -48,21 +48,41 @@ type aggregator struct {
// NewAggregator creates a throughput aggregator that simply emits metrics
// about the number of operations seen over the aggregationInterval.
-func NewAggregator(options Options, logger *zap.Logger, metricsFactory metrics.Factory, participant leaderelection.ElectionParticipant, store samplingstore.Store) (strategystore.Aggregator, error) {
+func NewAggregator(
+ options Options,
+ logger *zap.Logger,
+ metricsFactory metrics.Factory,
+ participant leaderelection.ElectionParticipant,
+ store samplingstore.Store,
+) (strategystore.Aggregator, error) {
hostname, err := hostname.AsIdentifier()
if err != nil {
return nil, err
}
- logger.Info("Using unique participantName in adaptive sampling", zap.String("participantName", hostname))
-
- postAggregator, err := newPostAggregator(options, hostname, store, participant, metricsFactory, logger)
+ logger.Info(
+ "Using unique participantName in adaptive sampling",
+ zap.String("participantName", hostname),
+ )
+
+ postAggregator, err := newPostAggregator(
+ options,
+ hostname,
+ store,
+ participant,
+ metricsFactory,
+ logger,
+ )
if err != nil {
return nil, err
}
return &aggregator{
- operationsCounter: metricsFactory.Counter(metrics.Options{Name: "sampling_operations"}),
- servicesCounter: metricsFactory.Counter(metrics.Options{Name: "sampling_services"}),
+ operationsCounter: metricsFactory.Counter(
+ metrics.Options{Name: "sampling_operations"},
+ ),
+ servicesCounter: metricsFactory.Counter(
+ metrics.Options{Name: "sampling_services"},
+ ),
currentThroughput: make(serviceOperationThroughput),
aggregationInterval: options.CalculationInterval,
postAggregator: postAggregator,
@@ -102,7 +122,11 @@ func (a *aggregator) saveThroughput() {
a.storage.InsertThroughput(throughputSlice)
}
-func (a *aggregator) RecordThroughput(service, operation string, samplerType span_model.SamplerType, probability float64) {
+func (a *aggregator) RecordThroughput(
+ service, operation string,
+ samplerType span_model.SamplerType,
+ probability float64,
+) {
a.Lock()
defer a.Unlock()
if _, ok := a.currentThroughput[service]; !ok {
diff --git a/plugin/sampling/strategystore/adaptive/aggregator_test.go b/plugin/sampling/strategystore/adaptive/aggregator_test.go
index bd34c3cb016..2314e7b1854 100644
--- a/plugin/sampling/strategystore/adaptive/aggregator_test.go
+++ b/plugin/sampling/strategystore/adaptive/aggregator_test.go
@@ -34,7 +34,8 @@ func TestAggregator(t *testing.T) {
metricsFactory := metricstest.NewFactory(0)
mockStorage := &mocks.Store{}
- mockStorage.On("InsertThroughput", mock.AnythingOfType("[]*model.Throughput")).Return(nil)
+ mockStorage.On("InsertThroughput", mock.AnythingOfType("[]*model.Throughput")).
+ Return(nil)
mockEP := &epmocks.ElectionParticipant{}
mockEP.On("Start").Return(nil)
mockEP.On("Close").Return(nil)
@@ -46,7 +47,13 @@ func TestAggregator(t *testing.T) {
}
logger := zap.NewNop()
- a, err := NewAggregator(testOpts, logger, metricsFactory, mockEP, mockStorage)
+ a, err := NewAggregator(
+ testOpts,
+ logger,
+ metricsFactory,
+ mockEP,
+ mockStorage,
+ )
require.NoError(t, err)
a.RecordThroughput("A", "GET", model.SamplerTypeProbabilistic, 0.001)
a.RecordThroughput("B", "POST", model.SamplerTypeProbabilistic, 0.001)
@@ -81,21 +88,46 @@ func TestIncrementThroughput(t *testing.T) {
BucketsForCalculation: 1,
}
logger := zap.NewNop()
- a, err := NewAggregator(testOpts, logger, metricsFactory, mockEP, mockStorage)
+ a, err := NewAggregator(
+ testOpts,
+ logger,
+ metricsFactory,
+ mockEP,
+ mockStorage,
+ )
require.NoError(t, err)
// 20 different probabilities
for i := 0; i < 20; i++ {
- a.RecordThroughput("A", "GET", model.SamplerTypeProbabilistic, 0.001*float64(i))
+ a.RecordThroughput(
+ "A",
+ "GET",
+ model.SamplerTypeProbabilistic,
+ 0.001*float64(i),
+ )
}
- assert.Len(t, a.(*aggregator).currentThroughput["A"]["GET"].Probabilities, 10)
-
- a, err = NewAggregator(testOpts, logger, metricsFactory, mockEP, mockStorage)
+ assert.Len(
+ t,
+ a.(*aggregator).currentThroughput["A"]["GET"].Probabilities,
+ 10,
+ )
+
+ a, err = NewAggregator(
+ testOpts,
+ logger,
+ metricsFactory,
+ mockEP,
+ mockStorage,
+ )
require.NoError(t, err)
// 20 of the same probabilities
for i := 0; i < 20; i++ {
a.RecordThroughput("A", "GET", model.SamplerTypeProbabilistic, 0.001)
}
- assert.Len(t, a.(*aggregator).currentThroughput["A"]["GET"].Probabilities, 1)
+ assert.Len(
+ t,
+ a.(*aggregator).currentThroughput["A"]["GET"].Probabilities,
+ 1,
+ )
}
func TestLowerboundThroughput(t *testing.T) {
@@ -109,11 +141,24 @@ func TestLowerboundThroughput(t *testing.T) {
}
logger := zap.NewNop()
- a, err := NewAggregator(testOpts, logger, metricsFactory, mockEP, mockStorage)
+ a, err := NewAggregator(
+ testOpts,
+ logger,
+ metricsFactory,
+ mockEP,
+ mockStorage,
+ )
require.NoError(t, err)
a.RecordThroughput("A", "GET", model.SamplerTypeLowerBound, 0.001)
- assert.EqualValues(t, 0, a.(*aggregator).currentThroughput["A"]["GET"].Count)
- assert.Empty(t, a.(*aggregator).currentThroughput["A"]["GET"].Probabilities["0.001000"])
+ assert.EqualValues(
+ t,
+ 0,
+ a.(*aggregator).currentThroughput["A"]["GET"].Count,
+ )
+ assert.Empty(
+ t,
+ a.(*aggregator).currentThroughput["A"]["GET"].Probabilities["0.001000"],
+ )
}
func TestRecordThroughput(t *testing.T) {
@@ -126,11 +171,21 @@ func TestRecordThroughput(t *testing.T) {
BucketsForCalculation: 1,
}
logger := zap.NewNop()
- a, err := NewAggregator(testOpts, logger, metricsFactory, mockEP, mockStorage)
+ a, err := NewAggregator(
+ testOpts,
+ logger,
+ metricsFactory,
+ mockEP,
+ mockStorage,
+ )
require.NoError(t, err)
// Testing non-root span
- span := &model.Span{References: []model.SpanRef{{SpanID: model.NewSpanID(1), RefType: model.ChildOf}}}
+ span := &model.Span{
+ References: []model.SpanRef{
+ {SpanID: model.NewSpanID(1), RefType: model.ChildOf},
+ },
+ }
a.HandleRootSpan(span, logger)
require.Empty(t, a.(*aggregator).currentThroughput)
@@ -153,5 +208,9 @@ func TestRecordThroughput(t *testing.T) {
model.String("sampler.param", "0.001"),
}
a.HandleRootSpan(span, logger)
- assert.EqualValues(t, 1, a.(*aggregator).currentThroughput["A"]["GET"].Count)
+ assert.EqualValues(
+ t,
+ 1,
+ a.(*aggregator).currentThroughput["A"]["GET"].Count,
+ )
}
diff --git a/plugin/sampling/strategystore/adaptive/cache.go b/plugin/sampling/strategystore/adaptive/cache.go
index ea7713c75fc..2757f68f14e 100644
--- a/plugin/sampling/strategystore/adaptive/cache.go
+++ b/plugin/sampling/strategystore/adaptive/cache.go
@@ -25,7 +25,10 @@ type SamplingCacheEntry struct {
type SamplingCache map[string]map[string]*SamplingCacheEntry
// Set adds a new entry for given service/operation.
-func (s SamplingCache) Set(service, operation string, entry *SamplingCacheEntry) {
+func (s SamplingCache) Set(
+ service, operation string,
+ entry *SamplingCacheEntry,
+) {
if _, ok := s[service]; !ok {
s[service] = make(map[string]*SamplingCacheEntry)
}
diff --git a/plugin/sampling/strategystore/adaptive/factory.go b/plugin/sampling/strategystore/adaptive/factory.go
index 35a583d4800..b1d4ff2fcf4 100644
--- a/plugin/sampling/strategystore/adaptive/factory.go
+++ b/plugin/sampling/strategystore/adaptive/factory.go
@@ -64,9 +64,15 @@ func (f *Factory) InitFromViper(v *viper.Viper, logger *zap.Logger) {
}
// Initialize implements strategystore.Factory
-func (f *Factory) Initialize(metricsFactory metrics.Factory, ssFactory storage.SamplingStoreFactory, logger *zap.Logger) error {
+func (f *Factory) Initialize(
+ metricsFactory metrics.Factory,
+ ssFactory storage.SamplingStoreFactory,
+ logger *zap.Logger,
+) error {
if ssFactory == nil {
- return errors.New("sampling store factory is nil. Please configure a backend that supports adaptive sampling")
+ return errors.New(
+ "sampling store factory is nil. Please configure a backend that supports adaptive sampling",
+ )
}
var err error
f.logger = logger
@@ -79,11 +85,15 @@ func (f *Factory) Initialize(metricsFactory metrics.Factory, ssFactory storage.S
if err != nil {
return err
}
- f.participant = leaderelection.NewElectionParticipant(f.lock, defaultResourceName, leaderelection.ElectionParticipantOptions{
- FollowerLeaseRefreshInterval: f.options.FollowerLeaseRefreshInterval,
- LeaderLeaseRefreshInterval: f.options.LeaderLeaseRefreshInterval,
- Logger: f.logger,
- })
+ f.participant = leaderelection.NewElectionParticipant(
+ f.lock,
+ defaultResourceName,
+ leaderelection.ElectionParticipantOptions{
+ FollowerLeaseRefreshInterval: f.options.FollowerLeaseRefreshInterval,
+ LeaderLeaseRefreshInterval: f.options.LeaderLeaseRefreshInterval,
+ Logger: f.logger,
+ },
+ )
f.participant.Start()
return nil
@@ -92,7 +102,13 @@ func (f *Factory) Initialize(metricsFactory metrics.Factory, ssFactory storage.S
// CreateStrategyStore implements strategystore.Factory
func (f *Factory) CreateStrategyStore() (strategystore.StrategyStore, strategystore.Aggregator, error) {
s := NewStrategyStore(*f.options, f.logger, f.participant, f.store)
- a, err := NewAggregator(*f.options, f.logger, f.metricsFactory, f.participant, f.store)
+ a, err := NewAggregator(
+ *f.options,
+ f.logger,
+ f.metricsFactory,
+ f.participant,
+ f.store,
+ )
if err != nil {
return nil, nil, err
}
diff --git a/plugin/sampling/strategystore/adaptive/factory_test.go b/plugin/sampling/strategystore/adaptive/factory_test.go
index 39157f1f39c..4166fc91e04 100644
--- a/plugin/sampling/strategystore/adaptive/factory_test.go
+++ b/plugin/sampling/strategystore/adaptive/factory_test.go
@@ -71,7 +71,14 @@ func TestFactory(t *testing.T) {
assert.Equal(t, time.Second, f.options.LeaderLeaseRefreshInterval)
assert.Equal(t, time.Second*2, f.options.FollowerLeaseRefreshInterval)
- require.NoError(t, f.Initialize(metrics.NullFactory, &mockSamplingStoreFactory{}, zap.NewNop()))
+ require.NoError(
+ t,
+ f.Initialize(
+ metrics.NullFactory,
+ &mockSamplingStoreFactory{},
+ zap.NewNop(),
+ ),
+ )
store, aggregator, err := f.CreateStrategyStore()
require.NoError(t, err)
require.NoError(t, store.Close())
@@ -95,7 +102,14 @@ func TestBadConfigFail(t *testing.T) {
f.InitFromViper(v, zap.NewNop())
- require.NoError(t, f.Initialize(metrics.NullFactory, &mockSamplingStoreFactory{}, zap.NewNop()))
+ require.NoError(
+ t,
+ f.Initialize(
+ metrics.NullFactory,
+ &mockSamplingStoreFactory{},
+ zap.NewNop(),
+ ),
+ )
_, _, err := f.CreateStrategyStore()
require.Error(t, err)
require.NoError(t, f.Close())
@@ -109,10 +123,16 @@ func TestSamplingStoreFactoryFails(t *testing.T) {
require.Error(t, f.Initialize(metrics.NullFactory, nil, zap.NewNop()))
// fail if lock fails
- require.Error(t, f.Initialize(metrics.NullFactory, &mockSamplingStoreFactory{lockFailsWith: errors.New("fail")}, zap.NewNop()))
+ require.Error(
+ t,
+ f.Initialize(metrics.NullFactory, &mockSamplingStoreFactory{lockFailsWith: errors.New("fail")}, zap.NewNop()),
+ )
// fail if store fails
- require.Error(t, f.Initialize(metrics.NullFactory, &mockSamplingStoreFactory{storeFailsWith: errors.New("fail")}, zap.NewNop()))
+ require.Error(
+ t,
+ f.Initialize(metrics.NullFactory, &mockSamplingStoreFactory{storeFailsWith: errors.New("fail")}, zap.NewNop()),
+ )
}
type mockSamplingStoreFactory struct {
@@ -131,13 +151,16 @@ func (m *mockSamplingStoreFactory) CreateLock() (distributedlock.Lock, error) {
return mockLock, nil
}
-func (m *mockSamplingStoreFactory) CreateSamplingStore(maxBuckets int) (samplingstore.Store, error) {
+func (m *mockSamplingStoreFactory) CreateSamplingStore(
+ maxBuckets int,
+) (samplingstore.Store, error) {
if m.storeFailsWith != nil {
return nil, m.storeFailsWith
}
mockStorage := &smocks.Store{}
- mockStorage.On("GetLatestProbabilities").Return(make(model.ServiceOperationProbabilities), nil)
+ mockStorage.On("GetLatestProbabilities").
+ Return(make(model.ServiceOperationProbabilities), nil)
mockStorage.On("GetThroughput", mock.AnythingOfType("time.Time"), mock.AnythingOfType("time.Time")).
Return([]*model.Throughput{}, nil)
diff --git a/plugin/sampling/strategystore/adaptive/options.go b/plugin/sampling/strategystore/adaptive/options.go
index 64288632dbf..23f858e2695 100644
--- a/plugin/sampling/strategystore/adaptive/options.go
+++ b/plugin/sampling/strategystore/adaptive/options.go
@@ -34,15 +34,17 @@ const (
leaderLeaseRefreshInterval = "sampling.leader-lease-refresh-interval"
followerLeaseRefreshInterval = "sampling.follower-lease-refresh-interval"
- defaultTargetSamplesPerSecond = 1
- defaultDeltaTolerance = 0.3
- defaultBucketsForCalculation = 1
- defaultCalculationInterval = time.Minute
- defaultAggregationBuckets = 10
- defaultDelay = time.Minute * 2
- defaultInitialSamplingProbability = 0.001
- defaultMinSamplingProbability = 1e-5 // one in 100k requests
- defaultMinSamplesPerSecond = 1.0 / float64(time.Minute/time.Second) // once every 1 minute
+ defaultTargetSamplesPerSecond = 1
+ defaultDeltaTolerance = 0.3
+ defaultBucketsForCalculation = 1
+ defaultCalculationInterval = time.Minute
+ defaultAggregationBuckets = 10
+ defaultDelay = time.Minute * 2
+ defaultInitialSamplingProbability = 0.001
+ defaultMinSamplingProbability = 1e-5 // one in 100k requests
+ defaultMinSamplesPerSecond = 1.0 / float64(
+ time.Minute/time.Second,
+ ) // once every 1 minute
defaultLeaderLeaseRefreshInterval = 5 * time.Second
defaultFollowerLeaseRefreshInterval = 60 * time.Second
)
@@ -118,22 +120,32 @@ func AddFlags(flagSet *flag.FlagSet) {
flagSet.Float64(targetSamplesPerSecond, defaultTargetSamplesPerSecond,
"The global target rate of samples per operation.",
)
- flagSet.Float64(deltaTolerance, defaultDeltaTolerance,
+ flagSet.Float64(
+ deltaTolerance,
+ defaultDeltaTolerance,
"The acceptable amount of deviation between the observed samples-per-second and the desired (target) samples-per-second, expressed as a ratio.",
)
- flagSet.Int(bucketsForCalculation, defaultBucketsForCalculation,
+ flagSet.Int(
+ bucketsForCalculation,
+ defaultBucketsForCalculation,
"This determines how much of the previous data is used in calculating the weighted QPS, ie. if BucketsForCalculation is 1, only the most recent data will be used in calculating the weighted QPS.",
)
- flagSet.Duration(calculationInterval, defaultCalculationInterval,
+ flagSet.Duration(
+ calculationInterval,
+ defaultCalculationInterval,
"How often new sampling probabilities are calculated. Recommended to be greater than the polling interval of your clients.",
)
flagSet.Int(aggregationBuckets, defaultAggregationBuckets,
"Amount of historical data to keep in memory.",
)
- flagSet.Duration(delay, defaultDelay,
+ flagSet.Duration(
+ delay,
+ defaultDelay,
"Determines how far back the most recent state is. Use this if you want to add some buffer time for the aggregation to finish.",
)
- flagSet.Float64(initialSamplingProbability, defaultInitialSamplingProbability,
+ flagSet.Float64(
+ initialSamplingProbability,
+ defaultInitialSamplingProbability,
"The initial sampling probability for all new operations.",
)
flagSet.Float64(minSamplingProbability, defaultMinSamplingProbability,
@@ -142,10 +154,14 @@ func AddFlags(flagSet *flag.FlagSet) {
flagSet.Float64(minSamplesPerSecond, defaultMinSamplesPerSecond,
"The minimum number of traces that are sampled per second.",
)
- flagSet.Duration(leaderLeaseRefreshInterval, defaultLeaderLeaseRefreshInterval,
+ flagSet.Duration(
+ leaderLeaseRefreshInterval,
+ defaultLeaderLeaseRefreshInterval,
"The duration to sleep if this processor is elected leader before attempting to renew the lease on the leader lock. This should be less than follower-lease-refresh-interval to reduce lock thrashing.",
)
- flagSet.Duration(followerLeaseRefreshInterval, defaultFollowerLeaseRefreshInterval,
+ flagSet.Duration(
+ followerLeaseRefreshInterval,
+ defaultFollowerLeaseRefreshInterval,
"The duration to sleep if this processor is a follower.",
)
}
@@ -162,6 +178,8 @@ func (opts *Options) InitFromViper(v *viper.Viper) *Options {
opts.MinSamplingProbability = v.GetFloat64(minSamplingProbability)
opts.MinSamplesPerSecond = v.GetFloat64(minSamplesPerSecond)
opts.LeaderLeaseRefreshInterval = v.GetDuration(leaderLeaseRefreshInterval)
- opts.FollowerLeaseRefreshInterval = v.GetDuration(followerLeaseRefreshInterval)
+ opts.FollowerLeaseRefreshInterval = v.GetDuration(
+ followerLeaseRefreshInterval,
+ )
return opts
}
diff --git a/plugin/sampling/strategystore/adaptive/options_test.go b/plugin/sampling/strategystore/adaptive/options_test.go
index 1ab64c0589c..78272581f8d 100644
--- a/plugin/sampling/strategystore/adaptive/options_test.go
+++ b/plugin/sampling/strategystore/adaptive/options_test.go
@@ -41,5 +41,9 @@ func TestOptionsWithFlags(t *testing.T) {
assert.Equal(t, 1e-4, opts.MinSamplingProbability)
assert.Equal(t, 0.016666666666666666, opts.MinSamplesPerSecond)
assert.Equal(t, time.Duration(5000000000), opts.LeaderLeaseRefreshInterval)
- assert.Equal(t, time.Duration(60000000000), opts.FollowerLeaseRefreshInterval)
+ assert.Equal(
+ t,
+ time.Duration(60000000000),
+ opts.FollowerLeaseRefreshInterval,
+ )
}
diff --git a/plugin/sampling/strategystore/adaptive/processor.go b/plugin/sampling/strategystore/adaptive/processor.go
index 4a56966d777..90ff40ccb58 100644
--- a/plugin/sampling/strategystore/adaptive/processor.go
+++ b/plugin/sampling/strategystore/adaptive/processor.go
@@ -44,14 +44,20 @@ const (
)
var (
- errNonZero = errors.New("CalculationInterval and AggregationBuckets must be greater than 0")
- errBucketsForCalculation = errors.New("BucketsForCalculation cannot be less than 1")
+ errNonZero = errors.New(
+ "CalculationInterval and AggregationBuckets must be greater than 0",
+ )
+ errBucketsForCalculation = errors.New(
+ "BucketsForCalculation cannot be less than 1",
+ )
)
// nested map: service -> operation -> throughput.
type serviceOperationThroughput map[string]map[string]*model.Throughput
-func (t serviceOperationThroughput) get(service, operation string) (*model.Throughput, bool) {
+func (t serviceOperationThroughput) get(
+ service, operation string,
+) (*model.Throughput, bool) {
svcThroughput, ok := t[service]
if ok {
v, ok := svcThroughput[operation]
@@ -121,7 +127,9 @@ func newPostAggregator(
if opts.BucketsForCalculation < 1 {
return nil, errBucketsForCalculation
}
- metricsFactory = metricsFactory.Namespace(metrics.NSOptions{Name: "adaptive_sampling_processor"})
+ metricsFactory = metricsFactory.Namespace(
+ metrics.NSOptions{Name: "adaptive_sampling_processor"},
+ )
return &PostAggregator{
Options: opts,
storage: storage,
@@ -131,17 +139,26 @@ func newPostAggregator(
logger: logger,
electionParticipant: electionParticipant,
// TODO make weightsCache and probabilityCalculator configurable
- weightVectorCache: NewWeightVectorCache(),
- probabilityCalculator: calculationstrategy.NewPercentageIncreaseCappedCalculator(1.0),
- serviceCache: []SamplingCache{},
- operationsCalculatedGauge: metricsFactory.Gauge(metrics.Options{Name: "operations_calculated"}),
- calculateProbabilitiesLatency: metricsFactory.Timer(metrics.TimerOptions{Name: "calculate_probabilities"}),
- shutdown: make(chan struct{}),
+ weightVectorCache: NewWeightVectorCache(),
+ probabilityCalculator: calculationstrategy.NewPercentageIncreaseCappedCalculator(
+ 1.0,
+ ),
+ serviceCache: []SamplingCache{},
+ operationsCalculatedGauge: metricsFactory.Gauge(
+ metrics.Options{Name: "operations_calculated"},
+ ),
+ calculateProbabilitiesLatency: metricsFactory.Timer(
+ metrics.TimerOptions{Name: "calculate_probabilities"},
+ ),
+ shutdown: make(chan struct{}),
}, nil
}
// GetSamplingStrategy implements protobuf endpoint for retrieving sampling strategy for a service.
-func (p *StrategyStore) GetSamplingStrategy(_ context.Context, service string) (*api_v2.SamplingStrategyResponse, error) {
+func (p *StrategyStore) GetSamplingStrategy(
+ _ context.Context,
+ service string,
+) (*api_v2.SamplingStrategyResponse, error) {
p.RLock()
defer p.RUnlock()
if strategy, ok := p.strategyResponses[service]; ok {
@@ -210,7 +227,9 @@ func (p *StrategyStore) isLeader() bool {
// trying to acquire the lock. With jitter, we can reduce the average amount of time before a
// new leader is elected. Furthermore, jitter can be used to spread out read load on storage.
func addJitter(jitterAmount time.Duration) time.Duration {
- return (jitterAmount / 2) + time.Duration(rand.Int63n(int64(jitterAmount/2)))
+ return (jitterAmount / 2) + time.Duration(
+ rand.Int63n(int64(jitterAmount/2)),
+ )
}
func (p *PostAggregator) runCalculation() {
@@ -269,7 +288,9 @@ func (p *PostAggregator) prependThroughputBucket(bucket *throughputBucket) {
// aggregateThroughput aggregates operation throughput from different buckets into one.
// All input buckets represent a single time range, but there are many of them because
// they are all independently generated by different collector instances from inbound span traffic.
-func (*PostAggregator) aggregateThroughput(throughputs []*model.Throughput) serviceOperationThroughput {
+func (*PostAggregator) aggregateThroughput(
+ throughputs []*model.Throughput,
+) serviceOperationThroughput {
aggregatedThroughput := make(serviceOperationThroughput)
for _, throughput := range throughputs {
service := throughput.Service
@@ -337,7 +358,10 @@ func (p *PostAggregator) throughputToQPS() serviceOperationQPS {
if len(qps[svc][op]) >= p.BucketsForCalculation {
continue
}
- qps[svc][op] = append(qps[svc][op], calculateQPS(throughput.Count, bucket.interval))
+ qps[svc][op] = append(
+ qps[svc][op],
+ calculateQPS(throughput.Count, bucket.interval),
+ )
}
}
}
@@ -364,7 +388,9 @@ func (p *PostAggregator) calculateWeightedQPS(allQPS []float64) float64 {
}
func (p *PostAggregator) prependServiceCache() {
- p.serviceCache = append([]SamplingCache{make(SamplingCache)}, p.serviceCache...)
+ p.serviceCache = append(
+ []SamplingCache{make(SamplingCache)},
+ p.serviceCache...)
if len(p.serviceCache) > serviceCacheSize {
p.serviceCache = p.serviceCache[0:serviceCacheSize]
}
@@ -394,7 +420,10 @@ func (p *PostAggregator) calculateProbabilitiesAndQPS() (model.ServiceOperationP
return retProbabilities, retQPS
}
-func (p *PostAggregator) calculateProbability(service, operation string, qps float64) float64 {
+func (p *PostAggregator) calculateProbability(
+ service, operation string,
+ qps float64,
+) float64 {
oldProbability := p.InitialSamplingProbability
// TODO: is this loop overly expensive?
p.RLock()
@@ -406,7 +435,12 @@ func (p *PostAggregator) calculateProbability(service, operation string, qps flo
latestThroughput := p.throughputs[0].throughput
p.RUnlock()
- usingAdaptiveSampling := p.isUsingAdaptiveSampling(oldProbability, service, operation, latestThroughput)
+ usingAdaptiveSampling := p.isUsingAdaptiveSampling(
+ oldProbability,
+ service,
+ operation,
+ latestThroughput,
+ )
p.serviceCache[0].Set(service, operation, &SamplingCacheEntry{
Probability: oldProbability,
UsingAdaptive: usingAdaptiveSampling,
@@ -414,7 +448,8 @@ func (p *PostAggregator) calculateProbability(service, operation string, qps flo
// Short circuit if the qps is close enough to targetQPS or if the service doesn't appear to be using
// adaptive sampling.
- if p.withinTolerance(qps, p.TargetSamplesPerSecond) || !usingAdaptiveSampling {
+ if p.withinTolerance(qps, p.TargetSamplesPerSecond) ||
+ !usingAdaptiveSampling {
return oldProbability
}
var newProbability float64
@@ -425,7 +460,10 @@ func (p *PostAggregator) calculateProbability(service, operation string, qps flo
} else {
newProbability = p.probabilityCalculator.Calculate(p.TargetSamplesPerSecond, qps, oldProbability)
}
- return math.Min(maxSamplingProbability, math.Max(p.MinSamplingProbability, newProbability))
+ return math.Min(
+ maxSamplingProbability,
+ math.Max(p.MinSamplingProbability, newProbability),
+ )
}
// is actual value within p.DeltaTolerance percentage of expected value.
@@ -463,7 +501,8 @@ func (p *PostAggregator) isUsingAdaptiveSampling(
// before.
if len(p.serviceCache) > 1 {
if e := p.serviceCache[1].Get(service, operation); e != nil {
- return e.UsingAdaptive && !FloatEquals(e.Probability, p.InitialSamplingProbability)
+ return e.UsingAdaptive &&
+ !FloatEquals(e.Probability, p.InitialSamplingProbability)
}
}
return false
@@ -474,7 +513,10 @@ func (p *StrategyStore) generateStrategyResponses() {
p.RLock()
strategies := make(map[string]*api_v2.SamplingStrategyResponse)
for svc, opProbabilities := range p.probabilities {
- opStrategies := make([]*api_v2.OperationSamplingStrategy, len(opProbabilities))
+ opStrategies := make(
+ []*api_v2.OperationSamplingStrategy,
+ len(opProbabilities),
+ )
var idx int
for op, probability := range opProbabilities {
opStrategies[idx] = &api_v2.OperationSamplingStrategy{
diff --git a/plugin/sampling/strategystore/adaptive/processor_test.go b/plugin/sampling/strategystore/adaptive/processor_test.go
index b9b587f26cf..41e9809ea75 100644
--- a/plugin/sampling/strategystore/adaptive/processor_test.go
+++ b/plugin/sampling/strategystore/adaptive/processor_test.go
@@ -37,10 +37,30 @@ import (
func testThroughputs() []*model.Throughput {
return []*model.Throughput{
- {Service: "svcA", Operation: "GET", Count: 4, Probabilities: map[string]struct{}{"0.1": {}}},
- {Service: "svcA", Operation: "GET", Count: 4, Probabilities: map[string]struct{}{"0.2": {}}},
- {Service: "svcA", Operation: "PUT", Count: 5, Probabilities: map[string]struct{}{"0.1": {}}},
- {Service: "svcB", Operation: "GET", Count: 3, Probabilities: map[string]struct{}{"0.1": {}}},
+ {
+ Service: "svcA",
+ Operation: "GET",
+ Count: 4,
+ Probabilities: map[string]struct{}{"0.1": {}},
+ },
+ {
+ Service: "svcA",
+ Operation: "GET",
+ Count: 4,
+ Probabilities: map[string]struct{}{"0.2": {}},
+ },
+ {
+ Service: "svcA",
+ Operation: "PUT",
+ Count: 5,
+ Probabilities: map[string]struct{}{"0.1": {}},
+ },
+ {
+ Service: "svcB",
+ Operation: "GET",
+ Count: 3,
+ Probabilities: map[string]struct{}{"0.1": {}},
+ },
}
}
@@ -78,10 +98,12 @@ func errTestStorage() error {
}
func testCalculator() calculationstrategy.ProbabilityCalculator {
- return calculationstrategy.CalculateFunc(func(targetQPS, qps, oldProbability float64) float64 {
- factor := targetQPS / qps
- return oldProbability * factor
- })
+ return calculationstrategy.CalculateFunc(
+ func(targetQPS, qps, oldProbability float64) float64 {
+ factor := targetQPS / qps
+ return oldProbability * factor
+ },
+ )
}
func TestAggregateThroughputInputsImmutability(t *testing.T) {
@@ -103,7 +125,11 @@ func TestAggregateThroughput(t *testing.T) {
opThroughput, ok := throughput["GET"]
require.True(t, ok)
assert.Equal(t, int64(8), opThroughput.Count)
- assert.Equal(t, map[string]struct{}{"0.1": {}, "0.2": {}}, opThroughput.Probabilities)
+ assert.Equal(
+ t,
+ map[string]struct{}{"0.1": {}, "0.2": {}},
+ opThroughput.Probabilities,
+ )
opThroughput, ok = throughput["PUT"]
require.True(t, ok)
@@ -128,7 +154,10 @@ func TestInitializeThroughput(t *testing.T) {
Return([]*model.Throughput{{Service: "svcA", Operation: "GET", Count: 7}}, nil)
mockStorage.On("GetThroughput", time.Time{}.Add(time.Minute*17), time.Time{}.Add(time.Minute*18)).
Return([]*model.Throughput{}, nil)
- p := &PostAggregator{storage: mockStorage, Options: Options{CalculationInterval: time.Minute, AggregationBuckets: 3}}
+ p := &PostAggregator{
+ storage: mockStorage,
+ Options: Options{CalculationInterval: time.Minute, AggregationBuckets: 3},
+ }
p.initializeThroughput(time.Time{}.Add(time.Minute * 20))
require.Len(t, p.throughputs, 2)
@@ -144,7 +173,10 @@ func TestInitializeThroughputFailure(t *testing.T) {
mockStorage := &smocks.Store{}
mockStorage.On("GetThroughput", time.Time{}.Add(time.Minute*19), time.Time{}.Add(time.Minute*20)).
Return(nil, errTestStorage())
- p := &PostAggregator{storage: mockStorage, Options: Options{CalculationInterval: time.Minute, AggregationBuckets: 1}}
+ p := &PostAggregator{
+ storage: mockStorage,
+ Options: Options{CalculationInterval: time.Minute, AggregationBuckets: 1},
+ }
p.initializeThroughput(time.Time{}.Add(time.Minute * 20))
assert.Empty(t, p.throughputs)
@@ -159,7 +191,10 @@ func TestCalculateQPS(t *testing.T) {
}
func TestGenerateOperationQPS(t *testing.T) {
- p := &PostAggregator{throughputs: testThroughputBuckets(), Options: Options{BucketsForCalculation: 10, AggregationBuckets: 10}}
+ p := &PostAggregator{
+ throughputs: testThroughputBuckets(),
+ Options: Options{BucketsForCalculation: 10, AggregationBuckets: 10},
+ }
svcOpQPS := p.throughputToQPS()
assert.Len(t, svcOpQPS, 2)
@@ -207,7 +242,10 @@ func TestGenerateOperationQPS(t *testing.T) {
}
func TestGenerateOperationQPS_UseMostRecentBucketOnly(t *testing.T) {
- p := &PostAggregator{throughputs: testThroughputBuckets(), Options: Options{BucketsForCalculation: 1, AggregationBuckets: 10}}
+ p := &PostAggregator{
+ throughputs: testThroughputBuckets(),
+ Options: Options{BucketsForCalculation: 1, AggregationBuckets: 10},
+ }
svcOpQPS := p.throughputToQPS()
assert.Len(t, svcOpQPS, 2)
@@ -242,8 +280,18 @@ func TestGenerateOperationQPS_UseMostRecentBucketOnly(t *testing.T) {
func TestCalculateWeightedQPS(t *testing.T) {
p := PostAggregator{weightVectorCache: NewWeightVectorCache()}
- assert.InDelta(t, 0.86735, p.calculateWeightedQPS([]float64{0.8, 1.2, 1.0}), 0.001)
- assert.InDelta(t, 0.95197, p.calculateWeightedQPS([]float64{1.0, 1.0, 0.0, 0.0}), 0.001)
+ assert.InDelta(
+ t,
+ 0.86735,
+ p.calculateWeightedQPS([]float64{0.8, 1.2, 1.0}),
+ 0.001,
+ )
+ assert.InDelta(
+ t,
+ 0.95197,
+ p.calculateWeightedQPS([]float64{1.0, 1.0, 0.0, 0.0}),
+ 0.001,
+ )
assert.Equal(t, 0.0, p.calculateWeightedQPS([]float64{}))
}
@@ -290,7 +338,11 @@ func TestCalculateProbability(t *testing.T) {
{"svcB", "DELETE", 0.0, 0.002, "test 0 qps"},
}
for _, test := range tests {
- probability := p.calculateProbability(test.service, test.operation, test.qps)
+ probability := p.calculateProbability(
+ test.service,
+ test.operation,
+ test.qps,
+ )
assert.Equal(t, test.expectedProbability, probability, test.errMsg)
}
}
@@ -322,12 +374,28 @@ func TestCalculateProbabilitiesAndQPS(t *testing.T) {
probabilities, qps := p.calculateProbabilitiesAndQPS()
require.Len(t, probabilities, 2)
- assert.Equal(t, map[string]float64{"GET": 0.00136, "PUT": 0.001}, probabilities["svcA"])
- assert.Equal(t, map[string]float64{"GET": 0.16, "PUT": 0.03}, probabilities["svcB"])
+ assert.Equal(
+ t,
+ map[string]float64{"GET": 0.00136, "PUT": 0.001},
+ probabilities["svcA"],
+ )
+ assert.Equal(
+ t,
+ map[string]float64{"GET": 0.16, "PUT": 0.03},
+ probabilities["svcB"],
+ )
require.Len(t, qps, 2)
- assert.Equal(t, map[string]float64{"GET": 0.7352941176470588, "PUT": 1}, qps["svcA"])
- assert.Equal(t, map[string]float64{"GET": 0.5147058823529411, "PUT": 0.25}, qps["svcB"])
+ assert.Equal(
+ t,
+ map[string]float64{"GET": 0.7352941176470588, "PUT": 1},
+ qps["svcA"],
+ )
+ assert.Equal(
+ t,
+ map[string]float64{"GET": 0.5147058823529411, "PUT": 0.25},
+ qps["svcB"],
+ )
_, gauges := mets.Backend.Snapshot()
assert.EqualValues(t, 4, gauges["test"])
@@ -338,9 +406,11 @@ func TestRunCalculationLoop(t *testing.T) {
mockStorage := &smocks.Store{}
mockStorage.On("GetThroughput", mock.AnythingOfType("time.Time"), mock.AnythingOfType("time.Time")).
Return(testThroughputs(), nil)
- mockStorage.On("GetLatestProbabilities").Return(model.ServiceOperationProbabilities{}, errTestStorage())
+ mockStorage.On("GetLatestProbabilities").
+ Return(model.ServiceOperationProbabilities{}, errTestStorage())
mockStorage.On("InsertProbabilitiesAndQPS", mock.AnythingOfType("string"), mock.AnythingOfType("model.ServiceOperationProbabilities"),
- mock.AnythingOfType("model.ServiceOperationQPS")).Return(errTestStorage())
+ mock.AnythingOfType("model.ServiceOperationQPS")).
+ Return(errTestStorage())
mockStorage.On("InsertThroughput", mock.AnythingOfType("[]*model.Throughput")).Return(errTestStorage())
mockEP := &epmocks.ElectionParticipant{}
mockEP.On("Start").Return(nil)
@@ -358,7 +428,13 @@ func TestRunCalculationLoop(t *testing.T) {
FollowerLeaseRefreshInterval: time.Second,
BucketsForCalculation: 10,
}
- agg, err := NewAggregator(cfg, logger, metrics.NullFactory, mockEP, mockStorage)
+ agg, err := NewAggregator(
+ cfg,
+ logger,
+ metrics.NullFactory,
+ mockEP,
+ mockStorage,
+ )
require.NoError(t, err)
agg.Start()
defer agg.Close()
@@ -385,9 +461,11 @@ func TestRunCalculationLoop_GetThroughputError(t *testing.T) {
mockStorage := &smocks.Store{}
mockStorage.On("GetThroughput", mock.AnythingOfType("time.Time"), mock.AnythingOfType("time.Time")).
Return(nil, errTestStorage())
- mockStorage.On("GetLatestProbabilities").Return(model.ServiceOperationProbabilities{}, errTestStorage())
+ mockStorage.On("GetLatestProbabilities").
+ Return(model.ServiceOperationProbabilities{}, errTestStorage())
mockStorage.On("InsertProbabilitiesAndQPS", mock.AnythingOfType("string"), mock.AnythingOfType("model.ServiceOperationProbabilities"),
- mock.AnythingOfType("model.ServiceOperationQPS")).Return(errTestStorage())
+ mock.AnythingOfType("model.ServiceOperationQPS")).
+ Return(errTestStorage())
mockStorage.On("InsertThroughput", mock.AnythingOfType("[]*model.Throughput")).Return(errTestStorage())
mockEP := &epmocks.ElectionParticipant{}
@@ -400,7 +478,13 @@ func TestRunCalculationLoop_GetThroughputError(t *testing.T) {
AggregationBuckets: 2,
BucketsForCalculation: 10,
}
- agg, err := NewAggregator(cfg, logger, metrics.NullFactory, mockEP, mockStorage)
+ agg, err := NewAggregator(
+ cfg,
+ logger,
+ metrics.NullFactory,
+ mockEP,
+ mockStorage,
+ )
require.NoError(t, err)
agg.Start()
for i := 0; i < 1000; i++ {
@@ -411,14 +495,19 @@ func TestRunCalculationLoop_GetThroughputError(t *testing.T) {
}
time.Sleep(time.Millisecond)
}
- match, errMsg := testutils.LogMatcher(2, getThroughputErrMsg, logBuffer.Lines())
+ match, errMsg := testutils.LogMatcher(
+ 2,
+ getThroughputErrMsg,
+ logBuffer.Lines(),
+ )
assert.True(t, match, errMsg)
require.NoError(t, agg.Close())
}
func TestLoadProbabilities(t *testing.T) {
mockStorage := &smocks.Store{}
- mockStorage.On("GetLatestProbabilities").Return(make(model.ServiceOperationProbabilities), nil)
+ mockStorage.On("GetLatestProbabilities").
+ Return(make(model.ServiceOperationProbabilities), nil)
p := &StrategyStore{storage: mockStorage}
require.Nil(t, p.probabilities)
@@ -428,7 +517,8 @@ func TestLoadProbabilities(t *testing.T) {
func TestRunUpdateProbabilitiesLoop(t *testing.T) {
mockStorage := &smocks.Store{}
- mockStorage.On("GetLatestProbabilities").Return(make(model.ServiceOperationProbabilities), nil)
+ mockStorage.On("GetLatestProbabilities").
+ Return(make(model.ServiceOperationProbabilities), nil)
mockEP := &epmocks.ElectionParticipant{}
mockEP.On("Start").Return(nil)
mockEP.On("Close").Return(nil)
@@ -473,9 +563,11 @@ func TestRealisticRunCalculationLoop(t *testing.T) {
mockStorage := &smocks.Store{}
mockStorage.On("GetThroughput", mock.AnythingOfType("time.Time"), mock.AnythingOfType("time.Time")).
Return(testThroughputs, nil)
- mockStorage.On("GetLatestProbabilities").Return(make(model.ServiceOperationProbabilities), nil)
+ mockStorage.On("GetLatestProbabilities").
+ Return(make(model.ServiceOperationProbabilities), nil)
mockStorage.On("InsertProbabilitiesAndQPS", "host", mock.AnythingOfType("model.ServiceOperationProbabilities"),
- mock.AnythingOfType("model.ServiceOperationQPS")).Return(nil)
+ mock.AnythingOfType("model.ServiceOperationQPS")).
+ Return(nil)
mockEP := &epmocks.ElectionParticipant{}
mockEP.On("Start").Return(nil)
mockEP.On("Close").Return(nil)
@@ -514,11 +606,21 @@ func TestRealisticRunCalculationLoop(t *testing.T) {
assert.Equal(t, 0.001, s.ProbabilisticSampling.SamplingRate,
"Within epsilon of 1QPS, no probability change")
case "PUT":
- assert.InEpsilon(t, 0.002, s.ProbabilisticSampling.SamplingRate, 0.025,
- "Under sampled, double probability")
+ assert.InEpsilon(
+ t,
+ 0.002,
+ s.ProbabilisticSampling.SamplingRate,
+ 0.025,
+ "Under sampled, double probability",
+ )
case "DELETE":
- assert.InEpsilon(t, 0.0005, s.ProbabilisticSampling.SamplingRate, 0.025,
- "Over sampled, halve probability")
+ assert.InEpsilon(
+ t,
+ 0.0005,
+ s.ProbabilisticSampling.SamplingRate,
+ 0.025,
+ "Over sampled, halve probability",
+ )
}
}
}
@@ -544,17 +646,46 @@ func TestConstructorFailure(t *testing.T) {
CalculationInterval: time.Second * 5,
AggregationBuckets: 0,
}
- _, err := newPostAggregator(cfg, "host", nil, nil, metrics.NullFactory, logger)
- require.EqualError(t, err, "CalculationInterval and AggregationBuckets must be greater than 0")
+ _, err := newPostAggregator(
+ cfg,
+ "host",
+ nil,
+ nil,
+ metrics.NullFactory,
+ logger,
+ )
+ require.EqualError(
+ t,
+ err,
+ "CalculationInterval and AggregationBuckets must be greater than 0",
+ )
cfg.CalculationInterval = 0
- _, err = newPostAggregator(cfg, "host", nil, nil, metrics.NullFactory, logger)
- require.EqualError(t, err, "CalculationInterval and AggregationBuckets must be greater than 0")
+ _, err = newPostAggregator(
+ cfg,
+ "host",
+ nil,
+ nil,
+ metrics.NullFactory,
+ logger,
+ )
+ require.EqualError(
+ t,
+ err,
+ "CalculationInterval and AggregationBuckets must be greater than 0",
+ )
cfg.CalculationInterval = time.Millisecond
cfg.AggregationBuckets = 1
cfg.BucketsForCalculation = -1
- _, err = newPostAggregator(cfg, "host", nil, nil, metrics.NullFactory, logger)
+ _, err = newPostAggregator(
+ cfg,
+ "host",
+ nil,
+ nil,
+ metrics.NullFactory,
+ logger,
+ )
require.EqualError(t, err, "BucketsForCalculation cannot be less than 1")
}
@@ -607,15 +738,39 @@ func TestUsingAdaptiveSampling(t *testing.T) {
operation string
}{
{expected: true, probability: 0.01, service: "svc", operation: "op"},
- {expected: true, probability: 0.0099999384, service: "svc", operation: "op"},
+ {
+ expected: true,
+ probability: 0.0099999384,
+ service: "svc",
+ operation: "op",
+ },
{expected: false, probability: 0.01, service: "non-svc"},
- {expected: false, probability: 0.01, service: "svc", operation: "non-op"},
- {expected: false, probability: 0.01, service: "svc", operation: "non-op"},
+ {
+ expected: false,
+ probability: 0.01,
+ service: "svc",
+ operation: "non-op",
+ },
+ {
+ expected: false,
+ probability: 0.01,
+ service: "svc",
+ operation: "non-op",
+ },
{expected: false, probability: 0.02, service: "svc", operation: "op"},
- {expected: false, probability: 0.0100009384, service: "svc", operation: "op"},
+ {
+ expected: false,
+ probability: 0.0100009384,
+ service: "svc",
+ operation: "op",
+ },
}
for _, test := range tests {
- assert.Equal(t, test.expected, p.isUsingAdaptiveSampling(test.probability, test.service, test.operation, throughput))
+ assert.Equal(
+ t,
+ test.expected,
+ p.isUsingAdaptiveSampling(test.probability, test.service, test.operation, throughput),
+ )
}
}
@@ -632,11 +787,20 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) {
{
throughput: serviceOperationThroughput{
"svcA": map[string]*model.Throughput{
- "GET": {Count: 3, Probabilities: map[string]struct{}{"0.001000": {}}},
- "PUT": {Count: 60, Probabilities: map[string]struct{}{"0.001000": {}}},
+ "GET": {
+ Count: 3,
+ Probabilities: map[string]struct{}{"0.001000": {}},
+ },
+ "PUT": {
+ Count: 60,
+ Probabilities: map[string]struct{}{"0.001000": {}},
+ },
},
"svcB": map[string]*model.Throughput{
- "PUT": {Count: 15, Probabilities: map[string]struct{}{"0.001000": {}}},
+ "PUT": {
+ Count: 15,
+ Probabilities: map[string]struct{}{"0.001000": {}},
+ },
},
},
interval: 60 * time.Second,
@@ -652,8 +816,12 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) {
AggregationBuckets: 10,
},
throughputs: buckets, probabilities: make(model.ServiceOperationProbabilities),
- qps: make(model.ServiceOperationQPS), weightVectorCache: NewWeightVectorCache(),
- probabilityCalculator: calculationstrategy.NewPercentageIncreaseCappedCalculator(1.0),
+ qps: make(
+ model.ServiceOperationQPS,
+ ), weightVectorCache: NewWeightVectorCache(),
+ probabilityCalculator: calculationstrategy.NewPercentageIncreaseCappedCalculator(
+ 1.0,
+ ),
serviceCache: []SamplingCache{},
operationsCalculatedGauge: metrics.NullFactory.Gauge(metrics.Options{}),
}
@@ -661,7 +829,11 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) {
probabilities, qps := p.calculateProbabilitiesAndQPS()
require.Len(t, probabilities, 2)
- assert.Equal(t, map[string]float64{"GET": 0.002, "PUT": 0.001}, probabilities["svcA"])
+ assert.Equal(
+ t,
+ map[string]float64{"GET": 0.002, "PUT": 0.001},
+ probabilities["svcA"],
+ )
assert.Equal(t, map[string]float64{"PUT": 0.002}, probabilities["svcB"])
p.probabilities = probabilities
@@ -673,11 +845,20 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) {
p.prependThroughputBucket(&throughputBucket{
throughput: serviceOperationThroughput{
"svcA": map[string]*model.Throughput{
- "PUT": {Count: 60, Probabilities: map[string]struct{}{"0.001000": {}}},
+ "PUT": {
+ Count: 60,
+ Probabilities: map[string]struct{}{"0.001000": {}},
+ },
},
"svcB": map[string]*model.Throughput{
- "GET": {Count: 30, Probabilities: map[string]struct{}{"0.001000": {}}},
- "PUT": {Count: 0, Probabilities: map[string]struct{}{"0.002000": {}}},
+ "GET": {
+ Count: 30,
+ Probabilities: map[string]struct{}{"0.001000": {}},
+ },
+ "PUT": {
+ Count: 0,
+ Probabilities: map[string]struct{}{"0.002000": {}},
+ },
},
},
interval: 60 * time.Second,
@@ -686,8 +867,16 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) {
probabilities, qps = p.calculateProbabilitiesAndQPS()
require.Len(t, probabilities, 2)
- assert.Equal(t, map[string]float64{"GET": 0.002, "PUT": 0.001}, probabilities["svcA"])
- assert.Equal(t, map[string]float64{"PUT": 0.004, "GET": 0.002}, probabilities["svcB"])
+ assert.Equal(
+ t,
+ map[string]float64{"GET": 0.002, "PUT": 0.001},
+ probabilities["svcA"],
+ )
+ assert.Equal(
+ t,
+ map[string]float64{"PUT": 0.004, "GET": 0.002},
+ probabilities["svcB"],
+ )
p.probabilities = probabilities
p.qps = qps
@@ -698,11 +887,20 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) {
p.prependThroughputBucket(&throughputBucket{
throughput: serviceOperationThroughput{
"svcA": map[string]*model.Throughput{
- "GET": {Count: 0, Probabilities: map[string]struct{}{"0.002000": {}}},
- "PUT": {Count: 60, Probabilities: map[string]struct{}{"0.001000": {}}},
+ "GET": {
+ Count: 0,
+ Probabilities: map[string]struct{}{"0.002000": {}},
+ },
+ "PUT": {
+ Count: 60,
+ Probabilities: map[string]struct{}{"0.001000": {}},
+ },
},
"svcB": map[string]*model.Throughput{
- "GET": {Count: 30, Probabilities: map[string]struct{}{"0.001000": {}}},
+ "GET": {
+ Count: 30,
+ Probabilities: map[string]struct{}{"0.001000": {}},
+ },
},
},
interval: 60 * time.Second,
@@ -711,8 +909,16 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) {
probabilities, qps = p.calculateProbabilitiesAndQPS()
require.Len(t, probabilities, 2)
- assert.Equal(t, map[string]float64{"GET": 0.004, "PUT": 0.001}, probabilities["svcA"])
- assert.Equal(t, map[string]float64{"PUT": 0.008, "GET": 0.002}, probabilities["svcB"])
+ assert.Equal(
+ t,
+ map[string]float64{"GET": 0.004, "PUT": 0.001},
+ probabilities["svcA"],
+ )
+ assert.Equal(
+ t,
+ map[string]float64{"PUT": 0.008, "GET": 0.002},
+ probabilities["svcB"],
+ )
p.probabilities = probabilities
p.qps = qps
@@ -722,12 +928,24 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) {
p.prependThroughputBucket(&throughputBucket{
throughput: serviceOperationThroughput{
"svcA": map[string]*model.Throughput{
- "GET": {Count: 1, Probabilities: map[string]struct{}{"0.004000": {}}},
- "PUT": {Count: 60, Probabilities: map[string]struct{}{"0.001000": {}}},
+ "GET": {
+ Count: 1,
+ Probabilities: map[string]struct{}{"0.004000": {}},
+ },
+ "PUT": {
+ Count: 60,
+ Probabilities: map[string]struct{}{"0.001000": {}},
+ },
},
"svcB": map[string]*model.Throughput{
- "GET": {Count: 30, Probabilities: map[string]struct{}{"0.001000": {}}},
- "PUT": {Count: 15, Probabilities: map[string]struct{}{"0.001000": {}}},
+ "GET": {
+ Count: 30,
+ Probabilities: map[string]struct{}{"0.001000": {}},
+ },
+ "PUT": {
+ Count: 15,
+ Probabilities: map[string]struct{}{"0.001000": {}},
+ },
},
},
interval: 60 * time.Second,
@@ -736,8 +954,16 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) {
probabilities, qps = p.calculateProbabilitiesAndQPS()
require.Len(t, probabilities, 2)
- assert.Equal(t, map[string]float64{"GET": 0.008, "PUT": 0.001}, probabilities["svcA"])
- assert.Equal(t, map[string]float64{"PUT": 0.008, "GET": 0.002}, probabilities["svcB"])
+ assert.Equal(
+ t,
+ map[string]float64{"GET": 0.008, "PUT": 0.001},
+ probabilities["svcA"],
+ )
+ assert.Equal(
+ t,
+ map[string]float64{"PUT": 0.008, "GET": 0.002},
+ probabilities["svcB"],
+ )
p.probabilities = probabilities
p.qps = qps
@@ -746,11 +972,20 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) {
p.prependThroughputBucket(&throughputBucket{
throughput: serviceOperationThroughput{
"svcA": map[string]*model.Throughput{
- "PUT": {Count: 30, Probabilities: map[string]struct{}{"0.001000": {}}},
+ "PUT": {
+ Count: 30,
+ Probabilities: map[string]struct{}{"0.001000": {}},
+ },
},
"svcB": map[string]*model.Throughput{
- "GET": {Count: 30, Probabilities: map[string]struct{}{"0.001000": {}}},
- "PUT": {Count: 15, Probabilities: map[string]struct{}{"0.001000": {}}},
+ "GET": {
+ Count: 30,
+ Probabilities: map[string]struct{}{"0.001000": {}},
+ },
+ "PUT": {
+ Count: 15,
+ Probabilities: map[string]struct{}{"0.001000": {}},
+ },
},
},
interval: 60 * time.Second,
@@ -759,8 +994,16 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) {
probabilities, qps = p.calculateProbabilitiesAndQPS()
require.Len(t, probabilities, 2)
- assert.Equal(t, map[string]float64{"GET": 0.016, "PUT": 0.001468867216804201}, probabilities["svcA"])
- assert.Equal(t, map[string]float64{"PUT": 0.008, "GET": 0.002}, probabilities["svcB"])
+ assert.Equal(
+ t,
+ map[string]float64{"GET": 0.016, "PUT": 0.001468867216804201},
+ probabilities["svcA"],
+ )
+ assert.Equal(
+ t,
+ map[string]float64{"PUT": 0.008, "GET": 0.002},
+ probabilities["svcB"],
+ )
p.probabilities = probabilities
p.qps = qps
@@ -770,11 +1013,20 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) {
p.prependThroughputBucket(&throughputBucket{
throughput: serviceOperationThroughput{
"svcA": map[string]*model.Throughput{
- "PUT": {Count: 30, Probabilities: map[string]struct{}{"0.001000": {}}},
+ "PUT": {
+ Count: 30,
+ Probabilities: map[string]struct{}{"0.001000": {}},
+ },
},
"svcB": map[string]*model.Throughput{
- "GET": {Count: 30, Probabilities: map[string]struct{}{"0.001000": {}}},
- "PUT": {Count: 1, Probabilities: map[string]struct{}{"0.008000": {}}},
+ "GET": {
+ Count: 30,
+ Probabilities: map[string]struct{}{"0.001000": {}},
+ },
+ "PUT": {
+ Count: 1,
+ Probabilities: map[string]struct{}{"0.008000": {}},
+ },
},
},
interval: 60 * time.Second,
@@ -783,8 +1035,16 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) {
probabilities, qps = p.calculateProbabilitiesAndQPS()
require.Len(t, probabilities, 2)
- assert.Equal(t, map[string]float64{"GET": 0.032, "PUT": 0.001468867216804201}, probabilities["svcA"])
- assert.Equal(t, map[string]float64{"PUT": 0.016, "GET": 0.002}, probabilities["svcB"])
+ assert.Equal(
+ t,
+ map[string]float64{"GET": 0.032, "PUT": 0.001468867216804201},
+ probabilities["svcA"],
+ )
+ assert.Equal(
+ t,
+ map[string]float64{"PUT": 0.016, "GET": 0.002},
+ probabilities["svcB"],
+ )
p.probabilities = probabilities
p.qps = qps
@@ -794,10 +1054,16 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) {
p.prependThroughputBucket(&throughputBucket{
throughput: serviceOperationThroughput{
"svcA": map[string]*model.Throughput{
- "PUT": {Count: 30, Probabilities: map[string]struct{}{"0.001000": {}}},
+ "PUT": {
+ Count: 30,
+ Probabilities: map[string]struct{}{"0.001000": {}},
+ },
},
"svcB": map[string]*model.Throughput{
- "GET": {Count: 15, Probabilities: map[string]struct{}{"0.001000": {}}},
+ "GET": {
+ Count: 15,
+ Probabilities: map[string]struct{}{"0.001000": {}},
+ },
},
},
interval: 60 * time.Second,
@@ -806,8 +1072,16 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) {
probabilities, qps = p.calculateProbabilitiesAndQPS()
require.Len(t, probabilities, 2)
- assert.Equal(t, map[string]float64{"GET": 0.064, "PUT": 0.001468867216804201}, probabilities["svcA"])
- assert.Equal(t, map[string]float64{"PUT": 0.032, "GET": 0.002}, probabilities["svcB"])
+ assert.Equal(
+ t,
+ map[string]float64{"GET": 0.064, "PUT": 0.001468867216804201},
+ probabilities["svcA"],
+ )
+ assert.Equal(
+ t,
+ map[string]float64{"PUT": 0.032, "GET": 0.002},
+ probabilities["svcB"],
+ )
p.probabilities = probabilities
p.qps = qps
@@ -817,10 +1091,16 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) {
p.prependThroughputBucket(&throughputBucket{
throughput: serviceOperationThroughput{
"svcA": map[string]*model.Throughput{
- "PUT": {Count: 20, Probabilities: map[string]struct{}{"0.001000": {}}},
+ "PUT": {
+ Count: 20,
+ Probabilities: map[string]struct{}{"0.001000": {}},
+ },
},
"svcB": map[string]*model.Throughput{
- "GET": {Count: 10, Probabilities: map[string]struct{}{"0.001000": {}}},
+ "GET": {
+ Count: 10,
+ Probabilities: map[string]struct{}{"0.001000": {}},
+ },
},
},
interval: 60 * time.Second,
@@ -829,8 +1109,16 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) {
probabilities, qps = p.calculateProbabilitiesAndQPS()
require.Len(t, probabilities, 2)
- assert.Equal(t, map[string]float64{"GET": 0.128, "PUT": 0.001468867216804201}, probabilities["svcA"])
- assert.Equal(t, map[string]float64{"PUT": 0.064, "GET": 0.002}, probabilities["svcB"])
+ assert.Equal(
+ t,
+ map[string]float64{"GET": 0.128, "PUT": 0.001468867216804201},
+ probabilities["svcA"],
+ )
+ assert.Equal(
+ t,
+ map[string]float64{"PUT": 0.064, "GET": 0.002},
+ probabilities["svcB"],
+ )
p.probabilities = probabilities
p.qps = qps
@@ -840,12 +1128,24 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) {
p.prependThroughputBucket(&throughputBucket{
throughput: serviceOperationThroughput{
"svcA": map[string]*model.Throughput{
- "PUT": {Count: 20, Probabilities: map[string]struct{}{"0.001000": {}}},
- "GET": {Count: 120, Probabilities: map[string]struct{}{"0.128000": {}}},
+ "PUT": {
+ Count: 20,
+ Probabilities: map[string]struct{}{"0.001000": {}},
+ },
+ "GET": {
+ Count: 120,
+ Probabilities: map[string]struct{}{"0.128000": {}},
+ },
},
"svcB": map[string]*model.Throughput{
- "PUT": {Count: 60, Probabilities: map[string]struct{}{"0.064000": {}}},
- "GET": {Count: 10, Probabilities: map[string]struct{}{"0.001000": {}}},
+ "PUT": {
+ Count: 60,
+ Probabilities: map[string]struct{}{"0.064000": {}},
+ },
+ "GET": {
+ Count: 10,
+ Probabilities: map[string]struct{}{"0.001000": {}},
+ },
},
},
interval: 60 * time.Second,
@@ -854,8 +1154,19 @@ func TestCalculateProbabilitiesAndQPSMultiple(t *testing.T) {
probabilities, qps = p.calculateProbabilitiesAndQPS()
require.Len(t, probabilities, 2)
- assert.Equal(t, map[string]float64{"GET": 0.0882586677054928, "PUT": 0.001468867216804201}, probabilities["svcA"])
- assert.Equal(t, map[string]float64{"PUT": 0.09587513707888091, "GET": 0.002}, probabilities["svcB"])
+ assert.Equal(
+ t,
+ map[string]float64{
+ "GET": 0.0882586677054928,
+ "PUT": 0.001468867216804201,
+ },
+ probabilities["svcA"],
+ )
+ assert.Equal(
+ t,
+ map[string]float64{"PUT": 0.09587513707888091, "GET": 0.002},
+ probabilities["svcB"],
+ )
p.probabilities = probabilities
p.qps = qps
diff --git a/plugin/sampling/strategystore/adaptive/strategy_store.go b/plugin/sampling/strategystore/adaptive/strategy_store.go
index 6a8749c9dc8..d890e97d32d 100644
--- a/plugin/sampling/strategystore/adaptive/strategy_store.go
+++ b/plugin/sampling/strategystore/adaptive/strategy_store.go
@@ -52,12 +52,19 @@ type StrategyStore struct {
}
// NewStrategyStore creates a strategy store that holds adaptive sampling strategies.
-func NewStrategyStore(options Options, logger *zap.Logger, participant leaderelection.ElectionParticipant, store samplingstore.Store) *StrategyStore {
+func NewStrategyStore(
+ options Options,
+ logger *zap.Logger,
+ participant leaderelection.ElectionParticipant,
+ store samplingstore.Store,
+) *StrategyStore {
return &StrategyStore{
- Options: options,
- storage: store,
- probabilities: make(model.ServiceOperationProbabilities),
- strategyResponses: make(map[string]*api_v2.SamplingStrategyResponse),
+ Options: options,
+ storage: store,
+ probabilities: make(model.ServiceOperationProbabilities),
+ strategyResponses: make(
+ map[string]*api_v2.SamplingStrategyResponse,
+ ),
logger: logger,
electionParticipant: participant,
followerRefreshInterval: defaultFollowerProbabilityInterval,
diff --git a/plugin/sampling/strategystore/factory.go b/plugin/sampling/strategystore/factory.go
index d7fe77b2710..798626b77a7 100644
--- a/plugin/sampling/strategystore/factory.go
+++ b/plugin/sampling/strategystore/factory.go
@@ -67,14 +67,20 @@ func NewFactory(config FactoryConfig) (*Factory, error) {
return f, nil
}
-func (*Factory) getFactoryOfType(factoryType Kind) (strategystore.Factory, error) {
+func (*Factory) getFactoryOfType(
+ factoryType Kind,
+) (strategystore.Factory, error) {
switch factoryType {
case samplingTypeFile:
return static.NewFactory(), nil
case samplingTypeAdaptive:
return adaptive.NewFactory(), nil
default:
- return nil, fmt.Errorf("unknown sampling strategy store type %s. Valid types are %v", factoryType, AllSamplingTypes)
+ return nil, fmt.Errorf(
+ "unknown sampling strategy store type %s. Valid types are %v",
+ factoryType,
+ AllSamplingTypes,
+ )
}
}
@@ -97,7 +103,11 @@ func (f *Factory) InitFromViper(v *viper.Viper, logger *zap.Logger) {
}
// Initialize implements strategystore.Factory
-func (f *Factory) Initialize(metricsFactory metrics.Factory, ssFactory storage.SamplingStoreFactory, logger *zap.Logger) error {
+func (f *Factory) Initialize(
+ metricsFactory metrics.Factory,
+ ssFactory storage.SamplingStoreFactory,
+ logger *zap.Logger,
+) error {
for _, factory := range f.factories {
if err := factory.Initialize(metricsFactory, ssFactory, logger); err != nil {
return err
@@ -110,7 +120,10 @@ func (f *Factory) Initialize(metricsFactory metrics.Factory, ssFactory storage.S
func (f *Factory) CreateStrategyStore() (strategystore.StrategyStore, strategystore.Aggregator, error) {
factory, ok := f.factories[f.StrategyStoreType]
if !ok {
- return nil, nil, fmt.Errorf("no %s strategy store registered", f.StrategyStoreType)
+ return nil, nil, fmt.Errorf(
+ "no %s strategy store registered",
+ f.StrategyStoreType,
+ )
}
return factory.CreateStrategyStore()
}
diff --git a/plugin/sampling/strategystore/factory_config.go b/plugin/sampling/strategystore/factory_config.go
index d3acc1a9595..731248958d9 100644
--- a/plugin/sampling/strategystore/factory_config.go
+++ b/plugin/sampling/strategystore/factory_config.go
@@ -36,7 +36,11 @@ func FactoryConfigFromEnv() (*FactoryConfig, error) {
strategyStoreType := getStrategyStoreTypeFromEnv()
if strategyStoreType != samplingTypeAdaptive &&
strategyStoreType != samplingTypeFile {
- return nil, fmt.Errorf("invalid sampling type: %s. Valid types are %v", strategyStoreType, AllSamplingTypes)
+ return nil, fmt.Errorf(
+ "invalid sampling type: %s. Valid types are %v",
+ strategyStoreType,
+ AllSamplingTypes,
+ )
}
return &FactoryConfig{
diff --git a/plugin/sampling/strategystore/factory_test.go b/plugin/sampling/strategystore/factory_test.go
index 28e8f47182d..01b5c5cd7bb 100644
--- a/plugin/sampling/strategystore/factory_test.go
+++ b/plugin/sampling/strategystore/factory_test.go
@@ -64,7 +64,9 @@ func TestNewFactory(t *testing.T) {
mockSSFactory := &mockSamplingStoreFactory{}
for _, tc := range tests {
- f, err := NewFactory(FactoryConfig{StrategyStoreType: Kind(tc.strategyStoreType)})
+ f, err := NewFactory(
+ FactoryConfig{StrategyStoreType: Kind(tc.strategyStoreType)},
+ )
if tc.expectError {
require.Error(t, err)
continue
@@ -76,14 +78,21 @@ func TestNewFactory(t *testing.T) {
mock := new(mockFactory)
f.factories[Kind(tc.strategyStoreType)] = mock
- require.NoError(t, f.Initialize(metrics.NullFactory, mockSSFactory, zap.NewNop()))
+ require.NoError(
+ t,
+ f.Initialize(metrics.NullFactory, mockSSFactory, zap.NewNop()),
+ )
_, _, err = f.CreateStrategyStore()
require.NoError(t, err)
require.NoError(t, f.Close())
// force the mock to return errors
mock.retError = true
- require.EqualError(t, f.Initialize(metrics.NullFactory, mockSSFactory, zap.NewNop()), "error initializing store")
+ require.EqualError(
+ t,
+ f.Initialize(metrics.NullFactory, mockSSFactory, zap.NewNop()),
+ "error initializing store",
+ )
_, _, err = f.CreateStrategyStore()
require.EqualError(t, err, "error creating store")
require.EqualError(t, f.Close(), "error closing store")
@@ -139,7 +148,11 @@ func (f *mockFactory) CreateStrategyStore() (ss.StrategyStore, ss.Aggregator, er
return nil, nil, nil
}
-func (f *mockFactory) Initialize(metricsFactory metrics.Factory, ssFactory storage.SamplingStoreFactory, logger *zap.Logger) error {
+func (f *mockFactory) Initialize(
+ metricsFactory metrics.Factory,
+ ssFactory storage.SamplingStoreFactory,
+ logger *zap.Logger,
+) error {
if f.retError {
return errors.New("error initializing store")
}
@@ -159,6 +172,8 @@ func (*mockSamplingStoreFactory) CreateLock() (distributedlock.Lock, error) {
return nil, nil
}
-func (*mockSamplingStoreFactory) CreateSamplingStore(maxBuckets int) (samplingstore.Store, error) {
+func (*mockSamplingStoreFactory) CreateSamplingStore(
+ maxBuckets int,
+) (samplingstore.Store, error) {
return nil, nil
}
diff --git a/plugin/sampling/strategystore/static/factory.go b/plugin/sampling/strategystore/static/factory.go
index d2fb0a8d8a9..ce91c436558 100644
--- a/plugin/sampling/strategystore/static/factory.go
+++ b/plugin/sampling/strategystore/static/factory.go
@@ -53,7 +53,11 @@ func (f *Factory) InitFromViper(v *viper.Viper, logger *zap.Logger) {
}
// Initialize implements strategystore.Factory
-func (f *Factory) Initialize(_ metrics.Factory, _ storage.SamplingStoreFactory, logger *zap.Logger) error {
+func (f *Factory) Initialize(
+ _ metrics.Factory,
+ _ storage.SamplingStoreFactory,
+ logger *zap.Logger,
+) error {
f.logger = logger
return nil
}
diff --git a/plugin/sampling/strategystore/static/factory_test.go b/plugin/sampling/strategystore/static/factory_test.go
index 11b169c4818..1a9e772516e 100644
--- a/plugin/sampling/strategystore/static/factory_test.go
+++ b/plugin/sampling/strategystore/static/factory_test.go
@@ -34,7 +34,9 @@ var (
func TestFactory(t *testing.T) {
f := NewFactory()
v, command := config.Viperize(f.AddFlags)
- command.ParseFlags([]string{"--sampling.strategies-file=fixtures/strategies.json"})
+ command.ParseFlags(
+ []string{"--sampling.strategies-file=fixtures/strategies.json"},
+ )
f.InitFromViper(v, zap.NewNop())
require.NoError(t, f.Initialize(metrics.NullFactory, nil, zap.NewNop()))
diff --git a/plugin/sampling/strategystore/static/options.go b/plugin/sampling/strategystore/static/options.go
index 73c8bb801b7..7bbde2d9e3f 100644
--- a/plugin/sampling/strategystore/static/options.go
+++ b/plugin/sampling/strategystore/static/options.go
@@ -42,9 +42,21 @@ type Options struct {
// AddFlags adds flags for Options
func AddFlags(flagSet *flag.FlagSet) {
- flagSet.Duration(samplingStrategiesReloadInterval, 0, "Reload interval to check and reload sampling strategies file. Zero value means no reloading")
- flagSet.String(samplingStrategiesFile, "", "The path for the sampling strategies file in JSON format. See sampling documentation to see format of the file")
- flagSet.Bool(samplingStrategiesBugfix5270, false, "Include default operation level strategies for Ratesampling type service level strategy. Cf. https://github.com/jaegertracing/jaeger/issues/5270")
+ flagSet.Duration(
+ samplingStrategiesReloadInterval,
+ 0,
+ "Reload interval to check and reload sampling strategies file. Zero value means no reloading",
+ )
+ flagSet.String(
+ samplingStrategiesFile,
+ "",
+ "The path for the sampling strategies file in JSON format. See sampling documentation to see format of the file",
+ )
+ flagSet.Bool(
+ samplingStrategiesBugfix5270,
+ false,
+ "Include default operation level strategies for Ratesampling type service level strategy. Cf. https://github.com/jaegertracing/jaeger/issues/5270",
+ )
}
// InitFromViper initializes Options with properties from viper
diff --git a/plugin/sampling/strategystore/static/strategy_store.go b/plugin/sampling/strategystore/static/strategy_store.go
index 05debf2d720..8fd3886a345 100644
--- a/plugin/sampling/strategystore/static/strategy_store.go
+++ b/plugin/sampling/strategystore/static/strategy_store.go
@@ -55,7 +55,10 @@ type storedStrategies struct {
type strategyLoader func() ([]byte, error)
// NewStrategyStore creates a strategy store that holds static sampling strategies.
-func NewStrategyStore(options Options, logger *zap.Logger) (ss.StrategyStore, error) {
+func NewStrategyStore(
+ options Options,
+ logger *zap.Logger,
+) (ss.StrategyStore, error) {
ctx, cancelFunc := context.WithCancel(context.Background())
h := &strategyStore{
logger: logger,
@@ -79,9 +82,11 @@ func NewStrategyStore(options Options, logger *zap.Logger) (ss.StrategyStore, er
}
if !h.options.IncludeDefaultOpStrategies {
- h.logger.Warn("Default operations level strategies will not be included for Ratelimiting service strategies." +
- "This behavior will be changed in future releases. " +
- "Cf. https://github.com/jaegertracing/jaeger/issues/5270")
+ h.logger.Warn(
+ "Default operations level strategies will not be included for Ratelimiting service strategies." +
+ "This behavior will be changed in future releases. " +
+ "Cf. https://github.com/jaegertracing/jaeger/issues/5270",
+ )
h.parseStrategies_deprecated(strategies)
} else {
h.parseStrategies(strategies)
@@ -94,13 +99,19 @@ func NewStrategyStore(options Options, logger *zap.Logger) (ss.StrategyStore, er
}
// GetSamplingStrategy implements StrategyStore#GetSamplingStrategy.
-func (h *strategyStore) GetSamplingStrategy(_ context.Context, serviceName string) (*api_v2.SamplingStrategyResponse, error) {
+func (h *strategyStore) GetSamplingStrategy(
+ _ context.Context,
+ serviceName string,
+) (*api_v2.SamplingStrategyResponse, error) {
ss := h.storedStrategies.Load().(*storedStrategies)
serviceStrategies := ss.serviceStrategies
if strategy, ok := serviceStrategies[serviceName]; ok {
return strategy, nil
}
- h.logger.Debug("sampling strategy not found, using default", zap.String("service", serviceName))
+ h.logger.Debug(
+ "sampling strategy not found, using default",
+ zap.String("service", serviceName),
+ )
return ss.defaultStrategy, nil
}
@@ -121,13 +132,19 @@ func (h *strategyStore) downloadSamplingStrategies(url string) ([]byte, error) {
}
resp, err := http.DefaultClient.Do(req)
if err != nil {
- return nil, fmt.Errorf("failed to download sampling strategies: %w", err)
+ return nil, fmt.Errorf(
+ "failed to download sampling strategies: %w",
+ err,
+ )
}
defer resp.Body.Close()
buf := new(bytes.Buffer)
if _, err = buf.ReadFrom(resp.Body); err != nil {
- return nil, fmt.Errorf("failed to read sampling strategies HTTP response body: %w", err)
+ return nil, fmt.Errorf(
+ "failed to read sampling strategies HTTP response body: %w",
+ err,
+ )
}
if resp.StatusCode == http.StatusServiceUnavailable {
@@ -149,7 +166,9 @@ func isURL(str string) bool {
return err == nil && u.Scheme != "" && u.Host != ""
}
-func (h *strategyStore) samplingStrategyLoader(strategiesFile string) strategyLoader {
+func (h *strategyStore) samplingStrategyLoader(
+ strategiesFile string,
+) strategyLoader {
if isURL(strategiesFile) {
return func() ([]byte, error) {
return h.downloadSamplingStrategies(strategiesFile)
@@ -157,16 +176,27 @@ func (h *strategyStore) samplingStrategyLoader(strategiesFile string) strategyLo
}
return func() ([]byte, error) {
- h.logger.Info("Loading sampling strategies", zap.String("filename", strategiesFile))
+ h.logger.Info(
+ "Loading sampling strategies",
+ zap.String("filename", strategiesFile),
+ )
currBytes, err := os.ReadFile(filepath.Clean(strategiesFile))
if err != nil {
- return nil, fmt.Errorf("failed to read strategies file %s: %w", strategiesFile, err)
+ return nil, fmt.Errorf(
+ "failed to read strategies file %s: %w",
+ strategiesFile,
+ err,
+ )
}
return currBytes, nil
}
}
-func (h *strategyStore) autoUpdateStrategies(ctx context.Context, interval time.Duration, loader strategyLoader) {
+func (h *strategyStore) autoUpdateStrategies(
+ ctx context.Context,
+ interval time.Duration,
+ loader strategyLoader,
+) {
lastValue := string(nullJSON)
ticker := time.NewTicker(interval)
defer ticker.Stop()
@@ -180,7 +210,10 @@ func (h *strategyStore) autoUpdateStrategies(ctx context.Context, interval time.
}
}
-func (h *strategyStore) reloadSamplingStrategy(loadFn strategyLoader, lastValue string) string {
+func (h *strategyStore) reloadSamplingStrategy(
+ loadFn strategyLoader,
+ lastValue string,
+) string {
newValue, err := loadFn()
if err != nil {
h.logger.Error("failed to re-load sampling strategies", zap.Error(err))
@@ -223,7 +256,9 @@ func loadStrategies(loadFn strategyLoader) (*strategies, error) {
func (h *strategyStore) parseStrategies_deprecated(strategies *strategies) {
newStore := defaultStrategies()
if strategies.DefaultStrategy != nil {
- newStore.defaultStrategy = h.parseServiceStrategies(strategies.DefaultStrategy)
+ newStore.defaultStrategy = h.parseServiceStrategies(
+ strategies.DefaultStrategy,
+ )
}
merge := true
@@ -253,7 +288,8 @@ func (h *strategyStore) parseStrategies_deprecated(strategies *strategies) {
if merge {
opS.PerOperationStrategies = mergePerOperationSamplingStrategies(
opS.PerOperationStrategies,
- newStore.defaultStrategy.OperationSampling.PerOperationStrategies)
+ newStore.defaultStrategy.OperationSampling.PerOperationStrategies,
+ )
}
}
h.storedStrategies.Store(newStore)
@@ -262,7 +298,9 @@ func (h *strategyStore) parseStrategies_deprecated(strategies *strategies) {
func (h *strategyStore) parseStrategies(strategies *strategies) {
newStore := defaultStrategies()
if strategies.DefaultStrategy != nil {
- newStore.defaultStrategy = h.parseServiceStrategies(strategies.DefaultStrategy)
+ newStore.defaultStrategy = h.parseServiceStrategies(
+ strategies.DefaultStrategy,
+ )
}
for _, s := range strategies.ServiceStrategies {
@@ -314,7 +352,9 @@ func mergePerOperationSamplingStrategies(
return a
}
-func (h *strategyStore) parseServiceStrategies(strategy *serviceStrategy) *api_v2.SamplingStrategyResponse {
+func (h *strategyStore) parseServiceStrategies(
+ strategy *serviceStrategy,
+) *api_v2.SamplingStrategyResponse {
resp := h.parseStrategy(&strategy.strategy)
if len(strategy.OperationStrategies) == 0 {
return resp
@@ -352,14 +392,18 @@ func (h *strategyStore) parseOperationStrategy(
fmt.Sprintf(
"Operation strategies only supports probabilistic sampling at the moment,"+
"'%s' defaulting to probabilistic sampling with probability %f",
- strategy.Operation, parent.DefaultSamplingProbability),
+ strategy.Operation,
+ parent.DefaultSamplingProbability,
+ ),
zap.Any("strategy", strategy))
return nil, false
}
return s, true
}
-func (h *strategyStore) parseStrategy(strategy *strategy) *api_v2.SamplingStrategyResponse {
+func (h *strategyStore) parseStrategy(
+ strategy *strategy,
+) *api_v2.SamplingStrategyResponse {
switch strategy.Type {
case samplerTypeProbabilistic:
return &api_v2.SamplingStrategyResponse{
@@ -376,12 +420,17 @@ func (h *strategyStore) parseStrategy(strategy *strategy) *api_v2.SamplingStrate
},
}
default:
- h.logger.Warn("Failed to parse sampling strategy", zap.Any("strategy", strategy))
+ h.logger.Warn(
+ "Failed to parse sampling strategy",
+ zap.Any("strategy", strategy),
+ )
return defaultStrategyResponse()
}
}
-func deepCopy(s *api_v2.SamplingStrategyResponse) *api_v2.SamplingStrategyResponse {
+func deepCopy(
+ s *api_v2.SamplingStrategyResponse,
+) *api_v2.SamplingStrategyResponse {
var buf bytes.Buffer
enc := gob.NewEncoder(&buf)
dec := gob.NewDecoder(&buf)
diff --git a/plugin/sampling/strategystore/static/strategy_store_test.go b/plugin/sampling/strategystore/static/strategy_store_test.go
index f499baa5a7e..69da9c2fdf4 100644
--- a/plugin/sampling/strategystore/static/strategy_store_test.go
+++ b/plugin/sampling/strategystore/static/strategy_store_test.go
@@ -73,7 +73,9 @@ func strategiesJSON(probability float32) string {
// Returns strategies in JSON format. Used for testing
// URL option for sampling strategies.
-func mockStrategyServer(t *testing.T) (*httptest.Server, *atomic.Pointer[string]) {
+func mockStrategyServer(
+ t *testing.T,
+) (*httptest.Server, *atomic.Pointer[string]) {
var strategy atomic.Pointer[string]
value := strategiesJSON(0.8)
strategy.Store(&value)
@@ -105,60 +107,118 @@ func mockStrategyServer(t *testing.T) (*httptest.Server, *atomic.Pointer[string]
}
func TestStrategyStoreWithFile(t *testing.T) {
- _, err := NewStrategyStore(Options{StrategiesFile: "fileNotFound.json"}, zap.NewNop())
- assert.Contains(t, err.Error(), "failed to read strategies file fileNotFound.json")
+ _, err := NewStrategyStore(
+ Options{StrategiesFile: "fileNotFound.json"},
+ zap.NewNop(),
+ )
+ assert.Contains(
+ t,
+ err.Error(),
+ "failed to read strategies file fileNotFound.json",
+ )
- _, err = NewStrategyStore(Options{StrategiesFile: "fixtures/bad_strategies.json"}, zap.NewNop())
- require.EqualError(t, err,
- "failed to unmarshal strategies: json: cannot unmarshal string into Go value of type static.strategies")
+ _, err = NewStrategyStore(
+ Options{StrategiesFile: "fixtures/bad_strategies.json"},
+ zap.NewNop(),
+ )
+ require.EqualError(
+ t,
+ err,
+ "failed to unmarshal strategies: json: cannot unmarshal string into Go value of type static.strategies",
+ )
// Test default strategy
logger, buf := testutils.NewLogger()
store, err := NewStrategyStore(Options{}, logger)
require.NoError(t, err)
- assert.Contains(t, buf.String(), "No sampling strategies source provided, using defaults")
+ assert.Contains(
+ t,
+ buf.String(),
+ "No sampling strategies source provided, using defaults",
+ )
s, err := store.GetSamplingStrategy(context.Background(), "foo")
require.NoError(t, err)
- assert.EqualValues(t, makeResponse(api_v2.SamplingStrategyType_PROBABILISTIC, 0.001), *s)
+ assert.EqualValues(
+ t,
+ makeResponse(api_v2.SamplingStrategyType_PROBABILISTIC, 0.001),
+ *s,
+ )
// Test reading strategies from a file
- store, err = NewStrategyStore(Options{StrategiesFile: "fixtures/strategies.json"}, logger)
+ store, err = NewStrategyStore(
+ Options{StrategiesFile: "fixtures/strategies.json"},
+ logger,
+ )
require.NoError(t, err)
s, err = store.GetSamplingStrategy(context.Background(), "foo")
require.NoError(t, err)
- assert.EqualValues(t, makeResponse(api_v2.SamplingStrategyType_PROBABILISTIC, 0.8), *s)
+ assert.EqualValues(
+ t,
+ makeResponse(api_v2.SamplingStrategyType_PROBABILISTIC, 0.8),
+ *s,
+ )
s, err = store.GetSamplingStrategy(context.Background(), "bar")
require.NoError(t, err)
- assert.EqualValues(t, makeResponse(api_v2.SamplingStrategyType_RATE_LIMITING, 5), *s)
+ assert.EqualValues(
+ t,
+ makeResponse(api_v2.SamplingStrategyType_RATE_LIMITING, 5),
+ *s,
+ )
s, err = store.GetSamplingStrategy(context.Background(), "default")
require.NoError(t, err)
- assert.EqualValues(t, makeResponse(api_v2.SamplingStrategyType_PROBABILISTIC, 0.5), *s)
+ assert.EqualValues(
+ t,
+ makeResponse(api_v2.SamplingStrategyType_PROBABILISTIC, 0.5),
+ *s,
+ )
}
func TestStrategyStoreWithURL(t *testing.T) {
// Test default strategy when URL is temporarily unavailable.
logger, buf := testutils.NewLogger()
mockServer, _ := mockStrategyServer(t)
- store, err := NewStrategyStore(Options{StrategiesFile: mockServer.URL + "/service-unavailable"}, logger)
+ store, err := NewStrategyStore(
+ Options{StrategiesFile: mockServer.URL + "/service-unavailable"},
+ logger,
+ )
require.NoError(t, err)
- assert.Contains(t, buf.String(), "No sampling strategies found or URL is unavailable, using defaults")
+ assert.Contains(
+ t,
+ buf.String(),
+ "No sampling strategies found or URL is unavailable, using defaults",
+ )
s, err := store.GetSamplingStrategy(context.Background(), "foo")
require.NoError(t, err)
- assert.EqualValues(t, makeResponse(api_v2.SamplingStrategyType_PROBABILISTIC, 0.001), *s)
+ assert.EqualValues(
+ t,
+ makeResponse(api_v2.SamplingStrategyType_PROBABILISTIC, 0.001),
+ *s,
+ )
// Test downloading strategies from a URL.
- store, err = NewStrategyStore(Options{StrategiesFile: mockServer.URL}, logger)
+ store, err = NewStrategyStore(
+ Options{StrategiesFile: mockServer.URL},
+ logger,
+ )
require.NoError(t, err)
s, err = store.GetSamplingStrategy(context.Background(), "foo")
require.NoError(t, err)
- assert.EqualValues(t, makeResponse(api_v2.SamplingStrategyType_PROBABILISTIC, 0.8), *s)
+ assert.EqualValues(
+ t,
+ makeResponse(api_v2.SamplingStrategyType_PROBABILISTIC, 0.8),
+ *s,
+ )
s, err = store.GetSamplingStrategy(context.Background(), "bar")
require.NoError(t, err)
- assert.EqualValues(t, makeResponse(api_v2.SamplingStrategyType_RATE_LIMITING, 5), *s)
+ assert.EqualValues(
+ t,
+ makeResponse(api_v2.SamplingStrategyType_RATE_LIMITING, 5),
+ *s,
+ )
}
func TestPerOperationSamplingStrategies(t *testing.T) {
@@ -175,18 +235,34 @@ func TestPerOperationSamplingStrategies(t *testing.T) {
for _, tc := range tests {
logger, buf := testutils.NewLogger()
store, err := NewStrategyStore(tc.options, logger)
- assert.Contains(t, buf.String(), "Operation strategies only supports probabilistic sampling at the moment,"+
- "'op2' defaulting to probabilistic sampling with probability 0.8")
- assert.Contains(t, buf.String(), "Operation strategies only supports probabilistic sampling at the moment,"+
- "'op4' defaulting to probabilistic sampling with probability 0.001")
+ assert.Contains(
+ t,
+ buf.String(),
+ "Operation strategies only supports probabilistic sampling at the moment,"+
+ "'op2' defaulting to probabilistic sampling with probability 0.8",
+ )
+ assert.Contains(
+ t,
+ buf.String(),
+ "Operation strategies only supports probabilistic sampling at the moment,"+
+ "'op4' defaulting to probabilistic sampling with probability 0.001",
+ )
require.NoError(t, err)
expected := makeResponse(api_v2.SamplingStrategyType_PROBABILISTIC, 0.8)
s, err := store.GetSamplingStrategy(context.Background(), "foo")
require.NoError(t, err)
- assert.Equal(t, api_v2.SamplingStrategyType_PROBABILISTIC, s.StrategyType)
- assert.Equal(t, *expected.ProbabilisticSampling, *s.ProbabilisticSampling)
+ assert.Equal(
+ t,
+ api_v2.SamplingStrategyType_PROBABILISTIC,
+ s.StrategyType,
+ )
+ assert.Equal(
+ t,
+ *expected.ProbabilisticSampling,
+ *s.ProbabilisticSampling,
+ )
require.NotNil(t, s.OperationSampling)
os := s.OperationSampling
@@ -194,19 +270,39 @@ func TestPerOperationSamplingStrategies(t *testing.T) {
require.Len(t, os.PerOperationStrategies, 4)
assert.Equal(t, "op6", os.PerOperationStrategies[0].Operation)
- assert.EqualValues(t, 0.5, os.PerOperationStrategies[0].ProbabilisticSampling.SamplingRate)
+ assert.EqualValues(
+ t,
+ 0.5,
+ os.PerOperationStrategies[0].ProbabilisticSampling.SamplingRate,
+ )
assert.Equal(t, "op1", os.PerOperationStrategies[1].Operation)
- assert.EqualValues(t, 0.2, os.PerOperationStrategies[1].ProbabilisticSampling.SamplingRate)
+ assert.EqualValues(
+ t,
+ 0.2,
+ os.PerOperationStrategies[1].ProbabilisticSampling.SamplingRate,
+ )
assert.Equal(t, "op0", os.PerOperationStrategies[2].Operation)
- assert.EqualValues(t, 0.2, os.PerOperationStrategies[2].ProbabilisticSampling.SamplingRate)
+ assert.EqualValues(
+ t,
+ 0.2,
+ os.PerOperationStrategies[2].ProbabilisticSampling.SamplingRate,
+ )
assert.Equal(t, "op7", os.PerOperationStrategies[3].Operation)
- assert.EqualValues(t, 1, os.PerOperationStrategies[3].ProbabilisticSampling.SamplingRate)
+ assert.EqualValues(
+ t,
+ 1,
+ os.PerOperationStrategies[3].ProbabilisticSampling.SamplingRate,
+ )
expected = makeResponse(api_v2.SamplingStrategyType_RATE_LIMITING, 5)
s, err = store.GetSamplingStrategy(context.Background(), "bar")
require.NoError(t, err)
- assert.Equal(t, api_v2.SamplingStrategyType_RATE_LIMITING, s.StrategyType)
+ assert.Equal(
+ t,
+ api_v2.SamplingStrategyType_RATE_LIMITING,
+ s.StrategyType,
+ )
assert.Equal(t, *expected.RateLimitingSampling, *s.RateLimitingSampling)
require.NotNil(t, s.OperationSampling)
@@ -214,19 +310,42 @@ func TestPerOperationSamplingStrategies(t *testing.T) {
assert.EqualValues(t, 0.001, os.DefaultSamplingProbability)
require.Len(t, os.PerOperationStrategies, 5)
assert.Equal(t, "op3", os.PerOperationStrategies[0].Operation)
- assert.EqualValues(t, 0.3, os.PerOperationStrategies[0].ProbabilisticSampling.SamplingRate)
+ assert.EqualValues(
+ t,
+ 0.3,
+ os.PerOperationStrategies[0].ProbabilisticSampling.SamplingRate,
+ )
assert.Equal(t, "op5", os.PerOperationStrategies[1].Operation)
- assert.EqualValues(t, 0.4, os.PerOperationStrategies[1].ProbabilisticSampling.SamplingRate)
+ assert.EqualValues(
+ t,
+ 0.4,
+ os.PerOperationStrategies[1].ProbabilisticSampling.SamplingRate,
+ )
assert.Equal(t, "op0", os.PerOperationStrategies[2].Operation)
- assert.EqualValues(t, 0.2, os.PerOperationStrategies[2].ProbabilisticSampling.SamplingRate)
+ assert.EqualValues(
+ t,
+ 0.2,
+ os.PerOperationStrategies[2].ProbabilisticSampling.SamplingRate,
+ )
assert.Equal(t, "op6", os.PerOperationStrategies[3].Operation)
- assert.EqualValues(t, 0, os.PerOperationStrategies[3].ProbabilisticSampling.SamplingRate)
+ assert.EqualValues(
+ t,
+ 0,
+ os.PerOperationStrategies[3].ProbabilisticSampling.SamplingRate,
+ )
assert.Equal(t, "op7", os.PerOperationStrategies[4].Operation)
- assert.EqualValues(t, 1, os.PerOperationStrategies[4].ProbabilisticSampling.SamplingRate)
+ assert.EqualValues(
+ t,
+ 1,
+ os.PerOperationStrategies[4].ProbabilisticSampling.SamplingRate,
+ )
s, err = store.GetSamplingStrategy(context.Background(), "default")
require.NoError(t, err)
- expectedRsp := makeResponse(api_v2.SamplingStrategyType_PROBABILISTIC, 0.5)
+ expectedRsp := makeResponse(
+ api_v2.SamplingStrategyType_PROBABILISTIC,
+ 0.5,
+ )
expectedRsp.OperationSampling = &api_v2.PerOperationSamplingStrategies{
DefaultSamplingProbability: 0.5,
PerOperationStrategies: []*api_v2.OperationSamplingStrategy{
@@ -256,11 +375,17 @@ func TestPerOperationSamplingStrategies(t *testing.T) {
func TestMissingServiceSamplingStrategyTypes(t *testing.T) {
logger, buf := testutils.NewLogger()
- store, err := NewStrategyStore(Options{StrategiesFile: "fixtures/missing-service-types.json"}, logger)
+ store, err := NewStrategyStore(
+ Options{StrategiesFile: "fixtures/missing-service-types.json"},
+ logger,
+ )
assert.Contains(t, buf.String(), "Failed to parse sampling strategy")
require.NoError(t, err)
- expected := makeResponse(api_v2.SamplingStrategyType_PROBABILISTIC, defaultSamplingProbability)
+ expected := makeResponse(
+ api_v2.SamplingStrategyType_PROBABILISTIC,
+ defaultSamplingProbability,
+ )
s, err := store.GetSamplingStrategy(context.Background(), "foo")
require.NoError(t, err)
@@ -269,12 +394,23 @@ func TestMissingServiceSamplingStrategyTypes(t *testing.T) {
require.NotNil(t, s.OperationSampling)
os := s.OperationSampling
- assert.EqualValues(t, defaultSamplingProbability, os.DefaultSamplingProbability)
+ assert.EqualValues(
+ t,
+ defaultSamplingProbability,
+ os.DefaultSamplingProbability,
+ )
require.Len(t, os.PerOperationStrategies, 1)
assert.Equal(t, "op1", os.PerOperationStrategies[0].Operation)
- assert.EqualValues(t, 0.2, os.PerOperationStrategies[0].ProbabilisticSampling.SamplingRate)
+ assert.EqualValues(
+ t,
+ 0.2,
+ os.PerOperationStrategies[0].ProbabilisticSampling.SamplingRate,
+ )
- expected = makeResponse(api_v2.SamplingStrategyType_PROBABILISTIC, defaultSamplingProbability)
+ expected = makeResponse(
+ api_v2.SamplingStrategyType_PROBABILISTIC,
+ defaultSamplingProbability,
+ )
s, err = store.GetSamplingStrategy(context.Background(), "bar")
require.NoError(t, err)
@@ -286,13 +422,25 @@ func TestMissingServiceSamplingStrategyTypes(t *testing.T) {
assert.EqualValues(t, 0.001, os.DefaultSamplingProbability)
require.Len(t, os.PerOperationStrategies, 2)
assert.Equal(t, "op3", os.PerOperationStrategies[0].Operation)
- assert.EqualValues(t, 0.3, os.PerOperationStrategies[0].ProbabilisticSampling.SamplingRate)
+ assert.EqualValues(
+ t,
+ 0.3,
+ os.PerOperationStrategies[0].ProbabilisticSampling.SamplingRate,
+ )
assert.Equal(t, "op5", os.PerOperationStrategies[1].Operation)
- assert.EqualValues(t, 0.4, os.PerOperationStrategies[1].ProbabilisticSampling.SamplingRate)
+ assert.EqualValues(
+ t,
+ 0.4,
+ os.PerOperationStrategies[1].ProbabilisticSampling.SamplingRate,
+ )
s, err = store.GetSamplingStrategy(context.Background(), "default")
require.NoError(t, err)
- assert.EqualValues(t, makeResponse(api_v2.SamplingStrategyType_PROBABILISTIC, 0.5), *s)
+ assert.EqualValues(
+ t,
+ makeResponse(api_v2.SamplingStrategyType_PROBABILISTIC, 0.5),
+ *s,
+ )
}
func TestParseStrategy(t *testing.T) {
@@ -305,14 +453,20 @@ func TestParseStrategy(t *testing.T) {
Service: "svc",
strategy: strategy{Type: "probabilistic", Param: 0.2},
},
- expected: makeResponse(api_v2.SamplingStrategyType_PROBABILISTIC, 0.2),
+ expected: makeResponse(
+ api_v2.SamplingStrategyType_PROBABILISTIC,
+ 0.2,
+ ),
},
{
strategy: serviceStrategy{
Service: "svc",
strategy: strategy{Type: "ratelimiting", Param: 3.5},
},
- expected: makeResponse(api_v2.SamplingStrategyType_RATE_LIMITING, 3),
+ expected: makeResponse(
+ api_v2.SamplingStrategyType_RATE_LIMITING,
+ 3,
+ ),
},
}
logger, buf := testutils.NewLogger()
@@ -320,19 +474,29 @@ func TestParseStrategy(t *testing.T) {
for _, test := range tests {
tt := test
t.Run("", func(t *testing.T) {
- assert.EqualValues(t, tt.expected, *store.parseStrategy(&tt.strategy.strategy))
+ assert.EqualValues(
+ t,
+ tt.expected,
+ *store.parseStrategy(&tt.strategy.strategy),
+ )
})
}
assert.Empty(t, buf.String())
// Test nonexistent strategy type
actual := *store.parseStrategy(&strategy{Type: "blah", Param: 3.5})
- expected := makeResponse(api_v2.SamplingStrategyType_PROBABILISTIC, defaultSamplingProbability)
+ expected := makeResponse(
+ api_v2.SamplingStrategyType_PROBABILISTIC,
+ defaultSamplingProbability,
+ )
assert.EqualValues(t, expected, actual)
assert.Contains(t, buf.String(), "Failed to parse sampling strategy")
}
-func makeResponse(samplerType api_v2.SamplingStrategyType, param float64) (resp api_v2.SamplingStrategyResponse) {
+func makeResponse(
+ samplerType api_v2.SamplingStrategyType,
+ param float64,
+) (resp api_v2.SamplingStrategyResponse) {
resp.StrategyType = samplerType
if samplerType == api_v2.SamplingStrategyType_PROBABILISTIC {
resp.ProbabilisticSampling = &api_v2.ProbabilisticSamplingStrategy{
@@ -382,10 +546,17 @@ func TestAutoUpdateStrategyWithFile(t *testing.T) {
// confirm baseline value
s, err := store.GetSamplingStrategy(context.Background(), "foo")
require.NoError(t, err)
- assert.EqualValues(t, makeResponse(api_v2.SamplingStrategyType_PROBABILISTIC, 0.8), *s)
+ assert.EqualValues(
+ t,
+ makeResponse(api_v2.SamplingStrategyType_PROBABILISTIC, 0.8),
+ *s,
+ )
// verify that reloading is a no-op
- value := store.reloadSamplingStrategy(store.samplingStrategyLoader(dstFile), string(srcBytes))
+ value := store.reloadSamplingStrategy(
+ store.samplingStrategyLoader(dstFile),
+ string(srcBytes),
+ )
assert.Equal(t, string(srcBytes), value)
// update file with new probability of 0.9
@@ -396,12 +567,17 @@ func TestAutoUpdateStrategyWithFile(t *testing.T) {
for i := 0; i < 1000; i++ { // wait up to 1sec
s, err = store.GetSamplingStrategy(context.Background(), "foo")
require.NoError(t, err)
- if s.ProbabilisticSampling != nil && s.ProbabilisticSampling.SamplingRate == 0.9 {
+ if s.ProbabilisticSampling != nil &&
+ s.ProbabilisticSampling.SamplingRate == 0.9 {
break
}
time.Sleep(1 * time.Millisecond)
}
- assert.EqualValues(t, makeResponse(api_v2.SamplingStrategyType_PROBABILISTIC, 0.9), *s)
+ assert.EqualValues(
+ t,
+ makeResponse(api_v2.SamplingStrategyType_PROBABILISTIC, 0.9),
+ *s,
+ )
}
func TestAutoUpdateStrategyWithURL(t *testing.T) {
@@ -417,7 +593,11 @@ func TestAutoUpdateStrategyWithURL(t *testing.T) {
// confirm baseline value
s, err := store.GetSamplingStrategy(context.Background(), "foo")
require.NoError(t, err)
- assert.EqualValues(t, makeResponse(api_v2.SamplingStrategyType_PROBABILISTIC, 0.8), *s)
+ assert.EqualValues(
+ t,
+ makeResponse(api_v2.SamplingStrategyType_PROBABILISTIC, 0.8),
+ *s,
+ )
// verify that reloading in no-op
value := store.reloadSamplingStrategy(
@@ -436,12 +616,17 @@ func TestAutoUpdateStrategyWithURL(t *testing.T) {
for i := 0; i < 1000; i++ { // wait up to 1sec
s, err = store.GetSamplingStrategy(context.Background(), "foo")
require.NoError(t, err)
- if s.ProbabilisticSampling != nil && s.ProbabilisticSampling.SamplingRate == 0.9 {
+ if s.ProbabilisticSampling != nil &&
+ s.ProbabilisticSampling.SamplingRate == 0.9 {
break
}
time.Sleep(1 * time.Millisecond)
}
- assert.EqualValues(t, makeResponse(api_v2.SamplingStrategyType_PROBABILISTIC, 0.9), *s)
+ assert.EqualValues(
+ t,
+ makeResponse(api_v2.SamplingStrategyType_PROBABILISTIC, 0.9),
+ *s,
+ )
}
func TestAutoUpdateStrategyErrors(t *testing.T) {
@@ -463,25 +648,62 @@ func TestAutoUpdateStrategyErrors(t *testing.T) {
defer store.Close()
// check invalid file path or read failure
- assert.Equal(t, "blah", store.reloadSamplingStrategy(store.samplingStrategyLoader(tempFile.Name()+"bad-path"), "blah"))
+ assert.Equal(
+ t,
+ "blah",
+ store.reloadSamplingStrategy(store.samplingStrategyLoader(tempFile.Name()+"bad-path"), "blah"),
+ )
assert.Len(t, logs.FilterMessage("failed to re-load sampling strategies").All(), 1)
// check bad file content
- require.NoError(t, os.WriteFile(tempFile.Name(), []byte("bad value"), 0o644))
- assert.Equal(t, "blah", store.reloadSamplingStrategy(store.samplingStrategyLoader(tempFile.Name()), "blah"))
- assert.Len(t, logs.FilterMessage("failed to update sampling strategies").All(), 1)
+ require.NoError(
+ t,
+ os.WriteFile(tempFile.Name(), []byte("bad value"), 0o644),
+ )
+ assert.Equal(
+ t,
+ "blah",
+ store.reloadSamplingStrategy(
+ store.samplingStrategyLoader(tempFile.Name()),
+ "blah",
+ ),
+ )
+ assert.Len(
+ t,
+ logs.FilterMessage("failed to update sampling strategies").All(),
+ 1,
+ )
// check invalid url
- assert.Equal(t, "duh", store.reloadSamplingStrategy(store.samplingStrategyLoader("bad-url"), "duh"))
- assert.Len(t, logs.FilterMessage("failed to re-load sampling strategies").All(), 2)
+ assert.Equal(
+ t,
+ "duh",
+ store.reloadSamplingStrategy(
+ store.samplingStrategyLoader("bad-url"),
+ "duh",
+ ),
+ )
+ assert.Len(
+ t,
+ logs.FilterMessage("failed to re-load sampling strategies").All(),
+ 2,
+ )
// check status code other than 200
mockServer, _ := mockStrategyServer(t)
- assert.Equal(t, "duh", store.reloadSamplingStrategy(store.samplingStrategyLoader(mockServer.URL+"/bad-status"), "duh"))
+ assert.Equal(
+ t,
+ "duh",
+ store.reloadSamplingStrategy(store.samplingStrategyLoader(mockServer.URL+"/bad-status"), "duh"),
+ )
assert.Len(t, logs.FilterMessage("failed to re-load sampling strategies").All(), 3)
// check bad content from url
- assert.Equal(t, "duh", store.reloadSamplingStrategy(store.samplingStrategyLoader(mockServer.URL+"/bad-content"), "duh"))
+ assert.Equal(
+ t,
+ "duh",
+ store.reloadSamplingStrategy(store.samplingStrategyLoader(mockServer.URL+"/bad-content"), "duh"),
+ )
assert.Len(t, logs.FilterMessage("failed to update sampling strategies").All(), 2)
}
@@ -496,7 +718,10 @@ func TestServiceNoPerOperationStrategies(t *testing.T) {
for _, service := range []string{"ServiceA", "ServiceB"} {
t.Run(service, func(t *testing.T) {
- strategy, err := store.GetSamplingStrategy(context.Background(), service)
+ strategy, err := store.GetSamplingStrategy(
+ context.Background(),
+ service,
+ )
require.NoError(t, err)
strategyJson, err := json.MarshalIndent(strategy, "", " ")
require.NoError(t, err)
@@ -506,8 +731,12 @@ func TestServiceNoPerOperationStrategies(t *testing.T) {
expectedServiceResponse, err := os.ReadFile(snapshotFile)
require.NoError(t, err)
- assert.Equal(t, string(expectedServiceResponse), string(strategyJson),
- "comparing against stored snapshot. Use REGENERATE_SNAPSHOTS=true to rebuild snapshots.")
+ assert.Equal(
+ t,
+ string(expectedServiceResponse),
+ string(strategyJson),
+ "comparing against stored snapshot. Use REGENERATE_SNAPSHOTS=true to rebuild snapshots.",
+ )
if regenerateSnapshots {
os.WriteFile(snapshotFile, strategyJson, 0o644)
@@ -528,7 +757,10 @@ func TestServiceNoPerOperationStrategiesDeprecatedBehavior(t *testing.T) {
for _, service := range []string{"ServiceA", "ServiceB"} {
t.Run(service, func(t *testing.T) {
- strategy, err := store.GetSamplingStrategy(context.Background(), service)
+ strategy, err := store.GetSamplingStrategy(
+ context.Background(),
+ service,
+ )
require.NoError(t, err)
strategyJson, err := json.MarshalIndent(strategy, "", " ")
require.NoError(t, err)
@@ -538,8 +770,12 @@ func TestServiceNoPerOperationStrategiesDeprecatedBehavior(t *testing.T) {
expectedServiceResponse, err := os.ReadFile(snapshotFile)
require.NoError(t, err)
- assert.Equal(t, string(expectedServiceResponse), string(strategyJson),
- "comparing against stored snapshot. Use REGENERATE_SNAPSHOTS=true to rebuild snapshots.")
+ assert.Equal(
+ t,
+ string(expectedServiceResponse),
+ string(strategyJson),
+ "comparing against stored snapshot. Use REGENERATE_SNAPSHOTS=true to rebuild snapshots.",
+ )
if regenerateSnapshots {
os.WriteFile(snapshotFile, strategyJson, 0o644)
@@ -559,7 +795,11 @@ func TestSamplingStrategyLoader(t *testing.T) {
mockServer, _ := mockStrategyServer(t)
loader = store.samplingStrategyLoader(mockServer.URL + "/bad-status")
_, err = loader()
- assert.Contains(t, err.Error(), "receiving 404 Not Found while downloading strategies file")
+ assert.Contains(
+ t,
+ err.Error(),
+ "receiving 404 Not Found while downloading strategies file",
+ )
// should download content from URL
loader = store.samplingStrategyLoader(mockServer.URL + "/bad-content")
diff --git a/plugin/storage/badger/dependencystore/storage.go b/plugin/storage/badger/dependencystore/storage.go
index 1cc57ebd1f9..cde1a0dbd43 100644
--- a/plugin/storage/badger/dependencystore/storage.go
+++ b/plugin/storage/badger/dependencystore/storage.go
@@ -35,7 +35,11 @@ func NewDependencyStore(store spanstore.Reader) *DependencyStore {
}
// GetDependencies returns all interservice dependencies, implements DependencyReader
-func (s *DependencyStore) GetDependencies(ctx context.Context, endTs time.Time, lookback time.Duration) ([]model.DependencyLink, error) {
+func (s *DependencyStore) GetDependencies(
+ ctx context.Context,
+ endTs time.Time,
+ lookback time.Duration,
+) ([]model.DependencyLink, error) {
deps := map[string]*model.DependencyLink{}
params := &spanstore.TraceQueryParameters{
@@ -59,7 +63,9 @@ func (s *DependencyStore) GetDependencies(ctx context.Context, endTs time.Time,
}
// depMapToSlice modifies the spans to DependencyLink in the same way as the memory storage plugin
-func depMapToSlice(deps map[string]*model.DependencyLink) []model.DependencyLink {
+func depMapToSlice(
+ deps map[string]*model.DependencyLink,
+) []model.DependencyLink {
retMe := make([]model.DependencyLink, 0, len(deps))
for _, dep := range deps {
retMe = append(retMe, *dep)
diff --git a/plugin/storage/badger/dependencystore/storage_test.go b/plugin/storage/badger/dependencystore/storage_test.go
index 653d6edef6a..4b9be2b436b 100644
--- a/plugin/storage/badger/dependencystore/storage_test.go
+++ b/plugin/storage/badger/dependencystore/storage_test.go
@@ -33,7 +33,10 @@ import (
)
// Opens a badger db and runs a test on it.
-func runFactoryTest(tb testing.TB, test func(tb testing.TB, sw spanstore.Writer, dr dependencystore.Reader)) {
+func runFactoryTest(
+ tb testing.TB,
+ test func(tb testing.TB, sw spanstore.Writer, dr dependencystore.Reader),
+) {
f := badger.NewFactory()
defer func() {
require.NoError(tb, f.Close())
@@ -60,40 +63,61 @@ func runFactoryTest(tb testing.TB, test func(tb testing.TB, sw spanstore.Writer,
}
func TestDependencyReader(t *testing.T) {
- runFactoryTest(t, func(tb testing.TB, sw spanstore.Writer, dr dependencystore.Reader) {
- tid := time.Now()
- links, err := dr.GetDependencies(context.Background(), tid, time.Hour)
- require.NoError(t, err)
- assert.Empty(t, links)
+ runFactoryTest(
+ t,
+ func(tb testing.TB, sw spanstore.Writer, dr dependencystore.Reader) {
+ tid := time.Now()
+ links, err := dr.GetDependencies(
+ context.Background(),
+ tid,
+ time.Hour,
+ )
+ require.NoError(t, err)
+ assert.Empty(t, links)
- traces := 40
- spans := 3
- for i := 0; i < traces; i++ {
- for j := 0; j < spans; j++ {
- s := model.Span{
- TraceID: model.TraceID{
- Low: uint64(i),
- High: 1,
- },
- SpanID: model.SpanID(j),
- OperationName: "operation-a",
- Process: &model.Process{
- ServiceName: fmt.Sprintf("service-%d", j),
- },
- StartTime: tid.Add(time.Duration(i)),
- Duration: time.Duration(i + j),
+ traces := 40
+ spans := 3
+ for i := 0; i < traces; i++ {
+ for j := 0; j < spans; j++ {
+ s := model.Span{
+ TraceID: model.TraceID{
+ Low: uint64(i),
+ High: 1,
+ },
+ SpanID: model.SpanID(j),
+ OperationName: "operation-a",
+ Process: &model.Process{
+ ServiceName: fmt.Sprintf("service-%d", j),
+ },
+ StartTime: tid.Add(time.Duration(i)),
+ Duration: time.Duration(i + j),
+ }
+ if j > 0 {
+ s.References = []model.SpanRef{
+ model.NewChildOfRef(s.TraceID, model.SpanID(j-1)),
+ }
+ }
+ err := sw.WriteSpan(context.Background(), &s)
+ require.NoError(t, err)
}
- if j > 0 {
- s.References = []model.SpanRef{model.NewChildOfRef(s.TraceID, model.SpanID(j-1))}
- }
- err := sw.WriteSpan(context.Background(), &s)
- require.NoError(t, err)
}
- }
- links, err = dr.GetDependencies(context.Background(), time.Now(), time.Hour)
- require.NoError(t, err)
- assert.NotEmpty(t, links)
- assert.Len(t, links, spans-1) // First span does not create a dependency
- assert.Equal(t, uint64(traces), links[0].CallCount) // Each trace calls the same services
- })
+ links, err = dr.GetDependencies(
+ context.Background(),
+ time.Now(),
+ time.Hour,
+ )
+ require.NoError(t, err)
+ assert.NotEmpty(t, links)
+ assert.Len(
+ t,
+ links,
+ spans-1,
+ ) // First span does not create a dependency
+ assert.Equal(
+ t,
+ uint64(traces),
+ links[0].CallCount,
+ ) // Each trace calls the same services
+ },
+ )
}
diff --git a/plugin/storage/badger/factory.go b/plugin/storage/badger/factory.go
index 5e223625efa..22eadcca57b 100644
--- a/plugin/storage/badger/factory.go
+++ b/plugin/storage/badger/factory.go
@@ -124,7 +124,10 @@ func (f *Factory) configureFromOptions(opts *Options) {
}
// Initialize implements storage.Factory
-func (f *Factory) Initialize(metricsFactory metrics.Factory, logger *zap.Logger) error {
+func (f *Factory) Initialize(
+ metricsFactory metrics.Factory,
+ logger *zap.Logger,
+) error {
f.logger = logger
opts := badger.DefaultOptions("")
@@ -158,12 +161,24 @@ func (f *Factory) Initialize(metricsFactory metrics.Factory, logger *zap.Logger)
}
f.store = store
- f.cache = badgerStore.NewCacheStore(f.store, f.Options.Primary.SpanStoreTTL, true)
-
- f.metrics.ValueLogSpaceAvailable = metricsFactory.Gauge(metrics.Options{Name: valueLogSpaceAvailableName})
- f.metrics.KeyLogSpaceAvailable = metricsFactory.Gauge(metrics.Options{Name: keyLogSpaceAvailableName})
- f.metrics.LastMaintenanceRun = metricsFactory.Gauge(metrics.Options{Name: lastMaintenanceRunName})
- f.metrics.LastValueLogCleaned = metricsFactory.Gauge(metrics.Options{Name: lastValueLogCleanedName})
+ f.cache = badgerStore.NewCacheStore(
+ f.store,
+ f.Options.Primary.SpanStoreTTL,
+ true,
+ )
+
+ f.metrics.ValueLogSpaceAvailable = metricsFactory.Gauge(
+ metrics.Options{Name: valueLogSpaceAvailableName},
+ )
+ f.metrics.KeyLogSpaceAvailable = metricsFactory.Gauge(
+ metrics.Options{Name: keyLogSpaceAvailableName},
+ )
+ f.metrics.LastMaintenanceRun = metricsFactory.Gauge(
+ metrics.Options{Name: lastMaintenanceRunName},
+ )
+ f.metrics.LastValueLogCleaned = metricsFactory.Gauge(
+ metrics.Options{Name: lastValueLogCleanedName},
+ )
f.registerBadgerExpvarMetrics(metricsFactory)
@@ -189,7 +204,11 @@ func (f *Factory) CreateSpanReader() (spanstore.Reader, error) {
// CreateSpanWriter implements storage.Factory
func (f *Factory) CreateSpanWriter() (spanstore.Writer, error) {
- return badgerStore.NewSpanWriter(f.store, f.cache, f.Options.Primary.SpanStoreTTL), nil
+ return badgerStore.NewSpanWriter(
+ f.store,
+ f.cache,
+ f.Options.Primary.SpanStoreTTL,
+ ), nil
}
// CreateDependencyReader implements storage.Factory
@@ -199,7 +218,9 @@ func (f *Factory) CreateDependencyReader() (dependencystore.Reader, error) {
}
// CreateSamplingStore implements storage.SamplingStoreFactory
-func (f *Factory) CreateSamplingStore(maxBuckets int) (samplingstore.Store, error) {
+func (f *Factory) CreateSamplingStore(
+ maxBuckets int,
+) (samplingstore.Store, error) {
return badgerSampling.NewSamplingStore(f.store), nil
}
@@ -240,7 +261,9 @@ func (f *Factory) maintenance() {
// After there's nothing to clean, the err is raised
for err == nil {
- err = f.store.RunValueLogGC(0.5) // 0.5 is selected to rewrite a file if half of it can be discarded
+ err = f.store.RunValueLogGC(
+ 0.5,
+ ) // 0.5 is selected to rewrite a file if half of it can be discarded
}
if errors.Is(err, badger.ErrNoRewrite) {
f.metrics.LastValueLogCleaned.Update(t.UnixNano())
diff --git a/plugin/storage/badger/factory_test.go b/plugin/storage/badger/factory_test.go
index 2216c03ef7a..554068e2277 100644
--- a/plugin/storage/badger/factory_test.go
+++ b/plugin/storage/badger/factory_test.go
@@ -110,7 +110,9 @@ func TestMaintenanceRun(t *testing.T) {
return gs[lastMaintenanceRunName]
}
- runtime := waiter(0) // First run, check that it was ran and caches previous size
+ runtime := waiter(
+ 0,
+ ) // First run, check that it was ran and caches previous size
// This is to for codecov only. Can break without anything else breaking as it does test badger's
// internal implementation
@@ -185,7 +187,11 @@ func TestBadgerMetrics(t *testing.T) {
vlogSize := waiter(0)
_, gs := mFactory.Snapshot()
assert.EqualValues(t, 0, vlogSize)
- assert.EqualValues(t, int64(0), gs["badger_v3_memtable_gets_total"]) // IntVal metric
+ assert.EqualValues(
+ t,
+ int64(0),
+ gs["badger_v3_memtable_gets_total"],
+ ) // IntVal metric
_, found = gs["badger_v3_lsm_size_bytes"] // Map metric
assert.True(t, found)
diff --git a/plugin/storage/badger/options.go b/plugin/storage/badger/options.go
index 22b8ffb14a9..c6c3aa86b83 100644
--- a/plugin/storage/badger/options.go
+++ b/plugin/storage/badger/options.go
@@ -60,8 +60,12 @@ const (
suffixMetricsInterval = ".metrics-update-interval" // Intended only for testing purposes
suffixReadOnly = ".read-only"
defaultDataDir = string(os.PathSeparator) + "data"
- defaultValueDir = defaultDataDir + string(os.PathSeparator) + "values"
- defaultKeysDir = defaultDataDir + string(os.PathSeparator) + "keys"
+ defaultValueDir = defaultDataDir + string(
+ os.PathSeparator,
+ ) + "values"
+ defaultKeysDir = defaultDataDir + string(
+ os.PathSeparator,
+ ) + "keys"
)
// NewOptions creates a new Options struct.
@@ -149,8 +153,12 @@ func initFromViper(cfg *NamespaceConfig, v *viper.Viper, logger *zap.Logger) {
cfg.ValueDirectory = v.GetString(cfg.namespace + suffixValueDirectory)
cfg.SyncWrites = v.GetBool(cfg.namespace + suffixSyncWrite)
cfg.SpanStoreTTL = v.GetDuration(cfg.namespace + suffixSpanstoreTTL)
- cfg.MaintenanceInterval = v.GetDuration(cfg.namespace + suffixMaintenanceInterval)
- cfg.MetricsUpdateInterval = v.GetDuration(cfg.namespace + suffixMetricsInterval)
+ cfg.MaintenanceInterval = v.GetDuration(
+ cfg.namespace + suffixMaintenanceInterval,
+ )
+ cfg.MetricsUpdateInterval = v.GetDuration(
+ cfg.namespace + suffixMetricsInterval,
+ )
cfg.ReadOnly = v.GetBool(cfg.namespace + suffixReadOnly)
}
diff --git a/plugin/storage/badger/options_test.go b/plugin/storage/badger/options_test.go
index 25cdd055c87..7c302a5ba40 100644
--- a/plugin/storage/badger/options_test.go
+++ b/plugin/storage/badger/options_test.go
@@ -49,7 +49,11 @@ func TestParseOptions(t *testing.T) {
assert.False(t, opts.GetPrimary().Ephemeral)
assert.True(t, opts.GetPrimary().SyncWrites)
- assert.Equal(t, time.Duration(168*time.Hour), opts.GetPrimary().SpanStoreTTL)
+ assert.Equal(
+ t,
+ time.Duration(168*time.Hour),
+ opts.GetPrimary().SpanStoreTTL,
+ )
assert.Equal(t, "/var/lib/badger", opts.GetPrimary().KeyDirectory)
assert.Equal(t, "/mnt/slow/badger", opts.GetPrimary().ValueDirectory)
assert.False(t, opts.GetPrimary().ReadOnly)
diff --git a/plugin/storage/badger/samplingstore/storage.go b/plugin/storage/badger/samplingstore/storage.go
index 8ff4fd8d812..d066f88a836 100644
--- a/plugin/storage/badger/samplingstore/storage.go
+++ b/plugin/storage/badger/samplingstore/storage.go
@@ -69,7 +69,9 @@ func (s *SamplingStore) InsertThroughput(throughput []*model.Throughput) error {
return nil
}
-func (s *SamplingStore) GetThroughput(start, end time.Time) ([]*model.Throughput, error) {
+func (s *SamplingStore) GetThroughput(
+ start, end time.Time,
+) ([]*model.Throughput, error) {
var retSlice []*model.Throughput
prefix := []byte{throughputKeyPrefix}
@@ -115,7 +117,12 @@ func (s *SamplingStore) InsertProbabilitiesAndQPS(hostname string,
) error {
startTime := jaegermodel.TimeAsEpochMicroseconds(time.Now())
entriesToStore := make([]*badger.Entry, 0)
- entries, err := s.createProbabilitiesEntry(hostname, probabilities, qps, startTime)
+ entries, err := s.createProbabilitiesEntry(
+ hostname,
+ probabilities,
+ qps,
+ startTime,
+ )
if err != nil {
return err
}
@@ -167,7 +174,12 @@ func (s *SamplingStore) GetLatestProbabilities() (model.ServiceOperationProbabil
return retVal, nil
}
-func (s *SamplingStore) createProbabilitiesEntry(hostname string, probabilities model.ServiceOperationProbabilities, qps model.ServiceOperationQPS, startTime uint64) (*badger.Entry, error) {
+func (s *SamplingStore) createProbabilitiesEntry(
+ hostname string,
+ probabilities model.ServiceOperationProbabilities,
+ qps model.ServiceOperationQPS,
+ startTime uint64,
+) (*badger.Entry, error) {
pK, pV, err := s.createProbabilitiesKV(hostname, probabilities, qps, startTime)
if err != nil {
return nil, err
@@ -178,7 +190,12 @@ func (s *SamplingStore) createProbabilitiesEntry(hostname string, probabilities
return e, nil
}
-func (*SamplingStore) createProbabilitiesKV(hostname string, probabilities model.ServiceOperationProbabilities, qps model.ServiceOperationQPS, startTime uint64) ([]byte, []byte, error) {
+func (*SamplingStore) createProbabilitiesKV(
+ hostname string,
+ probabilities model.ServiceOperationProbabilities,
+ qps model.ServiceOperationQPS,
+ startTime uint64,
+) ([]byte, []byte, error) {
key := make([]byte, 16)
key[0] = probabilitiesKeyPrefix
pos := 1
@@ -195,7 +212,10 @@ func (*SamplingStore) createProbabilitiesKV(hostname string, probabilities model
return key, bb, err
}
-func (s *SamplingStore) createThroughputEntry(throughput []*model.Throughput, startTime uint64) (*badger.Entry, error) {
+func (s *SamplingStore) createThroughputEntry(
+ throughput []*model.Throughput,
+ startTime uint64,
+) (*badger.Entry, error) {
pK, pV, err := s.createThroughputKV(throughput, startTime)
if err != nil {
return nil, err
@@ -206,14 +226,20 @@ func (s *SamplingStore) createThroughputEntry(throughput []*model.Throughput, st
return e, nil
}
-func (*SamplingStore) createBadgerEntry(key []byte, value []byte) *badger.Entry {
+func (*SamplingStore) createBadgerEntry(
+ key []byte,
+ value []byte,
+) *badger.Entry {
return &badger.Entry{
Key: key,
Value: value,
}
}
-func (*SamplingStore) createThroughputKV(throughput []*model.Throughput, startTime uint64) ([]byte, []byte, error) {
+func (*SamplingStore) createThroughputKV(
+ throughput []*model.Throughput,
+ startTime uint64,
+) ([]byte, []byte, error) {
key := make([]byte, 16)
key[0] = throughputKeyPrefix
pos := 1
diff --git a/plugin/storage/badger/samplingstore/storage_test.go b/plugin/storage/badger/samplingstore/storage_test.go
index 8b92a2ca43e..f53123bf4a8 100644
--- a/plugin/storage/badger/samplingstore/storage_test.go
+++ b/plugin/storage/badger/samplingstore/storage_test.go
@@ -52,7 +52,10 @@ func TestGetThroughput(t *testing.T) {
err := store.InsertThroughput(expected)
require.NoError(t, err)
- actual, err := store.GetThroughput(start.Add(-time.Millisecond), start.Add(time.Second*time.Duration(10)))
+ actual, err := store.GetThroughput(
+ start.Add(-time.Millisecond),
+ start.Add(time.Second*time.Duration(10)),
+ )
require.NoError(t, err)
assert.Equal(t, expected, actual)
})
@@ -79,12 +82,16 @@ func TestGetLatestProbabilities(t *testing.T) {
require.NoError(t, err)
err = store.InsertProbabilitiesAndQPS(
"newhostname",
- samplemodel.ServiceOperationProbabilities{"new-srv2": {"op": 0.123}},
+ samplemodel.ServiceOperationProbabilities{
+ "new-srv2": {"op": 0.123},
+ },
samplemodel.ServiceOperationQPS{"new-srv2": {"op": 1}},
)
require.NoError(t, err)
- expected := samplemodel.ServiceOperationProbabilities{"new-srv2": {"op": 0.123}}
+ expected := samplemodel.ServiceOperationProbabilities{
+ "new-srv2": {"op": 0.123},
+ }
actual, err := store.GetLatestProbabilities()
require.NoError(t, err)
assert.Equal(t, expected, actual)
@@ -93,9 +100,11 @@ func TestGetLatestProbabilities(t *testing.T) {
func TestDecodeProbabilitiesValue(t *testing.T) {
expected := ProbabilitiesAndQPS{
- Hostname: "dell11eg843d",
- Probabilities: samplemodel.ServiceOperationProbabilities{"new-srv": {"op": 0.1}},
- QPS: samplemodel.ServiceOperationQPS{"new-srv": {"op": 4}},
+ Hostname: "dell11eg843d",
+ Probabilities: samplemodel.ServiceOperationProbabilities{
+ "new-srv": {"op": 0.1},
+ },
+ QPS: samplemodel.ServiceOperationQPS{"new-srv": {"op": 4}},
}
marshalBytes, err := json.Marshal(expected)
@@ -124,7 +133,10 @@ func TestDecodeThroughtputValue(t *testing.T) {
assert.Equal(t, expected, acrual)
}
-func runWithBadger(t *testing.T, test func(t *testing.T, store *SamplingStore)) {
+func runWithBadger(
+ t *testing.T,
+ test func(t *testing.T, store *SamplingStore),
+) {
opts := badger.DefaultOptions("")
opts.SyncWrites = false
diff --git a/plugin/storage/badger/spanstore/cache.go b/plugin/storage/badger/spanstore/cache.go
index 5f1b7f89f41..8b61d52fcfa 100644
--- a/plugin/storage/badger/spanstore/cache.go
+++ b/plugin/storage/badger/spanstore/cache.go
@@ -71,8 +71,12 @@ func (c *CacheStore) loadServices() {
// Seek all the services first
for it.Seek(serviceKey); it.ValidForPrefix(serviceKey); it.Next() {
- timestampStartIndex := len(it.Item().Key()) - (sizeOfTraceID + 8) // 8 = sizeof(uint64)
- serviceName := string(it.Item().Key()[len(serviceKey):timestampStartIndex])
+ timestampStartIndex := len(
+ it.Item().Key(),
+ ) - (sizeOfTraceID + 8) // 8 = sizeof(uint64)
+ serviceName := string(
+ it.Item().Key()[len(serviceKey):timestampStartIndex],
+ )
keyTTL := it.Item().ExpiresAt()
if v, found := c.services[serviceName]; found {
if v > keyTTL {
@@ -97,8 +101,12 @@ func (c *CacheStore) loadOperations(service string) {
// Seek all the services first
for it.Seek(serviceKey); it.ValidForPrefix(serviceKey); it.Next() {
- timestampStartIndex := len(it.Item().Key()) - (sizeOfTraceID + 8) // 8 = sizeof(uint64)
- operationName := string(it.Item().Key()[len(serviceKey):timestampStartIndex])
+ timestampStartIndex := len(
+ it.Item().Key(),
+ ) - (sizeOfTraceID + 8) // 8 = sizeof(uint64)
+ operationName := string(
+ it.Item().Key()[len(serviceKey):timestampStartIndex],
+ )
keyTTL := it.Item().ExpiresAt()
if _, found := c.operations[service]; !found {
c.operations[service] = make(map[string]uint64)
@@ -128,7 +136,9 @@ func (c *CacheStore) Update(service, operation string, expireTime uint64) {
}
// GetOperations returns all operations for a specific service & spanKind traced by Jaeger
-func (c *CacheStore) GetOperations(service string) ([]spanstore.Operation, error) {
+func (c *CacheStore) GetOperations(
+ service string,
+) ([]spanstore.Operation, error) {
operations := make([]string, 0, len(c.services))
t := uint64(time.Now().Unix())
c.cacheLock.Lock()
diff --git a/plugin/storage/badger/spanstore/cache_test.go b/plugin/storage/badger/spanstore/cache_test.go
index fafc861ab2b..df3d9555a86 100644
--- a/plugin/storage/badger/spanstore/cache_test.go
+++ b/plugin/storage/badger/spanstore/cache_test.go
@@ -69,7 +69,12 @@ func TestOldReads(t *testing.T) {
runWithBadger(t, func(store *badger.DB, t *testing.T) {
timeNow := model.TimeAsEpochMicroseconds(time.Now())
s1Key := createIndexKey(serviceNameIndexKey, []byte("service1"), timeNow, model.TraceID{High: 0, Low: 0})
- s1o1Key := createIndexKey(operationNameIndexKey, []byte("service1operation1"), timeNow, model.TraceID{High: 0, Low: 0})
+ s1o1Key := createIndexKey(
+ operationNameIndexKey,
+ []byte("service1operation1"),
+ timeNow,
+ model.TraceID{High: 0, Low: 0},
+ )
tid := time.Now().Add(1 * time.Minute)
@@ -100,7 +105,11 @@ func TestOldReads(t *testing.T) {
// Now make sure we didn't use the older timestamps from the DB
assert.Equal(t, uint64(nuTid.Unix()), cache.services["service1"])
- assert.Equal(t, uint64(nuTid.Unix()), cache.operations["service1"]["operation1"])
+ assert.Equal(
+ t,
+ uint64(nuTid.Unix()),
+ cache.operations["service1"]["operation1"],
+ )
})
}
diff --git a/plugin/storage/badger/spanstore/read_write_test.go b/plugin/storage/badger/spanstore/read_write_test.go
index a7655741260..1536827bce0 100644
--- a/plugin/storage/badger/spanstore/read_write_test.go
+++ b/plugin/storage/badger/spanstore/read_write_test.go
@@ -37,342 +37,382 @@ import (
)
func TestWriteReadBack(t *testing.T) {
- runFactoryTest(t, func(tb testing.TB, sw spanstore.Writer, sr spanstore.Reader) {
- tid := time.Now()
- traces := 40
- spans := 3
-
- dummyKv := []model.KeyValue{
- {
- Key: "key",
- VType: model.StringType,
- VStr: "value",
- },
- }
+ runFactoryTest(
+ t,
+ func(tb testing.TB, sw spanstore.Writer, sr spanstore.Reader) {
+ tid := time.Now()
+ traces := 40
+ spans := 3
+
+ dummyKv := []model.KeyValue{
+ {
+ Key: "key",
+ VType: model.StringType,
+ VStr: "value",
+ },
+ }
- for i := 0; i < traces; i++ {
- for j := 0; j < spans; j++ {
- s := model.Span{
- TraceID: model.TraceID{
- Low: uint64(i),
- High: 1,
- },
- SpanID: model.SpanID(j),
- OperationName: "operation",
- Process: &model.Process{
- ServiceName: "service",
- Tags: dummyKv,
- },
- StartTime: tid.Add(time.Duration(i)),
- Duration: time.Duration(i + j),
- Tags: dummyKv,
- Logs: []model.Log{
- {
- Timestamp: tid,
- Fields: dummyKv,
+ for i := 0; i < traces; i++ {
+ for j := 0; j < spans; j++ {
+ s := model.Span{
+ TraceID: model.TraceID{
+ Low: uint64(i),
+ High: 1,
},
- },
+ SpanID: model.SpanID(j),
+ OperationName: "operation",
+ Process: &model.Process{
+ ServiceName: "service",
+ Tags: dummyKv,
+ },
+ StartTime: tid.Add(time.Duration(i)),
+ Duration: time.Duration(i + j),
+ Tags: dummyKv,
+ Logs: []model.Log{
+ {
+ Timestamp: tid,
+ Fields: dummyKv,
+ },
+ },
+ }
+ err := sw.WriteSpan(context.Background(), &s)
+ require.NoError(t, err)
}
- err := sw.WriteSpan(context.Background(), &s)
- require.NoError(t, err)
}
- }
- for i := 0; i < traces; i++ {
- tr, err := sr.GetTrace(context.Background(), model.TraceID{
- Low: uint64(i),
- High: 1,
- })
- require.NoError(t, err)
+ for i := 0; i < traces; i++ {
+ tr, err := sr.GetTrace(context.Background(), model.TraceID{
+ Low: uint64(i),
+ High: 1,
+ })
+ require.NoError(t, err)
- assert.Len(t, tr.Spans, spans)
- }
- })
+ assert.Len(t, tr.Spans, spans)
+ }
+ },
+ )
}
func TestValidation(t *testing.T) {
- runFactoryTest(t, func(tb testing.TB, sw spanstore.Writer, sr spanstore.Reader) {
- tid := time.Now()
- params := &spanstore.TraceQueryParameters{
- StartTimeMin: tid,
- StartTimeMax: tid.Add(time.Duration(10)),
- }
+ runFactoryTest(
+ t,
+ func(tb testing.TB, sw spanstore.Writer, sr spanstore.Reader) {
+ tid := time.Now()
+ params := &spanstore.TraceQueryParameters{
+ StartTimeMin: tid,
+ StartTimeMax: tid.Add(time.Duration(10)),
+ }
- params.OperationName = "no-service"
- _, err := sr.FindTraces(context.Background(), params)
- require.EqualError(t, err, "service name must be set")
- params.ServiceName = "find-service"
+ params.OperationName = "no-service"
+ _, err := sr.FindTraces(context.Background(), params)
+ require.EqualError(t, err, "service name must be set")
+ params.ServiceName = "find-service"
- _, err = sr.FindTraces(context.Background(), nil)
- require.EqualError(t, err, "malformed request object")
+ _, err = sr.FindTraces(context.Background(), nil)
+ require.EqualError(t, err, "malformed request object")
- params.StartTimeMin = params.StartTimeMax.Add(1 * time.Hour)
- _, err = sr.FindTraces(context.Background(), params)
- require.EqualError(t, err, "min start time is above max")
- params.StartTimeMin = tid
+ params.StartTimeMin = params.StartTimeMax.Add(1 * time.Hour)
+ _, err = sr.FindTraces(context.Background(), params)
+ require.EqualError(t, err, "min start time is above max")
+ params.StartTimeMin = tid
- params.DurationMax = time.Duration(1 * time.Millisecond)
- params.DurationMin = time.Duration(1 * time.Minute)
- _, err = sr.FindTraces(context.Background(), params)
- require.EqualError(t, err, "min duration is above max")
+ params.DurationMax = time.Duration(1 * time.Millisecond)
+ params.DurationMin = time.Duration(1 * time.Minute)
+ _, err = sr.FindTraces(context.Background(), params)
+ require.EqualError(t, err, "min duration is above max")
- params = &spanstore.TraceQueryParameters{
- StartTimeMin: tid,
- }
- _, err = sr.FindTraces(context.Background(), params)
- require.EqualError(t, err, "start and end time must be set")
+ params = &spanstore.TraceQueryParameters{
+ StartTimeMin: tid,
+ }
+ _, err = sr.FindTraces(context.Background(), params)
+ require.EqualError(t, err, "start and end time must be set")
- params.StartTimeMax = tid.Add(1 * time.Minute)
- params.Tags = map[string]string{"A": "B"}
- _, err = sr.FindTraces(context.Background(), params)
- require.EqualError(t, err, "service name must be set")
- })
+ params.StartTimeMax = tid.Add(1 * time.Minute)
+ params.Tags = map[string]string{"A": "B"}
+ _, err = sr.FindTraces(context.Background(), params)
+ require.EqualError(t, err, "service name must be set")
+ },
+ )
}
func TestIndexSeeks(t *testing.T) {
- runFactoryTest(t, func(tb testing.TB, sw spanstore.Writer, sr spanstore.Reader) {
- startT := time.Now()
- traces := 60
- spans := 3
- tid := startT
-
- traceOrder := make([]uint64, traces)
-
- for i := 0; i < traces; i++ {
- lowId := rand.Uint64()
- traceOrder[i] = lowId
- tid = tid.Add(time.Duration(time.Millisecond * time.Duration(i)))
-
- for j := 0; j < spans; j++ {
- s := model.Span{
- TraceID: model.TraceID{
- Low: lowId,
- High: 1,
- },
- SpanID: model.SpanID(rand.Uint64()),
- OperationName: fmt.Sprintf("operation-%d", j),
- Process: &model.Process{
- ServiceName: fmt.Sprintf("service-%d", i%4),
- },
- StartTime: tid,
- Duration: time.Duration(time.Duration(i+j) * time.Millisecond),
- Tags: model.KeyValues{
- model.KeyValue{
- Key: fmt.Sprintf("k%d", i),
- VStr: fmt.Sprintf("val%d", j),
- VType: model.StringType,
+ runFactoryTest(
+ t,
+ func(tb testing.TB, sw spanstore.Writer, sr spanstore.Reader) {
+ startT := time.Now()
+ traces := 60
+ spans := 3
+ tid := startT
+
+ traceOrder := make([]uint64, traces)
+
+ for i := 0; i < traces; i++ {
+ lowId := rand.Uint64()
+ traceOrder[i] = lowId
+ tid = tid.Add(
+ time.Duration(time.Millisecond * time.Duration(i)),
+ )
+
+ for j := 0; j < spans; j++ {
+ s := model.Span{
+ TraceID: model.TraceID{
+ Low: lowId,
+ High: 1,
},
- {
- Key: "error",
- VType: model.BoolType,
- VBool: true,
+ SpanID: model.SpanID(rand.Uint64()),
+ OperationName: fmt.Sprintf("operation-%d", j),
+ Process: &model.Process{
+ ServiceName: fmt.Sprintf("service-%d", i%4),
},
- },
- }
+ StartTime: tid,
+ Duration: time.Duration(
+ time.Duration(i+j) * time.Millisecond,
+ ),
+ Tags: model.KeyValues{
+ model.KeyValue{
+ Key: fmt.Sprintf("k%d", i),
+ VStr: fmt.Sprintf("val%d", j),
+ VType: model.StringType,
+ },
+ {
+ Key: "error",
+ VType: model.BoolType,
+ VBool: true,
+ },
+ },
+ }
- err := sw.WriteSpan(context.Background(), &s)
- require.NoError(t, err)
+ err := sw.WriteSpan(context.Background(), &s)
+ require.NoError(t, err)
+ }
}
- }
- testOrder := func(trs []*model.Trace) {
- // Assert that we returned correctly in DESC time order
- for l := 1; l < len(trs); l++ {
- assert.True(t, trs[l].Spans[spans-1].StartTime.Before(trs[l-1].Spans[spans-1].StartTime))
+ testOrder := func(trs []*model.Trace) {
+ // Assert that we returned correctly in DESC time order
+ for l := 1; l < len(trs); l++ {
+ assert.True(
+ t,
+ trs[l].Spans[spans-1].StartTime.Before(
+ trs[l-1].Spans[spans-1].StartTime,
+ ),
+ )
+ }
}
- }
-
- params := &spanstore.TraceQueryParameters{
- StartTimeMin: startT,
- StartTimeMax: startT.Add(time.Duration(time.Millisecond * 10)),
- ServiceName: "service-1",
- }
-
- trs, err := sr.FindTraces(context.Background(), params)
- require.NoError(t, err)
- assert.Len(t, trs, 1)
- assert.Len(t, trs[0].Spans, spans)
- params.OperationName = "operation-1"
- trs, err = sr.FindTraces(context.Background(), params)
- require.NoError(t, err)
- assert.Len(t, trs, 1)
+ params := &spanstore.TraceQueryParameters{
+ StartTimeMin: startT,
+ StartTimeMax: startT.Add(time.Duration(time.Millisecond * 10)),
+ ServiceName: "service-1",
+ }
- params.ServiceName = "service-10" // this should not match
- trs, err = sr.FindTraces(context.Background(), params)
- require.NoError(t, err)
- assert.Empty(t, trs)
+ trs, err := sr.FindTraces(context.Background(), params)
+ require.NoError(t, err)
+ assert.Len(t, trs, 1)
+ assert.Len(t, trs[0].Spans, spans)
- params.OperationName = "operation-4"
- trs, err = sr.FindTraces(context.Background(), params)
- require.NoError(t, err)
- assert.Empty(t, trs)
-
- // Multi-index hits
-
- params.StartTimeMax = startT.Add(time.Duration(time.Millisecond * 666))
- params.ServiceName = "service-3"
- params.OperationName = "operation-1"
- tags := make(map[string]string)
- tags["k11"] = "val0"
- tags["error"] = "true"
- params.Tags = tags
- params.DurationMin = time.Duration(1 * time.Millisecond)
- trs, err = sr.FindTraces(context.Background(), params)
- require.NoError(t, err)
- assert.Len(t, trs, 1)
- assert.Len(t, trs[0].Spans, spans)
+ params.OperationName = "operation-1"
+ trs, err = sr.FindTraces(context.Background(), params)
+ require.NoError(t, err)
+ assert.Len(t, trs, 1)
- // Query limited amount of hits
+ params.ServiceName = "service-10" // this should not match
+ trs, err = sr.FindTraces(context.Background(), params)
+ require.NoError(t, err)
+ assert.Empty(t, trs)
- params.StartTimeMax = startT.Add(time.Duration(time.Hour * 1))
- delete(params.Tags, "k11")
- params.NumTraces = 2
- trs, err = sr.FindTraces(context.Background(), params)
- require.NoError(t, err)
- assert.Len(t, trs, 2)
- assert.Equal(t, traceOrder[59], trs[0].Spans[0].TraceID.Low)
- assert.Equal(t, traceOrder[55], trs[1].Spans[0].TraceID.Low)
- testOrder(trs)
-
- // Check for DESC return order with duration index
- params = &spanstore.TraceQueryParameters{
- StartTimeMin: startT,
- StartTimeMax: startT.Add(time.Duration(time.Hour * 1)),
- DurationMin: time.Duration(30 * time.Millisecond), // Filters one
- DurationMax: time.Duration(50 * time.Millisecond), // Filters three
- NumTraces: 9,
- }
- trs, err = sr.FindTraces(context.Background(), params)
- require.NoError(t, err)
- assert.Len(t, trs, 9) // Returns 23, we limited to 9
-
- // Check the newest items are returned
- assert.Equal(t, traceOrder[50], trs[0].Spans[0].TraceID.Low)
- assert.Equal(t, traceOrder[42], trs[8].Spans[0].TraceID.Low)
- testOrder(trs)
-
- // Check for DESC return order without duration index, but still with limit
- params.DurationMin = 0
- params.DurationMax = 0
- params.NumTraces = 7
- trs, err = sr.FindTraces(context.Background(), params)
- require.NoError(t, err)
- assert.Len(t, trs, 7)
- assert.Equal(t, traceOrder[59], trs[0].Spans[0].TraceID.Low)
- assert.Equal(t, traceOrder[53], trs[6].Spans[0].TraceID.Low)
- testOrder(trs)
-
- // StartTime, endTime scan - full table scan (so technically no index seek)
- params = &spanstore.TraceQueryParameters{
- StartTimeMin: startT,
- StartTimeMax: startT.Add(time.Duration(time.Millisecond * 10)),
- }
+ params.OperationName = "operation-4"
+ trs, err = sr.FindTraces(context.Background(), params)
+ require.NoError(t, err)
+ assert.Empty(t, trs)
+
+ // Multi-index hits
+
+ params.StartTimeMax = startT.Add(
+ time.Duration(time.Millisecond * 666),
+ )
+ params.ServiceName = "service-3"
+ params.OperationName = "operation-1"
+ tags := make(map[string]string)
+ tags["k11"] = "val0"
+ tags["error"] = "true"
+ params.Tags = tags
+ params.DurationMin = time.Duration(1 * time.Millisecond)
+ trs, err = sr.FindTraces(context.Background(), params)
+ require.NoError(t, err)
+ assert.Len(t, trs, 1)
+ assert.Len(t, trs[0].Spans, spans)
- trs, err = sr.FindTraces(context.Background(), params)
- require.NoError(t, err)
- assert.Len(t, trs, 5)
- assert.Len(t, trs[0].Spans, spans)
- testOrder(trs)
+ // Query limited amount of hits
- // StartTime and Duration queries
- params.StartTimeMax = startT.Add(time.Duration(time.Hour * 10))
- params.DurationMin = time.Duration(53 * time.Millisecond) // trace 51 (min)
- params.DurationMax = time.Duration(56 * time.Millisecond) // trace 56 (max)
+ params.StartTimeMax = startT.Add(time.Duration(time.Hour * 1))
+ delete(params.Tags, "k11")
+ params.NumTraces = 2
+ trs, err = sr.FindTraces(context.Background(), params)
+ require.NoError(t, err)
+ assert.Len(t, trs, 2)
+ assert.Equal(t, traceOrder[59], trs[0].Spans[0].TraceID.Low)
+ assert.Equal(t, traceOrder[55], trs[1].Spans[0].TraceID.Low)
+ testOrder(trs)
+
+ // Check for DESC return order with duration index
+ params = &spanstore.TraceQueryParameters{
+ StartTimeMin: startT,
+ StartTimeMax: startT.Add(time.Duration(time.Hour * 1)),
+ DurationMin: time.Duration(
+ 30 * time.Millisecond,
+ ), // Filters one
+ DurationMax: time.Duration(
+ 50 * time.Millisecond,
+ ), // Filters three
+ NumTraces: 9,
+ }
+ trs, err = sr.FindTraces(context.Background(), params)
+ require.NoError(t, err)
+ assert.Len(t, trs, 9) // Returns 23, we limited to 9
+
+ // Check the newest items are returned
+ assert.Equal(t, traceOrder[50], trs[0].Spans[0].TraceID.Low)
+ assert.Equal(t, traceOrder[42], trs[8].Spans[0].TraceID.Low)
+ testOrder(trs)
+
+ // Check for DESC return order without duration index, but still with limit
+ params.DurationMin = 0
+ params.DurationMax = 0
+ params.NumTraces = 7
+ trs, err = sr.FindTraces(context.Background(), params)
+ require.NoError(t, err)
+ assert.Len(t, trs, 7)
+ assert.Equal(t, traceOrder[59], trs[0].Spans[0].TraceID.Low)
+ assert.Equal(t, traceOrder[53], trs[6].Spans[0].TraceID.Low)
+ testOrder(trs)
+
+ // StartTime, endTime scan - full table scan (so technically no index seek)
+ params = &spanstore.TraceQueryParameters{
+ StartTimeMin: startT,
+ StartTimeMax: startT.Add(time.Duration(time.Millisecond * 10)),
+ }
- trs, err = sr.FindTraces(context.Background(), params)
- require.NoError(t, err)
- assert.Len(t, trs, 6)
- assert.Equal(t, traceOrder[56], trs[0].Spans[0].TraceID.Low)
- assert.Equal(t, traceOrder[51], trs[5].Spans[0].TraceID.Low)
- testOrder(trs)
- })
+ trs, err = sr.FindTraces(context.Background(), params)
+ require.NoError(t, err)
+ assert.Len(t, trs, 5)
+ assert.Len(t, trs[0].Spans, spans)
+ testOrder(trs)
+
+ // StartTime and Duration queries
+ params.StartTimeMax = startT.Add(time.Duration(time.Hour * 10))
+ params.DurationMin = time.Duration(
+ 53 * time.Millisecond,
+ ) // trace 51 (min)
+ params.DurationMax = time.Duration(
+ 56 * time.Millisecond,
+ ) // trace 56 (max)
+
+ trs, err = sr.FindTraces(context.Background(), params)
+ require.NoError(t, err)
+ assert.Len(t, trs, 6)
+ assert.Equal(t, traceOrder[56], trs[0].Spans[0].TraceID.Low)
+ assert.Equal(t, traceOrder[51], trs[5].Spans[0].TraceID.Low)
+ testOrder(trs)
+ },
+ )
}
func TestFindNothing(t *testing.T) {
- runFactoryTest(t, func(tb testing.TB, sw spanstore.Writer, sr spanstore.Reader) {
- startT := time.Now()
- params := &spanstore.TraceQueryParameters{
- StartTimeMin: startT,
- StartTimeMax: startT.Add(time.Duration(time.Millisecond * 10)),
- ServiceName: "service-1",
- }
-
- trs, err := sr.FindTraces(context.Background(), params)
- require.NoError(t, err)
- assert.Empty(t, trs)
+ runFactoryTest(
+ t,
+ func(tb testing.TB, sw spanstore.Writer, sr spanstore.Reader) {
+ startT := time.Now()
+ params := &spanstore.TraceQueryParameters{
+ StartTimeMin: startT,
+ StartTimeMax: startT.Add(time.Duration(time.Millisecond * 10)),
+ ServiceName: "service-1",
+ }
- tr, err := sr.GetTrace(context.Background(), model.TraceID{High: 0, Low: 0})
- assert.Equal(t, spanstore.ErrTraceNotFound, err)
- assert.Nil(t, tr)
- })
+ trs, err := sr.FindTraces(context.Background(), params)
+ require.NoError(t, err)
+ assert.Empty(t, trs)
+
+ tr, err := sr.GetTrace(
+ context.Background(),
+ model.TraceID{High: 0, Low: 0},
+ )
+ assert.Equal(t, spanstore.ErrTraceNotFound, err)
+ assert.Nil(t, tr)
+ },
+ )
}
func TestWriteDuplicates(t *testing.T) {
- runFactoryTest(t, func(tb testing.TB, sw spanstore.Writer, sr spanstore.Reader) {
- tid := time.Now()
- times := 40
- spans := 3
- for i := 0; i < times; i++ {
- for j := 0; j < spans; j++ {
- s := model.Span{
- TraceID: model.TraceID{
- Low: uint64(0),
- High: 1,
- },
- SpanID: model.SpanID(j),
- OperationName: "operation",
- Process: &model.Process{
- ServiceName: "service",
- },
- StartTime: tid.Add(time.Duration(10)),
- Duration: time.Duration(i + j),
+ runFactoryTest(
+ t,
+ func(tb testing.TB, sw spanstore.Writer, sr spanstore.Reader) {
+ tid := time.Now()
+ times := 40
+ spans := 3
+ for i := 0; i < times; i++ {
+ for j := 0; j < spans; j++ {
+ s := model.Span{
+ TraceID: model.TraceID{
+ Low: uint64(0),
+ High: 1,
+ },
+ SpanID: model.SpanID(j),
+ OperationName: "operation",
+ Process: &model.Process{
+ ServiceName: "service",
+ },
+ StartTime: tid.Add(time.Duration(10)),
+ Duration: time.Duration(i + j),
+ }
+ err := sw.WriteSpan(context.Background(), &s)
+ require.NoError(t, err)
}
- err := sw.WriteSpan(context.Background(), &s)
- require.NoError(t, err)
}
- }
- })
+ },
+ )
}
func TestMenuSeeks(t *testing.T) {
- runFactoryTest(t, func(tb testing.TB, sw spanstore.Writer, sr spanstore.Reader) {
- tid := time.Now()
- traces := 40
- services := 4
- spans := 3
- for i := 0; i < traces; i++ {
- for j := 0; j < spans; j++ {
- s := model.Span{
- TraceID: model.TraceID{
- Low: uint64(i),
- High: 1,
- },
- SpanID: model.SpanID(j),
- OperationName: fmt.Sprintf("operation-%d", j),
- Process: &model.Process{
- ServiceName: fmt.Sprintf("service-%d", i%services),
- },
- StartTime: tid.Add(time.Duration(i)),
- Duration: time.Duration(i + j),
+ runFactoryTest(
+ t,
+ func(tb testing.TB, sw spanstore.Writer, sr spanstore.Reader) {
+ tid := time.Now()
+ traces := 40
+ services := 4
+ spans := 3
+ for i := 0; i < traces; i++ {
+ for j := 0; j < spans; j++ {
+ s := model.Span{
+ TraceID: model.TraceID{
+ Low: uint64(i),
+ High: 1,
+ },
+ SpanID: model.SpanID(j),
+ OperationName: fmt.Sprintf("operation-%d", j),
+ Process: &model.Process{
+ ServiceName: fmt.Sprintf("service-%d", i%services),
+ },
+ StartTime: tid.Add(time.Duration(i)),
+ Duration: time.Duration(i + j),
+ }
+ err := sw.WriteSpan(context.Background(), &s)
+ require.NoError(t, err)
}
- err := sw.WriteSpan(context.Background(), &s)
- require.NoError(t, err)
}
- }
- operations, err := sr.GetOperations(
- context.Background(),
- spanstore.OperationQueryParameters{ServiceName: "service-1"},
- )
- require.NoError(t, err)
+ operations, err := sr.GetOperations(
+ context.Background(),
+ spanstore.OperationQueryParameters{ServiceName: "service-1"},
+ )
+ require.NoError(t, err)
- serviceList, err := sr.GetServices(context.Background())
- require.NoError(t, err)
+ serviceList, err := sr.GetServices(context.Background())
+ require.NoError(t, err)
- assert.Len(t, operations, spans)
- assert.Len(t, serviceList, services)
- })
+ assert.Len(t, operations, spans)
+ assert.Len(t, serviceList, services)
+ },
+ )
}
func TestPersist(t *testing.T) {
@@ -443,7 +483,10 @@ func TestPersist(t *testing.T) {
}
// Opens a badger db and runs a test on it.
-func runFactoryTest(tb testing.TB, test func(tb testing.TB, sw spanstore.Writer, sr spanstore.Reader)) {
+func runFactoryTest(
+ tb testing.TB,
+ test func(tb testing.TB, sw spanstore.Writer, sr spanstore.Reader),
+) {
f := badger.NewFactory()
defer func() {
require.NoError(tb, f.Close())
@@ -471,7 +514,14 @@ func runFactoryTest(tb testing.TB, test func(tb testing.TB, sw spanstore.Writer,
// Benchmarks intended for profiling
-func writeSpans(sw spanstore.Writer, tags []model.KeyValue, services, operations []string, traces, spans int, high uint64, tid time.Time) {
+func writeSpans(
+ sw spanstore.Writer,
+ tags []model.KeyValue,
+ services, operations []string,
+ traces, spans int,
+ high uint64,
+ tid time.Time,
+) {
for i := 0; i < traces; i++ {
for j := 0; j < spans; j++ {
s := model.Span{
@@ -494,31 +544,45 @@ func writeSpans(sw spanstore.Writer, tags []model.KeyValue, services, operations
}
func BenchmarkWrites(b *testing.B) {
- runFactoryTest(b, func(tb testing.TB, sw spanstore.Writer, sr spanstore.Reader) {
- tid := time.Now()
- traces := 1000
- spans := 32
- tagsCount := 64
- tags, services, operations := makeWriteSupports(tagsCount, spans)
-
- f, err := os.Create("writes.out")
- if err != nil {
- log.Fatal("could not create CPU profile: ", err)
- }
- if err := pprof.StartCPUProfile(f); err != nil {
- log.Fatal("could not start CPU profile: ", err)
- }
- defer pprof.StopCPUProfile()
-
- b.ResetTimer()
- for a := 0; a < b.N; a++ {
- writeSpans(sw, tags, services, operations, traces, spans, uint64(0), tid)
- }
- b.StopTimer()
- })
+ runFactoryTest(
+ b,
+ func(tb testing.TB, sw spanstore.Writer, sr spanstore.Reader) {
+ tid := time.Now()
+ traces := 1000
+ spans := 32
+ tagsCount := 64
+ tags, services, operations := makeWriteSupports(tagsCount, spans)
+
+ f, err := os.Create("writes.out")
+ if err != nil {
+ log.Fatal("could not create CPU profile: ", err)
+ }
+ if err := pprof.StartCPUProfile(f); err != nil {
+ log.Fatal("could not start CPU profile: ", err)
+ }
+ defer pprof.StopCPUProfile()
+
+ b.ResetTimer()
+ for a := 0; a < b.N; a++ {
+ writeSpans(
+ sw,
+ tags,
+ services,
+ operations,
+ traces,
+ spans,
+ uint64(0),
+ tid,
+ )
+ }
+ b.StopTimer()
+ },
+ )
}
-func makeWriteSupports(tagsCount, spans int) ([]model.KeyValue, []string, []string) {
+func makeWriteSupports(
+ tagsCount, spans int,
+) ([]model.KeyValue, []string, []string) {
tags := make([]model.KeyValue, tagsCount)
for i := 0; i < tagsCount; i++ {
tags[i] = model.KeyValue{
@@ -538,41 +602,58 @@ func makeWriteSupports(tagsCount, spans int) ([]model.KeyValue, []string, []stri
return tags, services, operations
}
-func makeReadBenchmark(b *testing.B, tid time.Time, params *spanstore.TraceQueryParameters, outputFile string) {
- runLargeFactoryTest(b, func(tb testing.TB, sw spanstore.Writer, sr spanstore.Reader) {
- tid := time.Now()
-
- // Total amount of traces is traces * tracesTimes
- traces := 1000
- tracesTimes := 1
-
- // Total amount of spans written is traces * tracesTimes * spans
- spans := 32
-
- // Default is 160k
-
- tagsCount := 64
- tags, services, operations := makeWriteSupports(tagsCount, spans)
-
- for h := 0; h < tracesTimes; h++ {
- writeSpans(sw, tags, services, operations, traces, spans, uint64(h), tid)
- }
+func makeReadBenchmark(
+ b *testing.B,
+ tid time.Time,
+ params *spanstore.TraceQueryParameters,
+ outputFile string,
+) {
+ runLargeFactoryTest(
+ b,
+ func(tb testing.TB, sw spanstore.Writer, sr spanstore.Reader) {
+ tid := time.Now()
+
+ // Total amount of traces is traces * tracesTimes
+ traces := 1000
+ tracesTimes := 1
+
+ // Total amount of spans written is traces * tracesTimes * spans
+ spans := 32
+
+ // Default is 160k
+
+ tagsCount := 64
+ tags, services, operations := makeWriteSupports(tagsCount, spans)
+
+ for h := 0; h < tracesTimes; h++ {
+ writeSpans(
+ sw,
+ tags,
+ services,
+ operations,
+ traces,
+ spans,
+ uint64(h),
+ tid,
+ )
+ }
- f, err := os.Create(outputFile)
- if err != nil {
- log.Fatal("could not create CPU profile: ", err)
- }
- if err := pprof.StartCPUProfile(f); err != nil {
- log.Fatal("could not start CPU profile: ", err)
- }
- defer pprof.StopCPUProfile()
+ f, err := os.Create(outputFile)
+ if err != nil {
+ log.Fatal("could not create CPU profile: ", err)
+ }
+ if err := pprof.StartCPUProfile(f); err != nil {
+ log.Fatal("could not start CPU profile: ", err)
+ }
+ defer pprof.StopCPUProfile()
- b.ResetTimer()
- for a := 0; a < b.N; a++ {
- sr.FindTraces(context.Background(), params)
- }
- b.StopTimer()
- })
+ b.ResetTimer()
+ for a := 0; a < b.N; a++ {
+ sr.FindTraces(context.Background(), params)
+ }
+ b.StopTimer()
+ },
+ )
}
func BenchmarkServiceTagsRangeQueryLimitIndexFetch(b *testing.B) {
@@ -586,7 +667,9 @@ func BenchmarkServiceTagsRangeQueryLimitIndexFetch(b *testing.B) {
},
}
- params.DurationMin = time.Duration(1 * time.Millisecond) // durationQuery takes 53% of total execution time..
+ params.DurationMin = time.Duration(
+ 1 * time.Millisecond,
+ ) // durationQuery takes 53% of total execution time..
params.NumTraces = 50
makeReadBenchmark(b, tid, params, "scanrangeandindexlimit.out")
@@ -606,7 +689,10 @@ func BenchmarkServiceIndexLimitFetch(b *testing.B) {
}
// Opens a badger db and runs a test on it.
-func runLargeFactoryTest(tb testing.TB, test func(tb testing.TB, sw spanstore.Writer, sr spanstore.Reader)) {
+func runLargeFactoryTest(
+ tb testing.TB,
+ test func(tb testing.TB, sw spanstore.Writer, sr spanstore.Reader),
+) {
assertion := require.New(tb)
f := badger.NewFactory()
opts := badger.NewOptions("badger")
@@ -646,63 +732,66 @@ func runLargeFactoryTest(tb testing.TB, test func(tb testing.TB, sw spanstore.Wr
// TestRandomTraceID from issue #1808
func TestRandomTraceID(t *testing.T) {
- runFactoryTest(t, func(tb testing.TB, sw spanstore.Writer, sr spanstore.Reader) {
- s1 := model.Span{
- TraceID: model.TraceID{
- Low: uint64(14767110704788176287),
- High: 0,
- },
- SpanID: model.SpanID(14976775253976086374),
- OperationName: "/",
- Process: &model.Process{
- ServiceName: "nginx",
- },
- Tags: model.KeyValues{
- model.KeyValue{
- Key: "http.request_id",
- VStr: "first",
- VType: model.StringType,
+ runFactoryTest(
+ t,
+ func(tb testing.TB, sw spanstore.Writer, sr spanstore.Reader) {
+ s1 := model.Span{
+ TraceID: model.TraceID{
+ Low: uint64(14767110704788176287),
+ High: 0,
},
- },
- StartTime: time.Now(),
- Duration: 1 * time.Second,
- }
- err := sw.WriteSpan(context.Background(), &s1)
- require.NoError(t, err)
+ SpanID: model.SpanID(14976775253976086374),
+ OperationName: "/",
+ Process: &model.Process{
+ ServiceName: "nginx",
+ },
+ Tags: model.KeyValues{
+ model.KeyValue{
+ Key: "http.request_id",
+ VStr: "first",
+ VType: model.StringType,
+ },
+ },
+ StartTime: time.Now(),
+ Duration: 1 * time.Second,
+ }
+ err := sw.WriteSpan(context.Background(), &s1)
+ require.NoError(t, err)
- s2 := model.Span{
- TraceID: model.TraceID{
- Low: uint64(4775132888371984950),
- High: 0,
- },
- SpanID: model.SpanID(13576481569227028654),
- OperationName: "/",
- Process: &model.Process{
- ServiceName: "nginx",
- },
- Tags: model.KeyValues{
- model.KeyValue{
- Key: "http.request_id",
- VStr: "second",
- VType: model.StringType,
+ s2 := model.Span{
+ TraceID: model.TraceID{
+ Low: uint64(4775132888371984950),
+ High: 0,
},
- },
- StartTime: time.Now(),
- Duration: 1 * time.Second,
- }
- err = sw.WriteSpan(context.Background(), &s2)
- require.NoError(t, err)
+ SpanID: model.SpanID(13576481569227028654),
+ OperationName: "/",
+ Process: &model.Process{
+ ServiceName: "nginx",
+ },
+ Tags: model.KeyValues{
+ model.KeyValue{
+ Key: "http.request_id",
+ VStr: "second",
+ VType: model.StringType,
+ },
+ },
+ StartTime: time.Now(),
+ Duration: 1 * time.Second,
+ }
+ err = sw.WriteSpan(context.Background(), &s2)
+ require.NoError(t, err)
- params := &spanstore.TraceQueryParameters{
- StartTimeMin: time.Now().Add(-1 * time.Minute),
- StartTimeMax: time.Now(),
- ServiceName: "nginx",
- Tags: map[string]string{
- "http.request_id": "second",
- },
- }
- traces, err := sr.FindTraces(context.Background(), params)
- require.NoError(t, err)
- assert.Len(t, traces, 1)
- })
+ params := &spanstore.TraceQueryParameters{
+ StartTimeMin: time.Now().Add(-1 * time.Minute),
+ StartTimeMax: time.Now(),
+ ServiceName: "nginx",
+ Tags: map[string]string{
+ "http.request_id": "second",
+ },
+ }
+ traces, err := sr.FindTraces(context.Background(), params)
+ require.NoError(t, err)
+ assert.Len(t, traces, 1)
+ },
+ )
}
diff --git a/plugin/storage/badger/spanstore/reader.go b/plugin/storage/badger/spanstore/reader.go
index 484deeaa575..d20430d86f8 100644
--- a/plugin/storage/badger/spanstore/reader.go
+++ b/plugin/storage/badger/spanstore/reader.go
@@ -49,7 +49,9 @@ var (
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",
+ )
// ErrNotSupported during development, don't support every option - yet
ErrNotSupported = errors.New("this query parameter is not supported yet")
@@ -110,7 +112,9 @@ func decodeValue(val []byte, encodeType byte) (*model.Span, error) {
}
// getTraces enriches TraceIDs to Traces
-func (r *TraceReader) getTraces(traceIDs []model.TraceID) ([]*model.Trace, error) {
+func (r *TraceReader) getTraces(
+ traceIDs []model.TraceID,
+) ([]*model.Trace, error) {
// Get by PK
traces := make([]*model.Trace, 0, len(traceIDs))
prefixes := make([][]byte, 0, len(traceIDs))
@@ -126,7 +130,11 @@ func (r *TraceReader) getTraces(traceIDs []model.TraceID) ([]*model.Trace, error
val := []byte{}
for _, prefix := range prefixes {
- spans := make([]*model.Span, 0, 32) // reduce reallocation requirements by defining some initial length
+ spans := make(
+ []*model.Span,
+ 0,
+ 32,
+ ) // reduce reallocation requirements by defining some initial length
for it.Seek(prefix); it.ValidForPrefix(prefix); it.Next() {
// Add value to the span store (decode from JSON / defined encoding first)
@@ -157,7 +165,10 @@ func (r *TraceReader) getTraces(traceIDs []model.TraceID) ([]*model.Trace, error
}
// GetTrace takes a traceID and returns a Trace associated with that traceID
-func (r *TraceReader) GetTrace(ctx context.Context, traceID model.TraceID) (*model.Trace, error) {
+func (r *TraceReader) GetTrace(
+ ctx context.Context,
+ traceID model.TraceID,
+) (*model.Trace, error) {
traces, err := r.getTraces([]model.TraceID{traceID})
if err != nil {
return nil, err
@@ -173,7 +184,9 @@ func (r *TraceReader) GetTrace(ctx context.Context, traceID model.TraceID) (*mod
}
// scanTimeRange returns all the Traces found between startTs and endTs
-func (r *TraceReader) scanTimeRange(plan *executionPlan) ([]model.TraceID, error) {
+func (r *TraceReader) scanTimeRange(
+ plan *executionPlan,
+) ([]model.TraceID, error) {
// We need to do a full table scan
traceKeys := make([][]byte, 0)
err := r.store.View(func(txn *badger.Txn) error {
@@ -193,7 +206,8 @@ func (r *TraceReader) scanTimeRange(plan *executionPlan) ([]model.TraceID, error
timestamp := key[sizeOfTraceID+1 : sizeOfTraceID+1+8]
traceID := key[1 : sizeOfTraceID+1]
- if bytes.Compare(timestamp, plan.startTimeMin) >= 0 && bytes.Compare(timestamp, plan.startTimeMax) <= 0 {
+ if bytes.Compare(timestamp, plan.startTimeMin) >= 0 &&
+ bytes.Compare(timestamp, plan.startTimeMax) <= 0 {
if !bytes.Equal(traceID, prevTraceID) {
if plan.hashOuter != nil {
trID := bytesToTraceID(traceID)
@@ -213,7 +227,10 @@ func (r *TraceReader) scanTimeRange(plan *executionPlan) ([]model.TraceID, error
sort.Slice(traceKeys, func(k, h int) bool {
// This sorts by timestamp to descending order
- return bytes.Compare(traceKeys[k][sizeOfTraceID+1:sizeOfTraceID+1+8], traceKeys[h][sizeOfTraceID+1:sizeOfTraceID+1+8]) > 0
+ return bytes.Compare(
+ traceKeys[k][sizeOfTraceID+1:sizeOfTraceID+1+8],
+ traceKeys[h][sizeOfTraceID+1:sizeOfTraceID+1+8],
+ ) > 0
})
sizeCount := len(traceKeys)
@@ -261,7 +278,10 @@ func setQueryDefaults(query *spanstore.TraceQueryParameters) {
}
// serviceQueries parses the query to index seeks which are unique index seeks
-func serviceQueries(query *spanstore.TraceQueryParameters, indexSeeks [][]byte) [][]byte {
+func serviceQueries(
+ query *spanstore.TraceQueryParameters,
+ indexSeeks [][]byte,
+) [][]byte {
if query.ServiceName != "" {
indexSearchKey := make([]byte, 0, 64) // 64 is a magic guess
tagQueryUsed := false
@@ -276,7 +296,9 @@ func serviceQueries(query *spanstore.TraceQueryParameters, indexSeeks [][]byte)
if query.OperationName != "" {
indexSearchKey = append(indexSearchKey, operationNameIndexKey)
- indexSearchKey = append(indexSearchKey, []byte(query.ServiceName+query.OperationName)...)
+ indexSearchKey = append(
+ indexSearchKey,
+ []byte(query.ServiceName+query.OperationName)...)
} else if !tagQueryUsed { // Tag query already reduces the search set with a serviceName
indexSearchKey = append(indexSearchKey, serviceNameIndexKey)
indexSearchKey = append(indexSearchKey, []byte(query.ServiceName)...)
@@ -290,7 +312,10 @@ func serviceQueries(query *spanstore.TraceQueryParameters, indexSeeks [][]byte)
}
// indexSeeksToTraceIDs does the index scanning against badger based on the parsed index queries
-func (r *TraceReader) indexSeeksToTraceIDs(plan *executionPlan, indexSeeks [][]byte) ([]model.TraceID, error) {
+func (r *TraceReader) indexSeeksToTraceIDs(
+ plan *executionPlan,
+ indexSeeks [][]byte,
+) ([]model.TraceID, error) {
for i := len(indexSeeks) - 1; i > 0; i-- {
indexResults, err := r.scanIndexKeys(indexSeeks[i], plan)
if err != nil {
@@ -367,7 +392,10 @@ func bytesToTraceID(key []byte) model.TraceID {
}
}
-func buildHash(plan *executionPlan, outerIDs [][]byte) map[model.TraceID]struct{} {
+func buildHash(
+ plan *executionPlan,
+ outerIDs [][]byte,
+) map[model.TraceID]struct{} {
var empty struct{}
hashed := make(map[model.TraceID]struct{})
@@ -388,7 +416,10 @@ func buildHash(plan *executionPlan, outerIDs [][]byte) map[model.TraceID]struct{
}
// durationQueries checks non unique index of durations and returns a map for further filtering purposes
-func (r *TraceReader) durationQueries(plan *executionPlan, query *spanstore.TraceQueryParameters) map[model.TraceID]struct{} {
+func (r *TraceReader) durationQueries(
+ plan *executionPlan,
+ query *spanstore.TraceQueryParameters,
+) map[model.TraceID]struct{} {
durMax := uint64(model.DurationAsMicroseconds(query.DurationMax))
durMin := uint64(model.DurationAsMicroseconds(query.DurationMin))
@@ -454,7 +485,10 @@ func mergeJoinIds(left, right [][]byte) [][]byte {
}
// FindTraces retrieves traces that match the traceQuery
-func (r *TraceReader) FindTraces(ctx context.Context, query *spanstore.TraceQueryParameters) ([]*model.Trace, error) {
+func (r *TraceReader) FindTraces(
+ ctx context.Context,
+ query *spanstore.TraceQueryParameters,
+) ([]*model.Trace, error) {
keys, err := r.FindTraceIDs(ctx, query)
if err != nil {
return nil, err
@@ -464,7 +498,10 @@ func (r *TraceReader) FindTraces(ctx context.Context, query *spanstore.TraceQuer
}
// FindTraceIDs retrieves only the TraceIDs that match the traceQuery, but not the trace data
-func (r *TraceReader) FindTraceIDs(ctx context.Context, query *spanstore.TraceQueryParameters) ([]model.TraceID, error) {
+func (r *TraceReader) FindTraceIDs(
+ ctx context.Context,
+ query *spanstore.TraceQueryParameters,
+) ([]model.TraceID, error) {
// Validate and set query defaults which were not defined
if err := validateQuery(query); err != nil {
return nil, err
@@ -477,10 +514,16 @@ func (r *TraceReader) FindTraceIDs(ctx context.Context, query *spanstore.TraceQu
indexSeeks = serviceQueries(query, indexSeeks)
startStampBytes := make([]byte, 8)
- binary.BigEndian.PutUint64(startStampBytes, model.TimeAsEpochMicroseconds(query.StartTimeMin))
+ binary.BigEndian.PutUint64(
+ startStampBytes,
+ model.TimeAsEpochMicroseconds(query.StartTimeMin),
+ )
endStampBytes := make([]byte, 8)
- binary.BigEndian.PutUint64(endStampBytes, model.TimeAsEpochMicroseconds(query.StartTimeMax))
+ binary.BigEndian.PutUint64(
+ endStampBytes,
+ model.TimeAsEpochMicroseconds(query.StartTimeMax),
+ )
plan := &executionPlan{
startTimeMin: startStampBytes,
@@ -521,14 +564,18 @@ func validateQuery(p *spanstore.TraceQueryParameters) error {
if !p.StartTimeMax.IsZero() && p.StartTimeMax.Before(p.StartTimeMin) {
return ErrStartTimeMinGreaterThanMax
}
- if p.DurationMin != 0 && p.DurationMax != 0 && p.DurationMin > p.DurationMax {
+ if p.DurationMin != 0 && p.DurationMax != 0 &&
+ p.DurationMin > p.DurationMax {
return ErrDurationMinGreaterThanMax
}
return nil
}
// scanIndexKeys scans the time range for index keys matching the given prefix.
-func (r *TraceReader) scanIndexKeys(indexKeyValue []byte, plan *executionPlan) ([][]byte, error) {
+func (r *TraceReader) scanIndexKeys(
+ indexKeyValue []byte,
+ plan *executionPlan,
+) ([][]byte, error) {
indexResults := make([][]byte, 0)
err := r.store.View(func(txn *badger.Txn) error {
@@ -549,8 +596,13 @@ func (r *TraceReader) scanIndexKeys(indexKeyValue []byte, plan *executionPlan) (
// ScanFunction is a prefix scanning (since we could have for example service1 & service12)
// Now we need to match only the exact key if we want to add it
- timestampStartIndex := len(it.Item().Key()) - (sizeOfTraceID + 8) // timestamp is stored with 8 bytes
- if bytes.Equal(indexKeyValue, it.Item().Key()[:timestampStartIndex]) {
+ timestampStartIndex := len(
+ it.Item().Key(),
+ ) - (sizeOfTraceID + 8) // timestamp is stored with 8 bytes
+ if bytes.Equal(
+ indexKeyValue,
+ it.Item().Key()[:timestampStartIndex],
+ ) {
traceIDBytes := item.Key()[len(item.Key())-sizeOfTraceID:]
traceIDCopy := make([]byte, sizeOfTraceID)
@@ -565,10 +617,16 @@ func (r *TraceReader) scanIndexKeys(indexKeyValue []byte, plan *executionPlan) (
}
// scanFunction compares the index name as well as the time range in the index key
-func scanFunction(it *badger.Iterator, indexPrefix []byte, timeBytesEnd []byte) bool {
+func scanFunction(
+ it *badger.Iterator,
+ indexPrefix []byte,
+ timeBytesEnd []byte,
+) bool {
if it.Valid() {
// We can't use the indexPrefix length, because we might have the same prefixValue for non-matching cases also
- timestampStartIndex := len(it.Item().Key()) - (sizeOfTraceID + 8) // timestamp is stored with 8 bytes
+ timestampStartIndex := len(
+ it.Item().Key(),
+ ) - (sizeOfTraceID + 8) // timestamp is stored with 8 bytes
timestamp := it.Item().Key()[timestampStartIndex : timestampStartIndex+8]
timestampInRange := bytes.Compare(timeBytesEnd, timestamp) <= 0
@@ -577,13 +635,21 @@ func scanFunction(it *badger.Iterator, indexPrefix []byte, timeBytesEnd []byte)
return false
}
- return bytes.HasPrefix(it.Item().Key()[:timestampStartIndex], indexPrefix) && timestampInRange
+ return bytes.HasPrefix(
+ it.Item().Key()[:timestampStartIndex],
+ indexPrefix,
+ ) &&
+ timestampInRange
}
return false
}
// scanRangeIndex scans the time range for index keys matching the given prefix.
-func (r *TraceReader) scanRangeIndex(plan *executionPlan, indexStartValue []byte, indexEndValue []byte) ([][]byte, error) {
+func (r *TraceReader) scanRangeIndex(
+ plan *executionPlan,
+ indexStartValue []byte,
+ indexEndValue []byte,
+) ([][]byte, error) {
indexResults := make([][]byte, 0)
err := r.store.View(func(txn *badger.Txn) error {
@@ -602,7 +668,9 @@ func (r *TraceReader) scanRangeIndex(plan *executionPlan, indexStartValue []byte
// ScanFunction is a prefix scanning (since we could have for example service1 & service12)
// Now we need to match only the exact key if we want to add it
- timestampStartIndex := len(it.Item().Key()) - (sizeOfTraceID + 8) // timestamp is stored with 8 bytes
+ timestampStartIndex := len(
+ it.Item().Key(),
+ ) - (sizeOfTraceID + 8) // timestamp is stored with 8 bytes
timestamp := it.Item().Key()[timestampStartIndex : timestampStartIndex+8]
if bytes.Compare(timestamp, plan.startTimeMax) <= 0 {
key := make([]byte, len(item.Key()))
diff --git a/plugin/storage/badger/spanstore/rw_internal_test.go b/plugin/storage/badger/spanstore/rw_internal_test.go
index 68a5f3fa2e5..050ced30c38 100644
--- a/plugin/storage/badger/spanstore/rw_internal_test.go
+++ b/plugin/storage/badger/spanstore/rw_internal_test.go
@@ -41,7 +41,10 @@ func TestEncodingTypes(t *testing.T) {
err := sw.WriteSpan(context.Background(), &testSpan)
require.NoError(t, err)
- tr, err := rw.GetTrace(context.Background(), model.TraceID{Low: 0, High: 1})
+ tr, err := rw.GetTrace(
+ context.Background(),
+ model.TraceID{Low: 0, High: 1},
+ )
require.NoError(t, err)
assert.Len(t, tr.Spans, 1)
})
@@ -84,7 +87,10 @@ func TestEncodingTypes(t *testing.T) {
return nil
})
- _, err = rw.GetTrace(context.Background(), model.TraceID{Low: 0, High: 1})
+ _, err = rw.GetTrace(
+ context.Background(),
+ model.TraceID{Low: 0, High: 1},
+ )
require.EqualError(t, err, "unknown encoding type: 0x04")
})
}
@@ -112,18 +118,23 @@ func TestDuplicateTraceIDDetection(t *testing.T) {
testSpan.TraceID.Low = rand.Uint64()
for i := 0; i < 32; i++ {
testSpan.SpanID = model.SpanID(rand.Uint64())
- testSpan.StartTime = origStartTime.Add(time.Duration(rand.Int31n(8000)) * time.Millisecond)
+ testSpan.StartTime = origStartTime.Add(
+ time.Duration(rand.Int31n(8000)) * time.Millisecond,
+ )
err := sw.WriteSpan(context.Background(), &testSpan)
require.NoError(t, err)
}
}
- traces, err := rw.FindTraceIDs(context.Background(), &spanstore.TraceQueryParameters{
- ServiceName: "service",
- NumTraces: 256, // Default is 100, we want to fetch more than there should be
- StartTimeMax: time.Now().Add(time.Hour),
- StartTimeMin: testSpan.StartTime.Add(-1 * time.Hour),
- })
+ traces, err := rw.FindTraceIDs(
+ context.Background(),
+ &spanstore.TraceQueryParameters{
+ ServiceName: "service",
+ NumTraces: 256, // Default is 100, we want to fetch more than there should be
+ StartTimeMax: time.Now().Add(time.Hour),
+ StartTimeMin: testSpan.StartTime.Add(-1 * time.Hour),
+ },
+ )
require.NoError(t, err)
assert.Len(t, traces, 128)
diff --git a/plugin/storage/badger/spanstore/writer.go b/plugin/storage/badger/spanstore/writer.go
index 0265e6c1e38..9f91003c6c2 100644
--- a/plugin/storage/badger/spanstore/writer.go
+++ b/plugin/storage/badger/spanstore/writer.go
@@ -55,7 +55,11 @@ type SpanWriter struct {
}
// NewSpanWriter returns a SpawnWriter with cache
-func NewSpanWriter(db *badger.DB, c *CacheStore, ttl time.Duration) *SpanWriter {
+func NewSpanWriter(
+ db *badger.DB,
+ c *CacheStore,
+ ttl time.Duration,
+) *SpanWriter {
return &SpanWriter{
store: db,
ttl: ttl,
@@ -70,7 +74,11 @@ func (w *SpanWriter) WriteSpan(ctx context.Context, span *model.Span) error {
startTime := model.TimeAsEpochMicroseconds(span.StartTime)
// Avoid doing as much as possible inside the transaction boundary, create entries here
- entriesToStore := make([]*badger.Entry, 0, len(span.Tags)+4+len(span.Process.Tags)+len(span.Logs)*4)
+ entriesToStore := make(
+ []*badger.Entry,
+ 0,
+ len(span.Tags)+4+len(span.Process.Tags)+len(span.Logs)*4,
+ )
trace, err := w.createTraceEntry(span, startTime, expireTime)
if err != nil {
@@ -78,27 +86,85 @@ func (w *SpanWriter) WriteSpan(ctx context.Context, span *model.Span) error {
}
entriesToStore = append(entriesToStore, trace)
- entriesToStore = append(entriesToStore, w.createBadgerEntry(createIndexKey(serviceNameIndexKey, []byte(span.Process.ServiceName), startTime, span.TraceID), nil, expireTime))
- entriesToStore = append(entriesToStore, w.createBadgerEntry(createIndexKey(operationNameIndexKey, []byte(span.Process.ServiceName+span.OperationName), startTime, span.TraceID), nil, expireTime))
+ entriesToStore = append(
+ entriesToStore,
+ w.createBadgerEntry(
+ createIndexKey(serviceNameIndexKey, []byte(span.Process.ServiceName), startTime, span.TraceID),
+ nil,
+ expireTime,
+ ),
+ )
+ entriesToStore = append(
+ entriesToStore,
+ w.createBadgerEntry(
+ createIndexKey(
+ operationNameIndexKey,
+ []byte(span.Process.ServiceName+span.OperationName),
+ startTime,
+ span.TraceID,
+ ),
+ nil,
+ expireTime,
+ ),
+ )
// It doesn't matter if we overwrite Duration index keys, everything is read at Trace level in any case
durationValue := make([]byte, 8)
binary.BigEndian.PutUint64(durationValue, uint64(model.DurationAsMicroseconds(span.Duration)))
- entriesToStore = append(entriesToStore, w.createBadgerEntry(createIndexKey(durationIndexKey, durationValue, startTime, span.TraceID), nil, expireTime))
+ entriesToStore = append(
+ entriesToStore,
+ w.createBadgerEntry(createIndexKey(durationIndexKey, durationValue, startTime, span.TraceID), nil, expireTime),
+ )
for _, kv := range span.Tags {
// Convert everything to string since queries are done that way also
// KEY: it VALUE:
- entriesToStore = append(entriesToStore, w.createBadgerEntry(createIndexKey(tagIndexKey, []byte(span.Process.ServiceName+kv.Key+kv.AsString()), startTime, span.TraceID), nil, expireTime))
+ entriesToStore = append(
+ entriesToStore,
+ w.createBadgerEntry(
+ createIndexKey(
+ tagIndexKey,
+ []byte(span.Process.ServiceName+kv.Key+kv.AsString()),
+ startTime,
+ span.TraceID,
+ ),
+ nil,
+ expireTime,
+ ),
+ )
}
for _, kv := range span.Process.Tags {
- entriesToStore = append(entriesToStore, w.createBadgerEntry(createIndexKey(tagIndexKey, []byte(span.Process.ServiceName+kv.Key+kv.AsString()), startTime, span.TraceID), nil, expireTime))
+ entriesToStore = append(
+ entriesToStore,
+ w.createBadgerEntry(
+ createIndexKey(
+ tagIndexKey,
+ []byte(span.Process.ServiceName+kv.Key+kv.AsString()),
+ startTime,
+ span.TraceID,
+ ),
+ nil,
+ expireTime,
+ ),
+ )
}
for _, log := range span.Logs {
for _, kv := range log.Fields {
- entriesToStore = append(entriesToStore, w.createBadgerEntry(createIndexKey(tagIndexKey, []byte(span.Process.ServiceName+kv.Key+kv.AsString()), startTime, span.TraceID), nil, expireTime))
+ entriesToStore = append(
+ entriesToStore,
+ w.createBadgerEntry(
+ createIndexKey(
+ tagIndexKey,
+ []byte(span.Process.ServiceName+kv.Key+kv.AsString()),
+ startTime,
+ span.TraceID,
+ ),
+ nil,
+ expireTime,
+ ),
+ )
}
}
@@ -124,7 +190,12 @@ func (w *SpanWriter) WriteSpan(ctx context.Context, span *model.Span) error {
return err
}
-func createIndexKey(indexPrefixKey byte, value []byte, startTime uint64, traceID model.TraceID) []byte {
+func createIndexKey(
+ indexPrefixKey byte,
+ value []byte,
+ startTime uint64,
+ traceID model.TraceID,
+) []byte {
// KEY: indexKey (traceId is last 16 bytes of the key)
key := make([]byte, 1+len(value)+8+sizeOfTraceID)
key[0] = (indexPrefixKey & indexKeyRange) | spanKeyPrefix
@@ -138,7 +209,11 @@ func createIndexKey(indexPrefixKey byte, value []byte, startTime uint64, traceID
return key
}
-func (*SpanWriter) createBadgerEntry(key []byte, value []byte, expireTime uint64) *badger.Entry {
+func (*SpanWriter) createBadgerEntry(
+ key []byte,
+ value []byte,
+ expireTime uint64,
+) *badger.Entry {
return &badger.Entry{
Key: key,
Value: value,
@@ -146,7 +221,10 @@ func (*SpanWriter) createBadgerEntry(key []byte, value []byte, expireTime uint64
}
}
-func (w *SpanWriter) createTraceEntry(span *model.Span, startTime, expireTime uint64) (*badger.Entry, error) {
+func (w *SpanWriter) createTraceEntry(
+ span *model.Span,
+ startTime, expireTime uint64,
+) (*badger.Entry, error) {
pK, pV, err := createTraceKV(span, w.encodingType, startTime)
if err != nil {
return nil, err
@@ -158,7 +236,11 @@ func (w *SpanWriter) createTraceEntry(span *model.Span, startTime, expireTime ui
return e, nil
}
-func createTraceKV(span *model.Span, encodingType byte, startTime uint64) ([]byte, []byte, error) {
+func createTraceKV(
+ span *model.Span,
+ encodingType byte,
+ startTime uint64,
+) ([]byte, []byte, error) {
// TODO Add Hash for Zipkin compatibility?
// Note, KEY must include startTime for proper sorting order for span-ids
@@ -184,7 +266,10 @@ func createTraceKV(span *model.Span, encodingType byte, startTime uint64) ([]byt
case jsonEncoding:
bb, err = json.Marshal(span)
default:
- return nil, nil, fmt.Errorf("unknown encoding type: %#02x", encodingType)
+ return nil, nil, fmt.Errorf(
+ "unknown encoding type: %#02x",
+ encodingType,
+ )
}
return key, bb, err
diff --git a/plugin/storage/badger/stats_linux.go b/plugin/storage/badger/stats_linux.go
index 0310a3c553d..ff5686df9c2 100644
--- a/plugin/storage/badger/stats_linux.go
+++ b/plugin/storage/badger/stats_linux.go
@@ -30,8 +30,12 @@ func (f *Factory) diskStatisticsUpdate() error {
_ = unix.Statfs(f.Options.GetPrimary().ValueDirectory, &valDirStatfs)
// Using Bavail instead of Bfree to get non-priviledged user space available
- f.metrics.ValueLogSpaceAvailable.Update(int64(valDirStatfs.Bavail) * int64(valDirStatfs.Bsize))
- f.metrics.KeyLogSpaceAvailable.Update(int64(keyDirStatfs.Bavail) * int64(keyDirStatfs.Bsize))
+ f.metrics.ValueLogSpaceAvailable.Update(
+ int64(valDirStatfs.Bavail) * int64(valDirStatfs.Bsize),
+ )
+ f.metrics.KeyLogSpaceAvailable.Update(
+ int64(keyDirStatfs.Bavail) * int64(keyDirStatfs.Bsize),
+ )
/*
TODO If we wanted to clean up oldest data to free up diskspace, we need at a minimum an index to the StartTime
diff --git a/plugin/storage/blackhole/blackhole.go b/plugin/storage/blackhole/blackhole.go
index 924203527db..50f987561d6 100644
--- a/plugin/storage/blackhole/blackhole.go
+++ b/plugin/storage/blackhole/blackhole.go
@@ -37,7 +37,11 @@ func NewStore() *Store {
}
// GetDependencies returns nothing.
-func (*Store) GetDependencies(ctx context.Context, endTs time.Time, lookback time.Duration) ([]model.DependencyLink, error) {
+func (*Store) GetDependencies(
+ ctx context.Context,
+ endTs time.Time,
+ lookback time.Duration,
+) ([]model.DependencyLink, error) {
return []model.DependencyLink{}, nil
}
@@ -47,7 +51,10 @@ func (*Store) WriteSpan(ctx context.Context, span *model.Span) error {
}
// GetTrace gets nothing.
-func (*Store) GetTrace(ctx context.Context, traceID model.TraceID) (*model.Trace, error) {
+func (*Store) GetTrace(
+ ctx context.Context,
+ traceID model.TraceID,
+) (*model.Trace, error) {
return nil, spanstore.ErrTraceNotFound
}
@@ -65,11 +72,17 @@ func (*Store) GetOperations(
}
// FindTraces returns nothing.
-func (*Store) FindTraces(ctx context.Context, query *spanstore.TraceQueryParameters) ([]*model.Trace, error) {
+func (*Store) FindTraces(
+ ctx context.Context,
+ query *spanstore.TraceQueryParameters,
+) ([]*model.Trace, error) {
return []*model.Trace{}, nil
}
// FindTraceIDs returns nothing.
-func (*Store) FindTraceIDs(ctx context.Context, query *spanstore.TraceQueryParameters) ([]model.TraceID, error) {
+func (*Store) FindTraceIDs(
+ ctx context.Context,
+ query *spanstore.TraceQueryParameters,
+) ([]model.TraceID, error) {
return []model.TraceID{}, nil
}
diff --git a/plugin/storage/blackhole/blackhole_test.go b/plugin/storage/blackhole/blackhole_test.go
index 0306897d724..15398b4397b 100644
--- a/plugin/storage/blackhole/blackhole_test.go
+++ b/plugin/storage/blackhole/blackhole_test.go
@@ -33,7 +33,11 @@ func withBlackhole(f func(store *Store)) {
func TestStoreGetDependencies(t *testing.T) {
withBlackhole(func(store *Store) {
- links, err := store.GetDependencies(context.Background(), time.Now(), time.Hour)
+ links, err := store.GetDependencies(
+ context.Background(),
+ time.Now(),
+ time.Hour,
+ )
require.NoError(t, err)
assert.Empty(t, links)
})
@@ -48,7 +52,10 @@ func TestStoreWriteSpan(t *testing.T) {
func TestStoreGetTrace(t *testing.T) {
withBlackhole(func(store *Store) {
- trace, err := store.GetTrace(context.Background(), model.NewTraceID(1, 2))
+ trace, err := store.GetTrace(
+ context.Background(),
+ model.NewTraceID(1, 2),
+ )
require.Error(t, err)
assert.Nil(t, trace)
})
diff --git a/plugin/storage/blackhole/factory.go b/plugin/storage/blackhole/factory.go
index 50cf4a9b886..80a17b90a97 100644
--- a/plugin/storage/blackhole/factory.go
+++ b/plugin/storage/blackhole/factory.go
@@ -42,7 +42,10 @@ func NewFactory() *Factory {
}
// Initialize implements storage.Factory
-func (f *Factory) Initialize(metricsFactory metrics.Factory, logger *zap.Logger) error {
+func (f *Factory) Initialize(
+ metricsFactory metrics.Factory,
+ logger *zap.Logger,
+) error {
f.metricsFactory, f.logger = metricsFactory, logger
f.store = NewStore()
logger.Info("Blackhole storage initialized")
diff --git a/plugin/storage/cassandra/dependencystore/bootstrap_test.go b/plugin/storage/cassandra/dependencystore/bootstrap_test.go
index 20f272f2794..dda0b04b085 100644
--- a/plugin/storage/cassandra/dependencystore/bootstrap_test.go
+++ b/plugin/storage/cassandra/dependencystore/bootstrap_test.go
@@ -30,7 +30,8 @@ func TestGetDependencyVersionV1(t *testing.T) {
session = &mocks.Session{}
query = &mocks.Query{}
)
- session.On("Query", mock.AnythingOfType("string"), mock.Anything).Return(query)
+ session.On("Query", mock.AnythingOfType("string"), mock.Anything).
+ Return(query)
query.On("Exec").Return(errors.New("error"))
assert.Equal(t, V1, GetDependencyVersion(session))
@@ -41,7 +42,8 @@ func TestGetDependencyVersionV2(t *testing.T) {
session = &mocks.Session{}
query = &mocks.Query{}
)
- session.On("Query", mock.AnythingOfType("string"), mock.Anything).Return(query)
+ session.On("Query", mock.AnythingOfType("string"), mock.Anything).
+ Return(query)
query.On("Exec").Return(nil)
assert.Equal(t, V2, GetDependencyVersion(session))
}
diff --git a/plugin/storage/cassandra/dependencystore/model.go b/plugin/storage/cassandra/dependencystore/model.go
index e6bbba8cad7..391ddd6b4b9 100644
--- a/plugin/storage/cassandra/dependencystore/model.go
+++ b/plugin/storage/cassandra/dependencystore/model.go
@@ -30,7 +30,10 @@ type Dependency struct {
}
// MarshalUDT handles marshalling a Dependency.
-func (d *Dependency) MarshalUDT(name string, info gocql.TypeInfo) ([]byte, error) {
+func (d *Dependency) MarshalUDT(
+ name string,
+ info gocql.TypeInfo,
+) ([]byte, error) {
switch name {
case "parent":
return gocql.Marshal(info, d.Parent)
@@ -46,7 +49,11 @@ func (d *Dependency) MarshalUDT(name string, info gocql.TypeInfo) ([]byte, error
}
// UnmarshalUDT handles unmarshalling a Dependency.
-func (d *Dependency) UnmarshalUDT(name string, info gocql.TypeInfo, data []byte) error {
+func (d *Dependency) UnmarshalUDT(
+ name string,
+ info gocql.TypeInfo,
+ data []byte,
+) error {
switch name {
case "parent":
return gocql.Unmarshal(info, data, &d.Parent)
diff --git a/plugin/storage/cassandra/dependencystore/model_test.go b/plugin/storage/cassandra/dependencystore/model_test.go
index 330a4012ec5..50bd0fda671 100644
--- a/plugin/storage/cassandra/dependencystore/model_test.go
+++ b/plugin/storage/cassandra/dependencystore/model_test.go
@@ -36,10 +36,30 @@ func TestDependencyUDT(t *testing.T) {
New: func() gocql.UDTUnmarshaler { return &Dependency{} },
ObjName: "Dependency",
Fields: []testutils.UDTField{
- {Name: "parent", Type: gocql.TypeAscii, ValIn: []byte("bi"), Err: false},
- {Name: "child", Type: gocql.TypeAscii, ValIn: []byte("ng"), Err: false},
- {Name: "call_count", Type: gocql.TypeBigInt, ValIn: []byte{0, 0, 0, 0, 0, 0, 0, 123}, Err: false},
- {Name: "source", Type: gocql.TypeAscii, ValIn: []byte("jaeger"), Err: false},
+ {
+ Name: "parent",
+ Type: gocql.TypeAscii,
+ ValIn: []byte("bi"),
+ Err: false,
+ },
+ {
+ Name: "child",
+ Type: gocql.TypeAscii,
+ ValIn: []byte("ng"),
+ Err: false,
+ },
+ {
+ Name: "call_count",
+ Type: gocql.TypeBigInt,
+ ValIn: []byte{0, 0, 0, 0, 0, 0, 0, 123},
+ Err: false,
+ },
+ {
+ Name: "source",
+ Type: gocql.TypeAscii,
+ ValIn: []byte("jaeger"),
+ Err: false,
+ },
{Name: "wrong-field", Err: true},
},
}
diff --git a/plugin/storage/cassandra/dependencystore/storage.go b/plugin/storage/cassandra/dependencystore/storage.go
index 7906f63c552..9a6c7ba899e 100644
--- a/plugin/storage/cassandra/dependencystore/storage.go
+++ b/plugin/storage/cassandra/dependencystore/storage.go
@@ -75,15 +75,21 @@ func NewDependencyStore(
return nil, errInvalidVersion
}
return &DependencyStore{
- session: session,
- dependenciesTableMetrics: casMetrics.NewTable(metricsFactory, "dependencies"),
- logger: logger,
- version: version,
+ session: session,
+ dependenciesTableMetrics: casMetrics.NewTable(
+ metricsFactory,
+ "dependencies",
+ ),
+ logger: logger,
+ version: version,
}, nil
}
// WriteDependencies implements dependencystore.Writer#WriteDependencies.
-func (s *DependencyStore) WriteDependencies(ts time.Time, dependencies []model.DependencyLink) error {
+func (s *DependencyStore) WriteDependencies(
+ ts time.Time,
+ dependencies []model.DependencyLink,
+) error {
deps := make([]Dependency, len(dependencies))
for i, d := range dependencies {
deps[i] = Dependency{
@@ -99,20 +105,34 @@ func (s *DependencyStore) WriteDependencies(ts time.Time, dependencies []model.D
case V1:
query = s.session.Query(depsInsertStmtV1, ts, ts, deps)
case V2:
- query = s.session.Query(depsInsertStmtV2, ts, ts.Truncate(tsBucket), deps)
+ query = s.session.Query(
+ depsInsertStmtV2,
+ ts,
+ ts.Truncate(tsBucket),
+ deps,
+ )
}
return s.dependenciesTableMetrics.Exec(query, s.logger)
}
// GetDependencies returns all interservice dependencies
-func (s *DependencyStore) GetDependencies(ctx context.Context, endTs time.Time, lookback time.Duration) ([]model.DependencyLink, error) {
+func (s *DependencyStore) GetDependencies(
+ ctx context.Context,
+ endTs time.Time,
+ lookback time.Duration,
+) ([]model.DependencyLink, error) {
startTs := endTs.Add(-1 * lookback)
var query cassandra.Query
switch s.version {
case V1:
query = s.session.Query(depsSelectStmtV1, startTs, endTs)
case V2:
- query = s.session.Query(depsSelectStmtV2, getBuckets(startTs, endTs), startTs, endTs)
+ query = s.session.Query(
+ depsSelectStmtV2,
+ getBuckets(startTs, endTs),
+ startTs,
+ endTs,
+ )
}
iter := query.Consistency(cassandra.One).Iter()
@@ -132,7 +152,12 @@ func (s *DependencyStore) GetDependencies(ctx context.Context, endTs time.Time,
}
if err := iter.Close(); err != nil {
- s.logger.Error("Failure to read Dependencies", zap.Time("endTs", endTs), zap.Duration("lookback", lookback), zap.Error(err))
+ s.logger.Error(
+ "Failure to read Dependencies",
+ zap.Time("endTs", endTs),
+ zap.Duration("lookback", lookback),
+ zap.Error(err),
+ )
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 eca789ba154..6b6f790d2cf 100644
--- a/plugin/storage/cassandra/dependencystore/storage_test.go
+++ b/plugin/storage/cassandra/dependencystore/storage_test.go
@@ -70,7 +70,12 @@ func TestVersionIsValid(t *testing.T) {
}
func TestInvalidVersion(t *testing.T) {
- _, err := NewDependencyStore(&mocks.Session{}, metrics.NullFactory, zap.NewNop(), versionEnumEnd)
+ _, err := NewDependencyStore(
+ &mocks.Session{},
+ metrics.NullFactory,
+ zap.NewNop(),
+ versionEnumEnd,
+ )
require.Error(t, err)
}
@@ -101,9 +106,19 @@ func TestDependencyStoreWrite(t *testing.T) {
return true
})
- s.session.On("Query", mock.AnythingOfType("string"), captureArgs).Return(query)
+ s.session.On("Query", mock.AnythingOfType("string"), captureArgs).
+ Return(query)
- ts := time.Date(2017, time.January, 24, 11, 15, 17, 12345, time.UTC)
+ ts := time.Date(
+ 2017,
+ time.January,
+ 24,
+ 11,
+ 15,
+ 17,
+ 12345,
+ time.UTC,
+ )
dependencies := []model.DependencyLink{
{
Parent: "a",
@@ -123,7 +138,20 @@ func TestDependencyStoreWrite(t *testing.T) {
}
if testCase.version == V2 {
if d, ok := args[1].(time.Time); ok {
- assert.Equal(t, time.Date(2017, time.January, 24, 0, 0, 0, 0, time.UTC), d)
+ assert.Equal(
+ t,
+ time.Date(
+ 2017,
+ time.January,
+ 24,
+ 0,
+ 0,
+ 0,
+ 0,
+ time.UTC,
+ ),
+ d,
+ )
} else {
assert.Fail(t, "expecting second arg as time", "received: %+v", args)
}
@@ -227,24 +255,55 @@ func TestDependencyStoreGetDependencies(t *testing.T) {
query.On("Consistency", cassandra.One).Return(query)
query.On("Iter").Return(iter)
- s.session.On("Query", mock.AnythingOfType("string"), matchEverything()).Return(query)
+ s.session.On("Query", mock.AnythingOfType("string"), matchEverything()).
+ Return(query)
- deps, err := s.storage.GetDependencies(context.Background(), time.Now(), 48*time.Hour)
+ deps, err := s.storage.GetDependencies(
+ context.Background(),
+ time.Now(),
+ 48*time.Hour,
+ )
if testCase.expectedError == "" {
require.NoError(t, err)
expected := []model.DependencyLink{
- {Parent: "a", Child: "b", CallCount: 1, Source: model.JaegerDependencyLinkSource},
- {Parent: "b", Child: "c", CallCount: 1, Source: model.JaegerDependencyLinkSource},
- {Parent: "a", Child: "b", CallCount: 1, Source: model.JaegerDependencyLinkSource},
- {Parent: "b", Child: "c", CallCount: 1, Source: model.JaegerDependencyLinkSource},
+ {
+ Parent: "a",
+ Child: "b",
+ CallCount: 1,
+ Source: model.JaegerDependencyLinkSource,
+ },
+ {
+ Parent: "b",
+ Child: "c",
+ CallCount: 1,
+ Source: model.JaegerDependencyLinkSource,
+ },
+ {
+ Parent: "a",
+ Child: "b",
+ CallCount: 1,
+ Source: model.JaegerDependencyLinkSource,
+ },
+ {
+ Parent: "b",
+ Child: "c",
+ CallCount: 1,
+ Source: model.JaegerDependencyLinkSource,
+ },
}
assert.Equal(t, expected, deps)
} else {
require.EqualError(t, err, testCase.expectedError)
}
for _, expectedLog := range testCase.expectedLogs {
- assert.True(t, strings.Contains(s.logBuffer.String(), expectedLog), "Log must contain %s, but was %s", expectedLog, s.logBuffer.String())
+ assert.True(
+ t,
+ strings.Contains(s.logBuffer.String(), expectedLog),
+ "Log must contain %s, but was %s",
+ expectedLog,
+ s.logBuffer.String(),
+ )
}
if len(testCase.expectedLogs) == 0 {
assert.Equal(t, "", s.logBuffer.String())
@@ -256,8 +315,26 @@ func TestDependencyStoreGetDependencies(t *testing.T) {
func TestGetBuckets(t *testing.T) {
var (
- start = time.Date(2017, time.January, 24, 11, 15, 17, 12345, time.UTC)
- end = time.Date(2017, time.January, 26, 11, 15, 17, 12345, time.UTC)
+ start = time.Date(
+ 2017,
+ time.January,
+ 24,
+ 11,
+ 15,
+ 17,
+ 12345,
+ time.UTC,
+ )
+ end = time.Date(
+ 2017,
+ time.January,
+ 26,
+ 11,
+ 15,
+ 17,
+ 12345,
+ time.UTC,
+ )
expected = []time.Time{
time.Date(2017, time.January, 24, 0, 0, 0, 0, time.UTC),
time.Date(2017, time.January, 25, 0, 0, 0, 0, time.UTC),
diff --git a/plugin/storage/cassandra/factory.go b/plugin/storage/cassandra/factory.go
index ae082e99cc5..5dc0c77b589 100644
--- a/plugin/storage/cassandra/factory.go
+++ b/plugin/storage/cassandra/factory.go
@@ -143,9 +143,16 @@ func (f *Factory) configureFromOptions(o *Options) {
}
// Initialize implements storage.Factory
-func (f *Factory) Initialize(metricsFactory metrics.Factory, logger *zap.Logger) error {
- f.primaryMetricsFactory = metricsFactory.Namespace(metrics.NSOptions{Name: "cassandra", Tags: nil})
- f.archiveMetricsFactory = metricsFactory.Namespace(metrics.NSOptions{Name: "cassandra-archive", Tags: nil})
+func (f *Factory) Initialize(
+ metricsFactory metrics.Factory,
+ logger *zap.Logger,
+) error {
+ f.primaryMetricsFactory = metricsFactory.Namespace(
+ metrics.NSOptions{Name: "cassandra", Tags: nil},
+ )
+ f.archiveMetricsFactory = metricsFactory.Namespace(
+ metrics.NSOptions{Name: "cassandra-archive", Tags: nil},
+ )
f.logger = logger
primarySession, err := f.primaryConfig.NewSession(logger)
@@ -168,7 +175,12 @@ func (f *Factory) Initialize(metricsFactory metrics.Factory, logger *zap.Logger)
// CreateSpanReader implements storage.Factory
func (f *Factory) CreateSpanReader() (spanstore.Reader, error) {
- return cSpanStore.NewSpanReader(f.primarySession, f.primaryMetricsFactory, f.logger, f.tracer.Tracer("cSpanStore.SpanReader")), nil
+ return cSpanStore.NewSpanReader(
+ f.primarySession,
+ f.primaryMetricsFactory,
+ f.logger,
+ f.tracer.Tracer("cSpanStore.SpanReader"),
+ ), nil
}
// CreateSpanWriter implements storage.Factory
@@ -177,13 +189,23 @@ func (f *Factory) CreateSpanWriter() (spanstore.Writer, error) {
if err != nil {
return nil, err
}
- return cSpanStore.NewSpanWriter(f.primarySession, f.Options.SpanStoreWriteCacheTTL, f.primaryMetricsFactory, f.logger, options...), nil
+ return cSpanStore.NewSpanWriter(
+ f.primarySession,
+ f.Options.SpanStoreWriteCacheTTL,
+ f.primaryMetricsFactory,
+ f.logger,
+ options...), nil
}
// CreateDependencyReader implements storage.Factory
func (f *Factory) CreateDependencyReader() (dependencystore.Reader, error) {
version := cDepStore.GetDependencyVersion(f.primarySession)
- return cDepStore.NewDependencyStore(f.primarySession, f.primaryMetricsFactory, f.logger, version)
+ return cDepStore.NewDependencyStore(
+ f.primarySession,
+ f.primaryMetricsFactory,
+ f.logger,
+ version,
+ )
}
// CreateArchiveSpanReader implements storage.ArchiveFactory
@@ -191,7 +213,12 @@ func (f *Factory) CreateArchiveSpanReader() (spanstore.Reader, error) {
if f.archiveSession == nil {
return nil, storage.ErrArchiveStorageNotConfigured
}
- return cSpanStore.NewSpanReader(f.archiveSession, f.archiveMetricsFactory, f.logger, f.tracer.Tracer("cSpanStore.SpanReader")), nil
+ return cSpanStore.NewSpanReader(
+ f.archiveSession,
+ f.archiveMetricsFactory,
+ f.logger,
+ f.tracer.Tracer("cSpanStore.SpanReader"),
+ ), nil
}
// CreateArchiveSpanWriter implements storage.ArchiveFactory
@@ -203,7 +230,12 @@ func (f *Factory) CreateArchiveSpanWriter() (spanstore.Writer, error) {
if err != nil {
return nil, err
}
- return cSpanStore.NewSpanWriter(f.archiveSession, f.Options.SpanStoreWriteCacheTTL, f.archiveMetricsFactory, f.logger, options...), nil
+ return cSpanStore.NewSpanWriter(
+ f.archiveSession,
+ f.Options.SpanStoreWriteCacheTTL,
+ f.archiveMetricsFactory,
+ f.logger,
+ options...), nil
}
// CreateLock implements storage.SamplingStoreFactory
@@ -212,14 +244,23 @@ func (f *Factory) CreateLock() (distributedlock.Lock, error) {
if err != nil {
return nil, err
}
- f.logger.Info("Using unique participantName in the distributed lock", zap.String("participantName", hostname))
+ f.logger.Info(
+ "Using unique participantName in the distributed lock",
+ zap.String("participantName", hostname),
+ )
return cLock.NewLock(f.primarySession, hostname), nil
}
// CreateSamplingStore implements storage.SamplingStoreFactory
-func (f *Factory) CreateSamplingStore(maxBuckets int) (samplingstore.Store, error) {
- return cSamplingStore.New(f.primarySession, f.primaryMetricsFactory, f.logger), nil
+func (f *Factory) CreateSamplingStore(
+ maxBuckets int,
+) (samplingstore.Store, error) {
+ return cSamplingStore.New(
+ f.primarySession,
+ f.primaryMetricsFactory,
+ f.logger,
+ ), nil
}
func writerOptions(opts *Options) ([]cSpanStore.Option, error) {
@@ -227,17 +268,25 @@ func writerOptions(opts *Options) ([]cSpanStore.Option, error) {
// drop all tag filters
if !opts.Index.Tags || !opts.Index.ProcessTags || !opts.Index.Logs {
- tagFilters = append(tagFilters, dbmodel.NewTagFilterDropAll(!opts.Index.Tags, !opts.Index.ProcessTags, !opts.Index.Logs))
+ tagFilters = append(
+ tagFilters,
+ dbmodel.NewTagFilterDropAll(!opts.Index.Tags, !opts.Index.ProcessTags, !opts.Index.Logs),
+ )
}
// black/white list tag filters
tagIndexBlacklist := opts.TagIndexBlacklist()
tagIndexWhitelist := opts.TagIndexWhitelist()
if len(tagIndexBlacklist) > 0 && len(tagIndexWhitelist) > 0 {
- return nil, errors.New("only one of TagIndexBlacklist and TagIndexWhitelist can be specified")
+ return nil, errors.New(
+ "only one of TagIndexBlacklist and TagIndexWhitelist can be specified",
+ )
}
if len(tagIndexBlacklist) > 0 {
- tagFilters = append(tagFilters, dbmodel.NewBlacklistFilter(tagIndexBlacklist))
+ tagFilters = append(
+ tagFilters,
+ dbmodel.NewBlacklistFilter(tagIndexBlacklist),
+ )
} else if len(tagIndexWhitelist) > 0 {
tagFilters = append(tagFilters, dbmodel.NewWhitelistFilter(tagIndexWhitelist))
}
@@ -248,7 +297,9 @@ func writerOptions(opts *Options) ([]cSpanStore.Option, error) {
return []cSpanStore.Option{cSpanStore.TagFilter(tagFilters[0])}, nil
}
- return []cSpanStore.Option{cSpanStore.TagFilter(dbmodel.NewChainedTagFilter(tagFilters...))}, nil
+ return []cSpanStore.Option{
+ cSpanStore.TagFilter(dbmodel.NewChainedTagFilter(tagFilters...)),
+ }, nil
}
var _ io.Closer = (*Factory)(nil)
diff --git a/plugin/storage/cassandra/factory_test.go b/plugin/storage/cassandra/factory_test.go
index aa52f718bd4..8d1993a6782 100644
--- a/plugin/storage/cassandra/factory_test.go
+++ b/plugin/storage/cassandra/factory_test.go
@@ -38,14 +38,19 @@ type mockSessionBuilder struct {
err error
}
-func newMockSessionBuilder(session *mocks.Session, err error) *mockSessionBuilder {
+func newMockSessionBuilder(
+ session *mocks.Session,
+ err error,
+) *mockSessionBuilder {
return &mockSessionBuilder{
session: session,
err: err,
}
}
-func (m *mockSessionBuilder) NewSession(*zap.Logger) (cassandra.Session, error) {
+func (m *mockSessionBuilder) NewSession(
+ *zap.Logger,
+) (cassandra.Session, error) {
return m.session, m.err
}
@@ -59,22 +64,35 @@ func TestCassandraFactory(t *testing.T) {
// after InitFromViper, f.primaryConfig points to a real session builder that will fail in unit tests,
// so we override it with a mock.
f.primaryConfig = newMockSessionBuilder(nil, errors.New("made-up error"))
- require.EqualError(t, f.Initialize(metrics.NullFactory, zap.NewNop()), "made-up error")
+ require.EqualError(
+ t,
+ f.Initialize(metrics.NullFactory, zap.NewNop()),
+ "made-up error",
+ )
var (
session = &mocks.Session{}
query = &mocks.Query{}
)
- session.On("Query", mock.AnythingOfType("string"), mock.Anything).Return(query)
+ session.On("Query", mock.AnythingOfType("string"), mock.Anything).
+ Return(query)
session.On("Close").Return()
query.On("Exec").Return(nil)
f.primaryConfig = newMockSessionBuilder(session, nil)
f.archiveConfig = newMockSessionBuilder(nil, errors.New("made-up error"))
- require.EqualError(t, f.Initialize(metrics.NullFactory, zap.NewNop()), "made-up error")
+ require.EqualError(
+ t,
+ f.Initialize(metrics.NullFactory, zap.NewNop()),
+ "made-up error",
+ )
f.archiveConfig = nil
require.NoError(t, f.Initialize(metrics.NullFactory, logger))
- assert.Contains(t, logBuf.String(), "Cassandra archive storage configuration is empty, skipping")
+ assert.Contains(
+ t,
+ logBuf.String(),
+ "Cassandra archive storage configuration is empty, skipping",
+ )
_, err := f.CreateSpanReader()
require.NoError(t, err)
@@ -123,30 +141,51 @@ func TestExclusiveWhitelistBlacklist(t *testing.T) {
// after InitFromViper, f.primaryConfig points to a real session builder that will fail in unit tests,
// so we override it with a mock.
f.primaryConfig = newMockSessionBuilder(nil, errors.New("made-up error"))
- require.EqualError(t, f.Initialize(metrics.NullFactory, zap.NewNop()), "made-up error")
+ require.EqualError(
+ t,
+ f.Initialize(metrics.NullFactory, zap.NewNop()),
+ "made-up error",
+ )
var (
session = &mocks.Session{}
query = &mocks.Query{}
)
- session.On("Query", mock.AnythingOfType("string"), mock.Anything).Return(query)
+ session.On("Query", mock.AnythingOfType("string"), mock.Anything).
+ Return(query)
query.On("Exec").Return(nil)
f.primaryConfig = newMockSessionBuilder(session, nil)
f.archiveConfig = newMockSessionBuilder(nil, errors.New("made-up error"))
- require.EqualError(t, f.Initialize(metrics.NullFactory, zap.NewNop()), "made-up error")
+ require.EqualError(
+ t,
+ f.Initialize(metrics.NullFactory, zap.NewNop()),
+ "made-up error",
+ )
f.archiveConfig = nil
require.NoError(t, f.Initialize(metrics.NullFactory, logger))
- assert.Contains(t, logBuf.String(), "Cassandra archive storage configuration is empty, skipping")
+ assert.Contains(
+ t,
+ logBuf.String(),
+ "Cassandra archive storage configuration is empty, skipping",
+ )
_, err := f.CreateSpanWriter()
- require.EqualError(t, err, "only one of TagIndexBlacklist and TagIndexWhitelist can be specified")
+ require.EqualError(
+ t,
+ err,
+ "only one of TagIndexBlacklist and TagIndexWhitelist can be specified",
+ )
f.archiveConfig = &mockSessionBuilder{}
require.NoError(t, f.Initialize(metrics.NullFactory, zap.NewNop()))
_, err = f.CreateArchiveSpanWriter()
- require.EqualError(t, err, "only one of TagIndexBlacklist and TagIndexWhitelist can be specified")
+ require.EqualError(
+ t,
+ err,
+ "only one of TagIndexBlacklist and TagIndexWhitelist can be specified",
+ )
}
func TestWriterOptions(t *testing.T) {
@@ -176,7 +215,12 @@ func TestWriterOptions(t *testing.T) {
opts = NewOptions("cassandra")
v, command = config.Viperize(opts.AddFlags)
- command.ParseFlags([]string{"--cassandra.index.tags=false", "--cassandra.index.tag-blacklist=a,b,c"})
+ command.ParseFlags(
+ []string{
+ "--cassandra.index.tags=false",
+ "--cassandra.index.tag-blacklist=a,b,c",
+ },
+ )
opts.InitFromViper(v)
options, _ = writerOptions(opts)
@@ -255,13 +299,19 @@ func TestFactory_Purge(t *testing.T) {
session = &mocks.Session{}
query = &mocks.Query{}
)
- session.On("Query", mock.AnythingOfType("string"), mock.Anything).Return(query)
+ session.On("Query", mock.AnythingOfType("string"), mock.Anything).
+ Return(query)
query.On("Exec").Return(nil)
f.primarySession = session
err := f.Purge(context.Background())
require.NoError(t, err)
- session.AssertCalled(t, "Query", mock.AnythingOfType("string"), mock.Anything)
+ session.AssertCalled(
+ t,
+ "Query",
+ mock.AnythingOfType("string"),
+ mock.Anything,
+ )
query.AssertCalled(t, "Exec")
}
diff --git a/plugin/storage/cassandra/options.go b/plugin/storage/cassandra/options.go
index b2e76b24710..8cf35d51c11 100644
--- a/plugin/storage/cassandra/options.go
+++ b/plugin/storage/cassandra/options.go
@@ -81,7 +81,7 @@ type IndexConfig struct {
// This struct adds a plain string field that can be bound to flags and is then parsed when
// preparing the actual config.Configuration.
type namespaceConfig struct {
- config.Configuration `mapstructure:",squash"`
+ config.Configuration ` mapstructure:",squash"`
namespace string
Enabled bool `mapstructure:"-"`
}
@@ -102,7 +102,10 @@ func NewOptions(primaryNamespace string, otherNamespaces ...string) *Options {
namespace: primaryNamespace,
Enabled: true,
},
- others: make(map[string]*namespaceConfig, len(otherNamespaces)),
+ others: make(
+ map[string]*namespaceConfig,
+ len(otherNamespaces),
+ ),
SpanStoreWriteCacheTTL: time.Hour * 12,
}
@@ -119,17 +122,21 @@ func (opt *Options) AddFlags(flagSet *flag.FlagSet) {
for _, cfg := range opt.others {
addFlags(flagSet, *cfg)
}
- flagSet.Duration(opt.Primary.namespace+suffixSpanStoreWriteCacheTTL,
+ flagSet.Duration(
+ opt.Primary.namespace+suffixSpanStoreWriteCacheTTL,
opt.SpanStoreWriteCacheTTL,
- "The duration to wait before rewriting an existing service or operation name")
+ "The duration to wait before rewriting an existing service or operation name",
+ )
flagSet.String(
opt.Primary.namespace+suffixIndexTagsBlacklist,
opt.Index.TagBlackList,
- "The comma-separated list of span tags to blacklist from being indexed. All other tags will be indexed. Mutually exclusive with the whitelist option.")
+ "The comma-separated list of span tags to blacklist from being indexed. All other tags will be indexed. Mutually exclusive with the whitelist option.",
+ )
flagSet.String(
opt.Primary.namespace+suffixIndexTagsWhitelist,
opt.Index.TagWhiteList,
- "The comma-separated list of span tags to whitelist for being indexed. All other tags will not be indexed. Mutually exclusive with the blacklist option.")
+ "The comma-separated list of span tags to whitelist for being indexed. All other tags will not be indexed. Mutually exclusive with the blacklist option.",
+ )
flagSet.Bool(
opt.Primary.namespace+suffixIndexLogs,
!opt.Index.Logs,
@@ -189,15 +196,18 @@ func addFlags(flagSet *flag.FlagSet, nsConfig namespaceConfig) {
flagSet.String(
nsConfig.namespace+suffixDC,
nsConfig.LocalDC,
- "The name of the Cassandra local data center for DC Aware host selection")
+ "The name of the Cassandra local data center for DC Aware host selection",
+ )
flagSet.String(
nsConfig.namespace+suffixConsistency,
nsConfig.Consistency,
- "The Cassandra consistency level, e.g. ANY, ONE, TWO, THREE, QUORUM, ALL, LOCAL_QUORUM, EACH_QUORUM, LOCAL_ONE (default LOCAL_ONE)")
+ "The Cassandra consistency level, e.g. ANY, ONE, TWO, THREE, QUORUM, ALL, LOCAL_QUORUM, EACH_QUORUM, LOCAL_ONE (default LOCAL_ONE)",
+ )
flagSet.Bool(
nsConfig.namespace+suffixDisableCompression,
false,
- "Disables the use of the default Snappy Compression while connecting to the Cassandra Cluster if set to true. This is useful for connecting to Cassandra Clusters(like Azure Cosmos Db with Cassandra API) that do not support SnappyCompression")
+ "Disables the use of the default Snappy Compression while connecting to the Cassandra Cluster if set to true. This is useful for connecting to Cassandra Clusters(like Azure Cosmos Db with Cassandra API) that do not support SnappyCompression",
+ )
flagSet.Int(
nsConfig.namespace+suffixProtoVer,
nsConfig.ProtoVersion,
@@ -222,12 +232,20 @@ func (opt *Options) InitFromViper(v *viper.Viper) {
for _, cfg := range opt.others {
cfg.initFromViper(v)
}
- opt.SpanStoreWriteCacheTTL = v.GetDuration(opt.Primary.namespace + suffixSpanStoreWriteCacheTTL)
- opt.Index.TagBlackList = stripWhiteSpace(v.GetString(opt.Primary.namespace + suffixIndexTagsBlacklist))
- opt.Index.TagWhiteList = stripWhiteSpace(v.GetString(opt.Primary.namespace + suffixIndexTagsWhitelist))
+ opt.SpanStoreWriteCacheTTL = v.GetDuration(
+ opt.Primary.namespace + suffixSpanStoreWriteCacheTTL,
+ )
+ opt.Index.TagBlackList = stripWhiteSpace(
+ v.GetString(opt.Primary.namespace + suffixIndexTagsBlacklist),
+ )
+ opt.Index.TagWhiteList = stripWhiteSpace(
+ v.GetString(opt.Primary.namespace + suffixIndexTagsWhitelist),
+ )
opt.Index.Tags = v.GetBool(opt.Primary.namespace + suffixIndexTags)
opt.Index.Logs = v.GetBool(opt.Primary.namespace + suffixIndexLogs)
- opt.Index.ProcessTags = v.GetBool(opt.Primary.namespace + suffixIndexProcessTags)
+ opt.Index.ProcessTags = v.GetBool(
+ opt.Primary.namespace + suffixIndexProcessTags,
+ )
}
func tlsFlagsConfig(namespace string) tlscfg.ClientFlagsConfig {
@@ -245,7 +263,9 @@ func (cfg *namespaceConfig) initFromViper(v *viper.Viper) {
cfg.MaxRetryAttempts = v.GetInt(cfg.namespace + suffixMaxRetryAttempts)
cfg.Timeout = v.GetDuration(cfg.namespace + suffixTimeout)
cfg.ConnectTimeout = v.GetDuration(cfg.namespace + suffixConnectTimeout)
- cfg.ReconnectInterval = v.GetDuration(cfg.namespace + suffixReconnectInterval)
+ cfg.ReconnectInterval = v.GetDuration(
+ cfg.namespace + suffixReconnectInterval,
+ )
servers := stripWhiteSpace(v.GetString(cfg.namespace + suffixServers))
cfg.Servers = strings.Split(servers, ",")
cfg.Port = v.GetInt(cfg.namespace + suffixPort)
@@ -254,8 +274,12 @@ func (cfg *namespaceConfig) initFromViper(v *viper.Viper) {
cfg.Consistency = v.GetString(cfg.namespace + suffixConsistency)
cfg.ProtoVersion = v.GetInt(cfg.namespace + suffixProtoVer)
cfg.SocketKeepAlive = v.GetDuration(cfg.namespace + suffixSocketKeepAlive)
- cfg.Authenticator.Basic.Username = v.GetString(cfg.namespace + suffixUsername)
- cfg.Authenticator.Basic.Password = v.GetString(cfg.namespace + suffixPassword)
+ cfg.Authenticator.Basic.Username = v.GetString(
+ cfg.namespace + suffixUsername,
+ )
+ cfg.Authenticator.Basic.Password = v.GetString(
+ cfg.namespace + suffixPassword,
+ )
cfg.DisableCompression = v.GetBool(cfg.namespace + suffixDisableCompression)
var err error
cfg.TLS, err = tlsFlagsConfig.InitFromViper(v)
diff --git a/plugin/storage/cassandra/options_test.go b/plugin/storage/cassandra/options_test.go
index 57c8ddbfe19..5a182d07347 100644
--- a/plugin/storage/cassandra/options_test.go
+++ b/plugin/storage/cassandra/options_test.go
@@ -76,8 +76,16 @@ func TestOptionsWithFlags(t *testing.T) {
assert.Equal(t, "mojave", primary.LocalDC)
assert.Equal(t, []string{"1.1.1.1", "2.2.2.2"}, primary.Servers)
assert.Equal(t, "ONE", primary.Consistency)
- assert.Equal(t, []string{"blerg", "blarg", "blorg"}, opts.TagIndexBlacklist())
- assert.Equal(t, []string{"flerg", "flarg", "florg"}, opts.TagIndexWhitelist())
+ assert.Equal(
+ t,
+ []string{"blerg", "blarg", "blorg"},
+ opts.TagIndexBlacklist(),
+ )
+ assert.Equal(
+ t,
+ []string{"flerg", "flarg", "florg"},
+ opts.TagIndexWhitelist(),
+ )
assert.True(t, opts.Index.Tags)
assert.False(t, opts.Index.ProcessTags)
assert.True(t, opts.Index.Logs)
@@ -91,7 +99,12 @@ func TestOptionsWithFlags(t *testing.T) {
assert.Equal(t, 42*time.Second, aux.Timeout)
assert.Equal(t, 42*time.Second, aux.ReconnectInterval)
assert.Equal(t, 4242, aux.Port)
- assert.Equal(t, "", aux.Consistency, "aux storage does not inherit consistency from primary")
+ assert.Equal(
+ t,
+ "",
+ aux.Consistency,
+ "aux storage does not inherit consistency from primary",
+ )
assert.Equal(t, 3, aux.ProtoVersion)
assert.Equal(t, 42*time.Second, aux.SocketKeepAlive)
}
diff --git a/plugin/storage/cassandra/samplingstore/storage.go b/plugin/storage/cassandra/samplingstore/storage.go
index 4db8308964d..ea6e24df94a 100644
--- a/plugin/storage/cassandra/samplingstore/storage.go
+++ b/plugin/storage/cassandra/samplingstore/storage.go
@@ -58,12 +58,19 @@ type SamplingStore struct {
}
// New creates a new cassandra sampling store.
-func New(session cassandra.Session, factory metrics.Factory, logger *zap.Logger) *SamplingStore {
+func New(
+ session cassandra.Session,
+ factory metrics.Factory,
+ logger *zap.Logger,
+) *SamplingStore {
return &SamplingStore{
session: session,
metrics: samplingStoreMetrics{
- operationThroughput: casMetrics.NewTable(factory, "operation_throughput"),
- probabilities: casMetrics.NewTable(factory, "probabilities"),
+ operationThroughput: casMetrics.NewTable(
+ factory,
+ "operation_throughput",
+ ),
+ probabilities: casMetrics.NewTable(factory, "probabilities"),
},
logger: logger,
}
@@ -72,13 +79,21 @@ func New(session cassandra.Session, factory metrics.Factory, logger *zap.Logger)
// InsertThroughput implements samplingstore.Writer#InsertThroughput.
func (s *SamplingStore) InsertThroughput(throughput []*model.Throughput) error {
throughputStr := throughputToString(throughput)
- query := s.session.Query(insertThroughput, generateRandomBucket(), gocql.TimeUUID(), throughputStr)
+ query := s.session.Query(
+ insertThroughput,
+ generateRandomBucket(),
+ gocql.TimeUUID(),
+ throughputStr,
+ )
return s.metrics.operationThroughput.Exec(query, s.logger)
}
// GetThroughput implements samplingstore.Reader#GetThroughput.
-func (s *SamplingStore) GetThroughput(start, end time.Time) ([]*model.Throughput, error) {
- iter := s.session.Query(getThroughput, gocql.UUIDFromTime(start), gocql.UUIDFromTime(end)).Iter()
+func (s *SamplingStore) GetThroughput(
+ start, end time.Time,
+) ([]*model.Throughput, error) {
+ iter := s.session.Query(getThroughput, gocql.UUIDFromTime(start), gocql.UUIDFromTime(end)).
+ Iter()
var throughput []*model.Throughput
var throughputStr string
for iter.Scan(&throughputStr) {
@@ -98,7 +113,13 @@ func (s *SamplingStore) InsertProbabilitiesAndQPS(
qps model.ServiceOperationQPS,
) error {
probabilitiesAndQPSStr := probabilitiesAndQPSToString(probabilities, qps)
- query := s.session.Query(insertProbabilities, constBucket, gocql.TimeUUID(), hostname, probabilitiesAndQPSStr)
+ query := s.session.Query(
+ insertProbabilities,
+ constBucket,
+ gocql.TimeUUID(),
+ hostname,
+ probabilitiesAndQPSStr,
+ )
return s.metrics.probabilities.Exec(query, s.logger)
}
@@ -119,7 +140,10 @@ func generateRandomBucket() int64 {
return time.Now().UnixNano() % 10
}
-func probabilitiesAndQPSToString(probabilities model.ServiceOperationProbabilities, qps model.ServiceOperationQPS) string {
+func probabilitiesAndQPSToString(
+ probabilities model.ServiceOperationProbabilities,
+ qps model.ServiceOperationQPS,
+) string {
var buf bytes.Buffer
writer := csv.NewWriter(&buf)
for svc, opProbabilities := range probabilities {
@@ -138,14 +162,18 @@ func probabilitiesAndQPSToString(probabilities model.ServiceOperationProbabiliti
return buf.String()
}
-func (s *SamplingStore) stringToProbabilitiesAndQPS(probabilitiesAndQPSStr string) model.ServiceOperationData {
+func (s *SamplingStore) stringToProbabilitiesAndQPS(
+ probabilitiesAndQPSStr string,
+) model.ServiceOperationData {
probabilitiesAndQPS := make(model.ServiceOperationData)
appendFunc := s.appendProbabilityAndQPS(probabilitiesAndQPS)
s.parseString(probabilitiesAndQPSStr, 4, appendFunc)
return probabilitiesAndQPS
}
-func (s *SamplingStore) stringToProbabilities(probabilitiesStr string) model.ServiceOperationProbabilities {
+func (s *SamplingStore) stringToProbabilities(
+ probabilitiesStr string,
+) model.ServiceOperationProbabilities {
probabilities := make(model.ServiceOperationProbabilities)
appendFunc := s.appendProbability(probabilities)
s.parseString(probabilitiesStr, 4, appendFunc)
@@ -156,7 +184,9 @@ func throughputToString(throughput []*model.Throughput) string {
var buf bytes.Buffer
writer := csv.NewWriter(&buf)
for _, t := range throughput {
- writer.Write([]string{t.Service, t.Operation, strconv.Itoa(int(t.Count)), probabilitiesSetToString(t.Probabilities)})
+ writer.Write(
+ []string{t.Service, t.Operation, strconv.Itoa(int(t.Count)), probabilitiesSetToString(t.Probabilities)},
+ )
}
writer.Flush()
return buf.String()
@@ -171,23 +201,35 @@ func probabilitiesSetToString(probabilities map[string]struct{}) string {
return strings.TrimSuffix(buf.String(), ",")
}
-func (s *SamplingStore) stringToThroughput(throughputStr string) []*model.Throughput {
+func (s *SamplingStore) stringToThroughput(
+ throughputStr string,
+) []*model.Throughput {
var throughput []*model.Throughput
appendFunc := s.appendThroughput(&throughput)
s.parseString(throughputStr, 4, appendFunc)
return throughput
}
-func (s *SamplingStore) appendProbabilityAndQPS(svcOpData model.ServiceOperationData) func(csvFields []string) {
+func (s *SamplingStore) appendProbabilityAndQPS(
+ svcOpData model.ServiceOperationData,
+) func(csvFields []string) {
return func(csvFields []string) {
probability, err := strconv.ParseFloat(csvFields[2], 64)
if err != nil {
- s.logger.Warn("probability cannot be parsed", zap.Any("entries", csvFields), zap.Error(err))
+ s.logger.Warn(
+ "probability cannot be parsed",
+ zap.Any("entries", csvFields),
+ zap.Error(err),
+ )
return
}
qps, err := strconv.ParseFloat(csvFields[3], 64)
if err != nil {
- s.logger.Warn("qps cannot be parsed", zap.Any("entries", csvFields), zap.Error(err))
+ s.logger.Warn(
+ "qps cannot be parsed",
+ zap.Any("entries", csvFields),
+ zap.Error(err),
+ )
return
}
service := csvFields[0]
@@ -202,11 +244,17 @@ func (s *SamplingStore) appendProbabilityAndQPS(svcOpData model.ServiceOperation
}
}
-func (s *SamplingStore) appendProbability(probabilities model.ServiceOperationProbabilities) func(csvFields []string) {
+func (s *SamplingStore) appendProbability(
+ probabilities model.ServiceOperationProbabilities,
+) func(csvFields []string) {
return func(csvFields []string) {
probability, err := strconv.ParseFloat(csvFields[2], 64)
if err != nil {
- s.logger.Warn("probability cannot be parsed", zap.Any("entries", csvFields), zap.Error(err))
+ s.logger.Warn(
+ "probability cannot be parsed",
+ zap.Any("entries", csvFields),
+ zap.Error(err),
+ )
return
}
service := csvFields[0]
@@ -218,11 +266,17 @@ func (s *SamplingStore) appendProbability(probabilities model.ServiceOperationPr
}
}
-func (s *SamplingStore) appendThroughput(throughput *[]*model.Throughput) func(csvFields []string) {
+func (s *SamplingStore) appendThroughput(
+ throughput *[]*model.Throughput,
+) func(csvFields []string) {
return func(csvFields []string) {
count, err := strconv.Atoi(csvFields[2])
if err != nil {
- s.logger.Warn("throughput count cannot be parsed", zap.Any("entries", csvFields), zap.Error(err))
+ s.logger.Warn(
+ "throughput count cannot be parsed",
+ zap.Any("entries", csvFields),
+ zap.Error(err),
+ )
return
}
*throughput = append(*throughput, &model.Throughput{
@@ -244,7 +298,11 @@ func parseProbabilitiesSet(probabilitiesStr string) map[string]struct{} {
return ret
}
-func (s *SamplingStore) parseString(str string, numColumns int, appendFunc func(csvFields []string)) {
+func (s *SamplingStore) parseString(
+ str string,
+ numColumns int,
+ appendFunc func(csvFields []string),
+) {
reader := csv.NewReader(strings.NewReader(str))
for {
csvFields, err := reader.Read()
@@ -255,7 +313,11 @@ func (s *SamplingStore) parseString(str string, numColumns int, appendFunc func(
s.logger.Error("failed to read csv", zap.Error(err))
}
if len(csvFields) != numColumns {
- s.logger.Warn("incomplete throughput data", zap.Int("expected_columns", numColumns), zap.Any("entries", csvFields))
+ s.logger.Warn(
+ "incomplete throughput data",
+ zap.Int("expected_columns", numColumns),
+ zap.Any("entries", csvFields),
+ )
continue
}
appendFunc(csvFields)
diff --git a/plugin/storage/cassandra/samplingstore/storage_test.go b/plugin/storage/cassandra/samplingstore/storage_test.go
index 9de051d15dc..b34cf8b08a1 100644
--- a/plugin/storage/cassandra/samplingstore/storage_test.go
+++ b/plugin/storage/cassandra/samplingstore/storage_test.go
@@ -68,7 +68,8 @@ func TestInsertThroughput(t *testing.T) {
return true
})
- s.session.On("Query", mock.AnythingOfType("string"), captureArgs).Return(query)
+ s.session.On("Query", mock.AnythingOfType("string"), captureArgs).
+ Return(query)
throughput := []*model.Throughput{
{
@@ -82,10 +83,20 @@ func TestInsertThroughput(t *testing.T) {
assert.Len(t, args, 3)
if _, ok := args[0].(int64); !ok {
- assert.Fail(t, "expecting first arg as int64", "received: %+v", args)
+ assert.Fail(
+ t,
+ "expecting first arg as int64",
+ "received: %+v",
+ args,
+ )
}
if _, ok := args[1].(gocql.UUID); !ok {
- assert.Fail(t, "expecting second arg as gocql.UUID", "received: %+v", args)
+ assert.Fail(
+ t,
+ "expecting second arg as gocql.UUID",
+ "received: %+v",
+ args,
+ )
}
if d, ok := args[2].(string); ok {
assert.Equal(t, "\"svc,withcomma\",\"op,withcomma\",40,\n", d)
@@ -106,7 +117,8 @@ func TestInsertProbabilitiesAndQPS(t *testing.T) {
return true
})
- s.session.On("Query", mock.AnythingOfType("string"), captureArgs).Return(query)
+ s.session.On("Query", mock.AnythingOfType("string"), captureArgs).
+ Return(query)
hostname := "hostname"
probabilities := model.ServiceOperationProbabilities{
@@ -130,7 +142,12 @@ func TestInsertProbabilitiesAndQPS(t *testing.T) {
assert.Fail(t, "expecting first arg as int", "received: %+v", args)
}
if _, ok := args[1].(gocql.UUID); !ok {
- assert.Fail(t, "expecting second arg as gocql.UUID", "received: %+v", args)
+ assert.Fail(
+ t,
+ "expecting second arg as gocql.UUID",
+ "received: %+v",
+ args,
+ )
}
if d, ok := args[2].(string); ok {
assert.Equal(t, hostname, d)
@@ -193,7 +210,8 @@ func TestGetThroughput(t *testing.T) {
query := &mocks.Query{}
query.On("Iter").Return(iter)
- s.session.On("Query", mock.AnythingOfType("string"), matchEverything()).Return(query)
+ s.session.On("Query", mock.AnythingOfType("string"), matchEverything()).
+ Return(query)
throughput, err := s.store.GetThroughput(testTime, testTime)
@@ -273,7 +291,8 @@ func TestGetLatestProbabilities(t *testing.T) {
query := &mocks.Query{}
query.On("Iter").Return(iter)
- s.session.On("Query", mock.AnythingOfType("string"), matchEverything()).Return(query)
+ s.session.On("Query", mock.AnythingOfType("string"), matchEverything()).
+ Return(query)
probabilities, err := s.store.GetLatestProbabilities()
@@ -293,22 +312,49 @@ func matchEverything() any {
}
func TestGenerateRandomBucket(t *testing.T) {
- assert.Contains(t, []int64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, generateRandomBucket())
+ assert.Contains(
+ t,
+ []int64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
+ generateRandomBucket(),
+ )
}
func TestThroughputToString(t *testing.T) {
throughput := []*model.Throughput{
- {Service: "svc1", Operation: "op,1", Count: 1, Probabilities: map[string]struct{}{"1": {}}},
- {Service: "svc2", Operation: "op2", Count: 2, Probabilities: map[string]struct{}{}},
+ {
+ Service: "svc1",
+ Operation: "op,1",
+ Count: 1,
+ Probabilities: map[string]struct{}{"1": {}},
+ },
+ {
+ Service: "svc2",
+ Operation: "op2",
+ Count: 2,
+ Probabilities: map[string]struct{}{},
+ },
}
str := throughputToString(throughput)
- assert.True(t, str == "svc1,\"op,1\",1,1\nsvc2,op2,2,\n" || str == "svc2,op2,2,\nsvc1,1\"op,1\",1,1\n")
+ assert.True(
+ t,
+ str == "svc1,\"op,1\",1,1\nsvc2,op2,2,\n" ||
+ str == "svc2,op2,2,\nsvc1,1\"op,1\",1,1\n",
+ )
throughput = []*model.Throughput{
- {Service: "svc1", Operation: "op,1", Count: 1, Probabilities: map[string]struct{}{"1": {}, "2": {}}},
+ {
+ Service: "svc1",
+ Operation: "op,1",
+ Count: 1,
+ Probabilities: map[string]struct{}{"1": {}, "2": {}},
+ },
}
str = throughputToString(throughput)
- assert.True(t, str == "svc1,\"op,1\",1,\"1,2\"\n" || str == "svc1,\"op,1\",1,\"2,1\"\n")
+ assert.True(
+ t,
+ str == "svc1,\"op,1\",1,\"1,2\"\n" ||
+ str == "svc1,\"op,1\",1,\"2,1\"\n",
+ )
}
func TestStringToThroughput(t *testing.T) {
@@ -382,12 +428,18 @@ func TestStringToProbabilities(t *testing.T) {
probabilities := s.stringToProbabilities(testStr)
assert.Len(t, probabilities, 2)
- assert.Equal(t, map[string]float64{"GET": 0.001, "PUT": 0.002}, probabilities["svc1"])
+ assert.Equal(
+ t,
+ map[string]float64{"GET": 0.001, "PUT": 0.002},
+ probabilities["svc1"],
+ )
assert.Equal(t, map[string]float64{"GET": 0.5}, probabilities["svc2"])
}
func TestProbabilitiesSetToString(t *testing.T) {
- s := probabilitiesSetToString(map[string]struct{}{"0.000001": {}, "0.000002": {}})
+ s := probabilitiesSetToString(
+ map[string]struct{}{"0.000001": {}, "0.000002": {}},
+ )
assert.True(t, s == "0.000001,0.000002" || s == "0.000002,0.000001")
assert.Equal(t, "", probabilitiesSetToString(nil))
}
diff --git a/plugin/storage/cassandra/savetracetest/main.go b/plugin/storage/cassandra/savetracetest/main.go
index 66281a56d47..d830f04e4f5 100644
--- a/plugin/storage/cassandra/savetracetest/main.go
+++ b/plugin/storage/cassandra/savetracetest/main.go
@@ -49,8 +49,18 @@ func main() {
if err != nil {
logger.Fatal("Failed to initialize tracer", zap.Error(err))
}
- spanStore := cSpanStore.NewSpanWriter(cqlSession, time.Hour*12, noScope, logger)
- spanReader := cSpanStore.NewSpanReader(cqlSession, noScope, logger, tracer.OTEL.Tracer("cSpanStore.SpanReader"))
+ spanStore := cSpanStore.NewSpanWriter(
+ cqlSession,
+ time.Hour*12,
+ noScope,
+ logger,
+ )
+ spanReader := cSpanStore.NewSpanReader(
+ cqlSession,
+ noScope,
+ logger,
+ tracer.OTEL.Tracer("cSpanStore.SpanReader"),
+ )
ctx := context.Background()
if err = spanStore.WriteSpan(ctx, getSomeSpan()); err != nil {
logger.Fatal("Failed to save", zap.Error(err))
@@ -90,7 +100,11 @@ func main() {
queryAndPrint(ctx, spanReader, tqp)
}
-func queryAndPrint(ctx context.Context, spanReader *cSpanStore.SpanReader, tqp *spanstore.TraceQueryParameters) {
+func queryAndPrint(
+ ctx context.Context,
+ spanReader *cSpanStore.SpanReader,
+ tqp *spanstore.TraceQueryParameters,
+) {
traces, err := spanReader.FindTraces(ctx, tqp)
if err != nil {
logger.Fatal("Failed to query", zap.Error(err))
diff --git a/plugin/storage/cassandra/spanstore/dbmodel/converter.go b/plugin/storage/cassandra/spanstore/dbmodel/converter.go
index 3622d345904..55af16eef0b 100644
--- a/plugin/storage/cassandra/spanstore/dbmodel/converter.go
+++ b/plugin/storage/cassandra/spanstore/dbmodel/converter.go
@@ -113,14 +113,18 @@ func (c converter) toDomain(dbSpan *Span) (*model.Span, error) {
TraceID: traceID,
SpanID: model.NewSpanID(uint64(dbSpan.SpanID)),
OperationName: dbSpan.OperationName,
- References: model.MaybeAddParentSpanID(traceID, model.NewSpanID(uint64(dbSpan.ParentID)), refs),
- Flags: model.Flags(uint32(dbSpan.Flags)),
- StartTime: model.EpochMicrosecondsAsTime(uint64(dbSpan.StartTime)),
- Duration: model.MicrosecondsAsDuration(uint64(dbSpan.Duration)),
- Tags: tags,
- Warnings: warnings,
- Logs: logs,
- Process: process,
+ References: model.MaybeAddParentSpanID(
+ traceID,
+ model.NewSpanID(uint64(dbSpan.ParentID)),
+ refs,
+ ),
+ Flags: model.Flags(uint32(dbSpan.Flags)),
+ StartTime: model.EpochMicrosecondsAsTime(uint64(dbSpan.StartTime)),
+ Duration: model.MicrosecondsAsDuration(uint64(dbSpan.Duration)),
+ Tags: tags,
+ Warnings: warnings,
+ Logs: logs,
+ Process: process,
}
return span, nil
}
diff --git a/plugin/storage/cassandra/spanstore/dbmodel/converter_test.go b/plugin/storage/cassandra/spanstore/dbmodel/converter_test.go
index 36015e3ad42..89eacf9a49a 100644
--- a/plugin/storage/cassandra/spanstore/dbmodel/converter_test.go
+++ b/plugin/storage/cassandra/spanstore/dbmodel/converter_test.go
@@ -166,7 +166,12 @@ func getTestSpan() *Span {
return span
}
-func getCustomSpan(dbTags []KeyValue, dbProcess Process, dbLogs []Log, dbRefs []SpanRef) *Span {
+func getCustomSpan(
+ dbTags []KeyValue,
+ dbProcess Process,
+ dbLogs []Log,
+ dbRefs []SpanRef,
+) *Span {
span := getTestSpan()
span.Tags = dbTags
span.Logs = dbLogs
@@ -177,10 +182,26 @@ func getCustomSpan(dbTags []KeyValue, dbProcess Process, dbLogs []Log, dbRefs []
func getTestUniqueTags() []TagInsertion {
return []TagInsertion{
- {ServiceName: "someServiceName", TagKey: "someBoolTag", TagValue: "true"},
- {ServiceName: "someServiceName", TagKey: "someDoubleTag", TagValue: "1.4"},
- {ServiceName: "someServiceName", TagKey: "someLongTag", TagValue: "123"},
- {ServiceName: "someServiceName", TagKey: "someStringTag", TagValue: "someTagValue"},
+ {
+ ServiceName: "someServiceName",
+ TagKey: "someBoolTag",
+ TagValue: "true",
+ },
+ {
+ ServiceName: "someServiceName",
+ TagKey: "someDoubleTag",
+ TagValue: "1.4",
+ },
+ {
+ ServiceName: "someServiceName",
+ TagKey: "someLongTag",
+ TagValue: "123",
+ },
+ {
+ ServiceName: "someServiceName",
+ TagKey: "someStringTag",
+ TagValue: "someTagValue",
+ },
}
}
@@ -213,7 +234,12 @@ func TestFromSpan(t *testing.T) {
}
func TestFailingFromDBSpanBadTags(t *testing.T) {
- faultyDBTags := getCustomSpan(badDBTags, someDBProcess, someDBLogs, someDBRefs)
+ faultyDBTags := getCustomSpan(
+ badDBTags,
+ someDBProcess,
+ someDBLogs,
+ someDBRefs,
+ )
failingDBSpanTransform(t, faultyDBTags, notValidTagTypeErrStr)
}
@@ -236,12 +262,17 @@ func TestFailingFromDBSpanBadProcess(t *testing.T) {
}
func TestFailingFromDBSpanBadRefs(t *testing.T) {
- faultyDBRefs := getCustomSpan(someDBTags, someDBProcess, someDBLogs, []SpanRef{
- {
- RefType: "makeOurOwnCasino",
- TraceID: someDBTraceID,
+ faultyDBRefs := getCustomSpan(
+ someDBTags,
+ someDBProcess,
+ someDBLogs,
+ []SpanRef{
+ {
+ RefType: "makeOurOwnCasino",
+ TraceID: someDBTraceID,
+ },
},
- })
+ )
failingDBSpanTransform(t, faultyDBRefs, "invalid SpanRefType in")
}
@@ -340,7 +371,14 @@ func TestFromDBWarnings(t *testing.T) {
}
func TestFailingFromDBWarnings(t *testing.T) {
- badDBWarningTags := []KeyValue{{Key: warningStringPrefix + "1", ValueType: "invalidValueType"}}
- span := getCustomSpan(badDBWarningTags, someDBProcess, someDBLogs, someDBRefs)
+ badDBWarningTags := []KeyValue{
+ {Key: warningStringPrefix + "1", ValueType: "invalidValueType"},
+ }
+ span := getCustomSpan(
+ badDBWarningTags,
+ someDBProcess,
+ someDBLogs,
+ someDBRefs,
+ )
failingDBSpanTransform(t, span, notValidTagTypeErrStr)
}
diff --git a/plugin/storage/cassandra/spanstore/dbmodel/cql_udt.go b/plugin/storage/cassandra/spanstore/dbmodel/cql_udt.go
index 0a8a6369005..550f566ea7d 100644
--- a/plugin/storage/cassandra/spanstore/dbmodel/cql_udt.go
+++ b/plugin/storage/cassandra/spanstore/dbmodel/cql_udt.go
@@ -40,7 +40,10 @@ func (t *TraceID) UnmarshalCQL(info gocql.TypeInfo, data []byte) error {
}
// MarshalUDT handles marshalling a Tag.
-func (t *KeyValue) MarshalUDT(name string, info gocql.TypeInfo) ([]byte, error) {
+func (t *KeyValue) MarshalUDT(
+ name string,
+ info gocql.TypeInfo,
+) ([]byte, error) {
switch name {
case "key":
return gocql.Marshal(info, t.Key)
@@ -62,7 +65,11 @@ func (t *KeyValue) MarshalUDT(name string, info gocql.TypeInfo) ([]byte, error)
}
// UnmarshalUDT handles unmarshalling a Tag.
-func (t *KeyValue) UnmarshalUDT(name string, info gocql.TypeInfo, data []byte) error {
+func (t *KeyValue) UnmarshalUDT(
+ name string,
+ info gocql.TypeInfo,
+ data []byte,
+) error {
switch name {
case "key":
return gocql.Unmarshal(info, data, &t.Key)
@@ -96,7 +103,11 @@ func (l *Log) MarshalUDT(name string, info gocql.TypeInfo) ([]byte, error) {
}
// UnmarshalUDT handles unmarshalling a Log.
-func (l *Log) UnmarshalUDT(name string, info gocql.TypeInfo, data []byte) error {
+func (l *Log) UnmarshalUDT(
+ name string,
+ info gocql.TypeInfo,
+ data []byte,
+) error {
switch name {
case "ts":
return gocql.Unmarshal(info, data, &l.Timestamp)
@@ -122,7 +133,11 @@ func (s *SpanRef) MarshalUDT(name string, info gocql.TypeInfo) ([]byte, error) {
}
// UnmarshalUDT handles unmarshalling a SpanRef.
-func (s *SpanRef) UnmarshalUDT(name string, info gocql.TypeInfo, data []byte) error {
+func (s *SpanRef) UnmarshalUDT(
+ name string,
+ info gocql.TypeInfo,
+ data []byte,
+) error {
switch name {
case "ref_type":
return gocql.Unmarshal(info, data, &s.RefType)
@@ -148,7 +163,11 @@ func (p *Process) MarshalUDT(name string, info gocql.TypeInfo) ([]byte, error) {
}
// UnmarshalUDT handles unmarshalling a Process.
-func (p *Process) UnmarshalUDT(name string, info gocql.TypeInfo, data []byte) error {
+func (p *Process) UnmarshalUDT(
+ name string,
+ info gocql.TypeInfo,
+ data []byte,
+) error {
switch name {
case "service_name":
return gocql.Unmarshal(info, data, &p.ServiceName)
diff --git a/plugin/storage/cassandra/spanstore/dbmodel/cql_udt_test.go b/plugin/storage/cassandra/spanstore/dbmodel/cql_udt_test.go
index 465b08086d8..36eeeb065e7 100644
--- a/plugin/storage/cassandra/spanstore/dbmodel/cql_udt_test.go
+++ b/plugin/storage/cassandra/spanstore/dbmodel/cql_udt_test.go
@@ -62,13 +62,48 @@ func TestDBModelUDTMarshall(t *testing.T) {
New: func() gocql.UDTUnmarshaler { return &KeyValue{} },
ObjName: "KeyValue",
Fields: []testutils.UDTField{
- {Name: "key", Type: gocql.TypeAscii, ValIn: []byte("key"), Err: false},
- {Name: "value_type", Type: gocql.TypeAscii, ValIn: []byte("value_type"), Err: false},
- {Name: "value_string", Type: gocql.TypeAscii, ValIn: []byte("string_value"), Err: false},
- {Name: "value_bool", Type: gocql.TypeBoolean, ValIn: []byte{1}, Err: false},
- {Name: "value_long", Type: gocql.TypeBigInt, ValIn: []byte{0, 0, 0, 0, 0, 0, 0, 123}, Err: false},
- {Name: "value_double", Type: gocql.TypeDouble, ValIn: floatBytes, Err: false},
- {Name: "value_binary", Type: gocql.TypeBlob, ValIn: []byte("value_binary"), Err: false},
+ {
+ Name: "key",
+ Type: gocql.TypeAscii,
+ ValIn: []byte("key"),
+ Err: false,
+ },
+ {
+ Name: "value_type",
+ Type: gocql.TypeAscii,
+ ValIn: []byte("value_type"),
+ Err: false,
+ },
+ {
+ Name: "value_string",
+ Type: gocql.TypeAscii,
+ ValIn: []byte("string_value"),
+ Err: false,
+ },
+ {
+ Name: "value_bool",
+ Type: gocql.TypeBoolean,
+ ValIn: []byte{1},
+ Err: false,
+ },
+ {
+ Name: "value_long",
+ Type: gocql.TypeBigInt,
+ ValIn: []byte{0, 0, 0, 0, 0, 0, 0, 123},
+ Err: false,
+ },
+ {
+ Name: "value_double",
+ Type: gocql.TypeDouble,
+ ValIn: floatBytes,
+ Err: false,
+ },
+ {
+ Name: "value_binary",
+ Type: gocql.TypeBlob,
+ ValIn: []byte("value_binary"),
+ Err: false,
+ },
{Name: "wrong-field", Err: true},
},
},
@@ -77,8 +112,17 @@ func TestDBModelUDTMarshall(t *testing.T) {
New: func() gocql.UDTUnmarshaler { return &Log{} },
ObjName: "Log",
Fields: []testutils.UDTField{
- {Name: "ts", Type: gocql.TypeBigInt, ValIn: []byte{0, 0, 0, 0, 0, 0, 0, 123}, Err: false},
- {Name: "fields", Type: gocql.TypeAscii, Err: true}, // for coverage only
+ {
+ Name: "ts",
+ Type: gocql.TypeBigInt,
+ ValIn: []byte{0, 0, 0, 0, 0, 0, 0, 123},
+ Err: false,
+ },
+ {
+ Name: "fields",
+ Type: gocql.TypeAscii,
+ Err: true,
+ }, // for coverage only
{Name: "wrong-field", Err: true},
},
},
@@ -88,7 +132,12 @@ func TestDBModelUDTMarshall(t *testing.T) {
ObjName: "SpanRef",
Fields: []testutils.UDTField{
{Name: "ref_type", Type: gocql.TypeAscii, ValIn: []byte("childOf"), Err: false},
- {Name: "trace_id", Type: gocql.TypeBlob, ValIn: []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, Err: false},
+ {
+ Name: "trace_id",
+ Type: gocql.TypeBlob,
+ ValIn: []byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1},
+ Err: false,
+ },
{Name: "span_id", Type: gocql.TypeBigInt, ValIn: []byte{0, 0, 0, 0, 0, 0, 0, 123}, Err: false},
{Name: "wrong-field", Err: true},
},
@@ -98,8 +147,17 @@ func TestDBModelUDTMarshall(t *testing.T) {
New: func() gocql.UDTUnmarshaler { return &Process{} },
ObjName: "Process",
Fields: []testutils.UDTField{
- {Name: "service_name", Type: gocql.TypeAscii, ValIn: []byte("google"), Err: false},
- {Name: "tags", Type: gocql.TypeAscii, Err: true}, // for coverage only
+ {
+ Name: "service_name",
+ Type: gocql.TypeAscii,
+ ValIn: []byte("google"),
+ Err: false,
+ },
+ {
+ Name: "tags",
+ Type: gocql.TypeAscii,
+ Err: true,
+ }, // for coverage only
{Name: "wrong-field", Err: true},
},
},
diff --git a/plugin/storage/cassandra/spanstore/dbmodel/tag_filter.go b/plugin/storage/cassandra/spanstore/dbmodel/tag_filter.go
index bb8749972d5..f5a301aea27 100644
--- a/plugin/storage/cassandra/spanstore/dbmodel/tag_filter.go
+++ b/plugin/storage/cassandra/spanstore/dbmodel/tag_filter.go
@@ -21,7 +21,10 @@ import (
// TagFilter filters out any tags that should not be indexed.
type TagFilter interface {
- FilterProcessTags(span *model.Span, processTags model.KeyValues) model.KeyValues
+ FilterProcessTags(
+ span *model.Span,
+ processTags model.KeyValues,
+ ) model.KeyValues
FilterTags(span *model.Span, tags model.KeyValues) model.KeyValues
FilterLogFields(span *model.Span, logFields model.KeyValues) model.KeyValues
}
@@ -35,7 +38,10 @@ func NewChainedTagFilter(filters ...TagFilter) ChainedTagFilter {
}
// FilterProcessTags calls each FilterProcessTags.
-func (tf ChainedTagFilter) FilterProcessTags(span *model.Span, processTags model.KeyValues) model.KeyValues {
+func (tf ChainedTagFilter) FilterProcessTags(
+ span *model.Span,
+ processTags model.KeyValues,
+) model.KeyValues {
for _, f := range tf {
processTags = f.FilterProcessTags(span, processTags)
}
@@ -43,7 +49,10 @@ func (tf ChainedTagFilter) FilterProcessTags(span *model.Span, processTags model
}
// FilterTags calls each FilterTags
-func (tf ChainedTagFilter) FilterTags(span *model.Span, tags model.KeyValues) model.KeyValues {
+func (tf ChainedTagFilter) FilterTags(
+ span *model.Span,
+ tags model.KeyValues,
+) model.KeyValues {
for _, f := range tf {
tags = f.FilterTags(span, tags)
}
@@ -51,7 +60,10 @@ func (tf ChainedTagFilter) FilterTags(span *model.Span, tags model.KeyValues) mo
}
// FilterLogFields calls each FilterLogFields
-func (tf ChainedTagFilter) FilterLogFields(span *model.Span, logFields model.KeyValues) model.KeyValues {
+func (tf ChainedTagFilter) FilterLogFields(
+ span *model.Span,
+ logFields model.KeyValues,
+) model.KeyValues {
for _, f := range tf {
logFields = f.FilterLogFields(span, logFields)
}
@@ -63,14 +75,23 @@ var DefaultTagFilter = tagFilterImpl{}
type tagFilterImpl struct{}
-func (tagFilterImpl) FilterProcessTags(span *model.Span, processTags model.KeyValues) model.KeyValues {
+func (tagFilterImpl) FilterProcessTags(
+ span *model.Span,
+ processTags model.KeyValues,
+) model.KeyValues {
return processTags
}
-func (tagFilterImpl) FilterTags(span *model.Span, tags model.KeyValues) model.KeyValues {
+func (tagFilterImpl) FilterTags(
+ span *model.Span,
+ tags model.KeyValues,
+) model.KeyValues {
return tags
}
-func (tagFilterImpl) FilterLogFields(span *model.Span, logFields model.KeyValues) model.KeyValues {
+func (tagFilterImpl) FilterLogFields(
+ span *model.Span,
+ logFields model.KeyValues,
+) model.KeyValues {
return logFields
}
diff --git a/plugin/storage/cassandra/spanstore/dbmodel/tag_filter_drop_all.go b/plugin/storage/cassandra/spanstore/dbmodel/tag_filter_drop_all.go
index c22eeafdc6b..e3980e19293 100644
--- a/plugin/storage/cassandra/spanstore/dbmodel/tag_filter_drop_all.go
+++ b/plugin/storage/cassandra/spanstore/dbmodel/tag_filter_drop_all.go
@@ -26,7 +26,11 @@ type TagFilterDropAll struct {
}
// NewTagFilterDropAll return a filter that filters all of the specified type
-func NewTagFilterDropAll(dropTags bool, dropProcessTags bool, dropLogs bool) *TagFilterDropAll {
+func NewTagFilterDropAll(
+ dropTags bool,
+ dropProcessTags bool,
+ dropLogs bool,
+) *TagFilterDropAll {
return &TagFilterDropAll{
dropTags: dropTags,
dropProcessTags: dropProcessTags,
@@ -35,7 +39,10 @@ func NewTagFilterDropAll(dropTags bool, dropProcessTags bool, dropLogs bool) *Ta
}
// FilterProcessTags implements TagFilter
-func (f *TagFilterDropAll) FilterProcessTags(span *model.Span, processTags model.KeyValues) model.KeyValues {
+func (f *TagFilterDropAll) FilterProcessTags(
+ span *model.Span,
+ processTags model.KeyValues,
+) model.KeyValues {
if f.dropProcessTags {
return model.KeyValues{}
}
@@ -43,7 +50,10 @@ func (f *TagFilterDropAll) FilterProcessTags(span *model.Span, processTags model
}
// FilterTags implements TagFilter
-func (f *TagFilterDropAll) FilterTags(span *model.Span, tags model.KeyValues) model.KeyValues {
+func (f *TagFilterDropAll) FilterTags(
+ span *model.Span,
+ tags model.KeyValues,
+) model.KeyValues {
if f.dropTags {
return model.KeyValues{}
}
@@ -51,7 +61,10 @@ func (f *TagFilterDropAll) FilterTags(span *model.Span, tags model.KeyValues) mo
}
// FilterLogFields implements TagFilter
-func (f *TagFilterDropAll) FilterLogFields(span *model.Span, logFields model.KeyValues) model.KeyValues {
+func (f *TagFilterDropAll) FilterLogFields(
+ span *model.Span,
+ logFields model.KeyValues,
+) model.KeyValues {
if f.dropLogs {
return model.KeyValues{}
}
diff --git a/plugin/storage/cassandra/spanstore/dbmodel/tag_filter_exact_match.go b/plugin/storage/cassandra/spanstore/dbmodel/tag_filter_exact_match.go
index 51917a9bff4..34dc7d10983 100644
--- a/plugin/storage/cassandra/spanstore/dbmodel/tag_filter_exact_match.go
+++ b/plugin/storage/cassandra/spanstore/dbmodel/tag_filter_exact_match.go
@@ -27,7 +27,10 @@ type ExactMatchTagFilter struct {
// newExactMatchTagFilter creates a ExactMatchTagFilter with the provided tags. Passing
// dropMatches true will exhibit blacklist behavior. Passing dropMatches false
// will exhibit whitelist behavior.
-func newExactMatchTagFilter(tags []string, dropMatches bool) ExactMatchTagFilter {
+func newExactMatchTagFilter(
+ tags []string,
+ dropMatches bool,
+) ExactMatchTagFilter {
mapTags := make(map[string]struct{})
for _, t := range tags {
mapTags[t] = struct{}{}
@@ -49,17 +52,26 @@ func NewWhitelistFilter(tags []string) ExactMatchTagFilter {
}
// FilterProcessTags implements TagFilter
-func (tf ExactMatchTagFilter) FilterProcessTags(span *model.Span, processTags model.KeyValues) model.KeyValues {
+func (tf ExactMatchTagFilter) FilterProcessTags(
+ span *model.Span,
+ processTags model.KeyValues,
+) model.KeyValues {
return tf.filter(processTags)
}
// FilterTags implements TagFilter
-func (tf ExactMatchTagFilter) FilterTags(span *model.Span, tags model.KeyValues) model.KeyValues {
+func (tf ExactMatchTagFilter) FilterTags(
+ span *model.Span,
+ tags model.KeyValues,
+) model.KeyValues {
return tf.filter(tags)
}
// FilterLogFields implements TagFilter
-func (tf ExactMatchTagFilter) FilterLogFields(span *model.Span, logFields model.KeyValues) model.KeyValues {
+func (tf ExactMatchTagFilter) FilterLogFields(
+ span *model.Span,
+ logFields model.KeyValues,
+) model.KeyValues {
return tf.filter(logFields)
}
diff --git a/plugin/storage/cassandra/spanstore/dbmodel/tag_filter_test.go b/plugin/storage/cassandra/spanstore/dbmodel/tag_filter_test.go
index e9c872f9eb3..2820fc54668 100644
--- a/plugin/storage/cassandra/spanstore/dbmodel/tag_filter_test.go
+++ b/plugin/storage/cassandra/spanstore/dbmodel/tag_filter_test.go
@@ -28,16 +28,22 @@ func TestDefaultTagFilter(t *testing.T) {
span := getTestJaegerSpan()
expectedTags := append(append(someTags, someTags...), someTags...)
filteredTags := DefaultTagFilter.FilterProcessTags(span, span.Process.Tags)
- filteredTags = append(filteredTags, DefaultTagFilter.FilterTags(span, span.Tags)...)
+ filteredTags = append(
+ filteredTags,
+ DefaultTagFilter.FilterTags(span, span.Tags)...)
for _, log := range span.Logs {
- filteredTags = append(filteredTags, DefaultTagFilter.FilterLogFields(span, log.Fields)...)
+ filteredTags = append(
+ filteredTags,
+ DefaultTagFilter.FilterLogFields(span, log.Fields)...)
}
compareTags(t, expectedTags, filteredTags)
}
type onlyStringsFilter struct{}
-func (onlyStringsFilter) filterStringTags(tags model.KeyValues) model.KeyValues {
+func (onlyStringsFilter) filterStringTags(
+ tags model.KeyValues,
+) model.KeyValues {
var ret model.KeyValues
for _, tag := range tags {
if tag.VType == model.StringType {
@@ -47,20 +53,31 @@ func (onlyStringsFilter) filterStringTags(tags model.KeyValues) model.KeyValues
return ret
}
-func (f onlyStringsFilter) FilterProcessTags(span *model.Span, processTags model.KeyValues) model.KeyValues {
+func (f onlyStringsFilter) FilterProcessTags(
+ span *model.Span,
+ processTags model.KeyValues,
+) model.KeyValues {
return f.filterStringTags(processTags)
}
-func (f onlyStringsFilter) FilterTags(span *model.Span, tags model.KeyValues) model.KeyValues {
+func (f onlyStringsFilter) FilterTags(
+ span *model.Span,
+ tags model.KeyValues,
+) model.KeyValues {
return f.filterStringTags(tags)
}
-func (f onlyStringsFilter) FilterLogFields(span *model.Span, logFields model.KeyValues) model.KeyValues {
+func (f onlyStringsFilter) FilterLogFields(
+ span *model.Span,
+ logFields model.KeyValues,
+) model.KeyValues {
return f.filterStringTags(logFields)
}
func TestChainedTagFilter(t *testing.T) {
- expectedTags := model.KeyValues{model.String(someStringTagKey, someStringTagValue)}
+ expectedTags := model.KeyValues{
+ model.String(someStringTagKey, someStringTagValue),
+ }
filter := NewChainedTagFilter(DefaultTagFilter, onlyStringsFilter{})
filteredTags := filter.FilterProcessTags(nil, someTags)
compareTags(t, expectedTags, filteredTags)
diff --git a/plugin/storage/cassandra/spanstore/dbmodel/unique_tags.go b/plugin/storage/cassandra/spanstore/dbmodel/unique_tags.go
index 191a64db948..24d63561b6c 100644
--- a/plugin/storage/cassandra/spanstore/dbmodel/unique_tags.go
+++ b/plugin/storage/cassandra/spanstore/dbmodel/unique_tags.go
@@ -21,10 +21,14 @@ import (
// GetAllUniqueTags creates a list of all unique tags from a set of filtered tags.
func GetAllUniqueTags(span *model.Span, tagFilter TagFilter) []TagInsertion {
- allTags := append(model.KeyValues{}, tagFilter.FilterProcessTags(span, span.Process.Tags)...)
+ allTags := append(
+ model.KeyValues{},
+ tagFilter.FilterProcessTags(span, span.Process.Tags)...)
allTags = append(allTags, tagFilter.FilterTags(span, span.Tags)...)
for _, log := range span.Logs {
- allTags = append(allTags, tagFilter.FilterLogFields(span, log.Fields)...)
+ allTags = append(
+ allTags,
+ tagFilter.FilterLogFields(span, log.Fields)...)
}
allTags.Sort()
uniqueTags := make([]TagInsertion, 0, len(allTags))
diff --git a/plugin/storage/cassandra/spanstore/operation_names.go b/plugin/storage/cassandra/spanstore/operation_names.go
index 167dcbd1c19..09460d71db4 100644
--- a/plugin/storage/cassandra/spanstore/operation_names.go
+++ b/plugin/storage/cassandra/spanstore/operation_names.go
@@ -115,7 +115,10 @@ func NewOperationNamesStorage(
session: session,
schemaVersion: schemaVersion,
table: table,
- metrics: casMetrics.NewTable(metricsFactory, schemas[schemaVersion].tableName),
+ metrics: casMetrics.NewTable(
+ metricsFactory,
+ schemas[schemaVersion].tableName,
+ ),
writeCacheTTL: writeCacheTTL,
logger: logger,
operationNames: cache.NewLRUWithOptions(
@@ -207,7 +210,11 @@ func getOperationsV2(
})
}
if err := iter.Close(); err != nil {
- err = fmt.Errorf("error reading %s from storage: %w", s.table.tableName, err)
+ 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 63ccfd005e1..c382c3777d1 100644
--- a/plugin/storage/cassandra/spanstore/operation_names_test.go
+++ b/plugin/storage/cassandra/spanstore/operation_names_test.go
@@ -50,8 +50,14 @@ func withOperationNamesStorage(writeCacheTTL time.Duration,
logger, logBuffer := testutils.NewLogger()
metricsFactory := metricstest.NewFactory(0)
query := &mocks.Query{}
- session.On("Query",
- fmt.Sprintf(tableCheckStmt, schemas[latestVersion].tableName), mock.Anything).Return(query)
+ session.On(
+ "Query",
+ fmt.Sprintf(
+ tableCheckStmt,
+ schemas[latestVersion].tableName,
+ ),
+ mock.Anything,
+ ).Return(query)
if schemaVersion != latestVersion {
query.On("Exec").Return(errors.New("new table does not exist"))
} else {
@@ -64,7 +70,12 @@ func withOperationNamesStorage(writeCacheTTL time.Duration,
metricsFactory: metricsFactory,
logger: logger,
logBuffer: logBuffer,
- storage: NewOperationNamesStorage(session, writeCacheTTL, metricsFactory, logger),
+ storage: NewOperationNamesStorage(
+ session,
+ writeCacheTTL,
+ metricsFactory,
+ logger,
+ ),
}
fn(s)
}
@@ -81,70 +92,78 @@ func TestOperationNamesStorageWrite(t *testing.T) {
{name: "test new schema with 1min ttl", ttl: time.Minute, schemaVersion: latestVersion},
} {
t.Run(test.name, func(t *testing.T) {
- withOperationNamesStorage(test.ttl, test.schemaVersion, func(s *operationNameStorageTest) {
- execError := errors.New("exec error")
- query := &mocks.Query{}
- query1 := &mocks.Query{}
- query2 := &mocks.Query{}
-
- if test.schemaVersion == previousVersion {
- query.On("Bind", []any{"service-a", "Operation-b"}).Return(query1)
- query.On("Bind", []any{"service-c", "operation-d"}).Return(query2)
- } else {
- query.On("Bind", []any{"service-a", "", "Operation-b"}).Return(query1)
- query.On("Bind", []any{"service-c", "", "operation-d"}).Return(query2)
- }
-
- query1.On("Exec").Return(nil)
- query2.On("Exec").Return(execError)
- query2.On("String").Return("select from " + schemas[test.schemaVersion].tableName)
-
- s.session.On("Query", mock.AnythingOfType("string"), mock.Anything).Return(query)
-
- err := s.storage.Write(dbmodel.Operation{
- ServiceName: "service-a",
- OperationName: "Operation-b",
- })
- require.NoError(t, err)
-
- err = s.storage.Write(dbmodel.Operation{
- ServiceName: "service-c",
- OperationName: "operation-d",
- })
- require.EqualError(t, err,
- "failed to Exec query 'select from "+
- schemas[test.schemaVersion].tableName+
- "': exec error")
- assert.Equal(t, map[string]string{
- "level": "error",
- "msg": "Failed to exec query",
- "query": "select from " + schemas[test.schemaVersion].tableName,
- "error": "exec error",
- }, s.logBuffer.JSONLine(0))
-
- counts, _ := s.metricsFactory.Snapshot()
- assert.Equal(t, map[string]int64{
- "attempts|table=" + schemas[test.schemaVersion].tableName: 2,
- "inserts|table=" + schemas[test.schemaVersion].tableName: 1,
- "errors|table=" + schemas[test.schemaVersion].tableName: 1,
- }, counts, "after first two writes")
-
- // write again
- err = s.storage.Write(dbmodel.Operation{
- ServiceName: "service-a",
- OperationName: "Operation-b",
- })
- require.NoError(t, err)
-
- counts2, _ := s.metricsFactory.Snapshot()
- expCounts := counts
- if test.ttl == 0 {
- // without write cache, the second write must succeed
- expCounts["attempts|table="+schemas[test.schemaVersion].tableName]++
- expCounts["inserts|table="+schemas[test.schemaVersion].tableName]++
- }
- assert.Equal(t, expCounts, counts2)
- })
+ withOperationNamesStorage(
+ test.ttl,
+ test.schemaVersion,
+ func(s *operationNameStorageTest) {
+ execError := errors.New("exec error")
+ query := &mocks.Query{}
+ query1 := &mocks.Query{}
+ query2 := &mocks.Query{}
+
+ if test.schemaVersion == previousVersion {
+ query.On("Bind", []any{"service-a", "Operation-b"}).
+ Return(query1)
+ query.On("Bind", []any{"service-c", "operation-d"}).
+ Return(query2)
+ } else {
+ query.On("Bind", []any{"service-a", "", "Operation-b"}).Return(query1)
+ query.On("Bind", []any{"service-c", "", "operation-d"}).Return(query2)
+ }
+
+ query1.On("Exec").Return(nil)
+ query2.On("Exec").Return(execError)
+ query2.On("String").
+ Return("select from " + schemas[test.schemaVersion].tableName)
+
+ s.session.On("Query", mock.AnythingOfType("string"), mock.Anything).
+ Return(query)
+
+ err := s.storage.Write(dbmodel.Operation{
+ ServiceName: "service-a",
+ OperationName: "Operation-b",
+ })
+ require.NoError(t, err)
+
+ err = s.storage.Write(dbmodel.Operation{
+ ServiceName: "service-c",
+ OperationName: "operation-d",
+ })
+ require.EqualError(t, err,
+ "failed to Exec query 'select from "+
+ schemas[test.schemaVersion].tableName+
+ "': exec error")
+ assert.Equal(t, map[string]string{
+ "level": "error",
+ "msg": "Failed to exec query",
+ "query": "select from " + schemas[test.schemaVersion].tableName,
+ "error": "exec error",
+ }, s.logBuffer.JSONLine(0))
+
+ counts, _ := s.metricsFactory.Snapshot()
+ assert.Equal(t, map[string]int64{
+ "attempts|table=" + schemas[test.schemaVersion].tableName: 2,
+ "inserts|table=" + schemas[test.schemaVersion].tableName: 1,
+ "errors|table=" + schemas[test.schemaVersion].tableName: 1,
+ }, counts, "after first two writes")
+
+ // write again
+ err = s.storage.Write(dbmodel.Operation{
+ ServiceName: "service-a",
+ OperationName: "Operation-b",
+ })
+ require.NoError(t, err)
+
+ counts2, _ := s.metricsFactory.Snapshot()
+ expCounts := counts
+ if test.ttl == 0 {
+ // without write cache, the second write must succeed
+ expCounts["attempts|table="+schemas[test.schemaVersion].tableName]++
+ expCounts["inserts|table="+schemas[test.schemaVersion].tableName]++
+ }
+ assert.Equal(t, expCounts, counts2)
+ },
+ )
})
}
}
@@ -162,44 +181,55 @@ func TestOperationNamesStorageGetServices(t *testing.T) {
{name: "test new schema with scan error", schemaVersion: latestVersion, expErr: scanError},
} {
t.Run(test.name, func(t *testing.T) {
- withOperationNamesStorage(0, test.schemaVersion, func(s *operationNameStorageTest) {
- var matched bool
- matchOnce := mock.MatchedBy(func(v []any) bool {
- if matched {
- return false
- }
- matched = true
- return true
- })
- matchEverything := mock.MatchedBy(func(v []any) bool { return true })
-
- iter := &mocks.Iterator{}
- iter.On("Scan", matchOnce).Return(true)
- iter.On("Scan", matchEverything).Return(false) // false to stop the loop
- iter.On("Close").Return(test.expErr)
-
- query := &mocks.Query{}
- query.On("Iter").Return(iter)
-
- s.session.On("Query", mock.AnythingOfType("string"), mock.Anything).Return(query)
- services, err := s.storage.GetOperations(spanstore.OperationQueryParameters{
- ServiceName: "service-a",
- })
- if test.expErr == nil {
- require.NoError(t, err)
- // expect one empty operation result
- // because mock iter.Scan(&placeholder) does not write to `placeholder`
- assert.Equal(t, []spanstore.Operation{{}}, services)
- } else {
- require.EqualError(
- t,
- err,
- fmt.Sprintf("error reading %s from storage: %s",
- schemas[test.schemaVersion].tableName,
- test.expErr.Error()),
+ withOperationNamesStorage(
+ 0,
+ test.schemaVersion,
+ func(s *operationNameStorageTest) {
+ var matched bool
+ matchOnce := mock.MatchedBy(func(v []any) bool {
+ if matched {
+ return false
+ }
+ matched = true
+ return true
+ })
+ matchEverything := mock.MatchedBy(
+ func(v []any) bool { return true },
)
- }
- })
+
+ iter := &mocks.Iterator{}
+ iter.On("Scan", matchOnce).Return(true)
+ iter.On("Scan", matchEverything).
+ Return(false)
+ // false to stop the loop
+ iter.On("Close").Return(test.expErr)
+
+ query := &mocks.Query{}
+ query.On("Iter").Return(iter)
+
+ s.session.On("Query", mock.AnythingOfType("string"), mock.Anything).
+ Return(query)
+ services, err := s.storage.GetOperations(
+ spanstore.OperationQueryParameters{
+ ServiceName: "service-a",
+ },
+ )
+ if test.expErr == nil {
+ require.NoError(t, err)
+ // expect one empty operation result
+ // because mock iter.Scan(&placeholder) does not write to `placeholder`
+ assert.Equal(t, []spanstore.Operation{{}}, services)
+ } else {
+ require.EqualError(
+ t,
+ err,
+ 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 1f32be79c62..48d61b77785 100644
--- a/plugin/storage/cassandra/spanstore/reader.go
+++ b/plugin/storage/cassandra/spanstore/reader.go
@@ -76,16 +76,22 @@ var (
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")
// 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")
@@ -121,20 +127,50 @@ func NewSpanReader(
logger *zap.Logger,
tracer trace.Tracer,
) *SpanReader {
- readFactory := metricsFactory.Namespace(metrics.NSOptions{Name: "read", Tags: nil})
- serviceNamesStorage := NewServiceNamesStorage(session, 0, metricsFactory, logger)
- operationNamesStorage := NewOperationNamesStorage(session, 0, metricsFactory, logger)
+ readFactory := metricsFactory.Namespace(
+ metrics.NSOptions{Name: "read", Tags: nil},
+ )
+ serviceNamesStorage := NewServiceNamesStorage(
+ session,
+ 0,
+ metricsFactory,
+ logger,
+ )
+ operationNamesStorage := NewOperationNamesStorage(
+ session,
+ 0,
+ metricsFactory,
+ logger,
+ )
return &SpanReader{
session: session,
serviceNamesReader: serviceNamesStorage.GetServices,
operationNamesReader: operationNamesStorage.GetOperations,
metrics: spanReaderMetrics{
- readTraces: casMetrics.NewTable(readFactory, "read_traces"),
- queryTrace: casMetrics.NewTable(readFactory, "query_traces"),
- queryTagIndex: casMetrics.NewTable(readFactory, "tag_index"),
- queryDurationIndex: casMetrics.NewTable(readFactory, "duration_index"),
- queryServiceOperationIndex: casMetrics.NewTable(readFactory, "service_operation_index"),
- queryServiceNameIndex: casMetrics.NewTable(readFactory, "service_name_index"),
+ readTraces: casMetrics.NewTable(
+ readFactory,
+ "read_traces",
+ ),
+ queryTrace: casMetrics.NewTable(
+ readFactory,
+ "query_traces",
+ ),
+ queryTagIndex: casMetrics.NewTable(
+ readFactory,
+ "tag_index",
+ ),
+ queryDurationIndex: casMetrics.NewTable(
+ readFactory,
+ "duration_index",
+ ),
+ queryServiceOperationIndex: casMetrics.NewTable(
+ readFactory,
+ "service_operation_index",
+ ),
+ queryServiceNameIndex: casMetrics.NewTable(
+ readFactory,
+ "service_name_index",
+ ),
},
logger: logger,
tracer: tracer,
@@ -154,7 +190,10 @@ func (s *SpanReader) GetOperations(
return s.operationNamesReader(query)
}
-func (s *SpanReader) readTrace(ctx context.Context, traceID dbmodel.TraceID) (*model.Trace, error) {
+func (s *SpanReader) readTrace(
+ ctx context.Context,
+ traceID dbmodel.TraceID,
+) (*model.Trace, error) {
ctx, span := s.startSpanForQuery(ctx, "readTrace", querySpanByTraceID)
defer span.End()
span.SetAttributes(attribute.Key("trace_id").String(traceID.String()))
@@ -164,7 +203,10 @@ func (s *SpanReader) readTrace(ctx context.Context, traceID dbmodel.TraceID) (*m
return trace, err
}
-func (s *SpanReader) readTraceInSpan(ctx context.Context, traceID dbmodel.TraceID) (*model.Trace, error) {
+func (s *SpanReader) readTraceInSpan(
+ ctx context.Context,
+ traceID dbmodel.TraceID,
+) (*model.Trace, error) {
start := time.Now()
q := s.session.Query(querySpanByTraceID, traceID)
i := q.Iter()
@@ -212,7 +254,10 @@ func (s *SpanReader) readTraceInSpan(ctx context.Context, traceID dbmodel.TraceI
}
// GetTrace takes a traceID and returns a Trace associated with that traceID
-func (s *SpanReader) GetTrace(ctx context.Context, traceID model.TraceID) (*model.Trace, error) {
+func (s *SpanReader) GetTrace(
+ ctx context.Context,
+ traceID model.TraceID,
+) (*model.Trace, error) {
return s.readTrace(ctx, dbmodel.TraceIDFromDomain(traceID))
}
@@ -226,10 +271,12 @@ func validateQuery(p *spanstore.TraceQueryParameters) error {
if p.StartTimeMin.IsZero() || p.StartTimeMax.IsZero() {
return ErrStartAndEndTimeNotSet
}
- if !p.StartTimeMin.IsZero() && !p.StartTimeMax.IsZero() && p.StartTimeMax.Before(p.StartTimeMin) {
+ if !p.StartTimeMin.IsZero() && !p.StartTimeMax.IsZero() &&
+ p.StartTimeMax.Before(p.StartTimeMin) {
return ErrStartTimeMinGreaterThanMax
}
- if p.DurationMin != 0 && p.DurationMax != 0 && p.DurationMin > p.DurationMax {
+ if p.DurationMin != 0 && p.DurationMax != 0 &&
+ p.DurationMin > p.DurationMax {
return ErrDurationMinGreaterThanMax
}
if (p.DurationMin != 0 || p.DurationMax != 0) && len(p.Tags) > 0 {
@@ -239,7 +286,10 @@ func validateQuery(p *spanstore.TraceQueryParameters) error {
}
// FindTraces retrieves traces that match the traceQuery
-func (s *SpanReader) FindTraces(ctx context.Context, traceQuery *spanstore.TraceQueryParameters) ([]*model.Trace, error) {
+func (s *SpanReader) FindTraces(
+ ctx context.Context,
+ traceQuery *spanstore.TraceQueryParameters,
+) ([]*model.Trace, error) {
uniqueTraceIDs, err := s.FindTraceIDs(ctx, traceQuery)
if err != nil {
return nil, err
@@ -248,7 +298,11 @@ func (s *SpanReader) FindTraces(ctx context.Context, traceQuery *spanstore.Trace
for _, traceID := range uniqueTraceIDs {
jTrace, err := s.GetTrace(ctx, traceID)
if err != nil {
- s.logger.Error("Failure to read trace", zap.String("trace_id", traceID.String()), zap.Error(err))
+ s.logger.Error(
+ "Failure to read trace",
+ zap.String("trace_id", traceID.String()),
+ zap.Error(err),
+ )
continue
}
retMe = append(retMe, jTrace)
@@ -257,7 +311,10 @@ func (s *SpanReader) FindTraces(ctx context.Context, traceQuery *spanstore.Trace
}
// FindTraceIDs retrieve traceIDs that match the traceQuery
-func (s *SpanReader) FindTraceIDs(ctx context.Context, traceQuery *spanstore.TraceQueryParameters) ([]model.TraceID, error) {
+func (s *SpanReader) FindTraceIDs(
+ ctx context.Context,
+ traceQuery *spanstore.TraceQueryParameters,
+) ([]model.TraceID, error) {
if err := validateQuery(traceQuery); err != nil {
return nil, err
}
@@ -280,7 +337,10 @@ func (s *SpanReader) FindTraceIDs(ctx context.Context, traceQuery *spanstore.Tra
return traceIDs, nil
}
-func (s *SpanReader) findTraceIDs(ctx context.Context, traceQuery *spanstore.TraceQueryParameters) (dbmodel.UniqueTraceIDs, error) {
+func (s *SpanReader) findTraceIDs(
+ ctx context.Context,
+ traceQuery *spanstore.TraceQueryParameters,
+) (dbmodel.UniqueTraceIDs, error) {
if traceQuery.DurationMin != 0 || traceQuery.DurationMax != 0 {
return s.queryByDuration(ctx, traceQuery)
}
@@ -308,7 +368,10 @@ func (s *SpanReader) findTraceIDs(ctx context.Context, traceQuery *spanstore.Tra
return s.queryByService(ctx, traceQuery)
}
-func (s *SpanReader) queryByTagsAndLogs(ctx context.Context, tq *spanstore.TraceQueryParameters) (dbmodel.UniqueTraceIDs, error) {
+func (s *SpanReader) queryByTagsAndLogs(
+ ctx context.Context,
+ tq *spanstore.TraceQueryParameters,
+) (dbmodel.UniqueTraceIDs, error) {
ctx, span := s.startSpanForQuery(ctx, "queryByTagsAndLogs", queryByTag)
defer span.End()
@@ -338,16 +401,25 @@ func (s *SpanReader) queryByTagsAndLogs(ctx context.Context, tq *spanstore.Trace
return dbmodel.IntersectTraceIDs(results), nil
}
-func (s *SpanReader) queryByDuration(ctx context.Context, traceQuery *spanstore.TraceQueryParameters) (dbmodel.UniqueTraceIDs, error) {
+func (s *SpanReader) queryByDuration(
+ ctx context.Context,
+ traceQuery *spanstore.TraceQueryParameters,
+) (dbmodel.UniqueTraceIDs, error) {
ctx, span := s.startSpanForQuery(ctx, "queryByDuration", queryByDuration)
defer span.End()
results := dbmodel.UniqueTraceIDs{}
- minDurationMicros := traceQuery.DurationMin.Nanoseconds() / int64(time.Microsecond/time.Nanosecond)
- maxDurationMicros := (time.Hour * 24).Nanoseconds() / int64(time.Microsecond/time.Nanosecond)
+ minDurationMicros := traceQuery.DurationMin.Nanoseconds() / int64(
+ time.Microsecond/time.Nanosecond,
+ )
+ maxDurationMicros := (time.Hour * 24).Nanoseconds() / int64(
+ time.Microsecond/time.Nanosecond,
+ )
if traceQuery.DurationMax != 0 {
- maxDurationMicros = traceQuery.DurationMax.Nanoseconds() / int64(time.Microsecond/time.Nanosecond)
+ maxDurationMicros = traceQuery.DurationMax.Nanoseconds() / int64(
+ time.Microsecond/time.Nanosecond,
+ )
}
// See writer.go:indexByDuration for how this is indexed
@@ -357,7 +429,9 @@ func (s *SpanReader) queryByDuration(ctx context.Context, traceQuery *spanstore.
for timeBucket := endTimeByHour; timeBucket.After(startTimeByHour) || timeBucket.Equal(startTimeByHour); timeBucket = timeBucket.Add(-1 * durationBucketSize) {
_, childSpan := s.tracer.Start(ctx, "queryForTimeBucket")
- childSpan.SetAttributes(attribute.Key("timeBucket").String(timeBucket.String()))
+ childSpan.SetAttributes(
+ attribute.Key("timeBucket").String(timeBucket.String()),
+ )
query := s.session.Query(
queryByDuration,
timeBucket,
@@ -382,7 +456,10 @@ func (s *SpanReader) queryByDuration(ctx context.Context, traceQuery *spanstore.
return results, nil
}
-func (s *SpanReader) queryByServiceNameAndOperation(ctx context.Context, tq *spanstore.TraceQueryParameters) (dbmodel.UniqueTraceIDs, error) {
+func (s *SpanReader) queryByServiceNameAndOperation(
+ ctx context.Context,
+ tq *spanstore.TraceQueryParameters,
+) (dbmodel.UniqueTraceIDs, error) {
_, span := s.startSpanForQuery(ctx, "queryByServiceNameAndOperation", queryByServiceAndOperationName)
defer span.End()
query := s.session.Query(
@@ -396,7 +473,10 @@ func (s *SpanReader) queryByServiceNameAndOperation(ctx context.Context, tq *spa
return s.executeQuery(span, query, s.metrics.queryServiceOperationIndex)
}
-func (s *SpanReader) queryByService(ctx context.Context, tq *spanstore.TraceQueryParameters) (dbmodel.UniqueTraceIDs, error) {
+func (s *SpanReader) queryByService(
+ ctx context.Context,
+ tq *spanstore.TraceQueryParameters,
+) (dbmodel.UniqueTraceIDs, error) {
_, span := s.startSpanForQuery(ctx, "queryByService", queryByServiceAndOperationName)
defer span.End()
query := s.session.Query(
@@ -409,7 +489,11 @@ func (s *SpanReader) queryByService(ctx context.Context, tq *spanstore.TraceQuer
return s.executeQuery(span, query, s.metrics.queryServiceNameIndex)
}
-func (s *SpanReader) executeQuery(span trace.Span, query cassandra.Query, tableMetrics *casMetrics.Table) (dbmodel.UniqueTraceIDs, error) {
+func (s *SpanReader) executeQuery(
+ span trace.Span,
+ query cassandra.Query,
+ tableMetrics *casMetrics.Table,
+) (dbmodel.UniqueTraceIDs, error) {
start := time.Now()
i := query.Iter()
retMe := dbmodel.UniqueTraceIDs{}
@@ -421,13 +505,20 @@ func (s *SpanReader) executeQuery(span trace.Span, query cassandra.Query, tableM
tableMetrics.Emit(err, time.Since(start))
if err != nil {
logErrorToSpan(span, err)
- s.logger.Error("Failed to exec query", zap.Error(err), zap.String("query", query.String()))
+ s.logger.Error(
+ "Failed to exec query",
+ zap.Error(err),
+ zap.String("query", query.String()),
+ )
return nil, err
}
return retMe, nil
}
-func (s *SpanReader) startSpanForQuery(ctx context.Context, name, query string) (context.Context, trace.Span) {
+func (s *SpanReader) startSpanForQuery(
+ ctx context.Context,
+ name, query string,
+) (context.Context, trace.Span) {
ctx, span := s.tracer.Start(ctx, name)
span.SetAttributes(
attribute.Key(semconv.DBStatementKey).String(query),
diff --git a/plugin/storage/cassandra/spanstore/reader_test.go b/plugin/storage/cassandra/spanstore/reader_test.go
index 816b0db9745..f35a1a44195 100644
--- a/plugin/storage/cassandra/spanstore/reader_test.go
+++ b/plugin/storage/cassandra/spanstore/reader_test.go
@@ -47,7 +47,9 @@ type spanReaderTest struct {
reader *SpanReader
}
-func tracerProvider(t *testing.T) (trace.TracerProvider, *tracetest.InMemoryExporter, func()) {
+func tracerProvider(
+ t *testing.T,
+) (trace.TracerProvider, *tracetest.InMemoryExporter, func()) {
exporter := tracetest.NewInMemoryExporter()
tp := sdktrace.NewTracerProvider(
sdktrace.WithSampler(sdktrace.AlwaysSample()),
@@ -75,7 +77,12 @@ func withSpanReader(t *testing.T, fn func(r *spanReaderTest)) {
logger: logger,
logBuffer: logBuffer,
traceBuffer: exp,
- reader: NewSpanReader(session, metricsFactory, logger, tracer.Tracer("test")),
+ reader: NewSpanReader(
+ session,
+ metricsFactory,
+ logger,
+ tracer.Tracer("test"),
+ ),
}
fn(r)
}
@@ -102,8 +109,13 @@ func TestSpanReaderGetOperations(t *testing.T) {
r.reader.operationNamesReader = func(parameters spanstore.OperationQueryParameters) ([]spanstore.Operation, error) {
return expectedOperations, nil
}
- s, err := r.reader.GetOperations(context.Background(),
- spanstore.OperationQueryParameters{ServiceName: "service-x", SpanKind: "server"})
+ s, err := r.reader.GetOperations(
+ context.Background(),
+ spanstore.OperationQueryParameters{
+ ServiceName: "service-x",
+ SpanKind: "server",
+ },
+ )
require.NoError(t, err)
assert.Equal(t, expectedOperations, s)
})
@@ -150,11 +162,19 @@ func TestSpanReaderGetTrace(t *testing.T) {
query.On("Consistency", cassandra.One).Return(query)
query.On("Iter").Return(iter)
- r.session.On("Query", mock.AnythingOfType("string"), matchEverything()).Return(query)
+ r.session.On("Query", mock.AnythingOfType("string"), matchEverything()).
+ Return(query)
- trace, err := r.reader.GetTrace(context.Background(), model.TraceID{})
+ trace, err := r.reader.GetTrace(
+ context.Background(),
+ model.TraceID{},
+ )
if testCase.expectedErr == "" {
- require.NotEmpty(t, r.traceBuffer.GetSpans(), "Spans recorded")
+ require.NotEmpty(
+ t,
+ r.traceBuffer.GetSpans(),
+ "Spans recorded",
+ )
require.NoError(t, err)
assert.NotNil(t, trace)
} else {
@@ -177,7 +197,8 @@ func TestSpanReaderGetTrace_TraceNotFound(t *testing.T) {
query.On("Consistency", cassandra.One).Return(query)
query.On("Iter").Return(iter)
- r.session.On("Query", mock.AnythingOfType("string"), matchEverything()).Return(query)
+ r.session.On("Query", mock.AnythingOfType("string"), matchEverything()).
+ Return(query)
trace, err := r.reader.GetTrace(context.Background(), model.TraceID{})
require.NotEmpty(t, r.traceBuffer.GetSpans(), "Spans recorded")
@@ -256,11 +277,13 @@ func TestSpanReaderFindTraces(t *testing.T) {
expectedCount: 2,
},
{
- caption: "operation name and tag error on operation query",
- queryTags: true,
- queryOperation: true,
- serviceNameAndOperationQueryError: errors.New("operation query error"),
- expectedError: "operation query error",
+ caption: "operation name and tag error on operation query",
+ queryTags: true,
+ queryOperation: true,
+ serviceNameAndOperationQueryError: errors.New(
+ "operation query error",
+ ),
+ expectedError: "operation query error",
expectedLogs: []string{
"Failed to exec query",
"operation query error",
@@ -349,19 +372,23 @@ func TestSpanReaderFindTraces(t *testing.T) {
mainQuery := mockQuery(testCase.mainQueryError)
tagsQuery := mockQuery(testCase.tagsQueryError)
- operationQuery := mockQuery(testCase.serviceNameAndOperationQueryError)
+ operationQuery := mockQuery(
+ testCase.serviceNameAndOperationQueryError,
+ )
durationQuery := mockQuery(testCase.durationQueryError)
makeLoadQuery := func() *mocks.Query {
loadQueryIter := &mocks.Iterator{}
- loadQueryIter.On("Scan", scanMatcher("loadIter")).Return(true)
+ loadQueryIter.On("Scan", scanMatcher("loadIter")).
+ Return(true)
loadQueryIter.On("Scan", matchEverything()).Return(false)
loadQueryIter.On("Close").Return(testCase.loadQueryError)
loadQuery := &mocks.Query{}
loadQuery.On("Consistency", cassandra.One).Return(loadQuery)
loadQuery.On("Iter").Return(loadQueryIter)
- loadQuery.On("PageSize", matchEverything()).Return(loadQuery)
+ loadQuery.On("PageSize", matchEverything()).
+ Return(loadQuery)
return loadQuery
}
@@ -403,11 +430,23 @@ func TestSpanReaderFindTraces(t *testing.T) {
queryParams.DurationMin = time.Minute
queryParams.DurationMax = time.Minute * 3
}
- res, err := r.reader.FindTraces(context.Background(), queryParams)
+ res, err := r.reader.FindTraces(
+ context.Background(),
+ queryParams,
+ )
if testCase.expectedError == "" {
- require.NotEmpty(t, r.traceBuffer.GetSpans(), "Spans recorded")
+ require.NotEmpty(
+ t,
+ r.traceBuffer.GetSpans(),
+ "Spans recorded",
+ )
require.NoError(t, err)
- assert.Len(t, res, testCase.expectedCount, "expecting certain number of traces")
+ assert.Len(
+ t,
+ res,
+ testCase.expectedCount,
+ "expecting certain number of traces",
+ )
} else {
require.EqualError(t, err, testCase.expectedError)
}
diff --git a/plugin/storage/cassandra/spanstore/service_names.go b/plugin/storage/cassandra/spanstore/service_names.go
index 6013573d64b..2f23482b54d 100644
--- a/plugin/storage/cassandra/spanstore/service_names.go
+++ b/plugin/storage/cassandra/spanstore/service_names.go
@@ -81,7 +81,11 @@ func (s *ServiceNamesStorage) Write(serviceName string) error {
}
// checks if the key is in cache; returns true if it is, otherwise puts it there and returns false
-func checkWriteCache(key string, c cache.Cache, writeCacheTTL time.Duration) bool {
+func checkWriteCache(
+ key string,
+ c cache.Cache,
+ writeCacheTTL time.Duration,
+) bool {
if writeCacheTTL == 0 {
return false
}
diff --git a/plugin/storage/cassandra/spanstore/service_names_test.go b/plugin/storage/cassandra/spanstore/service_names_test.go
index 3c35dc402af..ed7e08764a6 100644
--- a/plugin/storage/cassandra/spanstore/service_names_test.go
+++ b/plugin/storage/cassandra/spanstore/service_names_test.go
@@ -40,7 +40,10 @@ type serviceNameStorageTest struct {
storage *ServiceNamesStorage
}
-func withServiceNamesStorage(writeCacheTTL time.Duration, fn func(s *serviceNameStorageTest)) {
+func withServiceNamesStorage(
+ writeCacheTTL time.Duration,
+ fn func(s *serviceNameStorageTest),
+) {
session := &mocks.Session{}
logger, logBuffer := testutils.NewLogger()
metricsFactory := metricstest.NewFactory(time.Second)
@@ -51,7 +54,12 @@ func withServiceNamesStorage(writeCacheTTL time.Duration, fn func(s *serviceName
metricsFactory: metricsFactory,
logger: logger,
logBuffer: logBuffer,
- storage: NewServiceNamesStorage(session, writeCacheTTL, metricsFactory, logger),
+ storage: NewServiceNamesStorage(
+ session,
+ writeCacheTTL,
+ metricsFactory,
+ logger,
+ ),
}
fn(s)
}
@@ -59,51 +67,62 @@ func withServiceNamesStorage(writeCacheTTL time.Duration, fn func(s *serviceName
func TestServiceNamesStorageWrite(t *testing.T) {
for _, ttl := range []time.Duration{0, time.Minute} {
writeCacheTTL := ttl // capture loop var
- t.Run(fmt.Sprintf("writeCacheTTL=%v", writeCacheTTL), func(t *testing.T) {
- withServiceNamesStorage(writeCacheTTL, func(s *serviceNameStorageTest) {
- execError := errors.New("exec error")
- query := &mocks.Query{}
- query1 := &mocks.Query{}
- query2 := &mocks.Query{}
- query.On("Bind", []any{"service-a"}).Return(query1)
- query.On("Bind", []any{"service-b"}).Return(query2)
- query1.On("Exec").Return(nil)
- query2.On("Exec").Return(execError)
- query2.On("String").Return("select from service_names")
-
- var emptyArgs []any
- s.session.On("Query", mock.AnythingOfType("string"), emptyArgs).Return(query)
-
- err := s.storage.Write("service-a")
- require.NoError(t, err)
- err = s.storage.Write("service-b")
- require.EqualError(t, err, "failed to Exec query 'select from service_names': exec error")
- assert.Equal(t, map[string]string{
- "level": "error",
- "msg": "Failed to exec query",
- "query": "select from service_names",
- "error": "exec error",
- }, s.logBuffer.JSONLine(0))
-
- counts, _ := s.metricsFactory.Snapshot()
- assert.Equal(t, map[string]int64{
- "attempts|table=service_names": 2, "inserts|table=service_names": 1, "errors|table=service_names": 1,
- }, counts)
-
- // write again
- err = s.storage.Write("service-a")
- require.NoError(t, err)
-
- counts2, _ := s.metricsFactory.Snapshot()
- expCounts := counts
- if writeCacheTTL == 0 {
- // without write cache, the second write must succeed
- expCounts["attempts|table=service_names"]++
- expCounts["inserts|table=service_names"]++
- }
- assert.Equal(t, expCounts, counts2)
- })
- })
+ t.Run(
+ fmt.Sprintf("writeCacheTTL=%v", writeCacheTTL),
+ func(t *testing.T) {
+ withServiceNamesStorage(
+ writeCacheTTL,
+ func(s *serviceNameStorageTest) {
+ execError := errors.New("exec error")
+ query := &mocks.Query{}
+ query1 := &mocks.Query{}
+ query2 := &mocks.Query{}
+ query.On("Bind", []any{"service-a"}).Return(query1)
+ query.On("Bind", []any{"service-b"}).Return(query2)
+ query1.On("Exec").Return(nil)
+ query2.On("Exec").Return(execError)
+ query2.On("String").Return("select from service_names")
+
+ var emptyArgs []any
+ s.session.On("Query", mock.AnythingOfType("string"), emptyArgs).
+ Return(query)
+
+ err := s.storage.Write("service-a")
+ require.NoError(t, err)
+ err = s.storage.Write("service-b")
+ require.EqualError(
+ t,
+ err,
+ "failed to Exec query 'select from service_names': exec error",
+ )
+ assert.Equal(t, map[string]string{
+ "level": "error",
+ "msg": "Failed to exec query",
+ "query": "select from service_names",
+ "error": "exec error",
+ }, s.logBuffer.JSONLine(0))
+
+ counts, _ := s.metricsFactory.Snapshot()
+ assert.Equal(t, map[string]int64{
+ "attempts|table=service_names": 2, "inserts|table=service_names": 1, "errors|table=service_names": 1,
+ }, counts)
+
+ // write again
+ err = s.storage.Write("service-a")
+ require.NoError(t, err)
+
+ counts2, _ := s.metricsFactory.Snapshot()
+ expCounts := counts
+ if writeCacheTTL == 0 {
+ // without write cache, the second write must succeed
+ expCounts["attempts|table=service_names"]++
+ expCounts["inserts|table=service_names"]++
+ }
+ assert.Equal(t, expCounts, counts2)
+ },
+ )
+ },
+ )
}
}
@@ -123,14 +142,17 @@ func TestServiceNamesStorageGetServices(t *testing.T) {
withServiceNamesStorage(writeCacheTTL, func(s *serviceNameStorageTest) {
iter := &mocks.Iterator{}
iter.On("Scan", matchOnce).Return(true)
- iter.On("Scan", matchEverything).Return(false) // false to stop the loop
+ iter.On("Scan", matchEverything).
+ Return(false)
+ // false to stop the loop
iter.On("Close").Return(expErr)
query := &mocks.Query{}
query.On("Iter").Return(iter)
var emptyArgs []any
- s.session.On("Query", mock.AnythingOfType("string"), emptyArgs).Return(query)
+ s.session.On("Query", mock.AnythingOfType("string"), emptyArgs).
+ Return(query)
services, err := s.storage.GetServices()
if expErr == nil {
diff --git a/plugin/storage/cassandra/spanstore/writer.go b/plugin/storage/cassandra/spanstore/writer.go
index 615dfcedbc3..4e370bda18a 100644
--- a/plugin/storage/cassandra/spanstore/writer.go
+++ b/plugin/storage/cassandra/spanstore/writer.go
@@ -108,20 +108,47 @@ func NewSpanWriter(
logger *zap.Logger,
options ...Option,
) *SpanWriter {
- serviceNamesStorage := NewServiceNamesStorage(session, writeCacheTTL, metricsFactory, logger)
- operationNamesStorage := NewOperationNamesStorage(session, writeCacheTTL, metricsFactory, logger)
- tagIndexSkipped := metricsFactory.Counter(metrics.Options{Name: "tag_index_skipped", Tags: nil})
+ serviceNamesStorage := NewServiceNamesStorage(
+ session,
+ writeCacheTTL,
+ metricsFactory,
+ logger,
+ )
+ operationNamesStorage := NewOperationNamesStorage(
+ session,
+ writeCacheTTL,
+ metricsFactory,
+ logger,
+ )
+ tagIndexSkipped := metricsFactory.Counter(
+ metrics.Options{Name: "tag_index_skipped", Tags: nil},
+ )
opts := applyOptions(options...)
return &SpanWriter{
session: session,
serviceNamesWriter: serviceNamesStorage.Write,
operationNamesWriter: operationNamesStorage.Write,
writerMetrics: spanWriterMetrics{
- traces: casMetrics.NewTable(metricsFactory, "traces"),
- tagIndex: casMetrics.NewTable(metricsFactory, "tag_index"),
- serviceNameIndex: casMetrics.NewTable(metricsFactory, "service_name_index"),
- serviceOperationIndex: casMetrics.NewTable(metricsFactory, "service_operation_index"),
- durationIndex: casMetrics.NewTable(metricsFactory, "duration_index"),
+ traces: casMetrics.NewTable(
+ metricsFactory,
+ "traces",
+ ),
+ tagIndex: casMetrics.NewTable(
+ metricsFactory,
+ "tag_index",
+ ),
+ serviceNameIndex: casMetrics.NewTable(
+ metricsFactory,
+ "service_name_index",
+ ),
+ serviceOperationIndex: casMetrics.NewTable(
+ metricsFactory,
+ "service_operation_index",
+ ),
+ durationIndex: casMetrics.NewTable(
+ metricsFactory,
+ "duration_index",
+ ),
},
logger: logger,
tagIndexSkipped: tagIndexSkipped,
@@ -183,7 +210,12 @@ func (s *SpanWriter) writeIndexes(span *model.Span, ds *dbmodel.Span) error {
OperationName: ds.OperationName,
}); err != nil {
// should this be a soft failure?
- return s.logError(ds, err, "Failed to insert service name and operation name", s.logger)
+ return s.logError(
+ ds,
+ err,
+ "Failed to insert service name and operation name",
+ s.logger,
+ )
}
if s.indexFilter(ds, dbmodel.ServiceIndex) {
@@ -194,7 +226,12 @@ func (s *SpanWriter) writeIndexes(span *model.Span, ds *dbmodel.Span) error {
if s.indexFilter(ds, dbmodel.OperationIndex) {
if err := s.indexByOperation(ds); err != nil {
- return s.logError(ds, err, "Failed to index operation name", s.logger)
+ return s.logError(
+ ds,
+ err,
+ "Failed to index operation name",
+ s.logger,
+ )
}
}
@@ -219,7 +256,15 @@ func (s *SpanWriter) indexByTags(span *model.Span, ds *dbmodel.Span) error {
// we should introduce retries or just ignore failures imo, retrying each individual tag insertion might be better
// we should consider bucketing.
if s.shouldIndexTag(v) {
- insertTagQuery := s.session.Query(tagIndex, ds.TraceID, ds.SpanID, v.ServiceName, ds.StartTime, v.TagKey, v.TagValue)
+ insertTagQuery := s.session.Query(
+ tagIndex,
+ ds.TraceID,
+ ds.SpanID,
+ v.ServiceName,
+ ds.StartTime,
+ v.TagKey,
+ v.TagValue,
+ )
if err := s.writerMetrics.tagIndex.Exec(insertTagQuery, s.logger); err != nil {
withTagInfo := s.logger.
With(zap.String("tag_key", v.TagKey)).
@@ -234,32 +279,54 @@ func (s *SpanWriter) indexByTags(span *model.Span, ds *dbmodel.Span) error {
return nil
}
-func (s *SpanWriter) indexByDuration(span *dbmodel.Span, startTime time.Time) error {
+func (s *SpanWriter) indexByDuration(
+ span *dbmodel.Span,
+ startTime time.Time,
+) error {
query := s.session.Query(durationIndex)
timeBucket := startTime.Round(durationBucketSize)
var err error
indexByOperationName := func(operationName string) {
- q1 := query.Bind(span.Process.ServiceName, operationName, timeBucket, span.Duration, span.StartTime, span.TraceID)
+ q1 := query.Bind(
+ span.Process.ServiceName,
+ operationName,
+ timeBucket,
+ span.Duration,
+ span.StartTime,
+ span.TraceID,
+ )
if err2 := s.writerMetrics.durationIndex.Exec(q1, s.logger); err2 != nil {
_ = s.logError(span, err2, "Cannot index duration", s.logger)
err = err2
}
}
- indexByOperationName("") // index by service name alone
- indexByOperationName(span.OperationName) // index by service name and operation name
+ indexByOperationName("") // index by service name alone
+ indexByOperationName(
+ span.OperationName,
+ ) // index by service name and operation name
return err
}
func (s *SpanWriter) indexByService(span *dbmodel.Span) error {
bucketNo := uint64(span.SpanHash) % defaultNumBuckets
query := s.session.Query(serviceNameIndex)
- q := query.Bind(span.Process.ServiceName, bucketNo, span.StartTime, span.TraceID)
+ q := query.Bind(
+ span.Process.ServiceName,
+ bucketNo,
+ span.StartTime,
+ span.TraceID,
+ )
return s.writerMetrics.serviceNameIndex.Exec(q, s.logger)
}
func (s *SpanWriter) indexByOperation(span *dbmodel.Span) error {
query := s.session.Query(serviceOperationIndex)
- q := query.Bind(span.Process.ServiceName, span.OperationName, span.StartTime, span.TraceID)
+ q := query.Bind(
+ span.Process.ServiceName,
+ span.OperationName,
+ span.StartTime,
+ span.TraceID,
+ )
return s.writerMetrics.serviceOperationIndex.Exec(q, s.logger)
}
@@ -268,7 +335,8 @@ func (*SpanWriter) shouldIndexTag(tag dbmodel.TagInsertion) bool {
isJSON := func(s string) bool {
var js json.RawMessage
// poor man's string-is-a-json check shortcircuits full unmarshalling
- return strings.HasPrefix(s, "{") && json.Unmarshal([]byte(s), &js) == nil
+ return strings.HasPrefix(s, "{") &&
+ json.Unmarshal([]byte(s), &js) == nil
}
return len(tag.TagKey) < maximumTagKeyOrValueSize &&
@@ -278,7 +346,12 @@ func (*SpanWriter) shouldIndexTag(tag dbmodel.TagInsertion) bool {
!isJSON(tag.TagValue)
}
-func (*SpanWriter) logError(span *dbmodel.Span, err error, msg string, logger *zap.Logger) error {
+func (*SpanWriter) logError(
+ span *dbmodel.Span,
+ err error,
+ msg string,
+ logger *zap.Logger,
+) error {
logger.
With(zap.String("trace_id", span.TraceID.String())).
With(zap.Int64("span_id", span.SpanID)).
@@ -287,7 +360,9 @@ func (*SpanWriter) logError(span *dbmodel.Span, err error, msg string, logger *z
return fmt.Errorf("%s: %w", msg, err)
}
-func (s *SpanWriter) saveServiceNameAndOperationName(operation dbmodel.Operation) error {
+func (s *SpanWriter) saveServiceNameAndOperationName(
+ operation dbmodel.Operation,
+) error {
if err := s.serviceNamesWriter(operation.ServiceName); err != nil {
return err
}
diff --git a/plugin/storage/cassandra/spanstore/writer_options_test.go b/plugin/storage/cassandra/spanstore/writer_options_test.go
index efe73ee782e..9cb3db2fa12 100644
--- a/plugin/storage/cassandra/spanstore/writer_options_test.go
+++ b/plugin/storage/cassandra/spanstore/writer_options_test.go
@@ -24,7 +24,10 @@ import (
)
func TestWriterOptions(t *testing.T) {
- opts := applyOptions(TagFilter(dbmodel.DefaultTagFilter), IndexFilter(dbmodel.DefaultIndexFilter))
+ opts := applyOptions(
+ TagFilter(dbmodel.DefaultTagFilter),
+ IndexFilter(dbmodel.DefaultIndexFilter),
+ )
assert.Equal(t, dbmodel.DefaultTagFilter, opts.tagFilter)
assert.ObjectsAreEqual(dbmodel.DefaultIndexFilter, opts.indexFilter)
}
diff --git a/plugin/storage/cassandra/spanstore/writer_test.go b/plugin/storage/cassandra/spanstore/writer_test.go
index 80e65debdaf..051e3af1779 100644
--- a/plugin/storage/cassandra/spanstore/writer_test.go
+++ b/plugin/storage/cassandra/spanstore/writer_test.go
@@ -44,7 +44,10 @@ type spanWriterTest struct {
writer *SpanWriter
}
-func withSpanWriter(writeCacheTTL time.Duration, fn func(w *spanWriterTest), options ...Option,
+func withSpanWriter(
+ writeCacheTTL time.Duration,
+ fn func(w *spanWriterTest),
+ options ...Option,
) {
session := &mocks.Session{}
query := &mocks.Query{}
@@ -58,7 +61,12 @@ func withSpanWriter(writeCacheTTL time.Duration, fn func(w *spanWriterTest), opt
session: session,
logger: logger,
logBuffer: logBuffer,
- writer: NewSpanWriter(session, writeCacheTTL, metricsFactory, logger, options...),
+ writer: NewSpanWriter(
+ session,
+ writeCacheTTL,
+ metricsFactory,
+ logger,
+ options...),
}
fn(w)
}
@@ -138,9 +146,11 @@ func TestSpanWriter(t *testing.T) {
},
},
{
- caption: "add span to operation name index",
- serviceOperationNameQueryError: errors.New("serviceOperationNameQueryError"),
- expectedError: "Failed to index operation name: failed to Exec query 'select from service_operation_index': serviceOperationNameQueryError",
+ caption: "add span to operation name index",
+ serviceOperationNameQueryError: errors.New(
+ "serviceOperationNameQueryError",
+ ),
+ expectedError: "Failed to index operation name: failed to Exec query 'select from service_operation_index': serviceOperationNameQueryError",
expectedLogs: []string{
`"msg":"Failed to exec query"`,
`"query":"select from service_operation_index"`,
@@ -148,9 +158,11 @@ func TestSpanWriter(t *testing.T) {
},
},
{
- caption: "add duration with no operation name",
- durationNoOperationQueryError: errors.New("durationNoOperationError"),
- expectedError: "Failed to index duration: failed to Exec query 'select from duration_index': durationNoOperationError",
+ caption: "add duration with no operation name",
+ durationNoOperationQueryError: errors.New(
+ "durationNoOperationError",
+ ),
+ expectedError: "Failed to index duration: failed to Exec query 'select from duration_index': durationNoOperationError",
expectedLogs: []string{
`"msg":"Failed to exec query"`,
`"query":"select from duration_index"`,
@@ -167,7 +179,10 @@ func TestSpanWriter(t *testing.T) {
OperationName: "operation-a",
Tags: model.KeyValues{
model.String("x", "y"),
- model.String("json", `{"x":"y"}`), // string tag with json value will not be inserted
+ model.String(
+ "json",
+ `{"x":"y"}`,
+ ), // string tag with json value will not be inserted
},
Process: &model.Process{
ServiceName: "service-a",
@@ -183,31 +198,43 @@ func TestSpanWriter(t *testing.T) {
spanQuery.On("String").Return("select from traces")
serviceNameQuery := &mocks.Query{}
- serviceNameQuery.On("Bind", matchEverything()).Return(serviceNameQuery)
- serviceNameQuery.On("Exec").Return(testCase.serviceNameQueryError)
- serviceNameQuery.On("String").Return("select from service_name_index")
+ serviceNameQuery.On("Bind", matchEverything()).
+ Return(serviceNameQuery)
+ serviceNameQuery.On("Exec").
+ Return(testCase.serviceNameQueryError)
+ serviceNameQuery.On("String").
+ Return("select from service_name_index")
serviceOperationNameQuery := &mocks.Query{}
- serviceOperationNameQuery.On("Bind", matchEverything()).Return(serviceOperationNameQuery)
- serviceOperationNameQuery.On("Exec").Return(testCase.serviceOperationNameQueryError)
- serviceOperationNameQuery.On("String").Return("select from service_operation_index")
+ serviceOperationNameQuery.On("Bind", matchEverything()).
+ Return(serviceOperationNameQuery)
+ serviceOperationNameQuery.On("Exec").
+ Return(testCase.serviceOperationNameQueryError)
+ serviceOperationNameQuery.On("String").
+ Return("select from service_operation_index")
tagsQuery := &mocks.Query{}
tagsQuery.On("Exec").Return(testCase.tagsQueryError)
tagsQuery.On("String").Return("select from tags")
durationNoOperationQuery := &mocks.Query{}
- durationNoOperationQuery.On("Bind", matchEverything()).Return(durationNoOperationQuery)
- durationNoOperationQuery.On("Exec").Return(testCase.durationNoOperationQueryError)
- durationNoOperationQuery.On("String").Return("select from duration_index")
+ durationNoOperationQuery.On("Bind", matchEverything()).
+ Return(durationNoOperationQuery)
+ durationNoOperationQuery.On("Exec").
+ Return(testCase.durationNoOperationQueryError)
+ durationNoOperationQuery.On("String").
+ Return("select from duration_index")
// Define expected queries
w.session.On("Query", stringMatcher(insertSpan), matchEverything()).Return(spanQuery)
w.session.On("Query", stringMatcher(serviceNameIndex), matchEverything()).Return(serviceNameQuery)
- w.session.On("Query", stringMatcher(serviceOperationIndex), matchEverything()).Return(serviceOperationNameQuery)
+ w.session.On("Query", stringMatcher(serviceOperationIndex), matchEverything()).
+ Return(serviceOperationNameQuery)
// note: using matchOnce below because we only want one tag to be inserted
- w.session.On("Query", stringMatcher(tagIndex), matchOnce()).Return(tagsQuery)
- w.session.On("Query", stringMatcher(durationIndex), matchOnce()).Return(durationNoOperationQuery)
+ w.session.On("Query", stringMatcher(tagIndex), matchOnce()).
+ Return(tagsQuery)
+ w.session.On("Query", stringMatcher(durationIndex), matchOnce()).
+ Return(durationNoOperationQuery)
w.writer.serviceNamesWriter = func(serviceName string) error { return testCase.serviceNameError }
w.writer.operationNamesWriter = func(operation dbmodel.Operation) error { return testCase.serviceNameError }
@@ -313,16 +340,21 @@ func TestStorageMode_IndexOnly(t *testing.T) {
serviceNameQuery.On("Exec").Return(nil)
serviceOperationNameQuery := &mocks.Query{}
- serviceOperationNameQuery.On("Bind", matchEverything()).Return(serviceOperationNameQuery)
+ serviceOperationNameQuery.On("Bind", matchEverything()).
+ Return(serviceOperationNameQuery)
serviceOperationNameQuery.On("Exec").Return(nil)
durationNoOperationQuery := &mocks.Query{}
- durationNoOperationQuery.On("Bind", matchEverything()).Return(durationNoOperationQuery)
+ durationNoOperationQuery.On("Bind", matchEverything()).
+ Return(durationNoOperationQuery)
durationNoOperationQuery.On("Exec").Return(nil)
- w.session.On("Query", stringMatcher(serviceNameIndex), matchEverything()).Return(serviceNameQuery)
- w.session.On("Query", stringMatcher(serviceOperationIndex), matchEverything()).Return(serviceOperationNameQuery)
- w.session.On("Query", stringMatcher(durationIndex), matchOnce()).Return(durationNoOperationQuery)
+ w.session.On("Query", stringMatcher(serviceNameIndex), matchEverything()).
+ Return(serviceNameQuery)
+ w.session.On("Query", stringMatcher(serviceOperationIndex), matchEverything()).
+ Return(serviceOperationNameQuery)
+ w.session.On("Query", stringMatcher(durationIndex), matchOnce()).
+ Return(durationNoOperationQuery)
err := w.writer.WriteSpan(context.Background(), span)
@@ -331,7 +363,12 @@ func TestStorageMode_IndexOnly(t *testing.T) {
serviceOperationNameQuery.AssertExpectations(t)
durationNoOperationQuery.AssertExpectations(t)
w.session.AssertExpectations(t)
- w.session.AssertNotCalled(t, "Query", stringMatcher(insertSpan), matchEverything())
+ w.session.AssertNotCalled(
+ t,
+ "Query",
+ stringMatcher(insertSpan),
+ matchEverything(),
+ )
}, StoreIndexesOnly())
}
@@ -353,9 +390,24 @@ func TestStorageMode_IndexOnly_WithFilter(t *testing.T) {
err := w.writer.WriteSpan(context.Background(), span)
require.NoError(t, err)
w.session.AssertExpectations(t)
- w.session.AssertNotCalled(t, "Query", stringMatcher(serviceOperationIndex), matchEverything())
- w.session.AssertNotCalled(t, "Query", stringMatcher(serviceNameIndex), matchEverything())
- w.session.AssertNotCalled(t, "Query", stringMatcher(durationIndex), matchEverything())
+ w.session.AssertNotCalled(
+ t,
+ "Query",
+ stringMatcher(serviceOperationIndex),
+ matchEverything(),
+ )
+ w.session.AssertNotCalled(
+ t,
+ "Query",
+ stringMatcher(serviceNameIndex),
+ matchEverything(),
+ )
+ w.session.AssertNotCalled(
+ t,
+ "Query",
+ stringMatcher(durationIndex),
+ matchEverything(),
+ )
}, StoreIndexesOnly())
}
@@ -389,19 +441,33 @@ func TestStorageMode_IndexOnly_FirehoseSpan(t *testing.T) {
serviceNameQuery.On("String").Return("select from service_name_index")
serviceOperationNameQuery := &mocks.Query{}
- serviceOperationNameQuery.On("Bind", matchEverything()).Return(serviceOperationNameQuery)
+ serviceOperationNameQuery.On("Bind", matchEverything()).
+ Return(serviceOperationNameQuery)
serviceOperationNameQuery.On("Exec").Return(nil)
- serviceOperationNameQuery.On("String").Return("select from service_operation_index")
+ serviceOperationNameQuery.On("String").
+ Return("select from service_operation_index")
// Define expected queries
- w.session.On("Query", stringMatcher(serviceNameIndex), matchEverything()).Return(serviceNameQuery)
- w.session.On("Query", stringMatcher(serviceOperationIndex), matchEverything()).Return(serviceOperationNameQuery)
+ w.session.On("Query", stringMatcher(serviceNameIndex), matchEverything()).
+ Return(serviceNameQuery)
+ w.session.On("Query", stringMatcher(serviceOperationIndex), matchEverything()).
+ Return(serviceOperationNameQuery)
err := w.writer.WriteSpan(context.Background(), span)
require.NoError(t, err)
w.session.AssertExpectations(t)
- w.session.AssertNotCalled(t, "Query", stringMatcher(tagIndex), matchEverything())
- w.session.AssertNotCalled(t, "Query", stringMatcher(durationIndex), matchEverything())
+ w.session.AssertNotCalled(
+ t,
+ "Query",
+ stringMatcher(tagIndex),
+ matchEverything(),
+ )
+ w.session.AssertNotCalled(
+ t,
+ "Query",
+ stringMatcher(durationIndex),
+ matchEverything(),
+ )
assert.Equal(t, "planet-express", *serviceWritten.Load())
assert.Equal(t, dbmodel.Operation{
ServiceName: "planet-express",
@@ -425,13 +491,19 @@ func TestStorageMode_StoreWithoutIndexing(t *testing.T) {
}
spanQuery := &mocks.Query{}
spanQuery.On("Exec").Return(nil)
- w.session.On("Query", stringMatcher(insertSpan), matchEverything()).Return(spanQuery)
+ w.session.On("Query", stringMatcher(insertSpan), matchEverything()).
+ Return(spanQuery)
err := w.writer.WriteSpan(context.Background(), span)
require.NoError(t, err)
spanQuery.AssertExpectations(t)
w.session.AssertExpectations(t)
- w.session.AssertNotCalled(t, "Query", stringMatcher(serviceNameIndex), matchEverything())
+ w.session.AssertNotCalled(
+ t,
+ "Query",
+ stringMatcher(serviceNameIndex),
+ matchEverything(),
+ )
}, StoreWithoutIndexing())
}
diff --git a/plugin/storage/es/dependencystore/dbmodel/converter_test.go b/plugin/storage/es/dependencystore/dbmodel/converter_test.go
index 76c3608eb84..4a998f53332 100644
--- a/plugin/storage/es/dependencystore/dbmodel/converter_test.go
+++ b/plugin/storage/es/dependencystore/dbmodel/converter_test.go
@@ -29,7 +29,9 @@ func TestConvertDependencies(t *testing.T) {
dLinks []model.DependencyLink
}{
{
- dLinks: []model.DependencyLink{{CallCount: 1, Parent: "foo", Child: "bar"}},
+ dLinks: []model.DependencyLink{
+ {CallCount: 1, Parent: "foo", Child: "bar"},
+ },
},
{
dLinks: []model.DependencyLink{{CallCount: 3, Parent: "foo"}},
diff --git a/plugin/storage/es/dependencystore/storage.go b/plugin/storage/es/dependencystore/storage.go
index 91dec5eb32d..38ea9f324e3 100644
--- a/plugin/storage/es/dependencystore/storage.go
+++ b/plugin/storage/es/dependencystore/storage.go
@@ -76,7 +76,10 @@ func prefixIndexName(prefix, index string) string {
}
// WriteDependencies implements dependencystore.Writer#WriteDependencies.
-func (s *DependencyStore) WriteDependencies(ts time.Time, dependencies []model.DependencyLink) error {
+func (s *DependencyStore) WriteDependencies(
+ ts time.Time,
+ dependencies []model.DependencyLink,
+) error {
writeIndexName := s.getWriteIndex(ts)
s.writeDependencies(writeIndexName, ts, dependencies)
return nil
@@ -84,14 +87,21 @@ func (s *DependencyStore) WriteDependencies(ts time.Time, dependencies []model.D
// CreateTemplates creates index templates.
func (s *DependencyStore) CreateTemplates(dependenciesTemplate string) error {
- _, err := s.client().CreateTemplate("jaeger-dependencies").Body(dependenciesTemplate).Do(context.Background())
+ _, err := s.client().
+ CreateTemplate("jaeger-dependencies").
+ Body(dependenciesTemplate).
+ Do(context.Background())
if err != nil {
return err
}
return nil
}
-func (s *DependencyStore) writeDependencies(indexName string, ts time.Time, dependencies []model.DependencyLink) {
+func (s *DependencyStore) writeDependencies(
+ indexName string,
+ ts time.Time,
+ dependencies []model.DependencyLink,
+) {
s.client().Index().Index(indexName).Type(dependencyType).
BodyJson(&dbmodel.TimeDependencies{
Timestamp: ts,
@@ -100,7 +110,11 @@ func (s *DependencyStore) writeDependencies(indexName string, ts time.Time, depe
}
// GetDependencies returns all interservice dependencies
-func (s *DependencyStore) GetDependencies(ctx context.Context, endTs time.Time, lookback time.Duration) ([]model.DependencyLink, error) {
+func (s *DependencyStore) GetDependencies(
+ ctx context.Context,
+ endTs time.Time,
+ lookback time.Duration,
+) ([]model.DependencyLink, error) {
indices := s.getReadIndices(endTs, lookback)
searchResult, err := s.client().Search(indices...).
Size(s.maxDocCount).
@@ -117,7 +131,9 @@ func (s *DependencyStore) GetDependencies(ctx context.Context, endTs time.Time,
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...)
}
@@ -125,25 +141,45 @@ func (s *DependencyStore) GetDependencies(ctx context.Context, endTs time.Time,
}
func buildTSQuery(endTs time.Time, lookback time.Duration) elastic.Query {
- return elastic.NewRangeQuery("timestamp").Gte(endTs.Add(-lookback)).Lte(endTs)
+ return elastic.NewRangeQuery("timestamp").
+ Gte(endTs.Add(-lookback)).
+ Lte(endTs)
}
-func (s *DependencyStore) getReadIndices(ts time.Time, lookback time.Duration) []string {
+func (s *DependencyStore) getReadIndices(
+ ts time.Time,
+ lookback time.Duration,
+) []string {
if s.useReadWriteAliases {
return []string{s.dependencyIndexPrefix + "read"}
}
var indices []string
- firstIndex := indexWithDate(s.dependencyIndexPrefix, s.indexDateLayout, ts.Add(-lookback))
- currentIndex := indexWithDate(s.dependencyIndexPrefix, s.indexDateLayout, ts)
+ firstIndex := indexWithDate(
+ s.dependencyIndexPrefix,
+ s.indexDateLayout,
+ ts.Add(-lookback),
+ )
+ currentIndex := indexWithDate(
+ s.dependencyIndexPrefix,
+ s.indexDateLayout,
+ ts,
+ )
for currentIndex != firstIndex {
indices = append(indices, currentIndex)
ts = ts.Add(-24 * time.Hour)
- currentIndex = indexWithDate(s.dependencyIndexPrefix, s.indexDateLayout, ts)
+ currentIndex = indexWithDate(
+ s.dependencyIndexPrefix,
+ s.indexDateLayout,
+ ts,
+ )
}
return append(indices, firstIndex)
}
-func indexWithDate(indexNamePrefix, indexDateLayout string, date time.Time) string {
+func indexWithDate(
+ indexNamePrefix, indexDateLayout string,
+ date time.Time,
+) string {
return indexNamePrefix + date.UTC().Format(indexDateLayout)
}
diff --git a/plugin/storage/es/dependencystore/storage_test.go b/plugin/storage/es/dependencystore/storage_test.go
index 852d19abfff..f4e9fb94819 100644
--- a/plugin/storage/es/dependencystore/storage_test.go
+++ b/plugin/storage/es/dependencystore/storage_test.go
@@ -45,7 +45,11 @@ type depStorageTest struct {
storage *DependencyStore
}
-func withDepStorage(indexPrefix, indexDateLayout string, maxDocCount int, fn func(r *depStorageTest)) {
+func withDepStorage(
+ indexPrefix, indexDateLayout string,
+ maxDocCount int,
+ fn func(r *depStorageTest),
+) {
client := &mocks.Client{}
logger, logBuffer := testutils.NewLogger()
r := &depStorageTest{
@@ -87,7 +91,11 @@ func TestNewSpanReaderIndexPrefix(t *testing.T) {
MaxDocCount: defaultMaxDocCount,
})
- assert.Equal(t, testCase.expected+dependencyIndex, r.dependencyIndexPrefix)
+ assert.Equal(
+ t,
+ testCase.expected+dependencyIndex,
+ r.dependencyIndexPrefix,
+ )
}
}
@@ -103,25 +111,45 @@ func TestWriteDependencies(t *testing.T) {
},
}
for _, testCase := range testCases {
- withDepStorage("", "2006-01-02", defaultMaxDocCount, func(r *depStorageTest) {
- fixedTime := time.Date(1995, time.April, 21, 4, 21, 19, 95, time.UTC)
- indexName := indexWithDate("", "2006-01-02", fixedTime)
- writeService := &mocks.IndexService{}
+ withDepStorage(
+ "",
+ "2006-01-02",
+ defaultMaxDocCount,
+ func(r *depStorageTest) {
+ fixedTime := time.Date(
+ 1995,
+ time.April,
+ 21,
+ 4,
+ 21,
+ 19,
+ 95,
+ time.UTC,
+ )
+ indexName := indexWithDate("", "2006-01-02", fixedTime)
+ writeService := &mocks.IndexService{}
- r.client.On("Index").Return(writeService)
- r.client.On("GetVersion").Return(testCase.esVersion)
+ r.client.On("Index").Return(writeService)
+ r.client.On("GetVersion").Return(testCase.esVersion)
- writeService.On("Index", stringMatcher(indexName)).Return(writeService)
- writeService.On("Type", stringMatcher(dependencyType)).Return(writeService)
- writeService.On("BodyJson", mock.Anything).Return(writeService)
- writeService.On("Add", mock.Anything).Return(nil, testCase.writeError)
- err := r.storage.WriteDependencies(fixedTime, []model.DependencyLink{})
- if testCase.expectedError != "" {
- require.EqualError(t, err, testCase.expectedError)
- } else {
- require.NoError(t, err)
- }
- })
+ writeService.On("Index", stringMatcher(indexName)).
+ Return(writeService)
+ writeService.On("Type", stringMatcher(dependencyType)).
+ Return(writeService)
+ writeService.On("BodyJson", mock.Anything).Return(writeService)
+ writeService.On("Add", mock.Anything).
+ Return(nil, testCase.writeError)
+ err := r.storage.WriteDependencies(
+ fixedTime,
+ []model.DependencyLink{},
+ )
+ if testCase.expectedError != "" {
+ require.EqualError(t, err, testCase.expectedError)
+ } else {
+ require.NoError(t, err)
+ }
+ },
+ )
}
}
@@ -155,49 +183,81 @@ func TestGetDependencies(t *testing.T) {
CallCount: 12,
},
},
- indices: []any{"jaeger-dependencies-1995-04-21", "jaeger-dependencies-1995-04-20"},
+ indices: []any{
+ "jaeger-dependencies-1995-04-21",
+ "jaeger-dependencies-1995-04-20",
+ },
maxDocCount: 1000, // can be anything, assertion will check this value is used in search query.
},
{
searchResult: createSearchResult(badDependencies),
expectedError: "unmarshalling ElasticSearch documents failed",
- indices: []any{"jaeger-dependencies-1995-04-21", "jaeger-dependencies-1995-04-20"},
+ indices: []any{
+ "jaeger-dependencies-1995-04-21",
+ "jaeger-dependencies-1995-04-20",
+ },
},
{
searchError: errors.New("search failure"),
expectedError: "failed to search for dependencies: search failure",
- indices: []any{"jaeger-dependencies-1995-04-21", "jaeger-dependencies-1995-04-20"},
+ indices: []any{
+ "jaeger-dependencies-1995-04-21",
+ "jaeger-dependencies-1995-04-20",
+ },
},
{
searchError: errors.New("search failure"),
expectedError: "failed to search for dependencies: search failure",
indexPrefix: "foo",
- indices: []any{"foo-jaeger-dependencies-1995-04-21", "foo-jaeger-dependencies-1995-04-20"},
+ indices: []any{
+ "foo-jaeger-dependencies-1995-04-21",
+ "foo-jaeger-dependencies-1995-04-20",
+ },
},
}
for _, testCase := range testCases {
- withDepStorage(testCase.indexPrefix, "2006-01-02", testCase.maxDocCount, func(r *depStorageTest) {
- fixedTime := time.Date(1995, time.April, 21, 4, 21, 19, 95, time.UTC)
+ withDepStorage(
+ testCase.indexPrefix,
+ "2006-01-02",
+ testCase.maxDocCount,
+ func(r *depStorageTest) {
+ fixedTime := time.Date(
+ 1995,
+ time.April,
+ 21,
+ 4,
+ 21,
+ 19,
+ 95,
+ time.UTC,
+ )
- searchService := &mocks.SearchService{}
- r.client.On("Search", testCase.indices...).Return(searchService)
+ searchService := &mocks.SearchService{}
+ r.client.On("Search", testCase.indices...).Return(searchService)
- searchService.On("Size", mock.MatchedBy(func(size int) bool {
- return size == testCase.maxDocCount
- })).Return(searchService)
- searchService.On("Query", mock.Anything).Return(searchService)
- searchService.On("IgnoreUnavailable", mock.AnythingOfType("bool")).Return(searchService)
- searchService.On("Do", mock.Anything).Return(testCase.searchResult, testCase.searchError)
+ searchService.On("Size", mock.MatchedBy(func(size int) bool {
+ return size == testCase.maxDocCount
+ })).Return(searchService)
+ searchService.On("Query", mock.Anything).Return(searchService)
+ searchService.On("IgnoreUnavailable", mock.AnythingOfType("bool")).
+ Return(searchService)
+ searchService.On("Do", mock.Anything).
+ Return(testCase.searchResult, testCase.searchError)
- actual, err := r.storage.GetDependencies(context.Background(), fixedTime, 24*time.Hour)
- if testCase.expectedError != "" {
- require.EqualError(t, err, testCase.expectedError)
- assert.Nil(t, actual)
- } else {
- require.NoError(t, err)
- assert.EqualValues(t, testCase.expectedOutput, actual)
- }
- })
+ actual, err := r.storage.GetDependencies(
+ context.Background(),
+ fixedTime,
+ 24*time.Hour,
+ )
+ if testCase.expectedError != "" {
+ require.EqualError(t, err, testCase.expectedError)
+ assert.Nil(t, actual)
+ } else {
+ require.NoError(t, err)
+ assert.EqualValues(t, testCase.expectedOutput, actual)
+ }
+ },
+ )
}
}
@@ -219,7 +279,11 @@ func TestGetReadIndices(t *testing.T) {
params Params
}{
{
- params: Params{IndexPrefix: "", IndexDateLayout: "2006-01-02", UseReadWriteAliases: true},
+ params: Params{
+ IndexPrefix: "",
+ IndexDateLayout: "2006-01-02",
+ UseReadWriteAliases: true,
+ },
lookback: 23 * time.Hour,
indices: []string{
dependencyIndex + "read",
@@ -230,7 +294,8 @@ func TestGetReadIndices(t *testing.T) {
lookback: 23 * time.Hour,
indices: []string{
dependencyIndex + fixedTime.Format("2006-01-02"),
- dependencyIndex + fixedTime.Add(-23*time.Hour).Format("2006-01-02"),
+ dependencyIndex + fixedTime.Add(-23*time.Hour).
+ Format("2006-01-02"),
},
},
{
@@ -238,27 +303,42 @@ func TestGetReadIndices(t *testing.T) {
lookback: 13 * time.Hour,
indices: []string{
dependencyIndex + fixedTime.UTC().Format("2006-01-02"),
- dependencyIndex + fixedTime.Add(-13*time.Hour).Format("2006-01-02"),
+ dependencyIndex + fixedTime.Add(-13*time.Hour).
+ Format("2006-01-02"),
},
},
{
- params: Params{IndexPrefix: "foo:", IndexDateLayout: "2006-01-02"},
+ params: Params{
+ IndexPrefix: "foo:",
+ IndexDateLayout: "2006-01-02",
+ },
lookback: 1 * time.Hour,
indices: []string{
- "foo:" + indexPrefixSeparator + dependencyIndex + fixedTime.Format("2006-01-02"),
+ "foo:" + indexPrefixSeparator + dependencyIndex + fixedTime.Format(
+ "2006-01-02",
+ ),
},
},
{
- params: Params{IndexPrefix: "foo-", IndexDateLayout: "2006-01-02"},
+ params: Params{
+ IndexPrefix: "foo-",
+ IndexDateLayout: "2006-01-02",
+ },
lookback: 0,
indices: []string{
- "foo-" + indexPrefixSeparator + dependencyIndex + fixedTime.Format("2006-01-02"),
+ "foo-" + indexPrefixSeparator + dependencyIndex + fixedTime.Format(
+ "2006-01-02",
+ ),
},
},
}
for _, testCase := range testCases {
s := NewDependencyStore(testCase.params)
- assert.EqualValues(t, testCase.indices, s.getReadIndices(fixedTime, testCase.lookback))
+ assert.EqualValues(
+ t,
+ testCase.indices,
+ s.getReadIndices(fixedTime, testCase.lookback),
+ )
}
}
@@ -270,11 +350,19 @@ func TestGetWriteIndex(t *testing.T) {
params Params
}{
{
- params: Params{IndexPrefix: "", IndexDateLayout: "2006-01-02", UseReadWriteAliases: true},
+ params: Params{
+ IndexPrefix: "",
+ IndexDateLayout: "2006-01-02",
+ UseReadWriteAliases: true,
+ },
writeIndex: dependencyIndex + "write",
},
{
- params: Params{IndexPrefix: "", IndexDateLayout: "2006-01-02", UseReadWriteAliases: false},
+ params: Params{
+ IndexPrefix: "",
+ IndexDateLayout: "2006-01-02",
+ UseReadWriteAliases: false,
+ },
writeIndex: dependencyIndex + fixedTime.Format("2006-01-02"),
},
}
diff --git a/plugin/storage/es/factory.go b/plugin/storage/es/factory.go
index d1c53821336..7771d94d5a4 100644
--- a/plugin/storage/es/factory.go
+++ b/plugin/storage/es/factory.go
@@ -139,34 +139,61 @@ func (f *Factory) configureFromOptions(o *Options) {
}
// Initialize implements storage.Factory.
-func (f *Factory) Initialize(metricsFactory metrics.Factory, logger *zap.Logger) error {
+func (f *Factory) Initialize(
+ metricsFactory metrics.Factory,
+ logger *zap.Logger,
+) error {
f.metricsFactory, f.logger = metricsFactory, logger
primaryClient, err := f.newClientFn(f.primaryConfig, logger, metricsFactory)
if err != nil {
- return fmt.Errorf("failed to create primary Elasticsearch client: %w", err)
+ return fmt.Errorf(
+ "failed to create primary Elasticsearch client: %w",
+ err,
+ )
}
f.primaryClient.Store(&primaryClient)
if f.primaryConfig.PasswordFilePath != "" {
- primaryWatcher, err := fswatcher.New([]string{f.primaryConfig.PasswordFilePath}, f.onPrimaryPasswordChange, f.logger)
+ primaryWatcher, err := fswatcher.New(
+ []string{f.primaryConfig.PasswordFilePath},
+ f.onPrimaryPasswordChange,
+ f.logger,
+ )
if err != nil {
- return fmt.Errorf("failed to create watcher for primary ES client's password: %w", err)
+ return fmt.Errorf(
+ "failed to create watcher for primary ES client's password: %w",
+ err,
+ )
}
f.watchers = append(f.watchers, primaryWatcher)
}
if f.archiveConfig.Enabled {
- archiveClient, err := f.newClientFn(f.archiveConfig, logger, metricsFactory)
+ archiveClient, err := f.newClientFn(
+ f.archiveConfig,
+ logger,
+ metricsFactory,
+ )
if err != nil {
- return fmt.Errorf("failed to create archive Elasticsearch client: %w", err)
+ return fmt.Errorf(
+ "failed to create archive Elasticsearch client: %w",
+ err,
+ )
}
f.archiveClient.Store(&archiveClient)
if f.archiveConfig.PasswordFilePath != "" {
- archiveWatcher, err := fswatcher.New([]string{f.archiveConfig.PasswordFilePath}, f.onArchivePasswordChange, f.logger)
+ archiveWatcher, err := fswatcher.New(
+ []string{f.archiveConfig.PasswordFilePath},
+ f.onArchivePasswordChange,
+ f.logger,
+ )
if err != nil {
- return fmt.Errorf("failed to create watcher for archive ES client's password: %w", err)
+ return fmt.Errorf(
+ "failed to create watcher for archive ES client's password: %w",
+ err,
+ )
}
f.watchers = append(f.watchers, archiveWatcher)
}
@@ -191,12 +218,25 @@ func (f *Factory) getArchiveClient() es.Client {
// CreateSpanReader implements storage.Factory
func (f *Factory) CreateSpanReader() (spanstore.Reader, error) {
- return createSpanReader(f.getPrimaryClient, f.primaryConfig, false, f.metricsFactory, f.logger, f.tracer)
+ return createSpanReader(
+ f.getPrimaryClient,
+ f.primaryConfig,
+ false,
+ f.metricsFactory,
+ f.logger,
+ f.tracer,
+ )
}
// CreateSpanWriter implements storage.Factory
func (f *Factory) CreateSpanWriter() (spanstore.Writer, error) {
- return createSpanWriter(f.getPrimaryClient, f.primaryConfig, false, f.metricsFactory, f.logger)
+ return createSpanWriter(
+ f.getPrimaryClient,
+ f.primaryConfig,
+ false,
+ f.metricsFactory,
+ f.logger,
+ )
}
// CreateDependencyReader implements storage.Factory
@@ -209,7 +249,14 @@ func (f *Factory) CreateArchiveSpanReader() (spanstore.Reader, error) {
if !f.archiveConfig.Enabled {
return nil, nil
}
- return createSpanReader(f.getArchiveClient, f.archiveConfig, true, f.metricsFactory, f.logger, f.tracer)
+ return createSpanReader(
+ f.getArchiveClient,
+ f.archiveConfig,
+ true,
+ f.metricsFactory,
+ f.logger,
+ f.tracer,
+ )
}
// CreateArchiveSpanWriter implements storage.ArchiveFactory
@@ -217,7 +264,13 @@ func (f *Factory) CreateArchiveSpanWriter() (spanstore.Writer, error) {
if !f.archiveConfig.Enabled {
return nil, nil
}
- return createSpanWriter(f.getArchiveClient, f.archiveConfig, true, f.metricsFactory, f.logger)
+ return createSpanWriter(
+ f.getArchiveClient,
+ f.archiveConfig,
+ true,
+ f.metricsFactory,
+ f.logger,
+ )
}
func createSpanReader(
@@ -229,7 +282,9 @@ func createSpanReader(
tp trace.TracerProvider,
) (spanstore.Reader, error) {
if cfg.UseILM && !cfg.UseReadWriteAliases {
- return nil, fmt.Errorf("--es.use-ilm must always be used in conjunction with --es.use-aliases to ensure ES writers and readers refer to the single index mapping")
+ return nil, fmt.Errorf(
+ "--es.use-ilm must always be used in conjunction with --es.use-aliases to ensure ES writers and readers refer to the single index mapping",
+ )
}
return esSpanStore.NewSpanReader(esSpanStore.SpanReaderParams{
Client: clientFn,
@@ -260,7 +315,9 @@ func createSpanWriter(
var tags []string
var err error
if cfg.UseILM && !cfg.UseReadWriteAliases {
- return nil, fmt.Errorf("--es.use-ilm must always be used in conjunction with --es.use-aliases to ensure ES writers and readers refer to the single index mapping")
+ return nil, fmt.Errorf(
+ "--es.use-ilm must always be used in conjunction with --es.use-aliases to ensure ES writers and readers refer to the single index mapping",
+ )
}
if tags, err = cfg.TagKeysAsFields(); err != nil {
logger.Error("failed to get tag keys", zap.Error(err))
@@ -296,7 +353,9 @@ func createSpanWriter(
return writer, nil
}
-func (f *Factory) CreateSamplingStore(maxBuckets int) (samplingstore.Store, error) {
+func (f *Factory) CreateSamplingStore(
+ maxBuckets int,
+) (samplingstore.Store, error) {
params := esSampleStore.Params{
Client: f.getPrimaryClient,
Logger: f.logger,
@@ -322,7 +381,9 @@ func (f *Factory) CreateSamplingStore(maxBuckets int) (samplingstore.Store, erro
return store, nil
}
-func mappingBuilderFromConfig(cfg *config.Configuration) mappings.MappingBuilder {
+func mappingBuilderFromConfig(
+ cfg *config.Configuration,
+) mappings.MappingBuilder {
return mappings.MappingBuilder{
TemplateBuilder: es.TextTemplateBuilder{},
Shards: cfg.NumShards,
@@ -381,25 +442,38 @@ func (f *Factory) onArchivePasswordChange() {
f.onClientPasswordChange(f.archiveConfig, &f.archiveClient)
}
-func (f *Factory) onClientPasswordChange(cfg *config.Configuration, client *atomic.Pointer[es.Client]) {
+func (f *Factory) onClientPasswordChange(
+ cfg *config.Configuration,
+ client *atomic.Pointer[es.Client],
+) {
newPassword, err := loadTokenFromFile(cfg.PasswordFilePath)
if err != nil {
- f.logger.Error("failed to reload password for Elasticsearch client", zap.Error(err))
+ f.logger.Error(
+ "failed to reload password for Elasticsearch client",
+ zap.Error(err),
+ )
return
}
- f.logger.Sugar().Infof("loaded new password of length %d from file", len(newPassword))
+ f.logger.Sugar().
+ Infof("loaded new password of length %d from file", len(newPassword))
newCfg := *cfg // copy by value
newCfg.Password = newPassword
newCfg.PasswordFilePath = "" // avoid error that both are set
newClient, err := f.newClientFn(&newCfg, f.logger, f.metricsFactory)
if err != nil {
- f.logger.Error("failed to recreate Elasticsearch client with new password", zap.Error(err))
+ f.logger.Error(
+ "failed to recreate Elasticsearch client with new password",
+ zap.Error(err),
+ )
return
}
if oldClient := *client.Swap(&newClient); oldClient != nil {
if err := oldClient.Close(); err != nil {
- f.logger.Error("failed to close Elasticsearch client", zap.Error(err))
+ f.logger.Error(
+ "failed to close Elasticsearch client",
+ zap.Error(err),
+ )
}
}
}
diff --git a/plugin/storage/es/factory_test.go b/plugin/storage/es/factory_test.go
index a79e2942a19..c42f7f4f0e1 100644
--- a/plugin/storage/es/factory_test.go
+++ b/plugin/storage/es/factory_test.go
@@ -57,12 +57,17 @@ type mockClientBuilder struct {
createTemplateError error
}
-func (m *mockClientBuilder) NewClient(_ *escfg.Configuration, logger *zap.Logger, metricsFactory metrics.Factory) (es.Client, error) {
+func (m *mockClientBuilder) NewClient(
+ _ *escfg.Configuration,
+ logger *zap.Logger,
+ metricsFactory metrics.Factory,
+) (es.Client, error) {
if m.err == nil {
c := &mocks.Client{}
tService := &mocks.TemplateCreateService{}
tService.On("Body", mock.Anything).Return(tService)
- tService.On("Do", context.Background()).Return(nil, m.createTemplateError)
+ tService.On("Do", context.Background()).
+ Return(nil, m.createTemplateError)
c.On("CreateTemplate", mock.Anything).Return(tService)
c.On("GetVersion").Return(uint(6))
c.On("Close").Return(nil)
@@ -78,7 +83,11 @@ func TestElasticsearchFactory(t *testing.T) {
f.InitFromViper(v, zap.NewNop())
f.newClientFn = (&mockClientBuilder{err: errors.New("made-up error")}).NewClient
- require.EqualError(t, f.Initialize(metrics.NullFactory, zap.NewNop()), "failed to create primary Elasticsearch client: made-up error")
+ require.EqualError(
+ t,
+ f.Initialize(metrics.NullFactory, zap.NewNop()),
+ "failed to create primary Elasticsearch client: made-up error",
+ )
f.archiveConfig.Enabled = true
f.newClientFn = func(c *escfg.Configuration, logger *zap.Logger, metricsFactory metrics.Factory) (es.Client, error) {
@@ -87,7 +96,11 @@ func TestElasticsearchFactory(t *testing.T) {
f.newClientFn = (&mockClientBuilder{err: errors.New("made-up error2")}).NewClient
return (&mockClientBuilder{}).NewClient(c, logger, metricsFactory)
}
- require.EqualError(t, f.Initialize(metrics.NullFactory, zap.NewNop()), "failed to create archive Elasticsearch client: made-up error2")
+ require.EqualError(
+ t,
+ f.Initialize(metrics.NullFactory, zap.NewNop()),
+ "failed to create archive Elasticsearch client: made-up error2",
+ )
f.newClientFn = (&mockClientBuilder{}).NewClient
require.NoError(t, f.Initialize(metrics.NullFactory, zap.NewNop()))
@@ -139,11 +152,19 @@ func TestElasticsearchILMUsedWithoutReadWriteAliases(t *testing.T) {
require.NoError(t, f.Initialize(metrics.NullFactory, zap.NewNop()))
defer f.Close()
w, err := f.CreateSpanWriter()
- require.EqualError(t, err, "--es.use-ilm must always be used in conjunction with --es.use-aliases to ensure ES writers and readers refer to the single index mapping")
+ require.EqualError(
+ t,
+ err,
+ "--es.use-ilm must always be used in conjunction with --es.use-aliases to ensure ES writers and readers refer to the single index mapping",
+ )
assert.Nil(t, w)
r, err := f.CreateSpanReader()
- require.EqualError(t, err, "--es.use-ilm must always be used in conjunction with --es.use-aliases to ensure ES writers and readers refer to the single index mapping")
+ require.EqualError(
+ t,
+ err,
+ "--es.use-ilm must always be used in conjunction with --es.use-aliases to ensure ES writers and readers refer to the single index mapping",
+ )
assert.Nil(t, r)
}
@@ -174,9 +195,16 @@ func TestTagKeysAsFields(t *testing.T) {
expected: nil,
},
{
- path: "fixtures/tags_01.txt",
- include: "televators,eriatarka,thewidow",
- expected: []string{"foo", "bar", "space", "televators", "eriatarka", "thewidow"},
+ path: "fixtures/tags_01.txt",
+ include: "televators,eriatarka,thewidow",
+ expected: []string{
+ "foo",
+ "bar",
+ "space",
+ "televators",
+ "eriatarka",
+ "thewidow",
+ },
},
{
path: "fixtures/tags_02.txt",
@@ -224,14 +252,21 @@ func TestCreateTemplateError(t *testing.T) {
func TestILMDisableTemplateCreation(t *testing.T) {
f := NewFactory()
- f.primaryConfig = &escfg.Configuration{UseILM: true, UseReadWriteAliases: true, CreateIndexTemplates: true}
+ f.primaryConfig = &escfg.Configuration{
+ UseILM: true,
+ UseReadWriteAliases: true,
+ CreateIndexTemplates: true,
+ }
f.archiveConfig = &escfg.Configuration{}
f.newClientFn = (&mockClientBuilder{createTemplateError: errors.New("template-error")}).NewClient
err := f.Initialize(metrics.NullFactory, zap.NewNop())
defer f.Close()
require.NoError(t, err)
_, err = f.CreateSpanWriter()
- require.NoError(t, err) // as the createTemplate is not called, CreateSpanWriter should not return an error
+ require.NoError(
+ t,
+ err,
+ ) // as the createTemplate is not called, CreateSpanWriter should not return an error
}
func TestArchiveDisabled(t *testing.T) {
@@ -266,7 +301,9 @@ func TestConfigureFromOptions(t *testing.T) {
f := NewFactory()
o := &Options{
Primary: namespaceConfig{Configuration: escfg.Configuration{Servers: []string{"server"}}},
- others: map[string]*namespaceConfig{"es-archive": {Configuration: escfg.Configuration{Servers: []string{"server2"}}}},
+ others: map[string]*namespaceConfig{
+ "es-archive": {Configuration: escfg.Configuration{Servers: []string{"server2"}}},
+ },
}
f.configureFromOptions(o)
assert.Equal(t, o.GetPrimary(), f.primaryConfig)
@@ -274,9 +311,11 @@ func TestConfigureFromOptions(t *testing.T) {
}
func TestESStorageFactoryWithConfig(t *testing.T) {
- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- w.Write(mockEsServerResponse)
- }))
+ server := httptest.NewServer(
+ http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ w.Write(mockEsServerResponse)
+ }),
+ )
defer server.Close()
cfg := escfg.Configuration{
Servers: []string{server.URL},
@@ -311,7 +350,11 @@ func TestConfigurationValidation(t *testing.T) {
err := test.cfg.Validate()
if test.wantErr {
require.Error(t, err)
- _, err = NewFactoryWithConfig(test.cfg, metrics.NullFactory, zap.NewNop())
+ _, err = NewFactoryWithConfig(
+ test.cfg,
+ metrics.NullFactory,
+ zap.NewNop(),
+ )
require.Error(t, err)
} else {
require.NoError(t, err)
@@ -329,7 +372,11 @@ func TestESStorageFactoryWithConfigError(t *testing.T) {
}
_, err := NewFactoryWithConfig(cfg, metrics.NullFactory, zap.NewNop())
require.Error(t, err)
- require.ErrorContains(t, err, "failed to create primary Elasticsearch client")
+ require.ErrorContains(
+ t,
+ err,
+ "failed to create primary Elasticsearch client",
+ )
}
func TestPasswordFromFile(t *testing.T) {
@@ -341,7 +388,12 @@ func TestPasswordFromFile(t *testing.T) {
t.Run("archive client", func(t *testing.T) {
f2 := NewFactory()
- testPasswordFromFile(t, f2, f2.getArchiveClient, f2.CreateArchiveSpanWriter)
+ testPasswordFromFile(
+ t,
+ f2,
+ f2.getArchiveClient,
+ f2.CreateArchiveSpanWriter,
+ )
})
t.Run("load token error", func(t *testing.T) {
@@ -352,7 +404,12 @@ func TestPasswordFromFile(t *testing.T) {
})
}
-func testPasswordFromFile(t *testing.T, f *Factory, getClient func() es.Client, getWriter func() (spanstore.Writer, error)) {
+func testPasswordFromFile(
+ t *testing.T,
+ f *Factory,
+ getClient func() es.Client,
+ getWriter func() (spanstore.Writer, error),
+) {
const (
pwd1 = "first password"
pwd2 = "second password"
@@ -361,19 +418,21 @@ func testPasswordFromFile(t *testing.T, f *Factory, getClient func() es.Client,
upwd2 = "user:" + pwd2
)
var authReceived sync.Map
- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- t.Logf("request to fake ES server: %v", r)
- // epecting header in the form Authorization:[Basic OmZpcnN0IHBhc3N3b3Jk]
- h := strings.Split(r.Header.Get("Authorization"), " ")
- require.Len(t, h, 2)
- require.Equal(t, "Basic", h[0])
- authBytes, err := base64.StdEncoding.DecodeString(h[1])
- require.NoError(t, err, "header: %s", h)
- auth := string(authBytes)
- authReceived.Store(auth, auth)
- t.Logf("request to fake ES server contained auth=%s", auth)
- w.Write(mockEsServerResponse)
- }))
+ server := httptest.NewServer(
+ http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ t.Logf("request to fake ES server: %v", r)
+ // epecting header in the form Authorization:[Basic OmZpcnN0IHBhc3N3b3Jk]
+ h := strings.Split(r.Header.Get("Authorization"), " ")
+ require.Len(t, h, 2)
+ require.Equal(t, "Basic", h[0])
+ authBytes, err := base64.StdEncoding.DecodeString(h[1])
+ require.NoError(t, err, "header: %s", h)
+ auth := string(authBytes)
+ authReceived.Store(auth, auth)
+ t.Logf("request to fake ES server contained auth=%s", auth)
+ w.Write(mockEsServerResponse)
+ }),
+ )
defer server.Close()
pwdFile := filepath.Join(t.TempDir(), "pwd")
@@ -446,9 +505,11 @@ func TestFactoryESClientsAreNil(t *testing.T) {
func TestPasswordFromFileErrors(t *testing.T) {
defer testutils.VerifyGoLeaksOnce(t)
- server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- w.Write(mockEsServerResponse)
- }))
+ server := httptest.NewServer(
+ http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ w.Write(mockEsServerResponse)
+ }),
+ )
defer server.Close()
pwdFile := filepath.Join(t.TempDir(), "pwd")
diff --git a/plugin/storage/es/mappings/mapping_test.go b/plugin/storage/es/mappings/mapping_test.go
index efa56c335bf..6b5cabbeaeb 100644
--- a/plugin/storage/es/mappings/mapping_test.go
+++ b/plugin/storage/es/mappings/mapping_test.go
@@ -65,7 +65,9 @@ func TestMappingBuilder_GetMapping(t *testing.T) {
require.NoError(t, err)
var wantbytes []byte
fileSuffix := fmt.Sprintf("-%d", tt.esVersion)
- wantbytes, err = FIXTURES.ReadFile("fixtures/" + tt.mapping + fileSuffix + ".json")
+ wantbytes, err = FIXTURES.ReadFile(
+ "fixtures/" + tt.mapping + fileSuffix + ".json",
+ )
require.NoError(t, err)
want := string(wantbytes)
assert.Equal(t, want, got)
@@ -118,7 +120,8 @@ func TestMappingBuilder_fixMapping(t *testing.T) {
templateBuilderMockFunc: func() *mocks.TemplateBuilder {
tb := mocks.TemplateBuilder{}
ta := mocks.TemplateApplier{}
- ta.On("Execute", mock.Anything, mock.Anything).Return(errors.New("template exec error"))
+ ta.On("Execute", mock.Anything, mock.Anything).
+ Return(errors.New("template exec error"))
tb.On("Parse", mock.Anything).Return(&ta, nil)
return &tb
},
@@ -128,7 +131,8 @@ func TestMappingBuilder_fixMapping(t *testing.T) {
name: "templateLoadError",
templateBuilderMockFunc: func() *mocks.TemplateBuilder {
tb := mocks.TemplateBuilder{}
- tb.On("Parse", mock.Anything).Return(nil, errors.New("template load error"))
+ tb.On("Parse", mock.Anything).
+ Return(nil, errors.New("template load error"))
return &tb
},
err: "template load error",
@@ -203,8 +207,12 @@ func TestMappingBuilder_GetSpanServiceMappings(t *testing.T) {
mockNewTextTemplateBuilder: func() es.TemplateBuilder {
tb := mocks.TemplateBuilder{}
ta := mocks.TemplateApplier{}
- ta.On("Execute", mock.Anything, mock.Anything).Return(nil).Once()
- ta.On("Execute", mock.Anything, mock.Anything).Return(errors.New("template load error")).Once()
+ ta.On("Execute", mock.Anything, mock.Anything).
+ Return(nil).
+ Once()
+ ta.On("Execute", mock.Anything, mock.Anything).
+ Return(errors.New("template load error")).
+ Once()
tb.On("Parse", mock.Anything).Return(&ta, nil)
return &tb
},
@@ -223,7 +231,9 @@ func TestMappingBuilder_GetSpanServiceMappings(t *testing.T) {
mockNewTextTemplateBuilder: func() es.TemplateBuilder {
tb := mocks.TemplateBuilder{}
ta := mocks.TemplateApplier{}
- ta.On("Execute", mock.Anything, mock.Anything).Return(errors.New("template load error")).Once()
+ ta.On("Execute", mock.Anything, mock.Anything).
+ Return(errors.New("template load error")).
+ Once()
tb.On("Parse", mock.Anything).Return(&ta, nil)
return &tb
},
@@ -254,7 +264,8 @@ func TestMappingBuilder_GetSpanServiceMappings(t *testing.T) {
func TestMappingBuilder_GetDependenciesMappings(t *testing.T) {
tb := mocks.TemplateBuilder{}
ta := mocks.TemplateApplier{}
- ta.On("Execute", mock.Anything, mock.Anything).Return(errors.New("template load error"))
+ ta.On("Execute", mock.Anything, mock.Anything).
+ Return(errors.New("template load error"))
tb.On("Parse", mock.Anything).Return(&ta, nil)
mappingBuilder := MappingBuilder{
@@ -267,7 +278,8 @@ func TestMappingBuilder_GetDependenciesMappings(t *testing.T) {
func TestMappingBuilder_GetSamplingMappings(t *testing.T) {
tb := mocks.TemplateBuilder{}
ta := mocks.TemplateApplier{}
- ta.On("Execute", mock.Anything, mock.Anything).Return(errors.New("template load error"))
+ ta.On("Execute", mock.Anything, mock.Anything).
+ Return(errors.New("template load error"))
tb.On("Parse", mock.Anything).Return(&ta, nil)
mappingBuilder := MappingBuilder{
diff --git a/plugin/storage/es/options.go b/plugin/storage/es/options.go
index 7661aa2b476..d320c69c1b5 100644
--- a/plugin/storage/es/options.go
+++ b/plugin/storage/es/options.go
@@ -92,7 +92,7 @@ type Options struct {
}
type namespaceConfig struct {
- config.Configuration `mapstructure:",squash"`
+ config.Configuration ` mapstructure:",squash"`
namespace string
}
@@ -138,7 +138,8 @@ func addFlags(flagSet *flag.FlagSet, nsConfig *namespaceConfig) {
flagSet.String(
nsConfig.namespace+suffixUsername,
nsConfig.Username,
- "The username required by Elasticsearch. The basic authentication also loads CA if it is specified.")
+ "The username required by Elasticsearch. The basic authentication also loads CA if it is specified.",
+ )
flagSet.String(
nsConfig.namespace+suffixPassword,
nsConfig.Password,
@@ -146,7 +147,8 @@ func addFlags(flagSet *flag.FlagSet, nsConfig *namespaceConfig) {
flagSet.String(
nsConfig.namespace+suffixTokenPath,
nsConfig.TokenFilePath,
- "Path to a file containing bearer token. This flag also loads CA if it is specified.")
+ "Path to a file containing bearer token. This flag also loads CA if it is specified.",
+ )
flagSet.String(
nsConfig.namespace+suffixPasswordPath,
nsConfig.PasswordFilePath,
@@ -154,16 +156,19 @@ func addFlags(flagSet *flag.FlagSet, nsConfig *namespaceConfig) {
flagSet.Bool(
nsConfig.namespace+suffixSniffer,
nsConfig.Sniffer,
- "The sniffer config for Elasticsearch; client uses sniffing process to find all nodes automatically, disable if not required")
+ "The sniffer config for Elasticsearch; client uses sniffing process to find all nodes automatically, disable if not required",
+ )
flagSet.String(
nsConfig.namespace+suffixServerURLs,
defaultServerURL,
- "The comma-separated list of Elasticsearch servers, must be full url i.e. http://localhost:9200")
+ "The comma-separated list of Elasticsearch servers, must be full url i.e. http://localhost:9200",
+ )
flagSet.String(
nsConfig.namespace+suffixRemoteReadClusters,
defaultRemoteReadClusters,
"Comma-separated list of Elasticsearch remote cluster names for cross-cluster querying."+
- "See Elasticsearch remote clusters and cross-cluster query api.")
+ "See Elasticsearch remote clusters and cross-cluster query api.",
+ )
flagSet.Duration(
nsConfig.namespace+suffixTimeout,
nsConfig.Timeout,
@@ -196,90 +201,110 @@ func addFlags(flagSet *flag.FlagSet, nsConfig *namespaceConfig) {
flagSet.Int(
nsConfig.namespace+suffixBulkSize,
nsConfig.BulkSize,
- "The number of bytes that the bulk requests can take up before the bulk processor decides to commit")
+ "The number of bytes that the bulk requests can take up before the bulk processor decides to commit",
+ )
flagSet.Int(
nsConfig.namespace+suffixBulkWorkers,
nsConfig.BulkWorkers,
- "The number of workers that are able to receive bulk requests and eventually commit them to Elasticsearch")
+ "The number of workers that are able to receive bulk requests and eventually commit them to Elasticsearch",
+ )
flagSet.Int(
nsConfig.namespace+suffixBulkActions,
nsConfig.BulkActions,
- "The number of requests that can be enqueued before the bulk processor decides to commit")
+ "The number of requests that can be enqueued before the bulk processor decides to commit",
+ )
flagSet.Duration(
nsConfig.namespace+suffixBulkFlushInterval,
nsConfig.BulkFlushInterval,
- "A time.Duration after which bulk requests are committed, regardless of other thresholds. Set to zero to disable. By default, this is disabled.")
+ "A time.Duration after which bulk requests are committed, regardless of other thresholds. Set to zero to disable. By default, this is disabled.",
+ )
flagSet.String(
nsConfig.namespace+suffixIndexPrefix,
nsConfig.IndexPrefix,
- "Optional prefix of Jaeger indices. For example \"production\" creates \"production-jaeger-*\".")
+ "Optional prefix of Jaeger indices. For example \"production\" creates \"production-jaeger-*\".",
+ )
flagSet.String(
nsConfig.namespace+suffixIndexDateSeparator,
defaultIndexDateSeparator,
- "Optional date separator of Jaeger indices. For example \".\" creates \"jaeger-span-2020.11.20\".")
+ "Optional date separator of Jaeger indices. For example \".\" creates \"jaeger-span-2020.11.20\".",
+ )
flagSet.String(
nsConfig.namespace+suffixIndexRolloverFrequencySpans,
defaultIndexRolloverFrequency,
"Rotates jaeger-span indices over the given period. For example \"day\" creates \"jaeger-span-yyyy-MM-dd\" every day after UTC 12AM. Valid options: [hour, day]. "+
- "This does not delete old indices. For details on complete index management solutions supported by Jaeger, refer to: https://www.jaegertracing.io/docs/deployment/#elasticsearch-rollover")
+ "This does not delete old indices. For details on complete index management solutions supported by Jaeger, refer to: https://www.jaegertracing.io/docs/deployment/#elasticsearch-rollover",
+ )
flagSet.String(
nsConfig.namespace+suffixIndexRolloverFrequencyServices,
defaultIndexRolloverFrequency,
"Rotates jaeger-service indices over the given period. For example \"day\" creates \"jaeger-service-yyyy-MM-dd\" every day after UTC 12AM. Valid options: [hour, day]. "+
- "This does not delete old indices. For details on complete index management solutions supported by Jaeger, refer to: https://www.jaegertracing.io/docs/deployment/#elasticsearch-rollover")
+ "This does not delete old indices. For details on complete index management solutions supported by Jaeger, refer to: https://www.jaegertracing.io/docs/deployment/#elasticsearch-rollover",
+ )
flagSet.String(
nsConfig.namespace+suffixIndexRolloverFrequencySampling,
defaultIndexRolloverFrequency,
"Rotates jaeger-sampling indices over the given period. For example \"day\" creates \"jaeger-sampling-yyyy-MM-dd\" every day after UTC 12AM. Valid options: [hour, day]. "+
- "This does not delete old indices. For details on complete index management solutions supported by Jaeger, refer to: https://www.jaegertracing.io/docs/deployment/#elasticsearch-rollover")
+ "This does not delete old indices. For details on complete index management solutions supported by Jaeger, refer to: https://www.jaegertracing.io/docs/deployment/#elasticsearch-rollover",
+ )
flagSet.Bool(
nsConfig.namespace+suffixTagsAsFieldsAll,
nsConfig.Tags.AllAsFields,
- "(experimental) Store all span and process tags as object fields. If true "+suffixTagsFile+" and "+suffixTagsAsFieldsInclude+" is ignored. Binary tags are always stored as nested objects.")
+ "(experimental) Store all span and process tags as object fields. If true "+suffixTagsFile+" and "+suffixTagsAsFieldsInclude+" is ignored. Binary tags are always stored as nested objects.",
+ )
flagSet.String(
nsConfig.namespace+suffixTagsAsFieldsInclude,
nsConfig.Tags.Include,
- "(experimental) Comma delimited list of tag keys which will be stored as object fields. Merged with the contents of "+suffixTagsFile)
+ "(experimental) Comma delimited list of tag keys which will be stored as object fields. Merged with the contents of "+suffixTagsFile,
+ )
flagSet.String(
nsConfig.namespace+suffixTagsFile,
nsConfig.Tags.File,
- "(experimental) Optional path to a file containing tag keys which will be stored as object fields. Each key should be on a separate line. Merged with "+suffixTagsAsFieldsInclude)
+ "(experimental) Optional path to a file containing tag keys which will be stored as object fields. Each key should be on a separate line. Merged with "+suffixTagsAsFieldsInclude,
+ )
flagSet.String(
nsConfig.namespace+suffixTagDeDotChar,
nsConfig.Tags.DotReplacement,
- "(experimental) The character used to replace dots (\".\") in tag keys stored as object fields.")
+ "(experimental) The character used to replace dots (\".\") in tag keys stored as object fields.",
+ )
flagSet.Bool(
nsConfig.namespace+suffixReadAlias,
nsConfig.UseReadWriteAliases,
"Use read and write aliases for indices. Use this option with Elasticsearch rollover "+
"API. It requires an external component to create aliases before startup and then performing its management. "+
- "Note that es"+suffixMaxSpanAge+" will influence trace search window start times.")
+ "Note that es"+suffixMaxSpanAge+" will influence trace search window start times.",
+ )
flagSet.Bool(
nsConfig.namespace+suffixUseILM,
nsConfig.UseILM,
"(experimental) Option to enable ILM for jaeger span & service indices. Use this option with "+nsConfig.namespace+suffixReadAlias+". "+
"It requires an external component to create aliases before startup and then performing its management. "+
- "ILM policy must be manually created in ES before startup. Supported only for elasticsearch version 7+.")
+ "ILM policy must be manually created in ES before startup. Supported only for elasticsearch version 7+.",
+ )
flagSet.Bool(
nsConfig.namespace+suffixCreateIndexTemplate,
nsConfig.CreateIndexTemplates,
- "Create index templates at application startup. Set to false when templates are installed manually.")
+ "Create index templates at application startup. Set to false when templates are installed manually.",
+ )
flagSet.Uint(
nsConfig.namespace+suffixVersion,
0,
- "The major Elasticsearch version. If not specified, the value will be auto-detected from Elasticsearch.")
+ "The major Elasticsearch version. If not specified, the value will be auto-detected from Elasticsearch.",
+ )
flagSet.Bool(
nsConfig.namespace+suffixSnifferTLSEnabled,
nsConfig.SnifferTLSEnabled,
- "Option to enable TLS when sniffing an Elasticsearch Cluster ; client uses sniffing process to find all nodes automatically, disabled by default")
+ "Option to enable TLS when sniffing an Elasticsearch Cluster ; client uses sniffing process to find all nodes automatically, disabled by default",
+ )
flagSet.Int(
nsConfig.namespace+suffixMaxDocCount,
nsConfig.MaxDocCount,
- "The maximum document count to return from an Elasticsearch query. This will also apply to aggregations.")
+ "The maximum document count to return from an Elasticsearch query. This will also apply to aggregations.",
+ )
flagSet.String(
nsConfig.namespace+suffixLogLevel,
nsConfig.LogLevel,
- "The Elasticsearch client log-level. Valid levels: [debug, info, error]")
+ "The Elasticsearch client log-level. Valid levels: [debug, info, error]",
+ )
flagSet.String(
nsConfig.namespace+suffixSendGetBodyAs,
nsConfig.SendGetBodyAs,
@@ -319,18 +344,31 @@ func initFromViper(cfg *namespaceConfig, v *viper.Viper) {
cfg.PasswordFilePath = v.GetString(cfg.namespace + suffixPasswordPath)
cfg.Sniffer = v.GetBool(cfg.namespace + suffixSniffer)
cfg.SnifferTLSEnabled = v.GetBool(cfg.namespace + suffixSnifferTLSEnabled)
- cfg.Servers = strings.Split(stripWhiteSpace(v.GetString(cfg.namespace+suffixServerURLs)), ",")
+ cfg.Servers = strings.Split(
+ stripWhiteSpace(v.GetString(cfg.namespace+suffixServerURLs)),
+ ",",
+ )
cfg.MaxSpanAge = v.GetDuration(cfg.namespace + suffixMaxSpanAge)
- cfg.AdaptiveSamplingLookback = v.GetDuration(cfg.namespace + suffixAdaptiveSamplingLookback)
+ cfg.AdaptiveSamplingLookback = v.GetDuration(
+ cfg.namespace + suffixAdaptiveSamplingLookback,
+ )
cfg.NumShards = v.GetInt64(cfg.namespace + suffixNumShards)
cfg.NumReplicas = v.GetInt64(cfg.namespace + suffixNumReplicas)
- cfg.PrioritySpanTemplate = v.GetInt64(cfg.namespace + suffixPrioritySpanTemplate)
- cfg.PriorityServiceTemplate = v.GetInt64(cfg.namespace + suffixPriorityServiceTemplate)
- cfg.PriorityDependenciesTemplate = v.GetInt64(cfg.namespace + suffixPriorityDependenciesTemplate)
+ cfg.PrioritySpanTemplate = v.GetInt64(
+ cfg.namespace + suffixPrioritySpanTemplate,
+ )
+ cfg.PriorityServiceTemplate = v.GetInt64(
+ cfg.namespace + suffixPriorityServiceTemplate,
+ )
+ cfg.PriorityDependenciesTemplate = v.GetInt64(
+ cfg.namespace + suffixPriorityDependenciesTemplate,
+ )
cfg.BulkSize = v.GetInt(cfg.namespace + suffixBulkSize)
cfg.BulkWorkers = v.GetInt(cfg.namespace + suffixBulkWorkers)
cfg.BulkActions = v.GetInt(cfg.namespace + suffixBulkActions)
- cfg.BulkFlushInterval = v.GetDuration(cfg.namespace + suffixBulkFlushInterval)
+ cfg.BulkFlushInterval = v.GetDuration(
+ cfg.namespace + suffixBulkFlushInterval,
+ )
cfg.Timeout = v.GetDuration(cfg.namespace + suffixTimeout)
cfg.ServiceCacheTTL = v.GetDuration(cfg.namespace + suffixServiceCacheTTL)
cfg.IndexPrefix = v.GetString(cfg.namespace + suffixIndexPrefix)
@@ -340,7 +378,9 @@ func initFromViper(cfg *namespaceConfig, v *viper.Viper) {
cfg.Tags.DotReplacement = v.GetString(cfg.namespace + suffixTagDeDotChar)
cfg.UseReadWriteAliases = v.GetBool(cfg.namespace + suffixReadAlias)
cfg.Enabled = v.GetBool(cfg.namespace + suffixEnabled)
- cfg.CreateIndexTemplates = v.GetBool(cfg.namespace + suffixCreateIndexTemplate)
+ cfg.CreateIndexTemplates = v.GetBool(
+ cfg.namespace + suffixCreateIndexTemplate,
+ )
cfg.Version = uint(v.GetInt(cfg.namespace + suffixVersion))
cfg.LogLevel = v.GetString(cfg.namespace + suffixLogLevel)
cfg.SendGetBodyAs = v.GetString(cfg.namespace + suffixSendGetBodyAs)
@@ -351,22 +391,40 @@ func initFromViper(cfg *namespaceConfig, v *viper.Viper) {
// TODO: Need to figure out a better way for do this.
cfg.AllowTokenFromContext = v.GetBool(bearertoken.StoragePropagationKey)
- remoteReadClusters := stripWhiteSpace(v.GetString(cfg.namespace + suffixRemoteReadClusters))
+ remoteReadClusters := stripWhiteSpace(
+ v.GetString(cfg.namespace + suffixRemoteReadClusters),
+ )
if len(remoteReadClusters) > 0 {
cfg.RemoteReadClusters = strings.Split(remoteReadClusters, ",")
}
cfg.IndexRolloverFrequencySpans = strings.ToLower(v.GetString(cfg.namespace + suffixIndexRolloverFrequencySpans))
- cfg.IndexRolloverFrequencyServices = strings.ToLower(v.GetString(cfg.namespace + suffixIndexRolloverFrequencyServices))
- cfg.IndexRolloverFrequencySampling = strings.ToLower(v.GetString(cfg.namespace + suffixIndexRolloverFrequencySampling))
+ cfg.IndexRolloverFrequencyServices = strings.ToLower(
+ v.GetString(cfg.namespace + suffixIndexRolloverFrequencyServices),
+ )
+ cfg.IndexRolloverFrequencySampling = strings.ToLower(
+ v.GetString(cfg.namespace + suffixIndexRolloverFrequencySampling),
+ )
separator := v.GetString(cfg.namespace + suffixIndexDateSeparator)
- cfg.IndexDateLayoutSpans = initDateLayout(cfg.IndexRolloverFrequencySpans, separator)
- cfg.IndexDateLayoutServices = initDateLayout(cfg.IndexRolloverFrequencyServices, separator)
- cfg.IndexDateLayoutSampling = initDateLayout(cfg.IndexRolloverFrequencySampling, separator)
+ cfg.IndexDateLayoutSpans = initDateLayout(
+ cfg.IndexRolloverFrequencySpans,
+ separator,
+ )
+ cfg.IndexDateLayoutServices = initDateLayout(
+ cfg.IndexRolloverFrequencyServices,
+ separator,
+ )
+ cfg.IndexDateLayoutSampling = initDateLayout(
+ cfg.IndexRolloverFrequencySampling,
+ separator,
+ )
// Dependencies calculation should be daily, and this index size is very small
- cfg.IndexDateLayoutDependencies = initDateLayout(defaultIndexRolloverFrequency, separator)
+ cfg.IndexDateLayoutDependencies = initDateLayout(
+ defaultIndexRolloverFrequency,
+ separator,
+ )
var err error
cfg.TLS, err = cfg.getTLSFlagsConfig().InitFromViper(v)
if err != nil {
diff --git a/plugin/storage/es/options_test.go b/plugin/storage/es/options_test.go
index ed9bbbefab3..f14178dc244 100644
--- a/plugin/storage/es/options_test.go
+++ b/plugin/storage/es/options_test.go
@@ -88,7 +88,11 @@ func TestOptionsWithFlags(t *testing.T) {
assert.Equal(t, "/foo/bar", primary.TokenFilePath)
assert.Equal(t, "/foo/bar/baz", primary.PasswordFilePath)
assert.Equal(t, []string{"1.1.1.1", "2.2.2.2"}, primary.Servers)
- assert.Equal(t, []string{"cluster_one", "cluster_two"}, primary.RemoteReadClusters)
+ assert.Equal(
+ t,
+ []string{"cluster_one", "cluster_two"},
+ primary.RemoteReadClusters,
+ )
assert.Equal(t, 48*time.Hour, primary.MaxSpanAge)
assert.True(t, primary.Sniffer)
assert.True(t, primary.SnifferTLSEnabled)
@@ -169,10 +173,26 @@ func TestIndexDateSeparator(t *testing.T) {
}{
{"not defined (default)", []string{}, "2006-01-02"},
{"empty separator", []string{"--es.index-date-separator="}, "20060102"},
- {"dot separator", []string{"--es.index-date-separator=."}, "2006.01.02"},
- {"crossbar separator", []string{"--es.index-date-separator=-"}, "2006-01-02"},
- {"slash separator", []string{"--es.index-date-separator=/"}, "2006/01/02"},
- {"empty string with single quotes", []string{"--es.index-date-separator=''"}, "2006''01''02"},
+ {
+ "dot separator",
+ []string{"--es.index-date-separator=."},
+ "2006.01.02",
+ },
+ {
+ "crossbar separator",
+ []string{"--es.index-date-separator=-"},
+ "2006-01-02",
+ },
+ {
+ "slash separator",
+ []string{"--es.index-date-separator=/"},
+ "2006/01/02",
+ },
+ {
+ "empty string with single quotes",
+ []string{"--es.index-date-separator=''"},
+ "2006''01''02",
+ },
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
@@ -205,24 +225,33 @@ func TestIndexRollover(t *testing.T) {
wantServiceIndexRolloverFrequency: -24 * time.Hour,
},
{
- name: "index day rollover",
- flags: []string{"--es.index-rollover-frequency-services=day", "--es.index-rollover-frequency-spans=hour"},
+ name: "index day rollover",
+ flags: []string{
+ "--es.index-rollover-frequency-services=day",
+ "--es.index-rollover-frequency-spans=hour",
+ },
wantSpanDateLayout: "2006-01-02-15",
wantServiceDateLayout: "2006-01-02",
wantSpanIndexRolloverFrequency: -1 * time.Hour,
wantServiceIndexRolloverFrequency: -24 * time.Hour,
},
{
- name: "index hour rollover",
- flags: []string{"--es.index-rollover-frequency-services=hour", "--es.index-rollover-frequency-spans=day"},
+ name: "index hour rollover",
+ flags: []string{
+ "--es.index-rollover-frequency-services=hour",
+ "--es.index-rollover-frequency-spans=day",
+ },
wantSpanDateLayout: "2006-01-02",
wantServiceDateLayout: "2006-01-02-15",
wantSpanIndexRolloverFrequency: -24 * time.Hour,
wantServiceIndexRolloverFrequency: -1 * time.Hour,
},
{
- name: "invalid index rollover frequency falls back to default 'day'",
- flags: []string{"--es.index-rollover-frequency-services=hours", "--es.index-rollover-frequency-spans=hours"},
+ name: "invalid index rollover frequency falls back to default 'day'",
+ flags: []string{
+ "--es.index-rollover-frequency-services=hours",
+ "--es.index-rollover-frequency-spans=hours",
+ },
wantSpanDateLayout: "2006-01-02",
wantServiceDateLayout: "2006-01-02",
wantSpanIndexRolloverFrequency: -24 * time.Hour,
@@ -237,9 +266,21 @@ func TestIndexRollover(t *testing.T) {
opts.InitFromViper(v)
primary := opts.GetPrimary()
assert.Equal(t, tc.wantSpanDateLayout, primary.IndexDateLayoutSpans)
- assert.Equal(t, tc.wantServiceDateLayout, primary.IndexDateLayoutServices)
- assert.Equal(t, tc.wantSpanIndexRolloverFrequency, primary.GetIndexRolloverFrequencySpansDuration())
- assert.Equal(t, tc.wantServiceIndexRolloverFrequency, primary.GetIndexRolloverFrequencyServicesDuration())
+ assert.Equal(
+ t,
+ tc.wantServiceDateLayout,
+ primary.IndexDateLayoutServices,
+ )
+ assert.Equal(
+ t,
+ tc.wantSpanIndexRolloverFrequency,
+ primary.GetIndexRolloverFrequencySpansDuration(),
+ )
+ assert.Equal(
+ t,
+ tc.wantServiceIndexRolloverFrequency,
+ primary.GetIndexRolloverFrequencyServicesDuration(),
+ )
})
}
}
diff --git a/plugin/storage/es/samplingstore/dbmodel/converter_test.go b/plugin/storage/es/samplingstore/dbmodel/converter_test.go
index 9ac02f1eac8..5071d9579dc 100644
--- a/plugin/storage/es/samplingstore/dbmodel/converter_test.go
+++ b/plugin/storage/es/samplingstore/dbmodel/converter_test.go
@@ -29,7 +29,14 @@ func TestConvertDependencies(t *testing.T) {
throughputs []*model.Throughput
}{
{
- throughputs: []*model.Throughput{{Service: "service1", Operation: "operation1", Count: 10, Probabilities: map[string]struct{}{"new-srv": {}}}},
+ throughputs: []*model.Throughput{
+ {
+ Service: "service1",
+ Operation: "operation1",
+ Count: 10,
+ Probabilities: map[string]struct{}{"new-srv": {}},
+ },
+ },
},
{
throughputs: []*model.Throughput{},
diff --git a/plugin/storage/es/samplingstore/storage.go b/plugin/storage/es/samplingstore/storage.go
index 6515ce05467..f688f6f3d76 100644
--- a/plugin/storage/es/samplingstore/storage.go
+++ b/plugin/storage/es/samplingstore/storage.go
@@ -80,9 +80,17 @@ func (s *SamplingStore) InsertThroughput(throughput []*model.Throughput) error {
return nil
}
-func (s *SamplingStore) GetThroughput(start, end time.Time) ([]*model.Throughput, error) {
+func (s *SamplingStore) GetThroughput(
+ start, end time.Time,
+) ([]*model.Throughput, error) {
ctx := context.Background()
- indices := getReadIndices(s.samplingIndexPrefix, s.indexDateLayout, start, end, s.indexRolloverFrequency)
+ indices := getReadIndices(
+ s.samplingIndexPrefix,
+ s.indexDateLayout,
+ start,
+ end,
+ s.indexRolloverFrequency,
+ )
searchResult, err := s.client().Search(indices...).
Size(s.maxDocCount).
Query(buildTSQuery(start, end)).
@@ -109,7 +117,11 @@ func (s *SamplingStore) InsertProbabilitiesAndQPS(hostname string,
qps model.ServiceOperationQPS,
) error {
ts := time.Now()
- writeIndexName := indexWithDate(s.samplingIndexPrefix, s.indexDateLayout, ts)
+ writeIndexName := indexWithDate(
+ s.samplingIndexPrefix,
+ s.indexDateLayout,
+ ts,
+ )
val := dbmodel.ProbabilitiesAndQPS{
Hostname: hostname,
Probabilities: probabilities,
@@ -122,7 +134,13 @@ func (s *SamplingStore) InsertProbabilitiesAndQPS(hostname string,
func (s *SamplingStore) GetLatestProbabilities() (model.ServiceOperationProbabilities, error) {
ctx := context.Background()
clientFn := s.client()
- indices, err := getLatestIndices(s.samplingIndexPrefix, s.indexDateLayout, clientFn, s.indexRolloverFrequency, s.lookback)
+ indices, err := getLatestIndices(
+ s.samplingIndexPrefix,
+ s.indexDateLayout,
+ clientFn,
+ s.indexRolloverFrequency,
+ s.lookback,
+ )
if err != nil {
return nil, fmt.Errorf("failed to get latest indices: %w", err)
}
@@ -131,7 +149,10 @@ func (s *SamplingStore) GetLatestProbabilities() (model.ServiceOperationProbabil
IgnoreUnavailable(true).
Do(ctx)
if err != nil {
- return nil, fmt.Errorf("failed to search for Latest Probabilities: %w", err)
+ return nil, fmt.Errorf(
+ "failed to search for Latest Probabilities: %w",
+ err,
+ )
}
lengthOfSearchResult := len(searchResult.Hits.Hits)
if lengthOfSearchResult == 0 {
@@ -153,7 +174,11 @@ func (s *SamplingStore) GetLatestProbabilities() (model.ServiceOperationProbabil
return latestProbabilities.ProbabilitiesAndQPS.Probabilities, nil
}
-func (s *SamplingStore) writeProbabilitiesAndQPS(indexName string, ts time.Time, pandqps dbmodel.ProbabilitiesAndQPS) {
+func (s *SamplingStore) writeProbabilitiesAndQPS(
+ indexName string,
+ ts time.Time,
+ pandqps dbmodel.ProbabilitiesAndQPS,
+) {
s.client().Index().Index(indexName).Type(probabilitiesType).
BodyJson(&dbmodel.TimeProbabilitiesAndQPS{
Timestamp: ts,
@@ -161,7 +186,12 @@ func (s *SamplingStore) writeProbabilitiesAndQPS(indexName string, ts time.Time,
}).Add()
}
-func getLatestIndices(indexPrefix, indexDateLayout string, clientFn es.Client, rollover time.Duration, maxDuration time.Duration) ([]string, error) {
+func getLatestIndices(
+ indexPrefix, indexDateLayout string,
+ clientFn es.Client,
+ rollover time.Duration,
+ maxDuration time.Duration,
+) ([]string, error) {
ctx := context.Background()
now := time.Now().UTC()
earliest := now.Add(-maxDuration)
@@ -182,7 +212,12 @@ func getLatestIndices(indexPrefix, indexDateLayout string, clientFn es.Client, r
}
}
-func getReadIndices(indexName, indexDateLayout string, startTime time.Time, endTime time.Time, rollover time.Duration) []string {
+func getReadIndices(
+ indexName, indexDateLayout string,
+ startTime time.Time,
+ endTime time.Time,
+ rollover time.Duration,
+) []string {
var indices []string
firstIndex := indexWithDate(indexName, indexDateLayout, startTime)
currentIndex := indexWithDate(indexName, indexDateLayout, endTime)
@@ -206,6 +241,9 @@ func buildTSQuery(start, end time.Time) elastic.Query {
return elastic.NewRangeQuery("timestamp").Gte(start).Lte(end)
}
-func indexWithDate(indexNamePrefix, indexDateLayout string, date time.Time) string {
+func indexWithDate(
+ indexNamePrefix, indexDateLayout string,
+ date time.Time,
+) string {
return indexNamePrefix + date.UTC().Format(indexDateLayout)
}
diff --git a/plugin/storage/es/samplingstore/storage_test.go b/plugin/storage/es/samplingstore/storage_test.go
index 3373b0fec0b..da4e5326bc8 100644
--- a/plugin/storage/es/samplingstore/storage_test.go
+++ b/plugin/storage/es/samplingstore/storage_test.go
@@ -43,7 +43,11 @@ type samplingStorageTest struct {
storage *SamplingStore
}
-func withEsSampling(indexPrefix, indexDateLayout string, maxDocCount int, fn func(w *samplingStorageTest)) {
+func withEsSampling(
+ indexPrefix, indexDateLayout string,
+ maxDocCount int,
+ fn func(w *samplingStorageTest),
+) {
client := &mocks.Client{}
logger, logBuffer := testutils.NewLogger()
w := &samplingStorageTest{
@@ -88,7 +92,11 @@ func TestNewIndexPrefix(t *testing.T) {
IndexDateLayout: "2006-01-02",
MaxDocCount: defaultMaxDocCount,
})
- assert.Equal(t, test.expected+samplingIndex+indexPrefixSeparator, r.samplingIndexPrefix)
+ assert.Equal(
+ t,
+ test.expected+samplingIndex+indexPrefixSeparator,
+ r.samplingIndexPrefix,
+ )
})
}
}
@@ -110,7 +118,13 @@ func TestGetReadIndices(t *testing.T) {
"prefix-jaeger-sampling-2024-02-10",
}
rollover := -time.Hour * 24
- indices := getReadIndices("prefix-jaeger-sampling-", "2006-01-02", test.start, test.end, rollover)
+ indices := getReadIndices(
+ "prefix-jaeger-sampling-",
+ "2006-01-02",
+ test.start,
+ test.end,
+ rollover,
+ )
assert.Equal(t, expectedIndices, indices)
})
}
@@ -129,9 +143,11 @@ func TestGetLatestIndices(t *testing.T) {
name: "with index",
indexDateLayout: "2006-01-02",
maxDuration: 24 * time.Hour,
- expectedIndices: []string{indexWithDate("", "2006-01-02", time.Now().UTC())},
- expectedError: "",
- indexExist: true,
+ expectedIndices: []string{
+ indexWithDate("", "2006-01-02", time.Now().UTC()),
+ },
+ expectedError: "",
+ indexExist: true,
},
{
name: "without index",
@@ -157,7 +173,13 @@ func TestGetLatestIndices(t *testing.T) {
w.client.On("IndexExists", mock.Anything).Return(indexService)
indexService.On("Do", mock.Anything).Return(test.indexExist, test.IndexExistError)
clientFnMock := w.storage.client()
- actualIndices, err := getLatestIndices("", test.indexDateLayout, clientFnMock, -24*time.Hour, test.maxDuration)
+ actualIndices, err := getLatestIndices(
+ "",
+ test.indexDateLayout,
+ clientFnMock,
+ -24*time.Hour,
+ test.maxDuration,
+ )
if test.expectedError != "" {
require.EqualError(t, err, test.expectedError)
assert.Nil(t, actualIndices)
@@ -180,26 +202,33 @@ func TestInsertThroughput(t *testing.T) {
}
t.Run(test.name, func(t *testing.T) {
- withEsSampling("", "2006-01-02", defaultMaxDocCount, func(w *samplingStorageTest) {
- throughputs := []*samplemodel.Throughput{
- {Service: "my-svc", Operation: "op"},
- {Service: "our-svc", Operation: "op2"},
- }
- fixedTime := time.Now()
- indexName := indexWithDate("", "2006-01-02", fixedTime)
- writeService := &mocks.IndexService{}
- w.client.On("Index").Return(writeService)
- writeService.On("Index", stringMatcher(indexName)).Return(writeService)
- writeService.On("Type", stringMatcher(throughputType)).Return(writeService)
- writeService.On("BodyJson", mock.Anything).Return(writeService)
- writeService.On("Add", mock.Anything)
- err := w.storage.InsertThroughput(throughputs)
- if test.expectedError != "" {
- require.EqualError(t, err, test.expectedError)
- } else {
- require.NoError(t, err)
- }
- })
+ withEsSampling(
+ "",
+ "2006-01-02",
+ defaultMaxDocCount,
+ func(w *samplingStorageTest) {
+ throughputs := []*samplemodel.Throughput{
+ {Service: "my-svc", Operation: "op"},
+ {Service: "our-svc", Operation: "op2"},
+ }
+ fixedTime := time.Now()
+ indexName := indexWithDate("", "2006-01-02", fixedTime)
+ writeService := &mocks.IndexService{}
+ w.client.On("Index").Return(writeService)
+ writeService.On("Index", stringMatcher(indexName)).
+ Return(writeService)
+ writeService.On("Type", stringMatcher(throughputType)).
+ Return(writeService)
+ writeService.On("BodyJson", mock.Anything).Return(writeService)
+ writeService.On("Add", mock.Anything)
+ err := w.storage.InsertThroughput(throughputs)
+ if test.expectedError != "" {
+ require.EqualError(t, err, test.expectedError)
+ } else {
+ require.NoError(t, err)
+ }
+ },
+ )
})
}
@@ -213,27 +242,42 @@ func TestInsertProbabilitiesAndQPS(t *testing.T) {
}
t.Run(test.name, func(t *testing.T) {
- withEsSampling("", "2006-01-02", defaultMaxDocCount, func(w *samplingStorageTest) {
- pAQ := dbmodel.ProbabilitiesAndQPS{
- Hostname: "dell11eg843d",
- Probabilities: samplemodel.ServiceOperationProbabilities{"new-srv": {"op": 0.1}},
- QPS: samplemodel.ServiceOperationQPS{"new-srv": {"op": 4}},
- }
- fixedTime := time.Now()
- indexName := indexWithDate("", "2006-01-02", fixedTime)
- writeService := &mocks.IndexService{}
- w.client.On("Index").Return(writeService)
- writeService.On("Index", stringMatcher(indexName)).Return(writeService)
- writeService.On("Type", stringMatcher(probabilitiesType)).Return(writeService)
- writeService.On("BodyJson", mock.Anything).Return(writeService)
- writeService.On("Add", mock.Anything)
- err := w.storage.InsertProbabilitiesAndQPS(pAQ.Hostname, pAQ.Probabilities, pAQ.QPS)
- if test.expectedError != "" {
- require.EqualError(t, err, test.expectedError)
- } else {
- require.NoError(t, err)
- }
- })
+ withEsSampling(
+ "",
+ "2006-01-02",
+ defaultMaxDocCount,
+ func(w *samplingStorageTest) {
+ pAQ := dbmodel.ProbabilitiesAndQPS{
+ Hostname: "dell11eg843d",
+ Probabilities: samplemodel.ServiceOperationProbabilities{
+ "new-srv": {"op": 0.1},
+ },
+ QPS: samplemodel.ServiceOperationQPS{
+ "new-srv": {"op": 4},
+ },
+ }
+ fixedTime := time.Now()
+ indexName := indexWithDate("", "2006-01-02", fixedTime)
+ writeService := &mocks.IndexService{}
+ w.client.On("Index").Return(writeService)
+ writeService.On("Index", stringMatcher(indexName)).
+ Return(writeService)
+ writeService.On("Type", stringMatcher(probabilitiesType)).
+ Return(writeService)
+ writeService.On("BodyJson", mock.Anything).Return(writeService)
+ writeService.On("Add", mock.Anything)
+ err := w.storage.InsertProbabilitiesAndQPS(
+ pAQ.Hostname,
+ pAQ.Probabilities,
+ pAQ.QPS,
+ )
+ if test.expectedError != "" {
+ require.EqualError(t, err, test.expectedError)
+ } else {
+ require.NoError(t, err)
+ }
+ },
+ )
})
}
@@ -312,27 +356,39 @@ func TestGetThroughput(t *testing.T) {
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
- withEsSampling(test.indexPrefix, "2006-01-02", defaultMaxDocCount, func(w *samplingStorageTest) {
- searchService := &mocks.SearchService{}
- if test.indexPrefix != "" {
- test.indexPrefix += "-"
- }
- index := test.indexPrefix + test.index
- w.client.On("Search", index).Return(searchService)
- searchService.On("Size", mock.Anything).Return(searchService)
- searchService.On("Query", mock.Anything).Return(searchService)
- searchService.On("IgnoreUnavailable", true).Return(searchService)
- searchService.On("Do", mock.Anything).Return(test.searchResult, test.searchError)
+ withEsSampling(
+ test.indexPrefix,
+ "2006-01-02",
+ defaultMaxDocCount,
+ func(w *samplingStorageTest) {
+ searchService := &mocks.SearchService{}
+ if test.indexPrefix != "" {
+ test.indexPrefix += "-"
+ }
+ index := test.indexPrefix + test.index
+ w.client.On("Search", index).Return(searchService)
+ searchService.On("Size", mock.Anything).
+ Return(searchService)
+ searchService.On("Query", mock.Anything).
+ Return(searchService)
+ searchService.On("IgnoreUnavailable", true).
+ Return(searchService)
+ searchService.On("Do", mock.Anything).
+ Return(test.searchResult, test.searchError)
- actual, err := w.storage.GetThroughput(time.Now().Add(-time.Minute), time.Now())
- if test.expectedError != "" {
- require.EqualError(t, err, test.expectedError)
- assert.Nil(t, actual)
- } else {
- require.NoError(t, err)
- assert.EqualValues(t, test.expectedOutput, actual)
- }
- })
+ actual, err := w.storage.GetThroughput(
+ time.Now().Add(-time.Minute),
+ time.Now(),
+ )
+ if test.expectedError != "" {
+ require.EqualError(t, err, test.expectedError)
+ assert.Nil(t, actual)
+ } else {
+ require.NoError(t, err)
+ assert.EqualValues(t, test.expectedOutput, actual)
+ }
+ },
+ )
})
}
}
@@ -411,30 +467,40 @@ func TestGetLatestProbabilities(t *testing.T) {
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
- withEsSampling(test.indexPrefix, "2006-01-02", defaultMaxDocCount, func(w *samplingStorageTest) {
- searchService := &mocks.SearchService{}
- if test.indexPrefix != "" {
- test.indexPrefix += "-"
- }
- index := test.indexPrefix + test.index
- w.client.On("Search", index).Return(searchService)
- searchService.On("Size", mock.Anything).Return(searchService)
- searchService.On("IgnoreUnavailable", true).Return(searchService)
- searchService.On("Do", mock.Anything).Return(test.searchResult, test.searchError)
+ withEsSampling(
+ test.indexPrefix,
+ "2006-01-02",
+ defaultMaxDocCount,
+ func(w *samplingStorageTest) {
+ searchService := &mocks.SearchService{}
+ if test.indexPrefix != "" {
+ test.indexPrefix += "-"
+ }
+ index := test.indexPrefix + test.index
+ w.client.On("Search", index).Return(searchService)
+ searchService.On("Size", mock.Anything).
+ Return(searchService)
+ searchService.On("IgnoreUnavailable", true).
+ Return(searchService)
+ searchService.On("Do", mock.Anything).
+ Return(test.searchResult, test.searchError)
- indicesexistsservice := &mocks.IndicesExistsService{}
- w.client.On("IndexExists", index).Return(indicesexistsservice)
- indicesexistsservice.On("Do", mock.Anything).Return(test.indexPresent, test.indexError)
+ indicesexistsservice := &mocks.IndicesExistsService{}
+ w.client.On("IndexExists", index).
+ Return(indicesexistsservice)
+ indicesexistsservice.On("Do", mock.Anything).
+ Return(test.indexPresent, test.indexError)
- actual, err := w.storage.GetLatestProbabilities()
- if test.expectedError != "" {
- require.EqualError(t, err, test.expectedError)
- assert.Nil(t, actual)
- } else {
- require.NoError(t, err)
- assert.EqualValues(t, test.expectedOutput, actual)
- }
- })
+ actual, err := w.storage.GetLatestProbabilities()
+ if test.expectedError != "" {
+ require.EqualError(t, err, test.expectedError)
+ assert.Nil(t, actual)
+ } else {
+ require.NoError(t, err)
+ assert.EqualValues(t, test.expectedOutput, actual)
+ }
+ },
+ )
})
}
}
diff --git a/plugin/storage/es/spanstore/dbmodel/from_domain.go b/plugin/storage/es/spanstore/dbmodel/from_domain.go
index e573a23a3ae..0f5d42478eb 100644
--- a/plugin/storage/es/spanstore/dbmodel/from_domain.go
+++ b/plugin/storage/es/spanstore/dbmodel/from_domain.go
@@ -22,12 +22,20 @@ import (
)
// NewFromDomain creates FromDomain used to convert model span to db span
-func NewFromDomain(allTagsAsObject bool, tagKeysAsFields []string, tagDotReplacement string) FromDomain {
+func NewFromDomain(
+ allTagsAsObject bool,
+ tagKeysAsFields []string,
+ tagDotReplacement string,
+) FromDomain {
tags := map[string]bool{}
for _, k := range tagKeysAsFields {
tags[k] = true
}
- return FromDomain{allTagsAsFields: allTagsAsObject, tagKeysAsFields: tags, tagDotReplacement: tagDotReplacement}
+ return FromDomain{
+ allTagsAsFields: allTagsAsObject,
+ tagKeysAsFields: tags,
+ tagDotReplacement: tagDotReplacement,
+ }
}
// FromDomain is used to convert model span to db span
@@ -85,11 +93,14 @@ func (FromDomain) convertRefType(refType model.SpanRefType) ReferenceType {
return ChildOf
}
-func (fd FromDomain) convertKeyValuesString(keyValues model.KeyValues) ([]KeyValue, map[string]any) {
+func (fd FromDomain) convertKeyValuesString(
+ keyValues model.KeyValues,
+) ([]KeyValue, map[string]any) {
var tagsMap map[string]any
var kvs []KeyValue
for _, kv := range keyValues {
- if kv.GetVType() != model.BinaryType && (fd.allTagsAsFields || fd.tagKeysAsFields[kv.Key]) {
+ if kv.GetVType() != model.BinaryType &&
+ (fd.allTagsAsFields || fd.tagKeysAsFields[kv.Key]) {
if tagsMap == nil {
tagsMap = map[string]any{}
}
diff --git a/plugin/storage/es/spanstore/dbmodel/from_domain_test.go b/plugin/storage/es/spanstore/dbmodel/from_domain_test.go
index b57d8383e70..109c6cd0a15 100644
--- a/plugin/storage/es/spanstore/dbmodel/from_domain_test.go
+++ b/plugin/storage/es/spanstore/dbmodel/from_domain_test.go
@@ -38,7 +38,10 @@ func TestFromDomainEmbedProcess(t *testing.T) {
domainStr, jsonStr := loadFixtures(t, i)
var span model.Span
- require.NoError(t, jsonpb.Unmarshal(bytes.NewReader(domainStr), &span))
+ require.NoError(
+ t,
+ jsonpb.Unmarshal(bytes.NewReader(domainStr), &span),
+ )
converter := NewFromDomain(false, nil, ":")
embeddedSpan := converter.FromDomainEmbedProcess(&span)
@@ -140,19 +143,30 @@ func TestConvertKeyValueValue(t *testing.T) {
expected: KeyValue{Key: key, Value: longString, Type: "string"},
},
{
- kv: model.Binary(key, []byte(longString)),
- expected: KeyValue{Key: key, Value: hex.EncodeToString([]byte(longString)), Type: "binary"},
+ kv: model.Binary(key, []byte(longString)),
+ expected: KeyValue{
+ Key: key,
+ Value: hex.EncodeToString([]byte(longString)),
+ Type: "binary",
+ },
},
{
- kv: model.KeyValue{VType: 1500, Key: key},
- expected: KeyValue{Key: key, Value: "unknown type 1500", Type: "1500"},
+ kv: model.KeyValue{VType: 1500, Key: key},
+ expected: KeyValue{
+ Key: key,
+ Value: "unknown type 1500",
+ Type: "1500",
+ },
},
}
for _, test := range tests {
- t.Run(fmt.Sprintf("%s:%s", test.expected.Type, test.expected.Key), func(t *testing.T) {
- actual := convertKeyValue(test.kv)
- assert.Equal(t, test.expected, actual)
- })
+ t.Run(
+ fmt.Sprintf("%s:%s", test.expected.Type, test.expected.Key),
+ func(t *testing.T) {
+ actual := convertKeyValue(test.kv)
+ assert.Equal(t, test.expected, actual)
+ },
+ )
}
}
diff --git a/plugin/storage/es/spanstore/dbmodel/json_span_compare_test.go b/plugin/storage/es/spanstore/dbmodel/json_span_compare_test.go
index af388cac119..7114404a162 100644
--- a/plugin/storage/es/spanstore/dbmodel/json_span_compare_test.go
+++ b/plugin/storage/es/spanstore/dbmodel/json_span_compare_test.go
@@ -57,9 +57,14 @@ func sortJSONTags(tags []KeyValue) {
type JSONLogByTimestamp []Log
-func (t JSONLogByTimestamp) Len() int { return len(t) }
-func (t JSONLogByTimestamp) Swap(i, j int) { t[i], t[j] = t[j], t[i] }
-func (t JSONLogByTimestamp) Less(i, j int) bool { return t[i].Timestamp < t[j].Timestamp }
+func (t JSONLogByTimestamp) Len() int { return len(t) }
+func (t JSONLogByTimestamp) Swap(i, j int) { t[i], t[j] = t[j], t[i] }
+
+func (t JSONLogByTimestamp) Less(
+ i, j int,
+) bool {
+ return t[i].Timestamp < t[j].Timestamp
+}
func sortJSONLogs(logs []Log) {
sort.Sort(JSONLogByTimestamp(logs))
diff --git a/plugin/storage/es/spanstore/dbmodel/to_domain.go b/plugin/storage/es/spanstore/dbmodel/to_domain.go
index 2bdd34ff64c..f0d34a2e5fa 100644
--- a/plugin/storage/es/spanstore/dbmodel/to_domain.go
+++ b/plugin/storage/es/spanstore/dbmodel/to_domain.go
@@ -113,7 +113,10 @@ func (ToDomain) convertRefs(refs []Reference) ([]model.SpanRef, error) {
case FollowsFrom:
refType = model.FollowsFrom
default:
- return nil, fmt.Errorf("not a valid SpanRefType string %s", string(r.RefType))
+ return nil, fmt.Errorf(
+ "not a valid SpanRefType string %s",
+ string(r.RefType),
+ )
}
traceID, err := model.TraceIDFromString(string(r.TraceID))
@@ -147,7 +150,9 @@ func (td ToDomain) convertKeyValues(tags []KeyValue) ([]model.KeyValue, error) {
return retMe, nil
}
-func (td ToDomain) convertTagFields(tagsMap map[string]any) ([]model.KeyValue, error) {
+func (td ToDomain) convertTagFields(
+ tagsMap map[string]any,
+) ([]model.KeyValue, error) {
kvs := make([]model.KeyValue, len(tagsMap))
i := 0
for k, v := range tagsMap {
@@ -200,7 +205,11 @@ func (ToDomain) convertKeyValue(tag *KeyValue) (model.KeyValue, error) {
}
tagValue, ok := tag.Value.(string)
if !ok {
- return model.KeyValue{}, fmt.Errorf("non-string Value of type %t in %v", tag.Value, tag)
+ return model.KeyValue{}, fmt.Errorf(
+ "non-string Value of type %t in %v",
+ tag.Value,
+ tag,
+ )
}
switch tag.Type {
case StringType:
@@ -230,7 +239,10 @@ func (ToDomain) convertKeyValue(tag *KeyValue) (model.KeyValue, error) {
}
return model.Binary(tag.Key, value), nil
}
- return model.KeyValue{}, fmt.Errorf("not a valid ValueType string %s", string(tag.Type))
+ return model.KeyValue{}, fmt.Errorf(
+ "not a valid ValueType string %s",
+ string(tag.Type),
+ )
}
func (td ToDomain) convertLogs(logs []Log) ([]model.Log, error) {
diff --git a/plugin/storage/es/spanstore/dbmodel/to_domain_test.go b/plugin/storage/es/spanstore/dbmodel/to_domain_test.go
index cba408a1143..382ca195525 100644
--- a/plugin/storage/es/spanstore/dbmodel/to_domain_test.go
+++ b/plugin/storage/es/spanstore/dbmodel/to_domain_test.go
@@ -53,7 +53,10 @@ func testToDomain(t *testing.T, testParentSpanID bool) {
outStr, err := os.ReadFile(out)
require.NoError(t, err)
var expectedSpan model.Span
- require.NoError(t, gogojsonpb.Unmarshal(bytes.NewReader(outStr), &expectedSpan))
+ require.NoError(
+ t,
+ gogojsonpb.Unmarshal(bytes.NewReader(outStr), &expectedSpan),
+ )
CompareModelSpans(t, &expectedSpan, actualSpan)
}
@@ -167,7 +170,11 @@ func TestFailureBadLogs(t *testing.T) {
},
},
}
- failingSpanTransform(t, &badLogsESSpan, "not a valid ValueType string badType")
+ failingSpanTransform(
+ t,
+ &badLogsESSpan,
+ "not a valid ValueType string badType",
+ )
}
func TestRevertKeyValueOfType(t *testing.T) {
@@ -214,7 +221,11 @@ func TestFailureBadRefs(t *testing.T) {
TraceID: "1",
},
}
- failingSpanTransform(t, &badRefsESSpan, "not a valid SpanRefType string makeOurOwnCasino")
+ failingSpanTransform(
+ t,
+ &badRefsESSpan,
+ "not a valid SpanRefType string makeOurOwnCasino",
+ )
}
func TestFailureBadTraceIDRefs(t *testing.T) {
@@ -258,7 +269,11 @@ func TestFailureBadProcess(t *testing.T) {
ServiceName: "hello",
Tags: badTags,
}
- failingSpanTransform(t, &badProcessESSpan, "not a valid ValueType string badType")
+ failingSpanTransform(
+ t,
+ &badProcessESSpan,
+ "not a valid ValueType string badType",
+ )
}
func TestFailureBadTraceID(t *testing.T) {
@@ -320,16 +335,40 @@ func TestTagsMap(t *testing.T) {
{fieldTags: map[string]any{"int.int": int64(1)}, expected: []model.KeyValue{model.Int64("int.int", 1)}},
{fieldTags: map[string]any{"int:int": int64(2)}, expected: []model.KeyValue{model.Int64("int.int", 2)}},
{fieldTags: map[string]any{"float": float64(1.1)}, expected: []model.KeyValue{model.Float64("float", 1.1)}},
- {fieldTags: map[string]any{"float": float64(123)}, expected: []model.KeyValue{model.Float64("float", float64(123))}},
- {fieldTags: map[string]any{"float": float64(123.0)}, expected: []model.KeyValue{model.Float64("float", float64(123.0))}},
- {fieldTags: map[string]any{"float:float": float64(123)}, expected: []model.KeyValue{model.Float64("float.float", float64(123))}},
- {fieldTags: map[string]any{"json_number:int": json.Number("123")}, expected: []model.KeyValue{model.Int64("json_number.int", 123)}},
- {fieldTags: map[string]any{"json_number:float": json.Number("123.0")}, expected: []model.KeyValue{model.Float64("json_number.float", float64(123.0))}},
- {fieldTags: map[string]any{"json_number:err": json.Number("foo")}, err: fmt.Errorf("invalid tag type in foo: strconv.ParseFloat: parsing \"foo\": invalid syntax")},
+ {
+ fieldTags: map[string]any{"float": float64(123)},
+ expected: []model.KeyValue{model.Float64("float", float64(123))},
+ },
+ {
+ fieldTags: map[string]any{"float": float64(123.0)},
+ expected: []model.KeyValue{model.Float64("float", float64(123.0))},
+ },
+ {
+ fieldTags: map[string]any{"float:float": float64(123)},
+ expected: []model.KeyValue{model.Float64("float.float", float64(123))},
+ },
+ {
+ fieldTags: map[string]any{"json_number:int": json.Number("123")},
+ expected: []model.KeyValue{model.Int64("json_number.int", 123)},
+ },
+ {
+ fieldTags: map[string]any{"json_number:float": json.Number("123.0")},
+ expected: []model.KeyValue{model.Float64("json_number.float", float64(123.0))},
+ },
+ {
+ fieldTags: map[string]any{"json_number:err": json.Number("foo")},
+ err: fmt.Errorf("invalid tag type in foo: strconv.ParseFloat: parsing \"foo\": invalid syntax"),
+ },
{fieldTags: map[string]any{"str": "foo"}, expected: []model.KeyValue{model.String("str", "foo")}},
{fieldTags: map[string]any{"str:str": "foo"}, expected: []model.KeyValue{model.String("str.str", "foo")}},
- {fieldTags: map[string]any{"binary": []byte("foo")}, expected: []model.KeyValue{model.Binary("binary", []byte("foo"))}},
- {fieldTags: map[string]any{"binary:binary": []byte("foo")}, expected: []model.KeyValue{model.Binary("binary.binary", []byte("foo"))}},
+ {
+ fieldTags: map[string]any{"binary": []byte("foo")},
+ expected: []model.KeyValue{model.Binary("binary", []byte("foo"))},
+ },
+ {
+ fieldTags: map[string]any{"binary:binary": []byte("foo")},
+ expected: []model.KeyValue{model.Binary("binary.binary", []byte("foo"))},
+ },
{fieldTags: map[string]any{"unsupported": struct{}{}}, err: fmt.Errorf("invalid tag type in %+v", struct{}{})},
}
converter := NewToDomain(":")
diff --git a/plugin/storage/es/spanstore/reader.go b/plugin/storage/es/spanstore/reader.go
index 51a2e380edf..b4ce7238ecc 100644
--- a/plugin/storage/es/spanstore/reader.go
+++ b/plugin/storage/es/spanstore/reader.go
@@ -69,10 +69,14 @@ var (
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")
@@ -81,13 +85,19 @@ var (
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)
objectTagFieldList = []string{objectTagsField, objectProcessTagsField}
- nestedTagFieldList = []string{nestedTagsField, nestedProcessTagsField, nestedLogFieldsField}
+ nestedTagFieldList = []string{
+ nestedTagsField,
+ nestedProcessTagsField,
+ nestedLogFieldsField,
+ }
)
// SpanReader can query for and load traces from ElasticSearch
@@ -140,9 +150,13 @@ func NewSpanReader(p SpanReaderParams) *SpanReader {
maxSpanAge = rolloverMaxSpanAge
}
return &SpanReader{
- client: p.Client,
- maxSpanAge: maxSpanAge,
- serviceOperationStorage: NewServiceOperationStorage(p.Client, p.Logger, 0), // the decorator takes care of metrics
+ client: p.Client,
+ maxSpanAge: maxSpanAge,
+ serviceOperationStorage: NewServiceOperationStorage(
+ p.Client,
+ p.Logger,
+ 0,
+ ), // the decorator takes care of metrics
spanIndexPrefix: indexNames(p.IndexPrefix, spanIndex),
serviceIndexPrefix: indexNames(p.IndexPrefix, serviceIndex),
spanIndexDateLayout: p.SpanIndexDateLayout,
@@ -150,12 +164,16 @@ func NewSpanReader(p SpanReaderParams) *SpanReader {
spanIndexRolloverFrequency: p.SpanIndexRolloverFrequency,
serviceIndexRolloverFrequency: p.SpanIndexRolloverFrequency,
spanConverter: dbmodel.NewToDomain(p.TagDotReplacement),
- timeRangeIndices: getTimeRangeIndexFn(p.Archive, p.UseReadWriteAliases, p.RemoteReadClusters),
- sourceFn: getSourceFn(p.Archive, p.MaxDocCount),
- maxDocCount: p.MaxDocCount,
- useReadWriteAliases: p.UseReadWriteAliases,
- logger: p.Logger,
- tracer: p.Tracer,
+ timeRangeIndices: getTimeRangeIndexFn(
+ p.Archive,
+ p.UseReadWriteAliases,
+ p.RemoteReadClusters,
+ ),
+ sourceFn: getSourceFn(p.Archive, p.MaxDocCount),
+ maxDocCount: p.MaxDocCount,
+ useReadWriteAliases: p.UseReadWriteAliases,
+ logger: p.Logger,
+ tracer: p.Tracer,
}
}
@@ -163,7 +181,10 @@ type timeRangeIndexFn func(indexName string, indexDateLayout string, startTime t
type sourceFn func(query elastic.Query, nextTime uint64) *elastic.SearchSource
-func getTimeRangeIndexFn(archive, useReadWriteAliases bool, remoteReadClusters []string) timeRangeIndexFn {
+func getTimeRangeIndexFn(
+ archive, useReadWriteAliases bool,
+ remoteReadClusters []string,
+) timeRangeIndexFn {
if archive {
var archiveSuffix string
if useReadWriteAliases {
@@ -171,23 +192,38 @@ func getTimeRangeIndexFn(archive, useReadWriteAliases bool, remoteReadClusters [
} else {
archiveSuffix = archiveIndexSuffix
}
- return addRemoteReadClusters(func(indexPrefix, indexDateLayout string, startTime time.Time, endTime time.Time, reduceDuration time.Duration) []string {
- return []string{archiveIndex(indexPrefix, archiveSuffix)}
- }, remoteReadClusters)
+ return addRemoteReadClusters(
+ func(indexPrefix, indexDateLayout string, startTime time.Time, endTime time.Time, reduceDuration time.Duration) []string {
+ return []string{archiveIndex(indexPrefix, archiveSuffix)}
+ },
+ remoteReadClusters,
+ )
}
if useReadWriteAliases {
- return addRemoteReadClusters(func(indexPrefix string, indexDateLayout string, startTime time.Time, endTime time.Time, reduceDuration time.Duration) []string {
- return []string{indexPrefix + "read"}
- }, remoteReadClusters)
+ return addRemoteReadClusters(
+ func(indexPrefix string, indexDateLayout string, startTime time.Time, endTime time.Time, reduceDuration time.Duration) []string {
+ return []string{indexPrefix + "read"}
+ },
+ remoteReadClusters,
+ )
}
return addRemoteReadClusters(timeRangeIndices, remoteReadClusters)
}
// Add a remote cluster prefix for each cluster and for each index and add it to the list of original indices.
// Elasticsearch cross cluster api example GET /twitter,cluster_one:twitter,cluster_two:twitter/_search.
-func addRemoteReadClusters(fn timeRangeIndexFn, remoteReadClusters []string) timeRangeIndexFn {
+func addRemoteReadClusters(
+ fn timeRangeIndexFn,
+ remoteReadClusters []string,
+) timeRangeIndexFn {
return func(indexPrefix string, indexDateLayout string, startTime time.Time, endTime time.Time, reduceDuration time.Duration) []string {
- jaegerIndices := fn(indexPrefix, indexDateLayout, startTime, endTime, reduceDuration)
+ jaegerIndices := fn(
+ indexPrefix,
+ indexDateLayout,
+ startTime,
+ endTime,
+ reduceDuration,
+ )
if len(remoteReadClusters) == 0 {
return jaegerIndices
}
@@ -217,7 +253,12 @@ func getSourceFn(archive bool, maxDocCount int) sourceFn {
}
// timeRangeIndices returns the array of indices that we need to query, based on query params
-func timeRangeIndices(indexName, indexDateLayout string, startTime time.Time, endTime time.Time, reduceDuration time.Duration) []string {
+func timeRangeIndices(
+ indexName, indexDateLayout string,
+ startTime time.Time,
+ endTime time.Time,
+ reduceDuration time.Duration,
+) []string {
var indices []string
firstIndex := indexWithDate(indexName, indexDateLayout, startTime)
currentIndex := indexWithDate(indexName, indexDateLayout, endTime)
@@ -240,11 +281,19 @@ func indexNames(prefix, index string) string {
}
// GetTrace takes a traceID and returns a Trace associated with that traceID
-func (s *SpanReader) GetTrace(ctx context.Context, traceID model.TraceID) (*model.Trace, error) {
+func (s *SpanReader) GetTrace(
+ ctx context.Context,
+ traceID model.TraceID,
+) (*model.Trace, error) {
ctx, span := s.tracer.Start(ctx, "GetTrace")
defer span.End()
currentTime := time.Now()
- traces, err := s.multiRead(ctx, []model.TraceID{traceID}, currentTime.Add(-s.maxSpanAge), currentTime)
+ traces, err := s.multiRead(
+ ctx,
+ []model.TraceID{traceID},
+ currentTime.Add(-s.maxSpanAge),
+ currentTime,
+ )
if err != nil {
return nil, es.DetailedError(err)
}
@@ -254,24 +303,34 @@ func (s *SpanReader) GetTrace(ctx context.Context, traceID model.TraceID) (*mode
return traces[0], nil
}
-func (s *SpanReader) collectSpans(esSpansRaw []*elastic.SearchHit) ([]*model.Span, error) {
+func (s *SpanReader) collectSpans(
+ esSpansRaw []*elastic.SearchHit,
+) ([]*model.Span, error) {
spans := make([]*model.Span, len(esSpansRaw))
for i, esSpanRaw := range esSpansRaw {
jsonSpan, err := s.unmarshalJSONSpan(esSpanRaw)
if err != nil {
- return nil, fmt.Errorf("marshalling JSON to span object failed: %w", err)
+ return nil, fmt.Errorf(
+ "marshalling JSON to span object failed: %w",
+ err,
+ )
}
span, err := s.spanConverter.SpanToDomain(jsonSpan)
if err != nil {
- return nil, fmt.Errorf("converting JSONSpan to domain Span failed: %w", err)
+ return nil, fmt.Errorf(
+ "converting JSONSpan to domain Span failed: %w",
+ err,
+ )
}
spans[i] = span
}
return spans, nil
}
-func (*SpanReader) unmarshalJSONSpan(esSpanRaw *elastic.SearchHit) (*dbmodel.Span, error) {
+func (*SpanReader) unmarshalJSONSpan(
+ esSpanRaw *elastic.SearchHit,
+) (*dbmodel.Span, error) {
esSpanInByteArray := esSpanRaw.Source
var jsonSpan dbmodel.Span
@@ -289,7 +348,13 @@ func (s *SpanReader) GetServices(ctx context.Context) ([]string, error) {
ctx, span := s.tracer.Start(ctx, "GetService")
defer span.End()
currentTime := time.Now()
- jaegerIndices := s.timeRangeIndices(s.serviceIndexPrefix, s.serviceIndexDateLayout, currentTime.Add(-s.maxSpanAge), currentTime, s.serviceIndexRolloverFrequency)
+ jaegerIndices := s.timeRangeIndices(
+ s.serviceIndexPrefix,
+ s.serviceIndexDateLayout,
+ currentTime.Add(-s.maxSpanAge),
+ currentTime,
+ s.serviceIndexRolloverFrequency,
+ )
return s.serviceOperationStorage.getServices(ctx, jaegerIndices, s.maxDocCount)
}
@@ -301,7 +366,13 @@ func (s *SpanReader) GetOperations(
ctx, span := s.tracer.Start(ctx, "GetOperations")
defer span.End()
currentTime := time.Now()
- jaegerIndices := s.timeRangeIndices(s.serviceIndexPrefix, s.serviceIndexDateLayout, currentTime.Add(-s.maxSpanAge), currentTime, s.serviceIndexRolloverFrequency)
+ jaegerIndices := s.timeRangeIndices(
+ s.serviceIndexPrefix,
+ s.serviceIndexDateLayout,
+ currentTime.Add(-s.maxSpanAge),
+ currentTime,
+ s.serviceIndexRolloverFrequency,
+ )
operations, err := s.serviceOperationStorage.getOperations(ctx, jaegerIndices, query.ServiceName, s.maxDocCount)
if err != nil {
return nil, err
@@ -318,7 +389,9 @@ func (s *SpanReader) GetOperations(
return result, err
}
-func bucketToStringArray(buckets []*elastic.AggregationBucketKeyItem) ([]string, error) {
+func bucketToStringArray(
+ buckets []*elastic.AggregationBucketKeyItem,
+) ([]string, error) {
strings := make([]string, len(buckets))
for i, keyitem := range buckets {
str, ok := keyitem.Key.(string)
@@ -331,7 +404,10 @@ func bucketToStringArray(buckets []*elastic.AggregationBucketKeyItem) ([]string,
}
// FindTraces retrieves traces that match the traceQuery
-func (s *SpanReader) FindTraces(ctx context.Context, traceQuery *spanstore.TraceQueryParameters) ([]*model.Trace, error) {
+func (s *SpanReader) FindTraces(
+ ctx context.Context,
+ traceQuery *spanstore.TraceQueryParameters,
+) ([]*model.Trace, error) {
ctx, span := s.tracer.Start(ctx, "FindTraces")
defer span.End()
@@ -339,11 +415,19 @@ func (s *SpanReader) FindTraces(ctx context.Context, traceQuery *spanstore.Trace
if err != nil {
return nil, es.DetailedError(err)
}
- return s.multiRead(ctx, uniqueTraceIDs, traceQuery.StartTimeMin, traceQuery.StartTimeMax)
+ return s.multiRead(
+ ctx,
+ uniqueTraceIDs,
+ traceQuery.StartTimeMin,
+ traceQuery.StartTimeMax,
+ )
}
// FindTraceIDs retrieves traces IDs that match the traceQuery
-func (s *SpanReader) FindTraceIDs(ctx context.Context, traceQuery *spanstore.TraceQueryParameters) ([]model.TraceID, error) {
+func (s *SpanReader) FindTraceIDs(
+ ctx context.Context,
+ traceQuery *spanstore.TraceQueryParameters,
+) ([]model.TraceID, error) {
ctx, span := s.tracer.Start(ctx, "FindTraceIDs")
defer span.End()
@@ -362,7 +446,11 @@ func (s *SpanReader) FindTraceIDs(ctx context.Context, traceQuery *spanstore.Tra
return convertTraceIDsStringsToModels(esTraceIDs)
}
-func (s *SpanReader) multiRead(ctx context.Context, traceIDs []model.TraceID, startTime, endTime time.Time) ([]*model.Trace, error) {
+func (s *SpanReader) multiRead(
+ ctx context.Context,
+ traceIDs []model.TraceID,
+ startTime, endTime time.Time,
+) ([]*model.Trace, error) {
ctx, childSpan := s.tracer.Start(ctx, "multiRead")
defer childSpan.End()
@@ -371,7 +459,9 @@ func (s *SpanReader) multiRead(ctx context.Context, traceIDs []model.TraceID, st
for i, traceID := range traceIDs {
tracesIDs[i] = traceID.String()
}
- childSpan.SetAttributes(attribute.Key("trace_ids").StringSlice(tracesIDs))
+ childSpan.SetAttributes(
+ attribute.Key("trace_ids").StringSlice(tracesIDs),
+ )
}
if len(traceIDs) == 0 {
@@ -380,7 +470,13 @@ func (s *SpanReader) multiRead(ctx context.Context, traceIDs []model.TraceID, st
// Add an hour in both directions so that traces that straddle two indexes are retrieved.
// i.e starts in one and ends in another.
- indices := s.timeRangeIndices(s.spanIndexPrefix, s.spanIndexDateLayout, startTime.Add(-time.Hour), endTime.Add(time.Hour), s.spanIndexRolloverFrequency)
+ indices := s.timeRangeIndices(
+ s.spanIndexPrefix,
+ s.spanIndexDateLayout,
+ startTime.Add(-time.Hour),
+ endTime.Add(time.Hour),
+ s.spanIndexRolloverFrequency,
+ )
nextTime := model.TimeAsEpochMicroseconds(startTime.Add(-time.Hour))
searchAfterTime := make(map[model.TraceID]uint64)
totalDocumentsFetched := make(map[model.TraceID]int)
@@ -395,7 +491,10 @@ func (s *SpanReader) multiRead(ctx context.Context, traceIDs []model.TraceID, st
query := elastic.NewBoolQuery().
Must(traceQuery)
if s.useReadWriteAliases {
- startTimeRangeQuery := s.buildStartTimeQuery(startTime.Add(-time.Hour*24), endTime.Add(time.Hour*24))
+ startTimeRangeQuery := s.buildStartTimeQuery(
+ startTime.Add(-time.Hour*24),
+ endTime.Add(time.Hour*24),
+ )
query = query.Must(startTimeRangeQuery)
}
@@ -410,7 +509,11 @@ func (s *SpanReader) multiRead(ctx context.Context, traceIDs []model.TraceID, st
}
// set traceIDs to empty
traceIDs = nil
- results, err := s.client().MultiSearch().Add(searchRequests...).Index(indices...).Do(ctx)
+ results, err := s.client().
+ MultiSearch().
+ Add(searchRequests...).
+ Index(indices...).
+ Do(ctx)
if err != nil {
err = es.DetailedError(err)
logErrorToSpan(childSpan, err)
@@ -440,9 +543,13 @@ func (s *SpanReader) multiRead(ctx context.Context, traceIDs []model.TraceID, st
}
totalDocumentsFetched[lastSpan.TraceID] += len(result.Hits.Hits)
- if totalDocumentsFetched[lastSpan.TraceID] < int(result.TotalHits()) {
+ if totalDocumentsFetched[lastSpan.TraceID] < int(
+ result.TotalHits(),
+ ) {
traceIDs = append(traceIDs, lastSpan.TraceID)
- searchAfterTime[lastSpan.TraceID] = model.TimeAsEpochMicroseconds(lastSpan.StartTime)
+ searchAfterTime[lastSpan.TraceID] = model.TimeAsEpochMicroseconds(
+ lastSpan.StartTime,
+ )
}
}
}
@@ -473,7 +580,9 @@ func buildTraceByIDQuery(traceID model.TraceID) elastic.Query {
elastic.NewTermQuery(traceIDField, legacyTraceID))
}
-func convertTraceIDsStringsToModels(traceIDs []string) ([]model.TraceID, error) {
+func convertTraceIDsStringsToModels(
+ traceIDs []string,
+) ([]model.TraceID, error) {
traceIDsMap := map[model.TraceID]bool{}
// https://github.com/jaegertracing/jaeger/pull/1956 added leading zeros to IDs
// So we need to also read IDs without leading zeros for compatibility with previously saved data.
@@ -484,7 +593,11 @@ func convertTraceIDsStringsToModels(traceIDs []string) ([]model.TraceID, error)
for _, ID := range traceIDs {
traceID, err := model.TraceIDFromString(ID)
if err != nil {
- return nil, fmt.Errorf("making traceID from string '%s' failed: %w", ID, err)
+ return nil, fmt.Errorf(
+ "making traceID from string '%s' failed: %w",
+ ID,
+ err,
+ )
}
if _, ok := traceIDsMap[traceID]; !ok {
traceIDsMap[traceID] = true
@@ -508,13 +621,17 @@ func validateQuery(p *spanstore.TraceQueryParameters) error {
if p.StartTimeMax.Before(p.StartTimeMin) {
return ErrStartTimeMinGreaterThanMax
}
- if p.DurationMin != 0 && p.DurationMax != 0 && p.DurationMin > p.DurationMax {
+ if p.DurationMin != 0 && p.DurationMax != 0 &&
+ p.DurationMin > p.DurationMax {
return ErrDurationMinGreaterThanMax
}
return nil
}
-func (s *SpanReader) findTraceIDs(ctx context.Context, traceQuery *spanstore.TraceQueryParameters) ([]string, error) {
+func (s *SpanReader) findTraceIDs(
+ ctx context.Context,
+ traceQuery *spanstore.TraceQueryParameters,
+) ([]string, error) {
ctx, childSpan := s.tracer.Start(ctx, "findTraceIDs")
defer childSpan.End()
// Below is the JSON body to our HTTP GET request to ElasticSearch. This function creates this.
@@ -572,7 +689,13 @@ func (s *SpanReader) findTraceIDs(ctx context.Context, traceQuery *spanstore.Tra
// }
aggregation := s.buildTraceIDAggregation(traceQuery.NumTraces)
boolQuery := s.buildFindTraceIDsQuery(traceQuery)
- jaegerIndices := s.timeRangeIndices(s.spanIndexPrefix, s.spanIndexDateLayout, traceQuery.StartTimeMin, traceQuery.StartTimeMax, s.spanIndexRolloverFrequency)
+ jaegerIndices := s.timeRangeIndices(
+ s.spanIndexPrefix,
+ s.spanIndexDateLayout,
+ traceQuery.StartTimeMin,
+ traceQuery.StartTimeMax,
+ s.spanIndexRolloverFrequency,
+ )
searchService := s.client().Search(jaegerIndices...).
Size(0). // set to 0 because we don't want actual documents.
@@ -583,7 +706,11 @@ func (s *SpanReader) findTraceIDs(ctx context.Context, traceQuery *spanstore.Tra
searchResult, err := searchService.Do(ctx)
if err != nil {
err = es.DetailedError(err)
- s.logger.Info("es search services failed", zap.Any("traceQuery", traceQuery), zap.Error(err))
+ s.logger.Info(
+ "es search services failed",
+ zap.Any("traceQuery", traceQuery),
+ zap.Error(err),
+ )
return nil, fmt.Errorf("search services failed: %w", err)
}
if searchResult.Aggregations == nil {
@@ -598,7 +725,9 @@ func (s *SpanReader) findTraceIDs(ctx context.Context, traceQuery *spanstore.Tra
return bucketToStringArray(traceIDBuckets)
}
-func (s *SpanReader) buildTraceIDAggregation(numOfTraces int) elastic.Aggregation {
+func (s *SpanReader) buildTraceIDAggregation(
+ numOfTraces int,
+) elastic.Aggregation {
return elastic.NewTermsAggregation().
Size(numOfTraces).
Field(traceIDField).
@@ -611,17 +740,25 @@ func (*SpanReader) buildTraceIDSubAggregation() elastic.Aggregation {
Field(startTimeField)
}
-func (s *SpanReader) buildFindTraceIDsQuery(traceQuery *spanstore.TraceQueryParameters) elastic.Query {
+func (s *SpanReader) buildFindTraceIDsQuery(
+ traceQuery *spanstore.TraceQueryParameters,
+) elastic.Query {
boolQuery := elastic.NewBoolQuery()
// add duration query
if traceQuery.DurationMax != 0 || traceQuery.DurationMin != 0 {
- durationQuery := s.buildDurationQuery(traceQuery.DurationMin, traceQuery.DurationMax)
+ durationQuery := s.buildDurationQuery(
+ traceQuery.DurationMin,
+ traceQuery.DurationMax,
+ )
boolQuery.Must(durationQuery)
}
// add startTime query
- startTimeQuery := s.buildStartTimeQuery(traceQuery.StartTimeMin, traceQuery.StartTimeMax)
+ startTimeQuery := s.buildStartTimeQuery(
+ traceQuery.StartTimeMin,
+ traceQuery.StartTimeMax,
+ )
boolQuery.Must(startTimeQuery)
// add process.serviceName query
@@ -632,7 +769,9 @@ func (s *SpanReader) buildFindTraceIDsQuery(traceQuery *spanstore.TraceQueryPara
// add operationName query
if traceQuery.OperationName != "" {
- operationNameQuery := s.buildOperationNameQuery(traceQuery.OperationName)
+ operationNameQuery := s.buildOperationNameQuery(
+ traceQuery.OperationName,
+ )
boolQuery.Must(operationNameQuery)
}
@@ -643,22 +782,32 @@ func (s *SpanReader) buildFindTraceIDsQuery(traceQuery *spanstore.TraceQueryPara
return boolQuery
}
-func (*SpanReader) buildDurationQuery(durationMin time.Duration, durationMax time.Duration) elastic.Query {
+func (*SpanReader) buildDurationQuery(
+ durationMin time.Duration,
+ durationMax time.Duration,
+) elastic.Query {
minDurationMicros := model.DurationAsMicroseconds(durationMin)
maxDurationMicros := defaultMaxDuration
if durationMax != 0 {
maxDurationMicros = model.DurationAsMicroseconds(durationMax)
}
- return elastic.NewRangeQuery(durationField).Gte(minDurationMicros).Lte(maxDurationMicros)
+ return elastic.NewRangeQuery(durationField).
+ Gte(minDurationMicros).
+ Lte(maxDurationMicros)
}
-func (*SpanReader) buildStartTimeQuery(startTimeMin time.Time, startTimeMax time.Time) elastic.Query {
+func (*SpanReader) buildStartTimeQuery(
+ startTimeMin time.Time,
+ startTimeMax time.Time,
+) elastic.Query {
minStartTimeMicros := model.TimeAsEpochMicroseconds(startTimeMin)
maxStartTimeMicros := model.TimeAsEpochMicroseconds(startTimeMax)
// startTimeMillisField is date field in ES mapping.
// Using date field in range queries helps to skip search on unnecessary shards at Elasticsearch side.
// https://discuss.elastic.co/t/timeline-query-on-timestamped-indices/129328/2
- return elastic.NewRangeQuery(startTimeMillisField).Gte(minStartTimeMicros / 1000).Lte(maxStartTimeMicros / 1000)
+ return elastic.NewRangeQuery(startTimeMillisField).
+ Gte(minStartTimeMicros / 1000).
+ Lte(maxStartTimeMicros / 1000)
}
func (*SpanReader) buildServiceNameQuery(serviceName string) elastic.Query {
@@ -677,14 +826,22 @@ func (s *SpanReader) buildTagQuery(k string, v string) elastic.Query {
queries[i] = s.buildObjectQuery(objectTagFieldList[i], kd, v)
}
for i := range nestedTagFieldList {
- queries[i+objectTagListLen] = s.buildNestedQuery(nestedTagFieldList[i], k, v)
+ queries[i+objectTagListLen] = s.buildNestedQuery(
+ nestedTagFieldList[i],
+ k,
+ v,
+ )
}
// but configuration can change over time
return elastic.NewBoolQuery().Should(queries...)
}
-func (*SpanReader) buildNestedQuery(field string, k string, v string) elastic.Query {
+func (*SpanReader) buildNestedQuery(
+ field string,
+ k string,
+ v string,
+) elastic.Query {
keyField := fmt.Sprintf("%s.%s", field, tagKeyField)
valueField := fmt.Sprintf("%s.%s", field, tagValueField)
keyQuery := elastic.NewMatchQuery(keyField, k)
@@ -693,7 +850,11 @@ func (*SpanReader) buildNestedQuery(field string, k string, v string) elastic.Qu
return elastic.NewNestedQuery(field, tagBoolQuery)
}
-func (*SpanReader) buildObjectQuery(field string, k string, v string) elastic.Query {
+func (*SpanReader) buildObjectQuery(
+ field string,
+ k string,
+ v string,
+) elastic.Query {
keyField := fmt.Sprintf("%s.%s", field, k)
keyQuery := elastic.NewRegexpQuery(keyField, v)
return elastic.NewBoolQuery().Must(keyQuery)
diff --git a/plugin/storage/es/spanstore/reader_test.go b/plugin/storage/es/spanstore/reader_test.go
index f989ca29616..1d73db0d3f1 100644
--- a/plugin/storage/es/spanstore/reader_test.go
+++ b/plugin/storage/es/spanstore/reader_test.go
@@ -94,7 +94,9 @@ type spanReaderTest struct {
reader *SpanReader
}
-func tracerProvider(t *testing.T) (trace.TracerProvider, *tracetest.InMemoryExporter, func()) {
+func tracerProvider(
+ t *testing.T,
+) (trace.TracerProvider, *tracetest.InMemoryExporter, func()) {
exporter := tracetest.NewInMemoryExporter()
tp := sdktrace.NewTracerProvider(
sdktrace.WithSampler(sdktrace.AlwaysSample()),
@@ -129,7 +131,11 @@ func withSpanReader(t *testing.T, fn func(r *spanReaderTest)) {
fn(r)
}
-func withArchiveSpanReader(t *testing.T, readAlias bool, fn func(r *spanReaderTest)) {
+func withArchiveSpanReader(
+ t *testing.T,
+ readAlias bool,
+ fn func(r *spanReaderTest),
+) {
client := &mocks.Client{}
tracer, exp, closer := tracerProvider(t)
defer closer()
@@ -207,7 +213,10 @@ func TestSpanReaderIndices(t *testing.T) {
params: SpanReaderParams{
IndexPrefix: "", Archive: false, SpanIndexDateLayout: spanDataLayout, ServiceIndexDateLayout: serviceDataLayout,
},
- indices: []string{spanIndex + spanDataLayoutFormat, serviceIndex + serviceDataLayoutFormat},
+ indices: []string{
+ spanIndex + spanDataLayoutFormat,
+ serviceIndex + serviceDataLayoutFormat,
+ },
},
{
params: SpanReaderParams{
@@ -219,31 +228,46 @@ func TestSpanReaderIndices(t *testing.T) {
params: SpanReaderParams{
IndexPrefix: "foo:", Archive: false, SpanIndexDateLayout: spanDataLayout, ServiceIndexDateLayout: serviceDataLayout,
},
- indices: []string{"foo:" + indexPrefixSeparator + spanIndex + spanDataLayoutFormat, "foo:" + indexPrefixSeparator + serviceIndex + serviceDataLayoutFormat},
+ indices: []string{
+ "foo:" + indexPrefixSeparator + spanIndex + spanDataLayoutFormat,
+ "foo:" + indexPrefixSeparator + serviceIndex + serviceDataLayoutFormat,
+ },
},
{
params: SpanReaderParams{
IndexPrefix: "foo:", UseReadWriteAliases: true,
},
- indices: []string{"foo:-" + spanIndex + "read", "foo:-" + serviceIndex + "read"},
+ indices: []string{
+ "foo:-" + spanIndex + "read",
+ "foo:-" + serviceIndex + "read",
+ },
},
{
params: SpanReaderParams{
IndexPrefix: "", Archive: true,
},
- indices: []string{spanIndex + archiveIndexSuffix, serviceIndex + archiveIndexSuffix},
+ indices: []string{
+ spanIndex + archiveIndexSuffix,
+ serviceIndex + archiveIndexSuffix,
+ },
},
{
params: SpanReaderParams{
IndexPrefix: "foo:", Archive: true,
},
- indices: []string{"foo:" + indexPrefixSeparator + spanIndex + archiveIndexSuffix, "foo:" + indexPrefixSeparator + serviceIndex + archiveIndexSuffix},
+ indices: []string{
+ "foo:" + indexPrefixSeparator + spanIndex + archiveIndexSuffix,
+ "foo:" + indexPrefixSeparator + serviceIndex + archiveIndexSuffix,
+ },
},
{
params: SpanReaderParams{
IndexPrefix: "foo:", Archive: true, UseReadWriteAliases: true,
},
- indices: []string{"foo:" + indexPrefixSeparator + spanIndex + archiveReadIndexSuffix, "foo:" + indexPrefixSeparator + serviceIndex + archiveReadIndexSuffix},
+ indices: []string{
+ "foo:" + indexPrefixSeparator + spanIndex + archiveReadIndexSuffix,
+ "foo:" + indexPrefixSeparator + serviceIndex + archiveReadIndexSuffix,
+ },
},
{
params: SpanReaderParams{
@@ -305,8 +329,20 @@ func TestSpanReaderIndices(t *testing.T) {
testCase.params.Tracer = tracer.Tracer("test")
r := NewSpanReader(testCase.params)
- actualSpan := r.timeRangeIndices(r.spanIndexPrefix, r.spanIndexDateLayout, date, date, -1*time.Hour)
- actualService := r.timeRangeIndices(r.serviceIndexPrefix, r.serviceIndexDateLayout, date, date, -24*time.Hour)
+ actualSpan := r.timeRangeIndices(
+ r.spanIndexPrefix,
+ r.spanIndexDateLayout,
+ date,
+ date,
+ -1*time.Hour,
+ )
+ actualService := r.timeRangeIndices(
+ r.serviceIndexPrefix,
+ r.serviceIndexDateLayout,
+ date,
+ date,
+ -24*time.Hour,
+ )
assert.Equal(t, testCase.indices, append(actualSpan, actualService...))
}
}
@@ -319,7 +355,9 @@ func TestSpanReader_GetTrace(t *testing.T) {
}
searchHits := &elastic.SearchHits{Hits: hits}
- mockSearchService(r).Return(&elastic.SearchResult{Hits: searchHits}, nil)
+ mockSearchService(
+ r,
+ ).Return(&elastic.SearchResult{Hits: searchHits}, nil)
mockMultiSearchService(r).
Return(&elastic.MultiSearchResult{
Responses: []*elastic.SearchResult{
@@ -327,7 +365,10 @@ func TestSpanReader_GetTrace(t *testing.T) {
},
}, nil)
- trace, err := r.reader.GetTrace(context.Background(), model.NewTraceID(0, 1))
+ trace, err := r.reader.GetTrace(
+ context.Background(),
+ model.NewTraceID(0, 1),
+ )
require.NotEmpty(t, r.traceBuffer.GetSpans(), "Spans recorded")
require.NoError(t, err)
require.NotNil(t, trace)
@@ -343,22 +384,32 @@ func TestSpanReader_GetTrace(t *testing.T) {
func TestSpanReader_multiRead_followUp_query(t *testing.T) {
withSpanReader(t, func(r *spanReaderTest) {
date := time.Date(2019, 10, 10, 5, 0, 0, 0, time.UTC)
- spanID1 := dbmodel.Span{SpanID: "0", TraceID: "1", StartTime: model.TimeAsEpochMicroseconds(date)}
+ spanID1 := dbmodel.Span{
+ SpanID: "0",
+ TraceID: "1",
+ StartTime: model.TimeAsEpochMicroseconds(date),
+ }
spanBytesID1, err := json.Marshal(spanID1)
require.NoError(t, err)
- spanID2 := dbmodel.Span{SpanID: "0", TraceID: "2", StartTime: model.TimeAsEpochMicroseconds(date)}
+ spanID2 := dbmodel.Span{
+ SpanID: "0",
+ TraceID: "2",
+ StartTime: model.TimeAsEpochMicroseconds(date),
+ }
spanBytesID2, err := json.Marshal(spanID2)
require.NoError(t, err)
traceID1Query := elastic.NewBoolQuery().Should(
- elastic.NewTermQuery(traceIDField, model.TraceID{High: 0, Low: 1}.String()).Boost(2),
+ elastic.NewTermQuery(traceIDField, model.TraceID{High: 0, Low: 1}.String()).
+ Boost(2),
elastic.NewTermQuery(traceIDField, fmt.Sprintf("%x", 1)))
id1Query := elastic.NewBoolQuery().Must(traceID1Query)
id1Search := elastic.NewSearchRequest().
IgnoreUnavailable(true).
Source(r.reader.sourceFn(id1Query, model.TimeAsEpochMicroseconds(date.Add(-time.Hour))))
traceID2Query := elastic.NewBoolQuery().Should(
- elastic.NewTermQuery(traceIDField, model.TraceID{High: 0, Low: 2}.String()).Boost(2),
+ elastic.NewTermQuery(traceIDField, model.TraceID{High: 0, Low: 2}.String()).
+ Boost(2),
elastic.NewTermQuery(traceIDField, fmt.Sprintf("%x", 2)))
id2Query := elastic.NewBoolQuery().Must(traceID2Query)
id2Search := elastic.NewSearchRequest().
@@ -371,11 +422,15 @@ func TestSpanReader_multiRead_followUp_query(t *testing.T) {
multiSearchService := &mocks.MultiSearchService{}
firstMultiSearch := &mocks.MultiSearchService{}
secondMultiSearch := &mocks.MultiSearchService{}
- multiSearchService.On("Add", id1Search, id2Search).Return(firstMultiSearch)
- multiSearchService.On("Add", id1SearchSpanTime).Return(secondMultiSearch)
-
- firstMultiSearch.On("Index", mock.AnythingOfType("string")).Return(firstMultiSearch)
- secondMultiSearch.On("Index", mock.AnythingOfType("string")).Return(secondMultiSearch)
+ multiSearchService.On("Add", id1Search, id2Search).
+ Return(firstMultiSearch)
+ multiSearchService.On("Add", id1SearchSpanTime).
+ Return(secondMultiSearch)
+
+ firstMultiSearch.On("Index", mock.AnythingOfType("string")).
+ Return(firstMultiSearch)
+ secondMultiSearch.On("Index", mock.AnythingOfType("string")).
+ Return(secondMultiSearch)
r.client.On("MultiSearch").Return(multiSearchService)
fistMultiSearchMock := firstMultiSearch.On("Do", mock.Anything)
@@ -404,7 +459,12 @@ func TestSpanReader_multiRead_followUp_query(t *testing.T) {
},
}, nil)
- traces, err := r.reader.multiRead(context.Background(), []model.TraceID{{High: 0, Low: 1}, {High: 0, Low: 2}}, date, date)
+ traces, err := r.reader.multiRead(
+ context.Background(),
+ []model.TraceID{{High: 0, Low: 1}, {High: 0, Low: 2}},
+ date,
+ date,
+ )
require.NotEmpty(t, r.traceBuffer.GetSpans(), "Spans recorded")
require.NoError(t, err)
require.NotNil(t, traces)
@@ -417,8 +477,14 @@ func TestSpanReader_multiRead_followUp_query(t *testing.T) {
require.NoError(t, err)
for _, s := range []*model.Span{sModel1, sModel2} {
- found := reflect.DeepEqual(traces[0].Spans[0], s) || reflect.DeepEqual(traces[1].Spans[0], s)
- assert.True(t, found, "span was expected to be within one of the traces but was not: %v", s)
+ found := reflect.DeepEqual(traces[0].Spans[0], s) ||
+ reflect.DeepEqual(traces[1].Spans[0], s)
+ assert.True(
+ t,
+ found,
+ "span was expected to be within one of the traces but was not: %v",
+ s,
+ )
}
})
}
@@ -428,13 +494,17 @@ func TestSpanReader_SearchAfter(t *testing.T) {
var hits []*elastic.SearchHit
for i := 0; i < 10000; i++ {
- hit := &elastic.SearchHit{Source: (*json.RawMessage)(&exampleESSpan)}
+ hit := &elastic.SearchHit{
+ Source: (*json.RawMessage)(&exampleESSpan),
+ }
hits = append(hits, hit)
}
searchHits := &elastic.SearchHits{Hits: hits, TotalHits: int64(10040)}
- mockSearchService(r).Return(&elastic.SearchResult{Hits: searchHits}, nil)
+ mockSearchService(
+ r,
+ ).Return(&elastic.SearchResult{Hits: searchHits}, nil)
mockMultiSearchService(r).
Return(&elastic.MultiSearchResult{
Responses: []*elastic.SearchResult{
@@ -442,7 +512,10 @@ func TestSpanReader_SearchAfter(t *testing.T) {
},
}, nil).Times(2)
- trace, err := r.reader.GetTrace(context.Background(), model.NewTraceID(0, 1))
+ trace, err := r.reader.GetTrace(
+ context.Background(),
+ model.NewTraceID(0, 1),
+ )
require.NotEmpty(t, r.traceBuffer.GetSpans(), "Spans recorded")
require.NoError(t, err)
require.NotNil(t, trace)
@@ -462,7 +535,10 @@ func TestSpanReader_GetTraceQueryError(t *testing.T) {
Return(&elastic.MultiSearchResult{
Responses: []*elastic.SearchResult{},
}, nil)
- trace, err := r.reader.GetTrace(context.Background(), model.NewTraceID(0, 1))
+ trace, err := r.reader.GetTrace(
+ context.Background(),
+ model.NewTraceID(0, 1),
+ )
require.NotEmpty(t, r.traceBuffer.GetSpans(), "Spans recorded")
require.EqualError(t, err, "trace not found")
require.Nil(t, trace)
@@ -474,7 +550,9 @@ func TestSpanReader_GetTraceNilHits(t *testing.T) {
var hits []*elastic.SearchHit
searchHits := &elastic.SearchHits{Hits: hits}
- mockSearchService(r).Return(&elastic.SearchResult{Hits: searchHits}, nil)
+ mockSearchService(
+ r,
+ ).Return(&elastic.SearchResult{Hits: searchHits}, nil)
mockMultiSearchService(r).
Return(&elastic.MultiSearchResult{
Responses: []*elastic.SearchResult{
@@ -482,7 +560,10 @@ func TestSpanReader_GetTraceNilHits(t *testing.T) {
},
}, nil)
- trace, err := r.reader.GetTrace(context.Background(), model.NewTraceID(0, 1))
+ trace, err := r.reader.GetTrace(
+ context.Background(),
+ model.NewTraceID(0, 1),
+ )
require.NotEmpty(t, r.traceBuffer.GetSpans(), "Spans recorded")
require.EqualError(t, err, "trace not found")
require.Nil(t, trace)
@@ -498,7 +579,9 @@ func TestSpanReader_GetTraceInvalidSpanError(t *testing.T) {
}
searchHits := &elastic.SearchHits{Hits: hits}
- mockSearchService(r).Return(&elastic.SearchResult{Hits: searchHits}, nil)
+ mockSearchService(
+ r,
+ ).Return(&elastic.SearchResult{Hits: searchHits}, nil)
mockMultiSearchService(r).
Return(&elastic.MultiSearchResult{
Responses: []*elastic.SearchResult{
@@ -506,7 +589,10 @@ func TestSpanReader_GetTraceInvalidSpanError(t *testing.T) {
},
}, nil)
- trace, err := r.reader.GetTrace(context.Background(), model.NewTraceID(0, 1))
+ trace, err := r.reader.GetTrace(
+ context.Background(),
+ model.NewTraceID(0, 1),
+ )
require.NotEmpty(t, r.traceBuffer.GetSpans(), "Spans recorded")
require.Error(t, err, "invalid span")
require.Nil(t, trace)
@@ -523,7 +609,9 @@ func TestSpanReader_GetTraceSpanConversionError(t *testing.T) {
}
searchHits := &elastic.SearchHits{Hits: hits}
- mockSearchService(r).Return(&elastic.SearchResult{Hits: searchHits}, nil)
+ mockSearchService(
+ r,
+ ).Return(&elastic.SearchResult{Hits: searchHits}, nil)
mockMultiSearchService(r).
Return(&elastic.MultiSearchResult{
Responses: []*elastic.SearchResult{
@@ -531,7 +619,10 @@ func TestSpanReader_GetTraceSpanConversionError(t *testing.T) {
},
}, nil)
- trace, err := r.reader.GetTrace(context.Background(), model.NewTraceID(0, 1))
+ trace, err := r.reader.GetTrace(
+ context.Background(),
+ model.NewTraceID(0, 1),
+ )
require.NotEmpty(t, r.traceBuffer.GetSpans(), "Spans recorded")
require.Error(t, err, "span conversion error, because lacks elements")
require.Nil(t, trace)
@@ -608,7 +699,13 @@ func TestSpanReaderFindIndices(t *testing.T) {
}
withSpanReader(t, func(r *spanReaderTest) {
for _, testCase := range testCases {
- actual := r.reader.timeRangeIndices(spanIndex, dateLayout, testCase.startTime, testCase.endTime, -24*time.Hour)
+ actual := r.reader.timeRangeIndices(
+ spanIndex,
+ dateLayout,
+ testCase.startTime,
+ testCase.endTime,
+ -24*time.Hour,
+ )
assert.EqualValues(t, testCase.expected, actual)
}
})
@@ -616,7 +713,11 @@ func TestSpanReaderFindIndices(t *testing.T) {
func TestSpanReader_indexWithDate(t *testing.T) {
withSpanReader(t, func(r *spanReaderTest) {
- actual := indexWithDate(spanIndex, "2006-01-02", time.Date(1995, time.April, 21, 4, 21, 19, 95, time.UTC))
+ actual := indexWithDate(
+ spanIndex,
+ "2006-01-02",
+ time.Date(1995, time.April, 21, 4, 21, 19, 95, time.UTC),
+ )
assert.Equal(t, "jaeger-span-1995-04-21", actual)
})
}
@@ -638,8 +739,10 @@ func testGet(typ string, t *testing.T) {
expectedOutput map[string]any
}{
{
- caption: typ + " full behavior",
- searchResult: &elastic.SearchResult{Aggregations: elastic.Aggregations(goodAggregations)},
+ caption: typ + " full behavior",
+ searchResult: &elastic.SearchResult{
+ Aggregations: elastic.Aggregations(goodAggregations),
+ },
expectedOutput: map[string]any{
operationsAggregation: []spanstore.Operation{{Name: "123"}},
"default": []string{"123"},
@@ -659,8 +762,10 @@ func testGet(typ string, t *testing.T) {
},
},
{
- caption: typ + " search error",
- searchResult: &elastic.SearchResult{Aggregations: elastic.Aggregations(badAggregations)},
+ caption: typ + " search error",
+ searchResult: &elastic.SearchResult{
+ Aggregations: elastic.Aggregations(badAggregations),
+ },
expectedError: func() string {
return "could not find aggregation of " + typ
},
@@ -671,7 +776,9 @@ func testGet(typ string, t *testing.T) {
testCase := tc
t.Run(testCase.caption, func(t *testing.T) {
withSpanReader(t, func(r *spanReaderTest) {
- mockSearchService(r).Return(testCase.searchResult, testCase.searchError)
+ mockSearchService(
+ r,
+ ).Return(testCase.searchResult, testCase.searchError)
actual, err := returnSearchFunc(typ, r)
if testCase.expectedError() != "" {
require.EqualError(t, err, testCase.expectedError())
@@ -696,7 +803,10 @@ func returnSearchFunc(typ string, r *spanReaderTest) (any, error) {
spanstore.OperationQueryParameters{ServiceName: "someService"},
)
case traceIDAggregation:
- return r.reader.findTraceIDs(context.Background(), &spanstore.TraceQueryParameters{})
+ return r.reader.findTraceIDs(
+ context.Background(),
+ &spanstore.TraceQueryParameters{},
+ )
}
return nil, errors.New("Specify services, operations, traceIDs only")
}
@@ -729,7 +839,9 @@ func TestSpanReader_bucketToStringArrayError(t *testing.T) {
func TestSpanReader_FindTraces(t *testing.T) {
goodAggregations := make(map[string]*json.RawMessage)
- rawMessage := []byte(`{"buckets": [{"key": "1","doc_count": 16},{"key": "2","doc_count": 16},{"key": "3","doc_count": 16}]}`)
+ rawMessage := []byte(
+ `{"buckets": [{"key": "1","doc_count": 16},{"key": "2","doc_count": 16},{"key": "3","doc_count": 16}]}`,
+ )
goodAggregations[traceIDAggregation] = (*json.RawMessage)(&rawMessage)
hits := make([]*elastic.SearchHit, 1)
@@ -777,7 +889,9 @@ func TestSpanReader_FindTraces(t *testing.T) {
func TestSpanReader_FindTracesInvalidQuery(t *testing.T) {
goodAggregations := make(map[string]*json.RawMessage)
- rawMessage := []byte(`{"buckets": [{"key": "1","doc_count": 16},{"key": "2","doc_count": 16},{"key": "3","doc_count": 16}]}`)
+ rawMessage := []byte(
+ `{"buckets": [{"key": "1","doc_count": 16},{"key": "2","doc_count": 16},{"key": "3","doc_count": 16}]}`,
+ )
goodAggregations[traceIDAggregation] = (*json.RawMessage)(&rawMessage)
hits := make([]*elastic.SearchHit, 1)
@@ -883,7 +997,9 @@ func TestSpanReader_FindTracesNoTraceIDs(t *testing.T) {
func TestSpanReader_FindTracesReadTraceFailure(t *testing.T) {
goodAggregations := make(map[string]*json.RawMessage)
- rawMessage := []byte(`{"buckets": [{"key": "1","doc_count": 16},{"key": "2","doc_count": 16}]}`)
+ rawMessage := []byte(
+ `{"buckets": [{"key": "1","doc_count": 16},{"key": "2","doc_count": 16}]}`,
+ )
goodAggregations[traceIDAggregation] = (*json.RawMessage)(&rawMessage)
badSpan := []byte(`{"TraceID": "123"asjlgajdfhilqghi[adfvca} bad json`)
@@ -917,7 +1033,9 @@ func TestSpanReader_FindTracesReadTraceFailure(t *testing.T) {
func TestSpanReader_FindTracesSpanCollectionFailure(t *testing.T) {
goodAggregations := make(map[string]*json.RawMessage)
- rawMessage := []byte(`{"buckets": [{"key": "1","doc_count": 16},{"key": "2","doc_count": 16}]}`)
+ rawMessage := []byte(
+ `{"buckets": [{"key": "1","doc_count": 16},{"key": "2","doc_count": 16}]}`,
+ )
goodAggregations[traceIDAggregation] = (*json.RawMessage)(&rawMessage)
badSpan := []byte(`{"TraceID": "123"asjlgajdfhilqghi[adfvca} bad json`)
@@ -976,22 +1094,38 @@ func TestTraceIDsStringsToModelsConversion(t *testing.T) {
assert.Equal(t, model.NewTraceID(0, 1), traceIDs[0])
traceIDs, err = convertTraceIDsStringsToModels([]string{"dsfjsdklfjdsofdfsdbfkgbgoaemlrksdfbsdofgerjl"})
- require.EqualError(t, err, "making traceID from string 'dsfjsdklfjdsofdfsdbfkgbgoaemlrksdfbsdofgerjl' failed: TraceID cannot be longer than 32 hex characters: dsfjsdklfjdsofdfsdbfkgbgoaemlrksdfbsdofgerjl")
+ require.EqualError(
+ t,
+ err,
+ "making traceID from string 'dsfjsdklfjdsofdfsdbfkgbgoaemlrksdfbsdofgerjl' failed: TraceID cannot be longer than 32 hex characters: dsfjsdklfjdsofdfsdbfkgbgoaemlrksdfbsdofgerjl",
+ )
assert.Empty(t, traceIDs)
}
func mockMultiSearchService(r *spanReaderTest) *mock.Call {
multiSearchService := &mocks.MultiSearchService{}
multiSearchService.On("Add", mock.Anything, mock.Anything, mock.Anything).Return(multiSearchService)
- multiSearchService.On("Index", mock.AnythingOfType("string"), mock.AnythingOfType("string"),
- mock.AnythingOfType("string"), mock.AnythingOfType("string"), mock.AnythingOfType("string")).Return(multiSearchService)
+ multiSearchService.On(
+ "Index",
+ mock.AnythingOfType("string"),
+ mock.AnythingOfType("string"),
+ mock.AnythingOfType(
+ "string",
+ ),
+ mock.AnythingOfType("string"),
+ mock.AnythingOfType("string"),
+ ).Return(multiSearchService)
r.client.On("MultiSearch").Return(multiSearchService)
return multiSearchService.On("Do", mock.Anything)
}
-func mockArchiveMultiSearchService(r *spanReaderTest, indexName string) *mock.Call {
+func mockArchiveMultiSearchService(
+ r *spanReaderTest,
+ indexName string,
+) *mock.Call {
multiSearchService := &mocks.MultiSearchService{}
- multiSearchService.On("Add", mock.Anything, mock.Anything, mock.Anything).Return(multiSearchService)
+ multiSearchService.On("Add", mock.Anything, mock.Anything, mock.Anything).
+ Return(multiSearchService)
multiSearchService.On("Index", indexName).Return(multiSearchService)
r.client.On("MultiSearch").Return(multiSearchService)
return multiSearchService.On("Do", mock.Anything)
@@ -1008,14 +1142,19 @@ func matchTermsAggregation(termsAgg *elastic.TermsAggregation) bool {
func mockSearchService(r *spanReaderTest) *mock.Call {
searchService := &mocks.SearchService{}
searchService.On("Query", mock.Anything).Return(searchService)
- searchService.On("IgnoreUnavailable", mock.AnythingOfType("bool")).Return(searchService)
+ searchService.On("IgnoreUnavailable", mock.AnythingOfType("bool")).
+ Return(searchService)
searchService.On("Size", mock.MatchedBy(func(size int) bool {
return size == 0 // Aggregations apply size (bucket) limits in their own query objects, and do not apply at the parent query level.
})).Return(searchService)
- searchService.On("Aggregation", stringMatcher(servicesAggregation), mock.MatchedBy(matchTermsAggregation)).Return(searchService)
- searchService.On("Aggregation", stringMatcher(operationsAggregation), mock.MatchedBy(matchTermsAggregation)).Return(searchService)
- searchService.On("Aggregation", stringMatcher(traceIDAggregation), mock.AnythingOfType("*elastic.TermsAggregation")).Return(searchService)
- r.client.On("Search", mock.AnythingOfType("string"), mock.AnythingOfType("string"), mock.AnythingOfType("string"), mock.AnythingOfType("string"), mock.AnythingOfType("string")).Return(searchService)
+ searchService.On("Aggregation", stringMatcher(servicesAggregation), mock.MatchedBy(matchTermsAggregation)).
+ Return(searchService)
+ searchService.On("Aggregation", stringMatcher(operationsAggregation), mock.MatchedBy(matchTermsAggregation)).
+ Return(searchService)
+ searchService.On("Aggregation", stringMatcher(traceIDAggregation), mock.AnythingOfType("*elastic.TermsAggregation")).
+ Return(searchService)
+ r.client.On("Search", mock.AnythingOfType("string"), mock.AnythingOfType("string"), mock.AnythingOfType("string"), mock.AnythingOfType("string"), mock.AnythingOfType("string")).
+ Return(searchService)
return searchService.On("Do", mock.Anything)
}
@@ -1075,7 +1214,9 @@ func TestSpanReader_buildTraceIDAggregation(t *testing.T) {
expected := make(map[string]any)
json.Unmarshal([]byte(expectedStr), &expected)
expected["terms"].(map[string]any)["size"] = 123
- expected["terms"].(map[string]any)["order"] = []any{map[string]string{"startTime": "desc"}}
+ expected["terms"].(map[string]any)["order"] = []any{
+ map[string]string{"startTime": "desc"},
+ }
assert.EqualValues(t, expected, actual)
})
}
@@ -1129,8 +1270,12 @@ func TestSpanReader_buildDurationQuery(t *testing.T) {
expected := make(map[string]any)
json.Unmarshal([]byte(expectedStr), &expected)
// We need to do this because we cannot process a json into uint64.
- expected["range"].(map[string]any)["duration"].(map[string]any)["from"] = model.DurationAsMicroseconds(durationMin)
- expected["range"].(map[string]any)["duration"].(map[string]any)["to"] = model.DurationAsMicroseconds(durationMax)
+ expected["range"].(map[string]any)["duration"].(map[string]any)["from"] = model.DurationAsMicroseconds(
+ durationMin,
+ )
+ expected["range"].(map[string]any)["duration"].(map[string]any)["to"] = model.DurationAsMicroseconds(
+ durationMax,
+ )
assert.EqualValues(t, expected, actual)
})
@@ -1147,15 +1292,22 @@ func TestSpanReader_buildStartTimeQuery(t *testing.T) {
withSpanReader(t, func(r *spanReaderTest) {
startTimeMin := time.Time{}.Add(time.Second)
startTimeMax := time.Time{}.Add(2 * time.Second)
- durationQuery := r.reader.buildStartTimeQuery(startTimeMin, startTimeMax)
+ durationQuery := r.reader.buildStartTimeQuery(
+ startTimeMin,
+ startTimeMax,
+ )
actual, err := durationQuery.Source()
require.NoError(t, err)
expected := make(map[string]any)
json.Unmarshal([]byte(expectedStr), &expected)
// We need to do this because we cannot process a json into uint64.
- expected["range"].(map[string]any)["startTimeMillis"].(map[string]any)["from"] = model.TimeAsEpochMicroseconds(startTimeMin) / 1000
- expected["range"].(map[string]any)["startTimeMillis"].(map[string]any)["to"] = model.TimeAsEpochMicroseconds(startTimeMax) / 1000
+ expected["range"].(map[string]any)["startTimeMillis"].(map[string]any)["from"] = model.TimeAsEpochMicroseconds(
+ startTimeMin,
+ ) / 1000
+ expected["range"].(map[string]any)["startTimeMillis"].(map[string]any)["to"] = model.TimeAsEpochMicroseconds(
+ startTimeMax,
+ ) / 1000
assert.EqualValues(t, expected, actual)
})
@@ -1293,10 +1445,18 @@ func TestSpanReader_ArchiveTraces_ReadAlias(t *testing.T) {
}
func TestConvertTraceIDsStringsToModels(t *testing.T) {
- ids, err := convertTraceIDsStringsToModels([]string{"1", "2", "01", "02", "001", "002"})
+ ids, err := convertTraceIDsStringsToModels(
+ []string{"1", "2", "01", "02", "001", "002"},
+ )
require.NoError(t, err)
- assert.Equal(t, []model.TraceID{model.NewTraceID(0, 1), model.NewTraceID(0, 2)}, ids)
- _, err = convertTraceIDsStringsToModels([]string{"1", "2", "01", "02", "001", "002", "blah"})
+ assert.Equal(
+ t,
+ []model.TraceID{model.NewTraceID(0, 1), model.NewTraceID(0, 2)},
+ ids,
+ )
+ _, err = convertTraceIDsStringsToModels(
+ []string{"1", "2", "01", "02", "001", "002", "blah"},
+ )
require.Error(t, err)
}
@@ -1319,13 +1479,17 @@ func TestBuildTraceByIDQuery(t *testing.T) {
{
traceID: traceIDHigh,
query: elastic.NewBoolQuery().Should(
- elastic.NewTermQuery(traceIDField, "00000000000000010000000000000001").Boost(2),
+ elastic.NewTermQuery(traceIDField, "00000000000000010000000000000001").
+ Boost(2),
elastic.NewTermQuery(traceIDField, "10000000000000001"),
),
},
{
traceID: traceID,
- query: elastic.NewTermQuery(traceIDField, "ffffffffffffffffffffffffffffffff"),
+ query: elastic.NewTermQuery(
+ traceIDField,
+ "ffffffffffffffffffffffffffffffff",
+ ),
},
}
for _, test := range tests {
diff --git a/plugin/storage/es/spanstore/service_operation.go b/plugin/storage/es/spanstore/service_operation.go
index a6c320b3f1c..76975c86fd4 100644
--- a/plugin/storage/es/spanstore/service_operation.go
+++ b/plugin/storage/es/spanstore/service_operation.go
@@ -63,7 +63,10 @@ func NewServiceOperationStorage(
}
// Write saves a service to operation pair.
-func (s *ServiceOperationStorage) Write(indexName string, jsonSpan *dbmodel.Span) {
+func (s *ServiceOperationStorage) Write(
+ indexName string,
+ jsonSpan *dbmodel.Span,
+) {
// Insert serviceName:operationName document
service := dbmodel.Service{
ServiceName: jsonSpan.Process.ServiceName,
@@ -72,12 +75,22 @@ func (s *ServiceOperationStorage) Write(indexName string, jsonSpan *dbmodel.Span
cacheKey := hashCode(service)
if !keyInCache(cacheKey, s.serviceCache) {
- s.client().Index().Index(indexName).Type(serviceType).Id(cacheKey).BodyJson(service).Add()
+ s.client().
+ Index().
+ Index(indexName).
+ Type(serviceType).
+ Id(cacheKey).
+ BodyJson(service).
+ Add()
writeCache(cacheKey, s.serviceCache)
}
}
-func (s *ServiceOperationStorage) getServices(context context.Context, indices []string, maxDocCount int) ([]string, error) {
+func (s *ServiceOperationStorage) getServices(
+ context context.Context,
+ indices []string,
+ maxDocCount int,
+) ([]string, error) {
serviceAggregation := getServicesAggregation(maxDocCount)
searchService := s.client().Search(indices...).
@@ -87,14 +100,19 @@ func (s *ServiceOperationStorage) getServices(context context.Context, indices [
searchResult, err := searchService.Do(context)
if err != nil {
- return nil, fmt.Errorf("search services failed: %w", es.DetailedError(err))
+ return nil, fmt.Errorf(
+ "search services failed: %w",
+ es.DetailedError(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)
@@ -103,10 +121,16 @@ func (s *ServiceOperationStorage) getServices(context context.Context, indices [
func getServicesAggregation(maxDocCount int) elastic.Query {
return elastic.NewTermsAggregation().
Field(serviceName).
- Size(maxDocCount) // ES deprecated size omission for aggregating all. https://github.com/elastic/elasticsearch/issues/18838
+ Size(maxDocCount)
+ // ES deprecated size omission for aggregating all. https://github.com/elastic/elasticsearch/issues/18838
}
-func (s *ServiceOperationStorage) getOperations(context context.Context, indices []string, service string, maxDocCount int) ([]string, error) {
+func (s *ServiceOperationStorage) getOperations(
+ context context.Context,
+ indices []string,
+ service string,
+ maxDocCount int,
+) ([]string, error) {
serviceQuery := elastic.NewTermQuery(serviceName, service)
serviceFilter := getOperationsAggregation(maxDocCount)
@@ -118,14 +142,19 @@ func (s *ServiceOperationStorage) getOperations(context context.Context, indices
searchResult, err := searchService.Do(context)
if err != nil {
- return nil, fmt.Errorf("search operations failed: %w", es.DetailedError(err))
+ return nil, fmt.Errorf(
+ "search operations failed: %w",
+ es.DetailedError(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)
@@ -134,7 +163,8 @@ func (s *ServiceOperationStorage) getOperations(context context.Context, indices
func getOperationsAggregation(maxDocCount int) elastic.Query {
return elastic.NewTermsAggregation().
Field(operationNameField).
- Size(maxDocCount) // ES deprecated size omission for aggregating all. https://github.com/elastic/elasticsearch/issues/18838
+ Size(maxDocCount)
+ // ES deprecated size omission for aggregating all. https://github.com/elastic/elasticsearch/issues/18838
}
func hashCode(s dbmodel.Service) string {
diff --git a/plugin/storage/es/spanstore/service_operation_test.go b/plugin/storage/es/spanstore/service_operation_test.go
index 515e9fbafcd..288beb55b82 100644
--- a/plugin/storage/es/spanstore/service_operation_test.go
+++ b/plugin/storage/es/spanstore/service_operation_test.go
@@ -39,7 +39,8 @@ func TestWriteService(t *testing.T) {
indexService.On("Index", stringMatcher(indexName)).Return(indexService)
indexService.On("Type", stringMatcher(serviceType)).Return(indexService)
indexService.On("Id", stringMatcher(serviceHash)).Return(indexService)
- indexService.On("BodyJson", mock.AnythingOfType("dbmodel.Service")).Return(indexService)
+ indexService.On("BodyJson", mock.AnythingOfType("dbmodel.Service")).
+ Return(indexService)
indexService.On("Add")
w.client.On("Index").Return(indexService)
@@ -74,7 +75,8 @@ func TestWriteServiceError(t *testing.T) {
indexService.On("Index", stringMatcher(indexName)).Return(indexService)
indexService.On("Type", stringMatcher(serviceType)).Return(indexService)
indexService.On("Id", stringMatcher(serviceHash)).Return(indexService)
- indexService.On("BodyJson", mock.AnythingOfType("dbmodel.Service")).Return(indexService)
+ indexService.On("BodyJson", mock.AnythingOfType("dbmodel.Service")).
+ Return(indexService)
indexService.On("Add")
w.client.On("Index").Return(indexService)
diff --git a/plugin/storage/es/spanstore/writer.go b/plugin/storage/es/spanstore/writer.go
index d7d8c211841..34906157baa 100644
--- a/plugin/storage/es/spanstore/writer.go
+++ b/plugin/storage/es/spanstore/writer.go
@@ -78,31 +78,60 @@ func NewSpanWriter(p SpanWriterParams) *SpanWriter {
serviceCacheTTL = serviceCacheTTLDefault
}
- serviceOperationStorage := NewServiceOperationStorage(p.Client, p.Logger, serviceCacheTTL)
+ serviceOperationStorage := NewServiceOperationStorage(
+ p.Client,
+ p.Logger,
+ serviceCacheTTL,
+ )
return &SpanWriter{
client: p.Client,
logger: p.Logger,
writerMetrics: spanWriterMetrics{
- indexCreate: storageMetrics.NewWriteMetrics(p.MetricsFactory, "index_create"),
+ indexCreate: storageMetrics.NewWriteMetrics(
+ p.MetricsFactory,
+ "index_create",
+ ),
},
- serviceWriter: serviceOperationStorage.Write,
- spanConverter: dbmodel.NewFromDomain(p.AllTagsAsFields, p.TagKeysAsFields, p.TagDotReplacement),
- spanServiceIndex: getSpanAndServiceIndexFn(p.Archive, p.UseReadWriteAliases, p.IndexPrefix, p.SpanIndexDateLayout, p.ServiceIndexDateLayout),
+ serviceWriter: serviceOperationStorage.Write,
+ spanConverter: dbmodel.NewFromDomain(p.AllTagsAsFields, p.TagKeysAsFields, p.TagDotReplacement),
+ spanServiceIndex: getSpanAndServiceIndexFn(
+ p.Archive,
+ p.UseReadWriteAliases,
+ p.IndexPrefix,
+ p.SpanIndexDateLayout,
+ p.ServiceIndexDateLayout,
+ ),
}
}
// CreateTemplates creates index templates.
-func (s *SpanWriter) CreateTemplates(spanTemplate, serviceTemplate, indexPrefix string) error {
+func (s *SpanWriter) CreateTemplates(
+ spanTemplate, serviceTemplate, indexPrefix string,
+) error {
if indexPrefix != "" && !strings.HasSuffix(indexPrefix, "-") {
indexPrefix += "-"
}
- _, err := s.client().CreateTemplate(indexPrefix + "jaeger-span").Body(spanTemplate).Do(context.Background())
+ _, err := s.client().
+ CreateTemplate(indexPrefix + "jaeger-span").
+ Body(spanTemplate).
+ Do(context.Background())
if err != nil {
- return fmt.Errorf("failed to create template %q: %w", indexPrefix+"jaeger-span", err)
+ return fmt.Errorf(
+ "failed to create template %q: %w",
+ indexPrefix+"jaeger-span",
+ err,
+ )
}
- _, err = s.client().CreateTemplate(indexPrefix + "jaeger-service").Body(serviceTemplate).Do(context.Background())
+ _, err = s.client().
+ CreateTemplate(indexPrefix + "jaeger-service").
+ Body(serviceTemplate).
+ Do(context.Background())
if err != nil {
- return fmt.Errorf("failed to create template %q: %w", indexPrefix+"jaeger-service", err)
+ return fmt.Errorf(
+ "failed to create template %q: %w",
+ indexPrefix+"jaeger-service",
+ err,
+ )
}
return nil
}
@@ -110,7 +139,11 @@ func (s *SpanWriter) CreateTemplates(spanTemplate, serviceTemplate, indexPrefix
// spanAndServiceIndexFn returns names of span and service indices
type spanAndServiceIndexFn func(spanTime time.Time) (string, string)
-func getSpanAndServiceIndexFn(archive, useReadWriteAliases bool, prefix, spanDateLayout string, serviceDateLayout string) spanAndServiceIndexFn {
+func getSpanAndServiceIndexFn(
+ archive, useReadWriteAliases bool,
+ prefix, spanDateLayout string,
+ serviceDateLayout string,
+) spanAndServiceIndexFn {
if prefix != "" {
prefix += indexPrefixSeparator
}
@@ -119,7 +152,10 @@ func getSpanAndServiceIndexFn(archive, useReadWriteAliases bool, prefix, spanDat
if archive {
return func(date time.Time) (string, string) {
if useReadWriteAliases {
- return archiveIndex(spanIndexPrefix, archiveWriteIndexSuffix), ""
+ return archiveIndex(
+ spanIndexPrefix,
+ archiveWriteIndexSuffix,
+ ), ""
}
return archiveIndex(spanIndexPrefix, archiveIndexSuffix), ""
}
@@ -131,7 +167,15 @@ func getSpanAndServiceIndexFn(archive, useReadWriteAliases bool, prefix, spanDat
}
}
return func(date time.Time) (string, string) {
- return indexWithDate(spanIndexPrefix, spanDateLayout, date), indexWithDate(serviceIndexPrefix, serviceDateLayout, date)
+ return indexWithDate(
+ spanIndexPrefix,
+ spanDateLayout,
+ date,
+ ), indexWithDate(
+ serviceIndexPrefix,
+ serviceDateLayout,
+ date,
+ )
}
}
diff --git a/plugin/storage/es/spanstore/writer_test.go b/plugin/storage/es/spanstore/writer_test.go
index 4630c94fcff..8b8fe4957e8 100644
--- a/plugin/storage/es/spanstore/writer_test.go
+++ b/plugin/storage/es/spanstore/writer_test.go
@@ -51,7 +51,15 @@ func withSpanWriter(fn func(w *spanWriterTest)) {
client: client,
logger: logger,
logBuffer: logBuffer,
- writer: NewSpanWriter(SpanWriterParams{Client: func() es.Client { return client }, Logger: logger, MetricsFactory: metricsFactory, SpanIndexDateLayout: "2006-01-02", ServiceIndexDateLayout: "2006-01-02"}),
+ writer: NewSpanWriter(
+ SpanWriterParams{
+ Client: func() es.Client { return client },
+ Logger: logger,
+ MetricsFactory: metricsFactory,
+ SpanIndexDateLayout: "2006-01-02",
+ ServiceIndexDateLayout: "2006-01-02",
+ },
+ ),
}
fn(w)
}
@@ -77,7 +85,10 @@ func TestSpanWriterIndices(t *testing.T) {
Client: clientFn, Logger: logger, MetricsFactory: metricsFactory,
IndexPrefix: "", SpanIndexDateLayout: spanDataLayout, ServiceIndexDateLayout: serviceDataLayout, Archive: false,
},
- indices: []string{spanIndex + spanDataLayoutFormat, serviceIndex + serviceDataLayoutFormat},
+ indices: []string{
+ spanIndex + spanDataLayoutFormat,
+ serviceIndex + serviceDataLayoutFormat,
+ },
},
{
params: SpanWriterParams{
@@ -91,14 +102,20 @@ func TestSpanWriterIndices(t *testing.T) {
Client: clientFn, Logger: logger, MetricsFactory: metricsFactory,
IndexPrefix: "foo:", SpanIndexDateLayout: spanDataLayout, ServiceIndexDateLayout: serviceDataLayout, Archive: false,
},
- indices: []string{"foo:" + indexPrefixSeparator + spanIndex + spanDataLayoutFormat, "foo:" + indexPrefixSeparator + serviceIndex + serviceDataLayoutFormat},
+ indices: []string{
+ "foo:" + indexPrefixSeparator + spanIndex + spanDataLayoutFormat,
+ "foo:" + indexPrefixSeparator + serviceIndex + serviceDataLayoutFormat,
+ },
},
{
params: SpanWriterParams{
Client: clientFn, Logger: logger, MetricsFactory: metricsFactory,
IndexPrefix: "foo:", SpanIndexDateLayout: spanDataLayout, ServiceIndexDateLayout: serviceDataLayout, UseReadWriteAliases: true,
},
- indices: []string{"foo:-" + spanIndex + "write", "foo:-" + serviceIndex + "write"},
+ indices: []string{
+ "foo:-" + spanIndex + "write",
+ "foo:-" + serviceIndex + "write",
+ },
},
{
params: SpanWriterParams{
@@ -112,20 +129,30 @@ func TestSpanWriterIndices(t *testing.T) {
Client: clientFn, Logger: logger, MetricsFactory: metricsFactory,
IndexPrefix: "foo:", SpanIndexDateLayout: spanDataLayout, ServiceIndexDateLayout: serviceDataLayout, Archive: true,
},
- indices: []string{"foo:" + indexPrefixSeparator + spanIndex + archiveIndexSuffix, ""},
+ indices: []string{
+ "foo:" + indexPrefixSeparator + spanIndex + archiveIndexSuffix,
+ "",
+ },
},
{
params: SpanWriterParams{
Client: clientFn, Logger: logger, MetricsFactory: metricsFactory,
IndexPrefix: "foo:", SpanIndexDateLayout: spanDataLayout, ServiceIndexDateLayout: serviceDataLayout, Archive: true, UseReadWriteAliases: true,
},
- indices: []string{"foo:" + indexPrefixSeparator + spanIndex + archiveWriteIndexSuffix, ""},
+ indices: []string{
+ "foo:" + indexPrefixSeparator + spanIndex + archiveWriteIndexSuffix,
+ "",
+ },
},
}
for _, testCase := range testCases {
w := NewSpanWriter(testCase.params)
spanIndexName, serviceIndexName := w.spanServiceIndex(date)
- assert.Equal(t, []string{spanIndexName, serviceIndexName}, testCase.indices)
+ assert.Equal(
+ t,
+ []string{spanIndexName, serviceIndexName},
+ testCase.indices,
+ )
}
}
@@ -159,7 +186,10 @@ func TestSpanWriter_WriteSpan(t *testing.T) {
testCase := tc
t.Run(testCase.caption, func(t *testing.T) {
withSpanWriter(func(w *spanWriterTest) {
- date, err := time.Parse(time.RFC3339, "1995-04-21T22:08:41+00:00")
+ date, err := time.Parse(
+ time.RFC3339,
+ "1995-04-21T22:08:41+00:00",
+ )
require.NoError(t, err)
span := &model.Span{
@@ -180,18 +210,26 @@ func TestSpanWriter_WriteSpan(t *testing.T) {
indexServicePut := &mocks.IndexService{}
indexSpanPut := &mocks.IndexService{}
- indexService.On("Index", stringMatcher(spanIndexName)).Return(indexService)
- indexService.On("Index", stringMatcher(serviceIndexName)).Return(indexService)
+ indexService.On("Index", stringMatcher(spanIndexName)).
+ Return(indexService)
+ indexService.On("Index", stringMatcher(serviceIndexName)).
+ Return(indexService)
- indexService.On("Type", stringMatcher(serviceType)).Return(indexServicePut)
- indexService.On("Type", stringMatcher(spanType)).Return(indexSpanPut)
+ indexService.On("Type", stringMatcher(serviceType)).
+ Return(indexServicePut)
+ indexService.On("Type", stringMatcher(spanType)).
+ Return(indexSpanPut)
- indexServicePut.On("Id", stringMatcher(serviceHash)).Return(indexServicePut)
- indexServicePut.On("BodyJson", mock.AnythingOfType("dbmodel.Service")).Return(indexServicePut)
+ indexServicePut.On("Id", stringMatcher(serviceHash)).
+ Return(indexServicePut)
+ indexServicePut.On("BodyJson", mock.AnythingOfType("dbmodel.Service")).
+ Return(indexServicePut)
indexServicePut.On("Add")
- indexSpanPut.On("Id", mock.AnythingOfType("string")).Return(indexSpanPut)
- indexSpanPut.On("BodyJson", mock.AnythingOfType("**dbmodel.Span")).Return(indexSpanPut)
+ indexSpanPut.On("Id", mock.AnythingOfType("string")).
+ Return(indexSpanPut)
+ indexSpanPut.On("BodyJson", mock.AnythingOfType("**dbmodel.Span")).
+ Return(indexSpanPut)
indexSpanPut.On("Add")
w.client.On("Index").Return(indexService)
@@ -207,7 +245,13 @@ func TestSpanWriter_WriteSpan(t *testing.T) {
}
for _, expectedLog := range testCase.expectedLogs {
- assert.True(t, strings.Contains(w.logBuffer.String(), expectedLog), "Log must contain %s, but was %s", expectedLog, w.logBuffer.String())
+ assert.True(
+ t,
+ strings.Contains(w.logBuffer.String(), expectedLog),
+ "Log must contain %s, but was %s",
+ expectedLog,
+ w.logBuffer.String(),
+ )
}
if len(testCase.expectedLogs) == 0 {
assert.Equal(t, "", w.logBuffer.String())
@@ -258,7 +302,8 @@ func TestCreateTemplates(t *testing.T) {
spanTemplateService: func() *mocks.TemplateCreateService {
tService := new(mocks.TemplateCreateService)
tService.On("Body", mock.Anything).Return(tService)
- tService.On("Do", context.Background()).Return(nil, errors.New("span-template-error"))
+ tService.On("Do", context.Background()).
+ Return(nil, errors.New("span-template-error"))
return tService
},
serviceTemplateService: func() *mocks.TemplateCreateService {
@@ -279,7 +324,8 @@ func TestCreateTemplates(t *testing.T) {
serviceTemplateService: func() *mocks.TemplateCreateService {
tService := new(mocks.TemplateCreateService)
tService.On("Body", mock.Anything).Return(tService)
- tService.On("Do", context.Background()).Return(nil, errors.New("service-template-error"))
+ tService.On("Do", context.Background()).
+ Return(nil, errors.New("service-template-error"))
return tService
},
},
@@ -288,12 +334,19 @@ func TestCreateTemplates(t *testing.T) {
for _, test := range tests {
withSpanWriter(func(w *spanWriterTest) {
prefix := ""
- if test.indexPrefix != "" && !strings.HasSuffix(test.indexPrefix, "-") {
+ if test.indexPrefix != "" &&
+ !strings.HasSuffix(test.indexPrefix, "-") {
prefix = test.indexPrefix + "-"
}
- w.client.On("CreateTemplate", prefix+"jaeger-span").Return(test.spanTemplateService())
- w.client.On("CreateTemplate", prefix+"jaeger-service").Return(test.serviceTemplateService())
- err := w.writer.CreateTemplates(mock.Anything, mock.Anything, test.indexPrefix)
+ w.client.On("CreateTemplate", prefix+"jaeger-span").
+ Return(test.spanTemplateService())
+ w.client.On("CreateTemplate", prefix+"jaeger-service").
+ Return(test.serviceTemplateService())
+ err := w.writer.CreateTemplates(
+ mock.Anything,
+ mock.Anything,
+ test.indexPrefix,
+ )
if test.err != "" {
require.Error(t, err, test.err)
}
@@ -308,7 +361,11 @@ func TestSpanIndexName(t *testing.T) {
StartTime: date,
}
spanIndexName := indexWithDate(spanIndex, "2006-01-02", span.StartTime)
- serviceIndexName := indexWithDate(serviceIndex, "2006-01-02", span.StartTime)
+ serviceIndexName := indexWithDate(
+ serviceIndex,
+ "2006-01-02",
+ span.StartTime,
+ )
assert.Equal(t, "jaeger-span-1995-04-21", spanIndexName)
assert.Equal(t, "jaeger-service-1995-04-21", serviceIndexName)
}
@@ -320,7 +377,8 @@ func TestWriteSpanInternal(t *testing.T) {
indexName := "jaeger-1995-04-21"
indexService.On("Index", stringMatcher(indexName)).Return(indexService)
indexService.On("Type", stringMatcher(spanType)).Return(indexService)
- indexService.On("BodyJson", mock.AnythingOfType("**dbmodel.Span")).Return(indexService)
+ indexService.On("BodyJson", mock.AnythingOfType("**dbmodel.Span")).
+ Return(indexService)
indexService.On("Add")
w.client.On("Index").Return(indexService)
@@ -340,7 +398,8 @@ func TestWriteSpanInternalError(t *testing.T) {
indexName := "jaeger-1995-04-21"
indexService.On("Index", stringMatcher(indexName)).Return(indexService)
indexService.On("Type", stringMatcher(spanType)).Return(indexService)
- indexService.On("BodyJson", mock.AnythingOfType("**dbmodel.Span")).Return(indexService)
+ indexService.On("BodyJson", mock.AnythingOfType("**dbmodel.Span")).
+ Return(indexService)
indexService.On("Add")
w.client.On("Index").Return(indexService)
@@ -372,7 +431,10 @@ func TestNewSpanTags(t *testing.T) {
}),
expected: dbmodel.Span{
Tag: map[string]any{"foo": "bar"}, Tags: []dbmodel.KeyValue{},
- Process: dbmodel.Process{Tag: map[string]any{"bar": "baz"}, Tags: []dbmodel.KeyValue{}},
+ Process: dbmodel.Process{
+ Tag: map[string]any{"bar": "baz"},
+ Tags: []dbmodel.KeyValue{},
+ },
},
name: "allTagsAsFields",
},
@@ -383,12 +445,21 @@ func TestNewSpanTags(t *testing.T) {
}),
expected: dbmodel.Span{
Tag: map[string]any{"foo": "bar"}, Tags: []dbmodel.KeyValue{},
- Process: dbmodel.Process{Tag: map[string]any{"bar": "baz"}, Tags: []dbmodel.KeyValue{}},
+ Process: dbmodel.Process{
+ Tag: map[string]any{"bar": "baz"},
+ Tags: []dbmodel.KeyValue{},
+ },
},
name: "definedTagNames",
},
{
- writer: NewSpanWriter(SpanWriterParams{Client: clientFn, Logger: logger, MetricsFactory: metricsFactory}),
+ writer: NewSpanWriter(
+ SpanWriterParams{
+ Client: clientFn,
+ Logger: logger,
+ MetricsFactory: metricsFactory,
+ },
+ ),
expected: dbmodel.Span{
Tags: []dbmodel.KeyValue{{
Key: "foo",
@@ -406,8 +477,10 @@ func TestNewSpanTags(t *testing.T) {
}
s := &model.Span{
- Tags: []model.KeyValue{{Key: "foo", VStr: "bar"}},
- Process: &model.Process{Tags: []model.KeyValue{{Key: "bar", VStr: "baz"}}},
+ Tags: []model.KeyValue{{Key: "foo", VStr: "bar"}},
+ Process: &model.Process{
+ Tags: []model.KeyValue{{Key: "bar", VStr: "baz"}},
+ },
}
for _, test := range testCases {
t.Run(test.name, func(t *testing.T) {
@@ -461,10 +534,14 @@ func TestSpanWriterParamsTTL(t *testing.T) {
indexService := &mocks.IndexService{}
- indexService.On("Index", stringMatcher(serviceIndexName)).Return(indexService)
- indexService.On("Type", stringMatcher(serviceType)).Return(indexService)
- indexService.On("Id", stringMatcher(serviceHash)).Return(indexService)
- indexService.On("BodyJson", mock.AnythingOfType("dbmodel.Service")).Return(indexService)
+ indexService.On("Index", stringMatcher(serviceIndexName)).
+ Return(indexService)
+ indexService.On("Type", stringMatcher(serviceType)).
+ Return(indexService)
+ indexService.On("Id", stringMatcher(serviceHash)).
+ Return(indexService)
+ indexService.On("BodyJson", mock.AnythingOfType("dbmodel.Service")).
+ Return(indexService)
indexService.On("Add")
client.On("Index").Return(indexService)
diff --git a/plugin/storage/factory.go b/plugin/storage/factory.go
index 4e6de6d29be..270e7a09ebc 100644
--- a/plugin/storage/factory.go
+++ b/plugin/storage/factory.go
@@ -77,7 +77,9 @@ func AllSamplingStorageTypes() []string {
f := &Factory{}
var backends []string
for _, st := range AllStorageTypes {
- f, _ := f.getFactoryOfType(st) // no errors since we're looping through supported types
+ f, _ := f.getFactoryOfType(
+ st,
+ ) // no errors since we're looping through supported types
if _, ok := f.(storage.SamplingStoreFactory); ok {
backends = append(backends, st)
}
@@ -142,12 +144,19 @@ func (*Factory) getFactoryOfType(factoryType string) (storage.Factory, error) {
case blackholeStorageType:
return blackhole.NewFactory(), nil
default:
- return nil, fmt.Errorf("unknown storage type %s. Valid types are %v", factoryType, AllStorageTypes)
+ return nil, fmt.Errorf(
+ "unknown storage type %s. Valid types are %v",
+ factoryType,
+ AllStorageTypes,
+ )
}
}
// Initialize implements storage.Factory.
-func (f *Factory) Initialize(metricsFactory metrics.Factory, logger *zap.Logger) error {
+func (f *Factory) Initialize(
+ metricsFactory metrics.Factory,
+ logger *zap.Logger,
+) error {
f.metricsFactory = metricsFactory
for _, factory := range f.factories {
if err := factory.Initialize(metricsFactory, logger); err != nil {
@@ -163,7 +172,10 @@ func (f *Factory) Initialize(metricsFactory metrics.Factory, logger *zap.Logger)
func (f *Factory) CreateSpanReader() (spanstore.Reader, error) {
factory, ok := f.factories[f.SpanReaderType]
if !ok {
- return nil, fmt.Errorf("no %s backend registered for span store", f.SpanReaderType)
+ return nil, fmt.Errorf(
+ "no %s backend registered for span store",
+ f.SpanReaderType,
+ )
}
return factory.CreateSpanReader()
}
@@ -174,7 +186,10 @@ func (f *Factory) CreateSpanWriter() (spanstore.Writer, error) {
for _, storageType := range f.SpanWriterTypes {
factory, ok := f.factories[storageType]
if !ok {
- return nil, fmt.Errorf("no %s backend registered for span store", storageType)
+ return nil, fmt.Errorf(
+ "no %s backend registered for span store",
+ storageType,
+ )
}
writer, err := factory.CreateSpanWriter()
if err != nil {
@@ -192,11 +207,16 @@ func (f *Factory) CreateSpanWriter() (spanstore.Writer, error) {
if f.DownsamplingRatio == defaultDownsamplingRatio {
return spanWriter, nil
}
- return spanstore.NewDownsamplingWriter(spanWriter, spanstore.DownsamplingOptions{
- Ratio: f.DownsamplingRatio,
- HashSalt: f.DownsamplingHashSalt,
- MetricsFactory: f.metricsFactory.Namespace(metrics.NSOptions{Name: "downsampling_writer"}),
- }), nil
+ return spanstore.NewDownsamplingWriter(
+ spanWriter,
+ spanstore.DownsamplingOptions{
+ Ratio: f.DownsamplingRatio,
+ HashSalt: f.DownsamplingHashSalt,
+ MetricsFactory: f.metricsFactory.Namespace(
+ metrics.NSOptions{Name: "downsampling_writer"},
+ ),
+ },
+ ), nil
}
// CreateSamplingStoreFactory creates a distributedlock.Lock and samplingstore.Store for use with adaptive sampling
@@ -206,11 +226,17 @@ func (f *Factory) CreateSamplingStoreFactory() (storage.SamplingStoreFactory, er
if f.SamplingStorageType != "" {
factory, ok := f.factories[f.SamplingStorageType]
if !ok {
- return nil, fmt.Errorf("no %s backend registered for sampling store", f.SamplingStorageType)
+ return nil, fmt.Errorf(
+ "no %s backend registered for sampling store",
+ f.SamplingStorageType,
+ )
}
ss, ok := factory.(storage.SamplingStoreFactory)
if !ok {
- return nil, fmt.Errorf("storage factory of type %s does not support sampling store", f.SamplingStorageType)
+ return nil, fmt.Errorf(
+ "storage factory of type %s does not support sampling store",
+ f.SamplingStorageType,
+ )
}
return ss, nil
}
@@ -231,7 +257,10 @@ func (f *Factory) CreateSamplingStoreFactory() (storage.SamplingStoreFactory, er
func (f *Factory) CreateDependencyReader() (dependencystore.Reader, error) {
factory, ok := f.factories[f.DependenciesStorageType]
if !ok {
- return nil, fmt.Errorf("no %s backend registered for span store", f.DependenciesStorageType)
+ return nil, fmt.Errorf(
+ "no %s backend registered for span store",
+ f.DependenciesStorageType,
+ )
}
return factory.CreateDependencyReader()
}
@@ -288,7 +317,8 @@ func (f *Factory) initDownsamplingFromViper(v *viper.Viper) {
}
f.FactoryConfig.DownsamplingRatio = v.GetFloat64(downsamplingRatio)
- if f.FactoryConfig.DownsamplingRatio < 0 || f.FactoryConfig.DownsamplingRatio > 1 {
+ if f.FactoryConfig.DownsamplingRatio < 0 ||
+ f.FactoryConfig.DownsamplingRatio > 1 {
// Values not in the range of 0 ~ 1.0 will be set to default.
f.FactoryConfig.DownsamplingRatio = 1.0
}
@@ -299,7 +329,10 @@ func (f *Factory) initDownsamplingFromViper(v *viper.Viper) {
func (f *Factory) CreateArchiveSpanReader() (spanstore.Reader, error) {
factory, ok := f.factories[f.SpanReaderType]
if !ok {
- return nil, fmt.Errorf("no %s backend registered for span store", f.SpanReaderType)
+ return nil, fmt.Errorf(
+ "no %s backend registered for span store",
+ f.SpanReaderType,
+ )
}
archive, ok := factory.(storage.ArchiveFactory)
if !ok {
@@ -312,7 +345,10 @@ func (f *Factory) CreateArchiveSpanReader() (spanstore.Reader, error) {
func (f *Factory) CreateArchiveSpanWriter() (spanstore.Writer, error) {
factory, ok := f.factories[f.SpanWriterTypes[0]]
if !ok {
- return nil, fmt.Errorf("no %s backend registered for span store", f.SpanWriterTypes[0])
+ return nil, fmt.Errorf(
+ "no %s backend registered for span store",
+ f.SpanWriterTypes[0],
+ )
}
archive, ok := factory.(storage.ArchiveFactory)
if !ok {
@@ -340,6 +376,9 @@ func (f *Factory) Close() error {
}
func (f *Factory) publishOpts() {
- safeexpvar.SetInt(downsamplingRatio, int64(f.FactoryConfig.DownsamplingRatio))
+ safeexpvar.SetInt(
+ downsamplingRatio,
+ int64(f.FactoryConfig.DownsamplingRatio),
+ )
safeexpvar.SetInt(spanStorageType+"-"+f.FactoryConfig.SpanReaderType, 1)
}
diff --git a/plugin/storage/factory_config.go b/plugin/storage/factory_config.go
index 1d8a0748d8f..c8da40e1c84 100644
--- a/plugin/storage/factory_config.go
+++ b/plugin/storage/factory_config.go
@@ -67,9 +67,11 @@ func FactoryConfigFromEnvAndCLI(args []string, log io.Writer) FactoryConfig {
spanStorageType = cassandraStorageType
}
if spanStorageType == grpcPluginDeprecated {
- fmt.Fprintf(log,
+ fmt.Fprintf(
+ log,
"WARNING: `%s` storage type is deprecated and will be remove from v1.60. Use `%s`.\n\n",
- grpcPluginDeprecated, grpcStorageType,
+ grpcPluginDeprecated,
+ grpcStorageType,
)
spanStorageType = grpcStorageType
}
diff --git a/plugin/storage/factory_config_test.go b/plugin/storage/factory_config_test.go
index 168dc1af8c2..d068901c3e9 100644
--- a/plugin/storage/factory_config_test.go
+++ b/plugin/storage/factory_config_test.go
@@ -41,11 +41,18 @@ func TestFactoryConfigFromEnv(t *testing.T) {
assert.Equal(t, memoryStorageType, f.DependenciesStorageType)
assert.Equal(t, cassandraStorageType, f.SamplingStorageType)
- t.Setenv(SpanStorageTypeEnvVar, elasticsearchStorageType+","+kafkaStorageType)
+ t.Setenv(
+ SpanStorageTypeEnvVar,
+ elasticsearchStorageType+","+kafkaStorageType,
+ )
f = FactoryConfigFromEnvAndCLI(nil, &bytes.Buffer{})
assert.Len(t, f.SpanWriterTypes, 2)
- assert.Equal(t, []string{elasticsearchStorageType, kafkaStorageType}, f.SpanWriterTypes)
+ assert.Equal(
+ t,
+ []string{elasticsearchStorageType, kafkaStorageType},
+ f.SpanWriterTypes,
+ )
assert.Equal(t, elasticsearchStorageType, f.SpanReaderType)
t.Setenv(SpanStorageTypeEnvVar, badgerStorageType)
@@ -62,9 +69,27 @@ func TestFactoryConfigFromEnvDeprecated(t *testing.T) {
log bool
value string
}{
- {args: []string{"appname", "-x", "y", "--span-storage.type=memory"}, log: true, value: "memory"},
- {args: []string{"appname", "-x", "y", "--span-storage.type", "memory"}, log: true, value: "memory"},
- {args: []string{"appname", "-x", "y", "--span-storage.type"}, log: true, value: "cassandra"},
+ {
+ args: []string{"appname", "-x", "y", "--span-storage.type=memory"},
+ log: true,
+ value: "memory",
+ },
+ {
+ args: []string{
+ "appname",
+ "-x",
+ "y",
+ "--span-storage.type",
+ "memory",
+ },
+ log: true,
+ value: "memory",
+ },
+ {
+ args: []string{"appname", "-x", "y", "--span-storage.type"},
+ log: true,
+ value: "cassandra",
+ },
{args: []string{"appname", "-x", "y"}, log: false, value: "cassandra"},
}
for _, testCase := range testCases {
diff --git a/plugin/storage/factory_test.go b/plugin/storage/factory_test.go
index b99aef57efc..2fdfa51ebbb 100644
--- a/plugin/storage/factory_test.go
+++ b/plugin/storage/factory_test.go
@@ -60,7 +60,11 @@ func TestNewFactory(t *testing.T) {
assert.Equal(t, cassandraStorageType, f.DependenciesStorageType)
f, err = NewFactory(FactoryConfig{
- SpanWriterTypes: []string{cassandraStorageType, kafkaStorageType, badgerStorageType},
+ SpanWriterTypes: []string{
+ cassandraStorageType,
+ kafkaStorageType,
+ badgerStorageType,
+ },
SpanReaderType: elasticsearchStorageType,
DependenciesStorageType: memoryStorageType,
})
@@ -70,11 +74,17 @@ func TestNewFactory(t *testing.T) {
assert.NotNil(t, f.factories[kafkaStorageType])
assert.NotEmpty(t, f.factories[elasticsearchStorageType])
assert.NotNil(t, f.factories[memoryStorageType])
- assert.Equal(t, []string{cassandraStorageType, kafkaStorageType, badgerStorageType}, f.SpanWriterTypes)
+ assert.Equal(
+ t,
+ []string{cassandraStorageType, kafkaStorageType, badgerStorageType},
+ f.SpanWriterTypes,
+ )
assert.Equal(t, elasticsearchStorageType, f.SpanReaderType)
assert.Equal(t, memoryStorageType, f.DependenciesStorageType)
- _, err = NewFactory(FactoryConfig{SpanWriterTypes: []string{"x"}, DependenciesStorageType: "y", SpanReaderType: "z"})
+ _, err = NewFactory(
+ FactoryConfig{SpanWriterTypes: []string{"x"}, DependenciesStorageType: "y", SpanReaderType: "z"},
+ )
require.Error(t, err)
expected := "unknown storage type" // could be 'x' or 'y' since code iterates through map.
assert.Equal(t, expected, err.Error()[0:len(expected)])
@@ -127,9 +137,13 @@ func TestCreate(t *testing.T) {
spanWriter := new(spanStoreMocks.Writer)
depReader := new(depStoreMocks.Reader)
- mock.On("CreateSpanReader").Return(spanReader, errors.New("span-reader-error"))
- mock.On("CreateSpanWriter").Once().Return(spanWriter, errors.New("span-writer-error"))
- mock.On("CreateDependencyReader").Return(depReader, errors.New("dep-reader-error"))
+ mock.On("CreateSpanReader").
+ Return(spanReader, errors.New("span-reader-error"))
+ mock.On("CreateSpanWriter").
+ Once().
+ Return(spanWriter, errors.New("span-writer-error"))
+ mock.On("CreateDependencyReader").
+ Return(depReader, errors.New("dep-reader-error"))
r, err := f.CreateSpanReader()
assert.Equal(t, spanReader, r)
@@ -188,7 +202,13 @@ func TestCreateDownsamplingWriter(t *testing.T) {
require.NoError(t, err)
// Currently directly assertEqual doesn't work since DownsamplingWriter initializes with different
// address for hashPool. The following workaround checks writer type instead
- assert.True(t, strings.HasPrefix(reflect.TypeOf(newWriter).String(), param.writerType))
+ assert.True(
+ t,
+ strings.HasPrefix(
+ reflect.TypeOf(newWriter).String(),
+ param.writerType,
+ ),
+ )
})
}
}
@@ -207,7 +227,9 @@ func TestCreateMulti(t *testing.T) {
spanWriter := new(spanStoreMocks.Writer)
spanWriter2 := new(spanStoreMocks.Writer)
- mock.On("CreateSpanWriter").Once().Return(spanWriter, errors.New("span-writer-error"))
+ mock.On("CreateSpanWriter").
+ Once().
+ Return(spanWriter, errors.New("span-writer-error"))
w, err := f.CreateSpanWriter()
assert.Nil(t, w)
@@ -239,8 +261,10 @@ func TestCreateArchive(t *testing.T) {
archiveSpanReader := new(spanStoreMocks.Reader)
archiveSpanWriter := new(spanStoreMocks.Writer)
- mock.ArchiveFactory.On("CreateArchiveSpanReader").Return(archiveSpanReader, errors.New("archive-span-reader-error"))
- mock.ArchiveFactory.On("CreateArchiveSpanWriter").Return(archiveSpanWriter, errors.New("archive-span-writer-error"))
+ mock.ArchiveFactory.On("CreateArchiveSpanReader").
+ Return(archiveSpanReader, errors.New("archive-span-reader-error"))
+ mock.ArchiveFactory.On("CreateArchiveSpanWriter").
+ Return(archiveSpanWriter, errors.New("archive-span-writer-error"))
ar, err := f.CreateArchiveSpanReader()
assert.Equal(t, archiveSpanReader, ar)
@@ -292,7 +316,11 @@ func TestCreateError(t *testing.T) {
}
func TestAllSamplingStorageTypes(t *testing.T) {
- assert.Equal(t, []string{"cassandra", "memory", "badger"}, AllSamplingStorageTypes())
+ assert.Equal(
+ t,
+ []string{"cassandra", "memory", "badger"},
+ AllSamplingStorageTypes(),
+ )
}
func TestCreateSamplingStoreFactory(t *testing.T) {
@@ -319,7 +347,11 @@ func TestCreateSamplingStoreFactory(t *testing.T) {
require.NoError(t, err)
ssFactory, err = f.CreateSamplingStoreFactory()
assert.Nil(t, ssFactory)
- require.EqualError(t, err, "storage factory of type elasticsearch does not support sampling store")
+ require.EqualError(
+ t,
+ err,
+ "storage factory of type elasticsearch does not support sampling store",
+ )
// if a compatible factory is specified then return it
cfg.SamplingStorageType = "cassandra"
@@ -396,7 +428,11 @@ func TestDefaultDownsamplingWithAddFlags(t *testing.T) {
f.InitFromViper(v, zap.NewNop())
assert.Equal(t, defaultDownsamplingRatio, f.FactoryConfig.DownsamplingRatio)
- assert.Equal(t, defaultDownsamplingHashSalt, f.FactoryConfig.DownsamplingHashSalt)
+ assert.Equal(
+ t,
+ defaultDownsamplingHashSalt,
+ f.FactoryConfig.DownsamplingHashSalt,
+ )
err = command.ParseFlags([]string{
"--downsampling.ratio=0.5",
@@ -409,8 +445,16 @@ func TestPublishOpts(t *testing.T) {
require.NoError(t, err)
f.publishOpts()
- assert.EqualValues(t, 1, expvar.Get(downsamplingRatio).(*expvar.Int).Value())
- assert.EqualValues(t, 1, expvar.Get(spanStorageType+"-"+f.SpanReaderType).(*expvar.Int).Value())
+ assert.EqualValues(
+ t,
+ 1,
+ expvar.Get(downsamplingRatio).(*expvar.Int).Value(),
+ )
+ assert.EqualValues(
+ t,
+ 1,
+ expvar.Get(spanStorageType+"-"+f.SpanReaderType).(*expvar.Int).Value(),
+ )
}
type errorFactory struct {
@@ -422,7 +466,10 @@ var (
_ io.Closer = (*errorFactory)(nil)
)
-func (errorFactory) Initialize(metricsFactory metrics.Factory, logger *zap.Logger) error {
+func (errorFactory) Initialize(
+ metricsFactory metrics.Factory,
+ logger *zap.Logger,
+) error {
panic("implement me")
}
diff --git a/plugin/storage/grpc/config.go b/plugin/storage/grpc/config.go
index 907cd1a13f9..5e64884295b 100644
--- a/plugin/storage/grpc/config.go
+++ b/plugin/storage/grpc/config.go
@@ -35,7 +35,7 @@ import (
// Configuration describes the options to customize the storage behavior.
type Configuration struct {
- RemoteServerAddr string `yaml:"server" mapstructure:"server"`
+ RemoteServerAddr string `yaml:"server" mapstructure:"server"`
RemoteTLS tlscfg.Options
RemoteConnectTimeout time.Duration `yaml:"connection-timeout" mapstructure:"connection-timeout"`
TenancyOpts tenancy.Options
@@ -67,22 +67,37 @@ type ClientPluginServices struct {
}
// TODO move this to factory.go
-func (c *ConfigV2) Build(logger *zap.Logger, tracerProvider trace.TracerProvider) (*ClientPluginServices, error) {
+func (c *ConfigV2) Build(
+ logger *zap.Logger,
+ tracerProvider trace.TracerProvider,
+) (*ClientPluginServices, error) {
telset := component.TelemetrySettings{
Logger: logger,
TracerProvider: tracerProvider,
}
newClientFn := func(opts ...grpc.DialOption) (conn *grpc.ClientConn, err error) {
- return c.ToClientConn(context.Background(), componenttest.NewNopHost(), telset, opts...)
+ return c.ToClientConn(
+ context.Background(),
+ componenttest.NewNopHost(),
+ telset,
+ opts...)
}
return newRemoteStorage(c, telset, newClientFn)
}
type newClientFn func(opts ...grpc.DialOption) (*grpc.ClientConn, error)
-func newRemoteStorage(c *ConfigV2, telset component.TelemetrySettings, newClient newClientFn) (*ClientPluginServices, error) {
+func newRemoteStorage(
+ c *ConfigV2,
+ telset component.TelemetrySettings,
+ newClient newClientFn,
+) (*ClientPluginServices, error) {
opts := []grpc.DialOption{
- grpc.WithStatsHandler(otelgrpc.NewClientHandler(otelgrpc.WithTracerProvider(telset.TracerProvider))),
+ grpc.WithStatsHandler(
+ otelgrpc.NewClientHandler(
+ otelgrpc.WithTracerProvider(telset.TracerProvider),
+ ),
+ ),
}
if c.Auth != nil {
return nil, fmt.Errorf("authenticator is not supported")
@@ -90,8 +105,18 @@ func newRemoteStorage(c *ConfigV2, telset component.TelemetrySettings, newClient
tenancyMgr := tenancy.NewManager(&c.Tenancy)
if tenancyMgr.Enabled {
- opts = append(opts, grpc.WithUnaryInterceptor(tenancy.NewClientUnaryInterceptor(tenancyMgr)))
- opts = append(opts, grpc.WithStreamInterceptor(tenancy.NewClientStreamInterceptor(tenancyMgr)))
+ opts = append(
+ opts,
+ grpc.WithUnaryInterceptor(
+ tenancy.NewClientUnaryInterceptor(tenancyMgr),
+ ),
+ )
+ opts = append(
+ opts,
+ grpc.WithStreamInterceptor(
+ tenancy.NewClientStreamInterceptor(tenancyMgr),
+ ),
+ )
}
remoteConn, err := newClient(opts...)
diff --git a/plugin/storage/grpc/factory.go b/plugin/storage/grpc/factory.go
index 0d8958cc2d3..2d8a087c899 100644
--- a/plugin/storage/grpc/factory.go
+++ b/plugin/storage/grpc/factory.go
@@ -78,12 +78,18 @@ func (*Factory) AddFlags(flagSet *flag.FlagSet) {
// InitFromViper implements plugin.Configurable
func (f *Factory) InitFromViper(v *viper.Viper, logger *zap.Logger) {
if err := v1InitFromViper(&f.configV1, v); err != nil {
- logger.Fatal("unable to initialize gRPC storage factory", zap.Error(err))
+ logger.Fatal(
+ "unable to initialize gRPC storage factory",
+ zap.Error(err),
+ )
}
}
// Initialize implements storage.Factory
-func (f *Factory) Initialize(metricsFactory metrics.Factory, logger *zap.Logger) error {
+func (f *Factory) Initialize(
+ metricsFactory metrics.Factory,
+ logger *zap.Logger,
+) error {
f.metricsFactory, f.logger = metricsFactory, logger
f.tracerProvider = otel.GetTracerProvider()
@@ -94,9 +100,15 @@ func (f *Factory) Initialize(metricsFactory metrics.Factory, logger *zap.Logger)
var err error
f.services, err = f.configV2.Build(logger, f.tracerProvider)
if err != nil {
- return fmt.Errorf("grpc storage builder failed to create a store: %w", err)
+ return fmt.Errorf(
+ "grpc storage builder failed to create a store: %w",
+ err,
+ )
}
- logger.Info("Remote storage configuration", zap.Any("configuration", f.configV2))
+ logger.Info(
+ "Remote storage configuration",
+ zap.Any("configuration", f.configV2),
+ )
return nil
}
@@ -108,7 +120,8 @@ func (f *Factory) CreateSpanReader() (spanstore.Reader, error) {
// CreateSpanWriter implements storage.Factory
func (f *Factory) CreateSpanWriter() (spanstore.Writer, error) {
if f.services.Capabilities != nil && f.services.StreamingSpanWriter != nil {
- if capabilities, err := f.services.Capabilities.Capabilities(); err == nil && capabilities.StreamingSpanWriter {
+ if capabilities, err := f.services.Capabilities.Capabilities(); err == nil &&
+ capabilities.StreamingSpanWriter {
return f.services.StreamingSpanWriter.StreamingSpanWriter(), nil
}
}
diff --git a/plugin/storage/grpc/factory_test.go b/plugin/storage/grpc/factory_test.go
index 94e1b0c4ddc..47ea47ed644 100644
--- a/plugin/storage/grpc/factory_test.go
+++ b/plugin/storage/grpc/factory_test.go
@@ -269,9 +269,11 @@ func TestStreamingSpanWriterFactory_CapabilitiesNil(t *testing.T) {
f.services.Capabilities = nil
mockWriter := f.services.Store.SpanWriter().(*spanStoreMocks.Writer)
- mockWriter.On("WriteSpan", mock.Anything, mock.Anything).Return(errors.New("not streaming writer"))
+ mockWriter.On("WriteSpan", mock.Anything, mock.Anything).
+ Return(errors.New("not streaming writer"))
mockWriter2 := f.services.StreamingSpanWriter.StreamingSpanWriter().(*spanStoreMocks.Writer)
- mockWriter2.On("WriteSpan", mock.Anything, mock.Anything).Return(errors.New("I am streaming writer"))
+ mockWriter2.On("WriteSpan", mock.Anything, mock.Anything).
+ Return(errors.New("I am streaming writer"))
writer, err := f.CreateSpanWriter()
require.NoError(t, err)
@@ -291,28 +293,46 @@ func TestStreamingSpanWriterFactory_Capabilities(t *testing.T) {
// then return false on the second call
On("Capabilities").Return(&shared.Capabilities{}, nil).Once().
// then return true on the second call
- On("Capabilities").Return(&shared.Capabilities{StreamingSpanWriter: true}, nil).Once()
+ On("Capabilities").
+ Return(&shared.Capabilities{StreamingSpanWriter: true}, nil).Once()
mockWriter := f.services.Store.SpanWriter().(*spanStoreMocks.Writer)
- mockWriter.On("WriteSpan", mock.Anything, mock.Anything).Return(errors.New("not streaming writer"))
+ mockWriter.On("WriteSpan", mock.Anything, mock.Anything).
+ Return(errors.New("not streaming writer"))
mockWriter2 := f.services.StreamingSpanWriter.StreamingSpanWriter().(*spanStoreMocks.Writer)
- mockWriter2.On("WriteSpan", mock.Anything, mock.Anything).Return(errors.New("I am streaming writer"))
+ mockWriter2.On("WriteSpan", mock.Anything, mock.Anything).
+ Return(errors.New("I am streaming writer"))
writer, err := f.CreateSpanWriter()
require.NoError(t, err)
err = writer.WriteSpan(context.Background(), nil)
require.Error(t, err)
- require.Contains(t, err.Error(), "not streaming writer", "unary writer when Capabilities return error")
+ require.Contains(
+ t,
+ err.Error(),
+ "not streaming writer",
+ "unary writer when Capabilities return error",
+ )
writer, err = f.CreateSpanWriter()
require.NoError(t, err)
err = writer.WriteSpan(context.Background(), nil)
require.Error(t, err)
- require.Contains(t, err.Error(), "not streaming writer", "unary writer when Capabilities return false")
+ require.Contains(
+ t,
+ err.Error(),
+ "not streaming writer",
+ "unary writer when Capabilities return false",
+ )
writer, err = f.CreateSpanWriter()
require.NoError(t, err)
err = writer.WriteSpan(context.Background(), nil)
require.Error(t, err)
- require.Contains(t, err.Error(), "I am streaming writer", "streaming writer when Capabilities return true")
+ require.Contains(
+ t,
+ err.Error(),
+ "I am streaming writer",
+ "streaming writer when Capabilities return true",
+ )
}
diff --git a/plugin/storage/grpc/options.go b/plugin/storage/grpc/options.go
index 1e9f85ed26c..48187446678 100644
--- a/plugin/storage/grpc/options.go
+++ b/plugin/storage/grpc/options.go
@@ -43,7 +43,11 @@ func v1AddFlags(flagSet *flag.FlagSet) {
tlsFlagsConfig().AddFlags(flagSet)
flagSet.String(remoteServer, "", "The remote storage gRPC server address as host:port")
- flagSet.Duration(remoteConnectionTimeout, defaultConnectionTimeout, "The remote storage gRPC server connection timeout")
+ flagSet.Duration(
+ remoteConnectionTimeout,
+ defaultConnectionTimeout,
+ "The remote storage gRPC server connection timeout",
+ )
}
func v1InitFromViper(cfg *Configuration, v *viper.Viper) error {
diff --git a/plugin/storage/grpc/proto/storage_v1/storage_test.go b/plugin/storage/grpc/proto/storage_v1/storage_test.go
index e9c4dd8b5d5..5b16db429e1 100644
--- a/plugin/storage/grpc/proto/storage_v1/storage_test.go
+++ b/plugin/storage/grpc/proto/storage_v1/storage_test.go
@@ -101,10 +101,12 @@ func makeSpan(someKV model.KeyValue) model.Span {
TraceID: traceID,
SpanID: model.NewSpanID(567),
OperationName: "hi",
- References: []model.SpanRef{model.NewChildOfRef(traceID, model.NewSpanID(123))},
- StartTime: time.Unix(0, 1000),
- Duration: 5000,
- Tags: model.KeyValues{someKV},
+ References: []model.SpanRef{
+ model.NewChildOfRef(traceID, model.NewSpanID(123)),
+ },
+ StartTime: time.Unix(0, 1000),
+ Duration: 5000,
+ Tags: model.KeyValues{someKV},
Logs: []model.Log{
{
Timestamp: time.Unix(0, 1000),
diff --git a/plugin/storage/grpc/proto/storageprototest/storage_test.pb.go b/plugin/storage/grpc/proto/storageprototest/storage_test.pb.go
index 369e573cf8f..67a9b8de89e 100644
--- a/plugin/storage/grpc/proto/storageprototest/storage_test.pb.go
+++ b/plugin/storage/grpc/proto/storageprototest/storage_test.pb.go
@@ -101,7 +101,9 @@ var (
func file_storage_test_proto_rawDescGZIP() []byte {
file_storage_test_proto_rawDescOnce.Do(func() {
- file_storage_test_proto_rawDescData = protoimpl.X.CompressGZIP(file_storage_test_proto_rawDescData)
+ file_storage_test_proto_rawDescData = protoimpl.X.CompressGZIP(
+ file_storage_test_proto_rawDescData,
+ )
})
return file_storage_test_proto_rawDescData
}
diff --git a/plugin/storage/grpc/shared/archive.go b/plugin/storage/grpc/shared/archive.go
index 1fceabddb03..db0ef2b9d6e 100644
--- a/plugin/storage/grpc/shared/archive.go
+++ b/plugin/storage/grpc/shared/archive.go
@@ -43,10 +43,16 @@ type archiveWriter struct {
}
// GetTrace takes a traceID and returns a Trace associated with that traceID from Archive Storage
-func (r *archiveReader) GetTrace(ctx context.Context, traceID model.TraceID) (*model.Trace, error) {
- stream, err := r.client.GetArchiveTrace(upgradeContext(ctx), &storage_v1.GetTraceRequest{
- TraceID: traceID,
- })
+func (r *archiveReader) GetTrace(
+ ctx context.Context,
+ traceID model.TraceID,
+) (*model.Trace, error) {
+ stream, err := r.client.GetArchiveTrace(
+ upgradeContext(ctx),
+ &storage_v1.GetTraceRequest{
+ TraceID: traceID,
+ },
+ )
if status.Code(err) == codes.NotFound {
return nil, spanstore.ErrTraceNotFound
}
@@ -63,17 +69,26 @@ func (*archiveReader) GetServices(ctx context.Context) ([]string, error) {
}
// GetOperations not used in archiveReader
-func (*archiveReader) GetOperations(ctx context.Context, query spanstore.OperationQueryParameters) ([]spanstore.Operation, error) {
+func (*archiveReader) GetOperations(
+ ctx context.Context,
+ query spanstore.OperationQueryParameters,
+) ([]spanstore.Operation, error) {
return nil, errors.New("GetOperations not implemented")
}
// FindTraces not used in archiveReader
-func (*archiveReader) FindTraces(ctx context.Context, query *spanstore.TraceQueryParameters) ([]*model.Trace, error) {
+func (*archiveReader) FindTraces(
+ ctx context.Context,
+ query *spanstore.TraceQueryParameters,
+) ([]*model.Trace, error) {
return nil, errors.New("FindTraces not implemented")
}
// FindTraceIDs not used in archiveReader
-func (*archiveReader) FindTraceIDs(ctx context.Context, query *spanstore.TraceQueryParameters) ([]model.TraceID, error) {
+func (*archiveReader) FindTraceIDs(
+ ctx context.Context,
+ query *spanstore.TraceQueryParameters,
+) ([]model.TraceID, error) {
return nil, errors.New("FindTraceIDs not implemented")
}
diff --git a/plugin/storage/grpc/shared/archive_test.go b/plugin/storage/grpc/shared/archive_test.go
index c6058211cdb..9a0c2753b53 100644
--- a/plugin/storage/grpc/shared/archive_test.go
+++ b/plugin/storage/grpc/shared/archive_test.go
@@ -67,7 +67,8 @@ func TestArchiveReader_GetTrace(t *testing.T) {
archiveSpanReader := new(mocks.ArchiveSpanReaderPluginClient)
archiveSpanReader.On("GetArchiveTrace", mock.Anything, &storage_v1.GetTraceRequest{
TraceID: mockTraceID,
- }).Return(traceClient, nil)
+ }).
+ Return(traceClient, nil)
reader := &archiveReader{client: archiveSpanReader}
trace, err := reader.GetTrace(context.Background(), mockTraceID)
@@ -81,7 +82,8 @@ func TestArchiveReaderGetTrace_NoTrace(t *testing.T) {
archiveSpanReader := new(mocks.ArchiveSpanReaderPluginClient)
archiveSpanReader.On("GetArchiveTrace", mock.Anything, &storage_v1.GetTraceRequest{
TraceID: mockTraceID,
- }).Return(nil, status.Errorf(codes.NotFound, ""))
+ }).
+ Return(nil, status.Errorf(codes.NotFound, ""))
reader := &archiveReader{client: archiveSpanReader}
_, err := reader.GetTrace(context.Background(), mockTraceID)
@@ -102,7 +104,10 @@ func TestArchiveReader_FindTraces(t *testing.T) {
func TestArchiveReader_GetOperations(t *testing.T) {
reader := archiveReader{client: &mocks.ArchiveSpanReaderPluginClient{}}
- _, err := reader.GetOperations(context.Background(), spanstore.OperationQueryParameters{})
+ _, err := reader.GetOperations(
+ context.Background(),
+ spanstore.OperationQueryParameters{},
+ )
require.Error(t, err)
}
diff --git a/plugin/storage/grpc/shared/grpc_client.go b/plugin/storage/grpc/shared/grpc_client.go
index 55f39971b14..3ecc0d9d8a5 100644
--- a/plugin/storage/grpc/shared/grpc_client.go
+++ b/plugin/storage/grpc/shared/grpc_client.go
@@ -74,7 +74,9 @@ type ContextUpgradeFunc func(ctx context.Context) context.Context
// composeContextUpgradeFuncs composes ContextUpgradeFunc and returns a composed function
// to run the given func in strict order.
-func composeContextUpgradeFuncs(funcs ...ContextUpgradeFunc) ContextUpgradeFunc {
+func composeContextUpgradeFuncs(
+ funcs ...ContextUpgradeFunc,
+) ContextUpgradeFunc {
return func(ctx context.Context) context.Context {
for _, fun := range funcs {
ctx = fun(ctx)
@@ -127,10 +129,16 @@ func (c *GRPCClient) ArchiveSpanWriter() spanstore.Writer {
}
// GetTrace takes a traceID and returns a Trace associated with that traceID
-func (c *GRPCClient) GetTrace(ctx context.Context, traceID model.TraceID) (*model.Trace, error) {
- stream, err := c.readerClient.GetTrace(upgradeContext(ctx), &storage_v1.GetTraceRequest{
- TraceID: traceID,
- })
+func (c *GRPCClient) GetTrace(
+ ctx context.Context,
+ traceID model.TraceID,
+) (*model.Trace, error) {
+ stream, err := c.readerClient.GetTrace(
+ upgradeContext(ctx),
+ &storage_v1.GetTraceRequest{
+ TraceID: traceID,
+ },
+ )
if status.Code(err) == codes.NotFound {
return nil, spanstore.ErrTraceNotFound
}
@@ -143,7 +151,10 @@ func (c *GRPCClient) GetTrace(ctx context.Context, traceID model.TraceID) (*mode
// GetServices returns a list of all known services
func (c *GRPCClient) GetServices(ctx context.Context) ([]string, error) {
- resp, err := c.readerClient.GetServices(upgradeContext(ctx), &storage_v1.GetServicesRequest{})
+ resp, err := c.readerClient.GetServices(
+ upgradeContext(ctx),
+ &storage_v1.GetServicesRequest{},
+ )
if err != nil {
return nil, fmt.Errorf("plugin error: %w", err)
}
@@ -156,10 +167,13 @@ func (c *GRPCClient) GetOperations(
ctx context.Context,
query spanstore.OperationQueryParameters,
) ([]spanstore.Operation, error) {
- resp, err := c.readerClient.GetOperations(upgradeContext(ctx), &storage_v1.GetOperationsRequest{
- Service: query.ServiceName,
- SpanKind: query.SpanKind,
- })
+ resp, err := c.readerClient.GetOperations(
+ upgradeContext(ctx),
+ &storage_v1.GetOperationsRequest{
+ Service: query.ServiceName,
+ SpanKind: query.SpanKind,
+ },
+ )
if err != nil {
return nil, fmt.Errorf("plugin error: %w", err)
}
@@ -183,19 +197,25 @@ func (c *GRPCClient) GetOperations(
}
// FindTraces retrieves traces that match the traceQuery
-func (c *GRPCClient) FindTraces(ctx context.Context, query *spanstore.TraceQueryParameters) ([]*model.Trace, error) {
- stream, err := c.readerClient.FindTraces(upgradeContext(ctx), &storage_v1.FindTracesRequest{
- Query: &storage_v1.TraceQueryParameters{
- ServiceName: query.ServiceName,
- OperationName: query.OperationName,
- Tags: query.Tags,
- StartTimeMin: query.StartTimeMin,
- StartTimeMax: query.StartTimeMax,
- DurationMin: query.DurationMin,
- DurationMax: query.DurationMax,
- NumTraces: int32(query.NumTraces),
+func (c *GRPCClient) FindTraces(
+ ctx context.Context,
+ query *spanstore.TraceQueryParameters,
+) ([]*model.Trace, error) {
+ stream, err := c.readerClient.FindTraces(
+ upgradeContext(ctx),
+ &storage_v1.FindTracesRequest{
+ Query: &storage_v1.TraceQueryParameters{
+ ServiceName: query.ServiceName,
+ OperationName: query.OperationName,
+ Tags: query.Tags,
+ StartTimeMin: query.StartTimeMin,
+ StartTimeMax: query.StartTimeMax,
+ DurationMin: query.DurationMin,
+ DurationMax: query.DurationMax,
+ NumTraces: int32(query.NumTraces),
+ },
},
- })
+ )
if err != nil {
return nil, fmt.Errorf("plugin error: %w", err)
}
@@ -221,19 +241,25 @@ func (c *GRPCClient) FindTraces(ctx context.Context, query *spanstore.TraceQuery
}
// FindTraceIDs retrieves traceIDs that match the traceQuery
-func (c *GRPCClient) FindTraceIDs(ctx context.Context, query *spanstore.TraceQueryParameters) ([]model.TraceID, error) {
- resp, err := c.readerClient.FindTraceIDs(upgradeContext(ctx), &storage_v1.FindTraceIDsRequest{
- Query: &storage_v1.TraceQueryParameters{
- ServiceName: query.ServiceName,
- OperationName: query.OperationName,
- Tags: query.Tags,
- StartTimeMin: query.StartTimeMin,
- StartTimeMax: query.StartTimeMax,
- DurationMin: query.DurationMin,
- DurationMax: query.DurationMax,
- NumTraces: int32(query.NumTraces),
+func (c *GRPCClient) FindTraceIDs(
+ ctx context.Context,
+ query *spanstore.TraceQueryParameters,
+) ([]model.TraceID, error) {
+ resp, err := c.readerClient.FindTraceIDs(
+ upgradeContext(ctx),
+ &storage_v1.FindTraceIDsRequest{
+ Query: &storage_v1.TraceQueryParameters{
+ ServiceName: query.ServiceName,
+ OperationName: query.OperationName,
+ Tags: query.Tags,
+ StartTimeMin: query.StartTimeMin,
+ StartTimeMax: query.StartTimeMax,
+ DurationMin: query.DurationMin,
+ DurationMax: query.DurationMax,
+ NumTraces: int32(query.NumTraces),
+ },
},
- })
+ )
if err != nil {
return nil, fmt.Errorf("plugin error: %w", err)
}
@@ -254,7 +280,10 @@ func (c *GRPCClient) WriteSpan(ctx context.Context, span *model.Span) error {
}
func (c *GRPCClient) Close() error {
- _, err := c.writerClient.Close(context.Background(), &storage_v1.CloseWriterRequest{})
+ _, err := c.writerClient.Close(
+ context.Background(),
+ &storage_v1.CloseWriterRequest{},
+ )
if err != nil && status.Code(err) != codes.Unimplemented {
return fmt.Errorf("plugin error: %w", err)
}
@@ -263,7 +292,11 @@ func (c *GRPCClient) Close() error {
}
// GetDependencies returns all interservice dependencies
-func (c *GRPCClient) GetDependencies(ctx context.Context, endTs time.Time, lookback time.Duration) ([]model.DependencyLink, error) {
+func (c *GRPCClient) GetDependencies(
+ ctx context.Context,
+ endTs time.Time,
+ lookback time.Duration,
+) ([]model.DependencyLink, error) {
resp, err := c.depsReaderClient.GetDependencies(ctx, &storage_v1.GetDependenciesRequest{
EndTime: endTs,
StartTime: endTs.Add(-lookback),
@@ -276,7 +309,10 @@ func (c *GRPCClient) GetDependencies(ctx context.Context, endTs time.Time, lookb
}
func (c *GRPCClient) Capabilities() (*Capabilities, error) {
- capabilities, err := c.capabilitiesClient.Capabilities(context.Background(), &storage_v1.CapabilitiesRequest{})
+ capabilities, err := c.capabilitiesClient.Capabilities(
+ context.Background(),
+ &storage_v1.CapabilitiesRequest{},
+ )
if status.Code(err) == codes.Unimplemented {
return &Capabilities{}, nil
}
@@ -291,7 +327,9 @@ func (c *GRPCClient) Capabilities() (*Capabilities, error) {
}, nil
}
-func readTrace(stream storage_v1.SpanReaderPlugin_GetTraceClient) (*model.Trace, error) {
+func readTrace(
+ stream storage_v1.SpanReaderPlugin_GetTraceClient,
+) (*model.Trace, error) {
trace := model.Trace{}
for received, err := stream.Recv(); !errors.Is(err, io.EOF); received, err = stream.Recv() {
if err != nil {
diff --git a/plugin/storage/grpc/shared/grpc_client_test.go b/plugin/storage/grpc/shared/grpc_client_test.go
index 8f9beb69650..a1cfc574a7e 100644
--- a/plugin/storage/grpc/shared/grpc_client_test.go
+++ b/plugin/storage/grpc/shared/grpc_client_test.go
@@ -118,18 +118,49 @@ func TestNewGRPCClient(t *testing.T) {
client := NewGRPCClient(conn)
assert.NotNil(t, client)
- assert.Implements(t, (*storage_v1.SpanReaderPluginClient)(nil), client.readerClient)
- assert.Implements(t, (*storage_v1.SpanWriterPluginClient)(nil), client.writerClient)
- assert.Implements(t, (*storage_v1.ArchiveSpanReaderPluginClient)(nil), client.archiveReaderClient)
- assert.Implements(t, (*storage_v1.ArchiveSpanWriterPluginClient)(nil), client.archiveWriterClient)
- assert.Implements(t, (*storage_v1.PluginCapabilitiesClient)(nil), client.capabilitiesClient)
- assert.Implements(t, (*storage_v1.DependenciesReaderPluginClient)(nil), client.depsReaderClient)
- assert.Implements(t, (*storage_v1.StreamingSpanWriterPluginClient)(nil), client.streamWriterClient)
+ assert.Implements(
+ t,
+ (*storage_v1.SpanReaderPluginClient)(nil),
+ client.readerClient,
+ )
+ assert.Implements(
+ t,
+ (*storage_v1.SpanWriterPluginClient)(nil),
+ client.writerClient,
+ )
+ assert.Implements(
+ t,
+ (*storage_v1.ArchiveSpanReaderPluginClient)(nil),
+ client.archiveReaderClient,
+ )
+ assert.Implements(
+ t,
+ (*storage_v1.ArchiveSpanWriterPluginClient)(nil),
+ client.archiveWriterClient,
+ )
+ assert.Implements(
+ t,
+ (*storage_v1.PluginCapabilitiesClient)(nil),
+ client.capabilitiesClient,
+ )
+ assert.Implements(
+ t,
+ (*storage_v1.DependenciesReaderPluginClient)(nil),
+ client.depsReaderClient,
+ )
+ assert.Implements(
+ t,
+ (*storage_v1.StreamingSpanWriterPluginClient)(nil),
+ client.streamWriterClient,
+ )
}
func TestContextUpgradeWithToken(t *testing.T) {
testBearerToken := "test-bearer-token"
- ctx := bearertoken.ContextWithBearerToken(context.Background(), testBearerToken)
+ ctx := bearertoken.ContextWithBearerToken(
+ context.Background(),
+ testBearerToken,
+ )
upgradedToken := upgradeContextWithBearerToken(ctx)
md, ok := metadata.FromOutgoingContext(upgradedToken)
assert.Truef(t, ok, "Expected metadata in context")
@@ -158,9 +189,10 @@ func TestGRPCClientGetOperationsV1(t *testing.T) {
withGRPCClient(func(r *grpcClientTest) {
r.spanReader.On("GetOperations", mock.Anything, &storage_v1.GetOperationsRequest{
Service: "service-a",
- }).Return(&storage_v1.GetOperationsResponse{
- OperationNames: []string{"operation-a"},
- }, nil)
+ }).
+ Return(&storage_v1.GetOperationsResponse{
+ OperationNames: []string{"operation-a"},
+ }, nil)
s, err := r.client.GetOperations(context.Background(),
spanstore.OperationQueryParameters{ServiceName: "service-a"})
@@ -173,14 +205,21 @@ func TestGRPCClientGetOperationsV2(t *testing.T) {
withGRPCClient(func(r *grpcClientTest) {
r.spanReader.On("GetOperations", mock.Anything, &storage_v1.GetOperationsRequest{
Service: "service-a",
- }).Return(&storage_v1.GetOperationsResponse{
- Operations: []*storage_v1.Operation{{Name: "operation-a", SpanKind: "server"}},
- }, nil)
+ }).
+ Return(&storage_v1.GetOperationsResponse{
+ Operations: []*storage_v1.Operation{
+ {Name: "operation-a", SpanKind: "server"},
+ },
+ }, nil)
s, err := r.client.GetOperations(context.Background(),
spanstore.OperationQueryParameters{ServiceName: "service-a"})
require.NoError(t, err)
- assert.Equal(t, []spanstore.Operation{{Name: "operation-a", SpanKind: "server"}}, s)
+ assert.Equal(
+ t,
+ []spanstore.Operation{{Name: "operation-a", SpanKind: "server"}},
+ s,
+ )
})
}
@@ -259,9 +298,13 @@ func TestGRPCClientFindTraces(t *testing.T) {
traceClient.On("Recv").Return(nil, io.EOF)
r.spanReader.On("FindTraces", mock.Anything, &storage_v1.FindTracesRequest{
Query: &storage_v1.TraceQueryParameters{},
- }).Return(traceClient, nil)
+ }).
+ Return(traceClient, nil)
- s, err := r.client.FindTraces(context.Background(), &spanstore.TraceQueryParameters{})
+ s, err := r.client.FindTraces(
+ context.Background(),
+ &spanstore.TraceQueryParameters{},
+ )
require.NoError(t, err)
assert.NotNil(t, s)
assert.Len(t, s, 2)
@@ -272,9 +315,13 @@ func TestGRPCClientFindTraces_Error(t *testing.T) {
withGRPCClient(func(r *grpcClientTest) {
r.spanReader.On("FindTraces", mock.Anything, &storage_v1.FindTracesRequest{
Query: &storage_v1.TraceQueryParameters{},
- }).Return(nil, errors.New("an error"))
+ }).
+ Return(nil, errors.New("an error"))
- s, err := r.client.FindTraces(context.Background(), &spanstore.TraceQueryParameters{})
+ s, err := r.client.FindTraces(
+ context.Background(),
+ &spanstore.TraceQueryParameters{},
+ )
require.Error(t, err)
assert.Nil(t, s)
})
@@ -286,9 +333,13 @@ func TestGRPCClientFindTraces_RecvError(t *testing.T) {
traceClient.On("Recv").Return(nil, errors.New("an error"))
r.spanReader.On("FindTraces", mock.Anything, &storage_v1.FindTracesRequest{
Query: &storage_v1.TraceQueryParameters{},
- }).Return(traceClient, nil)
+ }).
+ Return(traceClient, nil)
- s, err := r.client.FindTraces(context.Background(), &spanstore.TraceQueryParameters{})
+ s, err := r.client.FindTraces(
+ context.Background(),
+ &spanstore.TraceQueryParameters{},
+ )
require.Error(t, err)
assert.Nil(t, s)
})
@@ -298,11 +349,15 @@ func TestGRPCClientFindTraceIDs(t *testing.T) {
withGRPCClient(func(r *grpcClientTest) {
r.spanReader.On("FindTraceIDs", mock.Anything, &storage_v1.FindTraceIDsRequest{
Query: &storage_v1.TraceQueryParameters{},
- }).Return(&storage_v1.FindTraceIDsResponse{
- TraceIDs: []model.TraceID{mockTraceID, mockTraceID2},
- }, nil)
-
- s, err := r.client.FindTraceIDs(context.Background(), &spanstore.TraceQueryParameters{})
+ }).
+ Return(&storage_v1.FindTraceIDsResponse{
+ TraceIDs: []model.TraceID{mockTraceID, mockTraceID2},
+ }, nil)
+
+ s, err := r.client.FindTraceIDs(
+ context.Background(),
+ &spanstore.TraceQueryParameters{},
+ )
require.NoError(t, err)
assert.Equal(t, []model.TraceID{mockTraceID, mockTraceID2}, s)
})
@@ -312,16 +367,19 @@ func TestGRPCClientWriteSpan(t *testing.T) {
withGRPCClient(func(r *grpcClientTest) {
r.spanWriter.On("WriteSpan", mock.Anything, &storage_v1.WriteSpanRequest{
Span: &mockTraceSpans[0],
- }).Return(&storage_v1.WriteSpanResponse{}, nil)
+ }).
+ Return(&storage_v1.WriteSpanResponse{}, nil)
- err := r.client.SpanWriter().WriteSpan(context.Background(), &mockTraceSpans[0])
+ err := r.client.SpanWriter().
+ WriteSpan(context.Background(), &mockTraceSpans[0])
require.NoError(t, err)
})
}
func TestGRPCClientCloseWriter(t *testing.T) {
withGRPCClient(func(r *grpcClientTest) {
- r.spanWriter.On("Close", mock.Anything, &storage_v1.CloseWriterRequest{}).Return(&storage_v1.CloseWriterResponse{}, nil)
+ r.spanWriter.On("Close", mock.Anything, &storage_v1.CloseWriterRequest{}).
+ Return(&storage_v1.CloseWriterResponse{}, nil)
err := r.client.Close()
require.NoError(t, err)
@@ -330,8 +388,9 @@ func TestGRPCClientCloseWriter(t *testing.T) {
func TestGRPCClientCloseNotSupported(t *testing.T) {
withGRPCClient(func(r *grpcClientTest) {
- r.spanWriter.On("Close", mock.Anything, &storage_v1.CloseWriterRequest{}).Return(
- nil, status.Errorf(codes.Unimplemented, "method not implemented"))
+ r.spanWriter.On("Close", mock.Anything, &storage_v1.CloseWriterRequest{}).
+ Return(
+ nil, status.Errorf(codes.Unimplemented, "method not implemented"))
err := r.client.Close()
require.NoError(t, err)
@@ -351,7 +410,8 @@ func TestGRPCClientGetDependencies(t *testing.T) {
r.depsReader.On("GetDependencies", mock.Anything, &storage_v1.GetDependenciesRequest{
StartTime: end.Add(-lookback),
EndTime: end,
- }).Return(&storage_v1.GetDependenciesResponse{Dependencies: deps}, nil)
+ }).
+ Return(&storage_v1.GetDependenciesResponse{Dependencies: deps}, nil)
s, err := r.client.GetDependencies(context.Background(), end, lookback)
require.NoError(t, err)
@@ -363,9 +423,11 @@ func TestGrpcClientWriteArchiveSpan(t *testing.T) {
withGRPCClient(func(r *grpcClientTest) {
r.archiveWriter.On("WriteArchiveSpan", mock.Anything, &storage_v1.WriteSpanRequest{
Span: &mockTraceSpans[0],
- }).Return(&storage_v1.WriteSpanResponse{}, nil)
+ }).
+ Return(&storage_v1.WriteSpanResponse{}, nil)
- err := r.client.ArchiveSpanWriter().WriteSpan(context.Background(), &mockTraceSpans[0])
+ err := r.client.ArchiveSpanWriter().
+ WriteSpan(context.Background(), &mockTraceSpans[0])
require.NoError(t, err)
})
}
@@ -374,9 +436,11 @@ func TestGrpcClientWriteArchiveSpan_Error(t *testing.T) {
withGRPCClient(func(r *grpcClientTest) {
r.archiveWriter.On("WriteArchiveSpan", mock.Anything, &storage_v1.WriteSpanRequest{
Span: &mockTraceSpans[0],
- }).Return(nil, status.Error(codes.Internal, "internal error"))
+ }).
+ Return(nil, status.Error(codes.Internal, "internal error"))
- err := r.client.ArchiveSpanWriter().WriteSpan(context.Background(), &mockTraceSpans[0])
+ err := r.client.ArchiveSpanWriter().
+ WriteSpan(context.Background(), &mockTraceSpans[0])
require.Error(t, err)
})
}
@@ -385,29 +449,35 @@ func TestGrpcClientStreamWriterWriteSpan(t *testing.T) {
withGRPCClient(func(r *grpcClientTest) {
stream := new(grpcMocks.StreamingSpanWriterPlugin_WriteSpanStreamClient)
r.streamWriter.On("WriteSpanStream", mock.Anything).Return(stream, nil)
- stream.On("Send", &storage_v1.WriteSpanRequest{Span: &mockTraceSpans[0]}).Return(nil)
- err := r.client.StreamingSpanWriter().WriteSpan(context.Background(), &mockTraceSpans[0])
+ stream.On("Send", &storage_v1.WriteSpanRequest{Span: &mockTraceSpans[0]}).
+ Return(nil)
+ err := r.client.StreamingSpanWriter().
+ WriteSpan(context.Background(), &mockTraceSpans[0])
require.NoError(t, err)
})
}
func TestGrpcClientGetArchiveTrace(t *testing.T) {
withGRPCClient(func(r *grpcClientTest) {
- traceClient := new(grpcMocks.ArchiveSpanReaderPlugin_GetArchiveTraceClient)
+ traceClient := new(
+ grpcMocks.ArchiveSpanReaderPlugin_GetArchiveTraceClient,
+ )
traceClient.On("Recv").Return(&storage_v1.SpansResponseChunk{
Spans: mockTraceSpans,
}, nil).Once()
traceClient.On("Recv").Return(nil, io.EOF)
r.archiveReader.On("GetArchiveTrace", mock.Anything, &storage_v1.GetTraceRequest{
TraceID: mockTraceID,
- }).Return(traceClient, nil)
+ }).
+ Return(traceClient, nil)
var expectedSpans []*model.Span
for i := range mockTraceSpans {
expectedSpans = append(expectedSpans, &mockTraceSpans[i])
}
- s, err := r.client.ArchiveSpanReader().GetTrace(context.Background(), mockTraceID)
+ s, err := r.client.ArchiveSpanReader().
+ GetTrace(context.Background(), mockTraceID)
require.NoError(t, err)
assert.Equal(t, &model.Trace{
Spans: expectedSpans,
@@ -417,13 +487,17 @@ func TestGrpcClientGetArchiveTrace(t *testing.T) {
func TestGrpcClientGetArchiveTrace_StreamError(t *testing.T) {
withGRPCClient(func(r *grpcClientTest) {
- traceClient := new(grpcMocks.ArchiveSpanReaderPlugin_GetArchiveTraceClient)
+ traceClient := new(
+ grpcMocks.ArchiveSpanReaderPlugin_GetArchiveTraceClient,
+ )
traceClient.On("Recv").Return(nil, errors.New("an error"))
r.archiveReader.On("GetArchiveTrace", mock.Anything, &storage_v1.GetTraceRequest{
TraceID: mockTraceID,
- }).Return(traceClient, nil)
+ }).
+ Return(traceClient, nil)
- s, err := r.client.ArchiveSpanReader().GetTrace(context.Background(), mockTraceID)
+ s, err := r.client.ArchiveSpanReader().
+ GetTrace(context.Background(), mockTraceID)
require.Error(t, err)
assert.Nil(t, s)
})
@@ -433,9 +507,11 @@ func TestGrpcClientGetArchiveTrace_NoTrace(t *testing.T) {
withGRPCClient(func(r *grpcClientTest) {
r.archiveReader.On("GetArchiveTrace", mock.Anything, &storage_v1.GetTraceRequest{
TraceID: mockTraceID,
- }).Return(nil, spanstore.ErrTraceNotFound)
+ }).
+ Return(nil, spanstore.ErrTraceNotFound)
- s, err := r.client.ArchiveSpanReader().GetTrace(context.Background(), mockTraceID)
+ s, err := r.client.ArchiveSpanReader().
+ GetTrace(context.Background(), mockTraceID)
require.Error(t, err)
assert.Nil(t, s)
})
@@ -443,13 +519,17 @@ func TestGrpcClientGetArchiveTrace_NoTrace(t *testing.T) {
func TestGrpcClientGetArchiveTrace_StreamErrorTraceNotFound(t *testing.T) {
withGRPCClient(func(r *grpcClientTest) {
- traceClient := new(grpcMocks.ArchiveSpanReaderPlugin_GetArchiveTraceClient)
+ traceClient := new(
+ grpcMocks.ArchiveSpanReaderPlugin_GetArchiveTraceClient,
+ )
traceClient.On("Recv").Return(nil, spanstore.ErrTraceNotFound)
r.archiveReader.On("GetArchiveTrace", mock.Anything, &storage_v1.GetTraceRequest{
TraceID: mockTraceID,
- }).Return(traceClient, nil)
+ }).
+ Return(traceClient, nil)
- s, err := r.client.ArchiveSpanReader().GetTrace(context.Background(), mockTraceID)
+ s, err := r.client.ArchiveSpanReader().
+ GetTrace(context.Background(), mockTraceID)
assert.Equal(t, spanstore.ErrTraceNotFound, err)
assert.Nil(t, s)
})
diff --git a/plugin/storage/grpc/shared/grpc_handler.go b/plugin/storage/grpc/shared/grpc_handler.go
index fd76ac7f1d3..1e7d1fb6c66 100644
--- a/plugin/storage/grpc/shared/grpc_handler.go
+++ b/plugin/storage/grpc/shared/grpc_handler.go
@@ -95,20 +95,44 @@ func (s *GRPCHandler) Register(ss *grpc.Server, hs *health.Server) error {
storage_v1.RegisterDependenciesReaderPluginServer(ss, s)
storage_v1.RegisterStreamingSpanWriterPluginServer(ss, s)
- hs.SetServingStatus("jaeger.storage.v1.SpanReaderPlugin", grpc_health_v1.HealthCheckResponse_SERVING)
- hs.SetServingStatus("jaeger.storage.v1.SpanWriterPlugin", grpc_health_v1.HealthCheckResponse_SERVING)
- hs.SetServingStatus("jaeger.storage.v1.ArchiveSpanReaderPlugin", grpc_health_v1.HealthCheckResponse_SERVING)
- hs.SetServingStatus("jaeger.storage.v1.ArchiveSpanWriterPlugin", grpc_health_v1.HealthCheckResponse_SERVING)
- hs.SetServingStatus("jaeger.storage.v1.PluginCapabilities", grpc_health_v1.HealthCheckResponse_SERVING)
- hs.SetServingStatus("jaeger.storage.v1.DependenciesReaderPlugin", grpc_health_v1.HealthCheckResponse_SERVING)
- hs.SetServingStatus("jaeger.storage.v1.StreamingSpanWriterPlugin", grpc_health_v1.HealthCheckResponse_SERVING)
+ hs.SetServingStatus(
+ "jaeger.storage.v1.SpanReaderPlugin",
+ grpc_health_v1.HealthCheckResponse_SERVING,
+ )
+ hs.SetServingStatus(
+ "jaeger.storage.v1.SpanWriterPlugin",
+ grpc_health_v1.HealthCheckResponse_SERVING,
+ )
+ hs.SetServingStatus(
+ "jaeger.storage.v1.ArchiveSpanReaderPlugin",
+ grpc_health_v1.HealthCheckResponse_SERVING,
+ )
+ hs.SetServingStatus(
+ "jaeger.storage.v1.ArchiveSpanWriterPlugin",
+ grpc_health_v1.HealthCheckResponse_SERVING,
+ )
+ hs.SetServingStatus(
+ "jaeger.storage.v1.PluginCapabilities",
+ grpc_health_v1.HealthCheckResponse_SERVING,
+ )
+ hs.SetServingStatus(
+ "jaeger.storage.v1.DependenciesReaderPlugin",
+ grpc_health_v1.HealthCheckResponse_SERVING,
+ )
+ hs.SetServingStatus(
+ "jaeger.storage.v1.StreamingSpanWriterPlugin",
+ grpc_health_v1.HealthCheckResponse_SERVING,
+ )
grpc_health_v1.RegisterHealthServer(ss, hs)
return nil
}
// GetDependencies returns all interservice dependencies
-func (s *GRPCHandler) GetDependencies(ctx context.Context, r *storage_v1.GetDependenciesRequest) (*storage_v1.GetDependenciesResponse, error) {
+func (s *GRPCHandler) GetDependencies(
+ ctx context.Context,
+ r *storage_v1.GetDependenciesRequest,
+) (*storage_v1.GetDependenciesResponse, error) {
deps, err := s.impl.DependencyReader().GetDependencies(ctx, r.EndTime, r.EndTime.Sub(r.StartTime))
if err != nil {
return nil, err
@@ -119,7 +143,9 @@ func (s *GRPCHandler) GetDependencies(ctx context.Context, r *storage_v1.GetDepe
}
// WriteSpanStream receive the span from stream and save it
-func (s *GRPCHandler) WriteSpanStream(stream storage_v1.StreamingSpanWriterPlugin_WriteSpanStreamServer) error {
+func (s *GRPCHandler) WriteSpanStream(
+ stream storage_v1.StreamingSpanWriterPlugin_WriteSpanStreamServer,
+) error {
writer := s.impl.StreamingSpanWriter()
if writer == nil {
return status.Error(codes.Unimplemented, "not implemented")
@@ -141,7 +167,10 @@ func (s *GRPCHandler) WriteSpanStream(stream storage_v1.StreamingSpanWriterPlugi
}
// WriteSpan saves the span
-func (s *GRPCHandler) WriteSpan(ctx context.Context, r *storage_v1.WriteSpanRequest) (*storage_v1.WriteSpanResponse, error) {
+func (s *GRPCHandler) WriteSpan(
+ ctx context.Context,
+ r *storage_v1.WriteSpanRequest,
+) (*storage_v1.WriteSpanResponse, error) {
err := s.impl.SpanWriter().WriteSpan(ctx, r.Span)
if err != nil {
return nil, err
@@ -149,7 +178,10 @@ func (s *GRPCHandler) WriteSpan(ctx context.Context, r *storage_v1.WriteSpanRequ
return &storage_v1.WriteSpanResponse{}, nil
}
-func (s *GRPCHandler) Close(ctx context.Context, r *storage_v1.CloseWriterRequest) (*storage_v1.CloseWriterResponse, error) {
+func (s *GRPCHandler) Close(
+ ctx context.Context,
+ r *storage_v1.CloseWriterRequest,
+) (*storage_v1.CloseWriterResponse, error) {
if closer, ok := s.impl.SpanWriter().(io.Closer); ok {
if err := closer.Close(); err != nil {
return nil, err
@@ -157,11 +189,17 @@ func (s *GRPCHandler) Close(ctx context.Context, r *storage_v1.CloseWriterReques
return &storage_v1.CloseWriterResponse{}, nil
}
- return nil, status.Error(codes.Unimplemented, "span writer does not support graceful shutdown")
+ return nil, status.Error(
+ codes.Unimplemented,
+ "span writer does not support graceful shutdown",
+ )
}
// GetTrace takes a traceID and streams a Trace associated with that traceID
-func (s *GRPCHandler) GetTrace(r *storage_v1.GetTraceRequest, stream storage_v1.SpanReaderPlugin_GetTraceServer) error {
+func (s *GRPCHandler) GetTrace(
+ r *storage_v1.GetTraceRequest,
+ stream storage_v1.SpanReaderPlugin_GetTraceServer,
+) error {
trace, err := s.impl.SpanReader().GetTrace(stream.Context(), r.TraceID)
if errors.Is(err, spanstore.ErrTraceNotFound) {
return status.Errorf(codes.NotFound, spanstore.ErrTraceNotFound.Error())
@@ -179,7 +217,10 @@ func (s *GRPCHandler) GetTrace(r *storage_v1.GetTraceRequest, stream storage_v1.
}
// GetServices returns a list of all known services
-func (s *GRPCHandler) GetServices(ctx context.Context, r *storage_v1.GetServicesRequest) (*storage_v1.GetServicesResponse, error) {
+func (s *GRPCHandler) GetServices(
+ ctx context.Context,
+ r *storage_v1.GetServicesRequest,
+) (*storage_v1.GetServicesResponse, error) {
services, err := s.impl.SpanReader().GetServices(ctx)
if err != nil {
return nil, err
@@ -194,10 +235,11 @@ func (s *GRPCHandler) GetOperations(
ctx context.Context,
r *storage_v1.GetOperationsRequest,
) (*storage_v1.GetOperationsResponse, error) {
- operations, err := s.impl.SpanReader().GetOperations(ctx, spanstore.OperationQueryParameters{
- ServiceName: r.Service,
- SpanKind: r.SpanKind,
- })
+ operations, err := s.impl.SpanReader().
+ GetOperations(ctx, spanstore.OperationQueryParameters{
+ ServiceName: r.Service,
+ SpanKind: r.SpanKind,
+ })
if err != nil {
return nil, err
}
@@ -214,7 +256,10 @@ func (s *GRPCHandler) GetOperations(
}
// FindTraces streams traces that match the traceQuery
-func (s *GRPCHandler) FindTraces(r *storage_v1.FindTracesRequest, stream storage_v1.SpanReaderPlugin_FindTracesServer) error {
+func (s *GRPCHandler) FindTraces(
+ r *storage_v1.FindTracesRequest,
+ stream storage_v1.SpanReaderPlugin_FindTracesServer,
+) error {
traces, err := s.impl.SpanReader().FindTraces(stream.Context(), &spanstore.TraceQueryParameters{
ServiceName: r.Query.ServiceName,
OperationName: r.Query.OperationName,
@@ -240,7 +285,10 @@ func (s *GRPCHandler) FindTraces(r *storage_v1.FindTracesRequest, stream storage
}
// FindTraceIDs retrieves traceIDs that match the traceQuery
-func (s *GRPCHandler) FindTraceIDs(ctx context.Context, r *storage_v1.FindTraceIDsRequest) (*storage_v1.FindTraceIDsResponse, error) {
+func (s *GRPCHandler) FindTraceIDs(
+ ctx context.Context,
+ r *storage_v1.FindTraceIDsRequest,
+) (*storage_v1.FindTraceIDsResponse, error) {
traceIDs, err := s.impl.SpanReader().FindTraceIDs(ctx, &spanstore.TraceQueryParameters{
ServiceName: r.Query.ServiceName,
OperationName: r.Query.OperationName,
@@ -259,7 +307,10 @@ func (s *GRPCHandler) FindTraceIDs(ctx context.Context, r *storage_v1.FindTraceI
}, nil
}
-func (*GRPCHandler) sendSpans(spans []*model.Span, sendFn func(*storage_v1.SpansResponseChunk) error) error {
+func (*GRPCHandler) sendSpans(
+ spans []*model.Span,
+ sendFn func(*storage_v1.SpansResponseChunk) error,
+) error {
chunk := make([]model.Span, 0, len(spans))
for i := 0; i < len(spans); i += spanBatchSize {
chunk = chunk[:0]
@@ -274,7 +325,10 @@ func (*GRPCHandler) sendSpans(spans []*model.Span, sendFn func(*storage_v1.Spans
return nil
}
-func (s *GRPCHandler) Capabilities(ctx context.Context, request *storage_v1.CapabilitiesRequest) (*storage_v1.CapabilitiesResponse, error) {
+func (s *GRPCHandler) Capabilities(
+ ctx context.Context,
+ request *storage_v1.CapabilitiesRequest,
+) (*storage_v1.CapabilitiesResponse, error) {
return &storage_v1.CapabilitiesResponse{
ArchiveSpanReader: s.impl.ArchiveSpanReader() != nil,
ArchiveSpanWriter: s.impl.ArchiveSpanWriter() != nil,
@@ -282,7 +336,10 @@ func (s *GRPCHandler) Capabilities(ctx context.Context, request *storage_v1.Capa
}, nil
}
-func (s *GRPCHandler) GetArchiveTrace(r *storage_v1.GetTraceRequest, stream storage_v1.ArchiveSpanReaderPlugin_GetArchiveTraceServer) error {
+func (s *GRPCHandler) GetArchiveTrace(
+ r *storage_v1.GetTraceRequest,
+ stream storage_v1.ArchiveSpanReaderPlugin_GetArchiveTraceServer,
+) error {
reader := s.impl.ArchiveSpanReader()
if reader == nil {
return status.Error(codes.Unimplemented, "not implemented")
@@ -303,7 +360,10 @@ func (s *GRPCHandler) GetArchiveTrace(r *storage_v1.GetTraceRequest, stream stor
return nil
}
-func (s *GRPCHandler) WriteArchiveSpan(ctx context.Context, r *storage_v1.WriteSpanRequest) (*storage_v1.WriteSpanResponse, error) {
+func (s *GRPCHandler) WriteArchiveSpan(
+ ctx context.Context,
+ r *storage_v1.WriteSpanRequest,
+) (*storage_v1.WriteSpanResponse, error) {
writer := s.impl.ArchiveSpanWriter()
if writer == nil {
return nil, status.Error(codes.Unimplemented, "not implemented")
diff --git a/plugin/storage/grpc/shared/grpc_handler_test.go b/plugin/storage/grpc/shared/grpc_handler_test.go
index 23d40c4534f..ad36f552792 100644
--- a/plugin/storage/grpc/shared/grpc_handler_test.go
+++ b/plugin/storage/grpc/shared/grpc_handler_test.go
@@ -105,9 +105,16 @@ func TestGRPCServerGetServices(t *testing.T) {
r.impl.spanReader.On("GetServices", mock.Anything).
Return([]string{"service-a"}, nil)
- s, err := r.server.GetServices(context.Background(), &storage_v1.GetServicesRequest{})
+ s, err := r.server.GetServices(
+ context.Background(),
+ &storage_v1.GetServicesRequest{},
+ )
require.NoError(t, err)
- assert.Equal(t, &storage_v1.GetServicesResponse{Services: []string{"service-a"}}, s)
+ assert.Equal(
+ t,
+ &storage_v1.GetServicesResponse{Services: []string{"service-a"}},
+ s,
+ )
})
}
@@ -124,9 +131,12 @@ func TestGRPCServerGetOperations(t *testing.T) {
spanstore.OperationQueryParameters{ServiceName: "service-a"}).
Return(expOperations, nil)
- resp, err := r.server.GetOperations(context.Background(), &storage_v1.GetOperationsRequest{
- Service: "service-a",
- })
+ resp, err := r.server.GetOperations(
+ context.Background(),
+ &storage_v1.GetOperationsRequest{
+ Service: "service-a",
+ },
+ )
require.NoError(t, err)
assert.Equal(t, len(expOperations), len(resp.Operations))
for i, operation := range resp.Operations {
@@ -177,9 +187,11 @@ func TestGRPCServerFindTraces(t *testing.T) {
traceSteam := new(grpcMocks.SpanReaderPlugin_FindTracesServer)
traceSteam.On("Context").Return(context.Background())
traceSteam.On("Send", &storage_v1.SpansResponseChunk{Spans: mockTracesSpans[:2]}).
- Return(nil).Once()
+ Return(nil).
+ Once()
traceSteam.On("Send", &storage_v1.SpansResponseChunk{Spans: mockTracesSpans[2:]}).
- Return(nil).Once()
+ Return(nil).
+ Once()
var traces []*model.Trace
var traceID model.TraceID
@@ -208,11 +220,20 @@ func TestGRPCServerFindTraceIDs(t *testing.T) {
r.impl.spanReader.On("FindTraceIDs", mock.Anything, &spanstore.TraceQueryParameters{}).
Return([]model.TraceID{mockTraceID, mockTraceID2}, nil)
- s, err := r.server.FindTraceIDs(context.Background(), &storage_v1.FindTraceIDsRequest{
- Query: &storage_v1.TraceQueryParameters{},
- })
+ s, err := r.server.FindTraceIDs(
+ context.Background(),
+ &storage_v1.FindTraceIDsRequest{
+ Query: &storage_v1.TraceQueryParameters{},
+ },
+ )
require.NoError(t, err)
- assert.Equal(t, &storage_v1.FindTraceIDsResponse{TraceIDs: []model.TraceID{mockTraceID, mockTraceID2}}, s)
+ assert.Equal(
+ t,
+ &storage_v1.FindTraceIDsResponse{
+ TraceIDs: []model.TraceID{mockTraceID, mockTraceID2},
+ },
+ s,
+ )
})
}
@@ -221,9 +242,12 @@ func TestGRPCServerWriteSpan(t *testing.T) {
r.impl.spanWriter.On("WriteSpan", context.Background(), &mockTraceSpans[0]).
Return(nil)
- s, err := r.server.WriteSpan(context.Background(), &storage_v1.WriteSpanRequest{
- Span: &mockTraceSpans[0],
- })
+ s, err := r.server.WriteSpan(
+ context.Background(),
+ &storage_v1.WriteSpanRequest{
+ Span: &mockTraceSpans[0],
+ },
+ )
require.NoError(t, err)
assert.Equal(t, &storage_v1.WriteSpanResponse{}, s)
})
@@ -232,12 +256,17 @@ func TestGRPCServerWriteSpan(t *testing.T) {
func TestGRPCServerWriteSpanStream(t *testing.T) {
withGRPCServer(func(r *grpcServerTest) {
stream := new(grpcMocks.StreamingSpanWriterPlugin_WriteSpanStreamServer)
- stream.On("Recv").Return(&storage_v1.WriteSpanRequest{Span: &mockTraceSpans[0]}, nil).Twice().
- On("Recv").Return(nil, io.EOF).Once()
+ stream.On("Recv").
+ Return(&storage_v1.WriteSpanRequest{Span: &mockTraceSpans[0]}, nil).
+ Twice().
+ On("Recv").
+ Return(nil, io.EOF).
+ Once()
stream.On("SendAndClose", &storage_v1.WriteSpanResponse{}).Return(nil)
stream.On("Context").Return(context.Background())
r.impl.streamWriter.On("WriteSpan", context.Background(), &mockTraceSpans[0]).
- Return(fmt.Errorf("some error")).Once().
+ Return(fmt.Errorf("some error")).
+ Once().
On("WriteSpan", context.Background(), &mockTraceSpans[0]).
Return(nil)
@@ -251,11 +280,16 @@ func TestGRPCServerWriteSpanStream(t *testing.T) {
func TestGRPCServerWriteSpanStreamWithGRPCError(t *testing.T) {
withGRPCServer(func(r *grpcServerTest) {
stream := new(grpcMocks.StreamingSpanWriterPlugin_WriteSpanStreamServer)
- stream.On("Recv").Return(&storage_v1.WriteSpanRequest{Span: &mockTraceSpans[0]}, nil).Twice().
- On("Recv").Return(nil, context.DeadlineExceeded).Once()
+ stream.On("Recv").
+ Return(&storage_v1.WriteSpanRequest{Span: &mockTraceSpans[0]}, nil).
+ Twice().
+ On("Recv").
+ Return(nil, context.DeadlineExceeded).
+ Once()
stream.On("SendAndClose", &storage_v1.WriteSpanResponse{}).Return(nil)
stream.On("Context").Return(context.Background())
- r.impl.streamWriter.On("WriteSpan", context.Background(), &mockTraceSpans[0]).Return(nil)
+ r.impl.streamWriter.On("WriteSpan", context.Background(), &mockTraceSpans[0]).
+ Return(nil)
err := r.server.WriteSpanStream(stream)
require.ErrorContains(t, err, context.DeadlineExceeded.Error())
@@ -275,12 +309,19 @@ func TestGRPCServerGetDependencies(t *testing.T) {
r.impl.depsReader.On("GetDependencies", end, lookback).
Return(deps, nil)
- s, err := r.server.GetDependencies(context.Background(), &storage_v1.GetDependenciesRequest{
- StartTime: end.Add(-lookback),
- EndTime: end,
- })
+ s, err := r.server.GetDependencies(
+ context.Background(),
+ &storage_v1.GetDependenciesRequest{
+ StartTime: end.Add(-lookback),
+ EndTime: end,
+ },
+ )
require.NoError(t, err)
- assert.Equal(t, &storage_v1.GetDependenciesResponse{Dependencies: deps}, s)
+ assert.Equal(
+ t,
+ &storage_v1.GetDependenciesResponse{Dependencies: deps},
+ s,
+ )
})
}
@@ -375,9 +416,12 @@ func TestGRPCServerWriteArchiveSpan_NoImpl(t *testing.T) {
withGRPCServer(func(r *grpcServerTest) {
r.server.impl.ArchiveSpanWriter = func() spanstore.Writer { return nil }
- _, err := r.server.WriteArchiveSpan(context.Background(), &storage_v1.WriteSpanRequest{
- Span: &mockTraceSpans[0],
- })
+ _, err := r.server.WriteArchiveSpan(
+ context.Background(),
+ &storage_v1.WriteSpanRequest{
+ Span: &mockTraceSpans[0],
+ },
+ )
assert.Equal(t, codes.Unimplemented, status.Code(err))
})
}
@@ -387,9 +431,12 @@ func TestGRPCServerWriteArchiveSpan(t *testing.T) {
r.impl.archiveWriter.On("WriteSpan", mock.Anything, &mockTraceSpans[0]).
Return(nil)
- s, err := r.server.WriteArchiveSpan(context.Background(), &storage_v1.WriteSpanRequest{
- Span: &mockTraceSpans[0],
- })
+ s, err := r.server.WriteArchiveSpan(
+ context.Background(),
+ &storage_v1.WriteSpanRequest{
+ Span: &mockTraceSpans[0],
+ },
+ )
require.NoError(t, err)
assert.Equal(t, &storage_v1.WriteSpanResponse{}, s)
})
@@ -400,18 +447,32 @@ func TestGRPCServerWriteArchiveSpan_Error(t *testing.T) {
r.impl.archiveWriter.On("WriteSpan", mock.Anything, &mockTraceSpans[0]).
Return(fmt.Errorf("some error"))
- _, err := r.server.WriteArchiveSpan(context.Background(), &storage_v1.WriteSpanRequest{
- Span: &mockTraceSpans[0],
- })
+ _, err := r.server.WriteArchiveSpan(
+ context.Background(),
+ &storage_v1.WriteSpanRequest{
+ Span: &mockTraceSpans[0],
+ },
+ )
require.Error(t, err)
})
}
func TestGRPCServerCapabilities(t *testing.T) {
withGRPCServer(func(r *grpcServerTest) {
- capabilities, err := r.server.Capabilities(context.Background(), &storage_v1.CapabilitiesRequest{})
+ capabilities, err := r.server.Capabilities(
+ context.Background(),
+ &storage_v1.CapabilitiesRequest{},
+ )
require.NoError(t, err)
- assert.Equal(t, &storage_v1.CapabilitiesResponse{ArchiveSpanReader: true, ArchiveSpanWriter: true, StreamingSpanWriter: true}, capabilities)
+ assert.Equal(
+ t,
+ &storage_v1.CapabilitiesResponse{
+ ArchiveSpanReader: true,
+ ArchiveSpanWriter: true,
+ StreamingSpanWriter: true,
+ },
+ capabilities,
+ )
})
}
@@ -420,7 +481,10 @@ func TestGRPCServerCapabilities_NoArchive(t *testing.T) {
r.server.impl.ArchiveSpanReader = func() spanstore.Reader { return nil }
r.server.impl.ArchiveSpanWriter = func() spanstore.Writer { return nil }
- capabilities, err := r.server.Capabilities(context.Background(), &storage_v1.CapabilitiesRequest{})
+ capabilities, err := r.server.Capabilities(
+ context.Background(),
+ &storage_v1.CapabilitiesRequest{},
+ )
require.NoError(t, err)
expected := &storage_v1.CapabilitiesResponse{
ArchiveSpanReader: false,
@@ -435,7 +499,10 @@ func TestGRPCServerCapabilities_NoStreamWriter(t *testing.T) {
withGRPCServer(func(r *grpcServerTest) {
r.server.impl.StreamingSpanWriter = func() spanstore.Writer { return nil }
- capabilities, err := r.server.Capabilities(context.Background(), &storage_v1.CapabilitiesRequest{})
+ capabilities, err := r.server.Capabilities(
+ context.Background(),
+ &storage_v1.CapabilitiesRequest{},
+ )
require.NoError(t, err)
expected := &storage_v1.CapabilitiesResponse{
ArchiveSpanReader: true,
diff --git a/plugin/storage/grpc/shared/streaming_writer.go b/plugin/storage/grpc/shared/streaming_writer.go
index fad5d6c0db1..ede7c66d49e 100644
--- a/plugin/storage/grpc/shared/streaming_writer.go
+++ b/plugin/storage/grpc/shared/streaming_writer.go
@@ -38,16 +38,24 @@ type streamingSpanWriter struct {
closed atomic.Bool
}
-func newStreamingSpanWriter(client storage_v1.StreamingSpanWriterPluginClient) *streamingSpanWriter {
+func newStreamingSpanWriter(
+ client storage_v1.StreamingSpanWriterPluginClient,
+) *streamingSpanWriter {
s := &streamingSpanWriter{
- client: client,
- streamPool: make(chan storage_v1.StreamingSpanWriterPlugin_WriteSpanStreamClient, defaultMaxPoolSize),
+ client: client,
+ streamPool: make(
+ chan storage_v1.StreamingSpanWriterPlugin_WriteSpanStreamClient,
+ defaultMaxPoolSize,
+ ),
}
return s
}
// WriteSpan write span into stream
-func (s *streamingSpanWriter) WriteSpan(ctx context.Context, span *model.Span) error {
+func (s *streamingSpanWriter) WriteSpan(
+ ctx context.Context,
+ span *model.Span,
+) error {
stream, err := s.getStream(ctx)
if err != nil {
return fmt.Errorf("plugin getStream error: %w", err)
@@ -72,7 +80,9 @@ func (s *streamingSpanWriter) Close() error {
return nil
}
-func (s *streamingSpanWriter) getStream(ctx context.Context) (storage_v1.StreamingSpanWriterPlugin_WriteSpanStreamClient, error) {
+func (s *streamingSpanWriter) getStream(
+ ctx context.Context,
+) (storage_v1.StreamingSpanWriterPlugin_WriteSpanStreamClient, error) {
select {
case st, ok := <-s.streamPool:
if ok {
@@ -84,7 +94,9 @@ func (s *streamingSpanWriter) getStream(ctx context.Context) (storage_v1.Streami
}
}
-func (s *streamingSpanWriter) putStream(stream storage_v1.StreamingSpanWriterPlugin_WriteSpanStreamClient) error {
+func (s *streamingSpanWriter) putStream(
+ stream storage_v1.StreamingSpanWriterPlugin_WriteSpanStreamClient,
+) error {
if s.closed.Load() {
_, err := stream.CloseAndRecv()
return err
diff --git a/plugin/storage/grpc/shared/streaming_writer_test.go b/plugin/storage/grpc/shared/streaming_writer_test.go
index 27577594112..68218053265 100644
--- a/plugin/storage/grpc/shared/streaming_writer_test.go
+++ b/plugin/storage/grpc/shared/streaming_writer_test.go
@@ -47,8 +47,11 @@ func TestStreamClientWriteSpan(t *testing.T) {
stream := new(grpcMocks.StreamingSpanWriterPlugin_WriteSpanStreamClient)
stream.On("Send", &storage_v1.WriteSpanRequest{Span: &mockTraceSpans[0]}).Return(io.EOF).Once().
On("Send", &storage_v1.WriteSpanRequest{Span: &mockTraceSpans[0]}).Return(nil).Twice()
- r.streamingSpanWriter.On("WriteSpanStream", mock.Anything).Return(nil, status.Error(codes.DeadlineExceeded, "timeout")).Once().
- On("WriteSpanStream", mock.Anything).Return(stream, nil)
+ r.streamingSpanWriter.On("WriteSpanStream", mock.Anything).
+ Return(nil, status.Error(codes.DeadlineExceeded, "timeout")).
+ Once().
+ On("WriteSpanStream", mock.Anything).
+ Return(stream, nil)
err := r.client.WriteSpan(context.Background(), &mockTraceSpans[0])
require.ErrorContains(t, err, "timeout")
@@ -56,10 +59,14 @@ func TestStreamClientWriteSpan(t *testing.T) {
require.ErrorContains(t, err, "EOF")
err = r.client.WriteSpan(context.Background(), &mockTraceSpans[0])
require.NoError(t, err)
- err = r.client.WriteSpan(context.Background(), &mockTraceSpans[0]) // get stream from pool should succeed
+ err = r.client.WriteSpan(
+ context.Background(),
+ &mockTraceSpans[0],
+ ) // get stream from pool should succeed
require.NoError(t, err)
- stream.On("CloseAndRecv").Return(nil, status.Error(codes.DeadlineExceeded, "timeout"))
+ stream.On("CloseAndRecv").
+ Return(nil, status.Error(codes.DeadlineExceeded, "timeout"))
for i := 0; i < defaultMaxPoolSize; i++ { // putStream when pool is full should call CloseAndRecv
err = r.client.putStream(stream)
if i == defaultMaxPoolSize-1 {
@@ -74,7 +81,9 @@ func TestStreamClientWriteSpan(t *testing.T) {
func TestStreamClientClose(t *testing.T) {
withStreamingWriterGRPCClient(func(r *streamingSpanWriterTest) {
stream := new(grpcMocks.StreamingSpanWriterPlugin_WriteSpanStreamClient)
- stream.On("CloseAndRecv").Return(&storage_v1.WriteSpanResponse{}, nil).Once()
+ stream.On("CloseAndRecv").
+ Return(&storage_v1.WriteSpanResponse{}, nil).
+ Once()
r.client.streamPool <- stream
err := r.client.Close()
@@ -82,7 +91,10 @@ func TestStreamClientClose(t *testing.T) {
err = r.client.Close()
require.ErrorContains(t, err, "already closed")
- err = r.client.WriteSpan(context.Background(), &mockTraceSpans[0]) // getStream from pool should fail when closed
+ err = r.client.WriteSpan(
+ context.Background(),
+ &mockTraceSpans[0],
+ ) // getStream from pool should fail when closed
require.ErrorContains(t, err, "closed")
})
}
@@ -90,12 +102,18 @@ func TestStreamClientClose(t *testing.T) {
func TestStreamClientCloseFail(t *testing.T) {
withStreamingWriterGRPCClient(func(r *streamingSpanWriterTest) {
stream := new(grpcMocks.StreamingSpanWriterPlugin_WriteSpanStreamClient)
- stream.On("CloseAndRecv").Return(nil, status.Error(codes.DeadlineExceeded, "timeout")).Twice()
+ stream.On("CloseAndRecv").
+ Return(nil, status.Error(codes.DeadlineExceeded, "timeout")).
+ Twice()
r.client.streamPool <- stream
err := r.client.Close()
require.ErrorContains(t, err, "timeout")
err = r.client.putStream(stream)
- require.ErrorContains(t, err, "timeout") // putStream after closed should call CloseAndRecv
+ require.ErrorContains(
+ t,
+ err,
+ "timeout",
+ ) // putStream after closed should call CloseAndRecv
})
}
diff --git a/plugin/storage/integration/cassandra_test.go b/plugin/storage/integration/cassandra_test.go
index f61af7d1f84..cc496deb71a 100644
--- a/plugin/storage/integration/cassandra_test.go
+++ b/plugin/storage/integration/cassandra_test.go
@@ -50,7 +50,10 @@ func (s *CassandraStorageIntegration) cleanUp(t *testing.T) {
require.NoError(t, s.factory.Purge(context.Background()))
}
-func (*CassandraStorageIntegration) initializeCassandraFactory(t *testing.T, flags []string) *cassandra.Factory {
+func (*CassandraStorageIntegration) initializeCassandraFactory(
+ t *testing.T,
+ flags []string,
+) *cassandra.Factory {
logger := zaptest.NewLogger(t, zaptest.WrapOptions(zap.AddCaller()))
f := cassandra.NewFactory()
v, command := config.Viperize(f.AddFlags)
@@ -85,7 +88,10 @@ func (s *CassandraStorageIntegration) initializeCassandra(t *testing.T) {
})
}
-func (s *CassandraStorageIntegration) initializeDependencyReaderAndWriter(t *testing.T, f *cassandra.Factory) {
+func (s *CassandraStorageIntegration) initializeDependencyReaderAndWriter(
+ t *testing.T,
+ f *cassandra.Factory,
+) {
var (
err error
ok bool
diff --git a/plugin/storage/integration/elasticsearch_test.go b/plugin/storage/integration/elasticsearch_test.go
index 3f36334f7f9..524502bc095 100644
--- a/plugin/storage/integration/elasticsearch_test.go
+++ b/plugin/storage/integration/elasticsearch_test.go
@@ -75,14 +75,18 @@ func (s *ESStorageIntegration) getVersion() (uint, error) {
}
// OpenSearch is based on ES 7.x
if strings.Contains(pingResult.TagLine, "OpenSearch") {
- if pingResult.Version.Number[0] == '1' || pingResult.Version.Number[0] == '2' {
+ if pingResult.Version.Number[0] == '1' ||
+ pingResult.Version.Number[0] == '2' {
esVersion = 7
}
}
return uint(esVersion), nil
}
-func (s *ESStorageIntegration) initializeES(t *testing.T, allTagsAsFields bool) {
+func (s *ESStorageIntegration) initializeES(
+ t *testing.T,
+ allTagsAsFields bool,
+) {
rawClient, err := elastic.NewClient(
elastic.SetURL(queryURL),
elastic.SetSniff(false))
@@ -107,7 +111,10 @@ func (s *ESStorageIntegration) esCleanUp(t *testing.T) {
require.NoError(t, s.factory.Purge(context.Background()))
}
-func (*ESStorageIntegration) initializeESFactory(t *testing.T, allTagsAsFields bool) *es.Factory {
+func (*ESStorageIntegration) initializeESFactory(
+ t *testing.T,
+ allTagsAsFields bool,
+) *es.Factory {
logger := zaptest.NewLogger(t, zaptest.WrapOptions(zap.AddCaller()))
f := es.NewFactory()
v, command := config.Viperize(f.AddFlags)
@@ -134,7 +141,10 @@ func (*ESStorageIntegration) initializeESFactory(t *testing.T, allTagsAsFields b
return f
}
-func (s *ESStorageIntegration) initSpanstore(t *testing.T, allTagsAsFields bool) {
+func (s *ESStorageIntegration) initSpanstore(
+ t *testing.T,
+ allTagsAsFields bool,
+) {
f := s.initializeESFactory(t, allTagsAsFields)
s.factory = f
var err error
@@ -172,7 +182,10 @@ func testElasticsearchStorage(t *testing.T, allTagsAsFields bool) {
}
s := &ESStorageIntegration{
StorageIntegration: StorageIntegration{
- Fixtures: LoadAndParseQueryTestCases(t, "fixtures/queries_es.json"),
+ Fixtures: LoadAndParseQueryTestCases(
+ t,
+ "fixtures/queries_es.json",
+ ),
SkipArchiveTest: false,
// TODO: remove this flag after ES supports returning spanKind
// Issue https://github.com/jaegertracing/jaeger/issues/1923
@@ -202,10 +215,12 @@ func TestElasticsearchStorage_IndexTemplates(t *testing.T) {
require.NoError(t, err)
// TODO abstract this into pkg/es/client.IndexManagementLifecycleAPI
if esVersion == 7 {
- serviceTemplateExists, err := s.client.IndexTemplateExists(indexPrefix + "-jaeger-service").Do(context.Background())
+ serviceTemplateExists, err := s.client.IndexTemplateExists(indexPrefix + "-jaeger-service").
+ Do(context.Background())
require.NoError(t, err)
assert.True(t, serviceTemplateExists)
- spanTemplateExists, err := s.client.IndexTemplateExists(indexPrefix + "-jaeger-span").Do(context.Background())
+ spanTemplateExists, err := s.client.IndexTemplateExists(indexPrefix + "-jaeger-span").
+ Do(context.Background())
require.NoError(t, err)
assert.True(t, spanTemplateExists)
} else {
@@ -219,7 +234,10 @@ func TestElasticsearchStorage_IndexTemplates(t *testing.T) {
s.cleanESIndexTemplates(t, indexPrefix)
}
-func (s *ESStorageIntegration) cleanESIndexTemplates(t *testing.T, prefix string) error {
+func (s *ESStorageIntegration) cleanESIndexTemplates(
+ t *testing.T,
+ prefix string,
+) error {
version, err := s.getVersion()
require.NoError(t, err)
if version > 7 {
@@ -227,11 +245,17 @@ func (s *ESStorageIntegration) cleanESIndexTemplates(t *testing.T, prefix string
if prefix != "" {
prefixWithSeparator += "-"
}
- _, err := s.v8Client.Indices.DeleteIndexTemplate(prefixWithSeparator + spanTemplateName)
+ _, err := s.v8Client.Indices.DeleteIndexTemplate(
+ prefixWithSeparator + spanTemplateName,
+ )
require.NoError(t, err)
- _, err = s.v8Client.Indices.DeleteIndexTemplate(prefixWithSeparator + serviceTemplateName)
+ _, err = s.v8Client.Indices.DeleteIndexTemplate(
+ prefixWithSeparator + serviceTemplateName,
+ )
require.NoError(t, err)
- _, err = s.v8Client.Indices.DeleteIndexTemplate(prefixWithSeparator + dependenciesTemplateName)
+ _, err = s.v8Client.Indices.DeleteIndexTemplate(
+ prefixWithSeparator + dependenciesTemplateName,
+ )
require.NoError(t, err)
} else {
_, err := s.client.IndexDeleteTemplate("*").Do(context.Background())
diff --git a/plugin/storage/integration/es_index_cleaner_test.go b/plugin/storage/integration/es_index_cleaner_test.go
index d9bc35bd67d..4f6f683f8af 100644
--- a/plugin/storage/integration/es_index_cleaner_test.go
+++ b/plugin/storage/integration/es_index_cleaner_test.go
@@ -138,12 +138,27 @@ func TestIndexCleaner(t *testing.T) {
runIndexCleanerTest(t, client, v8Client, "", test.expectedIndices, test.envVars, test.adaptiveSampling)
})
t.Run(fmt.Sprintf("%s_prefix, %s", test.name, test.envVars), func(t *testing.T) {
- runIndexCleanerTest(t, client, v8Client, indexPrefix, test.expectedIndices, append(test.envVars, "INDEX_PREFIX="+indexPrefix), test.adaptiveSampling)
+ runIndexCleanerTest(
+ t,
+ client,
+ v8Client,
+ indexPrefix,
+ test.expectedIndices,
+ append(test.envVars, "INDEX_PREFIX="+indexPrefix),
+ test.adaptiveSampling,
+ )
})
}
}
-func runIndexCleanerTest(t *testing.T, client *elastic.Client, v8Client *elasticsearch8.Client, prefix string, expectedIndices, envVars []string, adaptiveSampling bool) {
+func runIndexCleanerTest(
+ t *testing.T,
+ client *elastic.Client,
+ v8Client *elasticsearch8.Client,
+ prefix string,
+ expectedIndices, envVars []string,
+ adaptiveSampling bool,
+) {
// make sure ES is clean
_, err := client.DeleteIndex("*").Do(context.Background())
require.NoError(t, err)
@@ -161,10 +176,19 @@ func runIndexCleanerTest(t *testing.T, client *elastic.Client, v8Client *elastic
for _, index := range expectedIndices {
expected = append(expected, prefix+index)
}
- assert.ElementsMatch(t, indices, expected, fmt.Sprintf("indices found: %v, expected: %v", indices, expected))
+ assert.ElementsMatch(
+ t,
+ indices,
+ expected,
+ fmt.Sprintf("indices found: %v, expected: %v", indices, expected),
+ )
}
-func createAllIndices(client *elastic.Client, prefix string, adaptiveSampling bool) error {
+func createAllIndices(
+ client *elastic.Client,
+ prefix string,
+ adaptiveSampling bool,
+) error {
prefixWithSeparator := prefix
if prefix != "" {
prefixWithSeparator += "-"
@@ -181,20 +205,36 @@ func createAllIndices(client *elastic.Client, prefix string, adaptiveSampling bo
return err
}
// create rollover archive index and roll alias to the new index
- err = runEsRollover("init", []string{"ARCHIVE=true", "INDEX_PREFIX=" + prefix}, adaptiveSampling)
+ err = runEsRollover(
+ "init",
+ []string{"ARCHIVE=true", "INDEX_PREFIX=" + prefix},
+ adaptiveSampling,
+ )
if err != nil {
return err
}
- err = runEsRollover("rollover", []string{"ARCHIVE=true", "INDEX_PREFIX=" + prefix, rolloverNowEnvVar}, adaptiveSampling)
+ err = runEsRollover(
+ "rollover",
+ []string{"ARCHIVE=true", "INDEX_PREFIX=" + prefix, rolloverNowEnvVar},
+ adaptiveSampling,
+ )
if err != nil {
return err
}
// create rollover main indices and roll over to the new index
- err = runEsRollover("init", []string{"ARCHIVE=false", "INDEX_PREFIX=" + prefix}, adaptiveSampling)
+ err = runEsRollover(
+ "init",
+ []string{"ARCHIVE=false", "INDEX_PREFIX=" + prefix},
+ adaptiveSampling,
+ )
if err != nil {
return err
}
- err = runEsRollover("rollover", []string{"ARCHIVE=false", "INDEX_PREFIX=" + prefix, rolloverNowEnvVar}, adaptiveSampling)
+ err = runEsRollover(
+ "rollover",
+ []string{"ARCHIVE=false", "INDEX_PREFIX=" + prefix, rolloverNowEnvVar},
+ adaptiveSampling,
+ )
if err != nil {
return err
}
@@ -215,7 +255,13 @@ func runEsCleaner(days int, envs []string) error {
for _, e := range envs {
dockerEnv += fmt.Sprintf(" -e %s", e)
}
- args := fmt.Sprintf("docker run %s --rm --net=host %s %d http://%s", dockerEnv, indexCleanerImage, days, queryHostPort)
+ args := fmt.Sprintf(
+ "docker run %s --rm --net=host %s %d http://%s",
+ dockerEnv,
+ indexCleanerImage,
+ days,
+ queryHostPort,
+ )
cmd := exec.Command("/bin/sh", "-c", args)
out, err := cmd.CombinedOutput()
fmt.Println(string(out))
@@ -227,7 +273,14 @@ func runEsRollover(action string, envs []string, adaptiveSampling bool) error {
for _, e := range envs {
dockerEnv += fmt.Sprintf(" -e %s", e)
}
- args := fmt.Sprintf("docker run %s --rm --net=host %s %s --adaptive-sampling=%t http://%s", dockerEnv, rolloverImage, action, adaptiveSampling, queryHostPort)
+ args := fmt.Sprintf(
+ "docker run %s --rm --net=host %s %s --adaptive-sampling=%t http://%s",
+ dockerEnv,
+ rolloverImage,
+ action,
+ adaptiveSampling,
+ queryHostPort,
+ )
cmd := exec.Command("/bin/sh", "-c", args)
out, err := cmd.CombinedOutput()
fmt.Println(string(out))
@@ -247,7 +300,12 @@ func createESV8Client() (*elasticsearch8.Client, error) {
})
}
-func cleanESIndexTemplates(t *testing.T, client *elastic.Client, v8Client *elasticsearch8.Client, prefix string) {
+func cleanESIndexTemplates(
+ t *testing.T,
+ client *elastic.Client,
+ v8Client *elasticsearch8.Client,
+ prefix string,
+) {
s := &ESStorageIntegration{
client: client,
v8Client: v8Client,
diff --git a/plugin/storage/integration/es_index_rollover_test.go b/plugin/storage/integration/es_index_rollover_test.go
index 4effa952363..7bccc39cb39 100644
--- a/plugin/storage/integration/es_index_rollover_test.go
+++ b/plugin/storage/integration/es_index_rollover_test.go
@@ -73,20 +73,55 @@ func runCreateIndicesWithILM(t *testing.T, ilmPolicyName string) {
}
if esVersion >= 7 {
- expectedIndices := []string{"jaeger-span-000001", "jaeger-service-000001", "jaeger-dependencies-000001"}
+ expectedIndices := []string{
+ "jaeger-span-000001",
+ "jaeger-service-000001",
+ "jaeger-dependencies-000001",
+ }
t.Run("NoPrefix", func(t *testing.T) {
- runIndexRolloverWithILMTest(t, client, "", expectedIndices, envVars, ilmPolicyName, false)
+ runIndexRolloverWithILMTest(
+ t,
+ client,
+ "",
+ expectedIndices,
+ envVars,
+ ilmPolicyName,
+ false,
+ )
})
t.Run("WithPrefix", func(t *testing.T) {
- runIndexRolloverWithILMTest(t, client, indexPrefix, expectedIndices, append(envVars, "INDEX_PREFIX="+indexPrefix), ilmPolicyName, false)
+ runIndexRolloverWithILMTest(
+ t,
+ client,
+ indexPrefix,
+ expectedIndices,
+ append(envVars, "INDEX_PREFIX="+indexPrefix),
+ ilmPolicyName,
+ false,
+ )
})
t.Run("WithAdaptiveSampling", func(t *testing.T) {
- runIndexRolloverWithILMTest(t, client, indexPrefix, expectedIndices, append(envVars, "INDEX_PREFIX="+indexPrefix), ilmPolicyName, true)
+ runIndexRolloverWithILMTest(
+ t,
+ client,
+ indexPrefix,
+ expectedIndices,
+ append(envVars, "INDEX_PREFIX="+indexPrefix),
+ ilmPolicyName,
+ true,
+ )
})
}
}
-func runIndexRolloverWithILMTest(t *testing.T, client *elastic.Client, prefix string, expectedIndices, envVars []string, ilmPolicyName string, adaptiveSampling bool) {
+func runIndexRolloverWithILMTest(
+ t *testing.T,
+ client *elastic.Client,
+ prefix string,
+ expectedIndices, envVars []string,
+ ilmPolicyName string,
+ adaptiveSampling bool,
+) {
writeAliases := []string{"jaeger-service-write", "jaeger-span-write", "jaeger-dependencies-write"}
if adaptiveSampling {
writeAliases = append(writeAliases, "jaeger-sampling-write")
@@ -121,17 +156,32 @@ func runIndexRolloverWithILMTest(t *testing.T, client *elastic.Client, prefix st
require.NoError(t, err)
// Get ILM Policy Attached
- settings, err := client.IndexGetSettings(expected...).FlatSettings(true).Do(context.Background())
+ settings, err := client.IndexGetSettings(expected...).
+ FlatSettings(true).
+ Do(context.Background())
require.NoError(t, err)
// Check ILM Policy is attached and Get rollover alias attached
for _, v := range settings {
assert.Equal(t, ilmPolicyName, v.Settings["index.lifecycle.name"])
- actualWriteAliases = append(actualWriteAliases, v.Settings["index.lifecycle.rollover_alias"].(string))
+ actualWriteAliases = append(
+ actualWriteAliases,
+ v.Settings["index.lifecycle.rollover_alias"].(string),
+ )
}
// Check indices created
- assert.ElementsMatch(t, indices, expected, fmt.Sprintf("indices found: %v, expected: %v", indices, expected))
+ assert.ElementsMatch(
+ t,
+ indices,
+ expected,
+ fmt.Sprintf("indices found: %v, expected: %v", indices, expected),
+ )
// Check rollover alias is write alias
- assert.ElementsMatch(t, actualWriteAliases, expectedWriteAliases, fmt.Sprintf("aliases found: %v, expected: %v", actualWriteAliases, expectedWriteAliases))
+ assert.ElementsMatch(
+ t,
+ actualWriteAliases,
+ expectedWriteAliases,
+ fmt.Sprintf("aliases found: %v, expected: %v", actualWriteAliases, expectedWriteAliases),
+ )
}
func getVersion(client *elastic.Client) (uint, error) {
@@ -147,7 +197,10 @@ func getVersion(client *elastic.Client) (uint, error) {
}
func createILMPolicy(client *elastic.Client, policyName string) error {
- _, err := client.XPackIlmPutLifecycle().Policy(policyName).BodyString(`{"policy": {"phases": {"hot": {"min_age": "0ms","actions": {"rollover": {"max_age": "1d"},"set_priority": {"priority": 100}}}}}}`).Do(context.Background())
+ _, err := client.XPackIlmPutLifecycle().
+ Policy(policyName).
+ BodyString(`{"policy": {"phases": {"hot": {"min_age": "0ms","actions": {"rollover": {"max_age": "1d"},"set_priority": {"priority": 100}}}}}}`).
+ Do(context.Background())
return err
}
@@ -157,7 +210,9 @@ func cleanES(t *testing.T, client *elastic.Client, policyName string) {
esVersion, err := getVersion(client)
require.NoError(t, err)
if esVersion >= 7 {
- _, err = client.XPackIlmDeleteLifecycle().Policy(policyName).Do(context.Background())
+ _, err = client.XPackIlmDeleteLifecycle().
+ Policy(policyName).
+ Do(context.Background())
if err != nil && !elastic.IsNotFound(err) {
assert.Fail(t, "Not able to clean up ILM Policy")
}
diff --git a/plugin/storage/integration/integration.go b/plugin/storage/integration/integration.go
index cb61759dc47..6ccd9b717ee 100644
--- a/plugin/storage/integration/integration.go
+++ b/plugin/storage/integration/integration.go
@@ -106,7 +106,10 @@ func SkipUnlessEnv(t *testing.T, storage ...string) {
return
}
}
- t.Skipf("This test requires environment variable STORAGE=%s", strings.Join(storage, "|"))
+ t.Skipf(
+ "This test requires environment variable STORAGE=%s",
+ strings.Join(storage, "|"),
+ )
}
var CassandraSkippedTests = []string{
@@ -132,13 +135,20 @@ func (s *StorageIntegration) skipIfNeeded(t *testing.T) {
}
}
-func (*StorageIntegration) waitForCondition(t *testing.T, predicate func(t *testing.T) bool) bool {
+func (*StorageIntegration) waitForCondition(
+ t *testing.T,
+ predicate func(t *testing.T) bool,
+) bool {
const iterations = 100 // Will wait at most 100 seconds.
for i := 0; i < iterations; i++ {
if predicate(t) {
return true
}
- t.Logf("Waiting for storage backend to update documents, iteration %d out of %d", i+1, iterations)
+ t.Logf(
+ "Waiting for storage backend to update documents, iteration %d out of %d",
+ i+1,
+ iterations,
+ )
time.Sleep(time.Second)
}
return predicate(t)
@@ -148,7 +158,11 @@ func (s *StorageIntegration) testGetServices(t *testing.T) {
s.skipIfNeeded(t)
defer s.cleanUp(t)
- expected := []string{"example-service-1", "example-service-2", "example-service-3"}
+ expected := []string{
+ "example-service-1",
+ "example-service-2",
+ "example-service-3",
+ }
s.loadParseAndWriteExampleTrace(t)
var actual []string
@@ -169,20 +183,27 @@ func (s *StorageIntegration) testGetServices(t *testing.T) {
func (s *StorageIntegration) testArchiveTrace(t *testing.T) {
s.skipIfNeeded(t)
if s.SkipArchiveTest {
- t.Skip("Skipping ArchiveTrace test because archive reader or writer is nil")
+ t.Skip(
+ "Skipping ArchiveTrace test because archive reader or writer is nil",
+ )
}
defer s.cleanUp(t)
tID := model.NewTraceID(uint64(11), uint64(22))
expected := &model.Span{
OperationName: "archive_span",
- StartTime: time.Now().Add(-time.Hour * 72 * 5).Truncate(time.Microsecond),
- TraceID: tID,
- SpanID: model.NewSpanID(55),
- References: []model.SpanRef{},
- Process: model.NewProcess("archived_service", model.KeyValues{}),
+ StartTime: time.Now().
+ Add(-time.Hour * 72 * 5).
+ Truncate(time.Microsecond),
+ TraceID: tID,
+ SpanID: model.NewSpanID(55),
+ References: []model.SpanRef{},
+ Process: model.NewProcess("archived_service", model.KeyValues{}),
}
- require.NoError(t, s.ArchiveSpanWriter.WriteSpan(context.Background(), expected))
+ require.NoError(
+ t,
+ s.ArchiveSpanWriter.WriteSpan(context.Background(), expected),
+ )
var actual *model.Trace
found := s.waitForCondition(t, func(t *testing.T) bool {
@@ -205,7 +226,10 @@ func (s *StorageIntegration) testGetLargeSpan(t *testing.T) {
var actual *model.Trace
found := s.waitForCondition(t, func(t *testing.T) bool {
var err error
- actual, err = s.SpanReader.GetTrace(context.Background(), expectedTraceID)
+ actual, err = s.SpanReader.GetTrace(
+ context.Background(),
+ expectedTraceID,
+ )
return err == nil && len(actual.Spans) >= len(expected.Spans)
})
if !assert.True(t, found) {
@@ -236,8 +260,12 @@ func (s *StorageIntegration) testGetOperations(t *testing.T) {
var actual []spanstore.Operation
found := s.waitForCondition(t, func(t *testing.T) bool {
var err error
- actual, err = s.SpanReader.GetOperations(context.Background(),
- spanstore.OperationQueryParameters{ServiceName: "example-service-1"})
+ actual, err = s.SpanReader.GetOperations(
+ context.Background(),
+ spanstore.OperationQueryParameters{
+ ServiceName: "example-service-1",
+ },
+ )
require.NoError(t, err)
sort.Slice(actual, func(i, j int) bool {
return actual[i].Name < actual[j].Name
@@ -261,7 +289,10 @@ func (s *StorageIntegration) testGetTrace(t *testing.T) {
var actual *model.Trace
found := s.waitForCondition(t, func(t *testing.T) bool {
var err error
- actual, err = s.SpanReader.GetTrace(context.Background(), expectedTraceID)
+ actual, err = s.SpanReader.GetTrace(
+ context.Background(),
+ expectedTraceID,
+ )
if err != nil {
t.Log(err)
}
@@ -284,7 +315,9 @@ func (s *StorageIntegration) testFindTraces(t *testing.T) {
defer s.cleanUp(t)
// Note: all cases include ServiceName + StartTime range
- s.Fixtures = append(s.Fixtures, LoadAndParseQueryTestCases(t, "fixtures/queries.json")...)
+ s.Fixtures = append(
+ s.Fixtures,
+ LoadAndParseQueryTestCases(t, "fixtures/queries.json")...)
// Each query test case only specifies matching traces, but does not provide counterexamples.
// To improve coverage we get all possible traces and store all of them before running queries.
@@ -313,18 +346,30 @@ func (s *StorageIntegration) testFindTraces(t *testing.T) {
}
}
-func (s *StorageIntegration) findTracesByQuery(t *testing.T, query *spanstore.TraceQueryParameters, expected []*model.Trace) []*model.Trace {
+func (s *StorageIntegration) findTracesByQuery(
+ t *testing.T,
+ query *spanstore.TraceQueryParameters,
+ expected []*model.Trace,
+) []*model.Trace {
var traces []*model.Trace
found := s.waitForCondition(t, func(t *testing.T) bool {
var err error
traces, err = s.SpanReader.FindTraces(context.Background(), query)
require.NoError(t, err)
if len(expected) != len(traces) {
- t.Logf("Expecting certain number of traces: expected: %d, actual: %d", len(expected), len(traces))
+ t.Logf(
+ "Expecting certain number of traces: expected: %d, actual: %d",
+ len(expected),
+ len(traces),
+ )
return false
}
if spanCount(expected) != spanCount(traces) {
- t.Logf("Excepting certain number of spans: expected: %d, actual: %d", spanCount(expected), spanCount(traces))
+ t.Logf(
+ "Excepting certain number of spans: expected: %d, actual: %d",
+ spanCount(expected),
+ spanCount(traces),
+ )
return false
}
return true
@@ -334,20 +379,32 @@ func (s *StorageIntegration) findTracesByQuery(t *testing.T, query *spanstore.Tr
}
func (s *StorageIntegration) writeTrace(t *testing.T, trace *model.Trace) {
- t.Logf("%-23s Writing trace with %d spans", time.Now().Format("2006-01-02 15:04:05.999"), len(trace.Spans))
+ t.Logf(
+ "%-23s Writing trace with %d spans",
+ time.Now().Format("2006-01-02 15:04:05.999"),
+ len(trace.Spans),
+ )
for _, span := range trace.Spans {
err := s.SpanWriter.WriteSpan(context.Background(), span)
- require.NoError(t, err, "Not expecting error when writing trace to storage")
+ require.NoError(
+ t,
+ err,
+ "Not expecting error when writing trace to storage",
+ )
}
}
-func (s *StorageIntegration) loadParseAndWriteExampleTrace(t *testing.T) *model.Trace {
+func (s *StorageIntegration) loadParseAndWriteExampleTrace(
+ t *testing.T,
+) *model.Trace {
trace := s.getTraceFixture(t, "example_trace")
s.writeTrace(t, trace)
return trace
}
-func (s *StorageIntegration) loadParseAndWriteLargeTrace(t *testing.T) *model.Trace {
+func (s *StorageIntegration) loadParseAndWriteLargeTrace(
+ t *testing.T,
+) *model.Trace {
trace := s.getTraceFixture(t, "example_trace")
span := trace.Spans[0]
spns := make([]*model.Span, 1, 10008)
@@ -364,7 +421,10 @@ func (s *StorageIntegration) loadParseAndWriteLargeTrace(t *testing.T) *model.Tr
return trace
}
-func (*StorageIntegration) getTraceFixture(t *testing.T, fixture string) *model.Trace {
+func (*StorageIntegration) getTraceFixture(
+ t *testing.T,
+ fixture string,
+) *model.Trace {
fileName := fmt.Sprintf("fixtures/traces/%s.json", fixture)
return getTraceFixtureExact(t, fileName)
}
@@ -380,11 +440,19 @@ func loadAndParseJSONPB(t *testing.T, path string, object proto.Message) {
inStr, err := fixtures.ReadFile(path)
require.NoError(t, err, "Not expecting error when loading fixture %s", path)
err = jsonpb.Unmarshal(bytes.NewReader(correctTime(inStr)), object)
- require.NoError(t, err, "Not expecting error when unmarshaling fixture %s", path)
+ require.NoError(
+ t,
+ err,
+ "Not expecting error when unmarshaling fixture %s",
+ path,
+ )
}
// LoadAndParseQueryTestCases loads and parses query test cases
-func LoadAndParseQueryTestCases(t *testing.T, queriesFile string) []*QueryFixtures {
+func LoadAndParseQueryTestCases(
+ t *testing.T,
+ queriesFile string,
+) []*QueryFixtures {
var queries []*QueryFixtures
loadAndParseJSON(t, queriesFile, &queries)
return queries
@@ -395,7 +463,12 @@ func loadAndParseJSON(t *testing.T, path string, object any) {
inStr, err := fixtures.ReadFile(path)
require.NoError(t, err, "Not expecting error when loading fixture %s", path)
err = json.Unmarshal(correctTime(inStr), object)
- require.NoError(t, err, "Not expecting error when unmarshaling fixture %s", path)
+ require.NoError(
+ t,
+ err,
+ "Not expecting error when unmarshaling fixture %s",
+ path,
+ )
}
// required, because we want to only query on recent traces, so we replace all the dates with recent dates.
@@ -421,7 +494,9 @@ func spanCount(traces []*model.Trace) int {
func (s *StorageIntegration) testGetDependencies(t *testing.T) {
if s.DependencyReader == nil || s.DependencyWriter == nil {
- t.Skipf("Skipping GetDependencies test because dependency reader or writer is nil")
+ t.Skipf(
+ "Skipping GetDependencies test because dependency reader or writer is nil",
+ )
return
}
@@ -448,12 +523,19 @@ func (s *StorageIntegration) testGetDependencies(t *testing.T) {
},
}
- require.NoError(t, s.DependencyWriter.WriteDependencies(time.Now(), expected))
+ require.NoError(
+ t,
+ s.DependencyWriter.WriteDependencies(time.Now(), expected),
+ )
var actual []model.DependencyLink
found := s.waitForCondition(t, func(t *testing.T) bool {
var err error
- actual, err = s.DependencyReader.GetDependencies(context.Background(), time.Now(), 5*time.Minute)
+ actual, err = s.DependencyReader.GetDependencies(
+ context.Background(),
+ time.Now(),
+ 5*time.Minute,
+ )
require.NoError(t, err)
sort.Slice(actual, func(i, j int) bool {
return actual[i].Parent < actual[j].Parent
@@ -484,7 +566,10 @@ func (s *StorageIntegration) testGetThroughput(t *testing.T) {
var actual []*samplemodel.Throughput
_ = s.waitForCondition(t, func(t *testing.T) bool {
var err error
- actual, err = s.SamplingStore.GetThroughput(start, start.Add(time.Second*time.Duration(10)))
+ actual, err = s.SamplingStore.GetThroughput(
+ start,
+ start.Add(time.Second*time.Duration(10)),
+ )
require.NoError(t, err)
return assert.ObjectsAreEqualValues(expected, len(actual))
})
@@ -494,15 +579,27 @@ func (s *StorageIntegration) testGetThroughput(t *testing.T) {
func (s *StorageIntegration) testGetLatestProbability(t *testing.T) {
s.skipIfNeeded(t)
if s.SamplingStore == nil {
- t.Skip("Skipping GetLatestProbability test because sampling store is nil")
+ t.Skip(
+ "Skipping GetLatestProbability test because sampling store is nil",
+ )
return
}
defer s.cleanUp(t)
- s.SamplingStore.InsertProbabilitiesAndQPS("newhostname1", samplemodel.ServiceOperationProbabilities{"new-srv3": {"op": 0.123}}, samplemodel.ServiceOperationQPS{"new-srv2": {"op": 11}})
- s.SamplingStore.InsertProbabilitiesAndQPS("dell11eg843d", samplemodel.ServiceOperationProbabilities{"new-srv": {"op": 0.1}}, samplemodel.ServiceOperationQPS{"new-srv": {"op": 4}})
-
- expected := samplemodel.ServiceOperationProbabilities{"new-srv": {"op": 0.1}}
+ s.SamplingStore.InsertProbabilitiesAndQPS(
+ "newhostname1",
+ samplemodel.ServiceOperationProbabilities{"new-srv3": {"op": 0.123}},
+ samplemodel.ServiceOperationQPS{"new-srv2": {"op": 11}},
+ )
+ s.SamplingStore.InsertProbabilitiesAndQPS(
+ "dell11eg843d",
+ samplemodel.ServiceOperationProbabilities{"new-srv": {"op": 0.1}},
+ samplemodel.ServiceOperationQPS{"new-srv": {"op": 4}},
+ )
+
+ expected := samplemodel.ServiceOperationProbabilities{
+ "new-srv": {"op": 0.1},
+ }
var actual samplemodel.ServiceOperationProbabilities
found := s.waitForCondition(t, func(t *testing.T) bool {
var err error
diff --git a/plugin/storage/integration/kafka_test.go b/plugin/storage/integration/kafka_test.go
index 77d4cdfa79c..804e0a53f21 100644
--- a/plugin/storage/integration/kafka_test.go
+++ b/plugin/storage/integration/kafka_test.go
@@ -48,7 +48,10 @@ func (s *KafkaIntegrationTestSuite) initialize(t *testing.T) {
const groupID = "kafka-integration-test"
const clientID = "kafka-integration-test"
// A new topic is generated per execution to avoid data overlap
- topic := "jaeger-kafka-integration-test-" + strconv.FormatInt(time.Now().UnixNano(), 10)
+ topic := "jaeger-kafka-integration-test-" + strconv.FormatInt(
+ time.Now().UnixNano(),
+ 10,
+ )
f := kafka.NewFactory()
v, command := config.Viperize(f.AddFlags)
@@ -91,7 +94,12 @@ func (s *KafkaIntegrationTestSuite) initialize(t *testing.T) {
}
options.InitFromViper(v)
traceStore := memory.NewStore()
- spanConsumer, err := builder.CreateConsumer(logger, metrics.NullFactory, traceStore, options)
+ spanConsumer, err := builder.CreateConsumer(
+ logger,
+ metrics.NullFactory,
+ traceStore,
+ options,
+ )
require.NoError(t, err)
spanConsumer.Start()
@@ -106,7 +114,10 @@ type ingester struct {
traceStore *memory.Store
}
-func (r *ingester) GetTrace(ctx context.Context, traceID model.TraceID) (*model.Trace, error) {
+func (r *ingester) GetTrace(
+ ctx context.Context,
+ traceID model.TraceID,
+) (*model.Trace, error) {
return r.traceStore.GetTrace(ctx, traceID)
}
@@ -121,11 +132,17 @@ func (*ingester) GetOperations(
return nil, nil
}
-func (*ingester) FindTraces(ctx context.Context, query *spanstore.TraceQueryParameters) ([]*model.Trace, error) {
+func (*ingester) FindTraces(
+ ctx context.Context,
+ query *spanstore.TraceQueryParameters,
+) ([]*model.Trace, error) {
return nil, nil
}
-func (*ingester) FindTraceIDs(ctx context.Context, query *spanstore.TraceQueryParameters) ([]model.TraceID, error) {
+func (*ingester) FindTraceIDs(
+ ctx context.Context,
+ query *spanstore.TraceQueryParameters,
+) ([]model.TraceID, error) {
return nil, nil
}
diff --git a/plugin/storage/integration/remote_memory_storage.go b/plugin/storage/integration/remote_memory_storage.go
index 1bd2dd7b3e5..18b9e33424a 100644
--- a/plugin/storage/integration/remote_memory_storage.go
+++ b/plugin/storage/integration/remote_memory_storage.go
@@ -39,7 +39,9 @@ func StartNewRemoteMemoryStorage(t *testing.T) *RemoteMemoryStorage {
},
}
tm := tenancy.NewManager(&opts.Tenancy)
- storageFactory, err := storage.NewFactory(storage.FactoryConfigFromEnvAndCLI(os.Args, os.Stderr))
+ storageFactory, err := storage.NewFactory(
+ storage.FactoryConfigFromEnvAndCLI(os.Args, os.Stderr),
+ )
require.NoError(t, err)
v, _ := config.Viperize(storageFactory.AddFlags)
@@ -47,7 +49,13 @@ func StartNewRemoteMemoryStorage(t *testing.T) *RemoteMemoryStorage {
require.NoError(t, storageFactory.Initialize(metrics.NullFactory, logger))
t.Logf("Starting in-process remote storage server on %s", opts.GRPCHostPort)
- server, err := app.NewServer(opts, storageFactory, tm, logger, healthcheck.New())
+ server, err := app.NewServer(
+ opts,
+ storageFactory,
+ tm,
+ logger,
+ healthcheck.New(),
+ )
require.NoError(t, err)
require.NoError(t, server.Start())
diff --git a/plugin/storage/integration/trace_compare.go b/plugin/storage/integration/trace_compare.go
index bb8c9ca83ba..aad5f8b0b15 100644
--- a/plugin/storage/integration/trace_compare.go
+++ b/plugin/storage/integration/trace_compare.go
@@ -26,8 +26,17 @@ import (
)
// CompareSliceOfTraces compares two trace slices
-func CompareSliceOfTraces(t *testing.T, expected []*model.Trace, actual []*model.Trace) {
- require.Equal(t, len(expected), len(actual), "Unequal number of expected vs. actual traces")
+func CompareSliceOfTraces(
+ t *testing.T,
+ expected []*model.Trace,
+ actual []*model.Trace,
+) {
+ require.Equal(
+ t,
+ len(expected),
+ len(actual),
+ "Unequal number of expected vs. actual traces",
+ )
model.SortTraces(expected)
model.SortTraces(actual)
for i := range expected {
@@ -74,7 +83,11 @@ func CompareTraces(t *testing.T, expected *model.Trace, actual *model.Trace) {
countBefore := len(actual.Spans)
dedupeSpans(actual)
if countAfter := len(actual.Spans); countAfter != countBefore {
- t.Logf("Removed spans with duplicate span IDs; before=%d, after=%d", countBefore, countAfter)
+ t.Logf(
+ "Removed spans with duplicate span IDs; before=%d, after=%d",
+ countBefore,
+ countAfter,
+ )
}
model.SortTrace(expected)
@@ -100,7 +113,11 @@ func checkSize(t *testing.T, expected *model.Trace, actual *model.Trace) {
require.Equal(t, len(expectedSpan.Tags), len(actualSpan.Tags))
require.Equal(t, len(expectedSpan.Logs), len(actualSpan.Logs))
if expectedSpan.Process != nil && actualSpan.Process != nil {
- require.Equal(t, len(expectedSpan.Process.Tags), len(actualSpan.Process.Tags))
+ require.Equal(
+ t,
+ len(expectedSpan.Process.Tags),
+ len(actualSpan.Process.Tags),
+ )
}
}
}
diff --git a/plugin/storage/kafka/factory.go b/plugin/storage/kafka/factory.go
index fb27411b1e4..131a84e4876 100644
--- a/plugin/storage/kafka/factory.go
+++ b/plugin/storage/kafka/factory.go
@@ -72,7 +72,10 @@ func (f *Factory) configureFromOptions(o Options) {
}
// Initialize implements storage.Factory
-func (f *Factory) Initialize(metricsFactory metrics.Factory, logger *zap.Logger) error {
+func (f *Factory) Initialize(
+ metricsFactory metrics.Factory,
+ logger *zap.Logger,
+) error {
f.metricsFactory, f.logger = metricsFactory, logger
logger.Info("Kafka factory",
zap.Any("producer builder", f.Builder),
@@ -83,7 +86,9 @@ func (f *Factory) Initialize(metricsFactory metrics.Factory, logger *zap.Logger)
case EncodingJSON:
f.marshaller = newJSONMarshaller()
default:
- return errors.New("kafka encoding is not one of '" + EncodingJSON + "' or '" + EncodingProto + "'")
+ return errors.New(
+ "kafka encoding is not one of '" + EncodingJSON + "' or '" + EncodingProto + "'",
+ )
}
p, err := f.NewProducer(logger)
if err != nil {
@@ -100,7 +105,13 @@ func (*Factory) CreateSpanReader() (spanstore.Reader, error) {
// CreateSpanWriter implements storage.Factory
func (f *Factory) CreateSpanWriter() (spanstore.Writer, error) {
- return NewSpanWriter(f.producer, f.marshaller, f.options.Topic, f.metricsFactory, f.logger), nil
+ return NewSpanWriter(
+ f.producer,
+ f.marshaller,
+ f.options.Topic,
+ f.metricsFactory,
+ f.logger,
+ ), nil
}
// CreateDependencyReader implements storage.Factory
diff --git a/plugin/storage/kafka/factory_test.go b/plugin/storage/kafka/factory_test.go
index d1192a5c97a..c2fc8e01e2a 100644
--- a/plugin/storage/kafka/factory_test.go
+++ b/plugin/storage/kafka/factory_test.go
@@ -37,7 +37,9 @@ type mockProducerBuilder struct {
t *testing.T
}
-func (m *mockProducerBuilder) NewProducer(*zap.Logger) (sarama.AsyncProducer, error) {
+func (m *mockProducerBuilder) NewProducer(
+ *zap.Logger,
+) (sarama.AsyncProducer, error) {
if m.err == nil {
return mocks.NewAsyncProducer(m.t, nil), nil
}
@@ -54,7 +56,11 @@ func TestKafkaFactory(t *testing.T) {
err: errors.New("made-up error"),
t: t,
}
- require.EqualError(t, f.Initialize(metrics.NullFactory, zap.NewNop()), "made-up error")
+ require.EqualError(
+ t,
+ f.Initialize(metrics.NullFactory, zap.NewNop()),
+ "made-up error",
+ )
f.Builder = &mockProducerBuilder{t: t}
require.NoError(t, f.Initialize(metrics.NullFactory, zap.NewNop()))
@@ -84,7 +90,9 @@ func TestKafkaFactoryEncoding(t *testing.T) {
t.Run(test.encoding, func(t *testing.T) {
f := NewFactory()
v, command := config.Viperize(f.AddFlags)
- err := command.ParseFlags([]string{"--kafka.producer.encoding=" + test.encoding})
+ err := command.ParseFlags(
+ []string{"--kafka.producer.encoding=" + test.encoding},
+ )
require.NoError(t, err)
f.InitFromViper(v, zap.NewNop())
@@ -152,7 +160,12 @@ func TestKafkaFactoryDoesNotLogPassword(t *testing.T) {
require.NoError(t, err)
logger.Sync()
- assert.NotContains(t, logbuf.String(), "SECRET", "log output must not contain password in clear text")
+ assert.NotContains(
+ t,
+ logbuf.String(),
+ "SECRET",
+ "log output must not contain password in clear text",
+ )
require.NoError(t, f.Close())
})
}
@@ -160,7 +173,10 @@ func TestKafkaFactoryDoesNotLogPassword(t *testing.T) {
func TestConfigureFromOptions(t *testing.T) {
f := NewFactory()
- o := Options{Topic: "testTopic", Config: kafkaConfig.Configuration{Brokers: []string{"host"}}}
+ o := Options{
+ Topic: "testTopic",
+ Config: kafkaConfig.Configuration{Brokers: []string{"host"}},
+ }
f.configureFromOptions(o)
assert.Equal(t, o, f.options)
assert.Equal(t, &o.Config, f.Builder)
diff --git a/plugin/storage/kafka/marshalling_test.go b/plugin/storage/kafka/marshalling_test.go
index f9f18d1ed0a..61ca5c19aa0 100644
--- a/plugin/storage/kafka/marshalling_test.go
+++ b/plugin/storage/kafka/marshalling_test.go
@@ -26,14 +26,22 @@ import (
)
func TestProtobufMarshallerAndUnmarshaller(t *testing.T) {
- testMarshallerAndUnmarshaller(t, newProtobufMarshaller(), NewProtobufUnmarshaller())
+ testMarshallerAndUnmarshaller(
+ t,
+ newProtobufMarshaller(),
+ NewProtobufUnmarshaller(),
+ )
}
func TestJSONMarshallerAndUnmarshaller(t *testing.T) {
testMarshallerAndUnmarshaller(t, newJSONMarshaller(), NewJSONUnmarshaller())
}
-func testMarshallerAndUnmarshaller(t *testing.T, marshaller Marshaller, unmarshaller Unmarshaller) {
+func testMarshallerAndUnmarshaller(
+ t *testing.T,
+ marshaller Marshaller,
+ unmarshaller Unmarshaller,
+) {
bytes, err := marshaller.Marshal(sampleSpan)
require.NoError(t, err)
diff --git a/plugin/storage/kafka/options.go b/plugin/storage/kafka/options.go
index 98a2edb0088..4edd175c8f3 100644
--- a/plugin/storage/kafka/options.go
+++ b/plugin/storage/kafka/options.go
@@ -162,7 +162,8 @@ func (*Options) AddFlags(flagSet *flag.FlagSet) {
flagSet.String(
configPrefix+suffixBrokers,
defaultBroker,
- "The comma-separated list of kafka brokers. i.e. '127.0.0.1:9092,0.0.0:1234'")
+ "The comma-separated list of kafka brokers. i.e. '127.0.0.1:9092,0.0.0:1234'",
+ )
flagSet.String(
configPrefix+suffixTopic,
defaultTopic,
@@ -174,7 +175,11 @@ func (*Options) AddFlags(flagSet *flag.FlagSet) {
flagSet.String(
configPrefix+suffixEncoding,
defaultEncoding,
- fmt.Sprintf(`Encoding of spans ("%s" or "%s") sent to kafka.`, EncodingJSON, EncodingProto),
+ fmt.Sprintf(
+ `Encoding of spans ("%s" or "%s") sent to kafka.`,
+ EncodingJSON,
+ EncodingProto,
+ ),
)
auth.AddFlags(configPrefix, flagSet)
@@ -187,24 +192,34 @@ func (opt *Options) InitFromViper(v *viper.Viper) {
log.Fatal(err)
}
- requiredAcks, err := getRequiredAcks(v.GetString(configPrefix + suffixRequiredAcks))
+ requiredAcks, err := getRequiredAcks(
+ v.GetString(configPrefix + suffixRequiredAcks),
+ )
if err != nil {
log.Fatal(err)
}
- compressionMode := strings.ToLower(v.GetString(configPrefix + suffixCompression))
+ compressionMode := strings.ToLower(
+ v.GetString(configPrefix + suffixCompression),
+ )
compressionModeCodec, err := getCompressionMode(compressionMode)
if err != nil {
log.Fatal(err)
}
- compressionLevel, err := getCompressionLevel(compressionMode, v.GetInt(configPrefix+suffixCompressionLevel))
+ compressionLevel, err := getCompressionLevel(
+ compressionMode,
+ v.GetInt(configPrefix+suffixCompressionLevel),
+ )
if err != nil {
log.Fatal(err)
}
opt.Config = producer.Configuration{
- Brokers: strings.Split(stripWhiteSpace(v.GetString(configPrefix+suffixBrokers)), ","),
+ Brokers: strings.Split(
+ stripWhiteSpace(v.GetString(configPrefix+suffixBrokers)),
+ ",",
+ ),
RequiredAcks: requiredAcks,
Compression: compressionModeCodec,
CompressionLevel: compressionLevel,
@@ -229,15 +244,25 @@ func stripWhiteSpace(str string) string {
func getCompressionLevel(mode string, compressionLevel int) (int, error) {
compressionModeData, ok := compressionModes[mode]
if !ok {
- return 0, fmt.Errorf("cannot find compression mode for compressionMode %v", mode)
+ return 0, fmt.Errorf(
+ "cannot find compression mode for compressionMode %v",
+ mode,
+ )
}
if compressionLevel == defaultCompressionLevel {
return compressionModeData.defaultCompressionLevel, nil
}
- if compressionModeData.minCompressionLevel > compressionLevel || compressionModeData.maxCompressionLevel < compressionLevel {
- return 0, fmt.Errorf("compression level %d for '%s' is not within valid range [%d, %d]", compressionLevel, mode, compressionModeData.minCompressionLevel, compressionModeData.maxCompressionLevel)
+ if compressionModeData.minCompressionLevel > compressionLevel ||
+ compressionModeData.maxCompressionLevel < compressionLevel {
+ return 0, fmt.Errorf(
+ "compression level %d for '%s' is not within valid range [%d, %d]",
+ compressionLevel,
+ mode,
+ compressionModeData.minCompressionLevel,
+ compressionModeData.maxCompressionLevel,
+ )
}
return compressionLevel, nil
diff --git a/plugin/storage/kafka/options_test.go b/plugin/storage/kafka/options_test.go
index 790cbab35ee..d905336e99f 100644
--- a/plugin/storage/kafka/options_test.go
+++ b/plugin/storage/kafka/options_test.go
@@ -47,7 +47,11 @@ func TestOptionsWithFlags(t *testing.T) {
opts.InitFromViper(v)
assert.Equal(t, "topic1", opts.Topic)
- assert.Equal(t, []string{"127.0.0.1:9092", "0.0.0:1234"}, opts.Config.Brokers)
+ assert.Equal(
+ t,
+ []string{"127.0.0.1:9092", "0.0.0:1234"},
+ opts.Config.Brokers,
+ )
assert.Equal(t, "protobuf", opts.Encoding)
assert.Equal(t, sarama.WaitForLocal, opts.Config.RequiredAcks)
assert.Equal(t, sarama.CompressionGZIP, opts.Config.Compression)
@@ -80,31 +84,61 @@ func TestFlagDefaults(t *testing.T) {
}
func TestCompressionLevelDefaults(t *testing.T) {
- compressionLevel, err := getCompressionLevel("none", defaultCompressionLevel)
+ compressionLevel, err := getCompressionLevel(
+ "none",
+ defaultCompressionLevel,
+ )
require.NoError(t, err)
- assert.Equal(t, compressionModes["none"].defaultCompressionLevel, compressionLevel)
+ assert.Equal(
+ t,
+ compressionModes["none"].defaultCompressionLevel,
+ compressionLevel,
+ )
compressionLevel, err = getCompressionLevel("gzip", defaultCompressionLevel)
require.NoError(t, err)
- assert.Equal(t, compressionModes["gzip"].defaultCompressionLevel, compressionLevel)
-
- compressionLevel, err = getCompressionLevel("snappy", defaultCompressionLevel)
+ assert.Equal(
+ t,
+ compressionModes["gzip"].defaultCompressionLevel,
+ compressionLevel,
+ )
+
+ compressionLevel, err = getCompressionLevel(
+ "snappy",
+ defaultCompressionLevel,
+ )
require.NoError(t, err)
- assert.Equal(t, compressionModes["snappy"].defaultCompressionLevel, compressionLevel)
+ assert.Equal(
+ t,
+ compressionModes["snappy"].defaultCompressionLevel,
+ compressionLevel,
+ )
compressionLevel, err = getCompressionLevel("lz4", defaultCompressionLevel)
require.NoError(t, err)
- assert.Equal(t, compressionModes["lz4"].defaultCompressionLevel, compressionLevel)
+ assert.Equal(
+ t,
+ compressionModes["lz4"].defaultCompressionLevel,
+ compressionLevel,
+ )
compressionLevel, err = getCompressionLevel("zstd", defaultCompressionLevel)
require.NoError(t, err)
- assert.Equal(t, compressionModes["zstd"].defaultCompressionLevel, compressionLevel)
+ assert.Equal(
+ t,
+ compressionModes["zstd"].defaultCompressionLevel,
+ compressionLevel,
+ )
}
func TestCompressionLevel(t *testing.T) {
compressionLevel, err := getCompressionLevel("none", 0)
require.NoError(t, err)
- assert.Equal(t, compressionModes["none"].defaultCompressionLevel, compressionLevel)
+ assert.Equal(
+ t,
+ compressionModes["none"].defaultCompressionLevel,
+ compressionLevel,
+ )
compressionLevel, err = getCompressionLevel("gzip", 4)
require.NoError(t, err)
@@ -112,7 +146,11 @@ func TestCompressionLevel(t *testing.T) {
compressionLevel, err = getCompressionLevel("snappy", 0)
require.NoError(t, err)
- assert.Equal(t, compressionModes["snappy"].defaultCompressionLevel, compressionLevel)
+ assert.Equal(
+ t,
+ compressionModes["snappy"].defaultCompressionLevel,
+ compressionLevel,
+ )
compressionLevel, err = getCompressionLevel("lz4", 10)
require.NoError(t, err)
@@ -176,31 +214,58 @@ func TestRequiredAcksFailures(t *testing.T) {
}
func TestTLSFlags(t *testing.T) {
- kerb := auth.KerberosConfig{ServiceName: "kafka", ConfigPath: "/etc/krb5.conf", KeyTabPath: "/etc/security/kafka.keytab"}
+ kerb := auth.KerberosConfig{
+ ServiceName: "kafka",
+ ConfigPath: "/etc/krb5.conf",
+ KeyTabPath: "/etc/security/kafka.keytab",
+ }
plain := auth.PlainTextConfig{Username: "", Password: "", Mechanism: "PLAIN"}
tests := []struct {
flags []string
expected auth.AuthenticationConfig
}{
{
- flags: []string{},
- expected: auth.AuthenticationConfig{Authentication: "none", Kerberos: kerb, PlainText: plain},
+ flags: []string{},
+ expected: auth.AuthenticationConfig{
+ Authentication: "none",
+ Kerberos: kerb,
+ PlainText: plain,
+ },
},
{
- flags: []string{"--kafka.producer.authentication=foo"},
- expected: auth.AuthenticationConfig{Authentication: "foo", Kerberos: kerb, PlainText: plain},
+ flags: []string{"--kafka.producer.authentication=foo"},
+ expected: auth.AuthenticationConfig{
+ Authentication: "foo",
+ Kerberos: kerb,
+ PlainText: plain,
+ },
},
{
- flags: []string{"--kafka.producer.authentication=kerberos", "--kafka.producer.tls.enabled=true"},
- expected: auth.AuthenticationConfig{Authentication: "kerberos", Kerberos: kerb, TLS: tlscfg.Options{Enabled: true}, PlainText: plain},
+ flags: []string{"--kafka.producer.authentication=kerberos", "--kafka.producer.tls.enabled=true"},
+ expected: auth.AuthenticationConfig{
+ Authentication: "kerberos",
+ Kerberos: kerb,
+ TLS: tlscfg.Options{Enabled: true},
+ PlainText: plain,
+ },
},
{
- flags: []string{"--kafka.producer.authentication=tls"},
- expected: auth.AuthenticationConfig{Authentication: "tls", Kerberos: kerb, TLS: tlscfg.Options{Enabled: true}, PlainText: plain},
+ flags: []string{"--kafka.producer.authentication=tls"},
+ expected: auth.AuthenticationConfig{
+ Authentication: "tls",
+ Kerberos: kerb,
+ TLS: tlscfg.Options{Enabled: true},
+ PlainText: plain,
+ },
},
{
- flags: []string{"--kafka.producer.authentication=tls", "--kafka.producer.tls.enabled=false"},
- expected: auth.AuthenticationConfig{Authentication: "tls", Kerberos: kerb, TLS: tlscfg.Options{Enabled: true}, PlainText: plain},
+ flags: []string{"--kafka.producer.authentication=tls", "--kafka.producer.tls.enabled=false"},
+ expected: auth.AuthenticationConfig{
+ Authentication: "tls",
+ Kerberos: kerb,
+ TLS: tlscfg.Options{Enabled: true},
+ PlainText: plain,
+ },
},
}
diff --git a/plugin/storage/kafka/writer.go b/plugin/storage/kafka/writer.go
index 9be38926b01..f5685aeb5ab 100644
--- a/plugin/storage/kafka/writer.go
+++ b/plugin/storage/kafka/writer.go
@@ -46,8 +46,12 @@ func NewSpanWriter(
logger *zap.Logger,
) *SpanWriter {
writeMetrics := spanWriterMetrics{
- SpansWrittenSuccess: factory.Counter(metrics.Options{Name: "kafka_spans_written", Tags: map[string]string{"status": "success"}}),
- SpansWrittenFailure: factory.Counter(metrics.Options{Name: "kafka_spans_written", Tags: map[string]string{"status": "failure"}}),
+ SpansWrittenSuccess: factory.Counter(
+ metrics.Options{Name: "kafka_spans_written", Tags: map[string]string{"status": "success"}},
+ ),
+ SpansWrittenFailure: factory.Counter(
+ metrics.Options{Name: "kafka_spans_written", Tags: map[string]string{"status": "failure"}},
+ ),
}
go func() {
diff --git a/plugin/storage/kafka/writer_test.go b/plugin/storage/kafka/writer_test.go
index 0b10ce7533b..6b2d19da7d1 100644
--- a/plugin/storage/kafka/writer_test.go
+++ b/plugin/storage/kafka/writer_test.go
@@ -75,20 +75,30 @@ type spanWriterTest struct {
// Checks that Kafka SpanWriter conforms to spanstore.Writer API
var _ spanstore.Writer = &SpanWriter{}
-func withSpanWriter(t *testing.T, fn func(span *model.Span, w *spanWriterTest)) {
+func withSpanWriter(
+ t *testing.T,
+ fn func(span *model.Span, w *spanWriterTest),
+) {
serviceMetrics := metricstest.NewFactory(100 * time.Millisecond)
defer serviceMetrics.Stop()
saramaConfig := sarama.NewConfig()
saramaConfig.Producer.Return.Successes = true
producer := saramaMocks.NewAsyncProducer(t, saramaConfig)
marshaller := &mocks.Marshaller{}
- marshaller.On("Marshal", mock.AnythingOfType("*model.Span")).Return([]byte{}, nil)
+ marshaller.On("Marshal", mock.AnythingOfType("*model.Span")).
+ Return([]byte{}, nil)
writerTest := &spanWriterTest{
producer: producer,
marshaller: marshaller,
metricsFactory: serviceMetrics,
- writer: NewSpanWriter(producer, marshaller, "someTopic", serviceMetrics, zap.NewNop()),
+ writer: NewSpanWriter(
+ producer,
+ marshaller,
+ "someTopic",
+ serviceMetrics,
+ zap.NewNop(),
+ ),
}
fn(sampleSpan, writerTest)
@@ -160,7 +170,8 @@ func TestKafkaWriterErr(t *testing.T) {
func TestMarshallerErr(t *testing.T) {
withSpanWriter(t, func(span *model.Span, w *spanWriterTest) {
marshaller := &mocks.Marshaller{}
- marshaller.On("Marshal", mock.AnythingOfType("*model.Span")).Return([]byte{}, errors.New(""))
+ marshaller.On("Marshal", mock.AnythingOfType("*model.Span")).
+ Return([]byte{}, errors.New(""))
w.writer.marshaller = marshaller
err := w.writer.WriteSpan(context.Background(), span)
diff --git a/plugin/storage/memory/factory.go b/plugin/storage/memory/factory.go
index efaf0ac1c23..9ac3f9394bc 100644
--- a/plugin/storage/memory/factory.go
+++ b/plugin/storage/memory/factory.go
@@ -80,10 +80,16 @@ func (f *Factory) configureFromOptions(opts Options) {
}
// Initialize implements storage.Factory
-func (f *Factory) Initialize(metricsFactory metrics.Factory, logger *zap.Logger) error {
+func (f *Factory) Initialize(
+ metricsFactory metrics.Factory,
+ logger *zap.Logger,
+) error {
f.metricsFactory, f.logger = metricsFactory, logger
f.store = WithConfiguration(f.options.Configuration)
- logger.Info("Memory storage initialized", zap.Any("configuration", f.store.defaultConfig))
+ logger.Info(
+ "Memory storage initialized",
+ zap.Any("configuration", f.store.defaultConfig),
+ )
f.publishOpts()
return nil
@@ -115,7 +121,9 @@ func (f *Factory) CreateDependencyReader() (dependencystore.Reader, error) {
}
// CreateSamplingStore implements storage.SamplingStoreFactory
-func (*Factory) CreateSamplingStore(maxBuckets int) (samplingstore.Store, error) {
+func (*Factory) CreateSamplingStore(
+ maxBuckets int,
+) (samplingstore.Store, error) {
return NewSamplingStore(maxBuckets), nil
}
@@ -125,5 +133,8 @@ func (*Factory) CreateLock() (distributedlock.Lock, error) {
}
func (f *Factory) publishOpts() {
- safeexpvar.SetInt("jaeger_storage_memory_max_traces", int64(f.options.Configuration.MaxTraces))
+ safeexpvar.SetInt(
+ "jaeger_storage_memory_max_traces",
+ int64(f.options.Configuration.MaxTraces),
+ )
}
diff --git a/plugin/storage/memory/factory_test.go b/plugin/storage/memory/factory_test.go
index 5c43799b704..3a200eab3f7 100644
--- a/plugin/storage/memory/factory_test.go
+++ b/plugin/storage/memory/factory_test.go
@@ -75,5 +75,9 @@ func TestPublishOpts(t *testing.T) {
f.InitFromViper(v, zap.NewNop())
require.NoError(t, f.Initialize(metrics.NullFactory, zap.NewNop()))
- assert.EqualValues(t, 100, expvar.Get("jaeger_storage_memory_max_traces").(*expvar.Int).Value())
+ assert.EqualValues(
+ t,
+ 100,
+ expvar.Get("jaeger_storage_memory_max_traces").(*expvar.Int).Value(),
+ )
}
diff --git a/plugin/storage/memory/memory.go b/plugin/storage/memory/memory.go
index 11fdd1dc074..df3b6e5d7f5 100644
--- a/plugin/storage/memory/memory.go
+++ b/plugin/storage/memory/memory.go
@@ -94,7 +94,11 @@ func (st *Store) getTenant(tenantID string) *Tenant {
}
// GetDependencies returns dependencies between services
-func (st *Store) GetDependencies(ctx context.Context, endTs time.Time, lookback time.Duration) ([]model.DependencyLink, error) {
+func (st *Store) GetDependencies(
+ ctx context.Context,
+ endTs time.Time,
+ lookback time.Duration,
+) ([]model.DependencyLink, error) {
m := st.getTenant(tenancy.GetTenant(ctx))
// deduper used below can modify the spans, so we take an exclusive lock
m.Lock()
@@ -141,7 +145,10 @@ func findSpan(trace *model.Trace, spanID model.SpanID) *model.Span {
return nil
}
-func traceIsBetweenStartAndEnd(startTs, endTs time.Time, trace *model.Trace) bool {
+func traceIsBetweenStartAndEnd(
+ startTs, endTs time.Time,
+ trace *model.Trace,
+) bool {
for _, s := range trace.Spans {
if s.StartTime.After(startTs) && endTs.After(s.StartTime) {
return true
@@ -194,7 +201,10 @@ func (st *Store) WriteSpan(ctx context.Context, span *model.Span) error {
}
// GetTrace gets a trace
-func (st *Store) GetTrace(ctx context.Context, traceID model.TraceID) (*model.Trace, error) {
+func (st *Store) GetTrace(
+ ctx context.Context,
+ traceID model.TraceID,
+) (*model.Trace, error) {
m := st.getTenant(tenancy.GetTenant(ctx))
m.RLock()
defer m.RUnlock()
@@ -249,7 +259,10 @@ func (st *Store) GetOperations(
}
// FindTraces returns all traces in the query parameters are satisfied by a trace's span
-func (st *Store) FindTraces(ctx context.Context, query *spanstore.TraceQueryParameters) ([]*model.Trace, error) {
+func (st *Store) FindTraces(
+ ctx context.Context,
+ query *spanstore.TraceQueryParameters,
+) ([]*model.Trace, error) {
m := st.getTenant(tenancy.GetTenant(ctx))
m.RLock()
defer m.RUnlock()
@@ -269,7 +282,9 @@ func (st *Store) FindTraces(ctx context.Context, query *spanstore.TraceQueryPara
// However, if query.NumTraces < results, then we should return the newest traces.
if query.NumTraces > 0 && len(retMe) > query.NumTraces {
sort.Slice(retMe, func(i, j int) bool {
- return retMe[i].Spans[0].StartTime.Before(retMe[j].Spans[0].StartTime)
+ return retMe[i].Spans[0].StartTime.Before(
+ retMe[j].Spans[0].StartTime,
+ )
})
retMe = retMe[len(retMe)-query.NumTraces:]
}
@@ -278,11 +293,17 @@ func (st *Store) FindTraces(ctx context.Context, query *spanstore.TraceQueryPara
}
// FindTraceIDs is not implemented.
-func (*Store) FindTraceIDs(ctx context.Context, query *spanstore.TraceQueryParameters) ([]model.TraceID, error) {
+func (*Store) FindTraceIDs(
+ ctx context.Context,
+ query *spanstore.TraceQueryParameters,
+) ([]model.TraceID, error) {
return nil, errors.New("not implemented")
}
-func validTrace(trace *model.Trace, query *spanstore.TraceQueryParameters) bool {
+func validTrace(
+ trace *model.Trace,
+ query *spanstore.TraceQueryParameters,
+) bool {
for _, span := range trace.Spans {
if validSpan(span, query) {
return true
@@ -291,7 +312,10 @@ func validTrace(trace *model.Trace, query *spanstore.TraceQueryParameters) bool
return false
}
-func findKeyValueMatch(kvs model.KeyValues, key, value string) (model.KeyValue, bool) {
+func findKeyValueMatch(
+ kvs model.KeyValues,
+ key, value string,
+) (model.KeyValue, bool) {
for _, kv := range kvs {
if kv.Key == key && kv.AsString() == value {
return kv, true
@@ -313,10 +337,12 @@ func validSpan(span *model.Span, query *spanstore.TraceQueryParameters) bool {
if query.DurationMax != 0 && span.Duration > query.DurationMax {
return false
}
- if !query.StartTimeMin.IsZero() && span.StartTime.Before(query.StartTimeMin) {
+ if !query.StartTimeMin.IsZero() &&
+ span.StartTime.Before(query.StartTimeMin) {
return false
}
- if !query.StartTimeMax.IsZero() && span.StartTime.After(query.StartTimeMax) {
+ if !query.StartTimeMax.IsZero() &&
+ span.StartTime.After(query.StartTimeMax) {
return false
}
spanKVs := flattenTags(span)
diff --git a/plugin/storage/memory/memory_test.go b/plugin/storage/memory/memory_test.go
index a1bc0500909..480e7624319 100644
--- a/plugin/storage/memory/memory_test.go
+++ b/plugin/storage/memory/memory_test.go
@@ -40,9 +40,11 @@ var (
)
var childSpan1 = &model.Span{
- TraceID: traceID,
- SpanID: model.NewSpanID(2),
- References: []model.SpanRef{model.NewChildOfRef(traceID, model.NewSpanID(1))},
+ TraceID: traceID,
+ SpanID: model.NewSpanID(2),
+ References: []model.SpanRef{
+ model.NewChildOfRef(traceID, model.NewSpanID(1)),
+ },
Process: &model.Process{
ServiceName: "childService",
Tags: model.KeyValues{},
@@ -65,9 +67,11 @@ var childSpan1 = &model.Span{
}
var childSpan2 = &model.Span{
- TraceID: traceID,
- SpanID: model.NewSpanID(3),
- References: []model.SpanRef{model.NewChildOfRef(traceID, model.NewSpanID(1))},
+ TraceID: traceID,
+ SpanID: model.NewSpanID(3),
+ References: []model.SpanRef{
+ model.NewChildOfRef(traceID, model.NewSpanID(1)),
+ },
Process: &model.Process{
ServiceName: "childService",
Tags: model.KeyValues{},
@@ -93,7 +97,9 @@ var childSpan2_1 = &model.Span{
TraceID: traceID,
SpanID: model.NewSpanID(4),
// child of childSpan2, but with the same service name
- References: []model.SpanRef{model.NewChildOfRef(traceID, model.NewSpanID(3))},
+ References: []model.SpanRef{
+ model.NewChildOfRef(traceID, model.NewSpanID(3)),
+ },
Process: &model.Process{
ServiceName: "childService",
Tags: model.KeyValues{},
@@ -135,7 +141,11 @@ func withMemoryStore(f func(store *Store)) {
func TestStoreGetEmptyDependencies(t *testing.T) {
// assert.Equal(t, testingSpan, testingSpan1B) // @@@
withMemoryStore(func(store *Store) {
- links, err := store.GetDependencies(context.Background(), time.Now(), time.Hour)
+ links, err := store.GetDependencies(
+ context.Background(),
+ time.Now(),
+ time.Hour,
+ )
require.NoError(t, err)
assert.Empty(t, links)
})
@@ -147,11 +157,19 @@ func TestStoreGetDependencies(t *testing.T) {
require.NoError(t, store.WriteSpan(context.Background(), childSpan1))
require.NoError(t, store.WriteSpan(context.Background(), childSpan2))
require.NoError(t, store.WriteSpan(context.Background(), childSpan2_1))
- links, err := store.GetDependencies(context.Background(), time.Now(), time.Hour)
+ links, err := store.GetDependencies(
+ context.Background(),
+ time.Now(),
+ time.Hour,
+ )
require.NoError(t, err)
assert.Empty(t, links)
- links, err = store.GetDependencies(context.Background(), time.Unix(0, 0).Add(time.Hour), time.Hour)
+ links, err = store.GetDependencies(
+ context.Background(),
+ time.Unix(0, 0).Add(time.Hour),
+ time.Hour,
+ )
require.NoError(t, err)
assert.Equal(t, []model.DependencyLink{{
Parent: "serviceName",
@@ -214,7 +232,10 @@ func TestStoreGetAndMutateTrace(t *testing.T) {
assert.Equal(t, testingSpan, trace.Spans[0])
assert.Empty(t, trace.Spans[0].Warnings)
- trace.Spans[0].Warnings = append(trace.Spans[0].Warnings, "the end is near")
+ trace.Spans[0].Warnings = append(
+ trace.Spans[0].Warnings,
+ "the end is near",
+ )
trace, err = store.GetTrace(context.Background(), testingSpan.TraceID)
require.NoError(t, err)
@@ -259,7 +280,9 @@ func TestStoreGetAllOperationsFound(t *testing.T) {
require.NoError(t, store.WriteSpan(context.Background(), childSpan2_1))
operations, err := store.GetOperations(
context.Background(),
- spanstore.OperationQueryParameters{ServiceName: childSpan1.Process.ServiceName},
+ spanstore.OperationQueryParameters{
+ ServiceName: childSpan1.Process.ServiceName,
+ },
)
require.NoError(t, err)
assert.Len(t, operations, 3)
@@ -300,7 +323,10 @@ func TestStoreGetOperationsNotFound(t *testing.T) {
func TestStoreGetEmptyTraceSet(t *testing.T) {
withPopulatedMemoryStore(func(store *Store) {
- traces, err := store.FindTraces(context.Background(), &spanstore.TraceQueryParameters{})
+ traces, err := store.FindTraces(
+ context.Background(),
+ &spanstore.TraceQueryParameters{},
+ )
require.NoError(t, err)
assert.Empty(t, traces)
})
@@ -310,7 +336,10 @@ func TestStoreFindTracesError(t *testing.T) {
withPopulatedMemoryStore(func(store *Store) {
err := store.WriteSpan(context.Background(), nonSerializableSpan)
require.NoError(t, err)
- _, err = store.FindTraces(context.Background(), &spanstore.TraceQueryParameters{ServiceName: "naughtyService"})
+ _, err = store.FindTraces(
+ context.Background(),
+ &spanstore.TraceQueryParameters{ServiceName: "naughtyService"},
+ )
require.Error(t, err)
})
}
@@ -351,15 +380,22 @@ func TestStoreFindTracesLimitGetsMostRecent(t *testing.T) {
memStore.WriteSpan(context.Background(), span)
}
- gotTraces, err := memStore.FindTraces(context.Background(), &spanstore.TraceQueryParameters{
- ServiceName: "serviceName",
- NumTraces: querySize,
- })
+ gotTraces, err := memStore.FindTraces(
+ context.Background(),
+ &spanstore.TraceQueryParameters{
+ ServiceName: "serviceName",
+ NumTraces: querySize,
+ },
+ )
require.NoError(t, err)
if assert.Len(t, gotTraces, len(expectedTraces)) {
for i := range gotTraces {
- assert.EqualValues(t, expectedTraces[i].Spans[0].StartTime.Unix(), gotTraces[i].Spans[0].StartTime.Unix())
+ assert.EqualValues(
+ t,
+ expectedTraces[i].Spans[0].StartTime.Unix(),
+ gotTraces[i].Spans[0].StartTime.Unix(),
+ )
}
}
}
@@ -471,17 +507,23 @@ func TestTenantStore(t *testing.T) {
assert.Equal(t, testingSpan2, trace2.Spans[0])
// Can we query the spans with correct tenancy
- traces1, err := store.FindTraces(ctxAcme, &spanstore.TraceQueryParameters{
- ServiceName: "serviceName",
- })
+ traces1, err := store.FindTraces(
+ ctxAcme,
+ &spanstore.TraceQueryParameters{
+ ServiceName: "serviceName",
+ },
+ )
require.NoError(t, err)
assert.Len(t, traces1, 1)
assert.Len(t, traces1[0].Spans, 1)
assert.Equal(t, testingSpan, traces1[0].Spans[0])
- traces2, err := store.FindTraces(ctxWonka, &spanstore.TraceQueryParameters{
- ServiceName: "serviceName2",
- })
+ traces2, err := store.FindTraces(
+ ctxWonka,
+ &spanstore.TraceQueryParameters{
+ ServiceName: "serviceName2",
+ },
+ )
require.NoError(t, err)
assert.Len(t, traces2, 1)
assert.Len(t, traces2[0].Spans, 1)
diff --git a/plugin/storage/memory/options.go b/plugin/storage/memory/options.go
index d2ec03d21b4..28f7ec7c878 100644
--- a/plugin/storage/memory/options.go
+++ b/plugin/storage/memory/options.go
@@ -31,7 +31,11 @@ type Options struct {
// AddFlags from this storage to the CLI
func AddFlags(flagSet *flag.FlagSet) {
- flagSet.Int(limit, 0, "The maximum amount of traces to store in memory. The default number of traces is unbounded.")
+ flagSet.Int(
+ limit,
+ 0,
+ "The maximum amount of traces to store in memory. The default number of traces is unbounded.",
+ )
}
// InitFromViper initializes the options struct with values from Viper
diff --git a/plugin/storage/memory/sampling.go b/plugin/storage/memory/sampling.go
index 9a6ca5aa79c..d678f978aaf 100644
--- a/plugin/storage/memory/sampling.go
+++ b/plugin/storage/memory/sampling.go
@@ -47,7 +47,9 @@ func NewSamplingStore(maxBuckets int) *SamplingStore {
}
// InsertThroughput implements samplingstore.Store#InsertThroughput.
-func (ss *SamplingStore) InsertThroughput(throughput []*model.Throughput) error {
+func (ss *SamplingStore) InsertThroughput(
+ throughput []*model.Throughput,
+) error {
ss.Lock()
defer ss.Unlock()
now := time.Now()
@@ -56,7 +58,9 @@ func (ss *SamplingStore) InsertThroughput(throughput []*model.Throughput) error
}
// GetThroughput implements samplingstore.Store#GetThroughput.
-func (ss *SamplingStore) GetThroughput(start, end time.Time) ([]*model.Throughput, error) {
+func (ss *SamplingStore) GetThroughput(
+ start, end time.Time,
+) ([]*model.Throughput, error) {
ss.Lock()
defer ss.Unlock()
var retSlice []*model.Throughput
@@ -76,7 +80,12 @@ func (ss *SamplingStore) InsertProbabilitiesAndQPS(
) error {
ss.Lock()
defer ss.Unlock()
- ss.probabilitiesAndQPS = &storedServiceOperationProbabilitiesAndQPS{hostname, probabilities, qps, time.Now()}
+ ss.probabilitiesAndQPS = &storedServiceOperationProbabilitiesAndQPS{
+ hostname,
+ probabilities,
+ qps,
+ time.Now(),
+ }
return nil
}
diff --git a/plugin/storage/memory/sampling_test.go b/plugin/storage/memory/sampling_test.go
index e212cb5441f..8ada495db9f 100644
--- a/plugin/storage/memory/sampling_test.go
+++ b/plugin/storage/memory/sampling_test.go
@@ -30,14 +30,32 @@ func withPopulatedSamplingStore(f func(samplingStore *SamplingStore)) {
millisAfter := now.Add(time.Millisecond * time.Duration(100))
secondsAfter := now.Add(time.Second * time.Duration(2))
throughputs := []*storedThroughput{
- {[]*model.Throughput{{Service: "svc-1", Operation: "op-1", Count: 1}}, now},
- {[]*model.Throughput{{Service: "svc-1", Operation: "op-2", Count: 1}}, millisAfter},
- {[]*model.Throughput{{Service: "svc-2", Operation: "op-3", Count: 1}}, secondsAfter},
+ {
+ []*model.Throughput{
+ {Service: "svc-1", Operation: "op-1", Count: 1},
+ },
+ now,
+ },
+ {
+ []*model.Throughput{
+ {Service: "svc-1", Operation: "op-2", Count: 1},
+ },
+ millisAfter,
+ },
+ {
+ []*model.Throughput{
+ {Service: "svc-2", Operation: "op-3", Count: 1},
+ },
+ secondsAfter,
+ },
}
pQPS := &storedServiceOperationProbabilitiesAndQPS{
hostname: "guntur38ab8928", probabilities: model.ServiceOperationProbabilities{"svc-1": {"op-1": 0.01}}, qps: model.ServiceOperationQPS{"svc-1": {"op-1": 10.0}}, time: now,
}
- samplingStore := &SamplingStore{throughputs: throughputs, probabilitiesAndQPS: pQPS}
+ samplingStore := &SamplingStore{
+ throughputs: throughputs,
+ probabilitiesAndQPS: pQPS,
+ }
f(samplingStore)
}
@@ -53,12 +71,18 @@ func TestInsertThroughtput(t *testing.T) {
{Service: "our-svc", Operation: "op2"},
}
require.NoError(t, samplingStore.InsertThroughput(throughputs))
- ret, _ := samplingStore.GetThroughput(start, start.Add(time.Second*time.Duration(1)))
+ ret, _ := samplingStore.GetThroughput(
+ start,
+ start.Add(time.Second*time.Duration(1)),
+ )
assert.Len(t, ret, 2)
for i := 0; i < 10; i++ {
in := []*model.Throughput{
- {Service: fmt.Sprint("svc-", i), Operation: fmt.Sprint("op-", i)},
+ {
+ Service: fmt.Sprint("svc-", i),
+ Operation: fmt.Sprint("op-", i),
+ },
}
samplingStore.InsertThroughput(in)
}
@@ -69,22 +93,42 @@ func TestInsertThroughtput(t *testing.T) {
func TestGetThroughput(t *testing.T) {
withPopulatedSamplingStore(func(samplingStore *SamplingStore) {
start := time.Now()
- ret, err := samplingStore.GetThroughput(start, start.Add(time.Second*time.Duration(1)))
+ ret, err := samplingStore.GetThroughput(
+ start,
+ start.Add(time.Second*time.Duration(1)),
+ )
require.NoError(t, err)
assert.Len(t, ret, 1)
ret1, _ := samplingStore.GetThroughput(start, start)
assert.Empty(t, ret1)
- ret2, _ := samplingStore.GetThroughput(start, start.Add(time.Hour*time.Duration(1)))
+ ret2, _ := samplingStore.GetThroughput(
+ start,
+ start.Add(time.Hour*time.Duration(1)),
+ )
assert.Len(t, ret2, 2)
})
}
func TestInsertProbabilitiesAndQPS(t *testing.T) {
withMemorySamplingStore(func(samplingStore *SamplingStore) {
- require.NoError(t, samplingStore.InsertProbabilitiesAndQPS("dell11eg843d", model.ServiceOperationProbabilities{"new-srv": {"op": 0.1}}, model.ServiceOperationQPS{"new-srv": {"op": 4}}))
+ require.NoError(
+ t,
+ samplingStore.InsertProbabilitiesAndQPS(
+ "dell11eg843d",
+ model.ServiceOperationProbabilities{"new-srv": {"op": 0.1}},
+ model.ServiceOperationQPS{"new-srv": {"op": 4}},
+ ),
+ )
assert.NotEmpty(t, 1, samplingStore.probabilitiesAndQPS)
// Only latest one is kept in memory
- require.NoError(t, samplingStore.InsertProbabilitiesAndQPS("lncol73", model.ServiceOperationProbabilities{"my-app": {"hello": 0.3}}, model.ServiceOperationQPS{"new-srv": {"op": 7}}))
+ require.NoError(
+ t,
+ samplingStore.InsertProbabilitiesAndQPS(
+ "lncol73",
+ model.ServiceOperationProbabilities{"my-app": {"hello": 0.3}},
+ model.ServiceOperationQPS{"new-srv": {"op": 7}},
+ ),
+ )
assert.Equal(t, 0.3, samplingStore.probabilitiesAndQPS.probabilities["my-app"]["hello"])
})
}
@@ -102,8 +146,19 @@ func TestGetLatestProbability(t *testing.T) {
ret, err := samplingStore.GetLatestProbabilities()
require.NoError(t, err)
assert.Equal(t, model.ServiceOperationProbabilities{"svc-1": {"op-1": 0.01}}, ret)
- require.NoError(t, samplingStore.InsertProbabilitiesAndQPS("utfhyolf", model.ServiceOperationProbabilities{"another-service": {"hello": 0.009}}, model.ServiceOperationQPS{"new-srv": {"op": 5}}))
+ require.NoError(
+ t,
+ samplingStore.InsertProbabilitiesAndQPS(
+ "utfhyolf",
+ model.ServiceOperationProbabilities{"another-service": {"hello": 0.009}},
+ model.ServiceOperationQPS{"new-srv": {"op": 5}},
+ ),
+ )
ret, _ = samplingStore.GetLatestProbabilities()
- assert.NotEqual(t, model.ServiceOperationProbabilities{"svc-1": {"op-1": 0.01}}, ret)
+ assert.NotEqual(
+ t,
+ model.ServiceOperationProbabilities{"svc-1": {"op-1": 0.01}},
+ ret,
+ )
})
}
diff --git a/ports/ports_test.go b/ports/ports_test.go
index a6dae7a4f18..ec65a09388a 100644
--- a/ports/ports_test.go
+++ b/ports/ports_test.go
@@ -42,7 +42,11 @@ func TestGetAddressFromCLIOptionsLegacy(t *testing.T) {
}
for _, test := range tests {
t.Run(fmt.Sprintf("%+v", test), func(t *testing.T) {
- assert.Equal(t, test.out, GetAddressFromCLIOptions(test.port, test.hostPort))
+ assert.Equal(
+ t,
+ test.out,
+ GetAddressFromCLIOptions(test.port, test.hostPort),
+ )
})
}
}
diff --git a/storage/dependencystore/interface.go b/storage/dependencystore/interface.go
index 4a68149862d..a72633f0d58 100644
--- a/storage/dependencystore/interface.go
+++ b/storage/dependencystore/interface.go
@@ -29,5 +29,9 @@ type Writer interface {
// Reader can load service dependencies from storage.
type Reader interface {
- GetDependencies(ctx context.Context, endTs time.Time, lookback time.Duration) ([]model.DependencyLink, error)
+ GetDependencies(
+ ctx context.Context,
+ endTs time.Time,
+ lookback time.Duration,
+ ) ([]model.DependencyLink, error)
}
diff --git a/storage/dependencystore/mocks/Reader.go b/storage/dependencystore/mocks/Reader.go
index a289fc0d213..54bb7a491cd 100644
--- a/storage/dependencystore/mocks/Reader.go
+++ b/storage/dependencystore/mocks/Reader.go
@@ -31,7 +31,11 @@ type Reader struct {
}
// GetDependencies provides a mock function with given fields: endTs, lookback
-func (_m *Reader) GetDependencies(ctx context.Context, endTs time.Time, lookback time.Duration) ([]model.DependencyLink, error) {
+func (_m *Reader) GetDependencies(
+ ctx context.Context,
+ endTs time.Time,
+ lookback time.Duration,
+) ([]model.DependencyLink, error) {
ret := _m.Called(endTs, lookback)
var r0 []model.DependencyLink
diff --git a/storage/factory.go b/storage/factory.go
index 462a626b64f..18692ffd56f 100644
--- a/storage/factory.go
+++ b/storage/factory.go
@@ -68,7 +68,9 @@ type SamplingStoreFactory interface {
var (
// ErrArchiveStorageNotConfigured can be returned by the ArchiveFactory when the archive storage is not configured.
- ErrArchiveStorageNotConfigured = errors.New("archive storage not configured")
+ ErrArchiveStorageNotConfigured = errors.New(
+ "archive storage not configured",
+ )
// ErrArchiveStorageNotSupported can be returned by the ArchiveFactory when the archive storage is not supported by the backend.
ErrArchiveStorageNotSupported = errors.New("archive storage not supported")
diff --git a/storage/metricsstore/interface.go b/storage/metricsstore/interface.go
index dc62fd0fa56..e97afd2c78b 100644
--- a/storage/metricsstore/interface.go
+++ b/storage/metricsstore/interface.go
@@ -25,16 +25,28 @@ import (
type Reader interface {
// GetLatencies gets the latency metrics for a specific quantile (e.g. 0.99) and list of services
// grouped by service and optionally grouped by operation.
- GetLatencies(ctx context.Context, params *LatenciesQueryParameters) (*metrics.MetricFamily, error)
+ GetLatencies(
+ ctx context.Context,
+ params *LatenciesQueryParameters,
+ ) (*metrics.MetricFamily, error)
// GetCallRates gets the call rate metrics for a given list of services grouped by service
// and optionally grouped by operation.
- GetCallRates(ctx context.Context, params *CallRateQueryParameters) (*metrics.MetricFamily, error)
+ GetCallRates(
+ ctx context.Context,
+ params *CallRateQueryParameters,
+ ) (*metrics.MetricFamily, error)
// GetErrorRates gets the error rate metrics for a given list of services grouped by service
// and optionally grouped by operation.
- GetErrorRates(ctx context.Context, params *ErrorRateQueryParameters) (*metrics.MetricFamily, error)
+ GetErrorRates(
+ ctx context.Context,
+ params *ErrorRateQueryParameters,
+ ) (*metrics.MetricFamily, error)
// GetMinStepDuration gets the min time resolution supported by the backing metrics store,
// e.g. 10s means the backend can only return data points that are at least 10s apart, not closer.
- GetMinStepDuration(ctx context.Context, params *MinStepDurationQueryParameters) (time.Duration, error)
+ GetMinStepDuration(
+ ctx context.Context,
+ params *MinStepDurationQueryParameters,
+ ) (time.Duration, error)
}
// BaseQueryParameters contains the common set of parameters used by all metrics queries:
diff --git a/storage/metricsstore/metrics/decorator.go b/storage/metricsstore/metrics/decorator.go
index 3a2cca9716c..f6fe063db8c 100644
--- a/storage/metricsstore/metrics/decorator.go
+++ b/storage/metricsstore/metrics/decorator.go
@@ -35,8 +35,8 @@ type ReadMetricsDecorator struct {
type queryMetrics struct {
Errors metrics.Counter `metric:"requests" tags:"result=err"`
Successes metrics.Counter `metric:"requests" tags:"result=ok"`
- ErrLatency metrics.Timer `metric:"latency" tags:"result=err"`
- OKLatency metrics.Timer `metric:"latency" tags:"result=ok"`
+ ErrLatency metrics.Timer `metric:"latency" tags:"result=err"`
+ OKLatency metrics.Timer `metric:"latency" tags:"result=ok"`
}
func (q *queryMetrics) emit(err error, latency time.Duration) {
@@ -50,25 +50,51 @@ func (q *queryMetrics) emit(err error, latency time.Duration) {
}
// NewReadMetricsDecorator returns a new ReadMetricsDecorator.
-func NewReadMetricsDecorator(reader metricsstore.Reader, metricsFactory metrics.Factory) *ReadMetricsDecorator {
+func NewReadMetricsDecorator(
+ reader metricsstore.Reader,
+ metricsFactory metrics.Factory,
+) *ReadMetricsDecorator {
return &ReadMetricsDecorator{
- reader: reader,
- getLatenciesMetrics: buildQueryMetrics("get_latencies", metricsFactory),
- getCallRatesMetrics: buildQueryMetrics("get_call_rates", metricsFactory),
- getErrorRatesMetrics: buildQueryMetrics("get_error_rates", metricsFactory),
- getMinStepDurationMetrics: buildQueryMetrics("get_min_step_duration", metricsFactory),
+ reader: reader,
+ getLatenciesMetrics: buildQueryMetrics(
+ "get_latencies",
+ metricsFactory,
+ ),
+ getCallRatesMetrics: buildQueryMetrics(
+ "get_call_rates",
+ metricsFactory,
+ ),
+ getErrorRatesMetrics: buildQueryMetrics(
+ "get_error_rates",
+ metricsFactory,
+ ),
+ getMinStepDurationMetrics: buildQueryMetrics(
+ "get_min_step_duration",
+ metricsFactory,
+ ),
}
}
-func buildQueryMetrics(operation string, metricsFactory metrics.Factory) *queryMetrics {
+func buildQueryMetrics(
+ operation string,
+ metricsFactory metrics.Factory,
+) *queryMetrics {
qMetrics := &queryMetrics{}
- scoped := metricsFactory.Namespace(metrics.NSOptions{Name: "", Tags: map[string]string{"operation": operation}})
+ scoped := metricsFactory.Namespace(
+ metrics.NSOptions{
+ Name: "",
+ Tags: map[string]string{"operation": operation},
+ },
+ )
metrics.Init(qMetrics, scoped, nil)
return qMetrics
}
// GetLatencies implements metricsstore.Reader#GetLatencies
-func (m *ReadMetricsDecorator) GetLatencies(ctx context.Context, params *metricsstore.LatenciesQueryParameters) (*protometrics.MetricFamily, error) {
+func (m *ReadMetricsDecorator) GetLatencies(
+ ctx context.Context,
+ params *metricsstore.LatenciesQueryParameters,
+) (*protometrics.MetricFamily, error) {
start := time.Now()
retMe, err := m.reader.GetLatencies(ctx, params)
m.getLatenciesMetrics.emit(err, time.Since(start))
@@ -76,7 +102,10 @@ func (m *ReadMetricsDecorator) GetLatencies(ctx context.Context, params *metrics
}
// GetCallRates implements metricsstore.Reader#GetCallRates
-func (m *ReadMetricsDecorator) GetCallRates(ctx context.Context, params *metricsstore.CallRateQueryParameters) (*protometrics.MetricFamily, error) {
+func (m *ReadMetricsDecorator) GetCallRates(
+ ctx context.Context,
+ params *metricsstore.CallRateQueryParameters,
+) (*protometrics.MetricFamily, error) {
start := time.Now()
retMe, err := m.reader.GetCallRates(ctx, params)
m.getCallRatesMetrics.emit(err, time.Since(start))
@@ -84,7 +113,10 @@ func (m *ReadMetricsDecorator) GetCallRates(ctx context.Context, params *metrics
}
// GetErrorRates implements metricsstore.Reader#GetErrorRates
-func (m *ReadMetricsDecorator) GetErrorRates(ctx context.Context, params *metricsstore.ErrorRateQueryParameters) (*protometrics.MetricFamily, error) {
+func (m *ReadMetricsDecorator) GetErrorRates(
+ ctx context.Context,
+ params *metricsstore.ErrorRateQueryParameters,
+) (*protometrics.MetricFamily, error) {
start := time.Now()
retMe, err := m.reader.GetErrorRates(ctx, params)
m.getErrorRatesMetrics.emit(err, time.Since(start))
@@ -92,7 +124,10 @@ func (m *ReadMetricsDecorator) GetErrorRates(ctx context.Context, params *metric
}
// GetMinStepDuration implements metricsstore.Reader#GetMinStepDuration
-func (m *ReadMetricsDecorator) GetMinStepDuration(ctx context.Context, params *metricsstore.MinStepDurationQueryParameters) (time.Duration, error) {
+func (m *ReadMetricsDecorator) GetMinStepDuration(
+ ctx context.Context,
+ params *metricsstore.MinStepDurationQueryParameters,
+) (time.Duration, error) {
start := time.Now()
retMe, err := m.reader.GetMinStepDuration(ctx, params)
m.getMinStepDurationMetrics.emit(err, time.Since(start))
diff --git a/storage/metricsstore/metrics/decorator_test.go b/storage/metricsstore/metrics/decorator_test.go
index 55710f97894..a28bcae4a63 100644
--- a/storage/metricsstore/metrics/decorator_test.go
+++ b/storage/metricsstore/metrics/decorator_test.go
@@ -78,7 +78,14 @@ func TestSuccessfulUnderlyingCalls(t *testing.T) {
"latency|operation=get_latencies|result=err.P50",
}
- checkExpectedExistingAndNonExistentCounters(t, counters, wantCounts, gauges, wantExistingKeys, wantNonExistentKeys)
+ checkExpectedExistingAndNonExistentCounters(
+ t,
+ counters,
+ wantCounts,
+ gauges,
+ wantExistingKeys,
+ wantNonExistentKeys,
+ )
}
func checkExpectedExistingAndNonExistentCounters(t *testing.T,
@@ -151,7 +158,14 @@ func TestFailingUnderlyingCalls(t *testing.T) {
"latency|operation=get_error_rates|result=ok.P50",
}
- checkExpectedExistingAndNonExistentCounters(t, counters, wantCounts, gauges, wantExistingKeys, wantNonExistentKeys)
+ checkExpectedExistingAndNonExistentCounters(
+ t,
+ counters,
+ wantCounts,
+ gauges,
+ wantExistingKeys,
+ wantNonExistentKeys,
+ )
}
func TestMain(m *testing.M) {
diff --git a/storage/mocks/Factory.go b/storage/mocks/Factory.go
index 8f2c713ec1e..84cacaa626b 100644
--- a/storage/mocks/Factory.go
+++ b/storage/mocks/Factory.go
@@ -99,7 +99,10 @@ func (_m *Factory) CreateSpanWriter() (spanstore.Writer, error) {
}
// Initialize provides a mock function with given fields: metricsFactory, logger
-func (_m *Factory) Initialize(metricsFactory metrics.Factory, logger *zap.Logger) error {
+func (_m *Factory) Initialize(
+ metricsFactory metrics.Factory,
+ logger *zap.Logger,
+) error {
ret := _m.Called(metricsFactory, logger)
var r0 error
diff --git a/storage/samplingstore/interface.go b/storage/samplingstore/interface.go
index 7c10aab8f40..81f56c7b3bb 100644
--- a/storage/samplingstore/interface.go
+++ b/storage/samplingstore/interface.go
@@ -27,7 +27,11 @@ type Store interface {
InsertThroughput(throughput []*model.Throughput) error
// InsertProbabilitiesAndQPS inserts calculated sampling probabilities and measured qps into storage.
- InsertProbabilitiesAndQPS(hostname string, probabilities model.ServiceOperationProbabilities, qps model.ServiceOperationQPS) error
+ InsertProbabilitiesAndQPS(
+ hostname string,
+ probabilities model.ServiceOperationProbabilities,
+ qps model.ServiceOperationQPS,
+ ) error
// GetThroughput retrieves aggregated throughput for operations within a time range.
GetThroughput(start, end time.Time) ([]*model.Throughput, error)
diff --git a/storage/samplingstore/mocks/Store.go b/storage/samplingstore/mocks/Store.go
index ddfa6692c7f..7ecf1f4772f 100644
--- a/storage/samplingstore/mocks/Store.go
+++ b/storage/samplingstore/mocks/Store.go
@@ -39,7 +39,12 @@ func (_m *Store) InsertThroughput(throughput []*model.Throughput) error {
return r0
}
-func (_m *Store) InsertProbabilitiesAndQPS(hostname string, probabilities model.ServiceOperationProbabilities, qps model.ServiceOperationQPS) error {
+
+func (_m *Store) InsertProbabilitiesAndQPS(
+ hostname string,
+ probabilities model.ServiceOperationProbabilities,
+ qps model.ServiceOperationQPS,
+) error {
ret := _m.Called(hostname, probabilities, qps)
var r0 error
@@ -51,7 +56,11 @@ func (_m *Store) InsertProbabilitiesAndQPS(hostname string, probabilities model.
return r0
}
-func (_m *Store) GetThroughput(start time.Time, end time.Time) ([]*model.Throughput, error) {
+
+func (_m *Store) GetThroughput(
+ start time.Time,
+ end time.Time,
+) ([]*model.Throughput, error) {
ret := _m.Called(start, end)
var r0 []*model.Throughput
@@ -72,6 +81,7 @@ func (_m *Store) GetThroughput(start time.Time, end time.Time) ([]*model.Through
return r0, r1
}
+
func (_m *Store) GetLatestProbabilities() (model.ServiceOperationProbabilities, error) {
ret := _m.Called()
diff --git a/storage/spanstore/composite.go b/storage/spanstore/composite.go
index 68f9607448c..d72e7416a9f 100644
--- a/storage/spanstore/composite.go
+++ b/storage/spanstore/composite.go
@@ -35,7 +35,10 @@ func NewCompositeWriter(spanWriters ...Writer) *CompositeWriter {
}
// WriteSpan calls WriteSpan on each span writer. It will sum up failures, it is not transactional
-func (c *CompositeWriter) WriteSpan(ctx context.Context, span *model.Span) error {
+func (c *CompositeWriter) WriteSpan(
+ ctx context.Context,
+ span *model.Span,
+) error {
var errs []error
for _, writer := range c.spanWriters {
if err := writer.WriteSpan(ctx, span); err != nil {
diff --git a/storage/spanstore/composite_test.go b/storage/spanstore/composite_test.go
index 85aed7a98b4..fdecdd081cd 100644
--- a/storage/spanstore/composite_test.go
+++ b/storage/spanstore/composite_test.go
@@ -31,27 +31,47 @@ var errIWillAlwaysFail = errors.New("ErrProneWriteSpanStore will always fail")
type errProneWriteSpanStore struct{}
-func (*errProneWriteSpanStore) WriteSpan(ctx context.Context, span *model.Span) error {
+func (*errProneWriteSpanStore) WriteSpan(
+ ctx context.Context,
+ span *model.Span,
+) error {
return errIWillAlwaysFail
}
type noopWriteSpanStore struct{}
-func (*noopWriteSpanStore) WriteSpan(ctx context.Context, span *model.Span) error {
+func (*noopWriteSpanStore) WriteSpan(
+ ctx context.Context,
+ span *model.Span,
+) error {
return nil
}
func TestCompositeWriteSpanStoreSuccess(t *testing.T) {
- c := spanstore.NewCompositeWriter(&noopWriteSpanStore{}, &noopWriteSpanStore{})
+ c := spanstore.NewCompositeWriter(
+ &noopWriteSpanStore{},
+ &noopWriteSpanStore{},
+ )
require.NoError(t, c.WriteSpan(context.Background(), nil))
}
func TestCompositeWriteSpanStoreSecondFailure(t *testing.T) {
c := spanstore.NewCompositeWriter(&errProneWriteSpanStore{}, &errProneWriteSpanStore{})
- require.EqualError(t, c.WriteSpan(context.Background(), nil), fmt.Sprintf("%s\n%s", errIWillAlwaysFail, errIWillAlwaysFail))
+ require.EqualError(
+ t,
+ c.WriteSpan(context.Background(), nil),
+ fmt.Sprintf("%s\n%s", errIWillAlwaysFail, errIWillAlwaysFail),
+ )
}
func TestCompositeWriteSpanStoreFirstFailure(t *testing.T) {
- c := spanstore.NewCompositeWriter(&errProneWriteSpanStore{}, &noopWriteSpanStore{})
- require.EqualError(t, c.WriteSpan(context.Background(), nil), errIWillAlwaysFail.Error())
+ c := spanstore.NewCompositeWriter(
+ &errProneWriteSpanStore{},
+ &noopWriteSpanStore{},
+ )
+ require.EqualError(
+ t,
+ c.WriteSpan(context.Background(), nil),
+ errIWillAlwaysFail.Error(),
+ )
}
diff --git a/storage/spanstore/downsampling_writer.go b/storage/spanstore/downsampling_writer.go
index b6463edac81..35d97018690 100644
--- a/storage/spanstore/downsampling_writer.go
+++ b/storage/spanstore/downsampling_writer.go
@@ -57,18 +57,27 @@ type DownsamplingOptions struct {
}
// NewDownsamplingWriter creates a DownsamplingWriter.
-func NewDownsamplingWriter(spanWriter Writer, downsamplingOptions DownsamplingOptions) *DownsamplingWriter {
+func NewDownsamplingWriter(
+ spanWriter Writer,
+ downsamplingOptions DownsamplingOptions,
+) *DownsamplingWriter {
writeMetrics := &downsamplingWriterMetrics{}
metrics.Init(writeMetrics, downsamplingOptions.MetricsFactory, nil)
return &DownsamplingWriter{
- sampler: NewSampler(downsamplingOptions.Ratio, downsamplingOptions.HashSalt),
+ sampler: NewSampler(
+ downsamplingOptions.Ratio,
+ downsamplingOptions.HashSalt,
+ ),
spanWriter: spanWriter,
metrics: *writeMetrics,
}
}
// WriteSpan calls WriteSpan on wrapped span writer.
-func (ds *DownsamplingWriter) WriteSpan(ctx context.Context, span *model.Span) error {
+func (ds *DownsamplingWriter) WriteSpan(
+ ctx context.Context,
+ span *model.Span,
+) error {
if !ds.sampler.ShouldSample(span) {
// Drops spans when hashVal falls beyond computed threshold.
ds.metrics.SpansDropped.Inc(1)
diff --git a/storage/spanstore/downsampling_writer_benchmark_test.go b/storage/spanstore/downsampling_writer_benchmark_test.go
index 8ca05efc1a3..4cdad3321da 100644
--- a/storage/spanstore/downsampling_writer_benchmark_test.go
+++ b/storage/spanstore/downsampling_writer_benchmark_test.go
@@ -94,7 +94,10 @@ func BenchmarkDownsamplingWriter_RandomHash(b *testing.B) {
countSmallerThanRatio++
}
}
- fmt.Printf("Random hash ratio %f should be close to 0.5, inspect the implementation of hashBytes if not\n", math.Abs(float64(countSmallerThanRatio)/float64(numberActions)))
+ fmt.Printf(
+ "Random hash ratio %f should be close to 0.5, inspect the implementation of hashBytes if not\n",
+ math.Abs(float64(countSmallerThanRatio)/float64(numberActions)),
+ )
}
c.sampler.hasherPool.Put(h)
}
diff --git a/storage/spanstore/downsampling_writer_test.go b/storage/spanstore/downsampling_writer_test.go
index 5087015373d..db25b330c41 100644
--- a/storage/spanstore/downsampling_writer_test.go
+++ b/storage/spanstore/downsampling_writer_test.go
@@ -28,7 +28,10 @@ import (
type noopWriteSpanStore struct{}
-func (*noopWriteSpanStore) WriteSpan(ct context.Context, span *model.Span) error {
+func (*noopWriteSpanStore) WriteSpan(
+ ct context.Context,
+ span *model.Span,
+) error {
return nil
}
@@ -36,7 +39,10 @@ var errIWillAlwaysFail = errors.New("ErrProneWriteSpanStore will always fail")
type errorWriteSpanStore struct{}
-func (*errorWriteSpanStore) WriteSpan(ctx context.Context, span *model.Span) error {
+func (*errorWriteSpanStore) WriteSpan(
+ ctx context.Context,
+ span *model.Span,
+) error {
return errIWillAlwaysFail
}
diff --git a/storage/spanstore/interface.go b/storage/spanstore/interface.go
index 534cf8a2280..45f0797a927 100644
--- a/storage/spanstore/interface.go
+++ b/storage/spanstore/interface.go
@@ -44,7 +44,10 @@ type Reader interface {
// GetOperations returns all operation names for a given service
// known to the backend from spans within its retention period.
- GetOperations(ctx context.Context, query OperationQueryParameters) ([]Operation, error)
+ GetOperations(
+ ctx context.Context,
+ query OperationQueryParameters,
+ ) ([]Operation, error)
// FindTraces returns all traces matching query parameters. There's currently
// an implementation-dependent abiguity whether all query filters (such as
@@ -52,13 +55,19 @@ type Reader interface {
// by different spans.
//
// If no matching traces are found, the function returns (nil, nil).
- FindTraces(ctx context.Context, query *TraceQueryParameters) ([]*model.Trace, error)
+ FindTraces(
+ ctx context.Context,
+ query *TraceQueryParameters,
+ ) ([]*model.Trace, error)
// FindTraceIDs does the same search as FindTraces, but returns only the list
// of matching trace IDs.
//
// If no matching traces are found, the function returns (nil, nil).
- FindTraceIDs(ctx context.Context, query *TraceQueryParameters) ([]model.TraceID, error)
+ FindTraceIDs(
+ ctx context.Context,
+ query *TraceQueryParameters,
+ ) ([]model.TraceID, error)
}
// TraceQueryParameters contains parameters of a trace query.
diff --git a/storage/spanstore/metrics/decorator.go b/storage/spanstore/metrics/decorator.go
index 492c37bb1ba..a55f2f8ee57 100644
--- a/storage/spanstore/metrics/decorator.go
+++ b/storage/spanstore/metrics/decorator.go
@@ -35,11 +35,11 @@ type ReadMetricsDecorator struct {
}
type queryMetrics struct {
- Errors metrics.Counter `metric:"requests" tags:"result=err"`
- Successes metrics.Counter `metric:"requests" tags:"result=ok"`
+ Errors metrics.Counter `metric:"requests" tags:"result=err"`
+ Successes metrics.Counter `metric:"requests" tags:"result=ok"`
Responses metrics.Timer `metric:"responses"` // used as a histogram, not necessary for GetTrace
- ErrLatency metrics.Timer `metric:"latency" tags:"result=err"`
- OKLatency metrics.Timer `metric:"latency" tags:"result=ok"`
+ ErrLatency metrics.Timer `metric:"latency" tags:"result=err"`
+ OKLatency metrics.Timer `metric:"latency" tags:"result=ok"`
}
func (q *queryMetrics) emit(err error, latency time.Duration, responses int) {
@@ -54,26 +54,46 @@ func (q *queryMetrics) emit(err error, latency time.Duration, responses int) {
}
// NewReadMetricsDecorator returns a new ReadMetricsDecorator.
-func NewReadMetricsDecorator(spanReader spanstore.Reader, metricsFactory metrics.Factory) *ReadMetricsDecorator {
+func NewReadMetricsDecorator(
+ spanReader spanstore.Reader,
+ metricsFactory metrics.Factory,
+) *ReadMetricsDecorator {
return &ReadMetricsDecorator{
- spanReader: spanReader,
- findTracesMetrics: buildQueryMetrics("find_traces", metricsFactory),
- findTraceIDsMetrics: buildQueryMetrics("find_trace_ids", metricsFactory),
- getTraceMetrics: buildQueryMetrics("get_trace", metricsFactory),
- getServicesMetrics: buildQueryMetrics("get_services", metricsFactory),
- getOperationsMetrics: buildQueryMetrics("get_operations", metricsFactory),
+ spanReader: spanReader,
+ findTracesMetrics: buildQueryMetrics("find_traces", metricsFactory),
+ findTraceIDsMetrics: buildQueryMetrics(
+ "find_trace_ids",
+ metricsFactory,
+ ),
+ getTraceMetrics: buildQueryMetrics("get_trace", metricsFactory),
+ getServicesMetrics: buildQueryMetrics("get_services", metricsFactory),
+ getOperationsMetrics: buildQueryMetrics(
+ "get_operations",
+ metricsFactory,
+ ),
}
}
-func buildQueryMetrics(operation string, metricsFactory metrics.Factory) *queryMetrics {
+func buildQueryMetrics(
+ operation string,
+ metricsFactory metrics.Factory,
+) *queryMetrics {
qMetrics := &queryMetrics{}
- scoped := metricsFactory.Namespace(metrics.NSOptions{Name: "", Tags: map[string]string{"operation": operation}})
+ scoped := metricsFactory.Namespace(
+ metrics.NSOptions{
+ Name: "",
+ Tags: map[string]string{"operation": operation},
+ },
+ )
metrics.Init(qMetrics, scoped, nil)
return qMetrics
}
// FindTraces implements spanstore.Reader#FindTraces
-func (m *ReadMetricsDecorator) FindTraces(ctx context.Context, traceQuery *spanstore.TraceQueryParameters) ([]*model.Trace, error) {
+func (m *ReadMetricsDecorator) FindTraces(
+ ctx context.Context,
+ traceQuery *spanstore.TraceQueryParameters,
+) ([]*model.Trace, error) {
start := time.Now()
retMe, err := m.spanReader.FindTraces(ctx, traceQuery)
m.findTracesMetrics.emit(err, time.Since(start), len(retMe))
@@ -81,7 +101,10 @@ func (m *ReadMetricsDecorator) FindTraces(ctx context.Context, traceQuery *spans
}
// FindTraceIDs implements spanstore.Reader#FindTraceIDs
-func (m *ReadMetricsDecorator) FindTraceIDs(ctx context.Context, traceQuery *spanstore.TraceQueryParameters) ([]model.TraceID, error) {
+func (m *ReadMetricsDecorator) FindTraceIDs(
+ ctx context.Context,
+ traceQuery *spanstore.TraceQueryParameters,
+) ([]model.TraceID, error) {
start := time.Now()
retMe, err := m.spanReader.FindTraceIDs(ctx, traceQuery)
m.findTraceIDsMetrics.emit(err, time.Since(start), len(retMe))
@@ -89,7 +112,10 @@ func (m *ReadMetricsDecorator) FindTraceIDs(ctx context.Context, traceQuery *spa
}
// GetTrace implements spanstore.Reader#GetTrace
-func (m *ReadMetricsDecorator) GetTrace(ctx context.Context, traceID model.TraceID) (*model.Trace, error) {
+func (m *ReadMetricsDecorator) GetTrace(
+ ctx context.Context,
+ traceID model.TraceID,
+) (*model.Trace, error) {
start := time.Now()
retMe, err := m.spanReader.GetTrace(ctx, traceID)
m.getTraceMetrics.emit(err, time.Since(start), 1)
@@ -97,7 +123,9 @@ func (m *ReadMetricsDecorator) GetTrace(ctx context.Context, traceID model.Trace
}
// GetServices implements spanstore.Reader#GetServices
-func (m *ReadMetricsDecorator) GetServices(ctx context.Context) ([]string, error) {
+func (m *ReadMetricsDecorator) GetServices(
+ ctx context.Context,
+) ([]string, error) {
start := time.Now()
retMe, err := m.spanReader.GetServices(ctx)
m.getServicesMetrics.emit(err, time.Since(start), len(retMe))
diff --git a/storage/spanstore/metrics/decorator_test.go b/storage/spanstore/metrics/decorator_test.go
index 8afc6a921a9..7c5466661cd 100644
--- a/storage/spanstore/metrics/decorator_test.go
+++ b/storage/spanstore/metrics/decorator_test.go
@@ -36,11 +36,14 @@ func TestSuccessfulUnderlyingCalls(t *testing.T) {
mrs := metrics.NewReadMetricsDecorator(&mockReader, mf)
mockReader.On("GetServices", context.Background()).Return([]string{}, nil)
mrs.GetServices(context.Background())
- operationQuery := spanstore.OperationQueryParameters{ServiceName: "something"}
+ operationQuery := spanstore.OperationQueryParameters{
+ ServiceName: "something",
+ }
mockReader.On("GetOperations", context.Background(), operationQuery).
Return([]spanstore.Operation{}, nil)
mrs.GetOperations(context.Background(), operationQuery)
- mockReader.On("GetTrace", context.Background(), model.TraceID{}).Return(&model.Trace{}, nil)
+ mockReader.On("GetTrace", context.Background(), model.TraceID{}).
+ Return(&model.Trace{}, nil)
mrs.GetTrace(context.Background(), model.TraceID{})
mockReader.On("FindTraces", context.Background(), &spanstore.TraceQueryParameters{}).
Return([]*model.Trace{}, nil)
@@ -71,7 +74,14 @@ func TestSuccessfulUnderlyingCalls(t *testing.T) {
"latency|operation=get_operations|result=err.P50",
}
- checkExpectedExistingAndNonExistentCounters(t, counters, expecteds, gauges, existingKeys, nonExistentKeys)
+ checkExpectedExistingAndNonExistentCounters(
+ t,
+ counters,
+ expecteds,
+ gauges,
+ existingKeys,
+ nonExistentKeys,
+ )
}
func checkExpectedExistingAndNonExistentCounters(t *testing.T,
@@ -104,7 +114,9 @@ func TestFailingUnderlyingCalls(t *testing.T) {
mockReader.On("GetServices", context.Background()).
Return(nil, errors.New("Failure"))
mrs.GetServices(context.Background())
- operationQuery := spanstore.OperationQueryParameters{ServiceName: "something"}
+ operationQuery := spanstore.OperationQueryParameters{
+ ServiceName: "something",
+ }
mockReader.On("GetOperations", context.Background(), operationQuery).
Return(nil, errors.New("Failure"))
mrs.GetOperations(context.Background(), operationQuery)
@@ -141,5 +153,12 @@ func TestFailingUnderlyingCalls(t *testing.T) {
"latency|operation=query|result=ok.P50", // this is not exhaustive
}
- checkExpectedExistingAndNonExistentCounters(t, counters, expecteds, gauges, existingKeys, nonExistentKeys)
+ checkExpectedExistingAndNonExistentCounters(
+ t,
+ counters,
+ expecteds,
+ gauges,
+ existingKeys,
+ nonExistentKeys,
+ )
}
diff --git a/storage/spanstore/metrics/write_metrics.go b/storage/spanstore/metrics/write_metrics.go
index de56ed30e4d..4b6a55245bf 100644
--- a/storage/spanstore/metrics/write_metrics.go
+++ b/storage/spanstore/metrics/write_metrics.go
@@ -33,7 +33,11 @@ type WriteMetrics struct {
// NewWriteMetrics takes a metrics scope and creates a metrics struct
func NewWriteMetrics(factory metrics.Factory, tableName string) *WriteMetrics {
t := &WriteMetrics{}
- metrics.Init(t, factory.Namespace(metrics.NSOptions{Name: tableName, Tags: nil}), nil)
+ metrics.Init(
+ t,
+ factory.Namespace(metrics.NSOptions{Name: tableName, Tags: nil}),
+ nil,
+ )
return t
}
diff --git a/storage_v2/spanstore/reader.go b/storage_v2/spanstore/reader.go
index b7e9f78ca09..14e3129f6ab 100644
--- a/storage_v2/spanstore/reader.go
+++ b/storage_v2/spanstore/reader.go
@@ -21,7 +21,10 @@ type Reader interface {
// GetTrace retrieves the trace with a given id.
//
// If no spans are stored for this trace, it returns ErrTraceNotFound.
- GetTrace(ctx context.Context, traceID pcommon.TraceID) (ptrace.Traces, error)
+ GetTrace(
+ ctx context.Context,
+ traceID pcommon.TraceID,
+ ) (ptrace.Traces, error)
// GetServices returns all service names known to the backend from spans
// within its retention period.
@@ -29,7 +32,10 @@ type Reader interface {
// GetOperations returns all operation names for a given service
// known to the backend from spans within its retention period.
- GetOperations(ctx context.Context, query OperationQueryParameters) ([]Operation, error)
+ GetOperations(
+ ctx context.Context,
+ query OperationQueryParameters,
+ ) ([]Operation, error)
// FindTraces returns all traces matching query parameters. There's currently
// an implementation-dependent ambiguity whether all query filters (such as
@@ -37,13 +43,19 @@ type Reader interface {
// by different spans.
//
// If no matching traces are found, the function returns (nil, nil).
- FindTraces(ctx context.Context, query TraceQueryParameters) ([]ptrace.Traces, error)
+ FindTraces(
+ ctx context.Context,
+ query TraceQueryParameters,
+ ) ([]ptrace.Traces, error)
// FindTraceIDs does the same search as FindTraces, but returns only the list
// of matching trace IDs.
//
// If no matching traces are found, the function returns (nil, nil).
- FindTraceIDs(ctx context.Context, query TraceQueryParameters) ([]pcommon.TraceID, error)
+ FindTraceIDs(
+ ctx context.Context,
+ query TraceQueryParameters,
+ ) ([]pcommon.TraceID, error)
}
// TraceQueryParameters contains parameters of a trace query.