Skip to content

Commit

Permalink
Merge branch 'main' into v2-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
darccio committed Nov 28, 2024
2 parents fc0c3af + 63e7470 commit 1e2b0ac
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 125 deletions.
24 changes: 12 additions & 12 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Note: Later matches take precedence

# default owner
* @DataDog/dd-trace-go-guild
* @DataDog/dd-trace-go-guild @DataDog/apm-go

# no owner: changes to these files will not automatically ping any particular
# team and can be reviewed by anybody with the appropriate permissions. This is
Expand All @@ -15,22 +15,22 @@ go.sum
/ddtrace @DataDog/apm-go

# profiling
/profiler @DataDog/profiling-go
/internal/traceprof @DataDog/profiling-go
/profiler @DataDog/profiling-go @DataDog/apm-go
/internal/traceprof @DataDog/profiling-go @DataDog/apm-go

# appsec
/appsec @DataDog/asm-go
/internal/appsec @DataDog/asm-go
/contrib/**/*appsec*.go @DataDog/asm-go
/.github/workflows/appsec.yml @DataDog/asm-go
/appsec @DataDog/asm-go @DataDog/apm-go
/internal/appsec @DataDog/asm-go @DataDog/apm-go
/contrib/**/*appsec*.go @DataDog/asm-go @DataDog/apm-go
/.github/workflows/appsec.yml @DataDog/asm-go @DataDog/apm-go

# datastreams
/datastreams @Datadog/data-streams-monitoring
/internal/datastreams @Datadog/data-streams-monitoring
/datastreams @Datadog/data-streams-monitoring @DataDog/apm-go
/internal/datastreams @Datadog/data-streams-monitoring @DataDog/apm-go

# civisibility
/internal/civisibility @DataDog/ci-app-libraries
/internal/civisibility @DataDog/ci-app-libraries @DataDog/apm-go

