Skip to content
This repository was archived by the owner on Feb 21, 2024. It is now read-only.

Commit b43c4aa

Browse files
authored
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
1 parent 6933196 commit b43c4aa

File tree

4 files changed

+71
-66
lines changed

4 files changed

+71
-66
lines changed

Dockerfile-dax

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ RUN make build FLAGS="-o build/featurebase" ${MAKE_FLAGS}
1616
### FeatureBase runner ###
1717
##########################
1818

19-
FROM alpine:3.13.2 as runner
19+
FROM golang:alpine as runner
2020

2121
LABEL maintainer "[email protected]"
2222

cmd/server.go

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,10 @@ package cmd
55
import (
66
"io"
77

8-
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/opentracer"
9-
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
10-
118
"github.com/featurebasedb/featurebase/v3/ctl"
129
"github.com/featurebasedb/featurebase/v3/server"
13-
"github.com/featurebasedb/featurebase/v3/tracing"
14-
"github.com/featurebasedb/featurebase/v3/tracing/opentracing"
1510
"github.com/pkg/errors"
1611
"github.com/spf13/cobra"
17-
jaegercfg "github.com/uber/jaeger-client-go/config"
18-
19-
"gopkg.in/DataDog/dd-trace-go.v1/profiler"
2012
)
2113

