Skip to content

Commit

Permalink
feat: Metrics for in-memory store (#393)
Browse files Browse the repository at this point in the history
* feat: Metrics for in-memory store

* down
  • Loading branch information
m30m authored Feb 18, 2025
1 parent 177c66f commit e569bf5
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
12 changes: 12 additions & 0 deletions auction-server/src/auction/repository/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use {
db::DB,
entities::ChainId,
},
axum_prometheus::metrics,
solana_sdk::pubkey::Pubkey,
std::collections::{
HashMap,
Expand Down Expand Up @@ -101,4 +102,15 @@ impl<T: ChainTrait> Repository<T> {
chain_id,
}
}
pub async fn update_metrics(&self) {
let label = [("chain_id", self.chain_id.to_string())];
let store = &self.in_memory_store;
metrics::gauge!("in_memory_auctions", &label).set(store.auctions.read().await.len() as f64);
metrics::gauge!("in_memory_pending_bids", &label)
.set(store.pending_bids.read().await.len() as f64);
metrics::gauge!("in_memory_auction_locks", &label)
.set(store.auction_lock.lock().await.len() as f64);
metrics::gauge!("in_memory_bid_locks", &label)
.set(store.bid_lock.lock().await.len() as f64);
}
}
17 changes: 16 additions & 1 deletion auction-server/src/auction/service/workers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl Service<Evm> {
}

const GET_LATEST_BLOCKHASH_INTERVAL_SVM: Duration = Duration::from_secs(5);

const METRIC_COLLECTION_INTERVAL: Duration = Duration::from_secs(1);
impl Service<Svm> {
pub async fn conclude_auction_for_log(
&self,
Expand Down Expand Up @@ -266,6 +266,21 @@ impl Service<Svm> {
Ok(())
}

pub async fn run_metric_collector_loop(&self) -> Result<()> {
let mut exit_check_interval = tokio::time::interval(EXIT_CHECK_INTERVAL);
let mut metric_interval = tokio::time::interval(METRIC_COLLECTION_INTERVAL);
while !SHOULD_EXIT.load(Ordering::Acquire) {
tokio::select! {
_ = metric_interval.tick() => {
self.repo.update_metrics().await;
}
_ = exit_check_interval.tick() => {}
}
}
tracing::info!("Shutting down metric collector svm...");
Ok(())
}

pub async fn run_watcher_loop(&self) -> Result<()> {
while !SHOULD_EXIT.load(Ordering::Acquire) {
let responses = (
Expand Down
16 changes: 16 additions & 0 deletions auction-server/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,22 @@ pub async fn start_server(run_options: RunOptions) -> Result<()> {
});
join_all(tracker_loops).await;
},
async {
let metric_loops = auction_services.iter().filter_map(|(chain_id, service)| {
if let auction_service::ServiceEnum::Svm(service) = service {
Some(fault_tolerant_handler(
format!("metric loop for chain {}", chain_id.clone()),
|| {
let service = service.clone();
async move { service.run_metric_collector_loop().await }
},
))
} else {
None
}
});
join_all(metric_loops).await;
},
async {
let watcher_loops = auction_services.iter().filter_map(|(chain_id, service)| {
if let auction_service::ServiceEnum::Svm(service) = service {
Expand Down

0 comments on commit e569bf5

Please sign in to comment.