Fix truncated Grape routes in Cells routing snapshot
What does this MR do and why?
API::API.routes memoizes its result, and grape-swagger reads it from
add_open_api_documentation! (lib/api/api.rb:426) while only 185 of the
eventual 358 endpoints are mounted. gitlab:cells:routes:generate inherited
that partial memo, so it collected 1228 of 2142 Grape routes.
As a result config/routing/gitlab_routes.json was missing 598 API path
templates - every route mounted after the OpenAPI block, for example:
/api/:version/projects/:id/boards
/api/:version/admin/sidekiq/queues/:queue_name
/api/:version/projects/:id/issues/:noteable_id/discussionsPaths absent from the snapshot are paths we could potentially misroute.
This MR calls API::API.compile! and API::API.reset_routes! before reading
the route table, then regenerates the snapshot. reset_routes! is the line
that fixes it (the endpoint tree already holds 2142 leaves before compiling);
compile! guarantees every mount is materialised and mirrors what
Gitlab::RequestEndpoints.all_api_endpoints already does.
Snapshot size goes from 4445 to 5043 entries. The change is purely additive:
added templates 598
removed templates 0
changed existing entries 0Checklist notes
- Changelog: omitted. This is development tooling; no user-facing behaviour changes.
- Tests:
spec/tasks/gitlab/cells/routes_rake_spec.rbstubsRoutesSnapshot.newand only asserts that both route tables reach the constructor, so it neither caught nor needs to catch this. A test that would catch it has to boot the full route table, which thegitlab:cells:routes:updated_checkCI job already does. - Documentation: no behaviour, API surface, configuration or UI change.
- Screenshots: not applicable, no UI change.
- Database / Application Security review: not applicable.
- Translation: no user-facing strings.
- Feature flag: not applicable, the task is run on demand and in CI.
References
This also tackles the missing internal APIs in the snapshot gitlab-com/gl-infra/tenant-scale/cells-infrastructure/team#786 (closed)
Screenshots or screen recordings
Not applicable, no UI change.
| Before | After |
|---|---|
| 4445 snapshot entries, 956 unique Grape paths | 5043 snapshot entries, 1554 unique Grape paths |
How to set up and validate locally
-
Check out
masterand confirm the truncation:RAILS_ENV=test CI=true GITLAB_CONFIG=$(pwd)/config/gitlab.yml.example \ bundle exec rails runner 'puts API::API.routes.count' # => 1228 -
Confirm the full table is larger:
RAILS_ENV=test CI=true GITLAB_CONFIG=$(pwd)/config/gitlab.yml.example \ bundle exec rails runner 'API::API.compile!; API::API.reset_routes!; puts API::API.routes.count' # => 2142 -
Check out this branch and regenerate; the file must not change:
bundle exec rake gitlab:cells:routes:generate # => Generated 5043 routes at config/routing/gitlab_routes.json git diff --stat -- config/routing/gitlab_routes.json -
Confirm the sync check passes:
bundle exec rake gitlab:cells:routes:updated_check
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.