Per-tenant SLA monitoring
Latency time-series joined to a tenants table — alerts when any single tenant breaches.
A request-latency time-series tagged with tenant_id joins to the relational tenants table to pick up the per-tenant SLA target. Any tenant whose 5-minute p99 breaches their own SLA fires an alert — without an external observability stack to maintain.
sql
WITH latency_5m AS (
SELECT
time_bucket('5 minutes', timestamp) AS bucket,
tags->>'tenant_id' AS tenant_id,
PERCENTILE_CONT(0.99)
WITHIN GROUP (ORDER BY value) AS p99
FROM metrics
WHERE metric = 'request.latency'
AND timestamp > now() - INTERVAL '15 minutes'
GROUP BY bucket, tenant_id
)
SELECT t.name, l.bucket, l.p99, t.sla_p99_ms
FROM latency_5m l
JOIN tenants t ON t.id::text = l.tenant_id
WHERE l.p99 > t.sla_p99_ms
ORDER BY l.bucket DESC, l.p99 DESC;