taler-rust

GNU Taler code in Rust. Largely core banking integrations.
Log | Files | Refs | Submodules | README | LICENSE

commit e9aedc01fa0725d6b0aa01ec5bf8c1b996706fc8
parent 080c8587ba31f63a7ca8b929b06ef2808ce723ad
Author: Antoine A <>
Date:   Wed, 14 Oct 2026 18:34:51 +0200

wise: add some more metrics

Diffstat:
Madapters/taler-wise/src/api.rs | 42+++++++++++++++++++++++++++++++++++++++---
1 file changed, 39 insertions(+), 3 deletions(-)

diff --git a/adapters/taler-wise/src/api.rs b/adapters/taler-wise/src/api.rs @@ -26,7 +26,11 @@ use axum::{ use compact_str::{CompactString, format_compact}; use http_client::headers::HeaderParser; use jiff::Timestamp; -use prometheus_client::{metrics::gauge::Gauge, registry::Registry}; +use prometheus_client::{ + encoding::EncodeLabelSet, + metrics::{family::Family, gauge::Gauge}, + registry::{Registry, Unit}, +}; use serde::Deserialize; use serde_json::value::RawValue; use sqlx::PgPool; @@ -142,9 +146,16 @@ pub struct WiseBalanceApi { registry: Registry, } +#[derive(Clone, Debug, Hash, PartialEq, Eq, EncodeLabelSet)] +struct TaskLabel { + name: &'static str, +} + #[derive(Default)] struct Metrics { db_access: Gauge, + task_execution: Family<TaskLabel, Gauge>, + task_success: Family<TaskLabel, Gauge>, } impl Metrics { @@ -156,11 +167,36 @@ impl Metrics { "Whether the last database metrics refresh succeeded", self.db_access.clone(), ); + registry.register_with_unit( + "task_execution_timestamp_seconds", + "Unix timestamp of the last task execution", + Unit::Seconds, + self.task_execution.clone(), + ); + registry.register_with_unit( + "task_success_timestamp_seconds", + "Unix timestamp of the last successful task execution", + Unit::Seconds, + self.task_success.clone(), + ); registry } - pub async fn sync(&self, db: &PgPool) { + pub async fn sync(&self, db: &PgPool, balance_id: u32) { let test = sqlx::query("SELECT 1").fetch_one(db).await.is_ok(); + if let Ok(Some(state)) = db::load_sync_state(db, balance_id).await { + let label = TaskLabel { name: "sync" }; + let success = state + .early_success + .max(state.sync_success) + .max(state.checkpoint_success); + + if let Some(time) = success { + self.task_success + .get_or_create(&label) + .set(time.as_second()); + } + } self.db_access.set(if test { 1 } else { 0 }); } } @@ -355,7 +391,7 @@ impl PreparedTransfer for WiseBalanceApi { impl Observability for WiseBalanceApi { async fn metrics(&self) -> ApiResult<&Registry> { - self.metrics.sync(&self.pool).await; + self.metrics.sync(&self.pool, self.id).await; Ok(&self.registry) } }