Commit 3bcfd402 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch...

Merge branch '213036-prometheusservice-validation-bug-prevents-saving-for-non-manual-configurations' into 'master'

Resolve "PrometheusService validation bug prevents saving for non-manual configurations"

Closes #213036

See merge request gitlab-org/gitlab!28485
parents cd2c1f8d 66d54e45
...@@ -13,9 +13,9 @@ class PrometheusService < MonitoringService ...@@ -13,9 +13,9 @@ class PrometheusService < MonitoringService
# to allow localhost URLs when the following conditions are true: # to allow localhost URLs when the following conditions are true:
# 1. project is the self-monitoring project. # 1. project is the self-monitoring project.
# 2. api_url is the internal Prometheus URL. # 2. api_url is the internal Prometheus URL.
with_options presence: true, if: :manual_configuration? do with_options presence: true do
validates :api_url, public_url: true, unless: proc { |object| object.allow_local_api_url? } validates :api_url, public_url: true, if: ->(object) { object.manual_configuration? && !object.allow_local_api_url? }
validates :api_url, url: true, if: proc { |object| object.allow_local_api_url? } validates :api_url, url: true, if: ->(object) { object.manual_configuration? && object.allow_local_api_url? }
end end
before_save :synchronize_service_state before_save :synchronize_service_state
......
...@@ -48,6 +48,18 @@ describe PrometheusService, :use_clean_rails_memory_store_caching do ...@@ -48,6 +48,18 @@ describe PrometheusService, :use_clean_rails_memory_store_caching do
it 'does not validate presence of api_url' do it 'does not validate presence of api_url' do
expect(service).not_to validate_presence_of(:api_url) expect(service).not_to validate_presence_of(:api_url)
expect(service.valid?).to eq(true)
end
context 'local connections allowed' do
before do
stub_application_setting(allow_local_requests_from_web_hooks_and_services: true)
end
it 'does not validate presence of api_url' do
expect(service).not_to validate_presence_of(:api_url)
expect(service.valid?).to eq(true)
end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment