Skip to Content

How do I test alerts from Prometheus about slow database queries before a real incident?

Tares lets you test slow database query alerts by making Prometheus fire one on purpose, then checking the event and its labels on the source page. The prometheus_alerts source polls Prometheus every 30 seconds by default. Each active alert becomes an event, and a resolved event follows when it clears. To test with a hand-written payload instead, post it to the ingest URL of an Alertmanager source.

How it works

The Prometheus alerts connector polls /api/v1/alerts on your Prometheus server. Prometheus decides what counts as an alert, and Tares records it.

  • Each active alert becomes one event. The event_type is the alert name, the text is its summary, and its labels become Tares labels.
  • Tares adds a synthetic state label with the value firing, pending or resolved.
  • State is tracked across polls. An alert fires once and re-emits only when its state changes. When it disappears, Tares emits a resolved event.
  • Discover proposes only the labels that are always present, severity and state. Labels such as namespace and service exist only while an alert is firing, so you add them from the Fields tab after real alerts have been ingested.

Because the connector polls, it has no ingest URL of its own. To test with a payload you write yourself, use a push source, either an Alertmanager source or a webhook source. A source that polls and a source that receives pushes are checked in the same place, Recent events and Fields on the source page.

Set it up

  1. Create the source. In the console go to Sources → Add source → Prometheus alerts, enter the Prometheus url (plus any auth) and click Discover. It lists your alerting rules and the severities present. You can also ask a connected agent: “Use tares to ingest the firing alerts from the Prometheus at localhost:9090.” Or use the same object with POST /api/sources:

    - name: alerts connector: prometheus_alerts poll: 30s config: url: http://localhost:9090 severities: critical,warning # blank = all labels: - { name: severity, field: labels.severity, primary: true } - { name: state, field: state }
  2. Make a slow query alert fire on purpose. Use a rule you control in Prometheus for your slow database query condition, and set its threshold low enough that it trips now. If you want to see alerts still waiting out their for: duration, turn on include pending in the source.

  3. Wait one poll interval, 30 seconds by default, and open the source. Recent events shows one event per active alert. Check that the event type is the alert name, the text is the summary you expect, and the state label reads firing.

  4. Open Fields. It lists the labels your alert carries. Promote the ones you want to correlate on, such as namespace or service, to labels on the source.

  5. Clear the condition, or remove the test rule. A resolved event appears on the timeline when the alert disappears from Prometheus.

  6. To test a hand-written payload, create an Alertmanager source and post a sample batch to its ingest URL. Change the alert name and annotations in your own copy to describe a slow query:

    curl -X POST http://localhost:8787/ingest/<ingest_key> \ -H 'Content-Type: application/json' \ -d '{"alerts":[{"status":"firing","labels":{"alertname":"PostgresDown","severity":"critical","namespace":"prod"},"annotations":{"summary":"Postgres is down"},"startsAt":"2024-01-01T00:00:00Z"}]}'

    Then read Recent events and Fields on that source. Do not rely on test_source for this. On a push source it takes no payload and only returns the ingest endpoint, so it does not check the label mapping. On a secured instance (tares up --auth), the Alertmanager receiver also needs an ingest-scoped API key. For a generic JSON sender, the same post-and-read check works on a webhook source.

What you get

  • You see exactly how a slow query alert looks in Tares before an incident: its event type, text, state and labels.
  • You choose real labels from the Fields tab, so the alert is keyed the way you want.
  • You see the firing event and the resolved event, so you know both ends of the alert lifecycle work.
  • With a sample batch on an Alertmanager source, you can repeat the check without touching your Prometheus rules.

When something else fits

  • If you want Alertmanager’s grouping, silencing and resolved handling with real-time delivery, use the Alertmanager source instead of polling Prometheus.
  • If the sender is not Prometheus or Alertmanager, a webhook source takes any JSON you post.
  • For the wider picture of watching and escalating, see AI SRE.

Still stuck? Get help

Last updated on