<p>The important part of the blog post you link to isn't testing the syntax of the YAML file; it's testing the semantics of the Prometheus configuration.</p>

<p>The core configuration in that post includes a fragment:</p>

<pre><code>- alert: MyAlert
  expr: avg without(instance)(up) &lt; 0.75
  for: 2m
  labels:
    severity: page
</code></pre>

<p>How do you know this is the right configuration?  If it's misconfigured then either your on-call team gets paged when the system is healthy, or it doesn't get paged when the system is down; both are bad.</p>

<p>The test setup shown in the blog post would let you test your Prometheus alerting setup, with artificial sample data (the "bar" instance is up for 5 minutes, then down for 5 minutes, and it's expected to page after it's been down for longer than 2 minutes), before you deploy it for real and without actually paging anyone.  That gives you some confidence your monitoring setup will do what you expect, before you deploy it for real.</p>

CC BY-SA 4.0
2020-01-27T10:56:41.260Z
2020-01-27T10:56:41.260Z
David Maze
<p>I read a very short blog posting about <a href="https://www.robustperception.io/unit-testing-alerts-with-prometheus" rel="nofollow noreferrer">Unit testing alerts with Prometheus</a></p>

<p>Can you explain me why I need unit testing for *.yml? What is the benefit of unit testing for configuration files?</p>

<p>I not understand what are the gains when implementing that.</p>

<configuration><prometheus><unit-testing>
What is Unit testing in the context of YML configuration Alerting rules?
Sybil
# What is Unit testing in the context of YML configuration Alerting rules?

(Asked by: username_0 on 2020-01-27)

I read a very short blog posting about [Unit testing alerts with Prometheus](https://www.robustperception.io/unit-testing-alerts-with-prometheus)

Can you explain me why I need unit testing for \*.yml? What is the benefit of unit testing for configuration files?

I not understand what are the gains when implementing that.

**Tags:** configuration, prometheus, unit-testing


---

## 1 answers

### Answer by username_1 on 2020-01-27. Score: 3 | Accepted answer

The important part of the blog post you link to isn't testing the syntax of the YAML file; it's testing the semantics of the Prometheus configuration.
The core configuration in that post includes a fragment:
- alert: MyAlert
  expr: avg without(instance)(up) < 0.75
  for: 2m
  labels:
    severity: page

How do you know this is the right configuration?  If it's misconfigured then either your on-call team gets paged when the system is healthy, or it doesn't get paged when the system is down; both are bad.
The test setup shown in the blog post would let you test your Prometheus alerting setup, with artificial sample data (the "bar" instance is up for 5 minutes, then down for 5 minutes, and it's expected to page after it's been down for longer than 2 minutes), before you deploy it for real and without actually paging anyone.  That gives you some confidence your monitoring setup will do what you expect, before you deploy it for real.


---

