--- sort: 12 weight: 12 menu: docs: parent: 'victoriametrics' weight: 12 title: vmalert-tool aliases: - /vmalert-tool.html --- # vmalert-tool VMAlert command-line tool ## Unit testing for rules You can use `vmalert-tool` to run unit tests for alerting and recording rules. It will perform 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 like [vmalert](https://docs.victoriametrics.com/vmalert/); * checks whether the firing alerts or resulting recording rules match the expected results. See how to run vmalert-tool for unit test below: ``` # Run vmalert-tool with one or multiple test files via `--files` cmd-line flag # Supports file path with hierarchical patterns and regexpes, and http url. ./vmalert-tool unittest --files /path/to/file --files http:///path/to/test.yaml ``` vmalert-tool unittest 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-tool validates and executes [MetricsQL](https://docs.victoriametrics.com/metricsql/) expressions, which aren't always backward compatible with [PromQL](https://prometheus.io/docs/prometheus/latest/querying/basics/). ### Limitations * vmalert-tool evaluates all the groups defined in `rule_files` using `evaluation_interval`(default `1m`) instead of `interval` under each rule group. * vmalert-tool shares the same limitation with [vmalert](https://docs.victoriametrics.com/vmalert/#limitations) on chaining rules under one group: >by default, rules execution is sequential within one group, but persistence of execution results to remote storage is asynchronous. Hence, user shouldn’t rely on chaining of recording rules when result of previous recording rule is reused in the next one; For example, you have recording rule A and alerting rule B in the same group, and rule B's expression is based on A's results. Rule B won't get the latest data of A, since data didn't persist to remote storage yet. The workaround is to divide them in two groups and put groupA in front of groupB (or use `group_eval_order` to define the evaluation order). In this way, vmalert-tool makes sure that the results of groupA must be written to storage before evaluating groupB: ```yaml groups: - name: groupA rules: - record: A expr: sum(xxx) - name: groupB rules: - alert: B expr: A >= 0.75 for: 1m ``` ### Test file format The configuration format for files specified in `--files` cmd-line flag is the following: ```yaml # Path to the files or http url containing [rule groups](https://docs.victoriametrics.com/vmalert/#groups) configuration. # Enterprise version of vmalert-tool 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: [ - ] ``` #### `` ```yaml # 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: [ : ... ] ``` #### `` ```yaml # series in the following format '{