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

chore: more logging #250

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
114 changes: 61 additions & 53 deletions src/handlers/push_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
},
serde::{Deserialize, Serialize},
std::sync::Arc,
tracing::instrument,
};

#[derive(Serialize, Deserialize, Debug, Clone, Eq, PartialEq)]
Expand Down Expand Up @@ -66,6 +67,8 @@
let inner_packed = match res {
Ok((res, analytics_options_inner)) => (res.status().as_u16(), res, analytics_options_inner),
Err((error, analytics_option_inner)) => {
warn!("error handling push message: {error:?}");

#[cfg(feature = "analytics")]
let error_str = format!("{:?}", &error);
let res = error.into_response();
Expand Down Expand Up @@ -129,6 +132,7 @@
Ok(response)
}

#[instrument(skip_all, fields(tenant_id, client_id = id, id = body.id))]
pub async fn handler_internal(
Path((tenant_id, id)): Path<(String, String)>,
StateExtractor(state): StateExtractor<Arc<AppState>>,
Expand Down Expand Up @@ -235,7 +239,7 @@
return Err((Error::MissmatchedTenantId, analytics));
}

return Err((Error::MissmatchedTenantId, None));

Check warning on line 242 in src/handlers/push_message.rs

View workflow job for this annotation

GitHub Actions / [ubuntu-latest/rust-stable] Clippy

unreachable statement

Check warning on line 242 in src/handlers/push_message.rs

View workflow job for this annotation

GitHub Actions / [ubuntu-latest/rust-stable] Unit Tests

unreachable statement
}
}

Expand Down Expand Up @@ -340,6 +344,7 @@
);

if tenant.suspended {
warn!("tenant suspended");
return Err((Error::TenantSuspended, analytics.clone()));
}

Expand All @@ -357,60 +362,63 @@

match provider.send_notification(client.token, body.payload).await {
Ok(()) => Ok(()),
Err(error) => match error {
Error::BadDeviceToken => {
state
.client_store
.delete_client(&tenant_id, &id)
.await
.map_err(|e| (Error::Store(e), analytics.clone()))?;
increment_counter!(state.metrics, client_suspensions);
warn!(
%request_id,
%tenant_id,
client_id = %id,
notification_id = %notification.id,
push_type = client.push_type.as_str(),
"client has been deleted due to a bad device token"
);
Err(Error::ClientDeleted)
}
Error::BadApnsCredentials => {
state
.tenant_store
.suspend_tenant(&tenant_id, "Invalid APNS Credentials")
.await
.map_err(|e| (e, analytics.clone()))?;
increment_counter!(state.metrics, tenant_suspensions);
warn!(
%request_id,
%tenant_id,
client_id = %id,
notification_id = %notification.id,
push_type = client.push_type.as_str(),
"tenant has been suspended due to invalid provider credentials"
);
Err(Error::TenantSuspended)
}
Error::BadFcmApiKey => {
state
.tenant_store
.suspend_tenant(&tenant_id, "Invalid FCM Credentials")
.await
.map_err(|e| (e, analytics.clone()))?;
increment_counter!(state.metrics, tenant_suspensions);
warn!(
%request_id,
%tenant_id,
client_id = %id,
notification_id = %notification.id,
push_type = client.push_type.as_str(),
"tenant has been suspended due to invalid provider credentials"
);
Err(Error::TenantSuspended)
Err(error) => {
warn!("error sending notification: {error:?}");
match error {
Error::BadDeviceToken => {
state
.client_store
.delete_client(&tenant_id, &id)
.await
.map_err(|e| (Error::Store(e), analytics.clone()))?;
increment_counter!(state.metrics, client_suspensions);
warn!(
%request_id,
%tenant_id,
client_id = %id,
notification_id = %notification.id,
push_type = client.push_type.as_str(),
"client has been deleted due to a bad device token"
);
Err(Error::ClientDeleted)
}
Error::BadApnsCredentials => {
state
.tenant_store
.suspend_tenant(&tenant_id, "Invalid APNS Credentials")
.await
.map_err(|e| (e, analytics.clone()))?;
increment_counter!(state.metrics, tenant_suspensions);
warn!(
%request_id,
%tenant_id,
client_id = %id,
notification_id = %notification.id,
push_type = client.push_type.as_str(),
"tenant has been suspended due to invalid provider credentials"
);
Err(Error::TenantSuspended)
}
Error::BadFcmApiKey => {
state
.tenant_store
.suspend_tenant(&tenant_id, "Invalid FCM Credentials")
.await
.map_err(|e| (e, analytics.clone()))?;
increment_counter!(state.metrics, tenant_suspensions);
warn!(
%request_id,
%tenant_id,
client_id = %id,
notification_id = %notification.id,
push_type = client.push_type.as_str(),
"tenant has been suspended due to invalid provider credentials"
);
Err(Error::TenantSuspended)
}
e => Err(e),
}
e => Err(e),
},
}
}
.map_err(|e| (e, analytics.clone()))?;

Expand Down Expand Up @@ -441,5 +449,5 @@
return Ok(((StatusCode::ACCEPTED).into_response(), analytics));
}

Ok(((StatusCode::ACCEPTED).into_response(), None))

Check warning on line 452 in src/handlers/push_message.rs

View workflow job for this annotation

GitHub Actions / [ubuntu-latest/rust-stable] Clippy

unreachable expression

Check warning on line 452 in src/handlers/push_message.rs

View workflow job for this annotation

GitHub Actions / [ubuntu-latest/rust-stable] Unit Tests

unreachable expression
}
2 changes: 1 addition & 1 deletion src/providers/noop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ impl PushProvider for NoopProvider {
impl NoopProvider {
/// Insert empty notifications for a new token
fn bootstrap(&mut self, token: String) {
self.notifications.entry(token).or_insert_with(Vec::new);
self.notifications.entry(token).or_default();
}
}
Loading