Commit 0ba0476d authored by Vitali Tatarintev's avatar Vitali Tatarintev

Removes generic_alert_endpoint feature flag

Releases Generic alerts integration that accepts alerts
from any source via a generic webhook receiver.
parent fc811901
...@@ -9,7 +9,6 @@ module Projects ...@@ -9,7 +9,6 @@ module Projects
skip_before_action :project skip_before_action :project
prepend_before_action :repository, :project_without_auth prepend_before_action :repository, :project_without_auth
before_action :check_generic_alert_endpoint_feature_flag!
def create def create
token = extract_alert_manager_token(request) token = extract_alert_manager_token(request)
...@@ -25,10 +24,6 @@ module Projects ...@@ -25,10 +24,6 @@ module Projects
.find_by_full_path("#{params[:namespace_id]}/#{params[:project_id]}") .find_by_full_path("#{params[:namespace_id]}/#{params[:project_id]}")
end end
def check_generic_alert_endpoint_feature_flag!
render_404 unless Feature.enabled?(:generic_alert_endpoint, @project)
end
def extract_alert_manager_token(request) def extract_alert_manager_token(request)
Doorkeeper::OAuth::Token.from_bearer_authorization(request) Doorkeeper::OAuth::Token.from_bearer_authorization(request)
end end
......
...@@ -643,8 +643,7 @@ module EE ...@@ -643,8 +643,7 @@ module EE
end end
def alerts_service_available? def alerts_service_available?
::Feature.enabled?(:generic_alert_endpoint, self) && feature_available?(:incident_management)
feature_available?(:incident_management)
end end
def package_already_taken?(package_name) def package_already_taken?(package_name)
......
...@@ -20,17 +20,12 @@ module Projects ...@@ -20,17 +20,12 @@ module Projects
delegate :alerts_service, to: :project delegate :alerts_service, to: :project
def generic_alert_endpoint_enabled?
Feature.enabled?(:generic_alert_endpoint, project)
end
def incident_management_available? def incident_management_available?
project.feature_available?(:incident_management) project.feature_available?(:incident_management)
end end
def alerts_service_activated? def alerts_service_activated?
incident_management_available? && incident_management_available? &&
generic_alert_endpoint_enabled? &&
alerts_service.try(:active?) alerts_service.try(:active?)
end end
......
...@@ -22,84 +22,66 @@ describe Projects::Alerting::NotificationsController do ...@@ -22,84 +22,66 @@ describe Projects::Alerting::NotificationsController do
post :create, params: project_params, body: body.to_json, as: :json post :create, params: project_params, body: body.to_json, as: :json
end end
context 'when feature flag is on' do context 'when notification service succeeds' do
before do let(:payload) do
stub_feature_flags(generic_alert_endpoint: true) {
title: 'Alert title',
hosts: 'https://gitlab.com'
}
end end
context 'when notification service succeeds' do let(:permitted_params) { ActionController::Parameters.new(payload).permit! }
let(:payload) do
{
title: 'Alert title',
hosts: 'https://gitlab.com'
}
end
let(:permitted_params) { ActionController::Parameters.new(payload).permit! }
it 'responds with ok' do
make_request
expect(response).to have_gitlab_http_status(:ok)
end
it 'does not pass excluded parameters to the notify service' do it 'responds with ok' do
make_request(payload) make_request
expect(Projects::Alerting::NotifyService) expect(response).to have_gitlab_http_status(:ok)
.to have_received(:new)
.with(project, nil, permitted_params)
end
end end
context 'when notification service fails' do it 'does not pass excluded parameters to the notify service' do
let(:service_response) { ServiceResponse.error(message: 'Unauthorized', http_status: 401) } make_request(payload)
it 'responds with the service response' do
make_request
expect(response).to have_gitlab_http_status(:unauthorized) expect(Projects::Alerting::NotifyService)
end .to have_received(:new)
.with(project, nil, permitted_params)
end end
end
context 'bearer token' do context 'when notification service fails' do
context 'when set' do let(:service_response) { ServiceResponse.error(message: 'Unauthorized', http_status: 401) }
it 'extracts bearer token' do
request.headers['HTTP_AUTHORIZATION'] = 'Bearer some token'
expect(notify_service).to receive(:execute).with('some token') it 'responds with the service response' do
make_request
make_request expect(response).to have_gitlab_http_status(:unauthorized)
end end
end
it 'pass nil if cannot extract a non-bearer token' do context 'bearer token' do
request.headers['HTTP_AUTHORIZATION'] = 'some token' context 'when set' do
it 'extracts bearer token' do
request.headers['HTTP_AUTHORIZATION'] = 'Bearer some token'
expect(notify_service).to receive(:execute).with(nil) expect(notify_service).to receive(:execute).with('some token')
make_request make_request
end
end end
context 'when missing' do it 'pass nil if cannot extract a non-bearer token' do
it 'passes nil' do request.headers['HTTP_AUTHORIZATION'] = 'some token'
expect(notify_service).to receive(:execute).with(nil)
make_request expect(notify_service).to receive(:execute).with(nil)
end
end
end
end
context 'when feature flag is off' do make_request
before do end
stub_feature_flags(generic_alert_endpoint: false)
end end
it 'responds with not_found' do context 'when missing' do
make_request it 'passes nil' do
expect(notify_service).to receive(:execute).with(nil)
expect(response).to have_gitlab_http_status(:not_found) make_request
end
end end
end end
end end
......
...@@ -25,7 +25,6 @@ describe 'User activates Alerts' do ...@@ -25,7 +25,6 @@ describe 'User activates Alerts' do
context 'when feature available', :js do context 'when feature available', :js do
before do before do
stub_licensed_features(incident_management: true) stub_licensed_features(incident_management: true)
stub_feature_flags(generic_alert_endpoint: true)
end end
context 'when service is deactivated' do context 'when service is deactivated' do
...@@ -60,14 +59,6 @@ describe 'User activates Alerts' do ...@@ -60,14 +59,6 @@ describe 'User activates Alerts' do
expect(reset_key.value).to be_present expect(reset_key.value).to be_present
end end
end end
context 'when feature flag `generic_alert_endpoint` disabled' do
before do
stub_feature_flags(generic_alert_endpoint: false)
end
it_behaves_like 'no service'
end
end end
context 'when feature unavailable' do context 'when feature unavailable' do
......
...@@ -1137,20 +1137,6 @@ describe Project do ...@@ -1137,20 +1137,6 @@ describe Project do
it { is_expected.to include(*disabled_services) } it { is_expected.to include(*disabled_services) }
end end
end end
context 'when incident_management is available' do
before do
stub_licensed_features(incident_management: true)
end
context 'when feature flag generic_alert_endpoint is disabled' do
before do
stub_feature_flags(generic_alert_endpoint: false)
end
it { is_expected.to include('alerts') }
end
end
end end
describe '#pull_mirror_available?' do describe '#pull_mirror_available?' do
......
...@@ -54,48 +54,34 @@ describe Projects::Alerting::NotifyService do ...@@ -54,48 +54,34 @@ describe Projects::Alerting::NotifyService do
stub_licensed_features(incident_management: true) stub_licensed_features(incident_management: true)
end end
context 'with Generic Alert Endpoint feature enabled' do context 'with activated Alerts Service' do
before do let!(:alerts_service) { create(:alerts_service, project: project) }
stub_feature_flags(generic_alert_endpoint: true)
end
context 'with activated Alerts Service' do
let!(:alerts_service) { create(:alerts_service, project: project) }
context 'with valid token' do context 'with valid token' do
let(:token) { alerts_service.token } let(:token) { alerts_service.token }
context 'with a valid payload' do
it_behaves_like 'processes incident issues', 1
end
context 'with an invalid payload' do context 'with a valid payload' do
before do it_behaves_like 'processes incident issues', 1
allow(Gitlab::Alerting::NotificationPayloadParser) end
.to receive(:call)
.and_raise(Gitlab::Alerting::NotificationPayloadParser::BadPayloadError)
end
it_behaves_like 'does not process incident issues', http_status: 400 context 'with an invalid payload' do
before do
allow(Gitlab::Alerting::NotificationPayloadParser)
.to receive(:call)
.and_raise(Gitlab::Alerting::NotificationPayloadParser::BadPayloadError)
end end
end
context 'with invalid token' do it_behaves_like 'does not process incident issues', http_status: 400
it_behaves_like 'does not process incident issues', http_status: 401
end end
end end
context 'with deactivated Alerts Service' do context 'with invalid token' do
let!(:alerts_service) { create(:alerts_service, :inactive, project: project) } it_behaves_like 'does not process incident issues', http_status: 401
it_behaves_like 'does not process incident issues', http_status: 403
end end
end end
context 'with Generic Alert Endpoint feature disabled' do context 'with deactivated Alerts Service' do
before do let!(:alerts_service) { create(:alerts_service, :inactive, project: project) }
stub_feature_flags(generic_alert_endpoint: false)
end
it_behaves_like 'does not process incident issues', http_status: 403 it_behaves_like 'does not process incident issues', http_status: 403
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