use of com.netflix.metacat.common.server.api.ratelimiter.RateLimiterRequestContext in project metacat by Netflix.
the class RequestWrapper method checkRequestRateLimit.
private void checkRequestRateLimit(@NonNull final QualifiedName name, @NonNull final String resourceRequestName, @NonNull final Map<String, String> tags) {
if (!this.config.isRateLimiterEnabled()) {
return;
}
log.info("Checking request rate limit for {}. Request: {}", name, resourceRequestName);
if (this.rateLimiter.hasExceededRequestLimit(new RateLimiterRequestContext(resourceRequestName, name))) {
final String errorMsg = String.format("Too many requests for resource %s. Request: %s", name, resourceRequestName);
log.warn(errorMsg);
registry.counter(requestRateLimitExceededId.withTags(tags)).increment();
if (this.config.isRateLimiterEnforced()) {
throw new MetacatTooManyRequestsException(errorMsg);
}
}
}
Aggregations