BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
efe4cab9
Commit
efe4cab9
authored
Nov 23, 2017
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
check method timing threshold when observing method performance
parent
84c5260f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
10 deletions
+59
-10
method_call.rb
lib/gitlab/metrics/method_call.rb
+2
-2
method_call_spec.rb
spec/lib/gitlab/metrics/method_call_spec.rb
+57
-8
No files found.
lib/gitlab/metrics/method_call.rb
View file @
efe4cab9
...
...
@@ -59,7 +59,7 @@ module Gitlab
@cpu_time
+=
cpu_time
@call_count
+=
1
if
prometheus_enabled?
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
)
end
...
...
@@ -87,7 +87,7 @@ module Gitlab
end
def
prometheus_enabled?
@prometheus_enabled
||=
current_application_settings
(
:prometheus_metrics_method_instrumentation_enabled
)
@prometheus_enabled
||=
Gitlab
::
CurrentSettings
.
current_application_settings
[
:prometheus_metrics_method_instrumentation_enabled
]
end
end
end
...
...
spec/lib/gitlab/metrics/method_call_spec.rb
View file @
efe4cab9
...
...
@@ -13,16 +13,65 @@ describe Gitlab::Metrics::MethodCall do
expect
(
method_call
.
call_count
).
to
eq
(
1
)
end
it
'observes the performance of the supplied block
'
do
expect
(
described_class
.
call_real_duration_histogram
)
.
to
receive
(
:observ
e
)
.
with
({
module: :Foo
,
method:
'#bar'
},
be_a_kind_of
(
Numeric
))
context
'when measurement is above threshold
'
do
before
do
allow
(
method_call
).
to
receive
(
:above_threshold?
).
and_return
(
tru
e
)
end
expect
(
described_class
.
call_cpu_duration_histogram
)
.
to
receive
(
:observe
)
.
with
({
module: :Foo
,
method:
'#bar'
},
be_a_kind_of
(
Numeric
))
context
'prometheus instrumentation is enabled'
do
before
do
allow
(
Gitlab
::
CurrentSettings
).
to
receive
(
:current_application_settings
)
.
and_return
(
prometheus_metrics_method_instrumentation_enabled:
true
)
end
method_call
.
measure
{
'foo'
}
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
)
.
to
receive
(
:observe
)
.
with
({
module: :Foo
,
method:
'#bar'
},
be_a_kind_of
(
Numeric
))
method_call
.
measure
{
'foo'
}
end
end
context
'prometheus instrumentation is disabled'
do
before
do
allow
(
Gitlab
::
CurrentSettings
).
to
receive
(
:current_application_settings
)
.
and_return
(
prometheus_metrics_method_instrumentation_enabled:
false
)
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
)
.
not_to
receive
(
:observe
)
method_call
.
measure
{
'foo'
}
end
end
end
context
'when measurement is below threshold'
do
before
do
allow
(
method_call
).
to
receive
(
:above_threshold?
).
and_return
(
false
)
allow
(
Gitlab
::
CurrentSettings
).
to
receive
(
:current_application_settings
)
.
and_return
(
prometheus_metrics_method_instrumentation_enabled:
true
)
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
)
.
not_to
receive
(
:observe
)
method_call
.
measure
{
'foo'
}
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