Commit 8ba06918 authored by Dhiraj Bodicherla's avatar Dhiraj Bodicherla Committed by Peter Leitzen

Do not override #editable? in PrometheusService

- Also add specs to ensure that #fields method always returns the
fields, even when there is a cluster present with Prometheus installed.

- This is being done so that the Prometheus manual configuration is
editable even when there is a Prometheus managed app installed on a
cluster.
parent 7b5ad03d
......@@ -36,10 +36,6 @@ class PrometheusService < MonitoringService
false
end
def editable?
manual_configuration? || !prometheus_available?
end
def title
'Prometheus'
end
......@@ -53,8 +49,6 @@ class PrometheusService < MonitoringService
end
def fields
return [] unless editable?
[
{
type: 'checkbox',
......
......@@ -12,11 +12,10 @@
.col-lg-9
= form_for(@service, as: :service, url: scoped_integration_path(@service), method: :put, html: { class: 'gl-show-field-errors integration-settings-form js-integration-settings-form', data: { 'can-test' => @service.can_test?, 'test-url' => test_project_service_path(@project, @service) } }) do |form|
= render 'shared/service_settings', form: form, service: @service
- if @service.editable?
.footer-block.row-content-block
= service_save_button(@service)
&nbsp;
= link_to _('Cancel'), project_settings_integrations_path(@project), class: 'btn btn-cancel'
.footer-block.row-content-block
= service_save_button(@service)
&nbsp;
= link_to _('Cancel'), project_settings_integrations_path(@project), class: 'btn btn-cancel'
- if lookup_context.template_exists?('show', "projects/services/#{@service.to_param}", true)
%hr
......
......@@ -3,7 +3,5 @@
%h4.append-bottom-default
= s_('PrometheusService|Manual configuration')
- unless @service.editable?
.info-well
= s_('PrometheusService|To enable manual configuration, uninstall Prometheus from your clusters')
%p
= s_('PrometheusService|Select the Active checkbox to override the Auto Configuration with custom settings. If unchecked, Auto Configuration settings are used.')
......@@ -13,7 +13,5 @@
%b.append-bottom-default
= s_('PrometheusService|Manual configuration')
- unless service.editable?
.info-well
= s_('PrometheusService|To enable manual configuration, uninstall Prometheus from your clusters')
%p
= s_('PrometheusService|Select the Active checkbox to override the Auto Configuration with custom settings. If unchecked, Auto Configuration settings are used.')
---
title: Make manual prometheus configuration section always editable
merge_request: 29209
author:
type: changed
......@@ -16342,13 +16342,13 @@ msgstr ""
msgid "PrometheusService|Prometheus is being automatically managed on your clusters"
msgstr ""
msgid "PrometheusService|These metrics will only be monitored after your first deployment to an environment"
msgid "PrometheusService|Select the Active checkbox to override the Auto Configuration with custom settings. If unchecked, Auto Configuration settings are used."
msgstr ""
msgid "PrometheusService|Time-series monitoring service"
msgid "PrometheusService|These metrics will only be monitored after your first deployment to an environment"
msgstr ""
msgid "PrometheusService|To enable manual configuration, uninstall Prometheus from your clusters"
msgid "PrometheusService|Time-series monitoring service"
msgstr ""
msgid "PrometheusService|To enable the installation of Prometheus on your clusters, deactivate the manual configuration below"
......
......@@ -19,6 +19,14 @@ describe Gitlab::Prometheus::Adapter do
it 'return prometheus service as prometheus adapter' do
expect(subject.prometheus_adapter).to eq(prometheus_service)
end
context 'with cluster with prometheus available' do
let!(:prometheus) { create(:clusters_applications_prometheus, :installed, cluster: cluster) }
it 'returns prometheus service' do
expect(subject.prometheus_adapter).to eq(prometheus_service)
end
end
end
context "prometheus service can't execute queries" do
......
......@@ -418,4 +418,48 @@ describe PrometheusService, :use_clean_rails_memory_store_caching do
end
end
end
describe '#editable?' do
it 'is editable' do
expect(service.editable?).to be(true)
end
context 'when cluster exists with prometheus installed' do
let(:cluster) { create(:cluster, projects: [project]) }
before do
service.update!(manual_configuration: false)
create(:clusters_applications_prometheus, :installed, cluster: cluster)
end
it 'remains editable' do
expect(service.editable?).to be(true)
end
end
end
describe '#fields' do
let(:expected_fields) do
[
{
type: 'checkbox',
name: 'manual_configuration',
title: s_('PrometheusService|Active'),
required: true
},
{
type: 'text',
name: 'api_url',
title: 'API URL',
placeholder: s_('PrometheusService|Prometheus API Base URL, like http://prometheus.example.com/'),
required: true
}
]
end
it 'returns fields' do
expect(service.fields).to eq(expected_fields)
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