Commit f5383578 authored by Pawel Chojnacki's avatar Pawel Chojnacki

NullMetric as a singleton

parent 3e898be8
......@@ -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
......
......@@ -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
......
......@@ -64,7 +64,7 @@ module Gitlab
if prometheus_metrics_enabled?
registry.get(name)
else
NullMetric.new
NullMetric.instance
end
end
......
......@@ -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
......
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