summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPawel Chojnacki <pawel@chojnacki.ws>2018-01-19 14:54:06 +0100
committerPawel Chojnacki <pawel@chojnacki.ws>2018-01-29 15:13:04 +0100
commitf5383578d92d525881bae909740306c57fb1cca0 (patch)
treee8c75c2d982074b668a96d7ebc1312ca90e2a6aa /lib
parent3e898be8aa80993a8af016b351c796beb8750d2e (diff)
downloadgitlab-ce-f5383578d92d525881bae909740306c57fb1cca0.tar.gz
NullMetric as a singleton
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/metrics/concern.rb2
-rw-r--r--lib/gitlab/metrics/null_metric.rb2
-rw-r--r--lib/gitlab/metrics/prometheus.rb2
3 files changed, 4 insertions, 2 deletions
diff --git a/lib/gitlab/metrics/concern.rb b/lib/gitlab/metrics/concern.rb
index 11852f50319..95a50d8b461 100644
--- a/lib/gitlab/metrics/concern.rb
+++ b/lib/gitlab/metrics/concern.rb
@@ -34,7 +34,7 @@ module Gitlab
options.evaluate(&block)
if disabled_by_feature(options)
- synchronized_cache_fill(name) { NullMetric.new }
+ synchronized_cache_fill(name) { NullMetric.instance }
else
synchronized_cache_fill(name) { build_metric!(type, name, options) }
end
diff --git a/lib/gitlab/metrics/null_metric.rb b/lib/gitlab/metrics/null_metric.rb
index 3b5a2907195..aabada5c21a 100644
--- a/lib/gitlab/metrics/null_metric.rb
+++ b/lib/gitlab/metrics/null_metric.rb
@@ -2,6 +2,8 @@ module Gitlab
module Metrics
# Mocks ::Prometheus::Client::Metric and all derived metrics
class NullMetric
+ include Singleton
+
def method_missing(name, *args, &block)
nil
end
diff --git a/lib/gitlab/metrics/prometheus.rb b/lib/gitlab/metrics/prometheus.rb
index b0b8e8436db..a697e61dd6b 100644
--- a/lib/gitlab/metrics/prometheus.rb
+++ b/lib/gitlab/metrics/prometheus.rb
@@ -64,7 +64,7 @@ module Gitlab
if prometheus_metrics_enabled?
registry.get(name)
else
- NullMetric.new
+ NullMetric.instance
end
end