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
diff options
context:
space:
mode:
authorPawel Chojnacki <pawel@chojnacki.ws>2018-01-18 22:22:49 +0300
committerPawel Chojnacki <pawel@chojnacki.ws>2018-01-29 17:13:04 +0300
commit3e898be8aa80993a8af016b351c796beb8750d2e (patch)
treef1101e171c5dcaf2c0aa8dd49a6b3520b7ece9fc /lib/gitlab/metrics
parent6ff9f028fd09b5ebd941f63a1aecc134741ef27e (diff)
Avoid cascading locking
Diffstat (limited to 'lib/gitlab/metrics')
-rw-r--r--lib/gitlab/metrics/concern.rb18
1 files changed, 12 insertions, 6 deletions
diff --git a/lib/gitlab/metrics/concern.rb b/lib/gitlab/metrics/concern.rb
index 6a05fb9b815..11852f50319 100644
--- a/lib/gitlab/metrics/concern.rb
+++ b/lib/gitlab/metrics/concern.rb
@@ -33,19 +33,25 @@ module Gitlab
options = MetricOptions.new(opts)
options.evaluate(&block)
+ if disabled_by_feature(options)
+ synchronized_cache_fill(name) { NullMetric.new }
+ else
+ synchronized_cache_fill(name) { build_metric!(type, name, options) }
+ end
+ end
+
+ def synchronized_cache_fill(key)
MUTEX.synchronize do
@_metrics_provider_cache ||= {}
- @_metrics_provider_cache[name] ||= build_metric!(type, name, options)
+ @_metrics_provider_cache[key] ||= yield
end
+ end
- @_metrics_provider_cache[name]
+ def disabled_by_feature(options)
+ options.with_feature && !Feature.get(options.with_feature).enabled?
end
def build_metric!(type, name, options)
- unless options.with_feature.nil? || Feature.get(options.with_feature).enabled?
- return NullMetric.new
- end
-
case type
when :gauge
Gitlab::Metrics.gauge(name, options.docstring, options.base_labels, options.multiprocess_mode)