NullMetric as a singleton
This commit is contained in:
parent
3e898be8aa
commit
f5383578d9
4 changed files with 7 additions and 3 deletions
|
@ -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
|
||||||
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
|
||||||
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
|
||||||
|
|
||||||
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
|
||||||
|
|
Loading…
Reference in a new issue