From 847621bc5dedfde19793e06cacb4d0fbfaeb3c68 Mon Sep 17 00:00:00 2001 From: Mark Haines Date: Thu, 28 Sep 2017 17:00:23 +0100 Subject: [PATCH] Add config for setting up a jaeger opentracing reporter (#271) * Add config for setting up a jaeger opentracing reporter * Remove redundant comment --- dendrite-config.yaml | 8 +++++ .../cmd/dendrite-client-api-server/main.go | 6 ++++ .../dendrite-federation-api-server/main.go | 6 ++++ .../dendrite-federation-sender-server/main.go | 6 ++++ .../cmd/dendrite-media-api-server/main.go | 6 ++++ .../cmd/dendrite-monolith-server/main.go | 6 ++++ .../dendrite-public-rooms-api-server/main.go | 6 ++++ .../dendrite/cmd/dendrite-room-server/main.go | 6 ++++ .../cmd/dendrite-sync-api-server/main.go | 6 ++++ .../dendrite/common/config/config.go | 33 +++++++++++++++++++ 10 files changed, 89 insertions(+) diff --git a/dendrite-config.yaml b/dendrite-config.yaml index c94960a4..1e92f0fd 100644 --- a/dendrite-config.yaml +++ b/dendrite-config.yaml @@ -91,3 +91,11 @@ listen: media_api: "localhost:7774" public_rooms_api: "localhost:7775" federation_sender: "localhost:7776" + +# The configuration for tracing the dendrite components. +tracing: + # Config for the jaeger opentracing reporter. + # See https://godoc.org/github.com/uber/jaeger-client-go/config#Configuration + # for documtation. + jaeger: + disabled: true diff --git a/src/github.com/matrix-org/dendrite/cmd/dendrite-client-api-server/main.go b/src/github.com/matrix-org/dendrite/cmd/dendrite-client-api-server/main.go index 630443d3..c53735aa 100644 --- a/src/github.com/matrix-org/dendrite/cmd/dendrite-client-api-server/main.go +++ b/src/github.com/matrix-org/dendrite/cmd/dendrite-client-api-server/main.go @@ -51,6 +51,12 @@ func main() { log.Fatalf("Invalid config file: %s", err) } + closer, err := cfg.SetupTracing("DendriteClientAPI") + if err != nil { + log.WithError(err).Fatalf("Failed to start tracer") + } + defer closer.Close() // nolint: errcheck + queryAPI := api.NewRoomserverQueryAPIHTTP(cfg.RoomServerURL(), nil) aliasAPI := api.NewRoomserverAliasAPIHTTP(cfg.RoomServerURL(), nil) inputAPI := api.NewRoomserverInputAPIHTTP(cfg.RoomServerURL(), nil) diff --git a/src/github.com/matrix-org/dendrite/cmd/dendrite-federation-api-server/main.go b/src/github.com/matrix-org/dendrite/cmd/dendrite-federation-api-server/main.go index b287ea62..83ac91ea 100644 --- a/src/github.com/matrix-org/dendrite/cmd/dendrite-federation-api-server/main.go +++ b/src/github.com/matrix-org/dendrite/cmd/dendrite-federation-api-server/main.go @@ -50,6 +50,12 @@ func main() { log.Fatalf("Invalid config file: %s", err) } + closer, err := cfg.SetupTracing("DendriteFederationAPI") + if err != nil { + log.WithError(err).Fatalf("Failed to start tracer") + } + defer closer.Close() // nolint: errcheck + federation := gomatrixserverlib.NewFederationClient( cfg.Matrix.ServerName, cfg.Matrix.KeyID, cfg.Matrix.PrivateKey, ) diff --git a/src/github.com/matrix-org/dendrite/cmd/dendrite-federation-sender-server/main.go b/src/github.com/matrix-org/dendrite/cmd/dendrite-federation-sender-server/main.go index dfc2dc2f..0b5a73ee 100644 --- a/src/github.com/matrix-org/dendrite/cmd/dendrite-federation-sender-server/main.go +++ b/src/github.com/matrix-org/dendrite/cmd/dendrite-federation-sender-server/main.go @@ -47,6 +47,12 @@ func main() { log.Fatalf("Invalid config file: %s", err) } + closer, err := cfg.SetupTracing("DendriteFederationSender") + if err != nil { + log.WithError(err).Fatalf("Failed to start tracer") + } + defer closer.Close() // nolint: errcheck + kafkaConsumer, err := sarama.NewConsumer(cfg.Kafka.Addresses, nil) if err != nil { log.WithFields(log.Fields{ diff --git a/src/github.com/matrix-org/dendrite/cmd/dendrite-media-api-server/main.go b/src/github.com/matrix-org/dendrite/cmd/dendrite-media-api-server/main.go index ccbc5681..1e8b86c4 100644 --- a/src/github.com/matrix-org/dendrite/cmd/dendrite-media-api-server/main.go +++ b/src/github.com/matrix-org/dendrite/cmd/dendrite-media-api-server/main.go @@ -48,6 +48,12 @@ func main() { log.Fatalf("Invalid config file: %s", err) } + closer, err := cfg.SetupTracing("DendriteMediaAPI") + if err != nil { + log.WithError(err).Fatalf("Failed to start tracer") + } + defer closer.Close() // nolint: errcheck + db, err := storage.Open(string(cfg.Database.MediaAPI)) if err != nil { log.WithError(err).Panic("Failed to open database") diff --git a/src/github.com/matrix-org/dendrite/cmd/dendrite-monolith-server/main.go b/src/github.com/matrix-org/dendrite/cmd/dendrite-monolith-server/main.go index 11920b8d..811c708a 100644 --- a/src/github.com/matrix-org/dendrite/cmd/dendrite-monolith-server/main.go +++ b/src/github.com/matrix-org/dendrite/cmd/dendrite-monolith-server/main.go @@ -83,6 +83,12 @@ func main() { log.Fatalf("Invalid config file: %s", err) } + closer, err := cfg.SetupTracing("DendriteMonolith") + if err != nil { + log.WithError(err).Fatalf("Failed to start tracer") + } + defer closer.Close() // nolint: errcheck + m := newMonolith(cfg) m.setupDatabases() m.setupFederation() diff --git a/src/github.com/matrix-org/dendrite/cmd/dendrite-public-rooms-api-server/main.go b/src/github.com/matrix-org/dendrite/cmd/dendrite-public-rooms-api-server/main.go index c8e705f9..807aa0ca 100644 --- a/src/github.com/matrix-org/dendrite/cmd/dendrite-public-rooms-api-server/main.go +++ b/src/github.com/matrix-org/dendrite/cmd/dendrite-public-rooms-api-server/main.go @@ -47,6 +47,12 @@ func main() { log.Fatalf("Invalid config file: %s", err) } + closer, err := cfg.SetupTracing("DendritePublicRoomsAPI") + if err != nil { + log.WithError(err).Fatalf("Failed to start tracer") + } + defer closer.Close() // nolint: errcheck + queryAPI := api.NewRoomserverQueryAPIHTTP(cfg.RoomServerURL(), nil) db, err := storage.NewPublicRoomsServerDatabase(string(cfg.Database.PublicRoomsAPI)) diff --git a/src/github.com/matrix-org/dendrite/cmd/dendrite-room-server/main.go b/src/github.com/matrix-org/dendrite/cmd/dendrite-room-server/main.go index 9da258c0..02988838 100644 --- a/src/github.com/matrix-org/dendrite/cmd/dendrite-room-server/main.go +++ b/src/github.com/matrix-org/dendrite/cmd/dendrite-room-server/main.go @@ -49,6 +49,12 @@ func main() { log.Fatalf("Invalid config file: %s", err) } + closer, err := cfg.SetupTracing("DendriteRoomServer") + if err != nil { + log.WithError(err).Fatalf("Failed to start tracer") + } + defer closer.Close() // nolint: errcheck + db, err := storage.Open(string(cfg.Database.RoomServer)) if err != nil { panic(err) diff --git a/src/github.com/matrix-org/dendrite/cmd/dendrite-sync-api-server/main.go b/src/github.com/matrix-org/dendrite/cmd/dendrite-sync-api-server/main.go index b5778631..ec6eebb6 100644 --- a/src/github.com/matrix-org/dendrite/cmd/dendrite-sync-api-server/main.go +++ b/src/github.com/matrix-org/dendrite/cmd/dendrite-sync-api-server/main.go @@ -51,6 +51,12 @@ func main() { log.Fatalf("Invalid config file: %s", err) } + closer, err := cfg.SetupTracing("DendriteSyncAPI") + if err != nil { + log.WithError(err).Fatalf("Failed to start tracer") + } + defer closer.Close() // nolint: errcheck + queryAPI := api.NewRoomserverQueryAPIHTTP(cfg.RoomServerURL(), nil) db, err := storage.NewSyncServerDatabase(string(cfg.Database.SyncAPI)) diff --git a/src/github.com/matrix-org/dendrite/common/config/config.go b/src/github.com/matrix-org/dendrite/common/config/config.go index 2324d513..2d347b59 100644 --- a/src/github.com/matrix-org/dendrite/common/config/config.go +++ b/src/github.com/matrix-org/dendrite/common/config/config.go @@ -19,14 +19,19 @@ import ( "crypto/sha256" "encoding/pem" "fmt" + "io" "io/ioutil" "path/filepath" "strings" "time" + "github.com/Sirupsen/logrus" "github.com/matrix-org/gomatrixserverlib" "golang.org/x/crypto/ed25519" "gopkg.in/yaml.v2" + + jaegerconfig "github.com/uber/jaeger-client-go/config" + jaegermetrics "github.com/uber/jaeger-lib/metrics" ) // Version is the current version of the config format. @@ -156,6 +161,12 @@ type Dendrite struct { FederationSender Address `yaml:"federation_sender"` PublicRoomsAPI Address `yaml:"public_rooms_api"` } `yaml:"listen"` + + // The config for tracing the dendrite servers. + Tracing struct { + // The config for the jaeger opentracing reporter. + Jaeger jaegerconfig.Configuration `yaml:"jaeger"` + } } // A Path on the filesystem. @@ -429,3 +440,25 @@ func (config *Dendrite) RoomServerURL() string { // internet for an internal API. return "http://" + string(config.Listen.RoomServer) } + +// SetupTracing configures the opentracing using the supplied configuration. +func (config *Dendrite) SetupTracing(serviceName string) (closer io.Closer, err error) { + return config.Tracing.Jaeger.InitGlobalTracer( + serviceName, + jaegerconfig.Logger(logrusLogger{logrus.StandardLogger()}), + jaegerconfig.Metrics(jaegermetrics.NullFactory), + ) +} + +// logrusLogger is a small wrapper that implements jaeger.Logger using logrus. +type logrusLogger struct { + l *logrus.Logger +} + +func (l logrusLogger) Error(msg string) { + l.l.Error(msg) +} + +func (l logrusLogger) Infof(msg string, args ...interface{}) { + l.l.Infof(msg, args...) +}