Week 13

Observability introduction

Logging in Spring Boot

Structured Logging

Shipping Logs to the Cloud

Debugging with Logs

Health & Metrics

Appendix: Alerting (optional)

Practice

Assignment

Backend Track

When the dashboard watches you back

<aside> ๐Ÿ’ญ

This chapter is optional. Do it after the assignment if you have time and curiosity โ€” it is not required for submission, but it is a satisfying capstone: your system will email you when it is in trouble.

</aside>

Your dashboard from Health & Metrics has one flaw: it only helps while someone is looking at it. Nobody stares at dashboards on a Saturday. An alert flips the direction โ€” instead of you checking the system, the system contacts you when a condition you defined becomes true. This is the mechanism behind every on-call rotation you will ever join.

Build one alert

You already know how to measure trouble โ€” in the dashboard you counted log lines by level. An alert is the same idea, narrowed to one number. Grafana's UI evolves, but creating an alert always comes down to the same four decisions:

  1. The query โ€” what to measure. In Alerting โ†’ Alert rules โ†’ New alert rule, build a Loki query the same way you did for the dashboard: filter app = my-app, add level = ERROR, then Operations โ†’ Aggregations โ†’ Count. That gives a single number: how many errors in the window.
  2. The condition โ€” when is it bad? Threshold: the value is above 0. Any error at all fires the alert โ€” crude, but honest for a service that should have none.
  3. The patience โ€” how long must it stay bad? Grafana asks for a pending period (e.g. 2 minutes) so a single blip does not page anyone at 03:00. Set the rule to evaluate every minute.
  4. The destination โ€” who gets told, and how? Under Contact points, add your email address. On the free tier, email works out of the box.

Test it like you mean it

An alert you have never seen fire is a hope, not a safety net. Trigger it deliberately. First, add a temporary endpoint to your project:

@GetMapping("/api/test-alert")
public String testAlert() {
    log.error("Test alert: this is a drill");
    return "Error logged";
}

Then:

  1. Deploy, hit it a few times, and wait out your pending period.
  2. Watch the alert move through its states in Grafana โ€” Normal โ†’ Pending โ†’ Firing โ€” and check your inbox.
  3. Stop hitting the endpoint; watch the alert resolve. Then delete the endpoint โ€” drills should not outlive the drill.

<aside> ๐ŸŽ‰

An email from your own production system, telling you it is unwell, seconds after it happened โ€” before any user complained. That is the whole point of this week, closing the loop on its own.

</aside>

A warning about crying wolf

The rookie mistake with alerts is making too many. An inbox full of alerts that "are probably fine" trains you to ignore them โ€” the industry calls this alert fatigue, and it is how real outages get missed. The professional rule: every alert must be actionable. If the honest response to an alert is "do nothing", the alert should not exist โ€” that information belongs on a dashboard, not in your inbox. One good alert (errors are happening) beats ten noisy ones.

Extra resources


The HackYourFuture curriculum is licensed underย CC BY-NC-SA 4.0 *https://hackyourfuture.net/*

CC BY-NC-SA 4.0 Icons

Built with โค๏ธ by the HackYourFuture community ยท Thank you, contributors

Found a mistake or have a suggestion? Let us know in the feedback form.