From a24541bdb7016a6f906e6632a0ea521b3c38f785 Mon Sep 17 00:00:00 2001 From: hagen1778 Date: Thu, 20 Jul 2023 15:32:49 +0200 Subject: [PATCH] docs: specify min version and limitations for vmalert's unit tests Signed-off-by: hagen1778 --- app/vmalert/README.md | 3 +++ docs/vmalert.md | 48 ++++++++++++++++++++++++++++--------------- 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/app/vmalert/README.md b/app/vmalert/README.md index 009a8ded6..ddb836daf 100644 --- a/app/vmalert/README.md +++ b/app/vmalert/README.md @@ -734,6 +734,9 @@ See full description for these flags in `./vmalert -help`. ## Unit Testing for Rules +> Unit testing is available from v1.94.0. +> Unit tests do not respect `-clusterMode` for now. + You can use `vmalert` to run unit tests for alerting and recording rules. In unit test mode vmalert performs the following actions: * sets up an isolated VictoriaMetrics instance; diff --git a/docs/vmalert.md b/docs/vmalert.md index 9e55cf839..885deef6f 100644 --- a/docs/vmalert.md +++ b/docs/vmalert.md @@ -745,21 +745,35 @@ See full description for these flags in `./vmalert -help`. ## Unit Testing for Rules -You can use `vmalert` to test your rules. -It will setup an isolated VM instance, simulate the periodic ingestion of samples for several time series, use those series to evaluate recording and alerting rules, and then test whether the firing alerts or metricsql expressions match what was configured as the expected results. +> Unit testing is available from v1.94.0. +> Unit tests do not respect `-clusterMode` for now. +You can use `vmalert` to run unit tests for alerting and recording rules. +In unit test mode vmalert performs the following actions: +* sets up an isolated VictoriaMetrics instance; +* simulates the periodic ingestion of time series; +* queries the ingested data for recording and alerting rules evaluation; +* tests whether the firing alerts or resulting recording rules match the expected results. + +See how to run vmalert in unit test mode below: ``` # Run vmalert with one or multiple test files via -unittestFile cmd-line flag ./vmalert -unittestFile=test1.yaml -unittestFile=test2.yaml ``` +vmalert is compatible with [Prometheus config format for tests](https://prometheus.io/docs/prometheus/latest/configuration/unit_testing_rules/#test-file-format) +except `promql_expr_test` field. Use `metricsql_expr_test` field name instead. The name is different because vmalert +validates and executes [MetricsQL](https://docs.victoriametrics.com/MetricsQL.html) expressions, +which aren't always backward compatible with [PromQL](https://prometheus.io/docs/prometheus/latest/querying/basics/). + ### Test file format +The configuration format for files specified in `-unittestFile` cmd-line flag is the following: ``` # Path to the files or http url containing [rule groups](https://docs.victoriametrics.com/vmalert.html#groups) configuration. # Enterprise version of vmalert supports S3 and GCS paths to rules. rule_files: - [ - ] + [ - ] # The evaluation interval for rules specified in `rule_files` [ evaluation_interval: | default = 1m ] @@ -767,7 +781,7 @@ rule_files: # Groups listed below will be evaluated by order. # Not All the groups need not be mentioned, if not, they will be evaluated by define order in rule_files. group_eval_order: - [ - ] + [ - ] # The list of unit test files to be checked during evaluation. tests: @@ -786,7 +800,7 @@ input_series: # Name of the test group, optional [ name: ] -# Unit tests for alerting rules. Alerting rules are from the input file. +# Unit tests for alerting rules alert_rule_test: [ - ] @@ -794,7 +808,7 @@ alert_rule_test: metricsql_expr_test: [ - ] -# External labels accessible to the alert template. +# External labels accessible for templating. external_labels: [ : ... ] @@ -803,7 +817,7 @@ external_labels: #### `` ``` -# series should format as '{