Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
bda4f081
Commit
bda4f081
authored
Feb 16, 2018
by
Dylan Griffith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve error handling for Gitlab::Profiler and improve doc about providing a user
parent
1192526b
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
0 deletions
+21
-0
doc/development/profiling.md
doc/development/profiling.md
+11
-0
lib/gitlab/profiler.rb
lib/gitlab/profiler.rb
+1
-0
spec/lib/gitlab/profiler_spec.rb
spec/lib/gitlab/profiler_spec.rb
+9
-0
No files found.
doc/development/profiling.md
View file @
bda4f081
...
@@ -27,6 +27,17 @@ Gitlab::Profiler.profile('/my-user')
...
@@ -27,6 +27,17 @@ Gitlab::Profiler.profile('/my-user')
# Returns a RubyProf::Profile where 100 seconds is spent in UsersController#show
# 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
Passing a
`logger:`
keyword argument to
`Gitlab::Profiler.profile`
will send
ActiveRecord and ActionController log output to that logger. Further options are
ActiveRecord and ActionController log output to that logger. Further options are
documented with the method source.
documented with the method source.
...
...
lib/gitlab/profiler.rb
View file @
bda4f081
...
@@ -45,6 +45,7 @@ module Gitlab
...
@@ -45,6 +45,7 @@ module Gitlab
if
user
if
user
private_token
||=
user
.
personal_access_tokens
.
active
.
pluck
(
:token
).
first
private_token
||=
user
.
personal_access_tokens
.
active
.
pluck
(
:token
).
first
raise
'Your user must have a personal_access_token'
unless
private_token
end
end
headers
[
'Private-Token'
]
=
private_token
if
private_token
headers
[
'Private-Token'
]
=
private_token
if
private_token
...
...
spec/lib/gitlab/profiler_spec.rb
View file @
bda4f081
...
@@ -53,6 +53,15 @@ describe Gitlab::Profiler do
...
@@ -53,6 +53,15 @@ describe Gitlab::Profiler do
described_class
.
profile
(
'/'
,
user:
user
)
described_class
.
profile
(
'/'
,
user:
user
)
end
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
it
'uses the private_token for auth if both it and user are set'
do
user
=
double
(
:user
)
user
=
double
(
:user
)
user_token
=
'user'
user_token
=
'user'
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment