mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
move DD profiling/tracing setup into command where it belongs (#2233)
* move DD profiling/tracing setup into command where it belongs * add url to http trace, use golang for container image
This commit is contained in:
parent
69331963da
commit
b43c4aabc5
4 changed files with 71 additions and 66 deletions
|
|
@ -16,7 +16,7 @@ RUN make build FLAGS="-o build/featurebase" ${MAKE_FLAGS}
|
|||
### FeatureBase runner ###
|
||||
##########################
|
||||
|
||||
FROM alpine:3.13.2 as runner
|
||||
FROM golang:alpine as runner
|
||||
|
||||
LABEL maintainer "dev@featurebase.com"
|
||||
|
||||
|
|
|
|||
|
|
@ -5,18 +5,10 @@ package cmd
|
|||
import (
|
||||
"io"
|
||||
|
||||
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/opentracer"
|
||||
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
|
||||
|
||||
"github.com/featurebasedb/featurebase/v3/ctl"
|
||||
"github.com/featurebasedb/featurebase/v3/server"
|
||||
"github.com/featurebasedb/featurebase/v3/tracing"
|
||||
"github.com/featurebasedb/featurebase/v3/tracing/opentracing"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
jaegercfg "github.com/uber/jaeger-client-go/config"
|
||||
|
||||
"gopkg.in/DataDog/dd-trace-go.v1/profiler"
|
||||
)
|
||||
|
||||
// Server is global so that tests can control and verify it.
|
||||
|
|
@ -65,64 +57,7 @@ on the configured port.`,
|
|||
if err := Server.Start(); err != nil {
|
||||
return considerUsageError(cmd, errors.Wrap(err, "running server"))
|
||||
}
|
||||
// anything past here is definitely not a usage error
|
||||
cmd.SilenceErrors = true
|
||||
cmd.SilenceUsage = true
|
||||
if Server.Config.DataDog.Enable {
|
||||
opts := make([]profiler.ProfileType, 0)
|
||||
if Server.Config.DataDog.CPUProfile {
|
||||
opts = append(opts, profiler.CPUProfile)
|
||||
}
|
||||
if Server.Config.DataDog.HeapProfile {
|
||||
opts = append(opts, profiler.HeapProfile)
|
||||
}
|
||||
if Server.Config.DataDog.BlockProfile {
|
||||
opts = append(opts, profiler.BlockProfile)
|
||||
}
|
||||
if Server.Config.DataDog.GoroutineProfile {
|
||||
opts = append(opts, profiler.GoroutineProfile)
|
||||
}
|
||||
if Server.Config.DataDog.MutexProfile {
|
||||
opts = append(opts, profiler.MutexProfile)
|
||||
}
|
||||
err := profiler.Start(
|
||||
profiler.WithService(Server.Config.DataDog.Service),
|
||||
profiler.WithEnv(Server.Config.DataDog.Env),
|
||||
profiler.WithVersion(Server.Config.DataDog.Version),
|
||||
profiler.WithTags(Server.Config.DataDog.Tags),
|
||||
profiler.WithProfileTypes(
|
||||
opts...,
|
||||
),
|
||||
)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "starting datadog")
|
||||
}
|
||||
defer profiler.Stop()
|
||||
}
|
||||
|
||||
if Server.Config.Tracing.SamplerType != "off" {
|
||||
// Initialize tracing in the command since it is global.
|
||||
var cfg jaegercfg.Configuration
|
||||
cfg.ServiceName = "pilosa"
|
||||
cfg.Sampler = &jaegercfg.SamplerConfig{
|
||||
Type: Server.Config.Tracing.SamplerType,
|
||||
Param: Server.Config.Tracing.SamplerParam,
|
||||
}
|
||||
cfg.Reporter = &jaegercfg.ReporterConfig{
|
||||
LocalAgentHostPort: Server.Config.Tracing.AgentHostPort,
|
||||
}
|
||||
tracer, closer, err := cfg.NewTracer()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "initializing jaeger tracer")
|
||||
}
|
||||
defer closer.Close()
|
||||
tracing.GlobalTracer = opentracing.NewTracer(tracer, Server.Logger())
|
||||
|
||||
} else if Server.Config.DataDog.EnableTracing { // Give preference to legacy support of jaeger
|
||||
t := opentracer.New(tracer.WithServiceName(Server.Config.DataDog.Service))
|
||||
defer tracer.Stop()
|
||||
tracing.GlobalTracer = opentracing.NewTracer(t, Server.Logger())
|
||||
}
|
||||
return errors.Wrap(Server.Wait(), "waiting on Server")
|
||||
},
|
||||
}
|
||||
|
|
|
|||
|
|
@ -391,6 +391,7 @@ func (h *Handler) queryArgValidator(next http.Handler) http.Handler {
|
|||
func (h *Handler) extractTracing(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
span, ctx := tracing.GlobalTracer.ExtractHTTPHeaders(r)
|
||||
span.LogKV("http.url", r.URL.String())
|
||||
defer span.Finish()
|
||||
|
||||
next.ServeHTTP(w, r.WithContext(ctx))
|
||||
|
|
|
|||
|
|
@ -45,9 +45,15 @@ import (
|
|||
"github.com/featurebasedb/featurebase/v3/systemlayer"
|
||||
"github.com/featurebasedb/featurebase/v3/syswrap"
|
||||
"github.com/featurebasedb/featurebase/v3/testhook"
|
||||
"github.com/featurebasedb/featurebase/v3/tracing"
|
||||
"github.com/featurebasedb/featurebase/v3/tracing/opentracing"
|
||||
"github.com/pelletier/go-toml"
|
||||
"github.com/pkg/errors"
|
||||
jaegercfg "github.com/uber/jaeger-client-go/config"
|
||||
"golang.org/x/sync/errgroup"
|
||||
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/opentracer"
|
||||
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
|
||||
"gopkg.in/DataDog/dd-trace-go.v1/profiler"
|
||||
)
|
||||
|
||||
type loggerLogger interface {
|
||||
|
|
@ -356,6 +362,10 @@ func (m *Command) Start() (err error) {
|
|||
}
|
||||
}()
|
||||
|
||||
if err := m.setupProfilingAndTracing(); err != nil {
|
||||
return errors.Wrap(err, "setting up profiling/tracing")
|
||||
}
|
||||
|
||||
_ = testhook.Opened(pilosa.NewAuditor(), m, nil)
|
||||
close(m.Started)
|
||||
return nil
|
||||
|
|
@ -791,6 +801,65 @@ func (m *Command) setupQueryLogger() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (m *Command) setupProfilingAndTracing() error {
|
||||
if m.Config.DataDog.Enable {
|
||||
opts := make([]profiler.ProfileType, 0)
|
||||
if m.Config.DataDog.CPUProfile {
|
||||
opts = append(opts, profiler.CPUProfile)
|
||||
}
|
||||
if m.Config.DataDog.HeapProfile {
|
||||
opts = append(opts, profiler.HeapProfile)
|
||||
}
|
||||
if m.Config.DataDog.BlockProfile {
|
||||
opts = append(opts, profiler.BlockProfile)
|
||||
}
|
||||
if m.Config.DataDog.GoroutineProfile {
|
||||
opts = append(opts, profiler.GoroutineProfile)
|
||||
}
|
||||
if m.Config.DataDog.MutexProfile {
|
||||
opts = append(opts, profiler.MutexProfile)
|
||||
}
|
||||
err := profiler.Start(
|
||||
profiler.WithService(m.Config.DataDog.Service),
|
||||
profiler.WithEnv(m.Config.DataDog.Env),
|
||||
profiler.WithVersion(m.Config.DataDog.Version),
|
||||
profiler.WithTags(m.Config.DataDog.Tags),
|
||||
profiler.WithProfileTypes(
|
||||
opts...,
|
||||
),
|
||||
)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "starting datadog")
|
||||
}
|
||||
defer profiler.Stop()
|
||||
}
|
||||
|
||||
if m.Config.Tracing.SamplerType != "off" {
|
||||
// Initialize tracing in the command since it is global.
|
||||
var cfg jaegercfg.Configuration
|
||||
cfg.ServiceName = "pilosa"
|
||||
cfg.Sampler = &jaegercfg.SamplerConfig{
|
||||
Type: m.Config.Tracing.SamplerType,
|
||||
Param: m.Config.Tracing.SamplerParam,
|
||||
}
|
||||
cfg.Reporter = &jaegercfg.ReporterConfig{
|
||||
LocalAgentHostPort: m.Config.Tracing.AgentHostPort,
|
||||
}
|
||||
tracer, closer, err := cfg.NewTracer()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "initializing jaeger tracer")
|
||||
}
|
||||
defer closer.Close()
|
||||
tracing.GlobalTracer = opentracing.NewTracer(tracer, m.Logger())
|
||||
|
||||
} else if m.Config.DataDog.EnableTracing { // Give preference to legacy support of jaeger
|
||||
t := opentracer.New(tracer.WithServiceName(m.Config.DataDog.Service))
|
||||
defer tracer.Stop()
|
||||
tracing.GlobalTracer = opentracing.NewTracer(t, m.Logger())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Close shuts down the server.
|
||||
func (m *Command) Close() error {
|
||||
select {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue