Module: Gitlab::SidekiqMiddleware

Defined in:
lib/gitlab/sidekiq_middleware.rb,
lib/gitlab/sidekiq_middleware/monitor.rb,
lib/gitlab/sidekiq_middleware/batch_loader.rb,
lib/gitlab/sidekiq_middleware/memory_killer.rb,
lib/gitlab/sidekiq_middleware/client_metrics.rb,
lib/gitlab/sidekiq_middleware/metrics_helper.rb,
lib/gitlab/sidekiq_middleware/query_analyzer.rb,
lib/gitlab/sidekiq_middleware/server_metrics.rb,
lib/gitlab/sidekiq_middleware/worker_context.rb,
lib/gitlab/sidekiq_middleware/arguments_logger.rb,
lib/gitlab/sidekiq_middleware/admin_mode/client.rb,
lib/gitlab/sidekiq_middleware/admin_mode/server.rb,
lib/gitlab/sidekiq_middleware/size_limiter/client.rb,
lib/gitlab/sidekiq_middleware/size_limiter/server.rb,
lib/gitlab/sidekiq_middleware/duplicate_jobs/client.rb,
lib/gitlab/sidekiq_middleware/duplicate_jobs/server.rb,
lib/gitlab/sidekiq_middleware/worker_context/client.rb,
lib/gitlab/sidekiq_middleware/worker_context/server.rb,
lib/gitlab/sidekiq_middleware/instrumentation_logger.rb,
lib/gitlab/sidekiq_middleware/size_limiter/validator.rb,
lib/gitlab/sidekiq_middleware/extra_done_log_metadata.rb,
lib/gitlab/sidekiq_middleware/size_limiter/compressor.rb,
lib/gitlab/sidekiq_middleware/request_store_middleware.rb,
lib/gitlab/sidekiq_middleware/duplicate_jobs/strategies.rb,
lib/gitlab/sidekiq_middleware/duplicate_jobs/duplicate_job.rb,
lib/gitlab/sidekiq_middleware/duplicate_jobs/strategies/base.rb,
lib/gitlab/sidekiq_middleware/duplicate_jobs/strategies/none.rb,
lib/gitlab/sidekiq_middleware/size_limiter/exceed_limit_error.rb,
lib/gitlab/sidekiq_middleware/duplicate_jobs/strategies/until_executed.rb,
lib/gitlab/sidekiq_middleware/duplicate_jobs/strategies/until_executing.rb,
lib/gitlab/sidekiq_middleware/duplicate_jobs/strategies/deduplicates_when_scheduling.rb

Overview

The SidekiqMiddleware class is responsible for configuring the middleware stacks used in the client and server middlewares

Defined Under Namespace

Modules: AdminMode, DuplicateJobs, MetricsHelper, SizeLimiter, WorkerContext Classes: ArgumentsLogger, BatchLoader, ClientMetrics, ExtraDoneLogMetadata, InstrumentationLogger, MemoryKiller, Monitor, QueryAnalyzer, RequestStoreMiddleware, ServerMetrics

Class Method Summary collapse

Class Method Details

.client_configuratorObject

The result of this method should be passed to Sidekiq's `config.client_middleware` method eg: `config.client_middleware(&Gitlab::SidekiqMiddleware.client_configurator)`


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/gitlab/sidekiq_middleware.rb', line 50

def self.client_configurator
  lambda do |chain|
    chain.add ::Gitlab::SidekiqMiddleware::WorkerContext::Client # needs to be before the Labkit middleware
    chain.add ::Labkit::Middleware::Sidekiq::Client
    # Sidekiq Client Middleware should be placed before DuplicateJobs::Client middleware,
    # so we can store WAL location before we deduplicate the job.
    chain.add ::Gitlab::Database::LoadBalancing::SidekiqClientMiddleware
    chain.add ::Gitlab::SidekiqMiddleware::DuplicateJobs::Client
    chain.add ::Gitlab::SidekiqStatus::ClientMiddleware
    chain.add ::Gitlab::SidekiqMiddleware::AdminMode::Client
    # Size limiter should be placed at the bottom, but before the metrics middleware
    chain.add ::Gitlab::SidekiqMiddleware::SizeLimiter::Client
    chain.add ::Gitlab::SidekiqMiddleware::ClientMetrics
  end
end

.server_configurator(metrics: true, arguments_logger: true, memory_killer: true) ⇒ Object

The result of this method should be passed to Sidekiq's `config.server_middleware` method eg: `config.server_middleware(&Gitlab::SidekiqMiddleware.server_configurator)`


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/gitlab/sidekiq_middleware.rb', line 10

def self.server_configurator(metrics: true, arguments_logger: true, memory_killer: true)
  lambda do |chain|
    # Size limiter should be placed at the top
    chain.add ::Gitlab::SidekiqMiddleware::SizeLimiter::Server
    chain.add ::Gitlab::SidekiqMiddleware::Monitor

    # 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

    if metrics
      chain.add ::Gitlab::SidekiqMiddleware::ServerMetrics

      ::Gitlab::SidekiqMiddleware::ServerMetrics.initialize_process_metrics
    end

    chain.add ::Gitlab::SidekiqMiddleware::ArgumentsLogger if arguments_logger
    chain.add ::Gitlab::SidekiqMiddleware::MemoryKiller if memory_killer
    chain.add ::Gitlab::SidekiqMiddleware::RequestStoreMiddleware
    chain.add ::Gitlab::SidekiqMiddleware::ExtraDoneLogMetadata
    chain.add ::Gitlab::SidekiqMiddleware::BatchLoader
    chain.add ::Gitlab::SidekiqMiddleware::InstrumentationLogger
    chain.add ::Gitlab::SidekiqMiddleware::AdminMode::Server
    chain.add ::Gitlab::SidekiqMiddleware::QueryAnalyzer
    chain.add ::Gitlab::SidekiqVersioning::Middleware
    chain.add ::Gitlab::SidekiqStatus::ServerMiddleware
    chain.add ::Gitlab::SidekiqMiddleware::WorkerContext::Server
    # DuplicateJobs::Server should be placed  at the bottom, but before the SidekiqServerMiddleware,
    # so we can compare the latest WAL location against replica
    chain.add ::Gitlab::SidekiqMiddleware::DuplicateJobs::Server
    chain.add ::Gitlab::Database::LoadBalancing::SidekiqServerMiddleware
  end
end