Skip to content

Commit

Permalink
propagate statsd client to stats concentrator
Browse files Browse the repository at this point in the history
  • Loading branch information
ajgajg1134 committed Dec 4, 2024
1 parent 9980c24 commit 7cd5754
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
3 changes: 2 additions & 1 deletion ddtrace/tracer/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type tracerStatSpan struct {

// newConcentrator creates a new concentrator using the given tracer
// configuration c. It creates buckets of bucketSize nanoseconds duration.
func newConcentrator(c *config, bucketSize int64) *concentrator {
func newConcentrator(c *config, bucketSize int64, statsdClient internal.StatsdClient) *concentrator {
sCfg := &stats.SpanConcentratorConfig{
ComputeStatsBySpanKind: false,
BucketInterval: defaultStatsBucketSize,
Expand Down Expand Up @@ -86,6 +86,7 @@ func newConcentrator(c *config, bucketSize int64) *concentrator {
cfg: c,
aggregationKey: aggKey,
spanConcentrator: spanConcentrator,
statsdClient: statsdClient,
}
}

Expand Down
16 changes: 10 additions & 6 deletions ddtrace/tracer/stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ import (

"github.com/stretchr/testify/assert"

"github.com/DataDog/datadog-go/v5/statsd"
"gopkg.in/DataDog/dd-trace-go.v1/internal/civisibility/constants"
"gopkg.in/DataDog/dd-trace-go.v1/internal/civisibility/utils"
"gopkg.in/DataDog/dd-trace-go.v1/internal/statsdtest"
)

func TestAlignTs(t *testing.T) {
Expand All @@ -39,7 +41,7 @@ func TestConcentrator(t *testing.T) {
}
t.Run("start-stop", func(t *testing.T) {
assert := assert.New(t)
c := newConcentrator(&config{}, bucketSize)
c := newConcentrator(&config{}, bucketSize, &statsd.NoOpClient{})
assert.EqualValues(atomic.LoadUint32(&c.stopped), 1)
c.Start()
assert.EqualValues(atomic.LoadUint32(&c.stopped), 0)
Expand All @@ -58,7 +60,7 @@ func TestConcentrator(t *testing.T) {
t.Run("flusher", func(t *testing.T) {
t.Run("old", func(t *testing.T) {
transport := newDummyTransport()
c := newConcentrator(&config{transport: transport, env: "someEnv"}, 500_000)
c := newConcentrator(&config{transport: transport, env: "someEnv"}, 500_000, &statsd.NoOpClient{})
assert.Len(t, transport.Stats(), 0)
ss1, ok := c.newTracerStatSpan(&s1, nil)
assert.True(t, ok)
Expand All @@ -73,9 +75,10 @@ func TestConcentrator(t *testing.T) {
assert.Equal(t, "http.request", actualStats[0].Stats[0].Stats[0].Name)
})

t.Run("recent", func(t *testing.T) {
t.Run("recent+stats", func(t *testing.T) {
transport := newDummyTransport()
c := newConcentrator(&config{transport: transport, env: "someEnv"}, (10 * time.Second).Nanoseconds())
testStats := &statsdtest.TestStatsdClient{}
c := newConcentrator(&config{transport: transport, env: "someEnv"}, (10 * time.Second).Nanoseconds(), testStats)
assert.Len(t, transport.Stats(), 0)
ss1, ok := c.newTracerStatSpan(&s1, nil)
assert.True(t, ok)
Expand All @@ -96,12 +99,13 @@ func TestConcentrator(t *testing.T) {
assert.Len(t, names, 2)
assert.NotNil(t, names["http.request"])
assert.NotNil(t, names["potato"])
assert.Contains(t, testStats.CallNames(), "datadog.tracer.stats.spans_in")
})

t.Run("ciGitSha", func(t *testing.T) {
utils.AddCITags(constants.GitCommitSHA, "DEADBEEF")
transport := newDummyTransport()
c := newConcentrator(&config{transport: transport, env: "someEnv"}, (10 * time.Second).Nanoseconds())
c := newConcentrator(&config{transport: transport, env: "someEnv"}, (10 * time.Second).Nanoseconds(), &statsd.NoOpClient{})
assert.Len(t, transport.Stats(), 0)
ss1, ok := c.newTracerStatSpan(&s1, nil)
assert.True(t, ok)
Expand All @@ -115,7 +119,7 @@ func TestConcentrator(t *testing.T) {
// stats should be sent if the concentrator is stopped
t.Run("stop", func(t *testing.T) {
transport := newDummyTransport()
c := newConcentrator(&config{transport: transport}, 500000)
c := newConcentrator(&config{transport: transport}, 500000, &statsd.NoOpClient{})
assert.Len(t, transport.Stats(), 0)
ss1, ok := c.newTracerStatSpan(&s1, nil)
assert.True(t, ok)
Expand Down
2 changes: 1 addition & 1 deletion ddtrace/tracer/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ func newUnstartedTracer(opts ...StartOption) *tracer {
prioritySampling: sampler,
pid: os.Getpid(),
logDroppedTraces: time.NewTicker(1 * time.Second),
stats: newConcentrator(c, defaultStatsBucketSize),
stats: newConcentrator(c, defaultStatsBucketSize, statsd),
obfuscator: obfuscate.NewObfuscator(obfuscate.Config{
SQL: obfuscate.SQLConfig{
TableNames: c.agent.HasFlag("table_names"),
Expand Down
3 changes: 2 additions & 1 deletion ddtrace/tracer/tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"time"

pb "github.com/DataDog/datadog-agent/pkg/proto/pbgo/trace"
"github.com/DataDog/datadog-go/v5/statsd"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/ext"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/internal"
Expand Down Expand Up @@ -2346,7 +2347,7 @@ func TestFlush(t *testing.T) {
tr.statsd = ts

transport := newDummyTransport()
c := newConcentrator(&config{transport: transport, env: "someEnv"}, defaultStatsBucketSize)
c := newConcentrator(&config{transport: transport, env: "someEnv"}, defaultStatsBucketSize, &statsd.NoOpClient{})
tr.stats = c
c.Start()
defer c.Stop()
Expand Down

0 comments on commit 7cd5754

Please sign in to comment.