Skip to content

Commit

Permalink
[Logs agent] Disable HTTP/2 when using a proxy (#32308)
Browse files Browse the repository at this point in the history
Co-authored-by: Jen Gilbert <[email protected]>
  • Loading branch information
gh123man and jhgilbert authored Dec 18, 2024
1 parent 5615184 commit 8f2d236
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
7 changes: 7 additions & 0 deletions pkg/logs/client/http/destination.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,13 @@ func httpClientFactory(timeout time.Duration, cfg pkgconfigmodel.Reader) func()
var transport *http.Transport

transportConfig := cfg.Get("logs_config.http_protocol")

// If any proxy is set, use http1
// This will be removed in a future version
if cfg.GetProxies() != nil {
transportConfig = "http1"
}

// Configure transport based on user setting
switch transportConfig {
case "http1":
Expand Down
31 changes: 31 additions & 0 deletions pkg/logs/client/http/destination_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,3 +494,34 @@ func TestTransportProtocol_HTTP1FallBack(t *testing.T) {
// Assert that the server automatically falls back to HTTP/1.1
assert.Equal(t, "HTTP/1.1", resp.Proto)
}

func TestTransportProtocol_HTTP1WhenUsingProxy(t *testing.T) {
c := configmock.New(t)

// Force client to use ALNP
c.SetWithoutSource("logs_config.http_protocol", "auto")
c.SetWithoutSource("skip_ssl_validation", true)

// The test server uses TLS, so if we set the http proxy (not https), it still makes
// a request to the test server, but disable HTTP/2 since a proxy is configured.
c.SetWithoutSource("proxy.http", "http://foo.bar")

server := NewTestHTTPSServer(false)
defer server.Close()

timeout := 5 * time.Second
client := httpClientFactory(timeout, c)()

req, err := http.NewRequest("POST", server.URL, nil)
if err != nil {
t.Fatalf("Failed to create request: %v", err)
}
resp, err := client.Do(req)
if err != nil {
t.Fatalf("Failed to send request: %v", err)
}
defer resp.Body.Close()

// Assert that the server chose HTTP/1.1 because a proxy was configured
assert.Equal(t, "HTTP/1.1", resp.Proto)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
features:
- |
Introduced a new configuration variable `logs_config.http_protocol`, allowing users to enforce HTTP/1.1 for outgoing HTTP connections in the Datadog Agent. This provides better control over transport protocols and improves compatibility with systems that do not support HTTP/2.
By default, the log agent will now attempt to use HTTP/2 and fall back to the best available protocol if HTTP/2 is not supported.
By default, the log agent will now attempt to use HTTP/2 (unless a proxy is configured) and fall back to the best available protocol if HTTP/2 is not supported.
enhancements:
- |
Improved logging to add visiblity for latency and transport protocol
Improved logging to add visibility for latency and transport protocol

0 comments on commit 8f2d236

Please sign in to comment.