Skip to content

Make default API rate limit configurable #274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import lombok.extern.slf4j.Slf4j;
import org.lowcoder.sdk.config.dynamic.ConfigCenter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.Ordered;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component;
Expand All @@ -30,8 +31,10 @@
@Component
public class ThrottlingFilter implements WebFilter, Ordered {

private static final int DEFAULT_RATE_THRESHOLD = 50;
@Value("${default.apiRateLimit:50}")
private int defaultApiRateLimit;


private final Map<String, RateLimiterWrapper> rateLimiterMap = new ConcurrentHashMap<>();
private Supplier<Map<String, Integer>> urlRateLimiter;

Expand All @@ -52,7 +55,7 @@ public Mono<Void> filter(@Nonnull ServerWebExchange exchange, @Nonnull WebFilter

RateLimiterWrapper rateLimiter = rateLimiterMap.compute(requestUrl,
(url, currentLimiter) -> {
int targetRate = urlRateLimiter.get().getOrDefault(url, DEFAULT_RATE_THRESHOLD);
int targetRate = urlRateLimiter.get().getOrDefault(url, defaultApiRateLimit);
if (currentLimiter == null) {
return RateLimiterWrapper.create(targetRate);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ default:
org-group-count: 100
org-app-count: 1000
developer-count: 50
api-rate-limit: 50

common:
cookie-name: LOCAL_LOWCODER_TOKEN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ default:
org-group-count: 100
org-app-count: 1000
developer-count: 50
api-rate-limit: 50

common:
cookie-name: LOWCODER_CE_SELFHOST_TOKEN
Expand Down