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
Jérome Perrin
gitlab-ce
Commits
fd0a5168
Commit
fd0a5168
authored
Dec 12, 2017
by
Pawel Chojnacki
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use class variables instead of CONSTANTs
parent
ca176a9b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
8 deletions
+12
-8
lib/gitlab/metrics/method_call.rb
lib/gitlab/metrics/method_call.rb
+10
-6
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 @
fd0a5168
...
@@ -2,8 +2,8 @@ module Gitlab
...
@@ -2,8 +2,8 @@ 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
::
AtomicBoolean
.
new
(
false
)
@@measurement_enabled_cache
=
Concurrent
::
AtomicBoolean
.
new
(
false
)
MEASUREMENT_ENABLED_CACHE_EXPIRES_AT
=
Concurrent
::
AtomicFixnum
.
new
(
Time
.
now
.
to_i
)
@@measurement_enabled_cache_expires_at
=
Concurrent
::
AtomicFixnum
.
new
(
Time
.
now
.
to_i
)
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
...
@@ -20,6 +20,10 @@ module Gitlab
...
@@ -20,6 +20,10 @@ module Gitlab
end
end
end
end
def
self
.
measurement_enabled_cache_expires_at
@@measurement_enabled_cache_expires_at
end
# name - The full name of the method (including namespace) such as
# name - The full name of the method (including namespace) such as
# `User#sign_in`.
# `User#sign_in`.
#
#
...
@@ -74,14 +78,14 @@ module Gitlab
...
@@ -74,14 +78,14 @@ module Gitlab
end
end
def
call_measurement_enabled?
def
call_measurement_enabled?
expires_at
=
MEASUREMENT_ENABLED_CACHE_EXPIRES_AT
.
value
expires_at
=
@@measurement_enabled_cache_expires_at
.
value
if
expires_at
<
Time
.
now
.
to_i
if
expires_at
<
Time
.
now
.
to_i
if
MEASUREMENT_ENABLED_CACHE_EXPIRES_AT
.
compare_and_set
(
expires_at
,
(
Time
.
now
+
30
.
seconds
).
to_i
)
if
@@measurement_enabled_cache_expires_at
.
compare_and_set
(
expires_at
,
(
Time
.
now
+
30
.
seconds
).
to_i
)
MEASUREMENT_ENABLED_CACHE
.
value
=
Feature
.
get
(
:prometheus_metrics_method_instrumentation
).
enabled?
@@measurement_enabled_cache
.
value
=
Feature
.
get
(
:prometheus_metrics_method_instrumentation
).
enabled?
end
end
end
end
MEASUREMENT_ENABLED_CACHE
.
value
@@measurement_enabled_cache
.
value
end
end
end
end
end
end
...
...
spec/lib/gitlab/metrics/method_call_spec.rb
View file @
fd0a5168
...
@@ -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
::
MEASUREMENT_ENABLED_CACHE_EXPIRES_AT
.
value
=
Time
.
now
.
to_i
-
1
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
...
@@ -66,7 +66,7 @@ describe Gitlab::Metrics::MethodCall do
...
@@ -66,7 +66,7 @@ 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
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
...
...
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