From 109e55f865a4a88def508f6a67387a80507ba3f9 Mon Sep 17 00:00:00 2001 From: Roman Khavronenko Date: Fri, 7 Jul 2023 07:44:34 +0200 Subject: [PATCH] vmalert: allow disabling of `step` param attached to instant queries (#4574) vmalert: allow disabling of `step` param attached to instant queries This might be useful for using vmalert with datasources that to not support this param, unlike VictoriaMetrics. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4573 Signed-off-by: hagen1778 --- app/vmalert/README.md | 2 ++ app/vmalert/datasource/vm_prom_api.go | 7 +++++-- docs/CHANGELOG.md | 1 + docs/vmalert.md | 2 ++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/app/vmalert/README.md b/app/vmalert/README.md index 0e2b29bd4..0b25c4a01 100644 --- a/app/vmalert/README.md +++ b/app/vmalert/README.md @@ -920,6 +920,8 @@ The shortlist of configuration flags is the following: 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.disableStepParam + Whether to disable adding 'step' param to the issued instant queries. This might be useful when using vmalert with datasources that do not support 'step' param for instant queries, like Google Managed Prometheus. It is not recommended to enable this flag if you use vmalert with VictoriaMetrics. -datasource.headers string Optional HTTP extraHeaders to send with each request to the corresponding -datasource.url. For example, -datasource.headers='My-Auth:foobar' would send 'My-Auth: foobar' HTTP header with every request to the corresponding -datasource.url. Multiple headers must be delimited by '^^': -datasource.headers='header1:value1^^header2:value2' -datasource.lookback duration diff --git a/app/vmalert/datasource/vm_prom_api.go b/app/vmalert/datasource/vm_prom_api.go index 950165f6a..fc2ef88a9 100644 --- a/app/vmalert/datasource/vm_prom_api.go +++ b/app/vmalert/datasource/vm_prom_api.go @@ -12,6 +12,9 @@ import ( var ( disablePathAppend = flag.Bool("remoteRead.disablePathAppend", false, "Whether to disable automatic appending of '/api/v1/query' path "+ "to the configured -datasource.url and -remoteRead.url") + disableStepParam = flag.Bool("datasource.disableStepParam", false, "Whether to disable adding 'step' param to the issued instant queries. "+ + "This might be useful when using vmalert with datasources that do not support 'step' param for instant queries, like Google Managed Prometheus. "+ + "It is not recommended to enable this flag if you use vmalert with VictoriaMetrics.") ) type promResponse struct { @@ -166,12 +169,12 @@ func (s *VMStorage) setPrometheusInstantReqParams(r *http.Request, query string, timestamp = timestamp.Truncate(s.evaluationInterval) } q.Set("time", fmt.Sprintf("%d", timestamp.Unix())) - if s.evaluationInterval > 0 { // set step as evaluationInterval by default + if !*disableStepParam && s.evaluationInterval > 0 { // set step as evaluationInterval by default // always convert to seconds to keep compatibility with older // Prometheus versions. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1943 q.Set("step", fmt.Sprintf("%ds", int(s.evaluationInterval.Seconds()))) } - if s.queryStep > 0 { // override step with user-specified value + if !*disableStepParam && s.queryStep > 0 { // override step with user-specified value // always convert to seconds to keep compatibility with older // Prometheus versions. See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1943 q.Set("step", fmt.Sprintf("%ds", int(s.queryStep.Seconds()))) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index e2af91c60..22c7b9bce 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -35,6 +35,7 @@ The following tip changes can be tested by building VictoriaMetrics components f * FEATURE: [vmalert](https://docs.victoriametrics.com/vmalert.html): update retry policy for pushing data to `-remoteWrite.url`. By default, vmalert will make multiple retry attempts with exponential delay. The total time spent during retry attempts shouldn't exceed `-remoteWrite.retryMaxTime` (default is 30s). When retry time is exceeded vmalert drops the data dedicated for `-remoteWrite.url`. Before, vmalert dropped data after 5 retry attempts with 1s delay between attempts (not configurable). See `-remoteWrite.retryMinInterval` and `-remoteWrite.retryMaxTime` cmd-line flags. * FEATURE: [vmalert](https://docs.victoriametrics.com/vmalert.html): expose `vmalert_remotewrite_send_duration_seconds_total` counter, which can be used for determining high saturation of every connection to remote storage with an alerting query `sum(rate(vmalert_remotewrite_send_duration_seconds_total[5m])) by(job, instance) > 0.9 * max(vmalert_remotewrite_concurrency) by(job, instance)`. This query triggers when a connection is saturated by more than 90%. This usually means that `-remoteWrite.concurrency` command-line flag must be increased in order to increase the number of concurrent writings into remote endpoint. See [this feature request](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4516). * FEATUTE: [vmalert](https://docs.victoriametrics.com/vmalert.html): display the error message received during unsuccessful config reload in vmalert's UI. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4076) for details. +* FEATUTE: [vmalert](https://docs.victoriametrics.com/vmalert.html): allow disabling of `step` param attached to [instant queries](https://docs.victoriametrics.com/keyConcepts.html#instant-query). This might be useful for using vmalert with datasources that to not support this param, unlike VictoriaMetrics. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4573) for details. * FEATURE: [vmauth](https://docs.victoriametrics.com/vmauth.html): expose `vmauth_user_request_duration_seconds` and `vmauth_unauthorized_user_request_duration_seconds` summary metrics for measuring requests latency per user. * FEATURE: [vmbackup](https://docs.victoriametrics.com/vmbackup.html): show backup progress percentage in log during backup uploading. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4460). * FEATURE: [vmrestore](https://docs.victoriametrics.com/vmrestore.html): show restoring progress percentage in log during backup downloading. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/4460). diff --git a/docs/vmalert.md b/docs/vmalert.md index dd640b1f1..a914402a5 100644 --- a/docs/vmalert.md +++ b/docs/vmalert.md @@ -931,6 +931,8 @@ The shortlist of configuration flags is the following: 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.disableStepParam + Whether to disable adding 'step' param to the issued instant queries. This might be useful when using vmalert with datasources that do not support 'step' param for instant queries, like Google Managed Prometheus. It is not recommended to enable this flag if you use vmalert to query VictoriaMetrics. -datasource.headers string Optional HTTP extraHeaders to send with each request to the corresponding -datasource.url. For example, -datasource.headers='My-Auth:foobar' would send 'My-Auth: foobar' HTTP header with every request to the corresponding -datasource.url. Multiple headers must be delimited by '^^': -datasource.headers='header1:value1^^header2:value2' -datasource.lookback duration