Skip to content

Commit 56f9e3e

Browse files
committed
Add metric tag when redis fails open
1 parent 8886618 commit 56f9e3e

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/main/java/org/signal/cdsi/limits/redis/RedisLeakyBucketRateLimiter.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.signal.cdsi.limits.LeakyBucketRateLimitConfiguration;
3434
import org.signal.cdsi.limits.LeakyBucketRateLimiter;
3535
import org.signal.cdsi.limits.RateLimitExceededException;
36+
import org.signal.cdsi.util.CompletionExceptions;
3637

3738
@Requires(bean = StatefulRedisClusterConnection.class)
3839
@EachBean(LeakyBucketRateLimitConfiguration.class)
@@ -127,11 +128,13 @@ public CompletableFuture<Void> validate(final String key, final int amount) {
127128
return null;
128129
})
129130
.exceptionally(e -> {
130-
if (e instanceof CompletionException ce && ce.getCause() instanceof RateLimitExceededException) {
131-
throw ce;
131+
if (CompletionExceptions.unwrap(e) instanceof RateLimitExceededException) {
132+
throw CompletionExceptions.wrap(e);
132133
}
133134
// If the leaky bucket data store is unavailable, allow the request to proceed. This is just a rate limit
134135
// for connections, and the more critical token rate limit will still be enforced.
136+
meterRegistry.counter(VALIDATE_COUNTER_NAME, "outcome", "failOpen").increment();
137+
135138
return null;
136139
})
137140
.thenRun(() -> validateTimer.record(Duration.between(start, clock.instant())));

0 commit comments

Comments
 (0)