Monitoring Alerts That Don't Suck
Tags: monitoring, practices, alerts, oncall
Published: 2021-07-02 07:27:52

---
title: Monitoring Alerts That Don't Suck
published: true
date: 2021-07-02 00:00:00 UTC
tags: Monitoring,Practices,Alerts,OnCall
canonical_url: https://hceris.com/monitoring-alerts-that-dont-suck/
cover_image: https://hceris.com/static/a41e9cd0b8e834da1989e7ec7b9e4791/acb04/cover.jpg
---

Have you ever been part of an [On-Call](https://www.pagerduty.com/resources/learn/call-rotations-schedules/) rotation?

If so, you know how annoying it is to have monitoring alerts that you can’t trust. If they don’t trigger, you’ll live in fear of missing an incident. If they trigger too much, they won’t let you sleep. Neither case sounds great.

Over the past year and a half, I’ve been part of projects that practice On-Call. You’d be surprised how easily people get used to situations that are so clearly dysfunctional. In this post, I want to talk about how I’ve tried to improve the quality of our alerts.

## What Is the Goal of Alerting?

Simply put, to detect problems in your application before your customers do. Highly available systems can’t afford to wait for a human operator to check if everything looks good. That’s too slow in case of an incident. You want the responsible people to know that something is wrong immediately.

Converting monitoring systems into alerts is a natural transition. In fact, platforms like [DataDog](https://www.datadoghq.com/) or [Splunk](https://www.splunk.com/) include these capabilities as part of their offerings.

Let’s say you read one of the [SRE books](https://sre.google/books/), and you’re now all about SLAs, error budgets, and all the good stuff. How to distill an alert to its base essence? An alert **has** to fulfill two conditions:

- It triggers when there’s a problem (avoids false negatives)
- Non-issues don’t cause it to trigger (avoids false positives)

When you put it like that, it kind of sounds trivial. Well, you wouldn’t believe how often one of the conditions doesn’t hold, though. Or both. Let’s explore how you end up in this situation.

## The Slow Descent Into Unreliability

As Tolstoy [said](https://en.wikipedia.org/wiki/Anna_Karenina_principle), each unhappy alerting setup is unreliable in its own way. I bet every developer has a story about an error that _just_ wouldn’t go away.

[![Ruins](https://hceris.com/static/f06baa975d50ea549df948d01f8fd425/acb04/ruins.jpg "Ruins")](/static/f06baa975d50ea549df948d01f8fd425/eea4a/ruins.jpg)<figcaption>
  A bit of tech debt
  </figcaption>

There are many causes of untrustworthy alerts: Unstable infrastructure, spikes in traffic, legacy applications that time out randomly. Every failure has an origin buried deeply somewhere.

In my experience, it’s not like you get to this point suddenly. Rather, it’s a slow decay. You don’t calibrate the conditions properly, which leads to occasional activation. It progressively gets worse over time while people get used to it. At some point, it’s as if things were _always_ like that. If there’s one thing to take from this article: Don’t let this happen.

One way or another, we need to consider the possibility of flakiness when designing alerts for our systems.

## Monitoring a Microservice

A comprehensive monitoring setup is a topic for a book, not a blog post. Let’s say we’re starting small. I want to monitor a single microservice. Keep in mind that these are technical metrics. We’re not measuring business outcomes (yet), as we seek to have a solid base before that. With that in mind, I’m borrowing the [RED method](https://www.weave.works/blog/the-red-method-key-metrics-for-microservices-architecture/). These are the metrics we want to monitor.

- _Rate_: Number of requests
- _Error Rate_: % of failed requests
- _Duration_: Time to fulfill a request. You see it as _latency_ as well.

That’s about it. These three metrics provide a meaningful view into the state of this hypothetical microservice. There are plenty of alert combinations to cover them, though.

### A Reasonable Set of Alerts for Reasonable People

I won’t claim that this works in every situation. Still, I’ve had success lately using alert pairs instead of a single alert.

- _Flatline Alert_: Catch extreme conditions through an absolute threshold, like a service receiving no traffic.
- _Change% Alert_: Catch rapid changes in a metric, like the error rate spiking.

[![Alert](https://hceris.com/static/3a914bafce322c65c55b3177c674253b/1d69c/alert.png "Alert")](/static/3a914bafce322c65c55b3177c674253b/c1b63/alert.png)

For each of the RED metrics, you deploy a pair of alerts. For instance, to cover the rate, you have a flatline for zero or close-to-zero requests and a change alert if traffic drops something like 50% within 15 minutes (tune numbers based on situation).

There’s quite a bit of overlap between all these alerts, but at the same time, they provide [defense in depth](https://en.wikipedia.org/wiki/Defense_in_depth_(computing)). Any decent incident management system can handle grouping, anyway. The sum of a threshold and a change percentage means that you don’t have to be too precise in tuning these values.

I like to keep the priorities simple and use one or two different priorities at most. It’s tempting to be overly granular, but that can backfire by introducing extra cognitive load.

## Some Ideas to Keep in Mind

There’s a lot to say about how to set the alerts and tune them. It’s also something that’s is dependent on your tools, and how you set up your systems. I’m going to pivot away from these details and talk about good practices and anti-patterns. I believe these are broadly applicable in different contexts.

### Fight Alert Fatigue

[![Fatigue](https://hceris.com/static/9397844f0444d9983f3490d9382ee17f/acb04/fatigue.jpg "Fatigue")](/static/9397844f0444d9983f3490d9382ee17f/eea4a/fatigue.jpg)<figcaption>
  Too many alarms in one night
  </figcaption>

Alerts should trigger for conditions that require immediate attention and for that only. I can’t stress this enough. [Alarm fatigue](https://en.wikipedia.org/wiki/Alarm_fatigue) slowly creeps in, and before you know it, you’ve internalized that people get paged twenty times a day, and it was never any different.

Be decisive. If an alert is noisy, change it or delete it. Don’t get used to the situation.

### Start Simple

Yes, the latest talk from somebody at [FAANG](https://en.wikipedia.org/wiki/Big_Tech) mentions an intricate setup. I can promise you there was a ton of iteration to get there. Don’t get Big Tech envy. Start simple. It’s never too late to introduce extra complexity.

### Multiple Angles

I see people making the mistake of trying to find the perfect alert that exactly covers their service. One such alert will be hard to tune if that’s possible at all. Instead, a combination of alerts does the job as well, and it’s simpler to maintain. Let your tools handle the grouping.

### Have A Playbook

An alert is just the first step. You need to give whoever picks it an actionable playbook. Don’t make assumptions about their knowledge. Somebody reacting to an alert might not have enough information to handle it. Make their life easier and they’ll thank you.

### Seek the Right Metrics

Raw numbers aren’t descriptive on their own. An error rate (errors / requests) says more than a count of errors. Similarly, a [percentile](https://www.elastic.co/blog/averages-can-dangerous-use-percentile) says more about your users’ experience than an average.

### Test your Alerts

Testing alerts isn’t always practical. Much like when you do [TDD](https://martinfowler.com/bliki/TestDrivenDevelopment.html), you want to prove that they actually do something. It’s awkward to realize that a pristine alert won’t ever activate.

## Avoid Doing This

Surely there’s some situation where you can argue that the following practices make sense. Maybe? I think it’s a good idea to stay away from them.

### Absolute Thresholds

Absolute thresholds are risky. They’re hard to get right, especially if your traffic is spiky or unpredictable. If you somehow manage to get a value that works _now_, that doesn’t mean it’ll work in the future.

I’d leave absolute thresholds for unequivocal triggers. It’s hard to argue that a service getting no requests whatsoever is healthy (unless it’s deactivated?).

### Creating Alerts Manually

Creating and tuning alerts manually doesn’t scale. The more alerts you create, the more visible it becomes. Using [Infrastructure as Code](https://www.hashicorp.com/resources/what-is-infrastructure-as-code) is a much sustainable approach. [Terraform](https://www.terraform.io/) has providers for most of the monitoring players.

### Alerts for Services with Low Traffic

Services that don’t have a lot of traffic are not suited for classical alerts. For instance, using a p50 latency in a service that gets 30 requests per hour is per definition flaky. One or two slow calls are enough to skew the metric so that it triggers an alert. By creating such alerts, you’re expecting your downstream dependencies to have a consistency that they might be unable to offer.

My recommendation is to stick to flatline alerts for these types of services. Alternatively, filter the metrics to include events that you can trust.

## Keep Your Sanity

[![This is fine](https://hceris.com/static/da5390a00ed3da32a6e36dc797ca9bb9/f93b5/thisisfine.jpg "This is fine")](/static/da5390a00ed3da32a6e36dc797ca9bb9/f93b5/thisisfine.jpg)<figcaption>
  Alerts are music to my ears
  </figcaption>

I firmly believe that it’s better to have a more modest setup that your engineers fully trust than a complex one that drives them nuts.

Alerts **aren’t** stationary but rather evolve constantly. If you have a solid foundation you can refine triggers quickly. If you have a dumpster fire it’s hard enough for the whole thing not to collapse.