1515//! `gitlawb_pack_size_bytes`
1616//! * a single `gitlawb_info{version, did}` gauge = 1, for joins/dashboards
1717//! * currently-connected peer count — `gitlawb_peers_connected`
18+ //! * reconciliation sweep gaps found and filled —
19+ //! `gitlawb_reconciliation_gaps_found_total` /
20+ //! `gitlawb_reconciliation_gaps_filled_total`
1821//!
1922//! All metrics live in a single process-wide registry initialized by
2023//! [`init`]. Increment helpers (`record_push`, `record_auth_failure`, ...)
3336use std:: sync:: OnceLock ;
3437
3538use prometheus:: {
36- Encoder , Histogram , HistogramOpts , IntCounterVec , IntGauge , IntGaugeVec , Opts , Registry ,
37- TextEncoder ,
39+ Encoder , Histogram , HistogramOpts , IntCounter , IntCounterVec , IntGauge , IntGaugeVec , Opts ,
40+ Registry , TextEncoder ,
3841} ;
3942
4043/// The single, process-wide metrics registry. Initialized by [`init`].
@@ -51,6 +54,8 @@ static SYNC_PROCESSED: OnceLock<IntCounterVec> = OnceLock::new();
5154static WEBHOOK_DELIVERIES : OnceLock < IntCounterVec > = OnceLock :: new ( ) ;
5255static PACK_SIZE : OnceLock < Histogram > = OnceLock :: new ( ) ;
5356static PEERS_CONNECTED : OnceLock < IntGauge > = OnceLock :: new ( ) ;
57+ static RECONCILIATION_GAPS_FOUND : OnceLock < IntCounter > = OnceLock :: new ( ) ;
58+ static RECONCILIATION_GAPS_FILLED : OnceLock < IntCounter > = OnceLock :: new ( ) ;
5459
5560/// One-time initializer. Builds the registry, registers every metric,
5661/// and sets the constant `gitlawb_info` gauge. Idempotent — calling
@@ -197,6 +202,30 @@ pub fn init(version: &str, node_did: &str) {
197202 . set ( peers_connected)
198203 . expect ( "set PEERS_CONNECTED once" ) ;
199204
205+ let gaps_found = IntCounter :: with_opts ( Opts :: new (
206+ "gitlawb_reconciliation_gaps_found_total" ,
207+ "Total reconciliation sweep gaps detected (objects that should be pinned but are not)" ,
208+ ) )
209+ . expect ( "gitlawb_reconciliation_gaps_found_total definition" ) ;
210+ registry
211+ . register ( Box :: new ( gaps_found. clone ( ) ) )
212+ . expect ( "register gitlawb_reconciliation_gaps_found_total" ) ;
213+ RECONCILIATION_GAPS_FOUND
214+ . set ( gaps_found)
215+ . expect ( "set RECONCILIATION_GAPS_FOUND once" ) ;
216+
217+ let gaps_filled = IntCounter :: with_opts ( Opts :: new (
218+ "gitlawb_reconciliation_gaps_filled_total" ,
219+ "Total reconciliation sweep gaps successfully filled (objects pinned by the sweep)" ,
220+ ) )
221+ . expect ( "gitlawb_reconciliation_gaps_filled_total definition" ) ;
222+ registry
223+ . register ( Box :: new ( gaps_filled. clone ( ) ) )
224+ . expect ( "register gitlawb_reconciliation_gaps_filled_total" ) ;
225+ RECONCILIATION_GAPS_FILLED
226+ . set ( gaps_filled)
227+ . expect ( "set RECONCILIATION_GAPS_FILLED once" ) ;
228+
200229 REGISTRY
201230 . set ( registry)
202231 . expect ( "set REGISTRY once (init must be called exactly once)" ) ;
@@ -264,6 +293,20 @@ pub fn set_peers_connected(count: i64) {
264293 }
265294}
266295
296+ /// Record reconciliation sweep gaps found (objects that should be pinned but are not).
297+ pub fn record_reconciliation_gaps_found ( count : u64 ) {
298+ if let Some ( c) = RECONCILIATION_GAPS_FOUND . get ( ) {
299+ c. inc_by ( count) ;
300+ }
301+ }
302+
303+ /// Record reconciliation sweep gaps filled (objects successfully pinned by the sweep).
304+ pub fn record_reconciliation_gaps_filled ( count : u64 ) {
305+ if let Some ( c) = RECONCILIATION_GAPS_FILLED . get ( ) {
306+ c. inc_by ( count) ;
307+ }
308+ }
309+
267310/// Encode the registry as the standard Prometheus text exposition format.
268311/// Returns an error if `init` was never called.
269312pub fn encode ( ) -> Result < String , prometheus:: Error > {
0 commit comments