2019-08-22 06:57:44 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-05-09 01:29:30 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe Gitlab::Metrics::Prometheus, :prometheus do
|
2018-05-09 01:29:30 -04:00
|
|
|
let(:all_metrics) { Gitlab::Metrics }
|
|
|
|
let(:registry) { all_metrics.registry }
|
|
|
|
|
2020-01-09 13:07:52 -05:00
|
|
|
after do
|
|
|
|
all_metrics.clear_errors!
|
|
|
|
end
|
|
|
|
|
2018-05-09 01:29:30 -04:00
|
|
|
describe '#reset_registry!' do
|
|
|
|
it 'clears existing metrics' do
|
|
|
|
registry.counter(:test, 'test metric')
|
|
|
|
|
|
|
|
expect(registry.metrics.count).to eq(1)
|
|
|
|
|
|
|
|
all_metrics.reset_registry!
|
|
|
|
|
|
|
|
expect(all_metrics.registry.metrics.count).to eq(0)
|
|
|
|
end
|
|
|
|
end
|
2020-01-09 07:08:03 -05:00
|
|
|
|
|
|
|
describe '#error_detected!' do
|
|
|
|
before do
|
|
|
|
allow(all_metrics).to receive(:metrics_folder_present?).and_return(true)
|
|
|
|
stub_application_setting(prometheus_metrics_enabled: true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'disables Prometheus metrics' do
|
|
|
|
expect(all_metrics.error?).to be_falsey
|
|
|
|
expect(all_metrics.prometheus_metrics_enabled?).to be_truthy
|
|
|
|
|
|
|
|
all_metrics.error_detected!
|
|
|
|
|
|
|
|
expect(all_metrics.prometheus_metrics_enabled?).to be_falsey
|
|
|
|
expect(all_metrics.error?).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
2018-05-09 01:29:30 -04:00
|
|
|
end
|