Lesson 9 of 9 · 26m
Alerting from Logs Without Creating Noise
When log-based alerting is appropriate, how to write rate and absence alerts, and the anti-patterns that make teams ignore their pager.
Logs are seductive alerting material because the exact error string is right there. That is also the trap. Error strings are unstable, volume is spiky, and one dependency failure can generate forty variations of the same pain. Alerts belong on user impact first; log alerts are the scalpel you use when metrics cannot express the condition.
Prefer rate and ratio over raw count
Bad: more than 10 errors in 5 minutes. Ten errors is nothing on a large service and catastrophic on a low-traffic internal tool.
Better: error_count / request_count > 0.02 for 10m and request_count > baseline_floor. The floor matters because two requests with one failure is a 50% error ratio, not a customer-facing outage.
Elastic rule sketch
Elastic alerting rules can run Elasticsearch queries or aggregations. Conceptually:
filter: service.name: checkout and log.level: error
window: 10m
group by: service.name, error.kind
threshold: count > 50
actions: page only for error.kind in known severe classesThe grouping is important. If one hundred pods all emit the same failure, you want one incident, not one hundred pages.
Loki alerting sketch
groups:
- name: checkout-logs
rules:
- alert: CheckoutPaymentFailureBurst
expr: |
sum by (service) (
count_over_time({service="checkout", environment="prod"} |= "payment capture failed" [5m])
) > 25
for: 10m
labels:
severity: page
annotations:
summary: "Burst of payment capture failures in checkout"Use for so a transient retry burst does not page. Use recording rules or metrics derived from logs when the same expensive query is needed repeatedly.
Absence alerts are powerful and dangerous
"No heartbeat events for five minutes" detects stuck workers better than waiting for errors. But absence alerts fire during deploys, network partitions, and logging outages. Scope them narrowly and include deployment suppression or maintenance windows.
A good absence rule answers:
did this specific worker stop producing its expected heartbeat,
while neighboring workers still are?Field notes
- Every log alert needs a runbook link. If nobody knows what to do, it is not an alert.
- Include sample log lines in the notification, but redact sensitive fields.
- Dedup and grouping matter more than perfect thresholds.
- Replays, batch backfills, and integration tests can all trigger log alerts. Label synthetic traffic and exclude it.
- If a log alert is important long-term, consider turning the condition into a metric. Metrics are cheaper to evaluate continuously.
Was this lesson helpful?