Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: Add back missing metrics #372

Merged
merged 8 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
7 changes: 5 additions & 2 deletions autoendpoint/src/routes/webpush.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ use crate::extractors::routers::{RouterType, Routers};
use crate::server::AppState;
use actix_web::web::Data;
use actix_web::HttpResponse;
use cadence::CountedExt;

/// Handle the `POST /wpush/{api_version}/{token}` and `POST /wpush/{token}` routes
pub async fn webpush_route(
notification: Notification,
routers: Routers,
_app_state: Data<AppState>,
app_state: Data<AppState>,
) -> ApiResult<HttpResponse> {
// TODO:
sentry::configure_scope(|scope| {
Expand All @@ -25,7 +26,9 @@ pub async fn webpush_route(
RouterType::from_str(&notification.subscription.user.router_type)
.map_err(|_| ApiErrorKind::InvalidRouterType)?,
);

if notification.has_topic() {
app_state.metrics.incr("ua.notification.topic")?;
}
jrconlin marked this conversation as resolved.
Show resolved Hide resolved
Ok(router.route_notification(&notification).await?.into())
}

Expand Down
11 changes: 11 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.clone();
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,13 @@ impl DbClient for DdbClientImpl {
)
.await?;

let metric = self.metrics.incr_with_tags("notification.message.stored");
if let Some(topic) = topic {
metric.with_tag("topic", topic.as_str()).send();
} else {
metric.send();
}

jrconlin marked this conversation as resolved.
Show resolved Hide resolved
Ok(())
}

Expand All @@ -543,6 +551,9 @@ impl DbClient for DdbClientImpl {
retryable_delete_error(self.metrics.clone()),
)
.await?;
self.metrics
.incr_with_tags("notification.message.removed")
jrconlin marked this conversation as resolved.
Show resolved Hide resolved
.send();
Ok(())
}

Expand Down