How do I test alerts from Prometheus about 5xx errors on an API before a real incident?
Tares lets you test 5xx alerts before a real incident by sending a sample alert batch to a source’s ingest URL and checking the label mapping and the event. Give the sample alert a service label such as api-server and set key_label to service on the source, so the event lands on the API’s own entity. The polled prometheus_alerts source has no ingest URL, so the test goes through an Alertmanager source that uses the same label values.
How it works
- The Prometheus alerts connector polls Prometheus and records alerts that its rules have already fired. It has no ingest URL, so you cannot post a sample to it.
- The Alertmanager connector is a push receiver. Every alert in a batch you POST to its ingest URL becomes one event. The
event_typeis the alert name, thetextis the summary, and the alert labels become Tares labels plus a syntheticstatusoffiringorresolved. - Tares keys each event on a label. By default it tries
namespace, thenservice, thenjob, theninstance. A test alert that carriesnamespacewould key onnamespaceand miss the API’s service. Settingkey_labeltoserviceon the source keys it onserviceinstead. - The same value has to appear on every source that describes the API. If the sample alert says
api-server, your Prometheus alerts source and any log source for the API useapi-servertoo, so Tares correlates them on one entity. - You can also check the label mapping with
test_sourceand a sample payload. The webhook connector page describes this check, and you can run it through a connected agent.
Set it up
- Create a test source. Ask a connected agent: “Use tares to create an Alertmanager source and give me the webhook URL.” Or open Sources → Add source → Alertmanager alerts, name it and Create.
- Set the key label to
service, either in the advancedkey_labelfield or in the source config:
- name: api-alerts
connector: alertmanager
config:
key_label: service- Send a sample 5xx alert to the ingest URL. The
servicelabel carries the value your other sources use for the API. On a secured instance, send an ingest-scoped API key with the request.
curl -X POST http://localhost:8787/ingest/<ingest_key> \
-H 'Content-Type: application/json' \
-d '{"alerts":[{"status":"firing","labels":{"alertname":"ApiHigh5xxRate","severity":"critical","namespace":"prod","service":"api-server"},"annotations":{"summary":"API 5xx error rate is high"},"startsAt":"2024-01-01T00:00:00Z"}]}'- Open the source and check Recent events. You see one event named ApiHigh5xxRate with the summary as its text and
statusset tofiring. Open Fields to confirm the labelsservice,severityandnamespacearrived. Confirm the event sits under theapi-serverentity, not underprod. - Send the same body with
"status":"resolved"to check that the resolved event shows up too. - Make the polled source use the same value. Add a
servicelabel fromlabels.serviceon your Prometheus alerts source:
- name: alerts
connector: prometheus_alerts
poll: 30s
config:
url: http://localhost:9090
severities: critical,warning # blank = all
labels:
- { name: service, field: labels.service, primary: true }
- { name: state, field: state }An alert’s dynamic labels only exist while it is firing. If service is not offered yet, add it from the Fields tab once real alerts have been ingested.
7. When the mapping looks right, point your real receiver at the same ingest URL and reload Alertmanager:
receivers:
- name: tares
webhook_configs:
- url: http://localhost:8787/ingest/<ingest_key>
send_resolved: true
route:
receiver: taresWhat you get
- You see how a 5xx alert maps to Tares labels before anything breaks:
event_type,text,statusand the labels you care about. - The test event lands on the
api-serverentity, so you know a real alert will sit beside your other sources for that API. - You confirm that firing and resolved events both arrive.
- You learn which fields exist from the Fields tab and can promote
serviceornamespaceto correlate on. - Once your real alerts are flowing, the setup is part of your wider AI SRE workflow.
When something else fits
- If you want real alerts through Alertmanager’s grouping, silencing and resolved handling with real-time delivery, use the Alertmanager source for production too, not only for the test.
- If you want Tares to read Prometheus directly with no Alertmanager, keep the prometheus_alerts source and check it under Recent events once Prometheus fires an alert.
- If your alert sender is not Alertmanager, a webhook source takes any JSON, and
test_sourcewith a sample payload checks its label mapping first.
Related
Last updated on