feat(ratelimit): make rate-limit thresholds runtime-configurable - #756
feat(ratelimit): make rate-limit thresholds runtime-configurable#756FenjuFu wants to merge 2 commits into
Conversation
The per-endpoint quotas were compile-time constants in the @ratelimit annotation, so operators could not tune them or turn limiting off without rebuilding (#726). Add RateLimitProperties (skillhub.ratelimit) with a global `enabled` toggle and per-category threshold overrides, and have RateLimitInterceptor resolve the effective authenticated/anonymous limit and window from config, falling back to the annotation defaults. Unset categories keep the built-in values, so behavior is unchanged until an override is provided; `enabled=false` disables quota checks entirely. All configurable via SKILLHUB_RATELIMIT_* environment variables. Closes #726 Signed-off-by: FenjuFu <92919259+FenjuFu@users.noreply.github.com>
|
Thanks for the PR. The direction is useful and the implementation is close, but I think this needs one more binding-level check before merge. The PR says the per-category overrides are configurable through I tried to validate that path on this PR head plus current Could you please add a test that proves the documented environment-variable override path actually binds into Keeping the map for YAML-style config is fine, but the env examples should be backed by tests because this feature is mainly for self-hosted operators. |
Signed-off-by: XiaoSeS <87064762+XiaoSeS@users.noreply.github.com>
|
Follow-up correction on the binding concern above: My original I pushed One deployment note: Compose users must explicitly pass category variables into |
What
Make the per-endpoint rate-limit thresholds configurable at runtime, with a global on/off switch — closes #726.
Why
The quotas were compile-time constants baked into the
@RateLimitannotation on each endpoint (search60/20, download120/30, publish10, the various auth flows, etc.). Operators couldn't tune them for their traffic or turn limiting off in a trusted/internal deployment without rebuilding the server.How
RateLimitProperties(skillhub.ratelimit, component-scanned likeDownloadRateLimitProperties):enabled— master switch;falsemakes the interceptor skip all quota checks.categories.<category>.{authenticated, anonymous, windowSeconds}— per-category overrides, each field optional.RateLimitInterceptornow resolves the effective authenticated/anonymous limit and window from config, falling back to the annotation values when nothing is configured.application.ymlwiresenabled: ${SKILLHUB_RATELIMIT_ENABLED:true}and documents the override keys with a commented example.Everything is reachable via
SKILLHUB_RATELIMIT_*env vars, e.g.:Behavior / compatibility
downloadis120/30in the portal/CLI controllers but60/20inClawHubCompatController) — seeding one value would silently change the compat endpoints. An override, when set, applies to every endpoint sharing that category, which is the intended "tune this category" semantic.RateLimitPropertiesTestcovering the enabled default, annotation fallback, partial-field override, and per-category isolation.Closes #726