feat(mail): send service identity mail through a leased worker

This commit is contained in:
shira committed 2026-10-06 21:08:11 +03:00
1 parent 204c6bae62
commit d21fd49a42
58 files changed
+7577 -164

No files matched your search

+18 -5
View File
@@ -92,9 +92,14 @@ groups:
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.
# Inert until the sending worker exists: TASK-016 must export
# lincodex_mail_sender_running (1 while its loop runs) as part of its
# definition of done. Without that series the rule matches nothing.
# Needs the sending worker (TASK-016), 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 waits for TASK-462 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
@@ -104,8 +109,16 @@ groups:
labels:
severity: warning
annotations:
summary: A pending mail delivery has been due for more than 15 minutes.
description: The sending worker runs but does not pick up due deliveries; check its logs and the quota gauges.
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
@@ -199,6 +199,16 @@ tests:
- 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"}
@@ -215,8 +225,88 @@ tests:
- exp_labels:
severity: warning
exp_annotations:
summary: A pending mail delivery has been due for more than 15 minutes.
description: The sending worker runs but does not pick up due deliveries; check its logs and the quota gauges.
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"}