Skip to content
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
25 changes: 25 additions & 0 deletions .chloggen/http2.yaml
Original file line number Diff line number Diff line change
@@ -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: []
1 change: 1 addition & 0 deletions config/confighttp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 10 additions & 3 deletions config/confighttp/confighttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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,
}
}

Expand Down Expand Up @@ -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
Comment thread
andrzej-stencel marked this conversation as resolved.

// Setting the Proxy URL
if hcs.ProxyURL != "" {
Expand Down
27 changes: 25 additions & 2 deletions config/confighttp/confighttp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions exporter/otlphttpexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func TestUnmarshalConfig(t *testing.T) {
MaxIdleConnsPerHost: defaultMaxIdleConnsPerHost,
MaxConnsPerHost: defaultMaxConnsPerHost,
IdleConnTimeout: defaultIdleConnTimeout,
ForceAttemptHTTP2: true,
},
}, cfg)
}
Expand Down
7 changes: 4 additions & 3 deletions internal/e2e/confighttp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading