diff options
author | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-05-29 15:19:43 +0300 |
---|---|---|
committer | Pawel Chojnacki <pawel@chojnacki.ws> | 2017-06-02 20:45:58 +0300 |
commit | c134a72cdb7e6de8b70dc60de99cf4edc68a9227 (patch) | |
tree | 0082ba4d422cc53eea223583bca9c98cbc823c96 /spec/lib/gitlab | |
parent | 770f07cd5c68075bb261f4b6139c92b2ac9309c0 (diff) |
Move Prometheus presentation logic to PrometheusText
+ Use NullMetrics to mock metrics when unused
+ Use method_missing in NullMetrics mocking
+ Update prometheus gem to version that correctly uses transitive dependencies
+ Ensure correct folders are used in Multiprocess prometheus client tests.
+ rename Sessions controller's metric
Diffstat (limited to 'spec/lib/gitlab')
-rw-r--r-- | spec/lib/gitlab/metrics_spec.rb | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/spec/lib/gitlab/metrics_spec.rb b/spec/lib/gitlab/metrics_spec.rb index 863868e1576..87c9f4ebda4 100644 --- a/spec/lib/gitlab/metrics_spec.rb +++ b/spec/lib/gitlab/metrics_spec.rb @@ -1,6 +1,8 @@ require 'spec_helper' describe Gitlab::Metrics do + include StubENV + describe '.settings' do it 'returns a Hash' do expect(described_class.settings).to be_an_instance_of(Hash) @@ -247,45 +249,53 @@ describe Gitlab::Metrics do it_behaves_like 'prometheus metrics API' - describe '#dummy_metric' do + describe '#null_metric' do subject { described_class.provide_metric(:test) } - it { is_expected.to be_a(Gitlab::Metrics::DummyMetric) } + it { is_expected.to be_a(Gitlab::Metrics::NullMetric) } end describe '#counter' do subject { described_class.counter(:counter, 'doc') } - it { is_expected.to be_a(Gitlab::Metrics::DummyMetric) } + it { is_expected.to be_a(Gitlab::Metrics::NullMetric) } end describe '#summary' do subject { described_class.summary(:summary, 'doc') } - it { is_expected.to be_a(Gitlab::Metrics::DummyMetric) } + it { is_expected.to be_a(Gitlab::Metrics::NullMetric) } end describe '#gauge' do subject { described_class.gauge(:gauge, 'doc') } - it { is_expected.to be_a(Gitlab::Metrics::DummyMetric) } + it { is_expected.to be_a(Gitlab::Metrics::NullMetric) } end describe '#histogram' do subject { described_class.histogram(:histogram, 'doc') } - it { is_expected.to be_a(Gitlab::Metrics::DummyMetric) } + it { is_expected.to be_a(Gitlab::Metrics::NullMetric) } end end context 'prometheus metrics enabled' do + around do |example| + Dir.mktmpdir do |tmp_dir| + @metrics_multiproc_dir = tmp_dir + example.run + end + end + before do + stub_const('Prometheus::Client::Multiprocdir', @metrics_multiproc_dir) allow(described_class).to receive(:prometheus_metrics_enabled?).and_return(true) end it_behaves_like 'prometheus metrics API' - describe '#dummy_metric' do + describe '#null_metric' do subject { described_class.provide_metric(:test) } it { is_expected.to be_nil } @@ -294,25 +304,25 @@ describe Gitlab::Metrics do describe '#counter' do subject { described_class.counter(:name, 'doc') } - it { is_expected.not_to be_a(Gitlab::Metrics::DummyMetric) } + it { is_expected.not_to be_a(Gitlab::Metrics::NullMetric) } end describe '#summary' do subject { described_class.summary(:name, 'doc') } - it { is_expected.not_to be_a(Gitlab::Metrics::DummyMetric) } + it { is_expected.not_to be_a(Gitlab::Metrics::NullMetric) } end describe '#gauge' do subject { described_class.gauge(:name, 'doc') } - it { is_expected.not_to be_a(Gitlab::Metrics::DummyMetric) } + it { is_expected.not_to be_a(Gitlab::Metrics::NullMetric) } end describe '#histogram' do subject { described_class.histogram(:name, 'doc') } - it { is_expected.not_to be_a(Gitlab::Metrics::DummyMetric) } + it { is_expected.not_to be_a(Gitlab::Metrics::NullMetric) } end end end |