Loading
Rate limit feature flag user list writes by size
What does this MR do and why?
Context
Nothing bounds the size of a feature flag user list or how often one user rewrites it, and the cost of each write grows with the size of the list. The figures and the agreed approach are in https://gitlab.com/gitlab-org/gitlab/-/work_items/638255#note_4182036252.
This MR
POSTandPUT /projects/:id/feature_flags_user_lists[/:iid], which the user lists UI also calls, count the bytes of the submitteduser_xidstoward a new per-user rate limit,feature_flag_user_list_write_bytes, before the write. A request withoutuser_xids, such as a rename, counts nothing.- The limit is a new
rate_limitsapplication setting,feature_flag_user_list_write_bytes_limit_per_user(default 16 MiB per minute,0disables), on Admin > Settings > Network and in the application settings API. - The new key starts in log mode: requests over the limit are logged until the
rate_limit_feature_flag_user_list_write_bytesflag is enabled, and then get429 Too Many Requests. - No size cap on the list itself. With the flag on, a single write larger than the limit gets a
429, so a list over the limit can no longer be saved. - Docs: a new rate limit page under
doc/rate_limits/api/, a line on the user lists API, and the settings API. The Changelog entry comes with the flag-removal MR.
Feature Flag: rate_limit_feature_flag_user_list_write_bytes
References
- https://gitlab.com/gitlab-org/gitlab/-/work_items/638255+
- https://gitlab.com/gitlab-org/gitlab/-/work_items/639017+
Screenshots or screen recordings
The new Feature flag user lists API rate limits block on Admin > Settings > Network. Before (master) and After (this branch) are attached at the end of this description.
How to set up and validate locally
- In a Rails console, set a small limit:
ApplicationSetting.current.update!(feature_flag_user_list_write_bytes_limit_per_user: 20) - With a personal access token (
apiscope) for a project where you can manage feature flags, create a list twice:Both returncurl --include --request POST --header "PRIVATE-TOKEN: <your_access_token>" \ --data "name=list-a&user_xids=user1,user2,user3" "http://gdk.test:3000/api/v4/projects/<id>/feature_flags_user_lists" curl --include --request POST --header "PRIVATE-TOKEN: <your_access_token>" \ --data "name=list-b&user_xids=user1,user2,user3" "http://gdk.test:3000/api/v4/projects/<id>/feature_flags_user_lists"201, andlog/api_json.logshowsrate_limit_stateending in_by_user_log:logfor the second request. - Run
Feature.enable(:rate_limit_feature_flag_user_list_write_bytes), wait a minute, and repeat the two requests with new names. The second returns429withRateLimit-Name: feature_flag_user_list_write_bytes. - A
PUTthat sends onlynamestill returns200. - Clean up:
Feature.remove(:rate_limit_feature_flag_user_list_write_bytes)and reset the setting to16777216.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Edited by Leaminn Ma

