Add `isStory` and `isSyncMessage` dimensions to message size metrics

This commit is contained in:
Jon Chambers 2025-02-10 12:08:40 -05:00 committed by GitHub
parent b086a73353
commit 3ae145bd60
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 16 additions and 6 deletions

View File

@ -337,7 +337,7 @@ public class MessageController {
contentLength += message.content().length(); contentLength += message.content().length();
} }
validateContentLength(contentLength, false, userAgent); validateContentLength(contentLength, false, isSyncMessage, isStory, userAgent);
validateEnvelopeType(message.type(), userAgent); validateEnvelopeType(message.type(), userAgent);
totalContentLength += contentLength; totalContentLength += contentLength;
@ -529,7 +529,7 @@ public class MessageController {
// Verify that the message isn't too large before performing more expensive validations // Verify that the message isn't too large before performing more expensive validations
multiRecipientMessage.getRecipients().values().forEach(recipient -> multiRecipientMessage.getRecipients().values().forEach(recipient ->
validateContentLength(multiRecipientMessage.messageSizeForRecipient(recipient), true, userAgent)); validateContentLength(multiRecipientMessage.messageSizeForRecipient(recipient), true, false, isStory, userAgent));
// Check that the request is well-formed and doesn't contain repeated entries for the same device for the same // Check that the request is well-formed and doesn't contain repeated entries for the same device for the same
// recipient // recipient
@ -931,26 +931,36 @@ public class MessageController {
} }
} }
private void validateContentLength(final int contentLength, final boolean multiRecipientMessage, final String userAgent) { private void validateContentLength(final int contentLength,
final boolean isMultiRecipientMessage,
final boolean isSyncMessage,
final boolean isStory,
final String userAgent) {
final boolean oversize = contentLength > MAX_MESSAGE_SIZE; final boolean oversize = contentLength > MAX_MESSAGE_SIZE;
DistributionSummary.builder(CONTENT_SIZE_DISTRIBUTION_NAME) DistributionSummary.builder(CONTENT_SIZE_DISTRIBUTION_NAME)
.tags(Tags.of(UserAgentTagUtil.getPlatformTag(userAgent), .tags(Tags.of(UserAgentTagUtil.getPlatformTag(userAgent),
Tag.of("oversize", String.valueOf(oversize)), Tag.of("oversize", String.valueOf(oversize)),
Tag.of("multiRecipientMessage", String.valueOf(multiRecipientMessage)))) Tag.of("multiRecipientMessage", String.valueOf(isMultiRecipientMessage)),
Tag.of("syncMessage", String.valueOf(isSyncMessage)),
Tag.of("story", String.valueOf(isStory))))
.publishPercentileHistogram(true) .publishPercentileHistogram(true)
.register(Metrics.globalRegistry) .register(Metrics.globalRegistry)
.record(contentLength); .record(contentLength);
if (oversize) { if (oversize) {
Metrics.counter(REJECT_OVERSIZE_MESSAGE_COUNTER, Tags.of(UserAgentTagUtil.getPlatformTag(userAgent))) Metrics.counter(REJECT_OVERSIZE_MESSAGE_COUNTER, Tags.of(UserAgentTagUtil.getPlatformTag(userAgent),
Tag.of("multiRecipientMessage", String.valueOf(isMultiRecipientMessage)),
Tag.of("syncMessage", String.valueOf(isSyncMessage)),
Tag.of("story", String.valueOf(isStory))))
.increment(); .increment();
throw new WebApplicationException(Status.REQUEST_ENTITY_TOO_LARGE); throw new WebApplicationException(Status.REQUEST_ENTITY_TOO_LARGE);
} }
if (contentLength > LARGE_MESSAGE_SIZE) { if (contentLength > LARGE_MESSAGE_SIZE) {
Metrics.counter( Metrics.counter(
LARGE_BUT_NOT_OVERSIZE_MESSAGE_COUNTER, LARGE_BUT_NOT_OVERSIZE_MESSAGE_COUNTER,
Tags.of(UserAgentTagUtil.getPlatformTag(userAgent), Tag.of("multiRecipientMessage", String.valueOf(multiRecipientMessage)))) Tags.of(UserAgentTagUtil.getPlatformTag(userAgent), Tag.of("multiRecipientMessage", String.valueOf(isMultiRecipientMessage))))
.increment(); .increment();
} }
} }