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
5949f62a
Commit
5949f62a
authored
Oct 15, 2020
by
Sean McGivern
Committed by
Bob Van Landuyt
Oct 22, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Expose API feature categories in logs and metrics
parent
9f252f39
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
5 deletions
+45
-5
lib/api/api.rb
lib/api/api.rb
+7
-1
lib/api/internal/base.rb
lib/api/internal/base.rb
+6
-4
spec/requests/api/api_spec.rb
spec/requests/api/api_spec.rb
+32
-0
No files found.
lib/api/api.rb
View file @
5949f62a
...
...
@@ -48,11 +48,17 @@ module API
before
do
coerce_nil_params_to_array!
api_endpoint
=
env
[
'api.endpoint'
]
feature_category
=
api_endpoint
.
options
[
:for
].
try
(
:feature_category_for_app
,
api_endpoint
).
to_s
header
[
Gitlab
::
Metrics
::
RequestsRackMiddleware
::
FEATURE_CATEGORY_HEADER
]
=
feature_category
Gitlab
::
ApplicationContext
.
push
(
user:
->
{
@current_user
},
project:
->
{
@project
},
namespace:
->
{
@group
},
caller_id:
route
.
origin
caller_id:
route
.
origin
,
feature_category:
feature_category
)
end
...
...
lib/api/internal/base.rb
View file @
5949f62a
...
...
@@ -7,14 +7,16 @@ module API
before
{
authenticate_by_gitlab_shell_token!
}
before
do
route_path
=
route
.
origin
route_class
=
route
.
app
.
options
[
:for
]
api_endpoint
=
env
[
'api.endpoint'
]
feature_category
=
api_endpoint
.
options
[
:for
].
try
(
:feature_category_for_app
,
api_endpoint
).
to_s
header
[
Gitlab
::
Metrics
::
RequestsRackMiddleware
::
FEATURE_CATEGORY_HEADER
]
=
feature_category
Gitlab
::
ApplicationContext
.
push
(
user:
->
{
actor
&
.
user
},
project:
->
{
project
},
caller_id:
route
_path
,
feature_category:
route_class
.
try
(
:feature_category_for_action
,
route_path
).
to_s
caller_id:
route
.
origin
,
feature_category:
feature_category
)
end
...
...
spec/requests/api/api_spec.rb
View file @
5949f62a
...
...
@@ -92,4 +92,36 @@ RSpec.describe API::API do
end
end
end
context
'application context'
do
let_it_be
(
:project
)
{
create
(
:project
)
}
let_it_be
(
:user
)
{
project
.
owner
}
it
'logs all application context fields'
do
allow_any_instance_of
(
Gitlab
::
GrapeLogging
::
Loggers
::
ContextLogger
).
to
receive
(
:parameters
)
do
Labkit
::
Context
.
current
.
to_h
.
tap
do
|
log_context
|
expect
(
log_context
).
to
match
(
'correlation_id'
=>
an_instance_of
(
String
),
'meta.caller_id'
=>
'/api/:version/projects/:id/issues'
,
'meta.project'
=>
project
.
full_path
,
'meta.root_namespace'
=>
project
.
namespace
.
full_path
,
'meta.user'
=>
user
.
username
,
'meta.feature_category'
=>
'issue_tracking'
)
end
end
get
(
api
(
"/projects/
#{
project
.
id
}
/issues"
,
user
))
end
it
'skips fields that do not apply'
do
allow_any_instance_of
(
Gitlab
::
GrapeLogging
::
Loggers
::
ContextLogger
).
to
receive
(
:parameters
)
do
Labkit
::
Context
.
current
.
to_h
.
tap
do
|
log_context
|
expect
(
log_context
).
to
match
(
'correlation_id'
=>
an_instance_of
(
String
),
'meta.caller_id'
=>
'/api/:version/users'
,
'meta.feature_category'
=>
'users'
)
end
end
get
(
api
(
'/users'
))
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