Consolidate rate-limit counters
This commit is contained in:
parent
9e3eb2319e
commit
6dddf54222
|
@ -1 +1 @@
|
||||||
Subproject commit 3acb91971203683fb98d403806cd0cc58e19f0df
|
Subproject commit 77155669a73563fe4961c8817bfb51b6d0461181
|
|
@ -125,14 +125,15 @@ public class MessageController {
|
||||||
private final ExecutorService multiRecipientMessageExecutor;
|
private final ExecutorService multiRecipientMessageExecutor;
|
||||||
|
|
||||||
private static final String LEGACY_MESSAGE_SENT_COUNTER = name(MessageController.class, "legacyMessageSent");
|
private static final String LEGACY_MESSAGE_SENT_COUNTER = name(MessageController.class, "legacyMessageSent");
|
||||||
private static final String SENT_MESSAGE_COUNTER_NAME = name(MessageController.class, "sentMessages");
|
private static final String SENT_MESSAGE_COUNTER_NAME = name(MessageController.class, "sentMessages");
|
||||||
private static final String REJECT_UNSEALED_SENDER_COUNTER_NAME = name(MessageController.class, "rejectUnsealedSenderLimit");
|
private static final String CONTENT_SIZE_DISTRIBUTION_NAME = name(MessageController.class, "messageContentSize");
|
||||||
private static final String CONTENT_SIZE_DISTRIBUTION_NAME = name(MessageController.class, "messageContentSize");
|
|
||||||
private static final String OUTGOING_MESSAGE_LIST_SIZE_BYTES_DISTRIBUTION_NAME = name(MessageController.class, "outgoingMessageListSizeBytes");
|
private static final String OUTGOING_MESSAGE_LIST_SIZE_BYTES_DISTRIBUTION_NAME = name(MessageController.class, "outgoingMessageListSizeBytes");
|
||||||
|
private static final String RATE_LIMITED_MESSAGE_COUNTER_NAME = name(MessageController.class, "rateLimitedMessage");
|
||||||
|
|
||||||
private static final String EPHEMERAL_TAG_NAME = "ephemeral";
|
private static final String EPHEMERAL_TAG_NAME = "ephemeral";
|
||||||
private static final String SENDER_TYPE_TAG_NAME = "senderType";
|
private static final String SENDER_TYPE_TAG_NAME = "senderType";
|
||||||
private static final String SENDER_COUNTRY_TAG_NAME = "senderCountry";
|
private static final String SENDER_COUNTRY_TAG_NAME = "senderCountry";
|
||||||
|
private static final String RATE_LIMIT_REASON_TAG_NAME = "rateLimitReason";
|
||||||
|
|
||||||
private static final long MAX_MESSAGE_SIZE = DataSize.kibibytes(256).toBytes();
|
private static final long MAX_MESSAGE_SIZE = DataSize.kibibytes(256).toBytes();
|
||||||
|
|
||||||
|
@ -223,20 +224,28 @@ public class MessageController {
|
||||||
assert (destination.isPresent());
|
assert (destination.isPresent());
|
||||||
|
|
||||||
if (source.isPresent() && !source.get().getAccount().getUuid().equals(destinationUuid)) {
|
if (source.isPresent() && !source.get().getAccount().getUuid().equals(destinationUuid)) {
|
||||||
rateLimiters.getMessagesLimiter().validate(source.get().getAccount().getUuid(), destination.get().getUuid());
|
|
||||||
|
|
||||||
final String senderCountryCode = Util.getCountryCode(source.get().getAccount().getNumber());
|
final String senderCountryCode = Util.getCountryCode(source.get().getAccount().getNumber());
|
||||||
|
|
||||||
|
try {
|
||||||
|
rateLimiters.getMessagesLimiter().validate(source.get().getAccount().getUuid(), destination.get().getUuid());
|
||||||
|
} catch (final RateLimitExceededException e) {
|
||||||
|
Metrics.counter(RATE_LIMITED_MESSAGE_COUNTER_NAME,
|
||||||
|
SENDER_COUNTRY_TAG_NAME, senderCountryCode,
|
||||||
|
RATE_LIMIT_REASON_TAG_NAME, "singleDestinationRate").increment();
|
||||||
|
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
unsealedSenderRateLimiter.validate(source.get().getAccount(), destination.get());
|
unsealedSenderRateLimiter.validate(source.get().getAccount(), destination.get());
|
||||||
} catch (final RateLimitExceededException e) {
|
} catch (final RateLimitExceededException e) {
|
||||||
|
|
||||||
final boolean legacyClient = rateLimitChallengeManager.isClientBelowMinimumVersion(userAgent);
|
final boolean legacyClient = rateLimitChallengeManager.isClientBelowMinimumVersion(userAgent);
|
||||||
|
final String rateLimitReason = legacyClient ? "unsealedSenderCardinality" : "challengeIssued";
|
||||||
|
|
||||||
Metrics.counter(REJECT_UNSEALED_SENDER_COUNTER_NAME,
|
Metrics.counter(RATE_LIMITED_MESSAGE_COUNTER_NAME,
|
||||||
SENDER_COUNTRY_TAG_NAME, senderCountryCode,
|
SENDER_COUNTRY_TAG_NAME, senderCountryCode,
|
||||||
"legacyClient", String.valueOf(legacyClient))
|
RATE_LIMIT_REASON_TAG_NAME, rateLimitReason).increment();
|
||||||
.increment();
|
|
||||||
|
|
||||||
if (legacyClient) {
|
if (legacyClient) {
|
||||||
throw e;
|
throw e;
|
||||||
|
|
Loading…
Reference in New Issue