Skip to content

Commit

Permalink
pkg/trace/api: enable Windows pipe support (#6615)
Browse files Browse the repository at this point in the history
Windows pipes are now supported by means of:

* `DD_APM_WINDOWS_PIPE_NAME` defines the pipe name to be used.
* `DD_APM_WINDOWS_PIPE_BUFFER_SIZE` defines the input buffer size
  (defaults to 1MB).
* `DD_APM_WINDOWS_PIPE_SECURITY_DESCRIPTOR` allows setting the security ID. Defaults to `D:AI(A;;GA;;;WD)` (grants access to everyone)
  • Loading branch information
gbbr authored Dec 2, 2020
1 parent 7e3423f commit 09f051a
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 0 deletions.
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)
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")
}
12 changes: 12 additions & 0 deletions releasenotes/notes/apm-windows-pipe-c8de92ce85fd930b.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Each section from every releasenote are combined when the
# CHANGELOG.rst is rendered. So the text needs to be worded so that
# it does not depend on any information only available in another
# section. This may mean repeating some details, but each section
# must be readable independently of the other.
#
# Each section note must be formatted as reStructuredText.
---
features:
- |
APM: Added support for Windows pipes. To enable it, set the pipe path using
DD_APM_WINDOWS_PIPE_NAME. For more details check https://github.com/DataDog/datadog-agent/pull/6615

0 comments on commit 09f051a

Please sign in to comment.