Skip to content

Commit

Permalink
refactor: remove helper methods from Metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
link2xt committed Apr 17, 2024
1 parent 1365364 commit 4739f3e
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 18 deletions.
15 changes: 0 additions & 15 deletions src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,6 @@ impl Metrics {
heartbeat_token_count,
}
}

/// Counts direct notification.
pub fn inc_direct_notification(&self) {
self.direct_notifications_total.inc();
}

/// Counts heartbeat notification.
pub fn inc_heartbeat_notification(&self) {
self.heartbeat_notifications_total.inc();
}

/// Sets number of tokens registered for heartbeat notifications.
pub fn set_heartbeat_token_count(&self, value: usize) {
self.heartbeat_token_count.set(value as i64);
}
}

type State = Arc<Metrics>;
Expand Down
4 changes: 2 additions & 2 deletions src/notifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async fn wakeup(
.collect::<Vec<_>>();

info!("sending notifications to {} devices", tokens.len());
metrics.set_heartbeat_token_count(tokens.len());
metrics.heartbeat_token_count.set(tokens.len() as i64);

for key_device_token in tokens {
info!("notify: {}", key_device_token);
Expand Down Expand Up @@ -82,7 +82,7 @@ async fn wakeup(
Ok(res) => match res.code {
200 => {
info!("delivered notification for {}", device_token);
metrics.inc_heartbeat_notification();
metrics.heartbeat_notifications_total.inc();
}
_ => {
warn!("unexpected status: {:?}", res);
Expand Down
2 changes: 1 addition & 1 deletion src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ async fn notify_device(mut req: tide::Request<State>) -> tide::Result<tide::Resp
match res.code {
200 => {
info!("delivered notification for {}", device_token);
req.state().metrics().inc_direct_notification();
req.state().metrics().direct_notifications_total.inc();
}
_ => {
warn!("unexpected status: {:?}", res);
Expand Down

0 comments on commit 4739f3e

Please sign in to comment.