Skip to content

Commit

Permalink
Merge pull request #13 from supernovahs/supernovahs/metrics
Browse files Browse the repository at this point in the history
feat(metrics)
  • Loading branch information
supernovahs authored Jun 14, 2024
2 parents e700fa2 + ccb530c commit 0b7058d
Show file tree
Hide file tree
Showing 17 changed files with 1,320 additions and 42 deletions.
363 changes: 356 additions & 7 deletions Cargo.lock

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ members = [ "crates/chainio/clients/avsregistry/",
"crates/metrics/collectors/rpc_calls/",
"crates/services/avsregistry/",
"crates/services/bls_aggregation/",
"crates/metrics/metrics-derive",
"crates/services/operatorsinfo/",
"crates/types/",
"crates/metrics/",
Expand Down Expand Up @@ -41,9 +42,14 @@ rustdoc.all = "warn"


[workspace.dependencies]
metrics-exporter-prometheus = "0.12.0"
ethers = "2.0.14"
ark-ff = "0.4.0"
eyre = "0.6.12"
syn = "2.0"
quote = "1.0"
metrics = "0.21.1"
once_cell = "1.17"
reqwest = "0.12.4"
reth = {git = "https://github.com/paradigmxyz/reth"}
prometheus-client = "0.22.2"
Expand All @@ -65,11 +71,14 @@ eigen-metrics-collectors-rpc-calls = {path = "crates/metrics/collectors/rpc_call
eigen-services-avsregistry = {path = "crates/services/avsregistry"}
eigen-services-bls_aggregation = {path = "crates/services/bls_aggregation"}
eigen-services-operatorsinfo = {path = "crates/services/operatorsinfo"}
eigen-metrics-derive = {path = "crates/metrics/metrics-derive"}
info-operator-service = {path = "examples/info-operator-service"}
tokio = {version = "1.37.0" , features = ["test-util", "full","sync"] }
futures-util = "0.3.30"
thiserror = "1.0"
tracing = "0.1.40"
hyper = "0.14.25"


#misc
parking_lot = "0.12"
Expand Down
2 changes: 1 addition & 1 deletion crates/chainio/clients/eth/src/instrumented_client.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use eigen_metrics_collectors_rpc_calls::Collector as RpcCallsCollector;
use eigen_metrics_collectors_rpc_calls::RpcCalls as RpcCallsCollector;
use ethers::providers::{Http, Middleware, Provider};

pub struct InstrumentedClient {
Expand Down
16 changes: 15 additions & 1 deletion crates/metrics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,18 @@ repository.workspace = true
ark-bn254 = "0.4.0"
ark-ff.workspace = true
eigen-crypto-bls.workspace = true
eigen-crypto-bn254.workspace = true
eigen-crypto-bn254.workspace = true
eigen-metrics-derive.workspace = true
metrics.workspace = true

#prometheus
prometheus = "0.13.4"
metrics-exporter-prometheus.workspace = true
eigen-metrics-collectors-economic.workspace = true
reqwest = "0.12.4"
eyre.workspace = true

#http
hyper.workspace = true

tokio.workspace = true
5 changes: 4 additions & 1 deletion crates/metrics/collectors/economic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ repository.workspace = true
ethers.workspace = true
eigen-client-elcontracts.workspace = true
eigen-client-avsregistry.workspace = true
alloy-primitives.workspace = true
alloy-primitives.workspace = true
eigen-metrics-derive.workspace = true
metrics.workspace = true
metrics-process = "=1.0.14"
61 changes: 33 additions & 28 deletions crates/metrics/collectors/economic/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,36 +1,41 @@
use alloy_primitives::{Address, U256};
use eigen_client_avsregistry::reader::AvsRegistryChainReader;
use eigen_client_elcontracts::reader::ELChainReader;
use std::collections::HashMap;
use eigen_metrics_derive::Metrics;
use metrics::{Gauge, Key, Label};

pub struct Collector {
elreader: ELChainReader,
avs_registry_reader: AvsRegistryChainReader,
operator_addr: Address,
operator_id: [u8; 32],
quorum_names: HashMap<u8, String>,
#[derive(Clone, Metrics)]
#[metrics(scope = "eigen.registeredstakes")]
pub struct RegisteredStakes {
#[metric(
rename = "eigen_registered_stakes",
describe = " A gauge with weighted delegation of delegated shares in delegation manager contract "
)]
registered_stake: Gauge,
}

impl Collector {
pub fn new(
elreader: ELChainReader,
avs_registry_reader: AvsRegistryChainReader,
operator_addr: Address,
operator_id: [u8; 32],
quorum_names: HashMap<u8, String>,
) -> Self {
Self {
elreader,
avs_registry_reader,
operator_addr,
operator_id,
quorum_names,
}
impl RegisteredStakes {
pub fn new() -> Self {
let gauge = Self {
registered_stake: metrics::register_gauge!("eigen_registered_stakes"),
};
RegisteredStakes::describe();

gauge
}

pub fn describe(&self) {}
pub fn set_stake(&self, quorum_number: &str, quorum_name: &str, value: f64) {
// Create the metric key with dynamic labels
let key = Key::from_parts(
"eigen_registered_stakes",
vec![
Label::new("quorum_number", quorum_number.to_string()),
Label::new("quorum_name", quorum_name.to_string()),
],
);

pub fn init_operator_id(&self) {}
// Register or retrieve the gauge with the specified key and set the value
metrics::gauge!(key.to_string(), value);
}

pub fn collect(&self) {}
pub fn registered_stakes(&self) -> Gauge {
self.registered_stake.clone()
}
}
3 changes: 2 additions & 1 deletion crates/metrics/collectors/rpc_calls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ rust-version.workspace = true
repository.workspace = true

[dependencies]
ethers.workspace = true
eigen-metrics-derive.workspace = true
metrics.workspace = true
75 changes: 74 additions & 1 deletion crates/metrics/collectors/rpc_calls/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,74 @@
pub struct Collector {}
use eigen_metrics_derive::Metrics;
use metrics::{Counter, Histogram, Key, Label};

#[derive(Clone, Metrics)]
#[metrics(scope = "eigen.rpcmetrics")]
pub struct RpcCalls {
#[metric(
rename = "eigen_rpc_request_duration_seconds",
describe = " Duration of json-rpc <method> in seconds from Ethereum Execution client <client> "
)]
rpc_request_duration_seconds: Histogram,
#[metric(
rename = "eigen_rpc_request_total",
describe = "Total of json-rpc <method> requests from Ethereum Execution client <client> "
)]
rpc_request_total: Counter,
}

