2020-01-01 13:55:28 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
# The SidekiqMiddleware class is responsible for configuring the
|
|
|
|
# middleware stacks used in the client and server middlewares
|
|
|
|
module SidekiqMiddleware
|
|
|
|
# The result of this method should be passed to
|
|
|
|
# Sidekiq's `config.server_middleware` method
|
|
|
|
# eg: `config.server_middleware(&Gitlab::SidekiqMiddleware.server_configurator)`
|
2020-05-24 23:13:21 +05:30
|
|
|
def self.server_configurator(metrics: true, arguments_logger: true, memory_killer: true)
|
2020-01-01 13:55:28 +05:30
|
|
|
lambda do |chain|
|
2021-09-04 01:27:46 +05:30
|
|
|
# Size limiter should be placed at the top
|
|
|
|
chain.add ::Gitlab::SidekiqMiddleware::SizeLimiter::Server
|
2020-04-08 14:13:33 +05:30
|
|
|
chain.add ::Gitlab::SidekiqMiddleware::Monitor
|
|
|
|
chain.add ::Gitlab::SidekiqMiddleware::ServerMetrics if metrics
|
|
|
|
chain.add ::Gitlab::SidekiqMiddleware::ArgumentsLogger if arguments_logger
|
|
|
|
chain.add ::Gitlab::SidekiqMiddleware::MemoryKiller if memory_killer
|
2020-05-24 23:13:21 +05:30
|
|
|
chain.add ::Gitlab::SidekiqMiddleware::RequestStoreMiddleware
|
|
|
|
chain.add ::Gitlab::SidekiqMiddleware::ExtraDoneLogMetadata
|
2020-04-08 14:13:33 +05:30
|
|
|
chain.add ::Gitlab::SidekiqMiddleware::BatchLoader
|
|
|
|
chain.add ::Labkit::Middleware::Sidekiq::Server
|
|
|
|
chain.add ::Gitlab::SidekiqMiddleware::InstrumentationLogger
|
2021-09-04 01:27:46 +05:30
|
|
|
chain.add ::Gitlab::Database::LoadBalancing::SidekiqServerMiddleware if load_balancing_enabled?
|
2020-04-08 14:13:33 +05:30
|
|
|
chain.add ::Gitlab::SidekiqMiddleware::AdminMode::Server
|
2020-10-24 23:57:45 +05:30
|
|
|
chain.add ::Gitlab::SidekiqVersioning::Middleware
|
2020-04-08 14:13:33 +05:30
|
|
|
chain.add ::Gitlab::SidekiqStatus::ServerMiddleware
|
|
|
|
chain.add ::Gitlab::SidekiqMiddleware::WorkerContext::Server
|
|
|
|
chain.add ::Gitlab::SidekiqMiddleware::DuplicateJobs::Server
|
2020-01-01 13:55:28 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# The result of this method should be passed to
|
|
|
|
# Sidekiq's `config.client_middleware` method
|
|
|
|
# eg: `config.client_middleware(&Gitlab::SidekiqMiddleware.client_configurator)`
|
|
|
|
def self.client_configurator
|
|
|
|
lambda do |chain|
|
2020-04-08 14:13:33 +05:30
|
|
|
chain.add ::Gitlab::SidekiqMiddleware::WorkerContext::Client # needs to be before the Labkit middleware
|
|
|
|
chain.add ::Labkit::Middleware::Sidekiq::Client
|
|
|
|
chain.add ::Gitlab::SidekiqMiddleware::DuplicateJobs::Client
|
2020-04-22 19:07:51 +05:30
|
|
|
chain.add ::Gitlab::SidekiqStatus::ClientMiddleware
|
|
|
|
chain.add ::Gitlab::SidekiqMiddleware::AdminMode::Client
|
2021-04-17 20:07:23 +05:30
|
|
|
# Size limiter should be placed at the bottom, but before the metrics midleware
|
|
|
|
chain.add ::Gitlab::SidekiqMiddleware::SizeLimiter::Client
|
2020-04-22 19:07:51 +05:30
|
|
|
chain.add ::Gitlab::SidekiqMiddleware::ClientMetrics
|
2021-09-04 01:27:46 +05:30
|
|
|
chain.add ::Gitlab::Database::LoadBalancing::SidekiqClientMiddleware if load_balancing_enabled?
|
2020-01-01 13:55:28 +05:30
|
|
|
end
|
|
|
|
end
|
2021-09-04 01:27:46 +05:30
|
|
|
|
|
|
|
def self.load_balancing_enabled?
|
|
|
|
::Gitlab::Database::LoadBalancing.enable?
|
|
|
|
end
|
|
|
|
private_class_method :load_balancing_enabled?
|
2020-01-01 13:55:28 +05:30
|
|
|
end
|
|
|
|
end
|