From 28cfc54170ab385130ca3cc3097cbcc740155bd9 Mon Sep 17 00:00:00 2001 From: Chris Eager Date: Fri, 11 Jun 2021 11:02:00 -0500 Subject: [PATCH] Update FunctionCounter builder to use non-null object and method --- .../textsecuregcm/limits/PreKeyRateLimiter.java | 2 +- .../limits/RateLimitResetMetricsManager.java | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/limits/PreKeyRateLimiter.java b/service/src/main/java/org/whispersystems/textsecuregcm/limits/PreKeyRateLimiter.java index c779c7315..ce56db9a4 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/limits/PreKeyRateLimiter.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/limits/PreKeyRateLimiter.java @@ -18,7 +18,7 @@ public class PreKeyRateLimiter { private static final String RATE_LIMIT_RESET_COUNTER_NAME = name(PreKeyRateLimiter.class, "reset"); private static final String RATE_LIMITED_PREKEYS_COUNTER_NAME = name(PreKeyRateLimiter.class, "rateLimited"); - private static final String RATE_LIMITED_PREKEYS_TOTAL_ACCOUNTS_COUNTER_NAME = name(PreKeyRateLimiter.class, "rateLimited"); + private static final String RATE_LIMITED_PREKEYS_TOTAL_ACCOUNTS_COUNTER_NAME = name(PreKeyRateLimiter.class, "rateLimitedTotal"); private static final String RATE_LIMITED_PREKEYS_ACCOUNTS_ENFORCED_COUNTER_NAME = name(PreKeyRateLimiter.class, "rateLimitedAccountsEnforced"); private static final String RATE_LIMITED_PREKEYS_ACCOUNTS_UNENFORCED_COUNTER_NAME = name(PreKeyRateLimiter.class, "rateLimitedAccountsUnenforced"); diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/limits/RateLimitResetMetricsManager.java b/service/src/main/java/org/whispersystems/textsecuregcm/limits/RateLimitResetMetricsManager.java index c5efb9067..56fcef6e5 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/limits/RateLimitResetMetricsManager.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/limits/RateLimitResetMetricsManager.java @@ -18,8 +18,13 @@ public class RateLimitResetMetricsManager { } void initializeFunctionCounters(String counterKey, String hllKey) { - FunctionCounter.builder(counterKey, null, (ignored) -> - metricsCluster.withCluster(conn -> conn.sync().pfcount(hllKey))).register(meterRegistry); + FunctionCounter + .builder(counterKey, this, manager -> manager.getCount(hllKey)) + .register(meterRegistry); + } + + Long getCount(final String hllKey) { + return metricsCluster.withCluster(conn -> conn.sync().pfcount(hllKey)); } void recordMetrics(Account account, boolean enforced, String counterKey, String hllEnforcedKey, String hllTotalKey,