Fix PrometheusService validation for non-manual configurations
What does this MR do?
There is a bug in the PrometheusService
validations, where the if: :manual_configuration?
condition is being ignored.
This is due to the following (from https://api.rubyonrails.org/?q=with_options):
NOTE: Each nesting level will merge inherited defaults in addition to their own.
class Post < ActiveRecord::Base with_options if: :persisted?, length: { minimum: 50 } do validates :content, if: -> { content.present? } end end
The code is equivalent to:
validates :content, length: { minimum: 50 }, if: -> { content.present? }
Hence the inherited default for if key is ignored.
This means that the validation as there were, were being executed as:
validates :api_url, public_url: true, presence: true, unless: proc { |object| object.allow_local_api_url? }, if: :manual_configuration?
validates :api_url, url: true, presence: true, if: proc { |object| object.allow_local_api_url? }
Notice that the second case above if: :manual_configuration?
condition.
Screenshots
Does this MR meet the acceptance criteria?
Conformity
-
Changelog entry -
Documentation (if required) -
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides -
Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. -
Tested in all supported browsers -
Informed Infrastructure department of a default or new setting change, if applicable per definition of done
Security
If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:
-
Label as security and @ mention @gitlab-com/gl-security/appsec
-
The MR includes necessary changes to maintain consistency between UI, API, email, or other methods -
Security reports checked/validated by a reviewer from the AppSec team
Closes #213036 (closed)