Skip to content
Snippets Groups Projects
Commit 87fa73c5 authored by Andrew Newdigate's avatar Andrew Newdigate Committed by Kamil Trzciński
Browse files

Attribute Sidekiq workers according to their workloads

These workload attributes include:

1. Are jobs for this worker latency sensitve?
1. Does the worker rely on external dependencies?
1. What resource boundary is the worker limited by? This can be either
   cpu or memory.

These attributes are non-mandatory, but in future, SLOS for workers will
be determined by these attributes, and therefore, if a job has specific
latency requirements, they should be configured through these
attributes.
parent 629dda38
No related branches found
No related tags found
No related merge requests found
Showing
with 83 additions and 0 deletions
Loading
Loading
@@ -3,6 +3,10 @@
module WorkerAttributes
extend ActiveSupport::Concern
 
# Resource boundaries that workers can declare through the
# `worker_resource_boundary` attribute
VALID_RESOURCE_BOUNDARIES = [:memory, :cpu, :unknown].freeze
class_methods do
def feature_category(value)
raise "Invalid category. Use `feature_category_not_owned!` to mark a worker as not owned" if value == :not_owned
Loading
Loading
@@ -24,6 +28,48 @@ def feature_category_not_owned?
get_worker_attribute(:feature_category) == :not_owned
end
 
# This should be set for jobs that need to be run immediately, or, if
# they are delayed, risk creating inconsistencies in the application
# that could being perceived by the user as incorrect behavior
# (ie, a bug)
# See doc/development/sidekiq_style_guide.md#Latency-Sensitive-Jobs
# for details
def latency_sensitive_worker!
worker_attributes[:latency_sensitive] = true
end
# Returns a truthy value if the worker is latency sensitive.
# See doc/development/sidekiq_style_guide.md#Latency-Sensitive-Jobs
# for details
def latency_sensitive_worker?
worker_attributes[:latency_sensitive]
end
# Set this attribute on a job when it will call to services outside of the
# application, such as 3rd party applications, other k8s clusters etc See
# doc/development/sidekiq_style_guide.md#Jobs-with-External-Dependencies for
# details
def worker_has_external_dependencies!
worker_attributes[:external_dependencies] = true
end
# Returns a truthy value if the worker has external dependencies.
# See doc/development/sidekiq_style_guide.md#Jobs-with-External-Dependencies
# for details
def worker_has_external_dependencies?
worker_attributes[:external_dependencies]
end
def worker_resource_boundary(boundary)
raise "Invalid boundary" unless VALID_RESOURCE_BOUNDARIES.include? boundary
worker_attributes[:resource_boundary] = boundary
end
def get_worker_resource_boundary
worker_attributes[:resource_boundary] || :unknown
end
protected
 
# Returns a worker attribute declared on this class or its parent class.
Loading
Loading
Loading
Loading
@@ -5,6 +5,7 @@ class AuthorizedProjectsWorker
prepend WaitableWorker
 
feature_category :authentication_and_authorization
latency_sensitive_worker!
 
# This is a workaround for a Ruby 2.3.7 bug. rspec-mocks cannot restore the
# visibility of prepended modules. See https://github.com/rspec/rspec-mocks/issues/1231
Loading
Loading
Loading
Loading
@@ -5,6 +5,8 @@ class BuildFinishedWorker
include PipelineQueue
 
queue_namespace :pipeline_processing
latency_sensitive_worker!
worker_resource_boundary :cpu
 
# rubocop: disable CodeReuse/ActiveRecord
def perform(build_id)
Loading
Loading
Loading
Loading
@@ -6,6 +6,7 @@ class BuildHooksWorker
 
queue_namespace :pipeline_hooks
feature_category :continuous_integration
latency_sensitive_worker!
 
# rubocop: disable CodeReuse/ActiveRecord
def perform(build_id)
Loading
Loading
Loading
Loading
@@ -6,6 +6,8 @@ class BuildQueueWorker
 
queue_namespace :pipeline_processing
feature_category :continuous_integration
latency_sensitive_worker!
worker_resource_boundary :cpu
 
# rubocop: disable CodeReuse/ActiveRecord
def perform(build_id)
Loading
Loading
Loading
Loading
@@ -5,6 +5,7 @@ class BuildSuccessWorker
include PipelineQueue
 
queue_namespace :pipeline_processing
latency_sensitive_worker!
 
# rubocop: disable CodeReuse/ActiveRecord
def perform(build_id)
Loading
Loading
Loading
Loading
@@ -4,6 +4,11 @@ class ChatNotificationWorker
include ApplicationWorker
 
