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:
authorPawel Chojnacki <pawel@chojnacki.ws>2017-12-08 21:36:30 +0300
committerPawel Chojnacki <pawel@chojnacki.ws>2017-12-12 20:38:28 +0300
commitb503e6ff423699f7556fb948051e9c180a7b89f0 (patch)
tree6d98ffe63aebc7f349a0288e15ee3f723d463617 /lib
parent53dc9e83c34b2a0ee2651046de031566f5b925d2 (diff)
Implement simple in memory cache that expires after 5 minutes
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/metrics/method_call.rb26
1 files changed, 19 insertions, 7 deletions
diff --git a/lib/gitlab/metrics/method_call.rb b/lib/gitlab/metrics/method_call.rb
index ab7e7a06a77..744c489d46e 100644
--- a/lib/gitlab/metrics/method_call.rb
+++ b/lib/gitlab/metrics/method_call.rb
@@ -18,6 +18,24 @@ 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_cache_expires_at = Time.now + 5.minutes
+ @call_measurement_enabled = Feature.get(:prometheus_metrics_method_instrumentation).enabled?
+ 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
+ end
+
# name - The full name of the method (including namespace) such as
# `User#sign_in`.
#
@@ -45,7 +63,7 @@ module Gitlab
@cpu_time += cpu_time
@call_count += 1
- if call_measurement_enabled? && above_threshold?
+ if self.class.call_measurement_enabled? && above_threshold?
self.class.call_duration_histogram.observe(@transaction.labels.merge(labels), real_time / 1000.0)
end
@@ -70,12 +88,6 @@ module Gitlab
def above_threshold?
real_time >= Metrics.method_call_threshold
end
-
- def call_measurement_enabled?
- Rails.cache.fetch(:prometheus_metrics_method_instrumentation_enabled, expires_in: 5.minutes) do
- Feature.get(:prometheus_metrics_method_instrumentation).enabled?
- end
- end
end
end
end