From 420c0f5e4618956a4eb89d237bb6c01ac5fa778c Mon Sep 17 00:00:00 2001 From: Ganesh Vernekar Date: Wed, 3 Oct 2018 17:15:09 +0530 Subject: [PATCH] Fix docs (#4690) Signed-off-by: Ganesh Vernekar --- docs/configuration/unit_testing_rules.md | 110 ++++++++++++----------- 1 file changed, 56 insertions(+), 54 deletions(-) diff --git a/docs/configuration/unit_testing_rules.md b/docs/configuration/unit_testing_rules.md index c1b2ac5cb5..f767d85891 100644 --- a/docs/configuration/unit_testing_rules.md +++ b/docs/configuration/unit_testing_rules.md @@ -133,35 +133,9 @@ value: ## Example -This is an example input files for unit testing which passes the test. `alerts.yml` contains the alerting rule, `tests.yml` is the test file which follows the syntax above. +This is an example input file for unit testing which passes the test. `test.yml` is the test file which follows the syntax above and `alerts.yml` contains the alerting rules. -### `alerts.yml` - -```yaml -# This is the rules file. - -groups: -- name: example - rules: - - - alert: InstanceDown - expr: up == 0 - for: 5m - labels: - severity: page - annotations: - summary: "Instance {{ $labels.instance }} down" - description: "{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 5 minutes." - - - alert: AnotherInstanceDown - expr: up == 0 - for: 10m - labels: - severity: page - annotations: - summary: "Instance {{ $labels.instance }} down" - description: "{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 5 minutes." -``` +With `alerts.yml` in the same directory, run `./promtool test rules test.yml`. ### `test.yml` @@ -188,30 +162,58 @@ tests: - series: 'go_goroutines{job="node_exporter", instance="localhost:9100"}' values: '10+10x7 10+30x4' # 10 20 30 40 50 60 70 80 10 40 70 100 130 - # Unit test for alerting rules. - alert_rule_test: - # Unit test 1. - - eval_time: 10m - alertname: InstanceDown - exp_alerts: - # Alert 1. - - exp_labels: - severity: page - instance: localhost:9090 - job: prometheus - exp_annotations: - summary: "Instance localhost:9090 down" - description: "localhost:9090 of job prometheus has been down for more than 5 minutes." - # Unit tests for promql expressions. - promql_expr_test: - # Unit test 1. - - expr: go_goroutines > 5 - eval_time: 4m - exp_samples: - # Sample 1. - - labels: 'go_goroutines{job="prometheus",instance="localhost:9090"}' - value: 50 - # Sample 2. - - labels: 'go_goroutines{job="node_exporter",instance="localhost:9100"}' - value: 50 + # Unit test for alerting rules. + alert_rule_test: + # Unit test 1. + - eval_time: 10m + alertname: InstanceDown + exp_alerts: + # Alert 1. + - exp_labels: + severity: page + instance: localhost:9090 + job: prometheus + exp_annotations: + summary: "Instance localhost:9090 down" + description: "localhost:9090 of job prometheus has been down for more than 5 minutes." + # Unit tests for promql expressions. + promql_expr_test: + # Unit test 1. + - expr: go_goroutines > 5 + eval_time: 4m + exp_samples: + # Sample 1. + - labels: 'go_goroutines{job="prometheus",instance="localhost:9090"}' + value: 50 + # Sample 2. + - labels: 'go_goroutines{job="node_exporter",instance="localhost:9100"}' + value: 50 +``` + +### `alerts.yml` + +```yaml +# This is the rules file. + +groups: +- name: example + rules: + + - alert: InstanceDown + expr: up == 0 + for: 5m + labels: + severity: page + annotations: + summary: "Instance {{ $labels.instance }} down" + description: "{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 5 minutes." + + - alert: AnotherInstanceDown + expr: up == 0 + for: 10m + labels: + severity: page + annotations: + summary: "Instance {{ $labels.instance }} down" + description: "{{ $labels.instance }} of job {{ $labels.job }} has been down for more than 5 minutes." ```