Skip to content

Commit

Permalink
[AMLII-2236] Enable Http/2 for log agent when using a proxy (#33369)
Browse files Browse the repository at this point in the history
Co-authored-by: Brett Blue <[email protected]>
  • Loading branch information
DDuongNguyen and brett0000FF authored Jan 24, 2025
1 parent cd756b3 commit bc60970
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
6 changes: 0 additions & 6 deletions pkg/logs/client/http/destination.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,12 +397,6 @@ func httpClientFactory(timeout time.Duration, cfg pkgconfigmodel.Reader) func()

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
36 changes: 34 additions & 2 deletions pkg/logs/client/http/destination_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,15 +495,15 @@ func TestTransportProtocol_HTTP1FallBack(t *testing.T) {
assert.Equal(t, "HTTP/1.1", resp.Proto)
}

func TestTransportProtocol_HTTP1WhenUsingProxy(t *testing.T) {
func TestTransportProtocol_HTTP2WhenUsingProxy(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.
// a request to the test server
c.SetWithoutSource("proxy.http", "http://foo.bar")

server := NewTestHTTPSServer(false)
Expand All @@ -522,6 +522,38 @@ func TestTransportProtocol_HTTP1WhenUsingProxy(t *testing.T) {
}
defer resp.Body.Close()

// Assert that the server chose HTTP/2.0 because a proxy was configured
assert.Equal(t, "HTTP/2.0", resp.Proto)
}

func TestTransportProtocol_HTTP1FallBackWhenUsingProxy(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
c.SetWithoutSource("proxy.http", "http://foo.bar")

// Start the test server that only support HTTP/1.1
server := NewTestHTTPSServer(true)
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
@@ -0,0 +1,11 @@
# Each section from every release note 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:
- |
Log Agent now officially supports http2 transport to proxy.

0 comments on commit bc60970

Please sign in to comment.