Files
lincodex/observability/prometheus/tests/lincodex_rules_test.yml
T

334 lines
14 KiB
YAML

# Unit tests for rules/lincodex.yml; run with `make -C observability check`.
# Every alert has a firing case; guarded alerts also have a silent one.
rule_files:
- ../rules/lincodex.yml
evaluation_interval: 1m
tests:
- interval: 1m
input_series:
- series: lincodex_outbox_relay_oldest_pending_age_seconds{job="backend",instance="a"}
values: 400x20
- series: lincodex_outbox_relay_oldest_pending_age_seconds{job="backend",instance="b"}
values: '0x20'
alert_rule_test:
- eval_time: 5m
alertname: LincodexOutboxRelayLagging
exp_alerts: []
- eval_time: 15m
alertname: LincodexOutboxRelayLagging
exp_alerts:
- exp_labels:
severity: warning
exp_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.
- interval: 1m
input_series:
- series: up{job="backend",instance="backend:9090"}
values: 1 1 0 0 0 0 0
alert_rule_test:
- eval_time: 3m
alertname: LincodexBackendDown
exp_alerts: []
- eval_time: 5m
alertname: LincodexBackendDown
exp_alerts:
- exp_labels:
severity: critical
instance: backend:9090
job: backend
exp_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.
- interval: 1m
input_series:
- series: lincodex_event_consumer_records_total{job="backend",consumer="mail_delivery",outcome="dead_lettered"}
values: 0 0 0 1 1 1
- series: lincodex_event_consumer_failures_total{job="backend",consumer="mail_delivery",stage="poll"}
values: 0+1x20
- series: lincodex_event_consumer_failures_total{job="backend",consumer="mail_delivery",stage="handler"}
values: 0+1x20
alert_rule_test:
- eval_time: 2m
alertname: LincodexEventConsumerDeadLetter
exp_alerts: []
- eval_time: 5m
alertname: LincodexEventConsumerDeadLetter
exp_alerts:
- exp_labels:
severity: warning
consumer: mail_delivery
exp_annotations:
summary: Consumer mail_delivery dead-lettered an event.
description: The record needs an operator; its event ID is in the consumer error log.
- eval_time: 5m
alertname: LincodexEventConsumerStalled
exp_alerts: []
- eval_time: 16m
alertname: LincodexEventConsumerStalled
exp_alerts:
- exp_labels:
severity: warning
consumer: mail_delivery
stage: poll
exp_annotations:
summary: Consumer mail_delivery keeps failing at poll.
description: The consumer cannot read Kafka or store its offsets; records wait or will be delivered again.
- interval: 1m
input_series:
- series: lincodex_scheduled_jobs_total{job="backend",kind="invitation.response_deadline",outcome="dead"}
values: 0 0 1 1 1
- series: lincodex_scheduled_jobs_oldest_due_age_seconds{job="backend",instance="a"}
values: 700x30
alert_rule_test:
- eval_time: 1m
alertname: LincodexScheduledJobDead
exp_alerts: []
- eval_time: 4m
alertname: LincodexScheduledJobDead
exp_alerts:
- exp_labels:
severity: warning
kind: invitation.response_deadline
exp_annotations:
summary: A scheduled job of kind invitation.response_deadline is dead.
description: The job used up its attempts and needs an operator.
- eval_time: 10m
alertname: LincodexScheduledJobsLagging
exp_alerts: []
- eval_time: 20m
alertname: LincodexScheduledJobsLagging
exp_alerts:
- exp_labels:
severity: warning
exp_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.
- interval: 1m
input_series:
- series: lincodex_http_requests_total{job="backend",method="GET",route="/api/v1/healthz",status="200"}
values: 0+10x20
- series: lincodex_http_requests_total{job="backend",method="GET",route="/api/v1/healthz",status="500"}
values: 0+5x20
alert_rule_test:
- eval_time: 20m
alertname: LincodexApiHighServerErrorRate
exp_alerts:
- exp_labels:
severity: warning
exp_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.
- interval: 1m
input_series:
- series: lincodex_http_requests_total{job="backend",method="GET",route="/api/v1/healthz",status="200"}
values: '0x20'
- series: lincodex_http_requests_total{job="backend",method="GET",route="/api/v1/healthz",status="500"}
values: 0+1x20
alert_rule_test:
- eval_time: 8m
alertname: LincodexApiHighServerErrorRate
exp_alerts: []
- eval_time: 15m
alertname: LincodexApiHighServerErrorRate
exp_alerts: []
- interval: 1m
input_series:
- series: lincodex_mail_deliveries{job="backend",instance="a",kind="verification",status="unknown"}
values: 1x10
- series: lincodex_mail_deliveries{job="backend",instance="b",kind="verification",status="unknown"}
values: 1x10
- series: lincodex_mail_quota_used_recipients{job="backend",instance="a",provider="resend",window="day"}
values: 100x10
- series: lincodex_mail_quota_limit_recipients{job="backend",instance="a",provider="resend",window="day"}
values: 100x10
- series: lincodex_mail_quota_provider_exhausted{job="backend",instance="a",provider="resend",window="day"}
values: '0x10'
- series: lincodex_mail_quota_used_recipients{job="backend",instance="a",provider="resend",window="month"}
values: 120x10
- series: lincodex_mail_quota_limit_recipients{job="backend",instance="a",provider="resend",window="month"}
values: 3000x10
- series: lincodex_mail_quota_provider_exhausted{job="backend",instance="a",provider="resend",window="month"}
values: '0x10'
alert_rule_test:
- eval_time: 10m
alertname: LincodexMailDeliveryUnknownOutcome
exp_alerts:
- exp_labels:
severity: warning
exp_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.
- eval_time: 10m
alertname: LincodexMailQuotaUsedUp
exp_alerts:
- exp_labels:
severity: info
provider: resend
window: day
exp_annotations:
summary: The day mail quota of resend is used up.
description: New deliveries wait for the UTC window reset in status waiting_quota; nothing switches the plan or the transport automatically.
- interval: 1m
input_series:
- series: lincodex_mail_quota_used_recipients{job="backend",instance="a",provider="resend",window="month"}
values: 120x10
- series: lincodex_mail_quota_limit_recipients{job="backend",instance="a",provider="resend",window="month"}
values: 3000x10
- series: lincodex_mail_quota_provider_exhausted{job="backend",instance="a",provider="resend",window="month"}
values: 0 0 0 0 0 1 1 1 1 1
alert_rule_test:
- eval_time: 3m
alertname: LincodexMailQuotaUsedUp
exp_alerts: []
- eval_time: 7m
alertname: LincodexMailQuotaUsedUp
exp_alerts:
- exp_labels:
severity: info
provider: resend
window: month
exp_annotations:
summary: The month mail quota of resend is used up.
description: New deliveries wait for the UTC window reset in status waiting_quota; nothing switches the plan or the transport automatically.
- interval: 1m
input_series:
- series: lincodex_mail_delivery_oldest_due_pending_age_seconds{job="backend",instance="a"}
values: 2000x40
alert_rule_test:
- eval_time: 30m
alertname: LincodexMailDeliveriesOverdue
exp_alerts: []
- interval: 1m
input_series:
- series: lincodex_mail_delivery_oldest_due_pending_age_seconds{job="backend",instance="a"}
values: 2000x40
- series: lincodex_mail_sender_running{job="backend",instance="a"}
values: 0x40
alert_rule_test:
- eval_time: 30m
alertname: LincodexMailDeliveriesOverdue
exp_alerts: []
- interval: 1m
input_series:
- series: lincodex_mail_delivery_oldest_due_pending_age_seconds{job="backend",instance="a"}
values: 2000x40
- series: lincodex_mail_sender_running{job="backend",instance="a"}
values: 1x40
alert_rule_test:
- eval_time: 10m
alertname: LincodexMailDeliveriesOverdue
exp_alerts: []
- eval_time: 20m
alertname: LincodexMailDeliveriesOverdue
exp_alerts:
- exp_labels:
severity: warning
exp_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.
- interval: 1m
input_series:
- series: lincodex_mail_delivery_oldest_due_pending_age_seconds{job="backend",instance="a"}
values: 2000x40
- series: lincodex_mail_sender_running{job="backend",instance="a"}
values: 0x40
- series: lincodex_mail_sender_running{job="backend",instance="b"}
values: 1x40
alert_rule_test:
- eval_time: 10m
alertname: LincodexMailDeliveriesOverdue
exp_alerts: []
- eval_time: 20m
alertname: LincodexMailDeliveriesOverdue
exp_alerts:
- exp_labels:
severity: warning
exp_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.
- interval: 1m
# A backlog of notifications only: the sampler reports an age of 0 for
# service mail, so the alert stays silent although the sender runs and
# notifications are due.
input_series:
- series: lincodex_mail_delivery_oldest_due_pending_age_seconds{job="backend",instance="a"}
values: 0x40
- series: lincodex_mail_deliveries{job="backend",instance="a",kind="notification",status="pending"}
values: 500x40
- series: lincodex_mail_sender_running{job="backend",instance="a"}
values: 1x40
alert_rule_test:
- eval_time: 30m
alertname: LincodexMailDeliveriesOverdue
exp_alerts: []
- interval: 1m
input_series:
- series: lincodex_mail_sender_cancelled_total{job="backend",instance="a",reason="content_invalid"}
values: 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
- series: lincodex_mail_sender_cancelled_total{job="backend",instance="a",reason="token_revoked"}
values: 0+5x40
alert_rule_test:
- eval_time: 9m
alertname: LincodexMailCancelledBroken
exp_alerts: []
- eval_time: 12m
alertname: LincodexMailCancelledBroken
exp_alerts:
- exp_labels:
severity: warning
exp_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.
- eval_time: 35m
alertname: LincodexMailCancelledBroken
exp_alerts: []
- interval: 1m
# Reasons that follow a user action never fire it, however many there are.
input_series:
- series: lincodex_mail_sender_cancelled_total{job="backend",instance="a",reason="token_revoked"}
values: 0+5x40
- series: lincodex_mail_sender_cancelled_total{job="backend",instance="a",reason="token_expired"}
values: 0+3x40
alert_rule_test:
- eval_time: 30m
alertname: LincodexMailCancelledBroken
exp_alerts: []
- interval: 1m
input_series:
- series: lincodex_mail_sender_cancelled_total{job="backend",instance="a",reason="processing_failed"}
values: 0 0 0 0 0 2x34
alert_rule_test:
- eval_time: 8m
alertname: LincodexMailCancelledBroken
exp_alerts:
- exp_labels:
severity: warning
exp_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.
- interval: 1m
input_series:
- series: lincodex_mail_metrics_last_success_timestamp_seconds{job="backend",instance="a"}
values: '0x20'
alert_rule_test:
- eval_time: 5m
alertname: LincodexMailMetricsStale
exp_alerts: []
- eval_time: 12m
alertname: LincodexMailMetricsStale
exp_alerts:
- exp_labels:
severity: warning
exp_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.
- interval: 1m
input_series:
- series: lincodex_mail_metrics_last_success_timestamp_seconds{job="backend",instance="a"}
values: 0+60x20
alert_rule_test:
- eval_time: 15m
alertname: LincodexMailMetricsStale
exp_alerts: []