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
0
Merge Requests
0
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
Jérome Perrin
gitlab-ce
Commits
6db3151f
Commit
6db3151f
authored
Sep 06, 2017
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduce missing Action concept
parent
c97dc61a
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
62 additions
and
33 deletions
+62
-33
lib/gitlab/metrics/method_call.rb
lib/gitlab/metrics/method_call.rb
+19
-16
lib/gitlab/metrics/subscribers/active_record.rb
lib/gitlab/metrics/subscribers/active_record.rb
+2
-2
lib/gitlab/metrics/subscribers/rails_cache.rb
lib/gitlab/metrics/subscribers/rails_cache.rb
+35
-9
lib/gitlab/metrics/transaction.rb
lib/gitlab/metrics/transaction.rb
+6
-6
No files found.
lib/gitlab/metrics/method_call.rb
View file @
6db3151f
...
@@ -4,26 +4,29 @@ module Gitlab
...
@@ -4,26 +4,29 @@ module Gitlab
class
MethodCall
class
MethodCall
attr_reader
:real_time
,
:cpu_time
,
:call_count
attr_reader
:real_time
,
:cpu_time
,
:call_count
# name - The full name of the method (including namespace) such as
# `User#sign_in`.
#
def
self
.
call_real_duration_histogram
def
self
.
call_real_duration_histogram
@call_real_duration_histogram
||=
Gitlab
::
Metrics
.
histogram
(
:gitlab_method_call_real_duration_milliseconds
,
@call_real_duration_histogram
||=
Gitlab
::
Metrics
.
histogram
(
:gitlab_method_call_real_duration_seconds
,
'Method calls real duration'
,
'Method calls real duration'
,
{
call_name:
nil
},
{
action:
nil
,
call_name:
nil
},
[
1
,
2
,
5
,
10
,
20
,
50
,
100
,
1000
])
[
1000
,
2000
,
5000
,
10000
,
20000
,
50000
,
100000
,
1000000
]
)
end
end
def
self
.
call_cpu_duration_histogram
def
self
.
call_cpu_duration_histogram
@call_duration_histogram
||=
Gitlab
::
Metrics
.
histogram
(
:gitlab_method_call_cpu_duration_milliseconds
,
@call_duration_histogram
||=
Gitlab
::
Metrics
.
histogram
(
:gitlab_method_call_cpu_duration_seconds
,
'Method calls cpu duration'
,
'Method calls cpu duration'
,
{
call_name:
nil
},
{
action:
nil
,
call_name:
nil
},
[
1
,
2
,
5
,
10
,
20
,
50
,
100
,
1000
])
[
1000
,
2000
,
5000
,
10000
,
20000
,
50000
,
100000
,
1000000
]
)
end
end
# name - The full name of the method (including namespace) such as
def
initialize
(
name
)
# `User#sign_in`.
#
def
initialize
(
name
,
action
)
@action
=
action
@name
=
name
@name
=
name
@real_time
=
0
@real_time
=
0
@cpu_time
=
0
@cpu_time
=
0
...
@@ -41,8 +44,8 @@ module Gitlab
...
@@ -41,8 +44,8 @@ module Gitlab
@call_count
+=
1
@call_count
+=
1
if
above_threshold?
if
above_threshold?
self
.
class
.
call_real_duration_histogram
.
observe
({
call_name:
@name
},
@real_time
)
self
.
class
.
call_real_duration_histogram
.
observe
({
call_name:
@name
,
action:
@action
},
@real_time
)
self
.
class
.
call_cpu_duration_histogram
.
observe
({
call_name:
@name
},
@cpu_time
)
self
.
class
.
call_cpu_duration_histogram
.
observe
({
call_name:
@name
,
action:
@action
},
@cpu_time
)
end
end
retval
retval
...
...
lib/gitlab/metrics/subscribers/active_record.rb
View file @
6db3151f
...
@@ -8,14 +8,14 @@ module Gitlab
...
@@ -8,14 +8,14 @@ module Gitlab
def
self
.
metric_sql_duration_seconds
def
self
.
metric_sql_duration_seconds
@metric_sql_duration_seconds
||=
Gitlab
::
Metrics
.
histogram
(
@metric_sql_duration_seconds
||=
Gitlab
::
Metrics
.
histogram
(
:gitlab_sql_duration_seconds
,
:gitlab_sql_duration_seconds
,
'SQL
duration seconds
'
,
'SQL
time
'
,
{},
{},
[
0.001
,
0.002
,
0.005
,
0.01
,
0.02
,
0.05
,
0.1
,
0.500
,
2.0
,
10.0
]
[
0.001
,
0.002
,
0.005
,
0.01
,
0.02
,
0.05
,
0.1
,
0.500
,
2.0
,
10.0
]
)
)
end
end
def
sql
(
event
)
def
sql
(
event
)
self
.
class
.
metric_sql_duration_secodnds
.
observe
({},
event
.
duration
/
1000.0
)
self
.
class
.
metric_sql_duration_secodnds
.
observe
({},
event
.
duration
/
1000.0
)
return
unless
current_transaction
return
unless
current_transaction
current_transaction
.
increment
(
:sql_duration
,
event
.
duration
,
false
)
current_transaction
.
increment
(
:sql_duration
,
event
.
duration
,
false
)
...
...
lib/gitlab/metrics/subscribers/rails_cache.rb
View file @
6db3151f
...
@@ -6,54 +6,80 @@ module Gitlab
...
@@ -6,54 +6,80 @@ module Gitlab
class
RailsCache
<
ActiveSupport
::
Subscriber
class
RailsCache
<
ActiveSupport
::
Subscriber
attach_to
:active_support
attach_to
:active_support
def
self
.
metric_cache_duration_seconds
@metric_cache_duration_seconds
||=
Gitlab
::
Metrics
.
histogram
(
:gitlab_cache_duration_seconds
,
'Cache access time'
,
{
action:
nil
,
operation:
nil
},
[
0.001
,
0.002
,
0.005
,
0.01
,
0.02
,
0.05
,
0.1
,
0.500
,
2.0
,
10.0
]
)
end
def
self
.
metric_cache_read_hit_total
@metric_cache_read_hit_total
||=
Gitlab
::
Metrics
.
counter
(
:gitlab_cache_read_hit_total
,
'Cache read hit'
,
{
action:
nil
})
end
def
self
.
metric_cache_read_miss_total
@metric_cache_read_miss_total
||=
Gitlab
::
Metrics
.
counter
(
:gitlab_cache_read_miss_total
,
'Cache read miss'
,
{
action:
nil
})
end
def
cache_read
(
event
)
def
cache_read
(
event
)
increment
(
:cache_
read
,
event
.
duration
)
observe
(
:
read
,
event
.
duration
)
return
unless
current_transaction
return
unless
current_transaction
return
if
event
.
payload
[
:super_operation
]
==
:fetch
return
if
event
.
payload
[
:super_operation
]
==
:fetch
if
event
.
payload
[
:hit
]
if
event
.
payload
[
:hit
]
self
.
class
.
metric_cache_read_hit_total
.
increment
({
action:
action
})
current_transaction
.
increment
(
:cache_read_hit_count
,
1
)
current_transaction
.
increment
(
:cache_read_hit_count
,
1
)
else
else
self
.
class
.
metric_cache_read_miss_total
.
increment
({
action:
action
})
current_transaction
.
increment
(
:cache_read_miss_count
,
1
)
current_transaction
.
increment
(
:cache_read_miss_count
,
1
)
end
end
end
end
def
cache_write
(
event
)
def
cache_write
(
event
)
increment
(
:cache_
write
,
event
.
duration
)
observe
(
:
write
,
event
.
duration
)
end
end
def
cache_delete
(
event
)
def
cache_delete
(
event
)
increment
(
:cache_
delete
,
event
.
duration
)
observe
(
:
delete
,
event
.
duration
)
end
end
def
cache_exist?
(
event
)
def
cache_exist?
(
event
)
increment
(
:cache_
exists
,
event
.
duration
)
observe
(
:
exists
,
event
.
duration
)
end
end
def
cache_fetch_hit
(
event
)
def
cache_fetch_hit
(
event
)
return
unless
current_transaction
return
unless
current_transaction
self
.
class
.
metric_cache_read_hit_total
.
increment
({
action:
action
})
current_transaction
.
increment
(
:cache_read_hit_count
,
1
)
current_transaction
.
increment
(
:cache_read_hit_count
,
1
)
end
end
def
cache_generate
(
event
)
def
cache_generate
(
event
)
return
unless
current_transaction
return
unless
current_transaction
self
.
class
.
metric_cache_read_miss_total
.
increment
({
action:
action
})
current_transaction
.
increment
(
:cache_read_miss_count
,
1
)
current_transaction
.
increment
(
:cache_read_miss_count
,
1
)
end
end
def
increment
(
key
,
duration
)
def
observe
(
key
,
duration
)
return
unless
current_transaction
return
unless
current_transaction
current_transaction
.
increment
(
:cache_duration
,
duration
)
metric_cache_duration_seconds
.
observe
({
operation:
key
,
action:
action
},
duration
/
1000.1
)
current_transaction
.
increment
(
:cache_count
,
1
)
current_transaction
.
increment
(
:cache_duration
,
duration
,
false
)
current_transaction
.
increment
(
"
#{
key
}
_duration"
.
to_sym
,
duration
)
current_transaction
.
increment
(
:cache_count
,
1
,
false
)
current_transaction
.
increment
(
"
#{
key
}
_count"
.
to_sym
,
1
)
current_transaction
.
increment
(
"
#{
key
}
_duration"
.
to_sym
,
duration
,
false
)
current_transaction
.
increment
(
"
#{
key
}
_count"
.
to_sym
,
1
,
false
)
end
end
private
private
def
action
current_transaction
&
.
action
end
def
current_transaction
def
current_transaction
Transaction
.
current
Transaction
.
current
end
end
...
...
lib/gitlab/metrics/transaction.rb
View file @
6db3151f
...
@@ -43,8 +43,8 @@ module Gitlab
...
@@ -43,8 +43,8 @@ module Gitlab
def
self
.
metric_transaction_duration_seconds
def
self
.
metric_transaction_duration_seconds
@metric_transaction_duration_seconds
||=
Gitlab
::
Metrics
.
histogram
(
@metric_transaction_duration_seconds
||=
Gitlab
::
Metrics
.
histogram
(
:gitlab_transaction_duration_seconds
,
:gitlab_transaction_duration_seconds
,
'Transaction duration
seconds
'
,
'Transaction duration'
,
{},
{
action:
nil
},
[
0.001
,
0.002
,
0.005
,
0.01
,
0.02
,
0.05
,
0.1
,
0.500
,
2.0
,
10.0
]
[
0.001
,
0.002
,
0.005
,
0.01
,
0.02
,
0.05
,
0.1
,
0.500
,
2.0
,
10.0
]
)
)
end
end
...
@@ -53,7 +53,7 @@ module Gitlab
...
@@ -53,7 +53,7 @@ module Gitlab
@metric_transaction_allocated_memory_bytes
||=
Gitlab
::
Metrics
.
histogram
(
@metric_transaction_allocated_memory_bytes
||=
Gitlab
::
Metrics
.
histogram
(
:gitlab_transaction_allocated_memory_bytes
,
:gitlab_transaction_allocated_memory_bytes
,
'Transaction allocated memory bytes'
,
'Transaction allocated memory bytes'
,
{},
{
action:
nil
},
[
500000
,
1000000
,
2000000
,
5000000
,
10000000
,
20000000
,
100000000
]
[
500000
,
1000000
,
2000000
,
5000000
,
10000000
,
20000000
,
100000000
]
)
)
end
end
...
@@ -69,8 +69,8 @@ module Gitlab
...
@@ -69,8 +69,8 @@ module Gitlab
@memory_after
=
System
.
memory_usage
@memory_after
=
System
.
memory_usage
@finished_at
=
System
.
monotonic_time
@finished_at
=
System
.
monotonic_time
Transaction
.
metric_transaction_duration_seconds
.
observe
({},
duration
*
1000
)
Transaction
.
metric_transaction_duration_seconds
.
observe
({
action:
action
},
duration
*
1000
)
Transaction
.
metric_transaction_allocated_memory_bytes
.
observe
({},
allocated_memory
/
2
^
20
)
Transaction
.
metric_transaction_allocated_memory_bytes
.
observe
({
action:
action
},
allocated_memory
/
2
^
20
)
Thread
.
current
[
THREAD_KEY
]
=
nil
Thread
.
current
[
THREAD_KEY
]
=
nil
end
end
...
@@ -94,7 +94,7 @@ module Gitlab
...
@@ -94,7 +94,7 @@ module Gitlab
# Returns a MethodCall object for the given name.
# Returns a MethodCall object for the given name.
def
method_call_for
(
name
)
def
method_call_for
(
name
)
unless
method
=
@methods
[
name
]
unless
method
=
@methods
[
name
]
@methods
[
name
]
=
method
=
MethodCall
.
new
(
name
)
@methods
[
name
]
=
method
=
MethodCall
.
new
(
name
,
action
)
end
end
method
method
...
...
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