Skip to content

Commit

Permalink
Add senderType tag to sendMessageLatency timer
Browse files Browse the repository at this point in the history
This will allow us to differentiate between sealed vs unsealed sends
latency
  • Loading branch information
ameya-signal authored and jon-signal committed Sep 27, 2024
1 parent c0aa9ce commit 7a6ce00
Showing 1 changed file with 20 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,7 @@ private record MultiRecipientDeliveryData(
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";
Expand Down Expand Up @@ -251,7 +248,6 @@ public MessageController(
this.clock = clock;
}

@Timed
@Path("/{destination}")
@PUT
@Consumes(MediaType.APPLICATION_JSON)
Expand Down Expand Up @@ -297,25 +293,25 @@ public Response sendMessage(@ReadOnly @Auth final Optional<AuthenticatedDevice>

@Context final ContainerRequestContext context) throws RateLimitExceededException {

final Sample sample = Timer.start();
try {
if (source.isEmpty() && accessKey.isEmpty() && groupSendToken == null && !isStory) {
throw new WebApplicationException(Status.UNAUTHORIZED);
}
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");
}
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 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 {
final boolean isSyncMessage = senderType.equals(SENDER_TYPE_SELF);

if (isSyncMessage && destinationIdentifier.identityType() == IdentityType.PNI) {
Expand Down Expand Up @@ -464,7 +460,10 @@ public Response sendMessage(@ReadOnly @Auth final Optional<AuthenticatedDevice>
.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));
}
}

Expand Down

0 comments on commit 7a6ce00

Please sign in to comment.