Skip to content

Commit aa8bc71

Browse files
committed
feat: add metrics to service
Signed-off-by: Gustavo Inacio <[email protected]>
1 parent c693f0e commit aa8bc71

File tree

12 files changed

+264
-130
lines changed

12 files changed

+264
-130
lines changed

Cargo.lock

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

common/src/indexer_errors.rs

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

4+
use lazy_static::lazy_static;
5+
use prometheus::{register_int_counter_vec, IntCounterVec};
46
use std::{
57
error::Error,
68
fmt::{self, Display},
79
};
810

911
use tracing::warn;
1012

11-
use crate::metrics;
12-
1313
const ERROR_BASE_URL: &str = "https://github.com/graphprotocol/indexer/blob/main/docs/errors.md";
1414

15+
lazy_static! {
16+
/// Register indexer error metrics in Prometheus registry
17+
pub static ref INDEXER_ERROR: IntCounterVec = register_int_counter_vec!(
18+
"indexer_error",
19+
"Indexer errors observed over time",
20+
&["code"]
21+
).expect("Create indexer_error metrics");
22+
}
23+
1524
#[derive(Debug, Clone)]
1625
pub enum IndexerErrorCode {
1726
IE001,
@@ -304,9 +313,7 @@ pub struct IndexerError {
304313
impl IndexerError {
305314
// Create Indexer Error and automatically increment counter by the error code
306315
pub fn new(code: IndexerErrorCode, cause: Option<IndexerErrorCause>) -> Self {
307-
metrics::INDEXER_ERROR
308-
.with_label_values(&[&code.to_string()])
309-
.inc();
316+
INDEXER_ERROR.with_label_values(&[&code.to_string()]).inc();
310317
let explanation = code.message();
311318
warn!(
312319
"Encountered error {}: {}. Cause: {:#?}",

common/src/indexer_service/http/indexer_service.rs

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::{
66
time::Duration,
77
};
88

9+
use alloy::dyn_abi::Eip712Domain;
910
use alloy::sol_types::eip712_domain;
1011
use anyhow;
1112
use autometrics::prometheus_exporter;
@@ -33,11 +34,11 @@ use tower_governor::{governor::GovernorConfigBuilder, GovernorLayer};
3334
use tower_http::{cors, cors::CorsLayer, normalize_path::NormalizePath, trace::TraceLayer};
3435
use tracing::{info, info_span};
3536

37+
use crate::escrow_accounts::EscrowAccounts;
38+
use crate::escrow_accounts::EscrowAccountsError;
3639
use crate::{
3740
address::public_key,
38-
indexer_service::http::{
39-
metrics::IndexerServiceMetrics, static_subgraph::static_subgraph_request_handler,
40-
},
41+
indexer_service::http::static_subgraph::static_subgraph_request_handler,
4142
prelude::{
4243
attestation_signers, dispute_manager, escrow_accounts, indexer_allocations,
4344
AttestationSigner, DeploymentDetails, SubgraphClient,
@@ -98,6 +99,12 @@ where
9899
FailedToSignAttestation,
99100
#[error("Failed to query subgraph: {0}")]
100101
FailedToQueryStaticSubgraph(anyhow::Error),
102+
103+
#[error("Could not decode signer: {0}")]
104+
CouldNotDecodeSigner(tap_core::Error),
105+
106+
#[error("There was an error while accessing escrow account: {0}")]
107+
EscrowAccount(EscrowAccountsError),
101108
}
102109

103110
impl<E> IntoResponse for IndexerServiceError<E>
@@ -122,6 +129,8 @@ where
122129
ReceiptError(_)
123130
| InvalidRequest(_)
124131
| InvalidFreeQueryAuthToken
132+
| CouldNotDecodeSigner(_)
133+
| EscrowAccount(_)
125134
| ProcessingError(_) => StatusCode::BAD_REQUEST,
126135

127136
FailedToQueryStaticSubgraph(_) => StatusCode::INTERNAL_SERVER_ERROR,
@@ -166,7 +175,6 @@ where
166175
pub config: IndexerServiceConfig,
167176
pub release: IndexerServiceRelease,
168177
pub url_namespace: &'static str,
169-
pub metrics_prefix: &'static str,
170178
pub extra_routes: Router<Arc<IndexerServiceState<I>>>,
171179
}
172180

@@ -178,7 +186,10 @@ where
178186
pub attestation_signers: Eventual<HashMap<Address, AttestationSigner>>,
179187
pub tap_manager: Manager<IndexerTapContext>,
180188
pub service_impl: Arc<I>,
181-
pub metrics: IndexerServiceMetrics,
189+
190+
// tap
191+
pub escrow_accounts: Eventual<EscrowAccounts>,
192+
pub domain_separator: Eip712Domain,
182193
}
183194

184195
pub struct IndexerService {}
@@ -188,8 +199,6 @@ impl IndexerService {
188199
where
189200
I: IndexerServiceImpl + Sync + Send + 'static,
190201
{
191-
let metrics = IndexerServiceMetrics::new(options.metrics_prefix);
192-
193202
let http_client = reqwest::Client::builder()
194203
.tcp_nodelay(true)
195204
.timeout(Duration::from_secs(30))
@@ -299,21 +308,26 @@ impl IndexerService {
299308
let checks = IndexerTapContext::get_checks(
300309
database,
301310
allocations,
302-
escrow_accounts,
311+
escrow_accounts.clone(),
303312
domain_separator.clone(),
304313
timestamp_error_tolerance,
305314
receipt_max_value,
306315
)
307316
.await;
308317

309-
let tap_manager = Manager::new(domain_separator, indexer_context, CheckList::new(checks));
318+
let tap_manager = Manager::new(
319+
domain_separator.clone(),
320+
indexer_context,
321+
CheckList::new(checks),
322+
);
310323

311324
let state = Arc::new(IndexerServiceState {
312325
config: options.config.clone(),
313326
attestation_signers,
314327
tap_manager,
315328
service_impl: Arc::new(options.service_impl),
316-
metrics,
329+
escrow_accounts,
330+
domain_separator,
317331
});
318332

319333
// Rate limits by allowing bursts of 10 requests and requiring 100ms of

common/src/indexer_service/http/metrics.rs

Lines changed: 0 additions & 37 deletions
This file was deleted.

common/src/indexer_service/http/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
mod config;
55
mod indexer_service;
6-
mod metrics;
76
mod request_handler;
87
mod static_subgraph;
98
mod tap_receipt_header;

0 commit comments

Comments
 (0)