1
0
Fork 0

Improve tracing

This commit is contained in:
Michael 2019-06-28 00:16:04 +02:00 committed by Traefiker Bot
parent 4245096be4
commit 84d7c65039
23 changed files with 924 additions and 411 deletions

View file

@ -15,6 +15,7 @@ import (
"github.com/containous/traefik/pkg/provider/kubernetes/ingress"
traefiktls "github.com/containous/traefik/pkg/tls"
"github.com/containous/traefik/pkg/tracing/datadog"
"github.com/containous/traefik/pkg/tracing/haystack"
"github.com/containous/traefik/pkg/tracing/instana"
"github.com/containous/traefik/pkg/tracing/jaeger"
"github.com/containous/traefik/pkg/tracing/zipkin"
@ -223,7 +224,6 @@ func TestDo_globalConfiguration(t *testing.T) {
}
config.Tracing = &static.Tracing{
Backend: "myBackend",
ServiceName: "myServiceName",
SpanNameLimit: 3,
Jaeger: &jaeger.Config{
@ -253,6 +253,15 @@ func TestDo_globalConfiguration(t *testing.T) {
LocalAgentPort: 32,
LogLevel: "ggg",
},
Haystack: &haystack.Config{
LocalAgentHost: "fff",
LocalAgentPort: 32,
GlobalTag: "eee",
TraceIDHeaderName: "fff",
ParentIDHeaderName: "ggg",
SpanIDHeaderName: "hhh",
BaggagePrefixHeaderName: "iii",
},
}
config.HostResolver = &types.HostResolverConfig{

View file

@ -292,7 +292,6 @@ func Test_decodeFileToNode_Toml(t *testing.T) {
{Name: "MaxIdleConnsPerHost", Value: "42"},
{Name: "RootCAs", Value: "foobar,foobar"}}},
{Name: "Tracing", Children: []*parser.Node{
{Name: "Backend", Value: "foobar"},
{Name: "DataDog", Children: []*parser.Node{
{Name: "BagagePrefixHeaderName", Value: "foobar"},
{Name: "Debug", Value: "true"},
@ -302,6 +301,13 @@ func Test_decodeFileToNode_Toml(t *testing.T) {
{Name: "PrioritySampling", Value: "true"},
{Name: "SamplingPriorityHeaderName", Value: "foobar"},
{Name: "TraceIDHeaderName", Value: "foobar"}}},
{Name: "Haystack", Children: []*parser.Node{
{Name: "GlobalTag", Value: "foobar"},
{Name: "LocalAgentHost", Value: "foobar"},
{Name: "LocalAgentPort", Value: "42"},
{Name: "ParentIDHeaderName", Value: "foobar"},
{Name: "SpanIDHeaderName", Value: "foobar"},
{Name: "TraceIDHeaderName", Value: "foobar"}}},
{Name: "Instana", Children: []*parser.Node{
{Name: "LocalAgentHost", Value: "foobar"},
{Name: "LocalAgentPort", Value: "42"},
@ -561,7 +567,6 @@ func Test_decodeFileToNode_Yaml(t *testing.T) {
{Name: "MaxIdleConnsPerHost", Value: "42"},
{Name: "RootCAs", Value: "foobar,foobar"}}},
{Name: "Tracing", Children: []*parser.Node{
{Name: "Backend", Value: "foobar"},
{Name: "DataDog", Children: []*parser.Node{
{Name: "BagagePrefixHeaderName", Value: "foobar"},
{Name: "Debug", Value: "true"},
@ -571,6 +576,13 @@ func Test_decodeFileToNode_Yaml(t *testing.T) {
{Name: "PrioritySampling", Value: "true"},
{Name: "SamplingPriorityHeaderName", Value: "foobar"},
{Name: "TraceIDHeaderName", Value: "foobar"}}},
{Name: "Haystack", Children: []*parser.Node{
{Name: "GlobalTag", Value: "foobar"},
{Name: "LocalAgentHost", Value: "foobar"},
{Name: "LocalAgentPort", Value: "42"},
{Name: "ParentIDHeaderName", Value: "foobar"},
{Name: "SpanIDHeaderName", Value: "foobar"},
{Name: "TraceIDHeaderName", Value: "foobar"}}},
{Name: "Instana", Children: []*parser.Node{
{Name: "LocalAgentHost", Value: "foobar"},
{Name: "LocalAgentPort", Value: "42"},

View file

@ -205,7 +205,6 @@
name1 = "foobar"
[Tracing]
Backend = "foobar"
ServiceName = "foobar"
SpanNameLimit = 42
@ -240,6 +239,14 @@
LocalAgentPort = 42
LogLevel = "foobar"
[Tracing.Haystack]
GlobalTag = "foobar"
LocalAgentHost = "foobar"
LocalAgentPort = 42
ParentIDHeaderName = "foobar"
SpanIDHeaderName = "foobar"
TraceIDHeaderName = "foobar"
[HostResolver]
CnameFlattening = true
ResolvConfig = "foobar"

View file

@ -193,7 +193,6 @@ AccessLog:
name0: foobar
name1: foobar
Tracing:
Backend: foobar
ServiceName: foobar
SpanNameLimit: 42
Jaeger:
@ -223,6 +222,13 @@ Tracing:
LocalAgentHost: foobar
LocalAgentPort: 42
LogLevel: foobar
Haystack:
GlobalTag: foobar
LocalAgentHost: foobar
LocalAgentPort: 42
ParentIDHeaderName: foobar
TraceIDHeaderName: foobar
SpanIDHeaderName: foobar
HostResolver:
CnameFlattening: true
ResolvConfig: foobar

View file

@ -24,7 +24,6 @@ import (
"github.com/containous/traefik/pkg/types"
assetfs "github.com/elazarl/go-bindata-assetfs"
"github.com/go-acme/lego/challenge/dns01"
jaegercli "github.com/uber/jaeger-client-go"
)
const (
@ -130,7 +129,6 @@ func (a *LifeCycle) SetDefaults() {
// Tracing holds the tracing configuration.
type Tracing struct {
Backend string `description:"Selects the tracking backend ('jaeger','zipkin','datadog','instana')." export:"true"`
ServiceName string `description:"Set the name for this service." export:"true"`
SpanNameLimit int `description:"Set the maximum character limit for Span names (default 0 = no limit)." export:"true"`
Jaeger *jaeger.Config `description:"Settings for jaeger." label:"allowEmpty"`
@ -142,7 +140,6 @@ type Tracing struct {
// SetDefaults sets the default values.
func (t *Tracing) SetDefaults() {
t.Backend = "jaeger"
t.ServiceName = "traefik"
t.SpanNameLimit = 0
}
@ -198,103 +195,6 @@ func (c *Configuration) SetEffectiveConfiguration(configFile string) {
}
c.initACMEProvider()
c.initTracing()
}
func (c *Configuration) initTracing() {
if c.Tracing != nil {
switch c.Tracing.Backend {
case jaeger.Name:
if c.Tracing.Jaeger == nil {
c.Tracing.Jaeger = &jaeger.Config{
SamplingServerURL: "http://localhost:5778/sampling",
SamplingType: "const",
SamplingParam: 1.0,
LocalAgentHostPort: "127.0.0.1:6831",
Propagation: "jaeger",
Gen128Bit: false,
TraceContextHeaderName: jaegercli.TraceContextHeaderName,
}
}
if c.Tracing.Zipkin != nil {
log.Warn("Zipkin configuration will be ignored")
c.Tracing.Zipkin = nil
}
if c.Tracing.DataDog != nil {
log.Warn("DataDog configuration will be ignored")
c.Tracing.DataDog = nil
}
if c.Tracing.Instana != nil {
log.Warn("Instana configuration will be ignored")
c.Tracing.Instana = nil
}
case zipkin.Name:
if c.Tracing.Zipkin == nil {
c.Tracing.Zipkin = &zipkin.Config{
HTTPEndpoint: "http://localhost:9411/api/v1/spans",
SameSpan: false,
ID128Bit: true,
Debug: false,
SampleRate: 1.0,
}
}
if c.Tracing.Jaeger != nil {
log.Warn("Jaeger configuration will be ignored")
c.Tracing.Jaeger = nil
}
if c.Tracing.DataDog != nil {
log.Warn("DataDog configuration will be ignored")
c.Tracing.DataDog = nil
}
if c.Tracing.Instana != nil {
log.Warn("Instana configuration will be ignored")
c.Tracing.Instana = nil
}
case datadog.Name:
if c.Tracing.DataDog == nil {
c.Tracing.DataDog = &datadog.Config{
LocalAgentHostPort: "localhost:8126",
GlobalTag: "",
Debug: false,
}
}
if c.Tracing.Zipkin != nil {
log.Warn("Zipkin configuration will be ignored")
c.Tracing.Zipkin = nil
}
if c.Tracing.Jaeger != nil {
log.Warn("Jaeger configuration will be ignored")
c.Tracing.Jaeger = nil
}
if c.Tracing.Instana != nil {
log.Warn("Instana configuration will be ignored")
c.Tracing.Instana = nil
}
case instana.Name:
if c.Tracing.Instana == nil {
c.Tracing.Instana = &instana.Config{
LocalAgentHost: "localhost",
LocalAgentPort: 42699,
LogLevel: "info",
}
}
if c.Tracing.Zipkin != nil {
log.Warn("Zipkin configuration will be ignored")
c.Tracing.Zipkin = nil
}
if c.Tracing.Jaeger != nil {
log.Warn("Jaeger configuration will be ignored")
c.Tracing.Jaeger = nil
}
if c.Tracing.DataDog != nil {
log.Warn("DataDog configuration will be ignored")
c.Tracing.DataDog = nil
}
default:
log.Warnf("Unknown tracer %q", c.Tracing.Backend)
return
}
}
}
// FIXME handle on new configuration ACME struct

View file

@ -20,10 +20,7 @@ import (
"github.com/containous/traefik/pkg/server/middleware"
"github.com/containous/traefik/pkg/tls"
"github.com/containous/traefik/pkg/tracing"
"github.com/containous/traefik/pkg/tracing/datadog"
"github.com/containous/traefik/pkg/tracing/instana"
"github.com/containous/traefik/pkg/tracing/jaeger"
"github.com/containous/traefik/pkg/tracing/zipkin"
"github.com/containous/traefik/pkg/types"
)
@ -53,20 +50,52 @@ type RouteAppenderFactory interface {
NewAppender(ctx context.Context, middlewaresBuilder *middleware.Builder, runtimeConfiguration *config.RuntimeConfiguration) types.RouteAppender
}
func setupTracing(conf *static.Tracing) tracing.TrackingBackend {
switch conf.Backend {
case jaeger.Name:
return conf.Jaeger
case zipkin.Name:
return conf.Zipkin
case datadog.Name:
return conf.DataDog
case instana.Name:
return conf.Instana
default:
log.WithoutContext().Warnf("Could not initialize tracing: unknown tracer %q", conf.Backend)
return nil
func setupTracing(conf *static.Tracing) tracing.Backend {
var backend tracing.Backend
if conf.Jaeger != nil {
backend = conf.Jaeger
}
if conf.Zipkin != nil {
if backend != nil {
log.WithoutContext().Error("Multiple tracing backend are not supported: cannot create Zipkin backend.")
} else {
backend = conf.Zipkin
}
}
if conf.DataDog != nil {
if backend != nil {
log.WithoutContext().Error("Multiple tracing backend are not supported: cannot create DataDog backend.")
} else {
backend = conf.DataDog
}
}
if conf.Instana != nil {
if backend != nil {
log.WithoutContext().Error("Multiple tracing backend are not supported: cannot create Instana backend.")
} else {
backend = conf.Instana
}
}
if conf.Haystack != nil {
if backend != nil {
log.WithoutContext().Error("Multiple tracing backend are not supported: cannot create Haystack backend.")
} else {
backend = conf.Haystack
}
}
if backend == nil {
log.WithoutContext().Debug("Could not initialize tracing, use Jaeger by default")
backend := &jaeger.Config{}
backend.SetDefaults()
}
return backend
}
// NewServer returns an initialized Server.
@ -100,11 +129,12 @@ func NewServer(staticConfiguration static.Configuration, provider provider.Provi
server.routinesPool = safe.NewPool(context.Background())
if staticConfiguration.Tracing != nil {
trackingBackend := setupTracing(staticConfiguration.Tracing)
var err error
server.tracer, err = tracing.NewTracing(staticConfiguration.Tracing.ServiceName, staticConfiguration.Tracing.SpanNameLimit, trackingBackend)
if err != nil {
log.WithoutContext().Warnf("Unable to create tracer: %v", err)
tracingBackend := setupTracing(staticConfiguration.Tracing)
if tracingBackend != nil {
server.tracer, err = tracing.NewTracing(staticConfiguration.Tracing.ServiceName, staticConfiguration.Tracing.SpanNameLimit, tracingBackend)
if err != nil {
log.WithoutContext().Warnf("Unable to create tracer: %v", err)
}
}
}

View file

@ -21,7 +21,7 @@ type Config struct {
TraceIDHeaderName string `description:"Specifies the header name that will be used to store the trace ID." export:"true"`
ParentIDHeaderName string `description:"Specifies the header name that will be used to store the parent ID." export:"true"`
SpanIDHeaderName string `description:"Specifies the header name that will be used to store the span ID." export:"true"`
BaggagePrefixHeaderName string `description:"specifies the header name prefix that will be used to store baggage items in a map." export:"true"`
BaggagePrefixHeaderName string `description:"Specifies the header name prefix that will be used to store baggage items in a map." export:"true"`
}
// SetDefaults sets the default values.

View file

@ -38,8 +38,8 @@ func FromContext(ctx context.Context) (*Tracing, error) {
return tracer, nil
}
// TrackingBackend is an abstraction for tracking backend (Jaeger, Zipkin, ...).
type TrackingBackend interface {
// Backend is an abstraction for tracking backend (Jaeger, Zipkin, ...).
type Backend interface {
Setup(componentName string) (opentracing.Tracer, io.Closer, error)
}
@ -53,14 +53,14 @@ type Tracing struct {
}
// NewTracing Creates a Tracing.
func NewTracing(serviceName string, spanNameLimit int, trackingBackend TrackingBackend) (*Tracing, error) {
func NewTracing(serviceName string, spanNameLimit int, tracingBackend Backend) (*Tracing, error) {
tracing := &Tracing{
ServiceName: serviceName,
SpanNameLimit: spanNameLimit,
}
var err error
tracing.tracer, tracing.closer, err = trackingBackend.Setup(serviceName)
tracing.tracer, tracing.closer, err = tracingBackend.Setup(serviceName)
if err != nil {
return nil, err
}