Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkg/{trace, config}: add support for statsd over windows pipes #7186

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ func InitConfig(config Config) {
config.BindEnvAndSetDefault("check_runners", int64(4))
config.BindEnvAndSetDefault("auth_token_file_path", "")
config.BindEnvAndSetDefault("bind_host", "localhost")
config.BindEnvAndSetDefault("dogstatsd_windows_pipe_name", "")
config.BindEnvAndSetDefault("ipc_address", "localhost")
config.BindEnvAndSetDefault("health_port", int64(0))
config.BindEnvAndSetDefault("disable_py3_validation", false)
Expand Down
3 changes: 3 additions & 0 deletions pkg/trace/config/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ func (c *AgentConfig) applyDatadogConfig() error {
}
}

if config.Datadog.IsSet("dogstatsd_windows_pipe_name") {
c.StatsdWindowsPipe = config.Datadog.GetString("dogstatsd_windows_pipe_name")
}
if config.Datadog.IsSet("bind_host") {
host := config.Datadog.GetString("bind_host")
c.StatsdHost = host
Expand Down
5 changes: 3 additions & 2 deletions pkg/trace/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,9 @@ type AgentConfig struct {
ConnectionResetInterval time.Duration // frequency at which outgoing connections are reset. 0 means no reset is performed

// internal telemetry
StatsdHost string
StatsdPort int
StatsdWindowsPipe string
StatsdHost string
StatsdPort int

// logging
LogLevel string
Expand Down
22 changes: 19 additions & 3 deletions pkg/trace/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,30 @@ import (
"fmt"

"github.com/DataDog/datadog-agent/pkg/trace/config"

"github.com/DataDog/datadog-go/statsd"
)

// Configure creates a statsd client for the given agent's configuration, using the specified global tags.
func Configure(conf *config.AgentConfig, tags []string) error {
client, err := statsd.New(fmt.Sprintf("%s:%d", conf.StatsdHost, conf.StatsdPort), statsd.WithTags(tags))
if err != nil {
return err
var (
client *statsd.Client
err error
)
if conf.StatsdWindowsPipe != "" {
pipe, err := dialPipe(conf.StatsdWindowsPipe, nil)
if err != nil {
return err
}
client, err = statsd.NewWithWriter(pipe, statsd.WithTags(tags))
if err != nil {
return err
}
} else {
client, err = statsd.New(fmt.Sprintf("%s:%d", conf.StatsdHost, conf.StatsdPort), statsd.WithTags(tags))
if err != nil {
return err
}
}
Client = client
return nil
Expand Down
16 changes: 16 additions & 0 deletions pkg/trace/metrics/pipe.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package metrics

import (
"errors"
"net"
"time"
)

type statsWriter struct {
net.Conn
}

// SetWriteTimeout is not available for Windows Pipes. returns error
func (w *statsWriter) SetWriteTimeout(d time.Duration) error {
return errors.New("SetWriteTimeout: not supported for Windows Pipe connections")
}
13 changes: 13 additions & 0 deletions pkg/trace/metrics/pipe_nonwindows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// +build !windows

package metrics

import (
"fmt"
"runtime"
"time"
)

func dialPipe(path string, timeout *time.Duration) (*statsWriter, error) {
return nil, fmt.Errorf("Windows Pipe not available on %s", runtime.GOOS)
}
15 changes: 15 additions & 0 deletions pkg/trace/metrics/pipe_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package metrics

import (
"time"

"github.com/Microsoft/go-winio"
)

func dialPipe(path string, timeout *time.Duration) (*statsWriter, error) {
c, err := winio.DialPipe(path, timeout)
if err != nil {
return nil, err
}
return &statsWriter{c}, nil
}