-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pkg/trace/api: add support for Unix Domain Sockets
This change adds support for Unix Domain Sockets by means of a configuration setting. By default, this feature is disabled. To enable it, simply point the yaml setting to the right socket path, for example: apm_config: receiver_socket: /tmp/trace.sock This will enable the HTTP server to listen on unix:https:///tmp/trace.sock The DD_APM_RECEIVER_SOCKET environment variable is an alias for the above.
- Loading branch information
Showing
9 changed files
with
140 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// +build !windows | ||
|
||
package api | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"net" | ||
"net/http" | ||
"testing" | ||
"time" | ||
|
||
"github.com/DataDog/datadog-agent/pkg/trace/config" | ||
"github.com/DataDog/datadog-agent/pkg/trace/pb" | ||
"github.com/DataDog/datadog-agent/pkg/trace/test/testutil" | ||
) | ||
|
||
func TestUDS(t *testing.T) { | ||
sockPath := "/tmp/test-trace.sock" | ||
payload := msgpTraces(t, pb.Traces{testutil.RandomTrace(10, 20)}) | ||
client := http.Client{ | ||
Transport: &http.Transport{ | ||
Proxy: http.ProxyFromEnvironment, | ||
DialContext: func(_ context.Context, _, _ string) (net.Conn, error) { | ||
return net.Dial("unix", sockPath) | ||
}, | ||
MaxIdleConns: 100, | ||
IdleConnTimeout: 90 * time.Second, | ||
TLSHandshakeTimeout: 10 * time.Second, | ||
ExpectContinueTimeout: 1 * time.Second, | ||
}, | ||
} | ||
|
||
t.Run("off", func(t *testing.T) { | ||
conf := config.New() | ||
conf.Endpoints[0].APIKey = "apikey_2" | ||
|
||
r := newTestReceiverFromConfig(conf) | ||
r.Start() | ||
defer r.Stop() | ||
|
||
resp, err := client.Post("https://localhost:8126/v0.4/traces", "application/msgpack", bytes.NewReader(payload)) | ||
if err == nil { | ||
t.Fatalf("expected to fail, got response %#v", resp) | ||
} | ||
}) | ||
|
||
t.Run("on", func(t *testing.T) { | ||
conf := config.New() | ||
conf.Endpoints[0].APIKey = "apikey_2" | ||
conf.ReceiverSocket = sockPath | ||
|
||
r := newTestReceiverFromConfig(conf) | ||
r.Start() | ||
defer r.Stop() | ||
|
||
resp, err := client.Post("https://localhost:8126/v0.4/traces", "application/msgpack", bytes.NewReader(payload)) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if resp.StatusCode != 200 { | ||
t.Fatalf("expected http.StatusOK, got response: %#v", resp) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
releasenotes/notes/apm-add-unix-domain-sockets-4b4821727cf024fb.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: add support for Unix Domain Sockets by means of the `apm_config.receiver_socket` configuration. It is off by default. When set, | ||
it must point to a valid sock file. |