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

feat: Add metrics for user creation/deletion. #506

Merged
merged 14 commits into from
Nov 9, 2023
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ pub async fn process_existing_user(
.metrics
.incr_with_tags("ua.expiration")
.with_tag("code", "104")
.with_tag("autoconnect", "true")
jrconlin marked this conversation as resolved.
Show resolved Hide resolved
.with_tag("reason", "no_current_month")
.send();
app_state.db.remove_user(&user.uaid).await?;
return Ok(None);
Expand All @@ -311,6 +313,8 @@ pub async fn process_existing_user(
.metrics
.incr_with_tags("ua.expiration")
.with_tag("code", "105")
.with_tag("autoconnect", "true")
.with_tag("reason", "invalid_current_month")
.send();
app_state.db.remove_user(&user.uaid).await?;
return Ok(None);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,12 @@ impl WebPushClient {
let flags = &self.flags;
if flags.reset_uaid {
debug!("▶️ WebPushClient:post_process_all_acked reset_uaid");
self.app_state
.metrics
.incr_with_tags("ua.expiration")
.with_tag("autoconnect", "true")
jrconlin marked this conversation as resolved.
Show resolved Hide resolved
.with_tag("reason", "reset_uaid")
.send();
self.app_state.db.remove_user(&self.uaid).await?;
Err(SMErrorKind::UaidReset.into())
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,12 @@ impl WebPushClient {
if self.sent_from_storage > self.app_state.settings.msg_limit {
// Exceeded the max limit of stored messages: drop the user to
// trigger a re-register
self.app_state
.metrics
.incr_with_tags("ua.expiration")
.with_tag("autoconnect", "true")
jrconlin marked this conversation as resolved.
Show resolved Hide resolved
.with_tag("reason", "too_many_messages")
.send();
self.app_state.db.remove_user(&self.uaid).await?;
return Err(SMErrorKind::UaidReset.into());
}
Expand Down
14 changes: 11 additions & 3 deletions autoconnect/autoconnect-ws/autoconnect-ws-sm/src/unidentified.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,27 @@ impl UnidentifiedClient {
);

// Ignore invalid uaids (treat as None) so they'll be issued a new one
let uaid = uaid.as_deref().and_then(|uaid| Uuid::try_parse(uaid).ok());
let original_uaid = uaid.as_deref().and_then(|uaid| Uuid::try_parse(uaid).ok());

let GetOrCreateUser {
user,
existing_user,
flags,
} = self.get_or_create_user(uaid).await?;
} = self.get_or_create_user(original_uaid).await?;
let uaid = user.uaid;
debug!(
"💬UnidentifiedClient::on_client_msg Hello! uaid: {} existing_user: {}",
uaid, existing_user,
);
let _ = self.app_state.metrics.incr("ua.command.hello");
self.app_state
.metrics
.incr_with_tags("ua.command.hello")
.with_tag("existing_user", &original_uaid.is_some().to_string())
jrconlin marked this conversation as resolved.
Show resolved Hide resolved
.with_tag(
"reassigned",
&(original_uaid.unwrap_or(uaid) != uaid).to_string(),
)
.send();
jrconlin marked this conversation as resolved.
Show resolved Hide resolved

let (broadcast_subs, broadcasts) = self
.broadcast_init(&Broadcast::from_hashmap(broadcasts.unwrap_or_default()))
Expand Down