Commit e63a276b authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'mwaw/deprecate_promethues_in_settings_integrations' into 'master'

Deprecate Setttings > Integrations > Prometheus section

Closes #200020

See merge request gitlab-org/gitlab!24472
parents 74cc831c 3e0ebb04
......@@ -8,6 +8,8 @@ class Projects::ServicesController < Projects::ApplicationController
before_action :ensure_service_enabled
before_action :service
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
......@@ -93,4 +95,16 @@ class Projects::ServicesController < Projects::ApplicationController
.as_json(only: @service.json_fields)
.merge(errors: @service.errors.as_json)
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
......@@ -25,17 +25,11 @@ describe 'Prometheus custom metrics', :js do
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')
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
wait_for_requests
......
......@@ -20,15 +20,11 @@ describe 'Prometheus external alerts', :js do
context 'with manual configuration' do
before do
check('Active')
fill_in('API URL', with: 'http://prometheus.example.com')
click_button('Save changes')
visit_edit_service
create(:prometheus_service, project: project, api_url: 'http://prometheus.example.com', manual_configuration: '1', active: true)
end
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('Receive alerts from manually configured Prometheus servers.')
......
......@@ -15235,6 +15235,9 @@ msgstr ""
msgid "PrometheusService|Waiting for your first deployment to an environment to find common metrics"
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"
msgstr ""
......
......@@ -191,16 +191,81 @@ describe Projects::ServicesController do
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
describe 'GET #edit' do
before do
get :edit, params: project_params(id: 'jira')
context 'Jira service' do
let(:service_param) { 'jira' }
before do
get :edit, params: project_params(id: service_param)
end
context 'with approved services' do
it 'renders edit page' do
expect(response).to be_successful
end
end
end
context 'with approved services' do
it 'renders edit page' do
expect(response).to be_successful
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
......
......@@ -15,11 +15,12 @@ describe 'User activates Prometheus' do
click_link('Prometheus')
end
it 'activates service' do
it 'does not activate service and informs about deprecation' do
check('Active')
fill_in('API URL', with: 'http://prometheus.example.com')
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
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