diff --git a/app/vmalert/README.md b/app/vmalert/README.md index 191105df5c..b8fd1f6508 100644 --- a/app/vmalert/README.md +++ b/app/vmalert/README.md @@ -525,6 +525,8 @@ The shortlist of configuration flags is the following: Optional bearer auth token to use for -datasource.url. -datasource.bearerTokenFile string Optional path to bearer token file to use for -datasource.url. + -datasource.disableKeepAlive + Whether to disable long-lived connections to the datasource. If true, disables HTTP keep-alives and will only use the connection to the server for a single HTTP request. -datasource.lookback duration Lookback defines how far into the past to look when evaluating queries. For example, if the datasource.lookback=5m then param "time" with value now()-5m will be added to every query. -datasource.maxIdleConnections int diff --git a/app/vmalert/datasource/init.go b/app/vmalert/datasource/init.go index 004a9b36d0..891e7f991e 100644 --- a/app/vmalert/datasource/init.go +++ b/app/vmalert/datasource/init.go @@ -41,7 +41,9 @@ var ( queryTimeAlignment = flag.Bool("datasource.queryTimeAlignment", true, `Whether to align "time" parameter with evaluation interval.`+ "Alignment supposed to produce deterministic results despite of number of vmalert replicas or time they were started. See more details here https://github.com/VictoriaMetrics/VictoriaMetrics/pull/1257") maxIdleConnections = flag.Int("datasource.maxIdleConnections", 100, `Defines the number of idle (keep-alive connections) to each configured datasource. Consider setting this value equal to the value: groups_total * group.concurrency. Too low a value may result in a high number of sockets in TIME_WAIT state.`) - roundDigits = flag.Int("datasource.roundDigits", 0, `Adds "round_digits" GET param to datasource requests. `+ + disableKeepAlive = flag.Bool("datasource.disableKeepAlive", false, `Whether to disable long-lived connections to the datasource. `+ + `If true, disables HTTP keep-alives and will only use the connection to the server for a single HTTP request.`) + roundDigits = flag.Int("datasource.roundDigits", 0, `Adds "round_digits" GET param to datasource requests. `+ `In VM "round_digits" limits the number of digits after the decimal point in response values.`) ) @@ -62,6 +64,7 @@ func Init(extraParams url.Values) (QuerierBuilder, error) { if err != nil { return nil, fmt.Errorf("failed to create transport: %w", err) } + tr.DisableKeepAlives = *disableKeepAlive tr.MaxIdleConnsPerHost = *maxIdleConnections if tr.MaxIdleConns != 0 && tr.MaxIdleConns < tr.MaxIdleConnsPerHost { tr.MaxIdleConns = tr.MaxIdleConnsPerHost diff --git a/docs/vmalert.md b/docs/vmalert.md index f01dcf6c55..c1ae5b979c 100644 --- a/docs/vmalert.md +++ b/docs/vmalert.md @@ -529,6 +529,8 @@ The shortlist of configuration flags is the following: Optional bearer auth token to use for -datasource.url. -datasource.bearerTokenFile string Optional path to bearer token file to use for -datasource.url. + -datasource.disableKeepAlive + Whether to disable long-lived connections to the datasource. If true, disables HTTP keep-alives and will only use the connection to the server for a single HTTP request. -datasource.lookback duration Lookback defines how far into the past to look when evaluating queries. For example, if the datasource.lookback=5m then param "time" with value now()-5m will be added to every query. -datasource.maxIdleConnections int