Commit a37544ab authored by Bob Van Landuyt's avatar Bob Van Landuyt

Reorder Sidekiq client middleware

The new order is as follows:

- ::Gitlab::SidekiqMiddleware::WorkerContext::Client
  Context for batch jobs
- ::Labkit::Middleware::Sidekiq::Client
  Serialize the context into the job hash
- ::Gitlab::SidekiqMiddleware::DuplicateJobs::Client
  Drop the job if needed
- ::Gitlab::SidekiqStatus::ClientMiddleware
  Keep track of the status of the job
- ::Gitlab::SidekiqMiddleware::AdminMode::Client
  Run the job with elevated permissions or not
- ::Gitlab::SidekiqMiddleware::ClientMetrics
  Count the enqueued job

This makes sure we add the logging information in the beginning of the
chain, as it could be needed for log messages coming form the other
middlewares.

Next we're doing deduplication, so we can skip any other work that
might not be needed.

The last step are the metrics, which counts enqueued jobs, this makes
sure that if anything happens in the chain, we don't count an enqueued
job. If that middleware is before the deduplication, count jobs that
might be dropped as enqueued.
parent b849cd74
......@@ -29,12 +29,12 @@ module Gitlab
# eg: `config.client_middleware(&Gitlab::SidekiqMiddleware.client_configurator)`
def self.client_configurator
lambda do |chain|
chain.add ::Gitlab::SidekiqStatus::ClientMiddleware
chain.add ::Gitlab::SidekiqMiddleware::ClientMetrics
chain.add ::Gitlab::SidekiqMiddleware::WorkerContext::Client # needs to be before the Labkit middleware
chain.add ::Labkit::Middleware::Sidekiq::Client
chain.add ::Gitlab::SidekiqMiddleware::AdminMode::Client
chain.add ::Gitlab::SidekiqMiddleware::DuplicateJobs::Client
chain.add ::Gitlab::SidekiqStatus::ClientMiddleware
chain.add ::Gitlab::SidekiqMiddleware::AdminMode::Client
chain.add ::Gitlab::SidekiqMiddleware::ClientMetrics
end
end
end
......
......@@ -134,12 +134,12 @@ describe Gitlab::SidekiqMiddleware do
let(:middleware_expected_args) { [worker_class_arg, job, queue, redis_pool] }
let(:expected_middlewares) do
[
Gitlab::SidekiqStatus::ClientMiddleware,
Gitlab::SidekiqMiddleware::ClientMetrics,
Gitlab::SidekiqMiddleware::WorkerContext::Client,
Labkit::Middleware::Sidekiq::Client,
Gitlab::SidekiqMiddleware::AdminMode::Client,
Gitlab::SidekiqMiddleware::DuplicateJobs::Client
::Gitlab::SidekiqMiddleware::WorkerContext::Client,
::Labkit::Middleware::Sidekiq::Client,
::Gitlab::SidekiqMiddleware::DuplicateJobs::Client,
::Gitlab::SidekiqStatus::ClientMiddleware,
::Gitlab::SidekiqMiddleware::AdminMode::Client,
::Gitlab::SidekiqMiddleware::ClientMetrics
]
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment