Fix meta.root_namespace not logging for groups API requests
What does this MR do and why?
Previously meta.root_namespace
did not log for any API call for
/api/v4/groups/:id
requests. This happened because of two issues:
-
lib/api/api.rb
attempts to push thenamespace
inApplicationContext
if@group
is set, but this instance variable was never set for those API calls. Instead of usinguser_group
, add this tofind_group!
so both CE and EE API calls will set the context. -
If the user is an admin,
bypass_session!
is called before@group
is set. This method logs a message callingApplicationContext#to_lazy_hash
, which memoizesnamespace
to benil
since@group
wasnil
. The fix in the first issue also takes care of this.
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
How to set up and validate locally
- Generate a personal access token if you don't have one.
- With this branch, make API requests to the groups API (https://docs.gitlab.com/ee/api/groups.html):
curl -H "PRIVATE-TOKEN: <YOUR TOKEN>" https://gdk.example/api/v4/groups/<some group id>
- Check
tail -1 log/api_json.log | jq . | grep root_namespace
. It should match the group namespace:
% tail -1 log/api_json.log | jq . | grep root_namespace
"meta.root_namespace": "gitlab-org",