An alert should fire when the application logs `OutOfMemoryError` more than 3 times in 5 minutes. How do you build it?
BeginnerScenarioLogging Pipelines
Answer
Situation read → A log-based alert. With Loki you can use the ruler with LogQL metric queries.
What I'd do →
- Write a LogQL query and test it in Grafana Explore.
- Put it in a Loki ruler rule group that sends to Alertmanager:
groups:
- name: app-logs
rules:
- alert: JavaOOM
expr: sum by (service) (count_over_time({env="prod"} |= "OutOfMemoryError" [5m])) > 3
for: 0m
labels: {severity: page}
annotations: {summary: "{{ $labels.service }} OOM errors in logs"}
- Prefer also exposing a metric (
jvmOOM counter or container restarts withOOMKilled) for long-term trends.
Why → Log alerts catch events with no metric, but metrics are cheaper to evaluate.
Interview tip → If you can turn a log pattern into a metric, do it; log alerts are a bridge.
More on Logging Pipelines
Developers SSH into servers and `grep` log files to debug. You are asked to centralise logging. Where do you start?BeginnerYour app writes free-text logs like `User 42 paid 19.99 in 340ms`. Why push for structured logging, and how?BeginnerLoki ingestion is failing with `stream limit exceeded` and the ingester memory is exploding. What happened?IntermediateFluent Bit pods on busy nodes are dropping logs during traffic spikes. How do you make the pipeline lossless?IntermediateThe Elasticsearch cluster for logs goes red every Monday after the weekend batch jobs. How do you stabilise it?AdvancedFinance says the log bill doubled in a quarter. How do you cut it without losing debugging ability?Intermediate