Fix nil value when tracing is enabled
This commit is contained in:
parent
0e3d1e1503
commit
8519b0d353
4 changed files with 165 additions and 13 deletions
|
@ -11,6 +11,8 @@ import (
|
||||||
"github.com/containous/traefik/api"
|
"github.com/containous/traefik/api"
|
||||||
"github.com/containous/traefik/log"
|
"github.com/containous/traefik/log"
|
||||||
"github.com/containous/traefik/middlewares/tracing"
|
"github.com/containous/traefik/middlewares/tracing"
|
||||||
|
"github.com/containous/traefik/middlewares/tracing/jaeger"
|
||||||
|
"github.com/containous/traefik/middlewares/tracing/zipkin"
|
||||||
"github.com/containous/traefik/ping"
|
"github.com/containous/traefik/ping"
|
||||||
acmeprovider "github.com/containous/traefik/provider/acme"
|
acmeprovider "github.com/containous/traefik/provider/acme"
|
||||||
"github.com/containous/traefik/provider/boltdb"
|
"github.com/containous/traefik/provider/boltdb"
|
||||||
|
@ -313,6 +315,43 @@ func (gc *GlobalConfiguration) SetEffectiveConfiguration(configFile string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
gc.initACMEProvider()
|
gc.initACMEProvider()
|
||||||
|
gc.initTracing()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gc *GlobalConfiguration) initTracing() {
|
||||||
|
if gc.Tracing != nil {
|
||||||
|
switch gc.Tracing.Backend {
|
||||||
|
case jaeger.Name:
|
||||||
|
if gc.Tracing.Jaeger == nil {
|
||||||
|
gc.Tracing.Jaeger = &jaeger.Config{
|
||||||
|
SamplingServerURL: "http://localhost:5778/sampling",
|
||||||
|
SamplingType: "const",
|
||||||
|
SamplingParam: 1.0,
|
||||||
|
LocalAgentHostPort: "127.0.0.1:6832",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if gc.Tracing.Zipkin != nil {
|
||||||
|
log.Warn("Zipkin configuration will be ignored")
|
||||||
|
gc.Tracing.Zipkin = nil
|
||||||
|
}
|
||||||
|
case zipkin.Name:
|
||||||
|
if gc.Tracing.Zipkin == nil {
|
||||||
|
gc.Tracing.Zipkin = &zipkin.Config{
|
||||||
|
HTTPEndpoint: "http://localhost:9411/api/v1/spans",
|
||||||
|
SameSpan: false,
|
||||||
|
ID128Bit: true,
|
||||||
|
Debug: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if gc.Tracing.Jaeger != nil {
|
||||||
|
log.Warn("Jaeger configuration will be ignored")
|
||||||
|
gc.Tracing.Jaeger = nil
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
log.Warnf("Unknown tracer %q", gc.Tracing.Backend)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gc *GlobalConfiguration) initACMEProvider() {
|
func (gc *GlobalConfiguration) initACMEProvider() {
|
||||||
|
|
|
@ -5,14 +5,18 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/containous/flaeg"
|
"github.com/containous/flaeg"
|
||||||
|
"github.com/containous/traefik/middlewares/tracing"
|
||||||
|
"github.com/containous/traefik/middlewares/tracing/jaeger"
|
||||||
|
"github.com/containous/traefik/middlewares/tracing/zipkin"
|
||||||
"github.com/containous/traefik/provider"
|
"github.com/containous/traefik/provider"
|
||||||
"github.com/containous/traefik/provider/file"
|
"github.com/containous/traefik/provider/file"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
const defaultConfigFile = "traefik.toml"
|
const defaultConfigFile = "traefik.toml"
|
||||||
|
|
||||||
func TestSetEffectiveConfigurationGraceTimeout(t *testing.T) {
|
func TestSetEffectiveConfigurationGraceTimeout(t *testing.T) {
|
||||||
tests := []struct {
|
testCases := []struct {
|
||||||
desc string
|
desc string
|
||||||
legacyGraceTimeout time.Duration
|
legacyGraceTimeout time.Duration
|
||||||
lifeCycleGraceTimeout time.Duration
|
lifeCycleGraceTimeout time.Duration
|
||||||
|
@ -37,10 +41,11 @@ func TestSetEffectiveConfigurationGraceTimeout(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range testCases {
|
||||||
test := test
|
test := test
|
||||||
t.Run(test.desc, func(t *testing.T) {
|
t.Run(test.desc, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
gc := &GlobalConfiguration{
|
gc := &GlobalConfiguration{
|
||||||
GraceTimeOut: flaeg.Duration(test.legacyGraceTimeout),
|
GraceTimeOut: flaeg.Duration(test.legacyGraceTimeout),
|
||||||
}
|
}
|
||||||
|
@ -52,17 +57,14 @@ func TestSetEffectiveConfigurationGraceTimeout(t *testing.T) {
|
||||||
|
|
||||||
gc.SetEffectiveConfiguration(defaultConfigFile)
|
gc.SetEffectiveConfiguration(defaultConfigFile)
|
||||||
|
|
||||||
gotGraceTimeout := time.Duration(gc.LifeCycle.GraceTimeOut)
|
assert.Equal(t, test.wantGraceTimeout, time.Duration(gc.LifeCycle.GraceTimeOut))
|
||||||
if gotGraceTimeout != test.wantGraceTimeout {
|
|
||||||
t.Fatalf("got effective grace timeout %d, want %d", gotGraceTimeout, test.wantGraceTimeout)
|
|
||||||
}
|
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSetEffectiveConfigurationFileProviderFilename(t *testing.T) {
|
func TestSetEffectiveConfigurationFileProviderFilename(t *testing.T) {
|
||||||
tests := []struct {
|
testCases := []struct {
|
||||||
desc string
|
desc string
|
||||||
fileProvider *file.Provider
|
fileProvider *file.Provider
|
||||||
wantFileProviderFilename string
|
wantFileProviderFilename string
|
||||||
|
@ -84,20 +86,128 @@ func TestSetEffectiveConfigurationFileProviderFilename(t *testing.T) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range testCases {
|
||||||
test := test
|
test := test
|
||||||
t.Run(test.desc, func(t *testing.T) {
|
t.Run(test.desc, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
gc := &GlobalConfiguration{
|
gc := &GlobalConfiguration{
|
||||||
File: test.fileProvider,
|
File: test.fileProvider,
|
||||||
}
|
}
|
||||||
|
|
||||||
gc.SetEffectiveConfiguration(defaultConfigFile)
|
gc.SetEffectiveConfiguration(defaultConfigFile)
|
||||||
|
|
||||||
gotFileProviderFilename := gc.File.Filename
|
assert.Equal(t, test.wantFileProviderFilename, gc.File.Filename)
|
||||||
if gotFileProviderFilename != test.wantFileProviderFilename {
|
})
|
||||||
t.Fatalf("got file provider file name %q, want %q", gotFileProviderFilename, test.wantFileProviderFilename)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSetEffectiveConfigurationTracing(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
desc string
|
||||||
|
tracing *tracing.Tracing
|
||||||
|
expected *tracing.Tracing
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
desc: "no tracing configuration",
|
||||||
|
tracing: &tracing.Tracing{},
|
||||||
|
expected: &tracing.Tracing{},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "tracing bad backend name",
|
||||||
|
tracing: &tracing.Tracing{
|
||||||
|
Backend: "powpow",
|
||||||
|
},
|
||||||
|
expected: &tracing.Tracing{
|
||||||
|
Backend: "powpow",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "tracing jaeger backend name",
|
||||||
|
tracing: &tracing.Tracing{
|
||||||
|
Backend: "jaeger",
|
||||||
|
Zipkin: &zipkin.Config{
|
||||||
|
HTTPEndpoint: "http://localhost:9411/api/v1/spans",
|
||||||
|
SameSpan: false,
|
||||||
|
ID128Bit: true,
|
||||||
|
Debug: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expected: &tracing.Tracing{
|
||||||
|
Backend: "jaeger",
|
||||||
|
Jaeger: &jaeger.Config{
|
||||||
|
SamplingServerURL: "http://localhost:5778/sampling",
|
||||||
|
SamplingType: "const",
|
||||||
|
SamplingParam: 1.0,
|
||||||
|
LocalAgentHostPort: "127.0.0.1:6832",
|
||||||
|
},
|
||||||
|
Zipkin: nil,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "tracing zipkin backend name",
|
||||||
|
tracing: &tracing.Tracing{
|
||||||
|
Backend: "zipkin",
|
||||||
|
Jaeger: &jaeger.Config{
|
||||||
|
SamplingServerURL: "http://localhost:5778/sampling",
|
||||||
|
SamplingType: "const",
|
||||||
|
SamplingParam: 1.0,
|
||||||
|
LocalAgentHostPort: "127.0.0.1:6832",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expected: &tracing.Tracing{
|
||||||
|
Backend: "zipkin",
|
||||||
|
Jaeger: nil,
|
||||||
|
Zipkin: &zipkin.Config{
|
||||||
|
HTTPEndpoint: "http://localhost:9411/api/v1/spans",
|
||||||
|
SameSpan: false,
|
||||||
|
ID128Bit: true,
|
||||||
|
Debug: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: "tracing zipkin backend name value override",
|
||||||
|
tracing: &tracing.Tracing{
|
||||||
|
Backend: "zipkin",
|
||||||
|
Jaeger: &jaeger.Config{
|
||||||
|
SamplingServerURL: "http://localhost:5778/sampling",
|
||||||
|
SamplingType: "const",
|
||||||
|
SamplingParam: 1.0,
|
||||||
|
LocalAgentHostPort: "127.0.0.1:6832",
|
||||||
|
},
|
||||||
|
Zipkin: &zipkin.Config{
|
||||||
|
HTTPEndpoint: "http://powpow:9411/api/v1/spans",
|
||||||
|
SameSpan: true,
|
||||||
|
ID128Bit: true,
|
||||||
|
Debug: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expected: &tracing.Tracing{
|
||||||
|
Backend: "zipkin",
|
||||||
|
Jaeger: nil,
|
||||||
|
Zipkin: &zipkin.Config{
|
||||||
|
HTTPEndpoint: "http://powpow:9411/api/v1/spans",
|
||||||
|
SameSpan: true,
|
||||||
|
ID128Bit: true,
|
||||||
|
Debug: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, test := range testCases {
|
||||||
|
test := test
|
||||||
|
t.Run(test.desc, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
gc := &GlobalConfiguration{
|
||||||
|
Tracing: test.tracing,
|
||||||
|
}
|
||||||
|
|
||||||
|
gc.SetEffectiveConfiguration(defaultConfigFile)
|
||||||
|
|
||||||
|
assert.Equal(t, test.expected, gc.Tracing)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,7 @@ func (c *Config) Setup(componentName string) (opentracing.Tracer, io.Closer, err
|
||||||
log.Warnf("Could not initialize jaeger tracer: %s", err.Error())
|
log.Warnf("Could not initialize jaeger tracer: %s", err.Error())
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
log.Debugf("jaeger tracer configured", err)
|
log.Debug("Jaeger tracer configured")
|
||||||
|
|
||||||
return opentracing.GlobalTracer(), closer, nil
|
return opentracing.GlobalTracer(), closer, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package zipkin
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
|
"github.com/containous/traefik/log"
|
||||||
opentracing "github.com/opentracing/opentracing-go"
|
opentracing "github.com/opentracing/opentracing-go"
|
||||||
zipkin "github.com/openzipkin/zipkin-go-opentracing"
|
zipkin "github.com/openzipkin/zipkin-go-opentracing"
|
||||||
)
|
)
|
||||||
|
@ -39,5 +40,7 @@ func (c *Config) Setup(serviceName string) (opentracing.Tracer, io.Closer, error
|
||||||
// Without this, child spans are getting the NOOP tracer
|
// Without this, child spans are getting the NOOP tracer
|
||||||
opentracing.SetGlobalTracer(tracer)
|
opentracing.SetGlobalTracer(tracer)
|
||||||
|
|
||||||
|
log.Debug("Zipkin tracer configured")
|
||||||
|
|
||||||
return tracer, collector, nil
|
return tracer, collector, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue