PrometheusService validation bug prevents saving for non-manual configurations
Summary
PrometheusService
is a model which is intended to support both manual and non-mnaul (Kubernetes provided) Prometheus installs.
We have validations (https://gitlab.com/gitlab-org/gitlab/-/blob/ac577f01d9fb9903da28b7a1f42f8869f6270b9f/app/models/project_services/prometheus_service.rb#L16-19) which are intended to be run only when manual_configuration? == true
, however this does not seem to be the case.
Steps to reproduce
service = PrometheusService.new(project: Project.first)
service.manual_configuration?
=> false
service.valid?
service.errors.messages
service.errors.messages
=> {:api_url=>["can't be blank", "is not a valid URL"]}
We also see errors in Sidekiq logs when installing the Prometheus managed app:
2020-03-31T23:07:27.552Z 26622 TID-ouj8kx1iy WARN: ActiveRecord::RecordInvalid: Validation failed: Api url can't be blank, Api url is not a valid URL
2020-03-31T23:07:27.552Z 26622 TID-ouj8kx1iy WARN: /Users/seanarnold/.rvm/gems/ruby-2.6.5/gems/activerecord-6.0.2/lib/active_record/validations.rb:81:in `raise_validation_error'
(If you are using an older version of GitLab, this will also determine whether the bug is fixed in a more recent version)
What is the current bug behavior?
PrometheusService
cannot be saved for a non-manual instance.
What is the expected correct behavior?
PrometheusService
should be able to be saved for a non-manual instance.
Possible fixes
Fix validations and add specs