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
Léo-Paul Géneau
gitlab-ce
Commits
d97548da
Commit
d97548da
authored
Jan 15, 2018
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cleanup method call
parent
e5d61415
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
35 deletions
+17
-35
lib/gitlab/metrics/concern.rb
lib/gitlab/metrics/concern.rb
+4
-2
lib/gitlab/metrics/method_call.rb
lib/gitlab/metrics/method_call.rb
+1
-1
spec/lib/gitlab/metrics/method_call_spec.rb
spec/lib/gitlab/metrics/method_call_spec.rb
+12
-32
No files found.
lib/gitlab/metrics/concern.rb
View file @
d97548da
...
@@ -43,12 +43,14 @@ module Gitlab
...
@@ -43,12 +43,14 @@ module Gitlab
return @@_metric_provider_cached_
#{
name
}
if @@_metric_provider_cached_
#{
name
}
return @@_metric_provider_cached_
#{
name
}
if @@_metric_provider_cached_
#{
name
}
@@_metrics_provider_mutex.synchronize do
@@_metrics_provider_mutex.synchronize do
puts "Initiaalized"
@@_metric_provider_cached_
#{
name
}
||=
#{
metric_fetching_code
}
@@_metric_provider_cached_
#{
name
}
||=
#{
metric_fetching_code
}
end
end
end
end
def reload_
#{
name
}
!
@@_metric_provider_cached_
#{
name
}
= nil
end
METRIC
METRIC
puts
method_code
instance_eval
(
method_code
,
__FILE__
,
line
)
instance_eval
(
method_code
,
__FILE__
,
line
)
module_eval
(
method_code
,
__FILE__
,
line
)
module_eval
(
method_code
,
__FILE__
,
line
)
...
...
lib/gitlab/metrics/method_call.rb
View file @
d97548da
...
@@ -41,7 +41,7 @@ module Gitlab
...
@@ -41,7 +41,7 @@ module Gitlab
@call_count
+=
1
@call_count
+=
1
if
above_threshold?
if
above_threshold?
gitlab_method_call_duration_seconds
.
observe
(
@transaction
.
labels
.
merge
(
labels
),
real_time
)
self
.
class
.
gitlab_method_call_duration_seconds
.
observe
(
@transaction
.
labels
.
merge
(
labels
),
real_time
)
end
end
retval
retval
...
...
spec/lib/gitlab/metrics/method_call_spec.rb
View file @
d97548da
...
@@ -5,6 +5,10 @@ describe Gitlab::Metrics::MethodCall do
...
@@ -5,6 +5,10 @@ describe Gitlab::Metrics::MethodCall do
let
(
:method_call
)
{
described_class
.
new
(
'Foo#bar'
,
:Foo
,
'#bar'
,
transaction
)
}
let
(
:method_call
)
{
described_class
.
new
(
'Foo#bar'
,
:Foo
,
'#bar'
,
transaction
)
}
describe
'#measure'
do
describe
'#measure'
do
before
do
described_class
.
reload_gitlab_method_call_duration_seconds!
end
it
'measures the performance of the supplied block'
do
it
'measures the performance of the supplied block'
do
method_call
.
measure
{
'foo'
}
method_call
.
measure
{
'foo'
}
...
@@ -20,8 +24,6 @@ describe Gitlab::Metrics::MethodCall do
...
@@ -20,8 +24,6 @@ describe Gitlab::Metrics::MethodCall do
context
'prometheus instrumentation is enabled'
do
context
'prometheus instrumentation is enabled'
do
before
do
before
do
allow
(
Feature
.
get
(
:prometheus_metrics_method_instrumentation
)).
to
receive
(
:enabled?
).
and_call_original
described_class
.
measurement_enabled_cache_expires_at
.
value
=
Time
.
now
.
to_i
-
1
Feature
.
get
(
:prometheus_metrics_method_instrumentation
).
enable
Feature
.
get
(
:prometheus_metrics_method_instrumentation
).
enable
end
end
...
@@ -31,30 +33,12 @@ describe Gitlab::Metrics::MethodCall do
...
@@ -31,30 +33,12 @@ describe Gitlab::Metrics::MethodCall do
end
end
end
end
it
'caches subsequent invocations of feature check'
do
it
'metric is not a NullMetric'
do
10
.
times
do
expect
(
described_class
).
not_to
be_instance_of
(
Gitlab
::
Metrics
::
NullMetric
)
method_call
.
measure
{
'foo'
}
end
expect
(
Feature
.
get
(
:prometheus_metrics_method_instrumentation
)).
to
have_received
(
:enabled?
).
once
end
it
'expires feature check cache after 1 minute'
do
method_call
.
measure
{
'foo'
}
Timecop
.
travel
(
1
.
minute
.
from_now
)
do
method_call
.
measure
{
'foo'
}
end
Timecop
.
travel
(
1
.
minute
.
from_now
+
1
.
second
)
do
method_call
.
measure
{
'foo'
}
end
expect
(
Feature
.
get
(
:prometheus_metrics_method_instrumentation
)).
to
have_received
(
:enabled?
).
twice
end
end
it
'observes the performance of the supplied block'
do
it
'observes the performance of the supplied block'
do
expect
(
described_class
.
call_duration_histogram
)
expect
(
described_class
.
gitlab_method_call_duration_seconds
)
.
to
receive
(
:observe
)
.
to
receive
(
:observe
)
.
with
({
module: :Foo
,
method:
'#bar'
},
be_a_kind_of
(
Numeric
))
.
with
({
module: :Foo
,
method:
'#bar'
},
be_a_kind_of
(
Numeric
))
...
@@ -64,14 +48,12 @@ describe Gitlab::Metrics::MethodCall do
...
@@ -64,14 +48,12 @@ describe Gitlab::Metrics::MethodCall do
context
'prometheus instrumentation is disabled'
do
context
'prometheus instrumentation is disabled'
do
before
do
before
do
described_class
.
measurement_enabled_cache_expires_at
.
value
=
Time
.
now
.
to_i
-
1
Feature
.
get
(
:prometheus_metrics_method_instrumentation
).
disable
Feature
.
get
(
:prometheus_metrics_method_instrumentation
).
disable
end
end
it
'
does not observe the performance
'
do
it
'
observes using NullMetric
'
do
expect
(
described_class
.
call_duration_histogram
)
expect
(
described_class
.
gitlab_method_call_duration_seconds
).
to
be_instance_of
(
Gitlab
::
Metrics
::
NullMetric
)
.
not_
to
receive
(
:observe
)
expect
(
described_class
.
gitlab_method_call_duration_seconds
).
to
receive
(
:observe
)
method_call
.
measure
{
'foo'
}
method_call
.
measure
{
'foo'
}
end
end
...
@@ -81,12 +63,10 @@ describe Gitlab::Metrics::MethodCall do
...
@@ -81,12 +63,10 @@ describe Gitlab::Metrics::MethodCall do
context
'when measurement is below threshold'
do
context
'when measurement is below threshold'
do
before
do
before
do
allow
(
method_call
).
to
receive
(
:above_threshold?
).
and_return
(
false
)
allow
(
method_call
).
to
receive
(
:above_threshold?
).
and_return
(
false
)
Feature
.
get
(
:prometheus_metrics_method_instrumentation
).
enable
end
end
it
'does not observe the performance'
do
it
'does not observe the performance'
do
expect
(
described_class
.
call_duration_histogram
)
expect
(
described_class
.
gitlab_method_call_duration_seconds
)
.
not_to
receive
(
:observe
)
.
not_to
receive
(
:observe
)
method_call
.
measure
{
'foo'
}
method_call
.
measure
{
'foo'
}
...
@@ -96,7 +76,7 @@ describe Gitlab::Metrics::MethodCall do
...
@@ -96,7 +76,7 @@ describe Gitlab::Metrics::MethodCall do
describe
'#to_metric'
do
describe
'#to_metric'
do
it
'returns a Metric instance'
do
it
'returns a Metric instance'
do
expect
(
method_call
).
to
receive
(
:real_time
).
and_return
(
4.0001
)
expect
(
method_call
).
to
receive
(
:real_time
).
and_return
(
4.0001
)
.
twice
expect
(
method_call
).
to
receive
(
:cpu_time
).
and_return
(
3.0001
)
expect
(
method_call
).
to
receive
(
:cpu_time
).
and_return
(
3.0001
)
method_call
.
measure
{
'foo'
}
method_call
.
measure
{
'foo'
}
...
...
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