Add temporary Sidekiq concurrency limit overrides

What does this MR do and why?

Add temporary per-worker limits so on-call can raise or lower concurrency without disabling throttling globally.

  • Accept positive limits, including temporary caps for otherwise-unlimited workers. Those caps apply when jobs run, not at enqueue, so the client middleware makes no extra Redis call.
  • Default TTL to 30 minutes; allow up to one day.
  • Preserve overrides during adaptive throttling and reject paused workers.
  • Reject overrides for ConcurrencyLimit::ResumeWorker to avoid blocking deferred-job recovery.
  • Restore the unexpired adaptive limit or worker default on reset or expiry.
  • Reject overrides for workers bypassed by disable_sidekiq_concurrency_limit_middleware_<Worker>, since the middleware would ignore them.
  • Log override set and reset from LimitManager, so console use is recorded as well as API calls.
  • Add a sidekiq_concurrency_limit_override_limit gauge (0 when no override is active) so an override can be told apart from adaptive throttling.

Behaviour change in current_limit

LimitManager#current_limit now applies a pause (negative class limit) and the global sidekiq_concurrency_limit_middleware flag before reading Redis. On master a stored adaptive value won for up to its 30-minute TTL, so a pause only took effect once that value expired. ResumeWorker, QueueManager and ConcurrencyLimitSampler read current_limit and see the new behaviour. Pause precedence is needed for overrides, so this is kept in this MR rather than split out.

Core implementation and tests only. The admin API follows in a stacked MR. No infrastructure was applied or deployed.

References

gitlab-com/gl-infra/production-engineering#29754 (closed)

https://app.incident.io/gitlab/incidents/14022

gitlab-com/gl-infra/tenant-scale/tenant-services/team#221

Screenshots or screen recordings

Not applicable: backend change.

How to set up and validate locally

  1. Select a worker in a local Rails console.
  2. Create a Gitlab::SidekiqMiddleware::ConcurrencyLimit::LimitManager with its class name and the service REDIS_KEY_PREFIX.
  3. Call set_override_limit!(20, ttl: 60) and inspect current_limit and override_status.
  4. Call clear_override_limit! and verify the previous adaptive limit or default returns.
  5. Confirm paused workers and ConcurrencyLimit::ResumeWorker reject overrides.

MR acceptance checklist

  • Run integration specs through Caproni: spec/lib/gitlab/sidekiq_middleware/concurrency_limit/, spec/lib/gitlab/sidekiq_middleware/throttling/, spec/workers/concurrency_limit/, spec/lib/gitlab/sidekiq_logging/concurrency_limit_logger_spec.rb, spec/lib/gitlab/metrics/samplers/concurrency_limit_sampler_spec.rb (268 examples, 0 failures).
  • RuboCop passes on changed files.
  • Review client hot-path overhead: no Redis call on enqueue (10a9ef1a).
  • Review rollout gating: no feature flag. Overrides are inert until set, only the Rails console can set one until !260641 (merged) merges, and sidekiq_concurrency_limit_middleware is default_enabled: true.
Edited by Efeosa Eguavoen

Merge request reports

Loading
Loading