impl RpcCalls {
pub fn new() -> Self {
let rpc_calls = Self {
rpc_request_duration_seconds: metrics::register_histogram!(
"eigen_rpc_request_duration_seconds"
),
rpc_request_total: metrics::register_counter!("eigen_rpc_request_total"),
};

RpcCalls::describe();

rpc_calls
}

pub fn rpc_request_duration_seconds(&self) -> Histogram {
self.rpc_request_duration_seconds.clone()
}

pub fn rpc_request_total(&self) -> Counter {
self.rpc_request_total.clone()
}

pub fn set_rpc_request_duration_seconds(
&self,
method: &str,
client_version: &str,
duration: f64,
) {
let key = Key::from_parts(
"eigen_rpc_request_duration_seconds",
vec![
Label::new("method", method.to_string()),
Label::new("client_version", client_version.to_string()),
],
);

metrics::histogram!(key.to_string(), duration);
}

pub fn set_rpc_request_total(
&self,
method: &str,
client_version: &str,
rpc_request_total: u64,
) {
let key = Key::from_parts(
"eigen_rpc_request_total",
vec![
Label::new("method", method.to_string()),
Label::new("client_version", client_version.to_string()),
],
);

metrics::counter!(key.to_string(), rpc_request_total);
}
}
26 changes: 26 additions & 0 deletions crates/metrics/metrics-derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[package]
name = "eigen-metrics-derive"
version.workspace = true
edition.workspace = true
rust-version.workspace = true
repository.workspace = true


[lib]
proc-macro = true

[dependencies]

#prometheus
prometheus = "0.13.4"

proc-macro2 = "1.0"

syn = { workspace = true, features = ["extra-traits"] }
quote.workspace = true
regex = "1.6.0"
once_cell.workspace = true

[dev-dependencies]
metrics.workspace = true
trybuild = "1.0"
Loading

0 comments on commit 0b7058d

Please sign in to comment.