How do I wake an AI SRE once when alerts from Prometheus report slow database queries?
Tares wakes your AI SRE from a trigger on the prometheus_alerts source, and a per-entity cooldown sets the minimum gap between firings for the same service. The source emits each alert once and a resolved event when it clears, not a copy on every poll. You define the trigger in YAML and subscribe your agent to it.
How it works
Tares polls Prometheus’s own alerts endpoint, so Prometheus decides what counts as an alert and Tares correlates it. This is how the pieces fit together:
- The source emits one event per alert. State is tracked across polls, so an alert is re-emitted only on a state change. Each event has
event_typeset to the alert name,textset to its summary, its labels, and astateoffiring,pendingorresolved. - Resolved events are recorded. When an alert disappears, the source emits a
resolvedevent. It appears under Recent events on the source next to the firing events, so the timeline shows when the slow queries started and when they cleared. - The trigger evaluates per entity. With
group_by: [key_value], each service is evaluated on its own, andkey_fieldnames the label that identifies the service. - The cooldown spaces out firings.
cooldownis the minimum gap between firings for the same entity. It stops a flapping condition from firing repeatedly for one service. - The agent gets the timeline. When the trigger fires, Tares POSTs the entity’s correlated timeline over the
context_windowto each subscriber, so the agent starts with context. This is the same flow your AI SRE setup uses for any symptom.
Set it up
- Add a
prometheus_alertssource. Discover proposes only the labels that are always present,severityandstate, so addservicefrom the Fields tab after real alerts have arrived (see the Prometheus alerts connector page). The sample below declaresservicewith the fieldlabels.serviceand marks it primary, withseverityas a plain label.
- 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: severity, field: labels.severity }
- { name: state, field: state }- Define the trigger from the triggers guide. Replace the alert name with the name of your slow-query rule, since the alert name becomes the
event_type.
triggers:
- name: slow_db_queries
sources: [alerts]
key_field: service
filters:
- { field: event_type, op: eq, value: PostgresSlowQueries }
- { field: state, op: eq, value: firing }
condition:
aggregate: count
predicate: "> 0"
window: 5m
group_by: [key_value]
emit:
kind: slow_db_queries
context_window: 15m
cooldown: 30m- Pick a
cooldownthat matches how long you want to hold off further firings for the same service. The30mabove is a starting value. - Wake an agent. A Tares agent is woken when a project wires it to the trigger and you turn it on there. An external agent registers a webhook over MCP:
Use tares to subscribe to the
slow_db_queriestrigger and deliver tohttps://my-agent.example.com/hook.
- Make your endpoint acknowledge with a 2xx. Delivery is at-least-once, so dedupe on
dispatch_id. 5xx responses and transport errors are retried with backoff. - Check the result. Open the source to see firing and
resolvedevents under Recent events, and open the trigger’s page to see each firing and its delivery status.
What you get
- A trigger that evaluates each service separately, so slow queries on one database do not mix with another service’s alerts.
- A cooldown that keeps a flapping alert from firing repeatedly for the same service within the gap you set.
- A correlated timeline in each dispatch, covering the 15 minutes around the firing, so the agent can start investigating without a follow-up call.
- A source timeline that shows resolved events, so you can see when an alert cleared.
- A logged record of every firing, with per-subscriber delivery status, on the trigger’s page and in the console under Firings.
When something else fits
- If you want Tares to look at the alerts on a clock instead of on a condition, give the trigger a schedule such as
condition: {every: 10m}. It fires once per interval and hands over a summary of the window, as described in the triggers guide. - If your alerts reach you through Alertmanager rather than a Prometheus server Tares can poll, use the
alertmanagerconnector, which receives them at an ingest URL.
Related
Last updated on