Commit 3e0ebb04 authored by Mikolaj Wawrzyniak's avatar Mikolaj Wawrzyniak

Deprecate Setttings > Integrations > Prometheus

Prometheus is moved from Settings > Integrations to
Settings > Operations. In old location there should be deprecation
warrings added, and update action should be disabled for
PrometheusService objects.
parent f503bfec
...@@ -8,6 +8,8 @@ class Projects::ServicesController < Projects::ApplicationController ...@@ -8,6 +8,8 @@ class Projects::ServicesController < Projects::ApplicationController
before_action :ensure_service_enabled before_action :ensure_service_enabled
before_action :service before_action :service
before_action :web_hook_logs, only: [:edit, :update] before_action :web_hook_logs, only: [:edit, :update]
before_action :set_deprecation_notice_for_prometheus_service, only: [:edit, :update]
before_action :redirect_deprecated_prometheus_service, only: [:update]
respond_to :html respond_to :html
...@@ -93,4 +95,16 @@ class Projects::ServicesController < Projects::ApplicationController ...@@ -93,4 +95,16 @@ class Projects::ServicesController < Projects::ApplicationController
.as_json(only: @service.json_fields) .as_json(only: @service.json_fields)
.merge(errors: @service.errors.as_json) .merge(errors: @service.errors.as_json)
end end
def redirect_deprecated_prometheus_service
redirect_to edit_project_service_path(project, @service) if @service.is_a?(::PrometheusService) && Feature.enabled?(:settings_operations_prometheus_service, project)
end
def set_deprecation_notice_for_prometheus_service
return if !@service.is_a?(::PrometheusService) || !Feature.enabled?(:settings_operations_prometheus_service, project)
operations_link_start = "<a href=\"#{project_settings_operations_path(project)}\">"
message = s_('PrometheusService|You can now manage your Prometheus settings on the %{operations_link_start}Operations%{operations_link_end} page. Fields on this page has been deprecated.') % { operations_link_start: operations_link_start, operations_link_end: "</a>" }
flash.now[:alert] = message.html_safe
end
end end
...@@ -25,17 +25,11 @@ describe 'Prometheus custom metrics', :js do ...@@ -25,17 +25,11 @@ describe 'Prometheus custom metrics', :js do
stub_request(:get, prometheus_query_with_time_url('avg(metric)', Time.now.utc)) stub_request(:get, prometheus_query_with_time_url('avg(metric)', Time.now.utc))
fill_in_prometheus_integration create(:prometheus_service, project: project, api_url: 'http://prometheus.example.com', manual_configuration: '1', active: true)
click_link('Prometheus') click_link('Prometheus')
end end
def fill_in_prometheus_integration
check('Active')
fill_in('API URL', with: 'https://prometheus.example.com')
click_button('Save changes')
end
it 'Deletes a custom metric' do it 'Deletes a custom metric' do
wait_for_requests wait_for_requests
......
...@@ -20,15 +20,11 @@ describe 'Prometheus external alerts', :js do ...@@ -20,15 +20,11 @@ describe 'Prometheus external alerts', :js do
context 'with manual configuration' do context 'with manual configuration' do
before do before do
check('Active') create(:prometheus_service, project: project, api_url: 'http://prometheus.example.com', manual_configuration: '1', active: true)
fill_in('API URL', with: 'http://prometheus.example.com')
click_button('Save changes')
visit_edit_service
end end
it 'shows the Alerts section' do it 'shows the Alerts section' do
wait_for_requests visit_edit_service
expect(alerts_section).to have_content('Alerts') expect(alerts_section).to have_content('Alerts')
expect(alerts_section).to have_content('Receive alerts from manually configured Prometheus servers.') expect(alerts_section).to have_content('Receive alerts from manually configured Prometheus servers.')
......
...@@ -15235,6 +15235,9 @@ msgstr "" ...@@ -15235,6 +15235,9 @@ msgstr ""
msgid "PrometheusService|Waiting for your first deployment to an environment to find common metrics" msgid "PrometheusService|Waiting for your first deployment to an environment to find common metrics"
msgstr "" msgstr ""
msgid "PrometheusService|You can now manage your Prometheus settings on the %{operations_link_start}Operations%{operations_link_end} page. Fields on this page has been deprecated."
msgstr ""
msgid "Promote" msgid "Promote"
msgstr "" msgstr ""
......
...@@ -191,11 +191,48 @@ describe Projects::ServicesController do ...@@ -191,11 +191,48 @@ describe Projects::ServicesController do
end end
end end
end end
context 'Prometheus service' do
let!(:service) { create(:prometheus_service, project: project) }
let(:service_params) { { manual_configuration: '1', api_url: 'http://example.com' } }
context 'feature flag :settings_operations_prometheus_service is enabled' do
before do
stub_feature_flags(settings_operations_prometheus_service: true)
end
it 'redirects user back to edit page with alert' do
put :update, params: project_params.merge(service: service_params)
expect(response).to redirect_to(edit_project_service_path(project, service))
expected_alert = "You can now manage your Prometheus settings on the <a href=\"#{project_settings_operations_path(project)}\">Operations</a> page. Fields on this page has been deprecated."
expect(response).to set_flash.now[:alert].to(expected_alert)
end
it 'does not modify service' do
expect { put :update, params: project_params.merge(service: service_params) }.not_to change { project.prometheus_service.reload.attributes }
end
end
context 'feature flag :settings_operations_prometheus_service is disabled' do
before do
stub_feature_flags(settings_operations_prometheus_service: false)
end
it 'modifies service' do
expect { put :update, params: project_params.merge(service: service_params) }.to change { project.prometheus_service.reload.attributes }
end
end
end
end end
describe 'GET #edit' do describe 'GET #edit' do
context 'Jira service' do
let(:service_param) { 'jira' }
before do before do
get :edit, params: project_params(id: 'jira') get :edit, params: project_params(id: service_param)
end end
context 'with approved services' do context 'with approved services' do
...@@ -205,6 +242,34 @@ describe Projects::ServicesController do ...@@ -205,6 +242,34 @@ describe Projects::ServicesController do
end end
end end
context 'Prometheus service' do
let(:service_param) { 'prometheus' }
context 'feature flag :settings_operations_prometheus_service is enabled' do
before do
stub_feature_flags(settings_operations_prometheus_service: true)
get :edit, params: project_params(id: service_param)
end
it 'renders deprecation warning notice' do
expected_alert = "You can now manage your Prometheus settings on the <a href=\"#{project_settings_operations_path(project)}\">Operations</a> page. Fields on this page has been deprecated."
expect(response).to set_flash.now[:alert].to(expected_alert)
end
end
context 'feature flag :settings_operations_prometheus_service is disabled' do
before do
stub_feature_flags(settings_operations_prometheus_service: false)
get :edit, params: project_params(id: service_param)
end
it 'does not render deprecation warning notice' do
expect(response).not_to set_flash.now[:alert]
end
end
end
end
private private
def project_params(opts = {}) def project_params(opts = {})
......
...@@ -15,11 +15,12 @@ describe 'User activates Prometheus' do ...@@ -15,11 +15,12 @@ describe 'User activates Prometheus' do
click_link('Prometheus') click_link('Prometheus')
end end
it 'activates service' do it 'does not activate service and informs about deprecation' do
check('Active') check('Active')
fill_in('API URL', with: 'http://prometheus.example.com') fill_in('API URL', with: 'http://prometheus.example.com')
click_button('Save changes') click_button('Save changes')
expect(page).to have_content('Prometheus activated.') expect(page).not_to have_content('Prometheus activated.')
expect(page).to have_content('Fields on this page has been deprecated.')
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