diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2018-02-16 09:14:47 +0000 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2018-02-16 09:14:47 +0000 |
commit | 049d2cc43511e89ce8719ae59d844ea306c5a641 (patch) | |
tree | a63e16a3580cae0d9228cc51894595994e0cf045 | |
parent | 27b71e800dfe4de3f692c700190b0026e012dc8c (diff) | |
parent | bda4f0811e3d7f3530d1d6c338e2de6ada5bf1f2 (diff) | |
download | gitlab-ce-049d2cc43511e89ce8719ae59d844ea306c5a641.tar.gz |
Merge branch 'update-profiler-docs-explaining-how-to-provide-user' into 'master'
Add documentation about how to provide a user to Gitlab::Profiler
See merge request gitlab-org/gitlab-ce!17169
-rw-r--r-- | doc/development/profiling.md | 11 | ||||
-rw-r--r-- | lib/gitlab/profiler.rb | 1 | ||||
-rw-r--r-- | spec/lib/gitlab/profiler_spec.rb | 9 |
3 files changed, 21 insertions, 0 deletions
diff --git a/doc/development/profiling.md b/doc/development/profiling.md index 97c997e0568..11878b4009b 100644 --- a/doc/development/profiling.md +++ b/doc/development/profiling.md @@ -27,6 +27,17 @@ Gitlab::Profiler.profile('/my-user') # Returns a RubyProf::Profile where 100 seconds is spent in UsersController#show ``` +For routes that require authorization you will need to provide a user to +`Gitlab::Profiler`. You can do this like so: + +```ruby +Gitlab::Profiler.profile('/gitlab-org/gitlab-test', user: User.first) +``` + +The user you provide will need to have a [personal access +token](https://docs.gitlab.com/ce/user/profile/personal_access_tokens.html) in +the GitLab instance. + Passing a `logger:` keyword argument to `Gitlab::Profiler.profile` will send ActiveRecord and ActionController log output to that logger. Further options are documented with the method source. diff --git a/lib/gitlab/profiler.rb b/lib/gitlab/profiler.rb index 95d94b3cc68..98a168b43bb 100644 --- a/lib/gitlab/profiler.rb +++ b/lib/gitlab/profiler.rb @@ -45,6 +45,7 @@ module Gitlab if user private_token ||= user.personal_access_tokens.active.pluck(:token).first + raise 'Your user must have a personal_access_token' unless private_token end headers['Private-Token'] = private_token if private_token diff --git a/spec/lib/gitlab/profiler_spec.rb b/spec/lib/gitlab/profiler_spec.rb index 4a43dbb2371..f02b1cf55fb 100644 --- a/spec/lib/gitlab/profiler_spec.rb +++ b/spec/lib/gitlab/profiler_spec.rb @@ -53,6 +53,15 @@ describe Gitlab::Profiler do described_class.profile('/', user: user) end + context 'when providing a user without a personal access token' do + it 'raises an error' do + user = double(:user) + allow(user).to receive_message_chain(:personal_access_tokens, :active, :pluck).and_return([]) + + expect { described_class.profile('/', user: user) }.to raise_error('Your user must have a personal_access_token') + end + end + it 'uses the private_token for auth if both it and user are set' do user = double(:user) user_token = 'user' |