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
cf941ceb
Commit
cf941ceb
authored
Aug 10, 2020
by
Heinrich Lee Yu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support API requests in Performance Bar
This adds Peek support for Grape API endpoints
parent
bdc9ae90
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
85 additions
and
4 deletions
+85
-4
changelogs/unreleased/33909-peek-api-requests.yml
changelogs/unreleased/33909-peek-api-requests.yml
+5
-0
config/initializers/peek.rb
config/initializers/peek.rb
+6
-0
lib/api/api.rb
lib/api/api.rb
+5
-0
lib/api/api_guard.rb
lib/api/api_guard.rb
+7
-4
lib/api/helpers/performance_bar_helpers.rb
lib/api/helpers/performance_bar_helpers.rb
+21
-0
spec/requests/api/performance_bar_spec.rb
spec/requests/api/performance_bar_spec.rb
+41
-0
No files found.
changelogs/unreleased/33909-peek-api-requests.yml
0 → 100644
View file @
cf941ceb
---
title
:
Support adding of API requests to the performance bar
merge_request
:
39057
author
:
type
:
added
config/initializers/peek.rb
View file @
cf941ceb
...
...
@@ -14,3 +14,9 @@ Peek.into Peek::Views::Rugged
Peek
.
into
Peek
::
Views
::
BulletDetailed
if
defined?
(
Bullet
)
Peek
.
into
Peek
::
Views
::
Tracing
if
Labkit
::
Tracing
.
tracing_url_enabled?
ActiveSupport
::
Notifications
.
subscribe
(
'endpoint_run.grape'
)
do
|
_name
,
_start
,
_finish
,
_id
,
payload
|
if
request_id
=
payload
[
:env
][
'action_dispatch.request_id'
]
Peek
.
adapter
.
save
(
request_id
)
end
end
lib/api/api.rb
View file @
cf941ceb
...
...
@@ -56,6 +56,10 @@ module API
)
end
before
do
set_peek_enabled_for_current_request
end
# The locale is set to the current user's locale when `current_user` is loaded
after
{
Gitlab
::
I18n
.
use_default_locale
}
...
...
@@ -116,6 +120,7 @@ module API
# Ensure the namespace is right, otherwise we might load Grape::API::Helpers
helpers
::
API
::
Helpers
helpers
::
API
::
Helpers
::
CommonHelpers
helpers
::
API
::
Helpers
::
PerformanceBarHelpers
namespace
do
after
do
...
...
lib/api/api_guard.rb
View file @
cf941ceb
...
...
@@ -7,6 +7,7 @@ require 'rack/oauth2'
module
API
module
APIGuard
extend
ActiveSupport
::
Concern
include
Gitlab
::
Utils
::
StrongMemoize
included
do
|
base
|
# OAuth2 Resource Server Authentication
...
...
@@ -64,10 +65,12 @@ module API
end
def
find_user_from_sources
deploy_token_from_request
||
find_user_from_bearer_token
||
find_user_from_job_token
||
find_user_from_warden
strong_memoize
(
:find_user_from_sources
)
do
deploy_token_from_request
||
find_user_from_bearer_token
||
find_user_from_job_token
||
find_user_from_warden
end
end
private
...
...
lib/api/helpers/performance_bar_helpers.rb
0 → 100644
View file @
cf941ceb
# frozen_string_literal: true
module
API
module
Helpers
module
PerformanceBarHelpers
def
set_peek_enabled_for_current_request
Gitlab
::
SafeRequestStore
.
fetch
(
:peek_enabled
)
{
perf_bar_cookie_enabled?
&&
perf_bar_enabled_for_user?
}
end
def
perf_bar_cookie_enabled?
cookies
[
:perf_bar_enabled
]
==
'true'
end
def
perf_bar_enabled_for_user?
# We cannot use `current_user` here because that method raises an exception when the user
# is unauthorized and some API endpoints require that `current_user` is not called.
Gitlab
::
PerformanceBar
.
enabled_for_user?
(
find_user_from_sources
)
end
end
end
end
spec/requests/api/performance_bar_spec.rb
0 → 100644
View file @
cf941ceb
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
'Performance Bar for API requests'
,
:request_store
,
:clean_gitlab_redis_cache
do
context
'with user that has access to the performance bar'
do
let_it_be
(
:admin
)
{
create
(
:admin
)
}
context
'when cookie is set to true'
do
before
do
cookies
[
:perf_bar_enabled
]
=
'true'
end
it
'stores performance data'
do
get
api
(
"/users/
#{
admin
.
id
}
"
,
admin
)
expect
(
Peek
.
adapter
.
get
(
headers
[
'X-Request-Id'
])).
not_to
be_empty
end
end
context
'when cookie is missing'
do
it
'does not store performance data'
do
get
api
(
"/users/
#{
admin
.
id
}
"
,
admin
)
expect
(
Peek
.
adapter
.
get
(
headers
[
'X-Request-Id'
])).
to
be_nil
end
end
end
context
'with user that does not have access to the performance bar'
do
let
(
:user
)
{
create
(
:user
)
}
it
'does not store performance data'
do
cookies
[
:perf_bar_enabled
]
=
'true'
get
api
(
"/users/
#{
user
.
id
}
"
,
user
)
expect
(
Peek
.
adapter
.
get
(
headers
[
'X-Request-Id'
])).
to
be_nil
end
end
end
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