Skip to content

Commit b6d6204

Browse files
committed
refactor: move metrics to new file and merge imports
Signed-off-by: Gustavo Inacio <[email protected]>
1 parent 828356f commit b6d6204

File tree

11 files changed

+213
-196
lines changed

11 files changed

+213
-196
lines changed

crates/tap-agent/src/agent.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use crate::agent::sender_accounts_manager::{
1616
use crate::{database, CONFIG, EIP_712_DOMAIN};
1717
use sender_accounts_manager::SenderAccountsManager;
1818

19+
mod metrics;
1920
pub mod sender_account;
2021
pub mod sender_accounts_manager;
2122
pub mod sender_allocation;
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
use prometheus::{
2+
register_counter_vec, register_gauge_vec, register_histogram_vec, register_int_gauge_vec,
3+
CounterVec, GaugeVec, HistogramVec, IntGaugeVec,
4+
};
5+
6+
lazy_static::lazy_static! {
7+
pub static ref SENDER_DENIED: IntGaugeVec =
8+
register_int_gauge_vec!("tap_sender_denied", "Sender is denied", &["sender"]).unwrap();
9+
pub static ref ESCROW_BALANCE: GaugeVec = register_gauge_vec!(
10+
"tap_sender_escrow_balance_grt_total",
11+
"Sender escrow balance",
12+
&["sender"]
13+
)
14+
.unwrap();
15+
pub static ref UNAGGREGATED_FEES: GaugeVec = register_gauge_vec!(
16+
"tap_unaggregated_fees_grt_total",
17+
"Unggregated Fees value",
18+
&["sender", "allocation"]
19+
)
20+
.unwrap();
21+
pub static ref SENDER_FEE_TRACKER: GaugeVec = register_gauge_vec!(
22+
"tap_sender_fee_tracker_grt_total",
23+
"Sender fee tracker metric",
24+
&["sender"]
25+
)
26+
.unwrap();
27+
pub static ref INVALID_RECEIPT_FEES: GaugeVec = register_gauge_vec!(
28+
"tap_invalid_receipt_fees_grt_total",
29+
"Failed receipt fees",
30+
&["sender", "allocation"]
31+
)
32+
.unwrap();
33+
pub static ref PENDING_RAV: GaugeVec = register_gauge_vec!(
34+
"tap_pending_rav_grt_total",
35+
"Pending ravs values",
36+
&["sender", "allocation"]
37+
)
38+
.unwrap();
39+
pub static ref MAX_FEE_PER_SENDER: GaugeVec = register_gauge_vec!(
40+
"tap_max_fee_per_sender_grt_total",
41+
"Max fee per sender in the config",
42+
&["sender"]
43+
)
44+
.unwrap();
45+
pub static ref RAV_REQUEST_TRIGGER_VALUE: GaugeVec = register_gauge_vec!(
46+
"tap_rav_request_trigger_value",
47+
"RAV request trigger value divisor",
48+
&["sender"]
49+
)
50+
.unwrap();
51+
pub static ref RECEIPTS_CREATED: CounterVec = register_counter_vec!(
52+
"tap_receipts_received_total",
53+
"Receipts received since start of the program.",
54+
&["sender", "allocation"]
55+
)
56+
.unwrap();
57+
58+
// Allocation metrics
59+
pub static ref CLOSED_SENDER_ALLOCATIONS: CounterVec = register_counter_vec!(
60+
"tap_closed_sender_allocation_total",
61+
"Count of sender-allocation managers closed since the start of the program",
62+
&["sender"]
63+
)
64+
.unwrap();
65+
pub static ref RAVS_CREATED: CounterVec = register_counter_vec!(
66+
"tap_ravs_created_total",
67+
"RAVs updated or created per sender allocation since the start of the program",
68+
&["sender", "allocation"]
69+
)
70+
.unwrap();
71+
pub static ref RAVS_FAILED: CounterVec = register_counter_vec!(
72+
"tap_ravs_failed_total",
73+
"RAV requests failed since the start of the program",
74+
&["sender", "allocation"]
75+
)
76+
.unwrap();
77+
pub static ref RAV_RESPONSE_TIME: HistogramVec = register_histogram_vec!(
78+
"tap_rav_response_time_seconds",
79+
"RAV response time per sender",
80+
&["sender"]
81+
)
82+
.unwrap();
83+
84+
}

crates/tap-agent/src/agent/sender_account.rs

Lines changed: 29 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,48 @@
11
// Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use alloy::hex::ToHexExt;
5-
use alloy::primitives::U256;
6-
7-
use bigdecimal::num_bigint::ToBigInt;
8-
use bigdecimal::ToPrimitive;
9-
4+
use alloy::{
5+
dyn_abi::Eip712Domain,
6+
hex::ToHexExt,
7+
primitives::{Address, U256},
8+
};
9+
use bigdecimal::{num_bigint::ToBigInt, ToPrimitive};
1010
use futures::{stream, StreamExt};
11-
use indexer_query::unfinalized_transactions;
12-
use indexer_query::UnfinalizedTransactions;
11+
use indexer_monitor::{EscrowAccounts, SubgraphClient};
12+
use indexer_query::{unfinalized_transactions, UnfinalizedTransactions};
1313
use indexer_watcher::watch_pipe;
1414
use jsonrpsee::http_client::HttpClientBuilder;
15-
use prometheus::{register_gauge_vec, register_int_gauge_vec, GaugeVec, IntGaugeVec};
16-
use reqwest::Url;
17-
use state::State;
18-
use std::collections::{HashMap, HashSet};
19-
use std::str::FromStr;
20-
use std::time::Duration;
21-
use tokio::sync::watch::Receiver;
22-
23-
use alloy::dyn_abi::Eip712Domain;
24-
use alloy::primitives::Address;
25-
use indexer_monitor::{EscrowAccounts, SubgraphClient};
2615
use ractor::{Actor, ActorProcessingErr, ActorRef, SupervisionEvent};
16+
use reqwest::Url;
2717
use sqlx::PgPool;
18+
use state::State;
19+
use std::{
20+
collections::{HashMap, HashSet},
21+
str::FromStr,
22+
time::Duration,
23+
};
2824
use tap_core::rav::SignedRAV;
25+
use tokio::sync::watch::Receiver;
2926
use tracing::{error, warn, Level};
3027

31-
use crate::adaptative_concurrency::AdaptiveLimiter;
32-
use crate::agent::sender_allocation::SenderAllocationMessage;
33-
use crate::agent::unaggregated_receipts::UnaggregatedReceipts;
34-
use crate::backoff::BackoffInfo;
35-
use crate::tracker::{SenderFeeTracker, SimpleFeeTracker};
36-
use lazy_static::lazy_static;
28+
use crate::{
29+
adaptative_concurrency::AdaptiveLimiter,
30+
agent::{
31+
metrics::{
32+
ESCROW_BALANCE, INVALID_RECEIPT_FEES, MAX_FEE_PER_SENDER, PENDING_RAV,
33+
RAV_REQUEST_TRIGGER_VALUE, SENDER_DENIED, SENDER_FEE_TRACKER, UNAGGREGATED_FEES,
34+
},
35+
sender_allocation::SenderAllocationMessage,
36+
unaggregated_receipts::UnaggregatedReceipts,
37+
},
38+
backoff::BackoffInfo,
39+
tracker::{SenderFeeTracker, SimpleFeeTracker},
40+
};
3741

38-
// mod actor;
39-
// mod config;
4042
mod state;
4143
#[cfg(test)]
4244
pub mod tests;
4345

44-
lazy_static! {
45-
static ref SENDER_DENIED: IntGaugeVec =
46-
register_int_gauge_vec!("tap_sender_denied", "Sender is denied", &["sender"]).unwrap();
47-
static ref ESCROW_BALANCE: GaugeVec = register_gauge_vec!(
48-
"tap_sender_escrow_balance_grt_total",
49-
"Sender escrow balance",
50-
&["sender"]
51-
)
52-
.unwrap();
53-
static ref UNAGGREGATED_FEES: GaugeVec = register_gauge_vec!(
54-
"tap_unaggregated_fees_grt_total",
55-
"Unggregated Fees value",
56-
&["sender", "allocation"]
57-
)
58-
.unwrap();
59-
static ref SENDER_FEE_TRACKER: GaugeVec = register_gauge_vec!(
60-
"tap_sender_fee_tracker_grt_total",
61-
"Sender fee tracker metric",
62-
&["sender"]
63-
)
64-
.unwrap();
65-
static ref INVALID_RECEIPT_FEES: GaugeVec = register_gauge_vec!(
66-
"tap_invalid_receipt_fees_grt_total",
67-
"Failed receipt fees",
68-
&["sender", "allocation"]
69-
)
70-
.unwrap();
71-
static ref PENDING_RAV: GaugeVec = register_gauge_vec!(
72-
"tap_pending_rav_grt_total",
73-
"Pending ravs values",
74-
&["sender", "allocation"]
75-
)
76-
.unwrap();
77-
static ref MAX_FEE_PER_SENDER: GaugeVec = register_gauge_vec!(
78-
"tap_max_fee_per_sender_grt_total",
79-
"Max fee per sender in the config",
80-
&["sender"]
81-
)
82-
.unwrap();
83-
static ref RAV_REQUEST_TRIGGER_VALUE: GaugeVec = register_gauge_vec!(
84-
"tap_rav_request_trigger_value",
85-
"RAV request trigger value divisor",
86-
&["sender"]
87-
)
88-
.unwrap();
89-
}
90-
9146
const INITIAL_RAV_REQUEST_CONCURRENT: usize = 1;
9247

9348
type RavMap = HashMap<Address, u128>;

crates/tap-agent/src/agent/sender_account/state.rs

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,38 @@
11
// Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use alloy::hex::ToHexExt;
5-
use alloy::primitives::U256;
6-
7-
use bigdecimal::ToPrimitive;
8-
9-
use indexer_query::closed_allocations::{self, ClosedAllocations};
10-
use std::collections::HashSet;
11-
use std::str::FromStr;
12-
use std::time::Duration;
13-
use tokio::sync::watch::Receiver;
14-
use tokio::task::JoinHandle;
15-
16-
use alloy::dyn_abi::Eip712Domain;
17-
use alloy::primitives::Address;
4+
use alloy::{
5+
dyn_abi::Eip712Domain,
6+
hex::ToHexExt,
7+
primitives::{Address, U256},
8+
};
189
use anyhow::Result;
10+
use bigdecimal::ToPrimitive;
1911
use indexer_monitor::{EscrowAccounts, SubgraphClient};
12+
use indexer_query::closed_allocations::{self, ClosedAllocations};
2013
use ractor::{Actor, ActorRef, MessagingErr};
2114
use sqlx::PgPool;
15+
use std::{collections::HashSet, str::FromStr, time::Duration};
2216
use tap_core::rav::SignedRAV;
17+
use tokio::{sync::watch::Receiver, task::JoinHandle};
2318
use tracing::error;
2419

25-
use crate::adaptative_concurrency::AdaptiveLimiter;
26-
use crate::agent::sender_account::{SenderAccount, SENDER_DENIED};
27-
use crate::agent::sender_allocation::{AllocationConfig, SenderAllocationMessage};
28-
use crate::agent::sender_allocation::{SenderAllocation, SenderAllocationArgs};
29-
use crate::agent::unaggregated_receipts::UnaggregatedReceipts;
30-
use crate::backoff::BackoffInfo;
31-
use crate::tracker::{SenderFeeTracker, SimpleFeeTracker};
32-
33-
use super::{SenderAccountConfig, SenderAccountMessage, PENDING_RAV, SENDER_FEE_TRACKER, UNAGGREGATED_FEES};
20+
use crate::{
21+
adaptative_concurrency::AdaptiveLimiter,
22+
agent::{
23+
sender_account::{SenderAccount, SENDER_DENIED},
24+
sender_allocation::{
25+
AllocationConfig, SenderAllocation, SenderAllocationArgs, SenderAllocationMessage,
26+
},
27+
unaggregated_receipts::UnaggregatedReceipts,
28+
},
29+
backoff::BackoffInfo,
30+
tracker::{SenderFeeTracker, SimpleFeeTracker},
31+
};
32+
33+
use super::{
34+
SenderAccountConfig, SenderAccountMessage, PENDING_RAV, SENDER_FEE_TRACKER, UNAGGREGATED_FEES,
35+
};
3436

3537
pub struct State {
3638
pub(super) prefix: Option<String>,

crates/tap-agent/src/agent/sender_account/tests.rs

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,33 @@
1-
21
use super::{SenderAccount, SenderAccountArgs, SenderAccountMessage};
3-
use crate::agent::sender_account::ReceiptFees;
4-
use crate::agent::sender_accounts_manager::NewReceiptNotification;
5-
use crate::agent::sender_allocation::SenderAllocationMessage;
6-
use crate::agent::unaggregated_receipts::UnaggregatedReceipts;
7-
use crate::tap::test_utils::{
8-
create_rav, store_rav_with_options, ALLOCATION_ID_0, ALLOCATION_ID_1, INDEXER, SENDER, SIGNER,
9-
TAP_EIP712_DOMAIN_SEPARATOR,
2+
use crate::{
3+
agent::{
4+
sender_account::ReceiptFees, sender_accounts_manager::NewReceiptNotification,
5+
sender_allocation::SenderAllocationMessage, unaggregated_receipts::UnaggregatedReceipts,
6+
},
7+
tap::test_utils::{
8+
create_rav, store_rav_with_options, ALLOCATION_ID_0, ALLOCATION_ID_1, INDEXER, SENDER,
9+
SIGNER, TAP_EIP712_DOMAIN_SEPARATOR,
10+
},
11+
};
12+
use alloy::{
13+
hex::ToHexExt,
14+
primitives::{Address, U256},
1015
};
11-
use alloy::hex::ToHexExt;
12-
use alloy::primitives::{Address, U256};
1316
use indexer_monitor::{DeploymentDetails, EscrowAccounts, SubgraphClient};
14-
use ractor::concurrency::JoinHandle;
15-
use ractor::{call, Actor, ActorProcessingErr, ActorRef, ActorStatus};
17+
use ractor::{call, concurrency::JoinHandle, Actor, ActorProcessingErr, ActorRef, ActorStatus};
1618
use reqwest::Url;
1719
use serde_json::json;
1820
use sqlx::PgPool;
19-
use std::collections::{HashMap, HashSet};
20-
use std::sync::atomic::AtomicU32;
21-
use std::sync::{Arc, Mutex};
22-
use std::time::{Duration, SystemTime, UNIX_EPOCH};
21+
use std::{
22+
collections::{HashMap, HashSet},
23+
sync::{atomic::AtomicU32, Arc, Mutex},
24+
time::{Duration, SystemTime, UNIX_EPOCH},
25+
};
2326
use tokio::sync::watch::{self, Sender};
24-
use wiremock::matchers::{body_string_contains, method};
25-
use wiremock::{Mock, MockGuard, MockServer, ResponseTemplate};
27+
use wiremock::{
28+
matchers::{body_string_contains, method},
29+
Mock, MockGuard, MockServer, ResponseTemplate,
30+
};
2631

2732
// we implement the PartialEq and Eq traits for SenderAccountMessage to be able to compare
2833
impl Eq for SenderAccountMessage {}

crates/tap-agent/src/agent/sender_accounts_manager.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ use futures::{stream, StreamExt};
99
use indexer_allocation::Allocation;
1010
use indexer_monitor::{EscrowAccounts, SubgraphClient};
1111
use indexer_watcher::watch_pipe;
12-
use lazy_static::lazy_static;
13-
use prometheus::{register_counter_vec, CounterVec};
1412
use ractor::{Actor, ActorProcessingErr, ActorRef, SupervisionEvent};
1513
use receipt_watcher::new_receipts_watcher;
1614
use reqwest::Url;
@@ -28,15 +26,6 @@ mod state;
2826
#[cfg(test)]
2927
mod tests;
3028

31-
lazy_static! {
32-
static ref RECEIPTS_CREATED: CounterVec = register_counter_vec!(
33-
"tap_receipts_received_total",
34-
"Receipts received since start of the program.",
35-
&["sender", "allocation"]
36-
)
37-
.unwrap();
38-
}
39-
4029
#[derive(Deserialize, Debug, PartialEq, Eq)]
4130
pub struct NewReceiptNotification {
4231
pub id: u64,

crates/tap-agent/src/agent/sender_accounts_manager/receipt_watcher.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::agent::{
2-
sender_account::SenderAccountMessage, sender_accounts_manager::RECEIPTS_CREATED,
2+
metrics::RECEIPTS_CREATED, sender_account::SenderAccountMessage,
33
sender_allocation::SenderAllocationMessage,
44
};
55
use anyhow::{anyhow, bail, Result};
@@ -11,7 +11,6 @@ use tracing::{error, warn};
1111

1212
use super::NewReceiptNotification;
1313

14-
1514
/// Continuously listens for new receipt notifications from Postgres and forwards them to the
1615
/// corresponding SenderAccount.
1716
pub async fn new_receipts_watcher(

crates/tap-agent/src/agent/sender_accounts_manager/state.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
// Copyright 2023-, Edge & Node, GraphOps, and Semiotic Labs.
22
// SPDX-License-Identifier: Apache-2.0
33

4-
use std::collections::HashSet;
5-
use std::time::Duration;
6-
use std::{collections::HashMap, str::FromStr};
4+
use std::{
5+
collections::{HashMap, HashSet},
6+
str::FromStr,
7+
time::Duration,
8+
};
79

810
use crate::agent::sender_account::{SenderAccount, SenderAccountArgs, SenderAccountConfig};
9-
use alloy::dyn_abi::Eip712Domain;
10-
use alloy::primitives::Address;
11-
use anyhow::Result;
12-
use anyhow::{anyhow, bail};
11+
use alloy::{dyn_abi::Eip712Domain, primitives::Address};
12+
use anyhow::{anyhow, bail, Result};
1313
use indexer_monitor::{EscrowAccounts, SubgraphClient};
14-
use ractor::concurrency::JoinHandle;
15-
use ractor::{Actor, ActorCell};
14+
use ractor::{concurrency::JoinHandle, Actor, ActorCell};
1615
use reqwest::Url;
1716
use sqlx::PgPool;
1817
use tokio::sync::watch::Receiver;

0 commit comments

Comments
 (0)