From db72218df5161dd49ef232ae271d9555635d70ee Mon Sep 17 00:00:00 2001 From: Luke Tchang Date: Thu, 21 Jul 2022 11:15:55 -0400 Subject: [PATCH] fix(metrics): contract sync metrics take home and replica labels (#210) * fix(metrics): contract sync metrics take home and remote labels * chore(changelog): bump * fix(metrics): replica not remote * feat(template): add check for running PR in test env to PR template --- .github/pull_request_template.md | 1 + agents/relayer/src/relayer.rs | 2 ++ agents/watcher/src/watcher.rs | 9 +++++++++ nomad-base/CHANGELOG.md | 1 + nomad-base/src/contract_sync/metrics.rs | 18 +++--------------- nomad-base/src/contract_sync/mod.rs | 24 ++++++++++++++++-------- nomad-base/src/settings/mod.rs | 2 ++ 7 files changed, 34 insertions(+), 23 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index beda8397..89b70b81 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -29,3 +29,4 @@ the code change. - [ ] Added Tests - [ ] Updated Documentation - [ ] Updated CHANGELOG.md for the appropriate package +- [ ] Ran PR in local/dev/staging diff --git a/agents/relayer/src/relayer.rs b/agents/relayer/src/relayer.rs index f773e630..cfd10015 100644 --- a/agents/relayer/src/relayer.rs +++ b/agents/relayer/src/relayer.rs @@ -232,6 +232,7 @@ mod test { let home_sync = ContractSync::new( AGENT_NAME.to_owned(), "home_1".to_owned(), + "replica_1".to_owned(), home_db.clone(), home_indexer.clone(), IndexSettings::default(), @@ -273,6 +274,7 @@ mod test { let replica_db = NomadDB::new("replica_1", db.clone()); let replica_sync = ContractSync::new( AGENT_NAME.to_owned(), + "home_1".to_owned(), "replica_1".to_owned(), replica_db.clone(), replica_indexer.clone(), diff --git a/agents/watcher/src/watcher.rs b/agents/watcher/src/watcher.rs index 3fb0067e..0ef19709 100644 --- a/agents/watcher/src/watcher.rs +++ b/agents/watcher/src/watcher.rs @@ -741,6 +741,7 @@ mod test { let home_sync = ContractSync::new( AGENT_NAME.to_owned(), "home_1".to_owned(), + "replica_1".to_owned(), nomad_db.clone(), home_indexer.clone(), IndexSettings::default(), @@ -836,6 +837,7 @@ mod test { let home_sync = ContractSync::new( AGENT_NAME.to_owned(), "home_1".to_owned(), + "replica_1".to_owned(), nomad_db.clone(), home_indexer.clone(), IndexSettings::default(), @@ -938,6 +940,7 @@ mod test { let home_sync = ContractSync::new( AGENT_NAME.to_owned(), "home_1".to_owned(), + "replica_1".to_owned(), nomad_db.clone(), home_indexer, IndexSettings::default(), @@ -1147,6 +1150,7 @@ mod test { let home_sync = ContractSync::new( AGENT_NAME.to_owned(), "home_1".to_owned(), + "replica_1".to_owned(), home_db.clone(), home_indexer.clone(), IndexSettings::default(), @@ -1157,6 +1161,7 @@ mod test { let replica_1_sync = ContractSync::new( AGENT_NAME.to_owned(), "replica_1".to_owned(), + "replica_1".to_owned(), replica_1_db.clone(), replica_indexer.clone(), IndexSettings::default(), @@ -1166,6 +1171,7 @@ mod test { ); let replica_2_sync = ContractSync::new( AGENT_NAME.to_owned(), + "home_2".to_owned(), "replica_2".to_owned(), replica_2_db.clone(), replica_indexer.clone(), @@ -1340,6 +1346,7 @@ mod test { let home_sync = ContractSync::new( AGENT_NAME.to_owned(), "home_1".to_owned(), + "replica_1".to_owned(), home_db.clone(), home_indexer.clone(), IndexSettings::default(), @@ -1349,6 +1356,7 @@ mod test { ); let replica_1_sync = ContractSync::new( AGENT_NAME.to_owned(), + "home_1".to_owned(), "replica_1".to_owned(), replica_1_db.clone(), replica_indexer.clone(), @@ -1359,6 +1367,7 @@ mod test { ); let replica_2_sync = ContractSync::new( AGENT_NAME.to_owned(), + "home_2".to_owned(), "replica_2".to_owned(), replica_2_db.clone(), replica_indexer.clone(), diff --git a/nomad-base/CHANGELOG.md b/nomad-base/CHANGELOG.md index c93429f2..992b4e97 100644 --- a/nomad-base/CHANGELOG.md +++ b/nomad-base/CHANGELOG.md @@ -2,6 +2,7 @@ ### Unreleased +- add home and remote labels to contract sync metrics for event differentiation - add `CONFIG_URL` check to `decl_settings` to optionally fetch config from a remote url - bug: add checks for empty replica name arrays in `NomadAgent::run_many` and `NomadAgent::run_all` diff --git a/nomad-base/src/contract_sync/metrics.rs b/nomad-base/src/contract_sync/metrics.rs index 36054f2e..63ce2b18 100644 --- a/nomad-base/src/contract_sync/metrics.rs +++ b/nomad-base/src/contract_sync/metrics.rs @@ -12,9 +12,6 @@ pub struct ContractSyncMetrics { pub store_event_latency: HistogramVec, /// Events stored into DB (label values differentiate updates vs. messages) pub stored_events: IntGaugeVec, - /// Unique occasions when agent missed an event (label values - /// differentiate updates vs. messages) - pub missed_events: IntGaugeVec, } impl ContractSyncMetrics { @@ -24,14 +21,14 @@ impl ContractSyncMetrics { .new_int_gauge_vec( "contract_sync_block_height", "Height of a recently observed block", - &["data_type", "contract_name", "agent"], + &["data_type", "home", "replica", "agent"], ) .expect("failed to register block_height metric"); let store_event_latency = metrics .new_histogram( "contract_sync_store_event_latency", "Latency between event emit and event store in db.", - &["data_type", "contract_name", "agent"], + &["data_type", "home", "replica", "agent"], &[ 0.0, 10.0, 20.0, 30.0, 40.0, 50.0, 60.0, 70.0, 80.0, 90.0, 100.0, 120.0, 140.0, 160.0, 180.0, 200.0, 250.0, 300.0, 350.0, 400.0, 450.0, 500.0, 1000.0, 2000.0, @@ -43,23 +40,14 @@ impl ContractSyncMetrics { .new_int_gauge_vec( "contract_sync_stored_events", "Number of events stored into db", - &["data_type", "contract_name", "agent"], + &["data_type", "home", "replica", "agent"], ) .expect("failed to register stored_events metric"); - let missed_events = metrics - .new_int_gauge_vec( - "contract_sync_missed_events", - "Number of unique occasions when agent missed an event", - &["data_type", "contract_name", "agent"], - ) - .expect("failed to register missed_events metric"); - ContractSyncMetrics { indexed_height, store_event_latency, stored_events, - missed_events, } } } diff --git a/nomad-base/src/contract_sync/mod.rs b/nomad-base/src/contract_sync/mod.rs index e49e10e3..f72a1ea3 100644 --- a/nomad-base/src/contract_sync/mod.rs +++ b/nomad-base/src/contract_sync/mod.rs @@ -28,7 +28,8 @@ const MESSAGES_LABEL: &str = "messages"; #[derive(Debug, Clone)] pub struct ContractSync { agent_name: String, - contract_name: String, + home: String, + replica: String, db: NomadDB, indexer: Arc, index_settings: IndexSettings, @@ -51,7 +52,8 @@ impl ContractSync { #[allow(clippy::too_many_arguments)] pub fn new( agent_name: String, - contract_name: String, + home: String, + replica: String, db: NomadDB, indexer: Arc, index_settings: IndexSettings, @@ -61,7 +63,8 @@ impl ContractSync { ) -> Self { Self { agent_name, - contract_name, + home, + replica, db, indexer, index_settings, @@ -93,18 +96,20 @@ where let indexer = self.indexer.clone(); let indexed_height = self.metrics.indexed_height.with_label_values(&[ UPDATES_LABEL, - &self.contract_name, + &self.home, + &self.replica, &self.agent_name, ]); let store_update_latency = self .metrics .store_event_latency .clone() - .with_label_values(&[UPDATES_LABEL, &self.contract_name, &self.agent_name]); + .with_label_values(&[UPDATES_LABEL, &self.home, &self.replica, &self.agent_name]); let stored_updates = self.metrics.stored_events.with_label_values(&[ UPDATES_LABEL, - &self.contract_name, + &self.home, + &self.replica, &self.agent_name, ]); @@ -247,13 +252,15 @@ where let indexer = self.indexer.clone(); let indexed_height = self.metrics.indexed_height.with_label_values(&[ MESSAGES_LABEL, - &self.contract_name, + &self.home, + &self.replica, &self.agent_name, ]); let stored_messages = self.metrics.stored_events.with_label_values(&[ MESSAGES_LABEL, - &self.contract_name, + &self.home, + &self.replica, &self.agent_name, ]); @@ -535,6 +542,7 @@ mod test { let contract_sync = ContractSync::new( "agent".to_owned(), "home_1".to_owned(), + "replica_1".to_owned(), nomad_db.clone(), indexer.clone(), index_settings, diff --git a/nomad-base/src/settings/mod.rs b/nomad-base/src/settings/mod.rs index 0c3317a4..9e46a35d 100644 --- a/nomad-base/src/settings/mod.rs +++ b/nomad-base/src/settings/mod.rs @@ -249,6 +249,7 @@ impl Settings { Ok(ContractSync::new( agent_name.to_owned(), home_name.to_owned(), + home_name.to_owned(), nomad_db, indexer, index_settings, @@ -303,6 +304,7 @@ impl Settings { Ok(ContractSync::new( agent_name.to_owned(), + self.home.name.clone(), replica_name.to_owned(), nomad_db, indexer,