Skip to content

Commit fdc0a6d

Browse files
authored
add chain-id (#14)
1 parent 54fa132 commit fdc0a6d

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

src/config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ pub struct AppConfig {
55
#[clap(short, long, value_parser, num_args = 1.., value_delimiter = ',')]
66
pub cometbft_urls: Vec<String>,
77

8+
#[clap(long, env)]
9+
pub chain_id: String,
10+
811
#[clap(long, env)]
912
pub slack_token: Option<String>,
1013

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ async fn main() -> anyhow::Result<()> {
4747
let state = Arc::new(RwLock::new(State::new(
4848
checksums,
4949
config.initial_block_height,
50+
config.chain_id
5051
)));
5152
let unlocked_state = state.read().await;
5253
let registry = unlocked_state.prometheus_registry();

src/state.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::num::NonZeroUsize;
1+
use std::{collections::HashMap, num::NonZeroUsize};
22

33
use lru::LruCache;
44
use prometheus_exporter::prometheus::{
@@ -19,6 +19,7 @@ pub struct State {
1919
pub checksums: Checksums,
2020
pub blocks: LruCache<Height, Block>,
2121
pub metrics: PrometheusMetrics,
22+
pub chain_id: String,
2223
}
2324

2425
#[derive(Debug, Clone)]
@@ -35,15 +36,13 @@ pub struct PrometheusMetrics {
3536
registry: Registry,
3637
}
3738

38-
impl Default for PrometheusMetrics {
39-
fn default() -> Self {
40-
Self::new()
41-
}
42-
}
43-
4439
impl PrometheusMetrics {
45-
pub fn new() -> Self {
46-
let registry = Registry::new_custom(None, None).expect("Failed to create registry");
40+
pub fn new(chain_id: String) -> Self {
41+
let registry = Registry::new_custom(
42+
Some("namada".to_string()),
43+
Some(HashMap::from_iter([("chain_id".to_string(), chain_id)])),
44+
)
45+
.expect("Failed to create registry");
4746

4847
let block_height_counter =
4948
GenericCounter::<AtomicU64>::new("block_height", "the latest block height recorded")
@@ -144,14 +143,15 @@ impl PrometheusMetrics {
144143
}
145144

146145
impl State {
147-
pub fn new(checksums: Checksums, block_height: u64) -> Self {
146+
pub fn new(checksums: Checksums, block_height: u64, chain_id: String) -> Self {
148147
Self {
149148
latest_block_height: Some(block_height),
150149
latest_epoch: None,
151150
latest_total_supply_native: None,
152151
checksums,
153152
blocks: LruCache::new(NonZeroUsize::new(1024).unwrap()),
154-
metrics: PrometheusMetrics::new(),
153+
metrics: PrometheusMetrics::new(chain_id.clone()),
154+
chain_id,
155155
}
156156
}
157157

0 commit comments

Comments
 (0)