Add config option for HTTP keep-alives

This commit is contained in:
Holger Obermaier 2023-10-11 17:28:16 +02:00
parent f059d52d43
commit 595399e7d9
2 changed files with 6 additions and 0 deletions

View File

@ -28,6 +28,9 @@ type HttpReceiverConfig struct {
IdleTimeout string `json:"idle_timeout"`
idleTimeout time.Duration
// Controls whether HTTP keep-alives are enabled. By default, keep-alives are enabled
KeepAlivesEnabled bool `json:"keep_alives_enabled"`
// Basic authentication
Username string `json:"username"`
Password string `json:"password"`
@ -47,6 +50,7 @@ func (r *HttpReceiver) Init(name string, config json.RawMessage) error {
// Set default values
r.config.Port = HTTP_RECEIVER_PORT
r.config.KeepAlivesEnabled = true
// should be larger than the measurement interval to keep the connection open
r.config.IdleTimeout = "120s"
@ -100,6 +104,7 @@ func (r *HttpReceiver) Init(name string, config json.RawMessage) error {
Handler: nil, // handler to invoke, http.DefaultServeMux if nil
IdleTimeout: r.config.idleTimeout,
}
r.server.SetKeepAlivesEnabled(r.config.KeepAlivesEnabled)
return nil
}

View File

@ -23,6 +23,7 @@ The `http` receiver can be used receive metrics through HTTP POST requests.
- `port`: Listen port
- `path`: URL path for the write endpoint
- `idle_timeout`: Maximum amount of time to wait for the next request when keep-alives are enabled should be larger than the measurement interval to keep the connection open
- `keep_alives_enabled`: Controls whether HTTP keep-alives are enabled. By default, keep-alives are enabled.
- `username`: username for basic authentication
- `password`: password for basic authentication