Skip to content

Commit 3a688cc

Browse files
devin-ai-integration[bot]Jayant Krishnamurthy
andauthored
feat: add request duration tracking for Fortuna callbacks (#2197)
* feat: add request_duration_ms histogram metric to track callback processing time Co-Authored-By: Jayant Krishnamurthy <jayant@dourolabs.xyz> * feat: implement request duration tracking in process_event_with_backoff Co-Authored-By: Jayant Krishnamurthy <jayant@dourolabs.xyz> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Jayant Krishnamurthy <jayant@dourolabs.xyz>
1 parent 97270f2 commit 3a688cc

File tree

3 files changed

+74
-27
lines changed

3 files changed

+74
-27
lines changed

apps/fortuna/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/fortuna/Cargo.toml

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,43 @@
11
[package]
2-
name = "fortuna"
3-
version = "6.6.0"
2+
name = "fortuna"
3+
version = "6.7.0"
44
edition = "2021"
55

66
[dependencies]
7-
anyhow = "1.0.75"
8-
axum = { version = "0.6.20", features = ["json", "ws", "macros"] }
9-
axum-macros = { version = "0.3.8" }
10-
base64 = { version = "0.21.0" }
7+
anyhow = "1.0.75"
8+
axum = { version = "0.6.20", features = ["json", "ws", "macros"] }
9+
axum-macros = { version = "0.3.8" }
10+
base64 = { version = "0.21.0" }
1111
bincode = "1.3.3"
12-
byteorder = "1.5.0"
13-
clap = { version = "4.4.6", features = ["derive", "cargo", "env"] }
14-
ethabi = "18.0.0"
15-
ethers = { version = "2.0.14", features = ["ws"] }
16-
futures = { version = "0.3.28" }
12+
byteorder = "1.5.0"
13+
clap = { version = "4.4.6", features = ["derive", "cargo", "env"] }
14+
ethabi = "18.0.0"
15+
ethers = { version = "2.0.14", features = ["ws"] }
16+
futures = { version = "0.3.28" }
1717
hex = "0.4.3"
18-
prometheus-client = { version = "0.21.2" }
18+
prometheus-client = { version = "0.21.2" }
1919
pythnet-sdk = { path = "../../pythnet/pythnet_sdk", features = ["strum"] }
20-
rand = "0.8.5"
21-
reqwest = { version = "0.11.22", features = ["json", "blocking"] }
22-
serde = { version = "1.0.188", features = ["derive"] }
23-
serde_qs = { version = "0.12.0", features = ["axum"] }
24-
serde_json = "1.0.107"
20+
rand = "0.8.5"
21+
reqwest = { version = "0.11.22", features = ["json", "blocking"] }
22+
serde = { version = "1.0.188", features = ["derive"] }
23+
serde_qs = { version = "0.12.0", features = ["axum"] }
24+
serde_json = "1.0.107"
2525
serde_with = { version = "3.4.0", features = ["hex", "base64"] }
2626
serde_yaml = "0.9.25"
27-
sha3 = "0.10.8"
28-
tokio = { version = "1.33.0", features = ["full"] }
29-
tower-http = { version = "0.4.0", features = ["cors"] }
30-
tracing = { version = "0.1.37", features = ["log"] }
27+
sha3 = "0.10.8"
28+
tokio = { version = "1.33.0", features = ["full"] }
29+
tower-http = { version = "0.4.0", features = ["cors"] }
30+
tracing = { version = "0.1.37", features = ["log"] }
3131
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
32-
utoipa = { version = "3.4.0", features = ["axum_extras"] }
33-
utoipa-swagger-ui = { version = "3.1.4", features = ["axum"] }
32+
utoipa = { version = "3.4.0", features = ["axum_extras"] }
33+
utoipa-swagger-ui = { version = "3.1.4", features = ["axum"] }
3434
once_cell = "1.18.0"
3535
lazy_static = "1.4.0"
3636
url = "2.5.0"
37-
chrono = { version = "0.4.38", features = ["clock", "std"] , default-features = false}
37+
chrono = { version = "0.4.38", features = [
38+
"clock",
39+
"std",
40+
], default-features = false }
3841
backoff = { version = "0.4.0", features = ["futures", "tokio"] }
3942
thiserror = "1.0.61"
4043
futures-locks = "0.7.1"

apps/fortuna/src/keeper.rs

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use {
2020
futures::StreamExt,
2121
prometheus_client::{
2222
encoding::EncodeLabelSet,
23-
metrics::{counter::Counter, family::Family, gauge::Gauge},
23+
metrics::{counter::Counter, family::Family, gauge::Gauge, histogram::Histogram},
2424
registry::Registry,
2525
},
2626
std::{
@@ -62,7 +62,6 @@ pub struct AccountLabel {
6262
pub address: String,
6363
}
6464

65-
#[derive(Default)]
6665
pub struct KeeperMetrics {
6766
pub current_sequence_number: Family<AccountLabel, Gauge>,
6867
pub end_sequence_number: Family<AccountLabel, Gauge>,
@@ -74,6 +73,33 @@ pub struct KeeperMetrics {
7473
pub requests_processed: Family<AccountLabel, Counter>,
7574
pub requests_reprocessed: Family<AccountLabel, Counter>,
7675
pub reveals: Family<AccountLabel, Counter>,
76+
pub request_duration_ms: Family<AccountLabel, Histogram>,
77+
}
78+
79+
impl Default for KeeperMetrics {
80+
fn default() -> Self {
81+
Self {
82+
current_sequence_number: Family::default(),
83+
end_sequence_number: Family::default(),
84+
balance: Family::default(),
85+
collected_fee: Family::default(),
86+
current_fee: Family::default(),
87+
total_gas_spent: Family::default(),
88+
requests: Family::default(),
89+
requests_processed: Family::default(),
90+
requests_reprocessed: Family::default(),
91+
reveals: Family::default(),
92+
request_duration_ms: Family::new_with_constructor(|| {
93+
Histogram::new(
94+
vec![
95+
1000.0, 2500.0, 5000.0, 7500.0, 10000.0, 20000.0, 30000.0, 40000.0,
96+
50000.0, 60000.0,
97+
]
98+
.into_iter(),
99+
)
100+
}),
101+
}
102+
}
77103
}
78104

79105
impl KeeperMetrics {
@@ -141,6 +167,12 @@ impl KeeperMetrics {
141167
keeper_metrics.requests_reprocessed.clone(),
142168
);
143169

170+
writable_registry.register(
171+
"request_duration_ms",
172+
"Time taken to process each callback request in milliseconds",
173+
keeper_metrics.request_duration_ms.clone(),
174+
);
175+
144176
keeper_metrics
145177
}
146178
}
@@ -342,6 +374,8 @@ pub async fn process_event_with_backoff(
342374
gas_limit: U256,
343375
metrics: Arc<KeeperMetrics>,
344376
) {
377+
let start_time = std::time::Instant::now();
378+
345379
metrics
346380
.requests
347381
.get_or_create(&AccountLabel {
@@ -372,6 +406,16 @@ pub async fn process_event_with_backoff(
372406
tracing::error!("Failed to process event: {:?}", e);
373407
}
374408
}
409+
410+
let duration_ms = start_time.elapsed().as_millis() as f64;
411+
metrics
412+
.request_duration_ms
413+
.get_or_create(&AccountLabel {
414+
chain_id: chain_state.id.clone(),
415+
address: chain_state.provider_address.to_string(),
416+
})
417+
.observe(duration_ms);
418+
375419
metrics
376420
.requests_processed
377421
.get_or_create(&AccountLabel {

0 commit comments

Comments
 (0)