Skip to content

Commit ff849f4

Browse files
authored
Default force_attempt_http2 to true and allow configuration (#5050)
* Default force_attempt_http2 to true and allow configuration * update changelog * Fix tests and default faro behavior
1 parent 0e58252 commit ff849f4

File tree

12 files changed

+42
-19
lines changed

12 files changed

+42
-19
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ Main (unreleased)
6161

6262
- Fix Docker log corruption for multiplexed long lines. (@axd1x8a)
6363

64+
- Allow configuration of `force_attempt_http2` and default it to `true` for otelcol exporters with HTTP client configurations. (@dehaansa)
65+
6466
v1.12.0
6567
-----------------
6668

docs/sources/reference/components/otelcol/otelcol.exporter.splunkhec.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ The following arguments are supported:
149149
| Name | Type | Description | Default | Required |
150150
|---------------------------|------------|-------------------------------------------------------------------------------------------------|---------|----------|
151151
| `endpoint` | `string` | The Splunk HEC endpoint to use. | | yes |
152+
| `force_attempt_http2` | `bool` | Force the HTTP client to try to use the HTTP/2 protocol. | `true` | no |
152153
| `disable_keep_alives` | `bool` | Disable HTTP keep-alive. | `false` | no |
153154
| `idle_conn_timeout` | `duration` | Time to wait before an idle connection closes itself. | `"45s"` | no |
154155
| `insecure_skip_verify` | `bool` | Ignores insecure server TLS certificates. | `false` | no |

docs/sources/shared/reference/components/otelcol-http-client-block.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ The following arguments are supported:
1212
| `auth` | `capsule(otelcol.Handler)` | Handler from an `otelcol.auth` component to use for authenticating requests. | | no |
1313
| `compression` | `string` | Compression mechanism to use for requests. | `"gzip"` | no |
1414
| `disable_keep_alives` | `bool` | Disable HTTP keep-alive. | `false` | no |
15+
| `force_attempt_http2` | `bool` | Force the HTTP client to try to use the HTTP/2 protocol. | `true` | no |
1516
| `headers` | `map(string)` | Additional headers to send with the request. | `{}` | no |
1617
| `http2_ping_timeout` | `duration` | Timeout after which the connection will be closed if a response to Ping isn't received. | `"15s"` | no |
1718
| `http2_read_idle_timeout` | `duration` | Timeout after which a health check using ping frame will be carried out if no frame is received on the connection. | `"0s"` | no |
@@ -36,4 +37,7 @@ If `http2_ping_timeout` is unset or set to `0s`, it will default to `15s`.
3637

3738
If `http2_read_idle_timeout` is unset or set to `0s`, then no health check will be performed.
3839

40+
Golang's default HTTP transport attempts HTTP/2 by default, however some settings (`max_conns_per_host`, `max_idle_conns_per_host`, `max_idle_conns`) are only relevant for HTTP/1.
41+
The `force_attempt_http2` attribute allows a user to only attempt HTTP/1.
42+
3943
{{< docs/shared lookup="reference/components/otelcol-compression-field.md" source="alloy" version="<ALLOY_VERSION>" >}}

internal/component/otelcol/config_http.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ type HTTPClientArguments struct {
148148
DisableKeepAlives bool `alloy:"disable_keep_alives,attr,optional"`
149149
HTTP2ReadIdleTimeout time.Duration `alloy:"http2_read_idle_timeout,attr,optional"`
150150
HTTP2PingTimeout time.Duration `alloy:"http2_ping_timeout,attr,optional"`
151+
ForceAttemptHTTP2 bool `alloy:"force_attempt_http2,attr,optional"`
151152

152153
// Auth is a binding to an otelcol.auth.* component extension which handles
153154
// authentication.
@@ -198,6 +199,7 @@ func (args *HTTPClientArguments) Convert() (*otelconfighttp.ClientConfig, error)
198199
DisableKeepAlives: args.DisableKeepAlives,
199200
HTTP2ReadIdleTimeout: args.HTTP2ReadIdleTimeout,
200201
HTTP2PingTimeout: args.HTTP2PingTimeout,
202+
ForceAttemptHTTP2: args.ForceAttemptHTTP2,
201203

202204
Auth: authentication,
203205

internal/component/otelcol/exporter/faro/faro.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,12 @@ type HTTPClientArguments otelcol.HTTPClientArguments
9999
// SetToDefault implements syntax.Defaulter.
100100
func (args *HTTPClientArguments) SetToDefault() {
101101
*args = HTTPClientArguments{
102-
Timeout: 30 * time.Second,
103-
MaxIdleConns: 100,
104-
IdleConnTimeout: 90 * time.Second,
105-
Headers: map[string]string{},
106-
Compression: otelcol.CompressionTypeGzip,
107-
WriteBufferSize: 512 * 1024,
102+
Timeout: 30 * time.Second,
103+
MaxIdleConns: 100,
104+
IdleConnTimeout: 90 * time.Second,
105+
Headers: map[string]string{},
106+
Compression: otelcol.CompressionTypeGzip,
107+
WriteBufferSize: 512 * 1024,
108+
ForceAttemptHTTP2: true,
108109
}
109110
}

internal/component/otelcol/exporter/faro/faro_test.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func TestConfigConversion(t *testing.T) {
3737
headers = {
3838
"X-Scope-OrgID" = "123",
3939
}
40+
force_attempt_http2 = false
4041
}
4142
sending_queue {
4243
enabled = true
@@ -63,6 +64,7 @@ func TestConfigConversion(t *testing.T) {
6364
Headers: configopaque.MapList{
6465
configopaque.Pair{Name: "X-Scope-OrgID", Value: "123"},
6566
},
67+
ForceAttemptHTTP2: false,
6668
},
6769
QueueConfig: defaultQueueConfig,
6870
RetryConfig: configretry.BackOffConfig{
@@ -84,13 +86,14 @@ func TestConfigConversion(t *testing.T) {
8486
`,
8587
expected: faroexporter.Config{
8688
ClientConfig: confighttp.ClientConfig{
87-
Endpoint: "https://faro.example.com/collect",
88-
Timeout: defaultTimeout,
89-
Compression: "gzip",
90-
WriteBufferSize: 512 * 1024,
91-
MaxIdleConns: 100,
92-
IdleConnTimeout: 90 * time.Second,
93-
Headers: configopaque.MapList{},
89+
Endpoint: "https://faro.example.com/collect",
90+
Timeout: defaultTimeout,
91+
Compression: "gzip",
92+
WriteBufferSize: 512 * 1024,
93+
MaxIdleConns: 100,
94+
IdleConnTimeout: 90 * time.Second,
95+
Headers: configopaque.MapList{},
96+
ForceAttemptHTTP2: true,
9497
},
9598
QueueConfig: defaultQueueConfig,
9699
RetryConfig: defaultRetrySettings,

internal/component/otelcol/exporter/otlphttp/otlphttp.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,12 @@ func (args *HTTPClientArguments) SetToDefault() {
137137
MaxIdleConns: maxIdleConns,
138138
IdleConnTimeout: idleConnTimeout,
139139

140-
Timeout: 30 * time.Second,
141-
Headers: map[string]string{},
142-
Compression: otelcol.CompressionTypeGzip,
143-
ReadBufferSize: 0,
144-
WriteBufferSize: 512 * 1024,
145-
HTTP2PingTimeout: 15 * time.Second,
140+
Timeout: 30 * time.Second,
141+
Headers: map[string]string{},
142+
Compression: otelcol.CompressionTypeGzip,
143+
ReadBufferSize: 0,
144+
WriteBufferSize: 512 * 1024,
145+
HTTP2PingTimeout: 15 * time.Second,
146+
ForceAttemptHTTP2: true,
146147
}
147148
}

internal/component/otelcol/exporter/splunkhec/config/splunkhec.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ type SplunkHecClientArguments struct {
6060
DisableKeepAlives bool `alloy:"disable_keep_alives,attr,optional"`
6161
// TLSSetting for the HTTP client.
6262
InsecureSkipVerify bool `alloy:"insecure_skip_verify,attr,optional"`
63+
// ForceAttemptHTTP2 for the HTTP client.
64+
ForceAttemptHTTP2 bool `alloy:"force_attempt_http2,attr,optional"`
6365
}
6466
type SplunkConf struct {
6567
// DeprecatedBatcher is the deprecated batcher configuration.
@@ -230,6 +232,7 @@ func (args *SplunkHecClientArguments) Convert() *confighttp.ClientConfig {
230232
MaxConnsPerHost: args.MaxConnsPerHost,
231233
IdleConnTimeout: args.IdleConnTimeout,
232234
DisableKeepAlives: args.DisableKeepAlives,
235+
ForceAttemptHTTP2: args.ForceAttemptHTTP2,
233236
TLS: configtls.ClientConfig{
234237
InsecureSkipVerify: args.InsecureSkipVerify,
235238
},
@@ -240,6 +243,7 @@ func (args *SplunkHecClientArguments) SetToDefault() {
240243
args.Timeout = 15 * time.Second
241244
args.MaxIdleConns = 100
242245
args.IdleConnTimeout = 90 * time.Second
246+
args.ForceAttemptHTTP2 = true
243247
}
244248

245249
func (args *SplunkHecClientArguments) Validate() error {

internal/component/otelcol/exporter/splunkhec/splunkhec_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ func TestConfigConversion(t *testing.T) {
5252
HTTP2ReadIdleTimeout: 0,
5353
HTTP2PingTimeout: 0,
5454
Cookies: confighttp.CookiesConfig{},
55+
ForceAttemptHTTP2: true,
5556
},
5657
QueueSettings: exporterhelper.QueueBatchConfig{
5758
Enabled: true,
@@ -139,6 +140,7 @@ func TestConfigConversion(t *testing.T) {
139140
DisableKeepAlives: false,
140141
HTTP2ReadIdleTimeout: 0,
141142
HTTP2PingTimeout: 0,
143+
ForceAttemptHTTP2: true,
142144
Cookies: confighttp.CookiesConfig{}},
143145
QueueSettings: exporterhelper.QueueBatchConfig{
144146
Enabled: true,

internal/converter/internal/otelcolconvert/converter_faroexporter.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ func toFaroHTTPClientArguments(cfg confighttp.ClientConfig) faro.HTTPClientArgum
9191
DisableKeepAlives: cfg.DisableKeepAlives,
9292
HTTP2PingTimeout: cfg.HTTP2PingTimeout,
9393
HTTP2ReadIdleTimeout: cfg.HTTP2ReadIdleTimeout,
94+
ForceAttemptHTTP2: cfg.ForceAttemptHTTP2,
9495

9596
Authentication: a,
9697
}

0 commit comments

Comments
 (0)