Alerts
How to be told when your functions misbehave: the metrics you can watch, how rules are checked, and how to manage them over HTTP.
1. Create a rule
Alert rules are managed over HTTP with a service_role key. The SDK has no method for them.
2. Metrics, conditions and channels
| Field | Allowed values |
|---|---|
metric | error_rate, latency_p95, job_failures, low_disk, ai_quota, anomaly_detection, or log_pattern:<service>:<regex> |
condition | gt, lt, eq, match, auto |
channel | email, webhook, slack |
threshold | A number |
destination | An e-mail address, or the URL of the webhook or Slack hook |
log_pattern watches the logs of one service for a regular expression: log_pattern:functions:timeout. An unknown value returns 400 and lists the accepted ones. Real answer for metric: "cpu":
3. How rules are checked
- The service checks every enabled rule once per minute.
- Numeric metrics are read from Prometheus;
log_patternrules query Loki. Each query has a 5-second limit. If one project fails, the others are still checked. - When a rule fires, the service sets
last_triggered_at, records an event and publishes it for delivery on the chosen channel. - A rule you disable is kept but not checked.
Alerts need Prometheus and Loki to be reachable from the functions service, and the e-mail channel needs an e-mail provider. On a development stack without them, a rule is stored but cannot fire.
4. Manage rules and history
| Action | Request |
|---|---|
| List rules | GET /v1/functions/alerts |
| Enable or disable | PATCH /v1/functions/alerts/{id} with {"enabled": false} |
| Delete | DELETE /v1/functions/alerts/{id} |
| History of one rule | GET /v1/functions/alerts/{id}/events |
| History of all rules | GET /v1/functions/alerts/events |
An event has alert_rule_id, event_type, triggered_value, message and created_at; the history routes accept limit and offset. Every route needs a service_role key.