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
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
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
20 deletions
+15
-20
method_call.rb
lib/gitlab/metrics/method_call.rb
+13
-18
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
module
Metrics
# Class for tracking timing information about method calls
class
MethodCall
MEASUREMENT_ENABLED_CACHE
=
Concurrent
::
AtomicReference
.
new
({
enabled:
false
,
expires_at:
Time
.
now
})
MUTEX
=
Mutex
.
new
BASE_LABELS
=
{
module:
nil
,
method:
nil
}.
freeze
attr_reader
:real_time
,
:cpu_time
,
:call_count
,
:labels
...
...
@@ -18,25 +19,19 @@ module Gitlab
end
end
def
self
.
call_measurement_enabled?
return
@call_measurement_enabled
unless
call_measurement_enabled_cache_expired?
MUTEX
.
synchronize
do
return
@call_measurement_enabled
unless
call_measurement_enabled_cache_expired?
@call_measurement_enabled
=
Feature
.
get
(
:prometheus_metrics_method_instrumentation
).
enabled?
@call_measurement_enabled_cache_expires_at
=
Time
.
now
+
5
.
minutes
@call_measurement_enabled
def
call_measurement_enabled?
res
=
MEASUREMENT_ENABLED_CACHE
.
update
do
|
cache
|
if
cache
[
:expires_at
]
<
Time
.
now
{
enabled:
Feature
.
get
(
:prometheus_metrics_method_instrumentation
).
enabled?
,
expires_at:
Time
.
now
+
5
.
minutes
}
else
cache
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
@call_measurement_enabled
=
nil
@call_measurement_enabled_cache_expires_at
=
nil
res
[
:enabled
]
end
# name - The full name of the method (including namespace) such as
...
...
@@ -66,7 +61,7 @@ module Gitlab
@cpu_time
+=
cpu_time
@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
)
end
...
...
spec/lib/gitlab/metrics/method_call_spec.rb
View file @
5904b033
...
...
@@ -21,7 +21,7 @@ describe Gitlab::Metrics::MethodCall do
context
'prometheus instrumentation is enabled'
do
before
do
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
end
...
...
@@ -62,7 +62,7 @@ describe Gitlab::Metrics::MethodCall do
context
'prometheus instrumentation is disabled'
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
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