From 3169524fb774e6bd85ce0a3982a669b18fd5cf12 Mon Sep 17 00:00:00 2001 From: Hui Wang Date: Fri, 5 Jul 2024 15:27:34 +0800 Subject: [PATCH] =?UTF-8?q?vmalert:=20allow=20omitting=20`-replay.timeTo`?= =?UTF-8?q?=20in=20replay=20mode,=20default=20valu=E2=80=A6=20(#6575)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …e is the current timestamp address https://github.com/VictoriaMetrics/VictoriaMetrics/issues/6492 --------- Signed-off-by: hagen1778 Co-authored-by: hagen1778 --- app/vmalert/Makefile | 3 +-- app/vmalert/main.go | 2 +- app/vmalert/replay.go | 21 ++++++++++++++------- docs/CHANGELOG.md | 1 + docs/vmalert.md | 14 +++++++------- 5 files changed, 24 insertions(+), 17 deletions(-) diff --git a/app/vmalert/Makefile b/app/vmalert/Makefile index 610a8e137..05a7399c8 100644 --- a/app/vmalert/Makefile +++ b/app/vmalert/Makefile @@ -101,8 +101,7 @@ replay-vmalert: vmalert -remoteWrite.url=http://localhost:8428 \ -external.label=cluster=east-1 \ -external.label=replica=a \ - -replay.timeFrom=2021-05-11T07:21:43Z \ - -replay.timeTo=2021-05-29T18:40:43Z + -replay.timeFrom=2024-06-01T00:00:00Z vmalert-linux-amd64: APP_NAME=vmalert CGO_ENABLED=1 GOOS=linux GOARCH=amd64 $(MAKE) app-local-goos-goarch diff --git a/app/vmalert/main.go b/app/vmalert/main.go index 57c1cbb40..d6f164215 100644 --- a/app/vmalert/main.go +++ b/app/vmalert/main.go @@ -132,7 +132,7 @@ func main() { validateTplFn = notifier.ValidateTemplates } - if *replayFrom != "" || *replayTo != "" { + if *replayFrom != "" { rw, err := remotewrite.Init(context.Background()) if err != nil { logger.Fatalf("failed to init remoteWrite: %s", err) diff --git a/app/vmalert/replay.go b/app/vmalert/replay.go index 9559e85fe..162da1ba6 100644 --- a/app/vmalert/replay.go +++ b/app/vmalert/replay.go @@ -15,9 +15,10 @@ import ( var ( replayFrom = flag.String("replay.timeFrom", "", - "The time filter in RFC3339 format to select time series with timestamp equal or higher than provided value. E.g. '2020-01-01T20:07:00Z'") + "The time filter in RFC3339 format to start the replay from. E.g. '2020-01-01T20:07:00Z'") replayTo = flag.String("replay.timeTo", "", - "The time filter in RFC3339 format to select timeseries with timestamp equal or lower than provided value. E.g. '2020-01-01T20:07:00Z'") + "The time filter in RFC3339 format to finish the replay by. E.g. '2020-01-01T20:07:00Z'. "+ + "By default, is set to the current time.") replayRulesDelay = flag.Duration("replay.rulesDelay", time.Second, "Delay between rules evaluation within the group. Could be important if there are chained rules inside the group "+ "and processing need to wait for previous rule results to be persisted by remote storage before evaluating the next rule."+ @@ -36,14 +37,20 @@ func replay(groupsCfg []config.Group, qb datasource.QuerierBuilder, rw remotewri } tFrom, err := time.Parse(time.RFC3339, *replayFrom) if err != nil { - return fmt.Errorf("failed to parse %q: %w", *replayFrom, err) + return fmt.Errorf("failed to parse replay.timeFrom=%q: %w", *replayFrom, err) } - tTo, err := time.Parse(time.RFC3339, *replayTo) - if err != nil { - return fmt.Errorf("failed to parse %q: %w", *replayTo, err) + + // use tFrom location for default value, otherwise filters could have different locations + tTo := time.Now().In(tFrom.Location()) + if *replayTo != "" { + tTo, err = time.Parse(time.RFC3339, *replayTo) + if err != nil { + return fmt.Errorf("failed to parse replay.timeTo=%q: %w", *replayTo, err) + } } + if !tTo.After(tFrom) { - return fmt.Errorf("replay.timeTo must be bigger than replay.timeFrom") + return fmt.Errorf("replay.timeTo=%v must be bigger than replay.timeFrom=%v", tTo, tFrom) } labels := make(map[string]string) for _, s := range *externalLabels { diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 93bc51cc7..ebac923e8 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -47,6 +47,7 @@ See also [LTS releases](https://docs.victoriametrics.com/lts-releases/). * These and other metrics were reflected on the [vmagent dashboard](https://github.com/VictoriaMetrics/VictoriaMetrics/blob/master/dashboards/vmagent.json) in `stream aggregation` section. * FEATURE: [vmagent](https://docs.victoriametrics.com/vmagent/) and [Single-node VictoriaMetrics](https://docs.victoriametrics.com/): add `-graphite.sanitizeMetricName` cmd-line flag for sanitizing metrics ingested via [Graphite protocol](https://docs.victoriametrics.com/#how-to-send-data-from-graphite-compatible-agents-such-as-statsd). See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/6077). * FEATURE: [VictoriaMetrics cluster](https://docs.victoriametrics.com/cluster-victoriametrics/): do not retry RPC calls to vmstorage nodes if [complexity limits](https://docs.victoriametrics.com/#resource-usage-limits) were exceeded. +* FEATURE: [vmalert](https://docs.victoriametrics.com/vmalert/): make `-replay.timeTo` optional in [replay mode](https://docs.victoriametrics.com/vmalert/#rules-backfilling). When omitted, the current timestamp will be used. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/6492). * BUGFIX: [docker-compose](https://github.com/VictoriaMetrics/VictoriaMetrics/tree/master/deployment/docker#docker-compose-environment-for-victoriametrics): fix incorrect link to vmui from [VictoriaMetrics plugin in Grafana](https://github.com/VictoriaMetrics/VictoriaMetrics/tree/master/deployment/docker#grafana). * BUGFIX: [docker-compose](https://github.com/VictoriaMetrics/VictoriaMetrics/tree/master/deployment/docker#docker-compose-environment-for-victoriametrics): fix incorrect link to vmui from [VictoriaMetrics plugin in Grafana](https://github.com/VictoriaMetrics/VictoriaMetrics/tree/master/deployment/docker#grafana). diff --git a/docs/vmalert.md b/docs/vmalert.md index 7aceaeee5..a15f73bf1 100644 --- a/docs/vmalert.md +++ b/docs/vmalert.md @@ -737,8 +737,8 @@ To run vmalert in `replay` mode: ./bin/vmalert -rule=path/to/your.rules \ # path to files with rules you usually use with vmalert -datasource.url=http://localhost:8428 \ # Prometheus HTTP API compatible datasource -remoteWrite.url=http://localhost:8428 \ # remote write compatible storage to persist results - -replay.timeFrom=2021-05-11T07:21:43Z \ # time from begin replay - -replay.timeTo=2021-05-29T18:40:43Z # time to finish replay + -replay.timeFrom=2021-05-11T07:21:43Z \ # to start replay from + -replay.timeTo=2021-05-29T18:40:43Z # to finish replay by, is optional ``` The output of the command will look like the following: @@ -770,12 +770,12 @@ max range per request: 8h20m0s ``` In `replay` mode all groups are executed sequentially one-by-one. Rules within the group are -executed sequentially as well (`concurrency` setting is ignored). Vmalert sends rule's expression +executed sequentially as well (`concurrency` setting is ignored). vmalert sends rule's expression to [/query_range](https://docs.victoriametrics.com/keyconcepts/#range-query) endpoint of the configured `-datasource.url`. Returned data is then processed according to the rule type and backfilled to `-remoteWrite.url` via [remote Write protocol](https://prometheus.io/docs/prometheus/latest/storage/#remote-storage-integrations). -Vmalert respects `evaluationInterval` value set by flag or per-group during the replay. -Vmalert automatically disables caching on VictoriaMetrics side by sending `nocache=1` param. It allows +vmalert respects `evaluationInterval` value set by flag or per-group during the replay. +vmalert automatically disables caching on VictoriaMetrics side by sending `nocache=1` param. It allows to prevent cache pollution and unwanted time range boundaries adjustment during backfilling. #### Recording rules @@ -1408,9 +1408,9 @@ The shortlist of configuration flags is the following: -replay.rulesDelay duration Delay between rules evaluation within the group. Could be important if there are chained rules inside the group and processing need to wait for previous rule results to be persisted by remote storage before evaluating the next rule.Keep it equal or bigger than -remoteWrite.flushInterval. (default 1s) -replay.timeFrom string - The time filter in RFC3339 format to select time series with timestamp equal or higher than provided value. E.g. '2020-01-01T20:07:00Z' + The time filter in RFC3339 format to start the replay from. E.g. '2020-01-01T20:07:00Z' -replay.timeTo string - The time filter in RFC3339 format to select timeseries with timestamp equal or lower than provided value. E.g. '2020-01-01T20:07:00Z' + The time filter in RFC3339 format to finish the replay by. E.g. '2020-01-01T20:07:00Z'. By default, is set to the current time. -rule array Path to the files or http url with alerting and/or recording rules. Supports hierarchical patterns and regexpes.