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
2d432147
Commit
2d432147
authored
Oct 17, 2019
by
Balakumar
Committed by
Kamil Trzciński
Oct 17, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Log cpu user time to structured logging
parent
c00149a5
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
85 additions
and
0 deletions
+85
-0
config/initializers/lograge.rb
config/initializers/lograge.rb
+4
-0
lib/gitlab/metrics/system.rb
lib/gitlab/metrics/system.rb
+2
-0
lib/gitlab/request_context.rb
lib/gitlab/request_context.rb
+6
-0
spec/initializers/lograge_spec.rb
spec/initializers/lograge_spec.rb
+33
-0
spec/lib/gitlab/metrics/system_spec.rb
spec/lib/gitlab/metrics/system_spec.rb
+40
-0
No files found.
config/initializers/lograge.rb
View file @
2d432147
...
...
@@ -32,6 +32,10 @@ unless Sidekiq.server?
payload
[
:response
]
=
event
.
payload
[
:response
]
if
event
.
payload
[
:response
]
payload
[
Labkit
::
Correlation
::
CorrelationId
::
LOG_KEY
]
=
Labkit
::
Correlation
::
CorrelationId
.
current_id
if
cpu_s
=
Gitlab
::
Metrics
::
System
.
thread_cpu_duration
(
::
Gitlab
::
RequestContext
.
start_thread_cpu_time
)
payload
[
:cpu_s
]
=
cpu_s
end
payload
end
end
...
...
lib/gitlab/metrics/system.rb
View file @
2d432147
...
...
@@ -65,6 +65,8 @@ module Gitlab
end
def
self
.
thread_cpu_time
# Not all OS kernels are supporting `Process::CLOCK_THREAD_CPUTIME_ID`
# Refer: https://gitlab.com/gitlab-org/gitlab/issues/30567#note_221765627
return
unless
defined?
(
Process
::
CLOCK_THREAD_CPUTIME_ID
)
Process
.
clock_gettime
(
Process
::
CLOCK_THREAD_CPUTIME_ID
,
:float_second
)
...
...
lib/gitlab/request_context.rb
View file @
2d432147
...
...
@@ -6,6 +6,10 @@ module Gitlab
def
client_ip
Gitlab
::
SafeRequestStore
[
:client_ip
]
end
def
start_thread_cpu_time
Gitlab
::
SafeRequestStore
[
:start_thread_cpu_time
]
end
end
def
initialize
(
app
)
...
...
@@ -23,6 +27,8 @@ module Gitlab
Gitlab
::
SafeRequestStore
[
:client_ip
]
=
req
.
ip
Gitlab
::
SafeRequestStore
[
:start_thread_cpu_time
]
=
Gitlab
::
Metrics
::
System
.
thread_cpu_time
@app
.
call
(
env
)
end
end
...
...
spec/initializers/lograge_spec.rb
View file @
2d432147
...
...
@@ -34,5 +34,38 @@ describe 'lograge', type: :request do
subject
end
it
'logs cpu_s on supported platform'
do
allow
(
Gitlab
::
Metrics
::
System
).
to
receive
(
:thread_cpu_time
)
.
and_return
(
0.111222333
,
0.222333833
)
expect
(
Lograge
.
formatter
).
to
receive
(
:call
)
.
with
(
a_hash_including
(
cpu_s:
0.1111115
))
.
and_call_original
expect
(
Lograge
.
logger
).
to
receive
(
:send
)
.
with
(
anything
,
include
(
'"cpu_s":0.1111115'
))
.
and_call_original
subject
end
it
'does not log cpu_s on unsupported platform'
do
allow
(
Gitlab
::
Metrics
::
System
).
to
receive
(
:thread_cpu_time
)
.
and_return
(
nil
)
expect
(
Lograge
.
formatter
).
to
receive
(
:call
)
.
with
(
hash_not_including
(
:cpu_s
))
.
and_call_original
expect
(
Lograge
.
logger
).
not_to
receive
(
:send
)
.
with
(
anything
,
include
(
'"cpu_s":'
))
.
and_call_original
subject
end
end
end
spec/lib/gitlab/metrics/system_spec.rb
View file @
2d432147
...
...
@@ -58,4 +58,44 @@ describe Gitlab::Metrics::System do
expect
(
described_class
.
monotonic_time
).
to
be_an
(
Float
)
end
end
describe
'.thread_cpu_time'
do
it
'returns cpu_time on supported platform'
do
stub_const
(
"Process::CLOCK_THREAD_CPUTIME_ID"
,
16
)
expect
(
Process
).
to
receive
(
:clock_gettime
)
.
with
(
16
,
kind_of
(
Symbol
))
{
0.111222333
}
expect
(
described_class
.
thread_cpu_time
).
to
eq
(
0.111222333
)
end
it
'returns nil on unsupported platform'
do
hide_const
(
"Process::CLOCK_THREAD_CPUTIME_ID"
)
expect
(
described_class
.
thread_cpu_time
).
to
be_nil
end
end
describe
'.thread_cpu_duration'
do
let
(
:start_time
)
{
described_class
.
thread_cpu_time
}
it
'returns difference between start and current time'
do
stub_const
(
"Process::CLOCK_THREAD_CPUTIME_ID"
,
16
)
expect
(
Process
).
to
receive
(
:clock_gettime
)
.
with
(
16
,
kind_of
(
Symbol
))
.
and_return
(
0.111222333
,
0.222333833
)
expect
(
described_class
.
thread_cpu_duration
(
start_time
)).
to
eq
(
0.1111115
)
end
it
'returns nil on unsupported platform'
do
hide_const
(
"Process::CLOCK_THREAD_CPUTIME_ID"
)
expect
(
described_class
.
thread_cpu_duration
(
start_time
)).
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