Skip to content
Snippets Groups Projects
Commit 15998eb4 authored by Shinya Maeda's avatar Shinya Maeda
Browse files

Track the validation error on Environment Update

This commit improves the tracability of the validation
error on Environment update.

Changelog: other
parent 9fcfe629
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -9,6 +9,8 @@ class UpdateEnvironmentService
delegate :variables, to: :deployable
delegate :options, to: :deployable, allow_nil: true
 
EnvironmentUpdateFailure = Class.new(StandardError)
def initialize(deployment)
@deployment = deployment
@deployable = deployment.deployable
Loading
Loading
@@ -31,8 +33,18 @@ def update_environment(deployment)
renew_deployment_tier
environment.fire_state_event(action)
 
if environment.save && !environment.stopped?
deployment.update_merge_request_metrics!
if environment.save
deployment.update_merge_request_metrics! unless environment.stopped?
else
# If there is a validation error on environment update, such as
# the external URL is malformed, the error message is recorded for debugging purpose.
# We should surface the error message to users for letting them to take an action.
# See https://gitlab.com/gitlab-org/gitlab/-/issues/21182.
Gitlab::ErrorTracking.track_exception(
EnvironmentUpdateFailure.new,
project_id: deployment.project_id,
environment_id: environment.id,
reason: environment.errors.full_messages.to_sentence)
end
end
end
Loading
Loading
Loading
Loading
@@ -95,6 +95,42 @@
end
end
 
context 'when external URL is specified and the tier is unset' do
let(:options) { { name: 'production', url: external_url } }
before do
environment.update_columns(external_url: external_url, tier: nil)
job.update!(environment: 'production')
end
context 'when external URL is valid' do
let(:external_url) { 'https://google.com' }
it 'succeeds to update the tier automatically' do
expect { subject.execute }.to change { environment.tier }.from(nil).to('production')
end
end
context 'when external URL is invalid' do
let(:external_url) { 'google.com' }
it 'fails to update the tier due to validation error' do
expect { subject.execute }.not_to change { environment.tier }
end
it 'tracks an exception' do
expect(Gitlab::ErrorTracking).to receive(:track_exception)
.with(an_instance_of(described_class::EnvironmentUpdateFailure),
project_id: project.id,
environment_id: environment.id,
reason: %q{External url is blocked: Only allowed schemes are http, https})
.once
subject.execute
end
end
end
context 'when variables are used' do
let(:options) do
{ name: 'review-apps/$CI_COMMIT_REF_NAME',
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment