Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Introduce new module utils-prometheus #95

Merged
merged 3 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ members = [
"ethereum-common",
"gear-programs/*",
"gear-programs/checkpoint-light-client/io",
"utils-prometheus",
]

resolver = "2"
Expand All @@ -32,6 +33,7 @@ grc20_gateway = { path = "gear-programs/grc20-gateway" }
bridging_payment = { path = "gear-programs/bridging-payment" }
gear_proof_storage = { path = "gear-programs/proof-storage" }
checkpoint_light_client-io = { path = "gear-programs/checkpoint-light-client/io", default-features = false }
utils-prometheus = { path = "utils-prometheus" }

plonky2 = { git = "https://github.com/gear-tech/plonky2.git", rev = "4a620f4d79efe9233d0e7682df5a2fc625b5420e" }
plonky2_field = { git = "https://github.com/gear-tech/plonky2.git", rev = "4a620f4d79efe9233d0e7682df5a2fc625b5420e" }
Expand Down
1 change: 1 addition & 0 deletions relayer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ serde.workspace = true
serde_json.workspace = true
thiserror.workspace = true
tokio.workspace = true
utils-prometheus.workspace = true

[build-dependencies]
cgo_oligami = "0.3"
3 changes: 1 addition & 2 deletions relayer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ use pretty_env_logger::env_logger::fmt::TimestampPrecision;
use ethereum_client::EthApi;
use gear_rpc_client::GearApi;
use message_relayer::MessageRelayer;
use metrics::MetricsBuilder;
use proof_storage::{FileSystemProofStorage, GearProofStorage, ProofStorage};
use prover::proving::GenesisConfig;
use relay_merkle_roots::MerkleRootRelayer;
use utils_prometheus::MetricsBuilder;

mod message_relayer;
mod metrics;
mod proof_storage;
mod prover_interface;
mod relay_merkle_roots;
Expand Down
2 changes: 1 addition & 1 deletion relayer/src/message_relayer/event_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use parity_scale_codec::Decode;
use primitive_types::H256;
use prometheus::{IntCounter, IntGauge};

use crate::metrics::{impl_metered_service, MeteredService};
use utils_prometheus::{impl_metered_service, MeteredService};

use super::{BlockEvent, MessageInBlock};

Expand Down
2 changes: 1 addition & 1 deletion relayer/src/message_relayer/merkle_root_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use ethereum_client::EthApi;
use gear_rpc_client::GearApi;
use prometheus::IntGauge;

use crate::metrics::{impl_metered_service, MeteredService};
use utils_prometheus::{impl_metered_service, MeteredService};

use super::RelayedMerkleRoot;

Expand Down
2 changes: 1 addition & 1 deletion relayer/src/message_relayer/message_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use gear_rpc_client::{dto::Message, GearApi};
use primitive_types::H256;
use prometheus::{Gauge, IntCounter, IntGauge};

use crate::metrics::{impl_metered_service, MeteredService};
use utils_prometheus::{impl_metered_service, MeteredService};

use super::{AuthoritySetId, BlockEvent, BlockNumber, RelayedMerkleRoot};

Expand Down
2 changes: 1 addition & 1 deletion relayer/src/message_relayer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use ethereum_client::EthApi;
use gear_rpc_client::{dto::Message, GearApi};
use primitive_types::{H256, U256};

use crate::metrics::MeteredService;
use utils_prometheus::MeteredService;

mod event_listener;
mod merkle_root_listener;
Expand Down
2 changes: 1 addition & 1 deletion relayer/src/proof_storage/gear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use prometheus::Gauge;
use rand::RngCore;
use serde::{Deserialize, Serialize};

use crate::{impl_metered_service, metrics::MeteredService};
use utils_prometheus::{impl_metered_service, MeteredService};

use super::{AuthoritySetId, ProofStorage, ProofStorageError};
use prover::proving::{CircuitData, Proof, ProofWithCircuitData};
Expand Down
2 changes: 1 addition & 1 deletion relayer/src/prover_interface.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{str::FromStr, time::Instant};

use crate::metrics::MeteredService;
use utils_prometheus::MeteredService;

use super::GENESIS_CONFIG;
use gear_rpc_client::{dto, GearApi};
Expand Down
3 changes: 2 additions & 1 deletion relayer/src/relay_merkle_roots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::{
};

use crate::{
metrics::{impl_metered_service, MeteredService},
proof_storage::ProofStorage,
prover_interface::{self, FinalProof},
GENESIS_CONFIG,
Expand All @@ -14,6 +13,8 @@ use crate::{
use ethereum_client::{EthApi, TxHash, TxStatus};
use gear_rpc_client::GearApi;

use utils_prometheus::{impl_metered_service, MeteredService};

const MIN_MAIN_LOOP_DURATION: Duration = Duration::from_secs(5);

pub struct MerkleRootRelayer {
Expand Down
9 changes: 9 additions & 0 deletions utils-prometheus/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "utils-prometheus"
version.workspace = true
edition.workspace = true

[dependencies]
axum.workspace = true
prometheus.workspace = true
tokio.workspace = true
10 changes: 7 additions & 3 deletions relayer/src/metrics.rs → utils-prometheus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ pub trait MeteredService {
fn get_sources(&self) -> impl IntoIterator<Item = Box<dyn Collector>>;
}

pub use crate::impl_metered_service;

#[macro_export]
macro_rules! impl_metered_service {
(
Expand All @@ -37,7 +35,7 @@ macro_rules! impl_metered_service {
),*
}

impl $crate::metrics::MeteredService for $struct_name {
impl $crate::MeteredService for $struct_name {
fn get_sources(&self) -> impl ::core::iter::IntoIterator<
Item = ::std::boxed::Box<dyn prometheus::core::Collector>
> {
Expand Down Expand Up @@ -79,6 +77,12 @@ impl MetricsBuilder {
}
}

impl Default for MetricsBuilder {
fn default() -> Self {
Self::new()
}
}

impl Metrics {
pub async fn run(self, endpoint: String) {
let reg = self.registry.clone();
Expand Down
Loading