Search in sources :

Example 1 with RateLimiterRequestContext

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);
        }
    }
}
Also used : MetacatTooManyRequestsException(com.netflix.metacat.common.exception.MetacatTooManyRequestsException) RateLimiterRequestContext(com.netflix.metacat.common.server.api.ratelimiter.RateLimiterRequestContext)

Aggregations

MetacatTooManyRequestsException (com.netflix.metacat.common.exception.MetacatTooManyRequestsException)1 RateLimiterRequestContext (com.netflix.metacat.common.server.api.ratelimiter.RateLimiterRequestContext)1