diff options
Diffstat (limited to 'spec/lib/gitlab/metrics_spec.rb')
-rw-r--r-- | spec/lib/gitlab/metrics_spec.rb | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/spec/lib/gitlab/metrics_spec.rb b/spec/lib/gitlab/metrics_spec.rb index 208a8d028cd..65bd06cda08 100644 --- a/spec/lib/gitlab/metrics_spec.rb +++ b/spec/lib/gitlab/metrics_spec.rb @@ -13,6 +13,18 @@ describe Gitlab::Metrics do end end + describe '.prometheus_metrics_enabled?' do + it 'returns a boolean' do + expect([true, false].include?(described_class.prometheus_metrics_enabled?)).to eq(true) + end + end + + describe '.influx_metrics_enabled?' do + it 'returns a boolean' do + expect([true, false].include?(described_class.influx_metrics_enabled?)).to eq(true) + end + end + describe '.submit_metrics' do it 'prepares and writes the metrics to InfluxDB' do connection = double(:connection) @@ -177,4 +189,117 @@ describe Gitlab::Metrics do end end end + + shared_examples 'prometheus metrics API' do + describe '#counter' do + subject { described_class.counter(:couter, 'doc') } + + describe '#increment' do + it { expect { subject.increment }.not_to raise_exception } + it { expect { subject.increment({}) }.not_to raise_exception } + it { expect { subject.increment({}, 1) }.not_to raise_exception } + end + end + + describe '#summary' do + subject { described_class.summary(:summary, 'doc') } + + describe '#observe' do + it { expect { subject.observe({}, 2) }.not_to raise_exception } + end + end + + describe '#gauge' do + subject { described_class.gauge(:gauge, 'doc') } + + describe '#observe' do + it { expect { subject.set({}, 1) }.not_to raise_exception } + end + end + + describe '#histogram' do + subject { described_class.histogram(:histogram, 'doc') } + + describe '#observe' do + it { expect { subject.observe({}, 2) }.not_to raise_exception } + end + end + end + + context 'prometheus metrics disabled' do + before do + allow(described_class).to receive(:prometheus_metrics_enabled?).and_return(false) + end + + it_behaves_like 'prometheus metrics API' + + describe '#dummy_metric' do + subject { described_class.provide_metric(:test) } + + it { is_expected.to be_a(Gitlab::Metrics::DummyMetric) } + end + + describe '#counter' do + subject { described_class.counter(:counter, 'doc') } + + it { is_expected.to be_a(Gitlab::Metrics::DummyMetric) } + + end + + describe '#summary' do + subject { described_class.summary(:summary, 'doc') } + + it { is_expected.to be_a(Gitlab::Metrics::DummyMetric) } + end + + describe '#gauge' do + subject { described_class.gauge(:gauge, 'doc') } + + it { is_expected.to be_a(Gitlab::Metrics::DummyMetric) } + end + + describe '#histogram' do + subject { described_class.histogram(:histogram, 'doc') } + + it { is_expected.to be_a(Gitlab::Metrics::DummyMetric) } + end + end + + context 'prometheus metrics enabled' do + before do + allow(described_class).to receive(:prometheus_metrics_enabled?).and_return(true) + end + + it_behaves_like 'prometheus metrics API' + + describe '#dummy_metric' do + subject { described_class.provide_metric(:test) } + + it { is_expected.to be_nil } + end + + describe '#counter' do + subject { described_class.counter(:name, 'doc') } + + it { is_expected.not_to be_a(Gitlab::Metrics::DummyMetric) } + end + + describe '#summary' do + subject { described_class.summary(:name, 'doc') } + + it { is_expected.not_to be_a(Gitlab::Metrics::DummyMetric) } + end + + describe '#gauge' do + subject { described_class.gauge(:name, 'doc') } + + it { is_expected.not_to be_a(Gitlab::Metrics::DummyMetric) } + end + + describe '#histogram' do + subject { described_class.histogram(:name, 'doc') } + + it { is_expected.not_to be_a(Gitlab::Metrics::DummyMetric) } + end + end end |