From 0c81ffe8b70bcfdf1714f54e6a8cf50881ba0c2e Mon Sep 17 00:00:00 2001 From: ravi-signal <99042880+ravi-signal@users.noreply.github.com> Date: Mon, 8 Jul 2024 14:27:48 -0500 Subject: [PATCH] Count unregistered APNS tokens with a recent update --- .../textsecuregcm/push/PushNotificationManager.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/push/PushNotificationManager.java b/service/src/main/java/org/whispersystems/textsecuregcm/push/PushNotificationManager.java index 83f540773..e5b61fe84 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/push/PushNotificationManager.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/push/PushNotificationManager.java @@ -32,6 +32,7 @@ public class PushNotificationManager { private static final String SENT_NOTIFICATION_COUNTER_NAME = name(PushNotificationManager.class, "sentPushNotification"); private static final String FAILED_NOTIFICATION_COUNTER_NAME = name(PushNotificationManager.class, "failedPushNotification"); + private static final String DEVICE_TOKEN_UNREGISTERED_COUNTER_NAME = name(PushNotificationManager.class, "deviceTokenUnregistered"); private static final Logger logger = LoggerFactory.getLogger(PushNotificationManager.class); @@ -136,6 +137,7 @@ public class PushNotificationManager { handleDeviceUnregistered(pushNotification.destination(), pushNotification.destinationDevice(), pushNotification.tokenType(), + result.errorCode(), result.unregisteredTimestamp()); } @@ -173,6 +175,7 @@ public class PushNotificationManager { private void handleDeviceUnregistered(final Account account, final Device device, final PushNotification.TokenType tokenType, + final Optional maybeErrorCode, final Optional maybeTokenInvalidationTimestamp) { final boolean tokenExpired = maybeTokenInvalidationTimestamp.map(tokenInvalidationTimestamp -> @@ -185,6 +188,12 @@ public class PushNotificationManager { clearPushToken(account, device, tokenType); } + Metrics.counter(DEVICE_TOKEN_UNREGISTERED_COUNTER_NAME, + "errorCode", maybeErrorCode.orElse("unknown"), + "isPrimary", String.valueOf(device.isPrimary()), + "hasUnregisteredTimestamp", String.valueOf(maybeTokenInvalidationTimestamp.isPresent()), + "tokenType", tokenType.name(), + "tokenExpired", String.valueOf(tokenExpired)).increment(); } private void clearPushToken(final Account account, final Device device, final PushNotification.TokenType tokenType) {