Add a metric for settlement fee and surplus calculation failures - #4674
Add a metric for settlement fee and surplus calculation failures#4674squadgazzz wants to merge 2 commits into
Conversation
…instead of hiding in logs
|
Claude finished @squadgazzz's task in 1m 11s —— View job PR Review: Settlement math error metric
Verdict: Looks good. Clean, minimal change that follows the existing metric conventions in this crate. The counter is correctly placed inside each One optional, non-blocking suggestion left inline on |
… is a visible increase
83398f0 to
7a9681c
Compare
Description
Fee and surplus math failures in the settlement observer only show up as warn logs. During the xdai incident (#4669) the observer persisted zeroed fees for two days before the solvers team spotted them in the DB, nobody was alerted.
We want an alert. Alerting off the warn line means matching its exact text, either through a Vector
log_to_metrictransform or a vmalert LogsQL rule. That coupling is fragile: reword the message and the metric silently stops counting while the alert keeps evaluating a flat zero, exactly the failure mode an alert must not have. A counter incremented next to the calculation cannot drift out of sync with the code.The counter is also published at zero when the observer starts. A counter series does not exist in Prometheus until its first increment, so a series born with the first failure already reads one,
increase()has nothing to subtract from, and the alert would sit quiet until a second failure arrived.Changes
settlement_math_errorscounter, labeled by calculation kind (surplus,fee,fee_breakdown), incremented wheneversummarize()falls back to zeroed valuesHow to test
Existing tests. The alert rule on the new metric follows in the infrastructure repo: