-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathmetrics.rs
More file actions
114 lines (103 loc) · 3.98 KB
/
metrics.rs
File metadata and controls
114 lines (103 loc) · 3.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
use prometheus::{register_int_counter, register_int_gauge, IntCounter, IntGauge};
use sqlx::PgPool;
use std::sync::LazyLock;
use tokio::{task::JoinHandle, time::sleep};
use tracing::{error, info};
pub(crate) static VERIFY_PROOF_SUCCESS_COUNTER: LazyLock<IntCounter> = LazyLock::new(|| {
register_int_counter!(
"coprocessor_txn_sender_verify_proof_success_counter",
"Number of successful verify or reject proof txns in transaction-sender"
)
.unwrap()
});
pub(crate) static VERIFY_PROOF_FAIL_COUNTER: LazyLock<IntCounter> = LazyLock::new(|| {
register_int_counter!(
"coprocessor_txn_sender_verify_proof_fail_counter",
"Number of failed verify or reject proof txns requests in transaction-sender"
)
.unwrap()
});
pub(crate) static ADD_CIPHERTEXT_MATERIAL_SUCCESS_COUNTER: LazyLock<IntCounter> =
LazyLock::new(|| {
register_int_counter!(
"coprocessor_txn_sender_add_ciphertext_material_success_counter",
"Number of successful add ciphertext material txns in transaction-sender"
)
.unwrap()
});
pub(crate) static ADD_CIPHERTEXT_MATERIAL_FAIL_COUNTER: LazyLock<IntCounter> =
LazyLock::new(|| {
register_int_counter!(
"coprocessor_txn_sender_add_ciphertext_material_fail_counter",
"Number of failed add ciphertext material txns requests in transaction-sender"
)
.unwrap()
});
pub(crate) static ADD_CIPHERTEXT_MATERIAL_UNSENT: LazyLock<IntGauge> = LazyLock::new(|| {
register_int_gauge!(
"coprocessor_add_ciphertext_material_unsent_gauge",
"Number of unsent add ciphertext material transactions"
)
.unwrap()
});
pub(crate) static VERIFY_PROOF_RESP_UNSENT_TXN: LazyLock<IntGauge> = LazyLock::new(|| {
register_int_gauge!(
"coprocessor_verify_proof_resp_unsent_txn_gauge",
"Number of unsent verify proof response transactions"
)
.unwrap()
});
pub(crate) static VERIFY_PROOF_PENDING: LazyLock<IntGauge> = LazyLock::new(|| {
register_int_gauge!(
"coprocessor_verify_proof_pending_gauge",
"Number of pending verify proof requests"
)
.unwrap()
});
pub fn spawn_gauge_update_routine(period: std::time::Duration, db_pool: PgPool) -> JoinHandle<()> {
tokio::spawn(async move {
loop {
match sqlx::query_scalar(
"SELECT COUNT(*) FROM ciphertext_digest WHERE txn_is_sent = FALSE",
)
.fetch_one(&db_pool)
.await
{
Ok(count) => {
info!(unsent_add_ciphertext_material_count = %count, "Fetched unsent add ciphertext material count");
ADD_CIPHERTEXT_MATERIAL_UNSENT.set(count);
}
Err(e) => {
error!(error = %e, "Failed to fetch unsent add ciphertext material count");
}
}
match sqlx::query_scalar("SELECT COUNT(*) FROM verify_proofs WHERE verified IS NULL")
.fetch_one(&db_pool)
.await
{
Ok(count) => {
info!(verify_proof_pending = %count, "Fetched pending verify proofs count");
VERIFY_PROOF_PENDING.set(count);
}
Err(e) => {
error!(error = %e, "Failed to fetch pending verify proofs count");
}
}
match sqlx::query_scalar(
"SELECT COUNT(*) FROM verify_proofs WHERE verified IS NOT NULL",
)
.fetch_one(&db_pool)
.await
{
Ok(count) => {
info!(verify_proof_resp_unsent_txn = %count, "Fetched unsent verify proof response count");
VERIFY_PROOF_RESP_UNSENT_TXN.set(count);
}
Err(e) => {
error!(error = %e, "Failed to fetch unsent verify proof response count");
}
}
sleep(period).await;
}
})
}