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
0051b5fb
Commit
0051b5fb
authored
Nov 23, 2017
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use only real duration to measure method call performance via Prometheus
parent
efe4cab9
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
35 deletions
+15
-35
db/migrate/20171122211913_add_prometheus_instrumentation_to_application_settings.rb
...add_prometheus_instrumentation_to_application_settings.rb
+0
-1
lib/gitlab/metrics/method_call.rb
lib/gitlab/metrics/method_call.rb
+6
-21
spec/lib/gitlab/metrics/method_call_spec.rb
spec/lib/gitlab/metrics/method_call_spec.rb
+9
-13
No files found.
db/migrate/20171122211913_add_prometheus_instrumentation_to_application_settings.rb
View file @
0051b5fb
...
...
@@ -13,4 +13,3 @@ class AddPrometheusInstrumentationToApplicationSettings < ActiveRecord::Migratio
remove_column
(
:application_settings
,
:prometheus_metrics_method_instrumentation_enabled
)
end
end
lib/gitlab/metrics/method_call.rb
View file @
0051b5fb
...
...
@@ -6,29 +6,15 @@ module Gitlab
BASE_LABELS
=
{
module:
nil
,
method:
nil
}.
freeze
attr_reader
:real_time
,
:cpu_time
,
:call_count
,
:labels
def
self
.
call_real_duration_histogram
return
@call_real_duration_histogram
if
@call_real_duration_histogram
MUTEX
.
synchronize
do
@call_real_duration_histogram
||=
Gitlab
::
Metrics
.
histogram
(
:gitlab_method_call_real_duration_seconds
,
'Method calls real duration'
,
Transaction
::
BASE_LABELS
.
merge
(
BASE_LABELS
),
[
0.1
,
0.2
,
0.5
,
1
,
2
,
5
,
10
]
)
end
end
def
self
.
call_cpu_duration_histogram
return
@call_cpu_duration_histogram
if
@call_cpu_duration_histogram
def
self
.
call_duration_histogram
return
@call_duration_histogram
if
@call_duration_histogram
MUTEX
.
synchronize
do
@call_duration_histogram
||=
Gitlab
::
Metrics
.
histogram
(
:gitlab_method_call_
cpu_
duration_seconds
,
'Method calls
cpu
duration'
,
:gitlab_method_call_duration_seconds
,
'Method calls
real
duration'
,
Transaction
::
BASE_LABELS
.
merge
(
BASE_LABELS
),
[
0.1
,
0.2
,
0.5
,
1
,
2
,
5
,
10
]
)
[
0.01
,
0.05
,
0.1
,
0.5
,
1
])
end
end
...
...
@@ -60,8 +46,7 @@ module Gitlab
@call_count
+=
1
if
prometheus_enabled?
&&
above_threshold?
self
.
class
.
call_real_duration_histogram
.
observe
(
@transaction
.
labels
.
merge
(
labels
),
real_time
/
1000.0
)
self
.
class
.
call_cpu_duration_histogram
.
observe
(
@transaction
.
labels
.
merge
(
labels
),
cpu_time
/
1000.0
)
self
.
class
.
call_duration_histogram
.
observe
(
@transaction
.
labels
.
merge
(
labels
),
real_time
/
1000.0
)
end
retval
...
...
spec/lib/gitlab/metrics/method_call_spec.rb
View file @
0051b5fb
...
...
@@ -25,11 +25,7 @@ describe Gitlab::Metrics::MethodCall do
end
it
'observes the performance of the supplied block'
do
expect
(
described_class
.
call_real_duration_histogram
)
.
to
receive
(
:observe
)
.
with
({
module: :Foo
,
method:
'#bar'
},
be_a_kind_of
(
Numeric
))
expect
(
described_class
.
call_cpu_duration_histogram
)
expect
(
described_class
.
call_duration_histogram
)
.
to
receive
(
:observe
)
.
with
({
module: :Foo
,
method:
'#bar'
},
be_a_kind_of
(
Numeric
))
...
...
@@ -44,10 +40,7 @@ describe Gitlab::Metrics::MethodCall do
end
it
'does not observe the performance'
do
expect
(
described_class
.
call_real_duration_histogram
)
.
not_to
receive
(
:observe
)
expect
(
described_class
.
call_cpu_duration_histogram
)
expect
(
described_class
.
call_duration_histogram
)
.
not_to
receive
(
:observe
)
method_call
.
measure
{
'foo'
}
...
...
@@ -64,10 +57,7 @@ describe Gitlab::Metrics::MethodCall do
end
it
'does not observe the performance'
do
expect
(
described_class
.
call_real_duration_histogram
)
.
not_to
receive
(
:observe
)
expect
(
described_class
.
call_cpu_duration_histogram
)
expect
(
described_class
.
call_duration_histogram
)
.
not_to
receive
(
:observe
)
method_call
.
measure
{
'foo'
}
...
...
@@ -92,7 +82,13 @@ describe Gitlab::Metrics::MethodCall do
end
describe
'#above_threshold?'
do
before
do
allow
(
Gitlab
::
Metrics
).
to
receive
(
:method_call_threshold
).
and_return
(
100
)
end
it
'returns false when the total call time is not above the threshold'
do
expect
(
method_call
).
to
receive
(
:real_time
).
and_return
(
9
)
expect
(
method_call
.
above_threshold?
).
to
eq
(
false
)
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