Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
c14a0db9
Commit
c14a0db9
authored
Nov 06, 2020
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Wrap Canary Update Request into Sidekiq Worker Job
This commit executes the external HTTP request in sidekiq worker.
parent
aa5bde98
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
138 additions
and
56 deletions
+138
-56
config/sidekiq_queues.yml
config/sidekiq_queues.yml
+2
-0
ee/app/graphql/mutations/environments/canary_ingress/update.rb
...p/graphql/mutations/environments/canary_ingress/update.rb
+1
-1
ee/app/services/environments/canary_ingress/update_service.rb
...pp/services/environments/canary_ingress/update_service.rb
+10
-1
ee/app/workers/all_queues.yml
ee/app/workers/all_queues.yml
+8
-0
ee/app/workers/environments/canary_ingress/update_worker.rb
ee/app/workers/environments/canary_ingress/update_worker.rb
+22
-0
ee/spec/graphql/mutations/environments/canary_ingress/update_spec.rb
...phql/mutations/environments/canary_ingress/update_spec.rb
+2
-2
ee/spec/services/environments/canary_ingress/update_service_spec.rb
...rvices/environments/canary_ingress/update_service_spec.rb
+60
-52
ee/spec/workers/environments/canary_ingress/update_worker_spec.rb
...workers/environments/canary_ingress/update_worker_spec.rb
+33
-0
No files found.
config/sidekiq_queues.yml
View file @
c14a0db9
...
...
@@ -112,6 +112,8 @@
-
2
-
-
emails_on_push
-
2
-
-
environments_canary_ingress_update
-
1
-
-
epics
-
2
-
-
error_tracking_issue_link
...
...
ee/app/graphql/mutations/environments/canary_ingress/update.rb
View file @
c14a0db9
...
...
@@ -23,7 +23,7 @@ module Mutations
result
=
::
Environments
::
CanaryIngress
::
UpdateService
.
new
(
environment
.
project
,
current_user
,
kwargs
)
.
execute
(
environment
)
.
execute
_async
(
environment
)
{
errors:
Array
.
wrap
(
result
[
:message
])
}
end
...
...
ee/app/services/environments/canary_ingress/update_service.rb
View file @
c14a0db9
...
...
@@ -3,11 +3,20 @@
module
Environments
module
CanaryIngress
class
UpdateService
<
::
BaseService
def
execute
(
environment
)
def
execute
_async
(
environment
)
result
=
validate
(
environment
)
return
result
unless
result
[
:status
]
==
:success
Environments
::
CanaryIngress
::
UpdateWorker
.
perform_async
(
environment
.
id
,
params
)
success
end
# This method actually executes the PATCH request to Kubernetes,
# that is used by internal processes i.e. sidekiq worker.
# You should always use `execute_async` to properly validate user's requests.
def
execute
(
environment
)
canary_ingress
=
environment
.
ingresses
&
.
find
(
&
:canary?
)
unless
canary_ingress
.
present?
...
...
ee/app/workers/all_queues.yml
View file @
c14a0db9
...
...
@@ -661,6 +661,14 @@
:weight:
1
:idempotent:
:tags: []
-
:name: environments_canary_ingress_update
:feature_category: :continuous_delivery
:has_external_dependencies:
true
:urgency: :low
:resource_boundary: :unknown
:weight:
1
:idempotent:
true
:tags: []
-
:name: group_saml_group_sync
:feature_category: :authentication_and_authorization
:has_external_dependencies:
...
...
ee/app/workers/environments/canary_ingress/update_worker.rb
0 → 100644
View file @
c14a0db9
# frozen_string_literal: true
module
Environments
module
CanaryIngress
class
UpdateWorker
include
ApplicationWorker
sidekiq_options
retry:
false
idempotent!
worker_has_external_dependencies!
feature_category
:continuous_delivery
def
perform
(
environment_id
,
params
)
Environment
.
find_by_id
(
environment_id
).
try
do
|
environment
|
Environments
::
CanaryIngress
::
UpdateService
.
new
(
environment
.
project
,
nil
,
params
.
with_indifferent_access
)
.
execute
(
environment
)
end
end
end
end
end
ee/spec/graphql/mutations/environments/canary_ingress/update_spec.rb
View file @
c14a0db9
...
...
@@ -29,7 +29,7 @@ RSpec.describe Mutations::Environments::CanaryIngress::Update do
context
'when service execution succeeded'
do
before
do
allow
(
update_service
).
to
receive
(
:execute
)
{
{
status: :success
}
}
allow
(
update_service
).
to
receive
(
:execute
_async
)
{
{
status: :success
}
}
end
it
'returns no errors'
do
...
...
@@ -39,7 +39,7 @@ RSpec.describe Mutations::Environments::CanaryIngress::Update do
context
'when service encounters a problem'
do
before
do
allow
(
update_service
).
to
receive
(
:execute
)
{
{
status: :error
,
message:
'something went wrong'
}
}
allow
(
update_service
).
to
receive
(
:execute
_async
)
{
{
status: :error
,
message:
'something went wrong'
}
}
end
it
'returns an error'
do
...
...
ee/spec/services/environments/canary_ingress/update_service_spec.rb
View file @
c14a0db9
...
...
@@ -21,63 +21,20 @@ RSpec.describe Environments::CanaryIngress::UpdateService, :clean_gitlab_redis_c
stub_licensed_features
(
deploy_board:
true
)
end
describe
'#execute'
do
subject
{
service
.
execute
(
environment
)
}
shared_examples_for
'failed request'
do
it
'returns an error'
do
expect
(
subject
[
:status
]).
to
eq
(
:error
)
expect
(
subject
[
:message
]).
to
eq
(
message
)
end
end
describe
'#execute_async'
do
subject
{
service
.
execute_async
(
environment
)
}
let
(
:environment
)
{
create
(
:environment
,
project:
project
)
}
let
(
:params
)
{
{
weight:
50
}
}
let
(
:canary_ingress
)
{
::
Gitlab
::
Kubernetes
::
Ingress
.
new
(
kube_ingress
(
track: :canary
))
}
shared_examples_for
'failed request'
do
it
'returns an error'
do
expect
(
subject
[
:status
]).
to
eq
(
:error
)
expect
(
subject
[
:message
]).
to
eq
(
message
)
end
end
context
'when canary ingress is present in the environment'
do
before
do
allow
(
environment
).
to
receive
(
:ingresses
)
{
[
canary_ingress
]
}
end
context
'when patch request succeeds'
do
let
(
:patch_data
)
do
{
metadata:
{
annotations:
{
Gitlab
::
Kubernetes
::
Ingress
::
ANNOTATION_KEY_CANARY_WEIGHT
=>
params
[
:weight
].
to_s
}
}
}
end
before
do
allow
(
environment
).
to
receive
(
:patch_ingress
).
with
(
canary_ingress
,
patch_data
)
{
true
}
end
it
'returns success'
do
expect
(
subject
[
:status
]).
to
eq
(
:success
)
expect
(
subject
[
:message
]).
to
be_nil
end
end
context
'when patch request does not succeed'
do
before
do
allow
(
environment
).
to
receive
(
:patch_ingress
)
{
false
}
end
it_behaves_like
'failed request'
do
let
(
:message
)
{
'Failed to update the Canary Ingress.'
}
end
end
end
context
'when canary ingress is not present in the environment'
do
it_behaves_like
'failed request'
do
let
(
:message
)
{
'Canary Ingress does not exist in the environment.'
}
end
end
context
'when canary_ingress_weight_control feature flag is disabled'
do
before
do
stub_feature_flags
(
canary_ingress_weight_control:
false
)
...
...
@@ -142,4 +99,55 @@ RSpec.describe Environments::CanaryIngress::UpdateService, :clean_gitlab_redis_c
end
end
end
describe
'#execute'
do
subject
{
service
.
execute
(
environment
)
}
let
(
:environment
)
{
create
(
:environment
,
project:
project
)
}
let
(
:params
)
{
{
weight:
50
}
}
let
(
:canary_ingress
)
{
::
Gitlab
::
Kubernetes
::
Ingress
.
new
(
kube_ingress
(
track: :canary
))
}
context
'when canary ingress is present in the environment'
do
before
do
allow
(
environment
).
to
receive
(
:ingresses
)
{
[
canary_ingress
]
}
end
context
'when patch request succeeds'
do
let
(
:patch_data
)
do
{
metadata:
{
annotations:
{
Gitlab
::
Kubernetes
::
Ingress
::
ANNOTATION_KEY_CANARY_WEIGHT
=>
params
[
:weight
].
to_s
}
}
}
end
before
do
allow
(
environment
).
to
receive
(
:patch_ingress
).
with
(
canary_ingress
,
patch_data
)
{
true
}
end
it
'returns success'
do
expect
(
subject
[
:status
]).
to
eq
(
:success
)
expect
(
subject
[
:message
]).
to
be_nil
end
end
context
'when patch request does not succeed'
do
before
do
allow
(
environment
).
to
receive
(
:patch_ingress
)
{
false
}
end
it_behaves_like
'failed request'
do
let
(
:message
)
{
'Failed to update the Canary Ingress.'
}
end
end
end
context
'when canary ingress is not present in the environment'
do
it_behaves_like
'failed request'
do
let
(
:message
)
{
'Canary Ingress does not exist in the environment.'
}
end
end
end
end
ee/spec/workers/environments/canary_ingress/update_worker_spec.rb
0 → 100644
View file @
c14a0db9
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Environments
::
CanaryIngress
::
UpdateWorker
do
let_it_be
(
:environment
)
{
create
(
:environment
)
}
let
(
:worker
)
{
described_class
.
new
}
describe
'#perform'
do
subject
{
worker
.
perform
(
environment_id
,
params
)
}
let
(
:environment_id
)
{
environment
.
id
}
let
(
:params
)
{
{
'weight'
=>
50
}
}
it
'executes the update service'
do
expect_next_instance_of
(
Environments
::
CanaryIngress
::
UpdateService
,
environment
.
project
,
nil
,
params
)
do
|
service
|
expect
(
service
).
to
receive
(
:execute
).
with
(
environment
)
end
subject
end
context
'when an environment does not exist'
do
let
(
:environment_id
)
{
non_existing_record_id
}
it
'does not execute the update service'
do
expect
(
Environments
::
CanaryIngress
::
UpdateService
).
not_to
receive
(
:new
)
subject
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment