Add nil check for Gitlab.config.prometheus

This commit is contained in:
rpereira2 2019-08-26 12:41:25 +05:30
parent 8112fb3754
commit b99cf2024d
2 changed files with 13 additions and 2 deletions

View File

@ -175,7 +175,7 @@ module Gitlab
end
def prometheus_enabled?
Gitlab.config.prometheus.enable
Gitlab.config.prometheus.enable if Gitlab.config.prometheus
rescue Settingslogic::MissingSetting
log_error(_('prometheus.enable is not present in gitlab.yml'))
@ -183,7 +183,7 @@ module Gitlab
end
def prometheus_listen_address
Gitlab.config.prometheus.listen_address
Gitlab.config.prometheus.listen_address if Gitlab.config.prometheus
rescue Settingslogic::MissingSetting
log_error(_('prometheus.listen_address is not present in gitlab.yml'))

View File

@ -197,6 +197,17 @@ describe Gitlab::DatabaseImporters::SelfMonitoring::Project::CreateService do
end
end
context 'when prometheus setting is nil' do
before do
stub_config(prometheus: nil)
end
it 'does not fail' do
expect(result).to include(status: :success)
expect(project.prometheus_service).to be_nil
end
end
context 'when prometheus setting is disabled in gitlab.yml' do
let(:prometheus_settings) do
{