Skip to content

Commit

Permalink
Merge branch 'v2-dev' into quinna.halim/outdated-integrations-workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
hannahkm authored Dec 9, 2024
2 parents 5a82d3a + 793e435 commit d1f43d8
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 14 deletions.
4 changes: 2 additions & 2 deletions ddtrace/tracer/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -1069,15 +1069,15 @@ func WithRuntimeMetrics() StartOption {
}
}

// WithDogstatsdAddress specifies the address to connect to for sending metrics to the Datadog
// WithDogstatsdAddr specifies the address to connect to for sending metrics to the Datadog
// Agent. It should be a "host:port" string, or the path to a unix domain socket.If not set, it
// attempts to determine the address of the statsd service according to the following rules:
// 1. Look for /var/run/datadog/dsd.socket and use it if present. IF NOT, continue to #2.
// 2. The host is determined by DD_AGENT_HOST, and defaults to "localhost"
// 3. The port is retrieved from the agent. If not present, it is determined by DD_DOGSTATSD_PORT, and defaults to 8125
//
// This option is in effect when WithRuntimeMetrics is enabled.
func WithDogstatsdAddress(addr string) StartOption {
func WithDogstatsdAddr(addr string) StartOption {
return func(cfg *config) {
cfg.dogstatsdAddr = addr
globalconfig.SetDogstatsdAddr(addr)
Expand Down
6 changes: 3 additions & 3 deletions ddtrace/tracer/option_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ func TestTracerOptionsDefaults(t *testing.T) {
t.Run("option", func(t *testing.T) {
o := make([]StartOption, len(opts))
copy(o, opts)
o = append(o, WithDogstatsdAddress("10.1.0.12:4002"))
o = append(o, WithDogstatsdAddr("10.1.0.12:4002"))
tracer, err := newTracer(o...)
assert.NoError(t, err)
defer tracer.Stop()
Expand All @@ -642,7 +642,7 @@ func TestTracerOptionsDefaults(t *testing.T) {
o := make([]StartOption, len(opts))
copy(o, opts)
fail = true
o = append(o, WithDogstatsdAddress("10.1.0.12:4002"))
o = append(o, WithDogstatsdAddr("10.1.0.12:4002"))
tracer, err := newTracer(o...)
assert.NoError(t, err)
defer tracer.Stop()
Expand All @@ -663,7 +663,7 @@ func TestTracerOptionsDefaults(t *testing.T) {
}
addr := filepath.Join(dir, "dsd.socket")
defer os.RemoveAll(addr)
tracer, err := newTracer(WithDogstatsdAddress("unix://" + addr))
tracer, err := newTracer(WithDogstatsdAddr("unix://" + addr))
assert.NoError(err)
defer tracer.Stop()
c := tracer.config
Expand Down
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"
"github.com/DataDog/dd-trace-go/v2/internal/civisibility/constants"
"github.com/DataDog/dd-trace-go/v2/internal/civisibility/utils"
"github.com/DataDog/dd-trace-go/v2/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 @@ -339,7 +339,7 @@ func newUnstartedTracer(opts ...StartOption) (*tracer, error) {
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 (
"testing"
"time"

"github.com/DataDog/datadog-go/v5/statsd"
"github.com/DataDog/dd-trace-go/v2/ddtrace"
"github.com/DataDog/dd-trace-go/v2/ddtrace/ext"
"github.com/DataDog/dd-trace-go/v2/ddtrace/internal/tracerstats"
Expand Down Expand Up @@ -2347,7 +2348,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 d1f43d8

Please sign in to comment.