2214
// Server is global so that tests can control and verify it.
@@ -65,64 +57,7 @@ on the configured port.`,
6557
if err := Server.Start(); err != nil {
6658
return considerUsageError(cmd, errors.Wrap(err, "running server"))
6759
}
68-
// anything past here is definitely not a usage error
69-
cmd.SilenceErrors = true
70-
cmd.SilenceUsage = true
71-
if Server.Config.DataDog.Enable {
72-
opts := make([]profiler.ProfileType, 0)
73-
if Server.Config.DataDog.CPUProfile {
74-
opts = append(opts, profiler.CPUProfile)
75-
}
76-
if Server.Config.DataDog.HeapProfile {
77-
opts = append(opts, profiler.HeapProfile)
78-
}
79-
if Server.Config.DataDog.BlockProfile {
80-
opts = append(opts, profiler.BlockProfile)
81-
}
82-
if Server.Config.DataDog.GoroutineProfile {
83-
opts = append(opts, profiler.GoroutineProfile)
84-
}
85-
if Server.Config.DataDog.MutexProfile {
86-
opts = append(opts, profiler.MutexProfile)
87-
}
88-
err := profiler.Start(
89-
profiler.WithService(Server.Config.DataDog.Service),
90-
profiler.WithEnv(Server.Config.DataDog.Env),
91-
profiler.WithVersion(Server.Config.DataDog.Version),
92-
profiler.WithTags(Server.Config.DataDog.Tags),
93-
profiler.WithProfileTypes(
94-
opts...,
95-
),
96-
)
97-
if err != nil {
98-
return errors.Wrap(err, "starting datadog")
99-
}
100-
defer profiler.Stop()
101-
}
10260

103-
if Server.Config.Tracing.SamplerType != "off" {
104-
// Initialize tracing in the command since it is global.
105-
var cfg jaegercfg.Configuration
106-
cfg.ServiceName = "pilosa"
107-
cfg.Sampler = &jaegercfg.SamplerConfig{
108-
Type: Server.Config.Tracing.SamplerType,
109-
Param: Server.Config.Tracing.SamplerParam,
110-
}
111-
cfg.Reporter = &jaegercfg.ReporterConfig{
112-
LocalAgentHostPort: Server.Config.Tracing.AgentHostPort,
113-
}
114-
tracer, closer, err := cfg.NewTracer()
115-
if err != nil {
116-
return errors.Wrap(err, "initializing jaeger tracer")
117-
}
118-
defer closer.Close()
119-
tracing.GlobalTracer = opentracing.NewTracer(tracer, Server.Logger())
120-
121-
} else if Server.Config.DataDog.EnableTracing { // Give preference to legacy support of jaeger
122-
t := opentracer.New(tracer.WithServiceName(Server.Config.DataDog.Service))
123-
defer tracer.Stop()
124-
tracing.GlobalTracer = opentracing.NewTracer(t, Server.Logger())
125-
}
12661
return errors.Wrap(Server.Wait(), "waiting on Server")
12762
},
12863
}

http_handler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ func (h *Handler) queryArgValidator(next http.Handler) http.Handler {
391391
func (h *Handler) extractTracing(next http.Handler) http.Handler {
392392
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
393393
span, ctx := tracing.GlobalTracer.ExtractHTTPHeaders(r)
394+
span.LogKV("http.url", r.URL.String())
394395
defer span.Finish()
395396

396397
next.ServeHTTP(w, r.WithContext(ctx))

server/server.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,15 @@ import (
4545
"github.com/featurebasedb/featurebase/v3/systemlayer"
4646
"github.com/featurebasedb/featurebase/v3/syswrap"
4747
"github.com/featurebasedb/featurebase/v3/testhook"
48+
"github.com/featurebasedb/featurebase/v3/tracing"
49+
"github.com/featurebasedb/featurebase/v3/tracing/opentracing"
4850
"github.com/pelletier/go-toml"
4951
"github.com/pkg/errors"
52+
jaegercfg "github.com/uber/jaeger-client-go/config"
5053
"golang.org/x/sync/errgroup"
54+
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/opentracer"
55+
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/tracer"
56+
"gopkg.in/DataDog/dd-trace-go.v1/profiler"
5157
)
5258

5359
type loggerLogger interface {
@@ -356,6 +362,10 @@ func (m *Command) Start() (err error) {
356362
}
357363
}()
358364

365+
if err := m.setupProfilingAndTracing(); err != nil {
366+
return errors.Wrap(err, "setting up profiling/tracing")
367+
}
368+
359369
_ = testhook.Opened(pilosa.NewAuditor(), m, nil)
360370
close(m.Started)
361371
return nil
@@ -791,6 +801,65 @@ func (m *Command) setupQueryLogger() error {
791801
return nil
792802
}
793803

804+
func (m *Command) setupProfilingAndTracing() error {
805+
if m.Config.DataDog.Enable {
806+
opts := make([]profiler.ProfileType, 0)
807+
if m.Config.DataDog.CPUProfile {
808+
opts = append(opts, profiler.CPUProfile)
809+
}
810+
if m.Config.DataDog.HeapProfile {
811+
opts = append(opts, profiler.HeapProfile)
812+
}
813+
if m.Config.DataDog.BlockProfile {
814+
opts = append(opts, profiler.BlockProfile)
815+
}
816+
if m.Config.DataDog.GoroutineProfile {
817+
opts = append(opts, profiler.GoroutineProfile)
818+
}
819+
if m.Config.DataDog.MutexProfile {
820+
opts = append(opts, profiler.MutexProfile)
821+
}
822+
err := profiler.Start(
823+
profiler.WithService(m.Config.DataDog.Service),
824+
profiler.WithEnv(m.Config.DataDog.Env),
825+
profiler.WithVersion(m.Config.DataDog.Version),
826+
profiler.WithTags(m.Config.DataDog.Tags),
827+
profiler.WithProfileTypes(
828+
opts...,
829+
),
830+
)
831+
if err != nil {
832+
return errors.Wrap(err, "starting datadog")
833+
}
834+
defer profiler.Stop()
835+
}
836+
837+
if m.Config.Tracing.SamplerType != "off" {
838+
// Initialize tracing in the command since it is global.
839+
var cfg jaegercfg.Configuration
840+
cfg.ServiceName = "pilosa"
841+
cfg.Sampler = &jaegercfg.SamplerConfig{
842+
Type: m.Config.Tracing.SamplerType,
843+
Param: m.Config.Tracing.SamplerParam,
844+
}
845+
cfg.Reporter = &jaegercfg.ReporterConfig{
846+
LocalAgentHostPort: m.Config.Tracing.AgentHostPort,
847+
}
848+
tracer, closer, err := cfg.NewTracer()
849+
if err != nil {
850+
return errors.Wrap(err, "initializing jaeger tracer")
851+
}
852+
defer closer.Close()
853+
tracing.GlobalTracer = opentracing.NewTracer(tracer, m.Logger())
854+
855+
} else if m.Config.DataDog.EnableTracing { // Give preference to legacy support of jaeger
856+
t := opentracer.New(tracer.WithServiceName(m.Config.DataDog.Service))
857+
defer tracer.Stop()
858+
tracing.GlobalTracer = opentracing.NewTracer(t, m.Logger())
859+
}
860+
return nil
861+
}
862+
794863
// Close shuts down the server.
795864
func (m *Command) Close() error {
796865
select {

0 commit comments

Comments
 (0)