You can find the specification for this compliance here.
Clone the repo
$ git clone https://github.com/prometheus/compliance.git
$ cd compliance/alert_generator
Check that the rules file is up-to-date with
$ make check-rules
go run ./cmd/rule_config_builder/main.go -rules-file-path="./rules.yaml"
level=info ts=2022-02-24T14:14:19.596Z caller=main.go:53 msg="Rules file successfully generated" path=/home/ganesh/go/src/github.com/prometheus/compliance/alert_generator/rules.yaml
$ echo $?
0
Run make rules
otherwise to generate fresh rules file.
Feed the rules.yaml
file present in the directory into the software that you are testing with any additional tweaks required.
It is suggested to wait until one evaluation of all rule groups is done before starting the test.
Check test-example.yaml for the example config to setup the test suite. That file has all the documentation on how to configure the test suite.
Feel free to modify the example config itself. Config for some softwares are provided as an example, more will be added.
If you are running your software in a local environment, you can set the alertmanager URL to http://<host>:<port>
with port being the one set in the test suite config. For example http://localhost:8080
.
If you are testing a cloud offering, or if the local software setup cannot access the test suite's network, there are two alternatives:
You can run ./cmd/alert_generator_compliance_tester
in docker and run it inside your infrastructure as a batch job. To do so, build the image with make docker
and instead of step 6, simply run alert_generator_compliance_tester:latest
with -config-file=<config file you have done in step 3>
.
See example here
- Open https://webhook.site/. It will give a unique link to use as a webhook. Let's take https://webhook.site/12345 as an example.
- Set https://webhook.site/12345 to be the alertmanager URL in your software - hence all alerts will be set to this webhook.
- On the webhook.site page, enable
XHR Redirect
on top, and in its settings, set theTarget
tohttp://<host>:<port>
from the above, for examplehttp://localhost:8080
.
Note:
- The webhook.site page must be open at all times. It redirects the request locally, hence able to redirect to local network.
- In the test logs you might see "error in unmarshaling" error immediately followed by "alerts received" log. You can ignore the error log. It is something to do with how webhook.site redirects.
- Disable any kind of browser blockers for webhook.site if you are not getting alerts redirected to the test suite.
If your software send alerts in a format that is not parsable by any of the provided parsers in alert_message_parsers.go, you can extend that file to include your custom parser and mention that name in the config file.
Now that everything is set up, you can run the test as follows
$ make run CONFIG=./test-example.yaml
A successful test run will exit with Congrats! All tests passed
message. An unsuccessful run will end with a description of what went wrong.
The test takes roughly 40 mins to run. But if all rule groups face any errors, the test will exit immediately.
- Get the rules file from step 2 above and put it in the Prometheus config.
- Set the alertmanager URL to
localhost:8080
. - Run Prometheus with
--web.enable-remote-write-receiver
flag to accept remote write. - Run the test with
make run CONFIG=./test-prometheus.yaml