2019-11-20 16:06:38 -05:00
|
|
|
# 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)`
|
2022-09-20 14:13:03 -04:00
|
|
|
def self.server_configurator(metrics: true, arguments_logger: true)
|
2019-11-20 16:06:38 -05:00
|
|
|
lambda do |chain|
|
2021-05-19 11:10:40 -04:00
|
|
|
# Size limiter should be placed at the top
|
|
|
|
chain.add ::Gitlab::SidekiqMiddleware::SizeLimiter::Server
|
2020-03-01 22:07:58 -05:00
|
|
|
chain.add ::Gitlab::SidekiqMiddleware::Monitor
|
2021-06-28 02:07:45 -04:00
|
|
|
|
2021-09-20 20:09:28 -04:00
|
|
|
# Labkit wraps the job in the `Labkit::Context` resurrected from
|
|
|
|
# the job-hash. We need properties from the context for
|
|
|
|
# recording metrics, so this needs to be before
|
|
|
|
# `::Gitlab::SidekiqMiddleware::ServerMetrics` (if we're using
|
|
|
|
# that).
|
|
|
|
chain.add ::Labkit::Middleware::Sidekiq::Server
|
|
|
|
|
2021-06-28 02:07:45 -04:00
|
|
|
if metrics
|
|
|
|
chain.add ::Gitlab::SidekiqMiddleware::ServerMetrics
|
|
|
|
|
|
|
|
::Gitlab::SidekiqMiddleware::ServerMetrics.initialize_process_metrics
|
|
|
|
end
|
|
|
|
|
2020-03-01 22:07:58 -05:00
|
|
|
chain.add ::Gitlab::SidekiqMiddleware::ArgumentsLogger if arguments_logger
|
2020-04-24 08:10:16 -04:00
|
|
|
chain.add ::Gitlab::SidekiqMiddleware::RequestStoreMiddleware
|
2020-05-19 08:08:21 -04:00
|
|
|
chain.add ::Gitlab::SidekiqMiddleware::ExtraDoneLogMetadata
|
2020-03-01 22:07:58 -05:00
|
|
|
chain.add ::Gitlab::SidekiqMiddleware::BatchLoader
|
|
|
|
chain.add ::Gitlab::SidekiqMiddleware::InstrumentationLogger
|
|
|
|
chain.add ::Gitlab::SidekiqMiddleware::AdminMode::Server
|
2022-03-16 05:08:20 -04:00
|
|
|
chain.add ::Gitlab::SidekiqMiddleware::QueryAnalyzer
|
2020-08-04 11:09:27 -04:00
|
|
|
chain.add ::Gitlab::SidekiqVersioning::Middleware
|
2020-03-01 22:07:58 -05:00
|
|
|
chain.add ::Gitlab::SidekiqStatus::ServerMiddleware
|
|
|
|
chain.add ::Gitlab::SidekiqMiddleware::WorkerContext::Server
|
2021-09-02 08:11:03 -04:00
|
|
|
# DuplicateJobs::Server should be placed at the bottom, but before the SidekiqServerMiddleware,
|
|
|
|
# so we can compare the latest WAL location against replica
|
2020-03-01 22:07:58 -05:00
|
|
|
chain.add ::Gitlab::SidekiqMiddleware::DuplicateJobs::Server
|
2021-09-21 14:11:18 -04:00
|
|
|
chain.add ::Gitlab::Database::LoadBalancing::SidekiqServerMiddleware
|
2019-11-20 16:06:38 -05:00
|
|
|
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-03-01 22:07:58 -05:00
|
|
|
chain.add ::Gitlab::SidekiqMiddleware::WorkerContext::Client # needs to be before the Labkit middleware
|
|
|
|
chain.add ::Labkit::Middleware::Sidekiq::Client
|
2021-09-02 08:11:03 -04:00
|
|
|
# Sidekiq Client Middleware should be placed before DuplicateJobs::Client middleware,
|
|
|
|
# so we can store WAL location before we deduplicate the job.
|
2021-09-21 14:11:18 -04:00
|
|
|
chain.add ::Gitlab::Database::LoadBalancing::SidekiqClientMiddleware
|
2020-03-01 22:07:58 -05:00
|
|
|
chain.add ::Gitlab::SidekiqMiddleware::DuplicateJobs::Client
|
2020-04-06 08:10:44 -04:00
|
|
|
chain.add ::Gitlab::SidekiqStatus::ClientMiddleware
|
|
|
|
chain.add ::Gitlab::SidekiqMiddleware::AdminMode::Client
|
2021-09-02 08:11:03 -04:00
|
|
|
# Size limiter should be placed at the bottom, but before the metrics middleware
|
2021-02-25 07:11:01 -05:00
|
|
|
chain.add ::Gitlab::SidekiqMiddleware::SizeLimiter::Client
|
2020-04-06 08:10:44 -04:00
|
|
|
chain.add ::Gitlab::SidekiqMiddleware::ClientMetrics
|
2019-11-20 16:06:38 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|