Measure the time taken to send APNs push notifications
This commit is contained in:
parent
85b16b674d
commit
4a0ef1f834
|
@ -17,11 +17,16 @@ import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.security.InvalidKeyException;
|
import java.security.InvalidKeyException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.time.Duration;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import io.micrometer.core.instrument.Metrics;
|
||||||
|
import io.micrometer.core.instrument.Timer;
|
||||||
import org.whispersystems.textsecuregcm.configuration.ApnConfiguration;
|
import org.whispersystems.textsecuregcm.configuration.ApnConfiguration;
|
||||||
|
|
||||||
|
import static org.whispersystems.textsecuregcm.metrics.MetricsUtil.name;
|
||||||
|
|
||||||
public class APNSender implements Managed, PushNotificationSender {
|
public class APNSender implements Managed, PushNotificationSender {
|
||||||
|
|
||||||
private final ExecutorService executor;
|
private final ExecutorService executor;
|
||||||
|
@ -45,6 +50,8 @@ public class APNSender implements Managed, PushNotificationSender {
|
||||||
|
|
||||||
private static final String APNS_CA_FILENAME = "apns-certificates.pem";
|
private static final String APNS_CA_FILENAME = "apns-certificates.pem";
|
||||||
|
|
||||||
|
private static final Timer SEND_NOTIFICATION_TIMER = Metrics.timer(name(APNSender.class, "sendNotification"));
|
||||||
|
|
||||||
public APNSender(ExecutorService executor, ApnConfiguration configuration)
|
public APNSender(ExecutorService executor, ApnConfiguration configuration)
|
||||||
throws IOException, NoSuchAlgorithmException, InvalidKeyException
|
throws IOException, NoSuchAlgorithmException, InvalidKeyException
|
||||||
{
|
{
|
||||||
|
@ -95,6 +102,8 @@ public class APNSender implements Managed, PushNotificationSender {
|
||||||
(notification.notificationType() == PushNotification.NotificationType.NOTIFICATION && !isVoip)
|
(notification.notificationType() == PushNotification.NotificationType.NOTIFICATION && !isVoip)
|
||||||
? "incoming-message" : null;
|
? "incoming-message" : null;
|
||||||
|
|
||||||
|
final Instant start = Instant.now();
|
||||||
|
|
||||||
return apnsClient.sendNotification(new SimpleApnsPushNotification(notification.deviceToken(),
|
return apnsClient.sendNotification(new SimpleApnsPushNotification(notification.deviceToken(),
|
||||||
topic,
|
topic,
|
||||||
payload,
|
payload,
|
||||||
|
@ -102,6 +111,12 @@ public class APNSender implements Managed, PushNotificationSender {
|
||||||
DeliveryPriority.IMMEDIATE,
|
DeliveryPriority.IMMEDIATE,
|
||||||
isVoip ? PushType.VOIP : PushType.ALERT,
|
isVoip ? PushType.VOIP : PushType.ALERT,
|
||||||
collapseId))
|
collapseId))
|
||||||
|
.whenComplete((response, throwable) -> {
|
||||||
|
// Note that we deliberately run this small bit of non-blocking measurement on the "send notification" thread
|
||||||
|
// to avoid any measurement noise that could arise from dispatching to another executor and waiting in its
|
||||||
|
// queue
|
||||||
|
SEND_NOTIFICATION_TIMER.record(Duration.between(start, Instant.now()));
|
||||||
|
})
|
||||||
.thenApplyAsync(response -> {
|
.thenApplyAsync(response -> {
|
||||||
final boolean accepted;
|
final boolean accepted;
|
||||||
final String rejectionReason;
|
final String rejectionReason;
|
||||||
|
|
Loading…
Reference in New Issue