Let SidekiqReporter publish zero for required-but-empty queues#33
Merged
Conversation
himynameisjonas
approved these changes
Jun 22, 2026
`SidekiqReporter` only published metrics for queues that currently exist in Redis. A queue with a per-queue CloudWatch autoscaling policy that never enqueues on a given shard would sit permanently in INSUFFICIENT_DATA, blocking scale-in for the whole ECS service. Add an optional `required_queues:` kwarg to `.enable`. The collector iterates `(required_queues + live.keys).uniq` and emits `0` (the correct latency for an empty queue) for any required queue missing from Redis. Behavior with `required_queues` omitted is unchanged, so existing consumers are unaffected. Bump to 0.3.0 (new public kwarg).
37ebb3b to
3e8cafe
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SidekiqReporteriteratesSidekiq::Queue.all, so a queue that has never been enqueued on a given shard is silently absent from CloudWatch. When that queue has a per-queue target-tracking autoscaling policy, its scale-in alarm sits permanently inINSUFFICIENT_DATAand the whole ECS service stops scaling in.What does this PR do?
required_queues:kwarg toSidekiqReporter.enable. Defaults to[], so existing consumers behave exactly as before.(required_queues + Sidekiq::Queue.all.keys).uniqand emits0for anyrequired_queuesentry not present in Redis.paused?behavior is preserved for live queues.Note
Consumer-side change for the Teamtailor monorepo: bump the gem and pass
required_queues: QUEUES_WITH_AUTOSCALING_POLICYfromconfig/initializers/03_sidekiq.rb. Follow-up PR.📖 Description for AI review
Context
ECS Fargate Sidekiq services on Teamtailor autoscale via per-queue CloudWatch target-tracking policies on the custom metric
sidekiq_queue_latency(namespaceTeamtailor/queue_times). Each queue has its own latency target (critical1s,default30s,import/low/mailers_low/within_1_hour/within_3_hours300s, etc.).AWS target-tracking only scales in when every policy can confirm it's safe. Verified on
eu-cyan-sidekiq-main(2026-06-22): the publisher emitted 13 queues but neverwithin_3_hours(that shard never enqueues to it), so its scale-in alarm sat inINSUFFICIENT_DATAand the service ratcheted from 1 to 5 tasks over weeks with zero scale-in events between spikes. Roughly $800/mo in waste across low-traffic shards.What was added
required_queues:kwarg onSidekiqReporter.enable. The collector lambda closes over it and passes it through tocollect_metrics.collect_metrics(required_queues = []): keeps zero-arg backwards compatibility, walks the dedup'd union ofrequired_queuesandSidekiq::Queue.all, defaulting absent queues to0. Preserves the existingpaused? ? 0 : latencyrule for live queues..enable, missing-queue zero emission, and dedup when a required queue is also live.What was intentionally left out
Key constraints to verify
.enablewithoutrequired_queues:must behave exactly as in 0.2.0. The default[]plus the dedup'd union ensures this.