diff --git a/cmd/veneur/main.go b/cmd/veneur/main.go index af7b82c9b..936104db6 100644 --- a/cmd/veneur/main.go +++ b/cmd/veneur/main.go @@ -6,6 +6,7 @@ import ( "net/http" "os" + "github.com/DataDog/datadog-go/statsd" "github.com/getsentry/sentry-go" "github.com/sirupsen/logrus" "github.com/stripe/veneur/v14" @@ -81,6 +82,20 @@ func main() { os.Exit(0) } + stats, err := statsd.New( + config.StatsAddress, + statsd.WithAggregationInterval(config.Interval), + statsd.WithChannelMode(), + statsd.WithChannelModeBufferSize(4096), + statsd.WithClientSideAggregation(), + statsd.WithMaxMessagesPerPayload(4096), + statsd.WithNamespace("veneur."), + statsd.WithoutTelemetry(), + ) + if err != nil { + logger.WithError(err).Fatal("failed to create statsd client") + } + server, err := veneur.NewFromConfig(veneur.ServerConfig{ Config: *config, Logger: logger, @@ -167,6 +182,7 @@ func main() { w.Write([]byte("hello world!\n")) }, }, + Statsd: stats, }) if err != nil { logger.WithError(err).Fatal("Could not initialize server") diff --git a/server.go b/server.go index 328fcac36..759284e3c 100644 --- a/server.go +++ b/server.go @@ -98,6 +98,7 @@ type ServerConfig struct { SourceTypes SourceTypes SpanSinkTypes SpanSinkTypes HttpCustomHandlers HttpCustomHandlers + Statsd *statsd.Client } // A Server is the actual veneur instance that will be run. @@ -507,20 +508,14 @@ func NewFromConfig(config ServerConfig) (*Server, error) { } ret.HistogramAggregates.Count = len(conf.Aggregates) - stats, err := statsd.New(conf.StatsAddress, statsd.WithoutTelemetry(), statsd.WithMaxMessagesPerPayload(4096)) - if err != nil { - return ret, err - } - stats.Namespace = "veneur." - scopes, err := scopesFromConfig(conf) if err != nil { return ret, err } - ret.Statsd = scopedstatsd.NewClient(stats, conf.VeneurMetricsAdditionalTags, scopes) + ret.Statsd = scopedstatsd.NewClient(config.Statsd, conf.VeneurMetricsAdditionalTags, scopes) ret.TraceClient, err = trace.NewChannelClient(ret.SpanChan, - trace.ReportStatistics(stats, 1*time.Second, []string{"ssf_format:internal"}), + trace.ReportStatistics(config.Statsd, 1*time.Second, []string{"ssf_format:internal"}), normalizeSpans(conf), ) if err != nil {