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/api: enable Windows pipe support #6615

Merged
merged 3 commits into from
Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions pkg/config/apm.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ func setupAPM(config Config) {
}

config.BindEnvAndSetDefault("apm_config.receiver_port", 8126, "DD_APM_RECEIVER_PORT", "DD_RECEIVER_PORT")
config.BindEnvAndSetDefault("apm_config.windows_pipe_buffer_size", 1_000_000, "DD_APM_WINDOWS_PIPE_BUFFER_SIZE") //nolint:errcheck
config.BindEnvAndSetDefault("apm_config.windows_pipe_security_descriptor", "D:AI(A;;GA;;;WD)", "DD_APM_WINDOWS_PIPE_SECURITY_DESCRIPTOR") //nolint:errcheck

config.BindEnv("apm_config.receiver_timeout", "DD_APM_RECEIVER_TIMEOUT") //nolint:errcheck
config.BindEnv("apm_config.max_payload_size", "DD_APM_MAX_PAYLOAD_SIZE") //nolint:errcheck
Expand All @@ -63,6 +65,7 @@ func setupAPM(config Config) {
config.BindEnv("apm_config.analyzed_spans", "DD_APM_ANALYZED_SPANS") //nolint:errcheck
config.BindEnv("apm_config.ignore_resources", "DD_APM_IGNORE_RESOURCES", "DD_IGNORE_RESOURCE") //nolint:errcheck
config.BindEnv("apm_config.receiver_socket", "DD_APM_RECEIVER_SOCKET") //nolint:errcheck
config.BindEnv("apm_config.windows_pipe_name", "DD_APM_WINDOWS_PIPE_NAME") //nolint:errcheck

config.SetEnvKeyTransformer("apm_config.ignore_resources", func(in string) interface{} {
r, err := splitCSVString(in, ',')
Expand Down
18 changes: 18 additions & 0 deletions pkg/trace/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func (r *HTTPReceiver) Start() {
go func() {
defer watchdog.LogOnPanic()
r.server.Serve(ln)
ln.Close()
}()
log.Infof("Listening for traces at http://%s", addr)

Expand All @@ -132,10 +133,27 @@ func (r *HTTPReceiver) Start() {
go func() {
defer watchdog.LogOnPanic()
r.server.Serve(ln)
ln.Close()
}()
log.Infof("Listening for traces at unix://%s", path)
}

if path := mainconfig.Datadog.GetString("apm_config.windows_pipe_name"); path != "" {
pipepath := `\\.\pipe\` + path
bufferSize := mainconfig.Datadog.GetInt("apm_config.windows_pipe_buffer_size")
secdec := mainconfig.Datadog.GetString("apm_config.windows_pipe_security_descriptor")
ln, err := listenPipe(pipepath, secdec, bufferSize)
if err != nil {
killProcess("Error creating %q named pipe: %v", pipepath, err)
}
go func() {
defer watchdog.LogOnPanic()
r.server.Serve(ln)
gbbr marked this conversation as resolved.
Show resolved Hide resolved
ln.Close()
}()
log.Infof("Listening for traces on Windowes pipe %q. Security descriptor is %q", pipepath, secdec)
}

go r.RateLimiter.Run()

go func() {
Expand Down
21 changes: 21 additions & 0 deletions pkg/trace/api/pipe.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-2020 Datadog, Inc.

// +build windows

package api

import (
"net"

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

func listenPipe(path string, secdec string, bufferSize int) (net.Listener, error) {
return winio.ListenPipe(path, &winio.PipeConfig{
SecurityDescriptor: secdec,
InputBufferSize: int32(bufferSize),
})
}
17 changes: 17 additions & 0 deletions pkg/trace/api/pipe_off.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-2020 Datadog, Inc.

// +build !windows

package api

import (
"errors"
"net"
)

func listenPipe(_, _ string, _ int) (net.Listener, error) {
return nil, errors.New("Windows named pipes are only supported on Windows operating systems")
}