Skip to content

Fix meta.root_namespace not logging for groups API requests

Stan Hu requested to merge sh-fix-root-namespace-metadata-api into master

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:

  1. lib/api/api.rb attempts to push the namespace in ApplicationContext if @group is set, but this instance variable was never set for those API calls. Instead of using user_group, add this to find_group! so both CE and EE API calls will set the context.

  2. If the user is an admin, bypass_session! is called before @group is set. This method logs a message calling ApplicationContext#to_lazy_hash, which memoizes namespace to be nil since @group was nil. 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

  1. Generate a personal access token if you don't have one.
  2. 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>
  1. 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",
Edited by Stan Hu

Merge request reports

Loading