Skip to content

Commit

Permalink
bug: Add back missing metrics (#372)
Browse files Browse the repository at this point in the history
A number of metrics were accidentally dropped during the code merge and
refactor.
  • Loading branch information
jrconlin committed Apr 27, 2023
1 parent 647ffb1 commit 1952559
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
4 changes: 4 additions & 0 deletions autoendpoint/src/extractors/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ impl Notification {
message_id.encrypt(fernet)
}

pub fn has_topic(&self) -> bool {
self.headers.topic.is_some()
}

/// Serialize the notification for delivery to the connection server. Some
/// fields in `autopush_common`'s `Notification` are marked with
/// `#[serde(skip_serializing)]` so they are not shown to the UA. These
Expand Down
6 changes: 6 additions & 0 deletions autoendpoint/src/routers/webpush.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ impl Router for WebPushRouter {
);
}
Err(error) => {
if error.is_timeout() {
self.metrics.incr("error.node.timeout")?;
};
if error.is_connect() {
self.metrics.incr("error.node.connect")?;
}
debug!("Error while sending webpush notification: {}", error);
self.remove_node_id(user, node_id).await?
}
Expand Down
1 change: 0 additions & 1 deletion autoendpoint/src/routes/webpush.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ pub async fn webpush_route(
RouterType::from_str(&notification.subscription.user.router_type)
.map_err(|_| ApiErrorKind::InvalidRouterType)?,
);

Ok(router.route_notification(&notification).await?.into())
}

Expand Down
8 changes: 8 additions & 0 deletions autopush-common/src/db/dynamodb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ impl DbClient for DdbClientImpl {
}

async fn save_message(&self, uaid: &Uuid, message: Notification) -> DbResult<()> {
let topic = message.topic.is_some().to_string();
let input = PutItemInput {
item: serde_dynamodb::to_hashmap(&NotificationRecord::from_notif(uaid, message))?,
table_name: self.settings.message_table.clone(),
Expand All @@ -524,6 +525,10 @@ impl DbClient for DdbClientImpl {
)
.await?;

self.metrics
.incr_with_tags("notification.message.stored")
.with_tag("topic", &topic)
.send();
Ok(())
}

Expand All @@ -543,6 +548,9 @@ impl DbClient for DdbClientImpl {
retryable_delete_error(self.metrics.clone()),
)
.await?;
self.metrics
.incr_with_tags("notification.message.deleted")
.send();
Ok(())
}

Expand Down

0 comments on commit 1952559

Please sign in to comment.