diff --git a/.chloggen/http2.yaml b/.chloggen/http2.yaml new file mode 100644 index 00000000000..af1bac4a634 --- /dev/null +++ b/.chloggen/http2.yaml @@ -0,0 +1,25 @@ +# 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. otlpreceiver) +component: confighttp + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Add option to configure ForceAttemptHTTP2 to support HTTP/1 specific transport settings. + +# One or more tracking issues or pull requests related to the change +issues: [13426] + +# (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: + +# 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: [] diff --git a/config/confighttp/README.md b/config/confighttp/README.md index 20abc5dbaf0..08987e61161 100644 --- a/config/confighttp/README.md +++ b/config/confighttp/README.md @@ -56,6 +56,7 @@ README](../configtls/README.md). - [`idle_conn_timeout`](https://golang.org/pkg/net/http/#Transport) - [`auth`](../configauth/README.md) - [`disable_keep_alives`](https://golang.org/pkg/net/http/#Transport) +- [`force_attempt_http2`](https://golang.org/pkg/net/http/#Transport) - [`http2_read_idle_timeout`](https://pkg.go.dev/golang.org/x/net/http2#Transport) - [`http2_ping_timeout`](https://pkg.go.dev/golang.org/x/net/http2#Transport) - [`cookies`](https://pkg.go.dev/net/http#CookieJar) diff --git a/config/confighttp/confighttp.go b/config/confighttp/confighttp.go index dff7685cfb3..fbf1c9f638c 100644 --- a/config/confighttp/confighttp.go +++ b/config/confighttp/confighttp.go @@ -119,6 +119,11 @@ type ClientConfig struct { // Cookies configures the cookie management of the HTTP client. Cookies CookiesConfig `mapstructure:"cookies,omitempty"` + // Enabling ForceAttemptHTTP2 forces the HTTP transport to use the HTTP/2 protocol. + // By default, this is set to true. + // NOTE: HTTP/2 does not support settings such as MaxConnsPerHost, MaxIdleConnsPerHost and MaxIdleConns. + ForceAttemptHTTP2 bool `mapstructure:"force_attempt_http2,omitempty"` + // Middlewares are used to add custom functionality to the HTTP client. // Middleware handlers are called in the order they appear in this list, // with the first middleware becoming the outermost handler. @@ -141,9 +146,10 @@ func NewDefaultClientConfig() ClientConfig { defaultTransport := http.DefaultTransport.(*http.Transport) return ClientConfig{ - Headers: map[string]configopaque.String{}, - MaxIdleConns: defaultTransport.MaxIdleConns, - IdleConnTimeout: defaultTransport.IdleConnTimeout, + Headers: map[string]configopaque.String{}, + MaxIdleConns: defaultTransport.MaxIdleConns, + IdleConnTimeout: defaultTransport.IdleConnTimeout, + ForceAttemptHTTP2: true, } } @@ -184,6 +190,7 @@ func (hcs *ClientConfig) ToClient(ctx context.Context, host component.Host, sett transport.MaxIdleConnsPerHost = hcs.MaxIdleConnsPerHost transport.MaxConnsPerHost = hcs.MaxConnsPerHost transport.IdleConnTimeout = hcs.IdleConnTimeout + transport.ForceAttemptHTTP2 = hcs.ForceAttemptHTTP2 // Setting the Proxy URL if hcs.ProxyURL != "" { diff --git a/config/confighttp/confighttp_test.go b/config/confighttp/confighttp_test.go index 99e43260a62..8299927238c 100644 --- a/config/confighttp/confighttp_test.go +++ b/config/confighttp/confighttp_test.go @@ -98,6 +98,28 @@ func TestAllHTTPClientSettings(t *testing.T) { }, shouldError: false, }, + { + name: "all_valid_settings_http2_enabled", + settings: ClientConfig{ + Endpoint: "localhost:1234", + TLS: configtls.ClientConfig{ + Insecure: false, + }, + ReadBufferSize: 1024, + WriteBufferSize: 512, + MaxIdleConns: maxIdleConns, + MaxIdleConnsPerHost: maxIdleConnsPerHost, + MaxConnsPerHost: maxConnsPerHost, + ForceAttemptHTTP2: true, + IdleConnTimeout: idleConnTimeout, + Compression: "", + DisableKeepAlives: true, + Cookies: CookiesConfig{Enabled: true}, + HTTP2ReadIdleTimeout: idleConnTimeout, + HTTP2PingTimeout: http2PingTimeout, + }, + shouldError: false, + }, { name: "all_valid_settings_with_none_compression", settings: ClientConfig{ @@ -696,8 +718,9 @@ func TestHttpReception(t *testing.T) { } hcs := &ClientConfig{ - Endpoint: prefix + ln.Addr().String(), - TLS: *tt.tlsClientCreds, + Endpoint: prefix + ln.Addr().String(), + TLS: *tt.tlsClientCreds, + ForceAttemptHTTP2: true, } client, errClient := hcs.ToClient(context.Background(), componenttest.NewNopHost(), nilProvidersSettings) diff --git a/exporter/otlphttpexporter/config_test.go b/exporter/otlphttpexporter/config_test.go index dc337d367b6..0ac8e1762d8 100644 --- a/exporter/otlphttpexporter/config_test.go +++ b/exporter/otlphttpexporter/config_test.go @@ -82,6 +82,7 @@ func TestUnmarshalConfig(t *testing.T) { MaxIdleConnsPerHost: defaultMaxIdleConnsPerHost, MaxConnsPerHost: defaultMaxConnsPerHost, IdleConnTimeout: defaultIdleConnTimeout, + ForceAttemptHTTP2: true, }, }, cfg) } diff --git a/internal/e2e/confighttp_test.go b/internal/e2e/confighttp_test.go index e4c5ff7928d..9442836ed5f 100644 --- a/internal/e2e/confighttp_test.go +++ b/internal/e2e/confighttp_test.go @@ -18,9 +18,10 @@ func TestConfmapMarshalConfigHTTP(t *testing.T) { conf := confmap.New() require.NoError(t, conf.Marshal(confighttp.NewDefaultClientConfig())) assert.Equal(t, map[string]any{ - "headers": map[string]any{}, - "idle_conn_timeout": 90 * time.Second, - "max_idle_conns": 100, + "headers": map[string]any{}, + "idle_conn_timeout": 90 * time.Second, + "max_idle_conns": 100, + "force_attempt_http2": true, }, conf.ToStringMap()) conf = confmap.New()