Commit 66d54e45 authored by Sean Arnold's avatar Sean Arnold Committed by Rémy Coutable

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

parent 827594ab
......@@ -13,9 +13,9 @@ class PrometheusService < MonitoringService
# to allow localhost URLs when the following conditions are true:
# 1. project is the self-monitoring project.
# 2. api_url is the internal Prometheus URL.
with_options presence: true, if: :manual_configuration? do
validates :api_url, public_url: true, unless: proc { |object| object.allow_local_api_url? }
validates :api_url, url: true, if: proc { |object| object.allow_local_api_url? }
with_options presence: true do
validates :api_url, public_url: true, if: ->(object) { object.manual_configuration? && !object.allow_local_api_url? }
validates :api_url, url: true, if: ->(object) { object.manual_configuration? && object.allow_local_api_url? }
end
before_save :synchronize_service_state
......
......@@ -48,6 +48,18 @@ describe PrometheusService, :use_clean_rails_memory_store_caching do
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
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
......
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