From 7a6ce00fed2b4dbe827e4db7259bf0d769d63413 Mon Sep 17 00:00:00 2001 From: Ameya Lokare Date: Thu, 26 Sep 2024 18:04:01 -0700 Subject: [PATCH] Add senderType tag to sendMessageLatency timer This will allow us to differentiate between sealed vs unsealed sends latency --- .../controllers/MessageController.java | 45 +++++++++---------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/MessageController.java b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/MessageController.java index b48e5898d..3579c9ab6 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/MessageController.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/MessageController.java @@ -181,10 +181,7 @@ public class MessageController { private static final String RATE_LIMITED_MESSAGE_COUNTER_NAME = name(MessageController.class, "rateLimitedMessage"); private static final String REJECT_INVALID_ENVELOPE_TYPE = name(MessageController.class, "rejectInvalidEnvelopeType"); - private static final Timer SEND_MESSAGE_LATENCY_TIMER = - Timer.builder(MetricsUtil.name(MessageController.class, "sendMessageLatency")) - .publishPercentileHistogram(true) - .register(Metrics.globalRegistry); + private static final String SEND_MESSAGE_LATENCY_TIMER_NAME = MetricsUtil.name(MessageController.class, "sendMessageLatency"); private static final String EPHEMERAL_TAG_NAME = "ephemeral"; private static final String SENDER_TYPE_TAG_NAME = "senderType"; @@ -251,7 +248,6 @@ public class MessageController { this.clock = clock; } - @Timed @Path("/{destination}") @PUT @Consumes(MediaType.APPLICATION_JSON) @@ -297,25 +293,25 @@ public class MessageController { @Context final ContainerRequestContext context) throws RateLimitExceededException { + if (source.isEmpty() && accessKey.isEmpty() && groupSendToken == null && !isStory) { + throw new WebApplicationException(Status.UNAUTHORIZED); + } + + if (groupSendToken != null) { + if (source.isPresent() || accessKey.isPresent()) { + throw new BadRequestException( + "Group send endorsement tokens should not be combined with other authentication"); + } else if (isStory) { + throw new BadRequestException("Group send endorsement tokens should not be sent for story messages"); + } + } + + final String senderType = source.map( + s -> s.getAccount().isIdentifiedBy(destinationIdentifier) ? SENDER_TYPE_SELF : SENDER_TYPE_IDENTIFIED) + .orElse(SENDER_TYPE_UNIDENTIFIED); + final Sample sample = Timer.start(); try { - if (source.isEmpty() && accessKey.isEmpty() && groupSendToken == null && !isStory) { - throw new WebApplicationException(Status.UNAUTHORIZED); - } - - if (groupSendToken != null) { - if (source.isPresent() || accessKey.isPresent()) { - throw new BadRequestException( - "Group send endorsement tokens should not be combined with other authentication"); - } else if (isStory) { - throw new BadRequestException("Group send endorsement tokens should not be sent for story messages"); - } - } - - final String senderType = source.map( - s -> s.getAccount().isIdentifiedBy(destinationIdentifier) ? SENDER_TYPE_SELF : SENDER_TYPE_IDENTIFIED) - .orElse(SENDER_TYPE_UNIDENTIFIED); - final boolean isSyncMessage = senderType.equals(SENDER_TYPE_SELF); if (isSyncMessage && destinationIdentifier.identityType() == IdentityType.PNI) { @@ -464,7 +460,10 @@ public class MessageController { .build()); } } finally { - sample.stop(SEND_MESSAGE_LATENCY_TIMER); + sample.stop(Timer.builder(SEND_MESSAGE_LATENCY_TIMER_NAME) + .tags(SENDER_TYPE_TAG_NAME, senderType) + .publishPercentileHistogram(true) + .register(Metrics.globalRegistry)); } }