Which logs from Docker containers does an AI SRE search when Alertmanager alert groups fire?
Tares gives an AI SRE the Docker logs of the container you connect, on the same service timeline as your Alertmanager alerts, when both carry the same service label. When an alert group fires, the agent reads that one correlated timeline for the service instead of querying each system separately. The match is made by the service value, so you set it on the alerts and on the logs.
How it works
- Alertmanager POSTs a batch of alerts to the ingest URL of your Tares alertmanager source. Tares fans the batch out into one event per alert. The event type is the alert name, the text is its summary, and the alert labels become Tares labels plus a synthetic
statusoffiringorresolved. - The alertmanager source keys each alert on the first label it finds in this order:
namespace,service,job,instance. An alert that carriesnamespacelands on the namespace, not on the service. Settingkey_label: serviceon the source makes it key on theservicelabel instead. - The docker_logs source tails one running container, one event per line. It reads through the Docker daemon, so run
taresdon the host. Optionalmatchanddropregex filters keep or skip lines, for exampleERROR|WARNto keep, orHTTP/1.1"to drop access logs. - You give the container’s logs a constant
servicelabel, for exampleapi-server. When the service value on the alerts and the service value on the logs are the same, both land on one timeline for that service. - An agent reads that timeline for the service. In the Build an AI SRE guide, a trigger fires on an alert event, the agent wakes, and it reads the correlated timeline of metrics, logs and alerts for that service. A connected client does the same on demand: asking what happened to api-server in the last 15 minutes makes it call
readwith the serviceapi-server.
The Alertmanager connector page covers the receiver, and the Docker logs connector page covers the tail.
Set it up
- Create an Alertmanager source. In the console go to Sources, then Add source, then Alertmanager alerts, name it and create it. Or ask a connected agent to create an Alertmanager source and give you the webhook URL. Set
key_labeltoserviceso alerts key on the service and not on the namespace:
- name: alerts
connector: alertmanager
config:
key_label: service- Add the receiver to your
alertmanager.ymlwith the ingest URL from the source page, then reload Alertmanager:
receivers:
- name: tares
webhook_configs:
- url: http://localhost:8787/ingest/<ingest_key>
send_resolved: true
route:
receiver: taresThe sender uses a Bearer Authorization header holding an ingest-scoped API key, needed only when Tares has auth on.
- Make sure your alert rules put a
servicelabel on each alert, with the same value you give the logs in the next step. Send a test alert that carriesservice: api-server, alongsidenamespace: prodif you like:
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","service":"api-server"},"annotations":{"summary":"Postgres is down"},"startsAt":"2024-01-01T00:00:00Z"}]}'- Create the docker_logs source for the container behind that service. Keep the constant
service: api-serverlabel as the primary label:
- name: logs
connector: docker_logs
poll: 5s
config:
container: tares-demo-api-server # the container name (docker ps)
labels:
- { name: service, const: api-server, primary: true }If the container runs under Compose, set compose_file so the tail follows restarts. Add match or drop if you want only certain lines.
- Check that the service values match. The
serviceon the alert and theserviceon the logs must be the same string, hereapi-server, so both land on the same timeline. Open Recent events on each source, then look at theapi-servertimeline in Explore. The alert and the log lines sit on one clock.
What you get
- Alert groups and container logs on one timeline per service, so the agent starts from the alerting service’s evidence.
- One event per alert, with its labels and
status, so the firing and the laterresolvedboth show next to the log lines. - Line-level control over the log stream with
matchanddrop, so noise such as access logs can stay out of the timeline. - The same view for an agent woken by a trigger and for a client you ask yourself, because both read the correlated timeline for the service.
When something else fits
- If you want a first level that looks at your sources on a schedule and escalates only when something moves, see Watch, then escalate.
- If your logs come from an OpenTelemetry pipeline instead of container tails, send them with the OTLP connector and give them the same
servicelabel. - If you want Prometheus to own the alerts without Alertmanager’s grouping, use the prometheus_alerts connector instead of alertmanager.
Related
Last updated on