# Gitlab configuration
.gitlab-ci.yml @DataDog/dd-trace-go-guild @DataDog/apm-core-reliability-and-performance
/.gitlab-ci @DataDog/dd-trace-go-guild @DataDog/apm-core-reliability-and-performance
.gitlab-ci.yml @DataDog/dd-trace-go-guild @DataDog/apm-core-reliability-and-performance @DataDog/apm-go
/.gitlab-ci @DataDog/dd-trace-go-guild @DataDog/apm-core-reliability-and-performance @DataDog/apm-go
80 changes: 43 additions & 37 deletions ddtrace/tracer/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ var (
// Replaced in tests
defaultSocketDSD = "/var/run/datadog/dsd.socket"

// defaultStatsdPort specifies the default port to use for connecting to the statsd server.
defaultStatsdPort = "8125"

// defaultMaxTagsHeaderLen specifies the default maximum length of the X-Datadog-Tags header value.
defaultMaxTagsHeaderLen = 128
)
Expand Down Expand Up @@ -530,9 +533,7 @@ func newConfig(opts ...StartOption) (*config, error) {
}
// if using stdout or traces are disabled, agent is disabled
agentDisabled := c.logToStdout || !c.enabled.current
ignoreStatsdPort := c.agent.ignore // preserve the value of c.agent.ignore when testing
c.agent = loadAgentFeatures(agentDisabled, c.agentURL, c.httpClient)
c.agent.ignore = ignoreStatsdPort
info, ok := debug.ReadBuildInfo()
if !ok {
c.loadContribIntegrations([]*debug.Module{})
Expand All @@ -541,25 +542,7 @@ func newConfig(opts ...StartOption) (*config, error) {
}
if c.statsdClient == nil {
// configure statsd client
addr := c.dogstatsdAddr
if addr == "" {
// no config defined address; use defaults
addr = defaultDogstatsdAddr()
}
if agentport := c.agent.StatsdPort; agentport > 0 && !c.agent.ignore {
// the agent reported a non-standard port
host, _, err := net.SplitHostPort(addr)
// Use agent-reported address if it differs from the user-defined TCP-based protocol URI
if err == nil && host != "unix" {
// we have a valid host:port address; replace the port because
// the agent knows better
if host == "" {
host = defaultHostname
}
addr = net.JoinHostPort(host, strconv.Itoa(agentport))
}
// not a valid TCP address, leave it as it is (could be a socket connection)
}
addr := resolveDogstatsdAddr(c)
globalconfig.SetDogstatsdAddr(addr)
c.dogstatsdAddr = addr
}
Expand All @@ -581,6 +564,44 @@ func newConfig(opts ...StartOption) (*config, error) {
return c, nil
}

// resolveDogstatsdAddr resolves the Dogstatsd address to use, based on the user-defined
// address and the agent-reported port. If the agent reports a port, it will be used
// instead of the user-defined address' port. UDS paths are honored regardless of the
// agent-reported port.
func resolveDogstatsdAddr(c *config) string {
addr := c.dogstatsdAddr
if addr == "" {
// no config defined address; use host and port from env vars
// or default to localhost:8125 if not set
addr = defaultDogstatsdAddr()
}
agentport := c.agent.StatsdPort
if agentport == 0 {
// the agent didn't report a port; use the already resolved address as
// features are loaded from the trace-agent, which might be not running
return addr
}
// the agent reported a port
host, _, err := net.SplitHostPort(addr)
if err != nil {
// parsing the address failed; use the already resolved address as is
return addr
}
if host == "unix" {
// no need to change the address because it's a UDS connection
// and these don't have ports
return addr
}
if host == "" {
// no host was provided; use the default hostname
host = defaultHostname
}
// use agent-reported address if it differs from the user-defined TCP-based protocol URI
// we have a valid host:port address; replace the port because the agent knows better
addr = net.JoinHostPort(host, strconv.Itoa(agentport))
return addr
}

func newStatsdClient(c *config) (internal.StatsdClient, error) {
if c.statsdClient != nil {
return c.statsdClient, nil
Expand Down Expand Up @@ -618,7 +639,7 @@ func defaultDogstatsdAddr() string {
// socket exists and user didn't specify otherwise via env vars
return "unix://" + defaultSocketDSD
}
host, port := defaultHostname, "8125"
host, port := defaultHostname, defaultStatsdPort
if envHost != "" {
host = envHost
}
Expand Down Expand Up @@ -653,9 +674,6 @@ type agentFeatures struct {
// featureFlags specifies all the feature flags reported by the trace-agent.
featureFlags map[string]struct{}

// ignore indicates that we should ignore the agent in favor of user set values.
// It should only be used during testing.
ignore bool
// peerTags specifies precursor tags to aggregate stats on when client stats is enabled
peerTags []string

Expand Down Expand Up @@ -686,9 +704,6 @@ func loadAgentFeatures(agentDisabled bool, agentURL *url.URL, httpClient *http.C
return
}
defer resp.Body.Close()
type agentConfig struct {
DefaultEnv string `json:"default_env"`
}
type infoResponse struct {
Endpoints []string `json:"endpoints"`
ClientDropP0s bool `json:"client_drop_p0s"`
Expand Down Expand Up @@ -824,15 +839,6 @@ func WithFeatureFlags(feats ...string) StartOption {
}
}

// withIgnoreAgent allows tests to ignore the agent running in CI so that we can
// properly test user set StatsdPort.
// This should only be used during testing.
func withIgnoreAgent(ignore bool) StartOption {
return func(c *config) {
c.agent.ignore = ignore
}
}

// WithLogger sets logger as the tracer's error printer.
// Diagnostic and startup tracer logs are prefixed to simplify the search within logs.
// If JSON logging format is required, it's possible to wrap tracer logs using an existing JSON logger with this
Expand Down
Loading

0 comments on commit 1e2b0ac

Please sign in to comment.