Expose Prometheus metrics for periodic replica validation
Feature Description
Expose the result and last successful time of periodic replica validation through Prometheus.
Use Cases
Alert on backup continuity problems, distinguish invalid backup files from storage errors that prevent a check, and detect validation that stops succeeding. Each alert needs the database and compaction level so an operator can identify the affected backup.
Attempted Solutions
At upstream commit 3b91159, Store.Validate returns validation findings or a storage error, and monitorValidation only writes those results to the logger. The post-compaction verification metric covers a different operation. An operator can build alerts from validation logs, but there is no metric for the last passing check.
Proposal
We have prepared a small change in the apoxy-dev/litestream fork that adds:
litestream_validation_checks_total{db,level,result}, with bounded resultssuccess,invalid, anderror.litestream_last_validation_success{db,level}, for the last check result.litestream_last_validation_success_timestamp_seconds{db,level}, for checks that stop succeeding.
The existing TestStore_Validate cases assert exported metrics for valid and invalid listings, database and level attribution, and skipped databases without a replica. The existing Monitoring & Metrics list documents the metrics and their labels. The change preserves the existing validation and replication behavior.
The metrics describe file continuity checks; they do not establish that a database restore will succeed.
We would like to contribute this upstream. The implementation is available for review in apoxy-dev/litestream#1. We will submit an upstream pull request after human review, as requested by the contribution guide.
Verification passed with Go 1.26.8 on macOS arm64:
go test -race -run '^TestStore_Validate$' .
go test -race -run 'TestStore_(Validate|ValidationMonitor)' .
go test -race -short ./...All pre-commit hooks passed, including go vet and staticcheck.
Does this metric set and labeling fit the project's monitoring conventions?
Source: benbjohnson/litestream