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
Boxiang Sun
gitlab-ce
Commits
5904b033
Commit
5904b033
authored
Dec 11, 2017
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemente measurement enabled cache using AtomicReference
parent
6af84964
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
20 deletions
+15
-20
lib/gitlab/metrics/method_call.rb
lib/gitlab/metrics/method_call.rb
+13
-18
spec/lib/gitlab/metrics/method_call_spec.rb
spec/lib/gitlab/metrics/method_call_spec.rb
+2
-2
No files found.
lib/gitlab/metrics/method_call.rb
View file @
5904b033
...
@@ -2,6 +2,7 @@ module Gitlab
...
@@ -2,6 +2,7 @@ module Gitlab
module
Metrics
module
Metrics
# Class for tracking timing information about method calls
# Class for tracking timing information about method calls
class
MethodCall
class
MethodCall
MEASUREMENT_ENABLED_CACHE
=
Concurrent
::
AtomicReference
.
new
({
enabled:
false
,
expires_at:
Time
.
now
})
MUTEX
=
Mutex
.
new
MUTEX
=
Mutex
.
new
BASE_LABELS
=
{
module:
nil
,
method:
nil
}.
freeze
BASE_LABELS
=
{
module:
nil
,
method:
nil
}.
freeze
attr_reader
:real_time
,
:cpu_time
,
:call_count
,
:labels
attr_reader
:real_time
,
:cpu_time
,
:call_count
,
:labels
...
@@ -18,25 +19,19 @@ module Gitlab
...
@@ -18,25 +19,19 @@ module Gitlab
end
end
end
end
def
self
.
call_measurement_enabled?
def
call_measurement_enabled?
return
@call_measurement_enabled
unless
call_measurement_enabled_cache_expired?
res
=
MEASUREMENT_ENABLED_CACHE
.
update
do
|
cache
|
if
cache
[
:expires_at
]
<
Time
.
now
MUTEX
.
synchronize
do
{
return
@call_measurement_enabled
unless
call_measurement_enabled_cache_expired?
enabled:
Feature
.
get
(
:prometheus_metrics_method_instrumentation
).
enabled?
,
expires_at:
Time
.
now
+
5
.
minutes
@call_measurement_enabled
=
Feature
.
get
(
:prometheus_metrics_method_instrumentation
).
enabled?
}
@call_measurement_enabled_cache_expires_at
=
Time
.
now
+
5
.
minutes
else
@call_measurement_enabled
cache
end
end
end
end
def
self
.
call_measurement_enabled_cache_expired?
@call_measurement_enabled
.
nil?
||
@call_measurement_enabled_cache_expires_at
.
nil?
||
@call_measurement_enabled_cache_expires_at
<
Time
.
now
end
def
self
.
call_measurement_enabled_cache_expire
res
[
:enabled
]
@call_measurement_enabled
=
nil
@call_measurement_enabled_cache_expires_at
=
nil
end
end
# name - The full name of the method (including namespace) such as
# name - The full name of the method (including namespace) such as
...
@@ -66,7 +61,7 @@ module Gitlab
...
@@ -66,7 +61,7 @@ module Gitlab
@cpu_time
+=
cpu_time
@cpu_time
+=
cpu_time
@call_count
+=
1
@call_count
+=
1
if
self
.
class
.
call_measurement_enabled?
&&
above_threshold?
if
call_measurement_enabled?
&&
above_threshold?
self
.
class
.
call_duration_histogram
.
observe
(
@transaction
.
labels
.
merge
(
labels
),
real_time
/
1000.0
)
self
.
class
.
call_duration_histogram
.
observe
(
@transaction
.
labels
.
merge
(
labels
),
real_time
/
1000.0
)
end
end
...
...
spec/lib/gitlab/metrics/method_call_spec.rb
View file @
5904b033
...
@@ -21,7 +21,7 @@ describe Gitlab::Metrics::MethodCall do
...
@@ -21,7 +21,7 @@ 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
allow
(
Feature
.
get
(
:prometheus_metrics_method_instrumentation
)).
to
receive
(
:enabled?
).
and_call_original
described_class
.
call_measurement_enabled_cache_expire
described_class
::
MEASUREMENT_ENABLED_CACHE
.
set
({
enabled:
false
,
expires_at:
Time
.
now
-
1
.
second
})
Feature
.
get
(
:prometheus_metrics_method_instrumentation
).
enable
Feature
.
get
(
:prometheus_metrics_method_instrumentation
).
enable
end
end
...
@@ -62,7 +62,7 @@ describe Gitlab::Metrics::MethodCall do
...
@@ -62,7 +62,7 @@ describe Gitlab::Metrics::MethodCall do
context
'prometheus instrumentation is disabled'
do
context
'prometheus instrumentation is disabled'
do
before
do
before
do
described_class
.
call_measurement_enabled_cache_expire
described_class
::
MEASUREMENT_ENABLED_CACHE
.
set
({
enabled:
false
,
expires_at:
Time
.
now
})
Feature
.
get
(
:prometheus_metrics_method_instrumentation
).
disable
Feature
.
get
(
:prometheus_metrics_method_instrumentation
).
disable
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