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

Adding Proxy support for Datadog Exporter #33316

Merged
merged 5 commits into from
Jun 5, 2024
Merged
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
27 changes: 27 additions & 0 deletions .chloggen/proxyurl-for-ddexp.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: datadogexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: The Datadog Exporter now supports the `proxy_url` parameter to configure an HTTP proxy to use when sending telemetry to Datadog.

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [33316]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
3 changes: 0 additions & 3 deletions exporter/datadogexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,9 +516,6 @@ func validateClientConfig(cfg confighttp.ClientConfig) error {
if cfg.Compression != "" {
unsupported = append(unsupported, "compression")
}
if cfg.ProxyURL != "" {
unsupported = append(unsupported, "proxy_url")
}
if cfg.Headers != nil {
unsupported = append(unsupported, "headers")
}
Expand Down
3 changes: 1 addition & 2 deletions exporter/datadogexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,13 @@ func TestValidate(t *testing.T) {
ClientConfig: confighttp.ClientConfig{
Endpoint: "endpoint",
Compression: "gzip",
ProxyURL: "proxy",
Auth: &auth,
Headers: map[string]configopaque.String{"key": "val"},
HTTP2ReadIdleTimeout: 250,
HTTP2PingTimeout: 200,
},
},
err: "these confighttp client configs are currently not respected by Datadog exporter: auth, endpoint, compression, proxy_url, headers, http2_read_idle_timeout, http2_ping_timeout",
err: "these confighttp client configs are currently not respected by Datadog exporter: auth, endpoint, compression, headers, http2_read_idle_timeout, http2_ping_timeout",
},
}
for _, testInstance := range tests {
Expand Down
9 changes: 8 additions & 1 deletion exporter/datadogexporter/internal/clientutil/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"fmt"
"net"
"net/http"
"net/url"
"time"

"go.opentelemetry.io/collector/component"
Expand All @@ -29,8 +30,14 @@ var (

// NewHTTPClient returns a http.Client configured with a subset of the confighttp.ClientConfig options.
func NewHTTPClient(hcs confighttp.ClientConfig) *http.Client {
// If the ProxyURL field in the configuration is set, the HTTP client will use the proxy.
// Otherwise, the HTTP client will use the system's proxy settings.
httpProxy := http.ProxyFromEnvironment
if parsedProxyURL, err := url.Parse(hcs.ProxyURL); err == nil && parsedProxyURL.Scheme != "" {
songy23 marked this conversation as resolved.
Show resolved Hide resolved
httpProxy = http.ProxyURL(parsedProxyURL)
}
transport := http.Transport{
Proxy: http.ProxyFromEnvironment,
Proxy: httpProxy,
pabloem marked this conversation as resolved.
Show resolved Hide resolved
// Default values consistent with https://github.com/DataDog/datadog-agent/blob/f9ae7f4b842f83b23b2dfe3f15d31f9e6b12e857/pkg/util/http/transport.go#L91-L106
DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
Expand Down
69 changes: 68 additions & 1 deletion exporter/datadogexporter/internal/clientutil/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package clientutil // import "github.com/open-telemetry/opentelemetry-collector-
import (
"crypto/tls"
"net/http"
"net/url"
"testing"
"time"

Expand Down Expand Up @@ -60,10 +61,10 @@ func TestNewHTTPClient(t *testing.T) {
MaxConnsPerHost: &maxConnPerHost,
DisableKeepAlives: true,
TLSSetting: configtls.ClientConfig{InsecureSkipVerify: true},
ProxyURL: "proxy",

// The rest are ignored
Endpoint: "endpoint",
ProxyURL: "proxy",
Compression: configcompression.TypeSnappy,
HTTP2ReadIdleTimeout: 15 * time.Second,
HTTP2PingTimeout: 20 * time.Second,
Expand All @@ -90,6 +91,72 @@ func TestNewHTTPClient(t *testing.T) {
t.Errorf("Mismatched transports -want +got %s", diff)
}
assert.Equal(t, 10*time.Second, client2.Timeout)

// Checking that the client config can receive ProxyUrl and
// it will be passed to the http client.
hcsForC3 := confighttp.ClientConfig{
ReadBufferSize: 100,
WriteBufferSize: 200,
Timeout: 10 * time.Second,
IdleConnTimeout: &idleConnTimeout,
MaxIdleConns: &maxIdleConn,
MaxIdleConnsPerHost: &maxIdleConnPerHost,
MaxConnsPerHost: &maxConnPerHost,
DisableKeepAlives: true,
TLSSetting: configtls.ClientConfig{InsecureSkipVerify: true},
ProxyURL: "http://datadog-proxy.myorganization.com:3128",

// The rest are ignored
songy23 marked this conversation as resolved.
Show resolved Hide resolved
Endpoint: "endpoint",
Compression: configcompression.TypeSnappy,
HTTP2ReadIdleTimeout: 15 * time.Second,
HTTP2PingTimeout: 20 * time.Second,
}
ddURL, _ := url.Parse("https://datadoghq.com")
parsedProxy, _ := url.Parse("http://datadog-proxy.myorganization.com:3128")
client3 := NewHTTPClient(hcsForC3)
tr3 := client3.Transport.(*http.Transport)
url3, _ := tr3.Proxy(&http.Request{
URL: ddURL,
})
assert.Equal(t, url3, parsedProxy)

// Checking that the client config can receive ProxyUrl to override the
// environment variable.
t.Setenv("HTTPS_PROXY", "http://datadog-proxy-from-env.myorganization.com:3128")
client4 := NewHTTPClient(hcsForC3)
tr4 := client4.Transport.(*http.Transport)
url4, _ := tr4.Proxy(&http.Request{
URL: ddURL,
})
assert.Equal(t, url4, parsedProxy)

// Checking that in the absence of ProxyUrl in the client config, the
// environment variable is used for the http proxy.
hcsForC5 := confighttp.ClientConfig{
ReadBufferSize: 100,
WriteBufferSize: 200,
Timeout: 10 * time.Second,
IdleConnTimeout: &idleConnTimeout,
MaxIdleConns: &maxIdleConn,
MaxIdleConnsPerHost: &maxIdleConnPerHost,
MaxConnsPerHost: &maxConnPerHost,
DisableKeepAlives: true,
TLSSetting: configtls.ClientConfig{InsecureSkipVerify: true},

// The rest are ignored
Endpoint: "endpoint",
Compression: configcompression.TypeSnappy,
HTTP2ReadIdleTimeout: 15 * time.Second,
HTTP2PingTimeout: 20 * time.Second,
}
parsedEnvProxy, _ := url.Parse("http://datadog-proxy-from-env.myorganization.com:3128")
client5 := NewHTTPClient(hcsForC5)
tr5 := client5.Transport.(*http.Transport)
url5, _ := tr5.Proxy(&http.Request{
URL: ddURL,
})
assert.Equal(t, url5, parsedEnvProxy)
}

func TestUserAgent(t *testing.T) {
Expand Down
Loading