Commit f5383578 authored by Pawel Chojnacki's avatar Pawel Chojnacki

NullMetric as a singleton

parent 3e898be8
...@@ -34,7 +34,7 @@ module Gitlab ...@@ -34,7 +34,7 @@ module Gitlab
options.evaluate(&block) options.evaluate(&block)
if disabled_by_feature(options) if disabled_by_feature(options)
synchronized_cache_fill(name) { NullMetric.new } synchronized_cache_fill(name) { NullMetric.instance }
else else
synchronized_cache_fill(name) { build_metric!(type, name, options) } synchronized_cache_fill(name) { build_metric!(type, name, options) }
end end
......
...@@ -2,6 +2,8 @@ module Gitlab ...@@ -2,6 +2,8 @@ module Gitlab
module Metrics module Metrics
# Mocks ::Prometheus::Client::Metric and all derived metrics # Mocks ::Prometheus::Client::Metric and all derived metrics
class NullMetric class NullMetric
include Singleton
def method_missing(name, *args, &block) def method_missing(name, *args, &block)
nil nil
end end
......
...@@ -64,7 +64,7 @@ module Gitlab ...@@ -64,7 +64,7 @@ module Gitlab
if prometheus_metrics_enabled? if prometheus_metrics_enabled?
registry.get(name) registry.get(name)
else else
NullMetric.new NullMetric.instance
end end
end end
......
...@@ -53,7 +53,9 @@ describe Gitlab::Metrics::Concern do ...@@ -53,7 +53,9 @@ describe Gitlab::Metrics::Concern do
describe "#fetch_#{metric_type}" do describe "#fetch_#{metric_type}" do
let(:fetch_method) { "fetch_#{metric_type}".to_sym } 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 context "when #{metric_type} is not cached" do
it 'initializes counter metric' do it 'initializes counter metric' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment