summaryrefslogtreecommitdiff
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
parent3e898be8aa80993a8af016b351c796beb8750d2e (diff)
downloadgitlab-ce-f5383578d92d525881bae909740306c57fb1cca0.tar.gz
NullMetric as a singleton
-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
-rw-r--r--spec/lib/gitlab/metrics/concern_spec.rb4
4 files changed, 7 insertions, 3 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
diff --git a/spec/lib/gitlab/metrics/concern_spec.rb b/spec/lib/gitlab/metrics/concern_spec.rb
index 1f750397750..9d0eddc7355 100644
--- a/spec/lib/gitlab/metrics/concern_spec.rb
+++ b/spec/lib/gitlab/metrics/concern_spec.rb
@@ -53,7 +53,9 @@ describe Gitlab::Metrics::Concern do
describe "#fetch_#{metric_type}" do
let(:fetch_method) { "fetch_#{metric_type}".to_sym }
- let(:null_metric) { Gitlab::Metrics::NullMetric.new }
+ let(:_metric_type) { metric_type }
+
+ let(:null_metric) { Gitlab::Metrics::NullMetric.instance }
context "when #{metric_type} is not cached" do
it 'initializes counter metric' do