diff --git a/pkg/logs/client/http/destination.go b/pkg/logs/client/http/destination.go index 93bf35ec67167..71af3e9ae5c9c 100644 --- a/pkg/logs/client/http/destination.go +++ b/pkg/logs/client/http/destination.go @@ -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": diff --git a/pkg/logs/client/http/destination_test.go b/pkg/logs/client/http/destination_test.go index 3f65bba9b9e2c..3592efaf9db63 100644 --- a/pkg/logs/client/http/destination_test.go +++ b/pkg/logs/client/http/destination_test.go @@ -495,7 +495,7 @@ 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 @@ -503,7 +503,7 @@ func TestTransportProtocol_HTTP1WhenUsingProxy(t *testing.T) { 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) @@ -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) } diff --git a/releasenotes/notes/enable-http2-for-log-agent-proxy-2fc186ff7688473c.yaml b/releasenotes/notes/enable-http2-for-log-agent-proxy-2fc186ff7688473c.yaml new file mode 100644 index 0000000000000..4373893a7b705 --- /dev/null +++ b/releasenotes/notes/enable-http2-for-log-agent-proxy-2fc186ff7688473c.yaml @@ -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. \ No newline at end of file