From 9f1b9b86cc6ec1bd8e4e696d20b1d62a62a1f3bd Mon Sep 17 00:00:00 2001 From: Roman Khavronenko Date: Fri, 28 Jul 2023 10:42:02 +0200 Subject: [PATCH] vmalert: revert unittest feature (#4734) * Revert "vmalert: unittest support stale datapoint (#4696)" This reverts commit 0b44df7ec8bd28c8fd55bb5a70b99e275109b280. * Revert "docs: specify min version and limitations for vmalert's unit tests" This reverts commit a24541bd Signed-off-by: hagen1778 * Revert "vmalert: init unit test (#4596)" This reverts commit da60a68d Signed-off-by: hagen1778 * docs: mention unittest revert in changelog Signed-off-by: hagen1778 --------- Signed-off-by: hagen1778 --- app/vmalert/Makefile | 5 - app/vmalert/README.md | 248 ---------- app/vmalert/group.go | 4 +- app/vmalert/main.go | 16 +- app/vmalert/manager.go | 2 +- app/vmalert/manager_test.go | 2 +- app/vmalert/remotewrite/client.go | 320 ------------- app/vmalert/remotewrite/debug_client.go | 97 ---- app/vmalert/remotewrite/debug_client_test.go | 50 -- app/vmalert/remotewrite/remotewrite.go | 319 ++++++++++++- .../{client_test.go => remotewrite_test.go} | 0 app/vmalert/replay.go | 6 +- app/vmalert/unitest_test.go | 40 -- app/vmalert/unittest.go | 436 ------------------ app/vmalert/unittest/alerting.go | 19 - app/vmalert/unittest/input.go | 182 -------- app/vmalert/unittest/input_test.go | 93 ---- app/vmalert/unittest/recording.go | 92 ---- .../testdata/disable-group-label.yaml | 43 -- .../unittest/testdata/failed-test.yaml | 41 -- .../unittest/testdata/long-period.yaml | 30 -- app/vmalert/unittest/testdata/rules.yaml | 39 -- app/vmalert/unittest/testdata/test1.yaml | 99 ---- app/vmalert/unittest/testdata/test2.yaml | 46 -- app/vmalert/unittest/type.go | 83 ---- app/vminsert/common/streamaggr.go | 3 +- docs/CHANGELOG.md | 2 + docs/vmalert.md | 248 ---------- lib/promutils/duration.go | 8 - 29 files changed, 325 insertions(+), 2248 deletions(-) delete mode 100644 app/vmalert/remotewrite/client.go delete mode 100644 app/vmalert/remotewrite/debug_client.go delete mode 100644 app/vmalert/remotewrite/debug_client_test.go rename app/vmalert/remotewrite/{client_test.go => remotewrite_test.go} (100%) delete mode 100644 app/vmalert/unitest_test.go delete mode 100644 app/vmalert/unittest.go delete mode 100644 app/vmalert/unittest/alerting.go delete mode 100644 app/vmalert/unittest/input.go delete mode 100644 app/vmalert/unittest/input_test.go delete mode 100644 app/vmalert/unittest/recording.go delete mode 100644 app/vmalert/unittest/testdata/disable-group-label.yaml delete mode 100644 app/vmalert/unittest/testdata/failed-test.yaml delete mode 100644 app/vmalert/unittest/testdata/long-period.yaml delete mode 100644 app/vmalert/unittest/testdata/rules.yaml delete mode 100644 app/vmalert/unittest/testdata/test1.yaml delete mode 100644 app/vmalert/unittest/testdata/test2.yaml delete mode 100644 app/vmalert/unittest/type.go diff --git a/app/vmalert/Makefile b/app/vmalert/Makefile index 37787e5c1..9f200f0c2 100644 --- a/app/vmalert/Makefile +++ b/app/vmalert/Makefile @@ -74,7 +74,6 @@ test-vmalert: go test -v -race -cover ./app/vmalert/config go test -v -race -cover ./app/vmalert/remotewrite go test -v -race -cover ./app/vmalert/utils - go test -v -race -cover ./app/vmalert/unittest run-vmalert: vmalert ./bin/vmalert -rule=app/vmalert/config/testdata/rules/rules2-good.rules \ @@ -104,10 +103,6 @@ replay-vmalert: vmalert -replay.timeFrom=2021-05-11T07:21:43Z \ -replay.timeTo=2021-05-29T18:40:43Z -unittest-vmalert: vmalert - ./bin/vmalert -unittestFile=app/vmalert/unittest/testdata/test1.yaml \ - -unittestFile=app/vmalert/unittest/testdata/test2.yaml - vmalert-linux-amd64: APP_NAME=vmalert CGO_ENABLED=1 GOOS=linux GOARCH=amd64 $(MAKE) app-local-goos-goarch diff --git a/app/vmalert/README.md b/app/vmalert/README.md index 613a8db62..4015aaa2c 100644 --- a/app/vmalert/README.md +++ b/app/vmalert/README.md @@ -742,249 +742,6 @@ See full description for these flags in `./vmalert -help`. * `limit` group's param has no effect during replay (might be changed in future); * `keep_firing_for` alerting rule param has no effect during replay (might be changed in future). -## Unit Testing for Rules - -> Unit testing is available from v1.92.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 ] - -# 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: - [ - ] -``` - -#### `` - -``` -# Interval between samples for input series -interval: -# Time series to persist into the database according to configured before running tests. -input_series: - [ - ] - -# Name of the test group, optional -[ name: ] - -# Unit tests for alerting rules -alert_rule_test: - [ - ] - -# Unit tests for Metricsql expressions. -metricsql_expr_test: - [ - ] - -# External labels accessible for templating. -external_labels: - [ : ... ] - -``` - -#### `` - -``` -# series in the following format '{