Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRobert Speicher <robert@gitlab.com>2017-12-13 21:46:40 +0300
committerRobert Speicher <robert@gitlab.com>2017-12-13 21:46:40 +0300
commit83998c0a33c70c786f48eef5ce723eb6dd76761f (patch)
tree916201803f9e34b0a4803622548eee8d6484f882 /lib
parent4fe92b1de16469e0f8534d7c85d3e8b5c868b558 (diff)
parentdb9e5bf75e8546649ddd65a5696ff4edb87ded20 (diff)
Merge branch 'pawel/cache_feature_check_for_5_minutes_for_method_call' into 'master'
Cache feature check for 1 minute for MethodCall instrumentation toggle See merge request gitlab-org/gitlab-ce!15800
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/metrics/method_call.rb17
1 files changed, 16 insertions, 1 deletions
diff --git a/lib/gitlab/metrics/method_call.rb b/lib/gitlab/metrics/method_call.rb
index 65d55576ac2..9112164f22e 100644
--- a/lib/gitlab/metrics/method_call.rb
+++ b/lib/gitlab/metrics/method_call.rb
@@ -1,7 +1,11 @@
+# rubocop:disable Style/ClassVars
+
module Gitlab
module Metrics
# Class for tracking timing information about method calls
class MethodCall
+ @@measurement_enabled_cache = Concurrent::AtomicBoolean.new(false)
+ @@measurement_enabled_cache_expires_at = Concurrent::AtomicFixnum.new(Time.now.to_i)
MUTEX = Mutex.new
BASE_LABELS = { module: nil, method: nil }.freeze
attr_reader :real_time, :cpu_time, :call_count, :labels
@@ -18,6 +22,10 @@ module Gitlab
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
# `User#sign_in`.
#
@@ -72,7 +80,14 @@ module Gitlab
end
def call_measurement_enabled?
- Feature.get(:prometheus_metrics_method_instrumentation).enabled?
+ expires_at = @@measurement_enabled_cache_expires_at.value
+ if expires_at < Time.now.to_i
+ if @@measurement_enabled_cache_expires_at.compare_and_set(expires_at, 1.minute.from_now.to_i)
+ @@measurement_enabled_cache.value = Feature.get(:prometheus_metrics_method_instrumentation).enabled?
+ end
+ end
+
+ @@measurement_enabled_cache.value
end
end
end