Skip to content

Commit

Permalink
[confighttp] Add read_timeout and read_header_timeout options to …
Browse files Browse the repository at this point in the history
…confighttp, to use as HTTP server config options.
  • Loading branch information
atoulme committed May 31, 2024
1 parent 4bbb604 commit 589f59b
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 5 deletions.
25 changes: 25 additions & 0 deletions .chloggen/confighttp_read_timeout.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 `read_timeout` and `read_header_timeout` options to confighttp, to use as HTTP server config options.

# One or more tracking issues or pull requests related to the change
issues: [5699]

# (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: []
4 changes: 0 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,6 @@ issues:
- text: "G402:"
linters:
- gosec
# https://github.com/open-telemetry/opentelemetry-collector/issues/5699
- text: "G112:"
linters:
- gosec

# The list of ids of default excludes to include or disable. By default it's empty.
# See the list of default excludes here https://golangci-lint.run/usage/configuration.
Expand Down
5 changes: 5 additions & 0 deletions config/confighttp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ will not be enabled.
- `max_request_body_size`: configures the maximum allowed body size in bytes for a single request. Default: `0` (no restriction)
- [`tls`](../configtls/README.md)
- [`auth`](../configauth/README.md)
- [`read_timeout`]: maximum duration for reading the entire request, including the body.
A zero or negative value means there will be no timeout. Default: `0` (no timeout)
- [`read_header_timeout`]: amount of time allowed to read request headers. The connection's read deadline is reset
after reading the headers and the Handler can decide what is considered too slow for the body.
If set to zero, the value of `read_timeout` is used. If both are zero, there is no timeout. Default: `0` (no timeout)

You can enable [`attribute processor`][attribute-processor] to append any http header to span's attribute using custom key. You also need to enable the "include_metadata"

Expand Down
22 changes: 21 additions & 1 deletion config/confighttp/confighttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,24 @@ type ServerConfig struct {
// Additional headers attached to each HTTP response sent to the client.
// Header values are opaque since they may be sensitive.
ResponseHeaders map[string]configopaque.String `mapstructure:"response_headers"`

// ReadTimeout is the maximum duration for reading the entire
// request, including the body. A zero or negative value means
// there will be no timeout.
//
// Because ReadTimeout does not let Handlers make per-request
// decisions on each request body's acceptable deadline or
// upload rate, most users will prefer to use
// ReadHeaderTimeout. It is valid to use them both.
ReadTimeout time.Duration `mapstructure:"read_timeout"`

// ReadHeaderTimeout is the amount of time allowed to read
// request headers. The connection's read deadline is reset
// after reading the headers and the Handler can decide what
// is considered too slow for the body. If ReadHeaderTimeout
// is zero, the value of ReadTimeout is used. If both are
// zero, there is no timeout.
ReadHeaderTimeout time.Duration `mapstructure:"read_header_timeout"`
}

// ToListener creates a net.Listener.
Expand Down Expand Up @@ -394,7 +412,9 @@ func (hss *ServerConfig) ToServer(_ context.Context, host component.Host, settin
}

return &http.Server{
Handler: handler,
Handler: handler,
ReadTimeout: hss.ReadTimeout,
ReadHeaderTimeout: hss.ReadHeaderTimeout,
}, nil
}

Expand Down

0 comments on commit 589f59b

Please sign in to comment.