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
2c3e5971
Commit
2c3e5971
authored
Apr 21, 2021
by
David Fernandez
Committed by
Bob Van Landuyt
Apr 21, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add an inner class in the cleanup container repository worker [RUN ALL RSPEC] [RUN AS-IF-FOSS]
parent
20a537c8
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
226 additions
and
156 deletions
+226
-156
app/workers/container_expiration_policies/cleanup_container_repository_worker.rb
...xpiration_policies/cleanup_container_repository_worker.rb
+109
-62
spec/workers/container_expiration_policies/cleanup_container_repository_worker_spec.rb
...tion_policies/cleanup_container_repository_worker_spec.rb
+108
-91
spec/workers/container_expiration_policy_worker_spec.rb
spec/workers/container_expiration_policy_worker_spec.rb
+9
-3
No files found.
app/workers/container_expiration_policies/cleanup_container_repository_worker.rb
View file @
2c3e5971
...
...
@@ -21,6 +21,87 @@ module ContainerExpirationPolicies
cleanup_tags_service_deleted_size
]
.
freeze
delegate
:perform_work
,
:remaining_work_count
,
to: :inner_instance
def
inner_instance
strong_memoize
(
:inner_instance
)
do
if
loopless_enabled?
Loopless
.
new
(
self
)
else
Looping
.
new
(
self
)
end
end
end
def
max_running_jobs
return
0
unless
throttling_enabled?
::
Gitlab
::
CurrentSettings
.
container_registry_expiration_policies_worker_capacity
end
def
throttling_enabled?
Feature
.
enabled?
(
:container_registry_expiration_policies_throttling
)
end
def
loopless_enabled?
Feature
.
enabled?
(
:container_registry_expiration_policies_loopless
)
end
def
max_cleanup_execution_time
::
Gitlab
::
CurrentSettings
.
container_registry_delete_tags_service_timeout
end
def
log_info
(
extra_structure
)
logger
.
info
(
structured_payload
(
extra_structure
))
end
def
log_on_done
(
result
)
LOG_ON_DONE_FIELDS
.
each
do
|
field
|
value
=
result
.
payload
[
field
]
next
if
value
.
nil?
log_extra_metadata_on_done
(
field
,
value
)
end
before_truncate_size
=
result
.
payload
[
:cleanup_tags_service_before_truncate_size
]
after_truncate_size
=
result
.
payload
[
:cleanup_tags_service_after_truncate_size
]
truncated
=
before_truncate_size
&&
after_truncate_size
&&
before_truncate_size
!=
after_truncate_size
log_extra_metadata_on_done
(
:cleanup_tags_service_truncated
,
!!
truncated
)
log_extra_metadata_on_done
(
:running_jobs_count
,
running_jobs_count
)
end
# rubocop: disable Scalability/IdempotentWorker
# TODO: move the logic from this class to the parent one when container_registry_expiration_policies_loopless is removed
# Tracking issue: https://gitlab.com/gitlab-org/gitlab/-/issues/325273
class
Loopless
# TODO fill the logic here with the approach documented in
# https://gitlab.com/gitlab-org/gitlab/-/issues/267546#limited-worker
def
initialize
(
parent
)
@parent
=
parent
end
end
# rubocop: enable Scalability/IdempotentWorker
# rubocop: disable Scalability/IdempotentWorker
# TODO remove this class when `container_registry_expiration_policies_loopless` is removed
# Tracking issue: https://gitlab.com/gitlab-org/gitlab/-/issues/325273
class
Looping
include
Gitlab
::
Utils
::
StrongMemoize
delegate
:throttling_enabled?
,
:log_extra_metadata_on_done
,
:log_info
,
:log_on_done
,
:max_cleanup_execution_time
,
to: :@parent
def
initialize
(
parent
)
@parent
=
parent
end
def
perform_work
return
unless
throttling_enabled?
return
unless
container_repository
...
...
@@ -53,12 +134,6 @@ module ContainerExpirationPolicies
total_count
end
def
max_running_jobs
return
0
unless
throttling_enabled?
::
Gitlab
::
CurrentSettings
.
current_application_settings
.
container_registry_expiration_policies_worker_capacity
end
private
def
allowed_to_run?
(
container_repository
)
...
...
@@ -67,14 +142,6 @@ module ContainerExpirationPolicies
Time
.
zone
.
now
+
max_cleanup_execution_time
.
seconds
<
policy
.
next_run_at
end
def
throttling_enabled?
Feature
.
enabled?
(
:container_registry_expiration_policies_throttling
)
end
def
max_cleanup_execution_time
::
Gitlab
::
CurrentSettings
.
current_application_settings
.
container_registry_delete_tags_service_timeout
end
def
policy
project
.
container_expiration_policy
end
...
...
@@ -98,27 +165,7 @@ module ContainerExpirationPolicies
end
end
end
def
log_info
(
extra_structure
)
logger
.
info
(
structured_payload
(
extra_structure
))
end
def
log_on_done
(
result
)
LOG_ON_DONE_FIELDS
.
each
do
|
field
|
value
=
result
.
payload
[
field
]
next
if
value
.
nil?
log_extra_metadata_on_done
(
field
,
value
)
end
before_truncate_size
=
result
.
payload
[
:cleanup_tags_service_before_truncate_size
]
after_truncate_size
=
result
.
payload
[
:cleanup_tags_service_after_truncate_size
]
truncated
=
before_truncate_size
&&
after_truncate_size
&&
before_truncate_size
!=
after_truncate_size
log_extra_metadata_on_done
(
:cleanup_tags_service_truncated
,
!!
truncated
)
log_extra_metadata_on_done
(
:running_jobs_count
,
running_jobs_count
)
end
# rubocop: enable Scalability/IdempotentWorker
end
end
spec/workers/container_expiration_policies/cleanup_container_repository_worker_spec.rb
View file @
2c3e5971
...
...
@@ -106,6 +106,11 @@ RSpec.describe ContainerExpirationPolicies::CleanupContainerRepositoryWorker do
end
end
context
'with loopless disabled'
do
before
do
stub_feature_flags
(
container_registry_expiration_policies_loopless:
false
)
end
context
'with repository in cleanup scheduled state'
do
it_behaves_like
'handling all repository conditions'
end
...
...
@@ -198,6 +203,7 @@ RSpec.describe ContainerExpirationPolicies::CleanupContainerRepositoryWorker do
expect
{
subject
}.
not_to
change
{
ContainerRepository
.
waiting_for_cleanup
.
count
}
end
end
end
def
cleanup_service_response
(
status: :finished
,
repository
:,
cleanup_tags_service_original_size:
100
,
cleanup_tags_service_before_truncate_size:
80
,
cleanup_tags_service_after_truncate_size:
80
,
cleanup_tags_service_before_delete_size:
50
,
cleanup_tags_service_deleted_size:
50
)
ServiceResponse
.
success
(
...
...
@@ -230,6 +236,10 @@ RSpec.describe ContainerExpirationPolicies::CleanupContainerRepositoryWorker do
describe
'#remaining_work_count'
do
subject
{
worker
.
remaining_work_count
}
context
'with loopless disabled'
do
before
do
stub_feature_flags
(
container_registry_expiration_policies_loopless:
false
)
end
context
'with container repositoires waiting for cleanup'
do
let_it_be
(
:unfinished_repositories
)
{
create_list
(
:container_repository
,
2
,
:cleanup_unfinished
)
}
...
...
@@ -264,6 +274,7 @@ RSpec.describe ContainerExpirationPolicies::CleanupContainerRepositoryWorker do
end
end
end
end
describe
'#max_running_jobs'
do
let
(
:capacity
)
{
50
}
...
...
@@ -274,6 +285,11 @@ RSpec.describe ContainerExpirationPolicies::CleanupContainerRepositoryWorker do
stub_application_setting
(
container_registry_expiration_policies_worker_capacity:
capacity
)
end
context
'with loopless disabled'
do
before
do
stub_feature_flags
(
container_registry_expiration_policies_loopless:
false
)
end
it
{
is_expected
.
to
eq
(
capacity
)
}
context
'with feature flag disabled'
do
...
...
@@ -284,6 +300,7 @@ RSpec.describe ContainerExpirationPolicies::CleanupContainerRepositoryWorker do
it
{
is_expected
.
to
eq
(
0
)
}
end
end
end
def
expect_log_info
(
structure
)
expect
(
worker
.
logger
)
...
...
spec/workers/container_expiration_policy_worker_spec.rb
View file @
2c3e5971
...
...
@@ -35,12 +35,18 @@ RSpec.describe ContainerExpirationPolicyWorker do
end
context
'With no container expiration policies'
do
context
'with loopless disabled'
do
before
do
stub_feature_flags
(
container_registry_expiration_policies_loopless:
false
)
end
it
'does not execute any policies'
do
expect
(
ContainerRepository
).
not_to
receive
(
:for_project_id
)
expect
{
subject
}.
not_to
change
{
ContainerRepository
.
cleanup_scheduled
.
count
}
end
end
end
context
'with throttling enabled'
do
before
do
...
...
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