Skip to content

Commit fc77293

Browse files
committed
Fix dynode active node gauge
1 parent a8915c0 commit fc77293

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

core/apps/dynode/src/metrics/mod.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,16 @@ impl Metrics {
187187
.set(1);
188188
}
189189

190+
pub fn move_node_host_current(&self, chain: &str, old_host: &str, new_host: &str) {
191+
self.node_host_current
192+
.get_or_create(&HostCurrentStateLabels {
193+
chain: chain.to_string(),
194+
host: old_host.to_string(),
195+
})
196+
.set(0);
197+
self.set_node_host_current(chain, new_host);
198+
}
199+
190200
pub fn add_cache_hit(&self, chain: &str, path: &str) {
191201
let path = self.truncate_path(path);
192202
self.cache_hits.get_or_create(&CacheLabels { chain: chain.to_string(), path }).inc();
@@ -301,4 +311,16 @@ mod tests {
301311
assert!(encoded.contains("host=\"api.trongrid.io\""));
302312
assert!(encoded.contains("reason=\"status=429\""));
303313
}
314+
315+
#[test]
316+
fn moves_current_node_host() {
317+
let metrics = create_test_metrics();
318+
319+
metrics.set_node_host_current("thorchain", "thornode.ninerealms.com");
320+
metrics.move_node_host_current("thorchain", "thornode.ninerealms.com", "gateway.liquify.com");
321+
322+
let encoded = metrics.get_metrics();
323+
assert!(encoded.contains("test_node_host_current{chain=\"thorchain\",host=\"thornode.ninerealms.com\"} 0"));
324+
assert!(encoded.contains("test_node_host_current{chain=\"thorchain\",host=\"gateway.liquify.com\"} 1"));
325+
}
304326
}

core/apps/dynode/src/monitoring/service.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl NodeService {
9595
(old_host, new_host)
9696
};
9797

98-
Self::sync_current_node_metric(metrics, chain_config.chain, selected);
98+
metrics.move_node_host_current(chain_config.chain.as_ref(), &old_host, &new_host);
9999
metrics.add_node_switch(chain_config.chain.as_ref(), &old_host, &new_host, reason.as_str());
100100
Some((old_host, new_host))
101101
}

0 commit comments

Comments
 (0)