feature_category :chatops
latency_sensitive_worker!
# TODO: break this into multiple jobs
# as the `responder` uses external dependencies
# See https://gitlab.com/gitlab-com/gl-infra/scalability/issues/34
# worker_has_external_dependencies!
 
RESCHEDULE_INTERVAL = 2.seconds
 
Loading
Loading
Loading
Loading
@@ -7,6 +7,7 @@ class BuildScheduleWorker
 
queue_namespace :pipeline_processing
feature_category :continuous_integration
worker_resource_boundary :cpu
 
def perform(build_id)
::Ci::Build.find_by_id(build_id).try do |build|
Loading
Loading
Loading
Loading
@@ -5,6 +5,8 @@ class ClusterInstallAppWorker
include ClusterQueue
include ClusterApplications
 
worker_has_external_dependencies!
def perform(app_name, app_id)
find_application(app_name, app_id) do |app|
Clusters::Applications::InstallService.new(app).execute
Loading
Loading
Loading
Loading
@@ -5,6 +5,8 @@ class ClusterPatchAppWorker
include ClusterQueue
include ClusterApplications
 
worker_has_external_dependencies!
def perform(app_name, app_id)
find_application(app_name, app_id) do |app|
Clusters::Applications::PatchService.new(app).execute
Loading
Loading
Loading
Loading
@@ -4,6 +4,8 @@ class ClusterProjectConfigureWorker
include ApplicationWorker
include ClusterQueue
 
worker_has_external_dependencies!
def perform(project_id)
# Scheduled for removal in https://gitlab.com/gitlab-org/gitlab-foss/issues/59319
end
Loading
Loading
Loading
Loading
@@ -4,6 +4,8 @@ class ClusterProvisionWorker
include ApplicationWorker
include ClusterQueue
 
worker_has_external_dependencies!
def perform(cluster_id)
Clusters::Cluster.find_by_id(cluster_id).try do |cluster|
cluster.provider.try do |provider|
Loading
Loading
Loading
Loading
@@ -5,6 +5,8 @@ class ClusterUpgradeAppWorker
include ClusterQueue
include ClusterApplications
 
worker_has_external_dependencies!
def perform(app_name, app_id)
find_application(app_name, app_id) do |app|
Clusters::Applications::UpgradeService.new(app).execute
Loading
Loading
Loading
Loading
@@ -8,6 +8,9 @@ class ClusterWaitForAppInstallationWorker
INTERVAL = 10.seconds
TIMEOUT = 20.minutes
 
worker_has_external_dependencies!
worker_resource_boundary :cpu
def perform(app_name, app_id)
find_application(app_name, app_id) do |app|
Clusters::Applications::CheckInstallationProgressService.new(app).execute
Loading
Loading
Loading
Loading
@@ -5,6 +5,8 @@ class ClusterWaitForIngressIpAddressWorker
include ClusterQueue
include ClusterApplications
 
worker_has_external_dependencies!
def perform(app_name, app_id)
find_application(app_name, app_id) do |app|
Clusters::Applications::CheckIngressIpAddressService.new(app).execute
Loading
Loading
Loading
Loading
@@ -7,6 +7,8 @@ class UninstallWorker
include ClusterQueue
include ClusterApplications
 
worker_has_external_dependencies!
def perform(app_name, app_id)
find_application(app_name, app_id) do |app|
Clusters::Applications::UninstallService.new(app).execute
Loading
Loading
Loading
Loading
@@ -10,6 +10,9 @@ class WaitForUninstallAppWorker
INTERVAL = 10.seconds
TIMEOUT = 20.minutes
 
worker_has_external_dependencies!
worker_resource_boundary :cpu
def perform(app_name, app_id)
find_application(app_name, app_id) do |app|
Clusters::Applications::CheckUninstallProgressService.new(app).execute
Loading
Loading
Loading
Loading
@@ -14,6 +14,7 @@ module ObjectImporter
include NotifyUponDeath
 
feature_category :importers
worker_has_external_dependencies!
end
 
# project - An instance of `Project` to import the data into.
Loading
Loading
Loading
Loading
@@ -6,6 +6,8 @@ class CreatePipelineWorker
 
queue_namespace :pipeline_creation
feature_category :continuous_integration
latency_sensitive_worker!
worker_resource_boundary :cpu
 
def perform(project_id, user_id, ref, source, params = {})
project = Project.find(project_id)
Loading
Loading
Loading
Loading
@@ -6,6 +6,7 @@ class FinishedWorker
 
queue_namespace :deployment
feature_category :continuous_delivery
worker_resource_boundary :cpu
 
def perform(deployment_id)
Deployment.find_by_id(deployment_id).try(:execute_hooks)
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