Skip to content

Commit

Permalink
fix(metrics): contract sync metrics take home and replica labels (#210)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
luketchang authored Jul 21, 2022
1 parent 7740c33 commit db72218
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 23 deletions.
1 change: 1 addition & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ the code change.
- [ ] Added Tests
- [ ] Updated Documentation
- [ ] Updated CHANGELOG.md for the appropriate package
- [ ] Ran PR in local/dev/staging
2 changes: 2 additions & 0 deletions agents/relayer/src/relayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down
9 changes: 9 additions & 0 deletions agents/watcher/src/watcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand All @@ -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(),
Expand All @@ -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(),
Expand Down Expand Up @@ -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(),
Expand All @@ -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(),
Expand All @@ -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(),
Expand Down
1 change: 1 addition & 0 deletions nomad-base/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
18 changes: 3 additions & 15 deletions nomad-base/src/contract_sync/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand All @@ -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,
}
}
}
24 changes: 16 additions & 8 deletions nomad-base/src/contract_sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ const MESSAGES_LABEL: &str = "messages";
#[derive(Debug, Clone)]
pub struct ContractSync<I> {
agent_name: String,
contract_name: String,
home: String,
replica: String,
db: NomadDB,
indexer: Arc<I>,
index_settings: IndexSettings,
Expand All @@ -51,7 +52,8 @@ impl<I> ContractSync<I> {
#[allow(clippy::too_many_arguments)]
pub fn new(
agent_name: String,
contract_name: String,
home: String,
replica: String,
db: NomadDB,
indexer: Arc<I>,
index_settings: IndexSettings,
Expand All @@ -61,7 +63,8 @@ impl<I> ContractSync<I> {
) -> Self {
Self {
agent_name,
contract_name,
home,
replica,
db,
indexer,
index_settings,
Expand Down Expand Up @@ -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,
]);

Expand Down Expand Up @@ -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,
]);

Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions nomad-base/src/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -303,6 +304,7 @@ impl Settings {

Ok(ContractSync::new(
agent_name.to_owned(),
self.home.name.clone(),
replica_name.to_owned(),
nomad_db,
indexer,
Expand Down

0 comments on commit db72218

Please sign in to comment.