# Alert rules for the Lincodex backend product metrics. Prometheus evaluates # them and shows their state on its /alerts page and to Grafana; no # Alertmanager is configured, so nothing is sent to a person yet. # # Gauges that describe database-wide state are reported by every backend # instance with the same value, so the rules aggregate them with max. Labels # stay bounded: route templates, status codes, problem codes, consumer and job # kind names, delivery kind and status, provider, and quota window. groups: - name: lincodex-api rules: - alert: LincodexBackendDown expr: up{job="backend"} == 0 for: 2m labels: severity: critical annotations: summary: Prometheus cannot scrape the backend metrics endpoint. description: The backend /metrics listener has not answered for 2 minutes; the API may be down as well. - alert: LincodexApiHighServerErrorRate # The second condition needs at least 15 requests in 5 minutes, so a # single failure on a quiet stand does not page anyone. expr: | ( sum(rate(lincodex_http_requests_total{job="backend",status=~"5.."}[5m])) / sum(rate(lincodex_http_requests_total{job="backend"}[5m])) > 0.05 ) and sum(rate(lincodex_http_requests_total{job="backend"}[5m])) > 0.05 for: 10m labels: severity: warning annotations: summary: More than 5% of API requests fail with a server error. description: Check lincodex_http_problems_total by route and code and the backend logs in Loki. - name: lincodex-events rules: - alert: LincodexOutboxRelayLagging expr: max(lincodex_outbox_relay_oldest_pending_age_seconds{job="backend"}) > 300 for: 10m labels: severity: warning annotations: summary: The earliest unpublished outbox event is older than 5 minutes. description: The relay does not keep up or cannot publish to Kafka; compare with the published rate of lincodex_outbox_relay_events_total and read the relay warnings. - alert: LincodexEventConsumerDeadLetter expr: sum by (consumer) (increase(lincodex_event_consumer_records_total{job="backend",outcome="dead_lettered"}[15m])) > 0 labels: severity: warning annotations: summary: Consumer {{ $labels.consumer }} dead-lettered an event. description: The record needs an operator; its event ID is in the consumer error log. - alert: LincodexEventConsumerStalled expr: sum by (consumer, stage) (increase(lincodex_event_consumer_failures_total{job="backend",stage=~"poll|commit"}[5m])) > 0 for: 10m labels: severity: warning annotations: summary: Consumer {{ $labels.consumer }} keeps failing at {{ $labels.stage }}. description: The consumer cannot read Kafka or store its offsets; records wait or will be delivered again. - alert: LincodexScheduledJobDead expr: sum by (kind) (increase(lincodex_scheduled_jobs_total{job="backend",outcome="dead"}[15m])) > 0 labels: severity: warning annotations: summary: A scheduled job of kind {{ $labels.kind }} is dead. description: The job used up its attempts and needs an operator. - alert: LincodexScheduledJobsLagging expr: max(lincodex_scheduled_jobs_oldest_due_age_seconds{job="backend"}) > 600 for: 15m labels: severity: warning annotations: summary: A due scheduled job has waited for more than 10 minutes. description: No instance claims due jobs; the worker may be disabled, failing, or missing the handler of their kind. - name: lincodex-mail rules: - alert: LincodexMailDeliveryUnknownOutcome expr: sum(max by (kind) (lincodex_mail_deliveries{job="backend",status="unknown"})) > 0 for: 5m labels: severity: warning annotations: summary: Mail deliveries have an unknown outcome. description: An attempt may have reached the provider without a conclusive answer; a retry needs the same idempotency key, and after the idempotency window an operator decides. # Needs the sending worker, which exports # lincodex_mail_sender_running: 1 while its loop runs, 0 otherwise, and # 0 for the whole process lifetime with EMAIL_PROVIDER=disabled, where no # loop starts. The rule fires only while at least one backend instance # reports 1, so a stand without a transport stays silent. The age gauge # counts only service mail (verification and password reset), the kinds # the worker sends: a due notification awaits product notification sending and is not # counted, so a notification backlog never fires this alert. - alert: LincodexMailDeliveriesOverdue expr: | max(lincodex_mail_delivery_oldest_due_pending_age_seconds{job="backend"}) > 900 and on () max(lincodex_mail_sender_running{job="backend"}) == 1 for: 15m labels: severity: warning annotations: summary: A pending service mail delivery has been due for more than 15 minutes. description: The sending worker runs but does not pick up due service mail (verification or password reset); check its logs and the quota gauges. Notifications are not counted. - alert: LincodexMailCancelledBroken expr: sum(increase(lincodex_mail_sender_cancelled_total{job="backend",reason=~"content_invalid|processing_failed"}[15m])) > 0 labels: severity: warning annotations: summary: The mail sending worker cancelled a delivery because of a broken row or a repeated internal failure. description: Reason content_invalid (the stored content does not match its hash, or the message is unsendable) or processing_failed (the worker failed on the row several times) is a defect or a manual edit, not a user action. Select id, kind, and cancel_reason from deliveries where status is cancelled and read the worker logs for the delivery_id. Cancellations that follow a user action (token_revoked, token_consumed, token_expired, account_not_current) are normal and do not fire this alert. - alert: LincodexMailMetricsStale expr: time() - max(lincodex_mail_metrics_last_success_timestamp_seconds{job="backend"}) > 300 for: 5m labels: severity: warning annotations: summary: The delivery and quota gauges have not been read for more than 5 minutes. description: The delivery metrics sampler cannot read PostgreSQL; the delivery and quota gauges show old values. Read its warnings in the backend logs. - alert: LincodexMailQuotaUsedUp expr: | max by (provider, window) (lincodex_mail_quota_used_recipients{job="backend"}) >= max by (provider, window) (lincodex_mail_quota_limit_recipients{job="backend"}) or max by (provider, window) (lincodex_mail_quota_provider_exhausted{job="backend"}) == 1 labels: severity: info annotations: summary: The {{ $labels.window }} mail quota of {{ $labels.provider }} is used up. description: New deliveries wait for the UTC window reset in status waiting_quota; nothing switches the plan or the transport automatically.