├── .gitignore ├── .travis.yml ├── Gemfile ├── History.md ├── LICENSE ├── README.md ├── Rakefile ├── lib ├── librato-sidekiq.rb └── librato-sidekiq │ ├── client_middleware.rb │ ├── middleware.rb │ └── version.rb ├── librato-sidekiq.gemspec └── spec ├── spec_helper.rb └── unit ├── client_middleware_spec.rb └── middleware_spec.rb /.gitignore: -------------------------------------------------------------------------------- 1 | .rvmrc 2 | .bundle 3 | .idea 4 | Gemfile.lock 5 | tmtags 6 | tags 7 | tmp.sock 8 | *.gemfile.lock 9 | *.gem 10 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | rvm: 3 | - 2.0.0 4 | - 2.1.0 5 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | gemspec 3 | -------------------------------------------------------------------------------- /History.md: -------------------------------------------------------------------------------- 1 | librato-sidekiq changelog 2 | ===================== 3 | 4 | HEAD 5 | ======= 6 | - Drop librato-rails dependency since librato-rack is API compliant. this is now an implicit dependency and not managed by gemspec 7 | 8 | 0.1.0 9 | ======= 10 | - Initial commit 11 | - Each completed job measures current stats, timing, and increments processed for queue and worker name 12 | 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 Scott Klein 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | librato-sidekiq 2 | ===== 3 | 4 | librato-sidekiq is a simple gem to stick Sidekiq stats and granular processing counts/times into [Librato Metrics](http://metrics.librato.com/) 5 | 6 | 7 | Requirements and Compatibility 8 | ------------ 9 | 10 | Gems: 11 | 12 | * sidekiq 13 | * librato-rails OR librato-rack 14 | 15 | Compatibility (tested): 16 | 17 | * Ruby 2.0.0 18 | * Ruby 2.1.0 19 | 20 | (if you can confirm another version of Ruby, email me at scott@statuspage.io) 21 | 22 | 23 | Usage with Rails 3.x 24 | --------------------------- 25 | 26 | In your Gemfile: 27 | 28 | ```ruby 29 | gem 'librato-sidekiq' 30 | ``` 31 | 32 | In `config/environments/librato_sidekiq.rb`: 33 | 34 | ```ruby 35 | # only needed for fine-tuning, gem will enable all metrics by default 36 | Librato::Sidekiq::Middleware.configure do |c| 37 | # only enable for production 38 | c.enabled = Rails.env.production? 39 | 40 | # only allow these 3 queues 41 | c.whitelist_queues = %w(default cron notifications) 42 | 43 | # ignore these worker classes 44 | c.blacklist_classes = %w(CronSchedulerWorker NotificationCheckerWorker) 45 | end 46 | ``` 47 | 48 | 49 | Configuration 50 | ------------------------ 51 | Librato::Sidekiq accepts the following options. 52 | 53 | **enabled**: Boolean, true by default 54 | 55 | **whitelist_queues**: Array, list of queue names that will be the only ones sent to Librato (optional) 56 | 57 | **blacklist_queues**: Array, list of queue names that will not be sent to Librato (optional) 58 | 59 | **whitelist_classes**: Array, list of worker classes that will be the only ones sent to Librato (optional) 60 | 61 | **blacklist_classes**: Array, list of worker classes that will not be sent to Librato (optional) 62 | 63 | 64 | Contributing 65 | ------------- 66 | 67 | If you have a fix you wish to provide, please fork the code, fix in your local project and then send a pull request on github. Please ensure that you include a test which verifies your fix and update History.md with a one sentence description of your fix so you get credit as a contributor. 68 | 69 | 70 | Thanks 71 | ------------ 72 | 73 | Mike Perham - for creating [Sidekiq](http://github.com/mperham/sidekiq), a fantastic contribution to the ruby world 74 | 75 | Librato - for a great [metrics service](http://metrics.librato.com) 76 | 77 | 78 | Author 79 | ---------- 80 | 81 | Scott Klein, scott@statuspage.io, [statuspage.io](https://www.statuspage.io), If you like and use this project, please check out the [StatusPage.io service](https://www.statuspage.io/tour) for your project or company 82 | 83 | 84 | Copyright 85 | ----------- 86 | 87 | Copyright (c) 2013 Scott Klein. See LICENSE for details. 88 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'rspec/core/rake_task' 2 | 3 | RSpec::Core::RakeTask.new(:spec) 4 | 5 | task :default => :spec 6 | -------------------------------------------------------------------------------- /lib/librato-sidekiq.rb: -------------------------------------------------------------------------------- 1 | require 'librato-sidekiq/middleware' 2 | require 'librato-sidekiq/client_middleware' 3 | 4 | Librato::Sidekiq::Middleware.configure 5 | Librato::Sidekiq::ClientMiddleware.configure 6 | -------------------------------------------------------------------------------- /lib/librato-sidekiq/client_middleware.rb: -------------------------------------------------------------------------------- 1 | module Librato 2 | module Sidekiq 3 | class ClientMiddleware < Middleware 4 | def reconfigure 5 | # puts "Reconfiguring with: #{options}" 6 | ::Sidekiq.configure_client do |config| 7 | config.client_middleware do |chain| 8 | chain.remove self.class 9 | chain.add self.class, options 10 | end 11 | end 12 | end 13 | 14 | protected 15 | 16 | def track(tracking_group, stats, worker_instance, msg, queue, elapsed) 17 | tracking_group.increment 'queued' 18 | return unless allowed_to_submit queue, worker_instance 19 | # puts "doing Librato insert" 20 | tracking_group.group queue.to_s do |q| 21 | q.increment 'queued' 22 | 23 | # using something like User.delay.send_email invokes 24 | # a class name with slashes. remove them in favor of underscores 25 | q.group msg['class'].underscore.gsub('/', '_') do |w| 26 | w.increment 'queued' 27 | end 28 | end 29 | end 30 | end 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /lib/librato-sidekiq/middleware.rb: -------------------------------------------------------------------------------- 1 | require 'active_support/core_ext/class/attribute_accessors' 2 | 3 | module Librato 4 | module Sidekiq 5 | class Middleware 6 | cattr_accessor :enabled do 7 | true 8 | end 9 | 10 | cattr_accessor :whitelist_queues, :blacklist_queues, :whitelist_classes, :blacklist_classes do 11 | [] 12 | end 13 | 14 | def initialize(options = {}) 15 | # hard dependency on one or the other being present 16 | rails = !!defined?(Librato::Rails) 17 | rack = !!defined?(Librato::Rack) 18 | fail 'librato-sidekiq depends on having one of librato-rails or librato-rack installed' unless rails || rack 19 | 20 | # librato-rails >= 0.10 changes behavior of reporting agent 21 | if File.basename($PROGRAM_NAME) == 'sidekiq' && rails && Librato::Rails::VERSION.split('.')[1].to_i >= 10 && ENV['LIBRATO_AUTORUN'].nil? 22 | puts 'NOTICE: --------------------------------------------------------------------' 23 | puts 'NOTICE: THE REPORTING AGENT HAS NOT STARTED, AND NO METRICS WILL BE SENT' 24 | puts 'NOTICE: librato-rails >= 0.10 requires LIBRATO_AUTORUN=1 in your environment' 25 | puts 'NOTICE: --------------------------------------------------------------------' 26 | end 27 | 28 | reconfigure 29 | end 30 | 31 | def self.configure 32 | yield(self) if block_given? 33 | new # will call reconfigure 34 | end 35 | 36 | def options 37 | { 38 | enabled: enabled, 39 | whitelist_queues: whitelist_queues, 40 | blacklist_queues: blacklist_queues, 41 | whitelist_classes: whitelist_classes, 42 | blacklist_classes: blacklist_classes 43 | } 44 | end 45 | 46 | def reconfigure 47 | # puts "Reconfiguring with: #{options}" 48 | ::Sidekiq.configure_server do |config| 49 | config.server_middleware do |chain| 50 | chain.remove self.class 51 | chain.add self.class, options 52 | end 53 | end 54 | end 55 | 56 | # redis_pool is needed for the sidekiq 3 upgrade 57 | # https://github.com/mperham/sidekiq/blob/master/3.0-Upgrade.md 58 | def call(worker_instance, msg, queue, redis_pool = nil) 59 | start_time = Time.now 60 | result = yield 61 | elapsed = (Time.now - start_time).to_f 62 | 63 | return result unless enabled 64 | # puts "#{worker_instance} #{queue}" 65 | 66 | stats = ::Sidekiq::Stats.new 67 | 68 | Librato.group 'sidekiq' do |sidekiq| 69 | track sidekiq, stats, worker_instance, msg, queue, elapsed 70 | end 71 | 72 | result 73 | end 74 | 75 | private 76 | 77 | def track(tracking_group, stats, worker_instance, msg, queue, elapsed) 78 | submit_general_stats tracking_group, stats 79 | return unless allowed_to_submit queue, worker_instance 80 | # puts "doing Librato insert" 81 | tracking_group.group queue.to_s do |q| 82 | q.increment 'processed' 83 | q.timing 'time', elapsed 84 | q.measure 'enqueued', stats.queues[queue].to_i 85 | 86 | # using something like User.delay.send_email invokes 87 | # a class name with slashes. remove them in favor of underscores 88 | q.group msg['class'].underscore.gsub('/', '_') do |w| 89 | w.increment 'processed' 90 | w.timing 'time', elapsed 91 | end 92 | end 93 | end 94 | 95 | def submit_general_stats(group, stats) 96 | group.increment 'processed' 97 | { 98 | enqueued: nil, 99 | failed: nil, 100 | scheduled_size: 'scheduled' 101 | }.each do |method, name| 102 | group.measure((name || method).to_s, stats.send(method).to_i) 103 | end 104 | end 105 | 106 | def queue_in_whitelist(queue) 107 | whitelist_queues.nil? || whitelist_queues.empty? || whitelist_queues.include?(queue.to_s) 108 | end 109 | 110 | def queue_in_blacklist(queue) 111 | blacklist_queues.include?(queue.to_s) 112 | end 113 | 114 | def class_in_whitelist(worker_instance) 115 | whitelist_classes.nil? || whitelist_classes.empty? || whitelist_classes.include?(worker_instance.class.to_s) 116 | end 117 | 118 | def class_in_blacklist(worker_instance) 119 | blacklist_classes.include?(worker_instance.class.to_s) 120 | end 121 | 122 | def allowed_to_submit(queue, worker_instance) 123 | class_in_whitelist(worker_instance) && !class_in_blacklist(worker_instance) && queue_in_whitelist(queue) && !queue_in_blacklist(queue) 124 | end 125 | end 126 | end 127 | end 128 | -------------------------------------------------------------------------------- /lib/librato-sidekiq/version.rb: -------------------------------------------------------------------------------- 1 | module Librato 2 | module Sidekiq 3 | VERSION = "0.1.2" 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /librato-sidekiq.gemspec: -------------------------------------------------------------------------------- 1 | require './lib/librato-sidekiq/version' 2 | 3 | Gem::Specification.new do |s| 4 | s.name = %q{librato-sidekiq} 5 | s.version = Librato::Sidekiq::VERSION 6 | s.license = "MIT" 7 | 8 | s.authors = ["Scott Klein", "Ole Michaelis"] 9 | s.description = %q{Sidekiq hooks to push stats into Librato} 10 | s.email = %q{scott@statuspage.io} 11 | s.files = Dir.glob("lib/**/*") + [ 12 | "LICENSE", 13 | "README.md", 14 | "History.md", 15 | "Gemfile", 16 | "librato-sidekiq.gemspec", 17 | ] 18 | s.homepage = %q{http://github.com/StatusPage/librato-sidekiq} 19 | s.rdoc_options = ["--charset=UTF-8"] 20 | s.require_paths = ["lib"] 21 | s.summary = %q{Sidekiq hooks to push stats into Librato} 22 | s.test_files = Dir.glob("spec/**/*") 23 | 24 | s.add_dependency(%q, [">= 0"]) 25 | s.add_dependency(%q, [">= 0"]) 26 | 27 | s.add_development_dependency(%q) 28 | s.add_development_dependency(%q) 29 | s.add_development_dependency(%q) 30 | end 31 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require 'librato-sidekiq/middleware' 2 | require 'librato-sidekiq/client_middleware' 3 | require 'timecop' 4 | 5 | # Fix time 6 | RSpec.configure do |config| 7 | config.before(:suite) do 8 | Timecop.freeze(Date.today + 30) 9 | end 10 | config.after(:suite) do 11 | Timecop.return 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /spec/unit/client_middleware_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe Librato::Sidekiq::ClientMiddleware do 4 | 5 | before(:each) do 6 | stub_const "Librato::Rails", Class.new 7 | stub_const "Sidekiq", Module.new 8 | stub_const "Sidekiq::Stats", Class.new 9 | end 10 | 11 | let(:middleware) do 12 | allow(Sidekiq).to receive(:configure_client) 13 | Librato::Sidekiq::ClientMiddleware.new 14 | end 15 | 16 | describe '#intialize' do 17 | it 'should call reconfigure' do 18 | expect(Sidekiq).to receive(:configure_client) 19 | Librato::Sidekiq::ClientMiddleware.new 20 | end 21 | end 22 | 23 | describe '#configure' do 24 | 25 | before(:each) { Sidekiq.should_receive(:configure_client) } 26 | 27 | it 'should yield with it self as argument' do 28 | expect { |b| Librato::Sidekiq::ClientMiddleware.configure &b }.to yield_with_args(Librato::Sidekiq::ClientMiddleware) 29 | end 30 | 31 | it 'should return a new instance' do 32 | expect(Librato::Sidekiq::ClientMiddleware.configure).to be_an_instance_of Librato::Sidekiq::ClientMiddleware 33 | end 34 | 35 | end 36 | 37 | describe '#reconfigure' do 38 | 39 | let(:chain) { double() } 40 | let(:config) { double() } 41 | 42 | it 'should add itself to the server middleware chain' do 43 | expect(chain).to receive(:remove).with Librato::Sidekiq::ClientMiddleware 44 | expect(chain).to receive(:add).with Librato::Sidekiq::ClientMiddleware, middleware.options 45 | 46 | expect(config).to receive(:client_middleware).once.and_yield(chain) 47 | expect(Sidekiq).to receive(:configure_client).once.and_yield(config) 48 | 49 | middleware.reconfigure 50 | end 51 | end 52 | 53 | describe '#call' do 54 | 55 | let(:meter) { double(measure: nil, increment: nil, group: nil) } 56 | 57 | let(:queue_name) { 'some_awesome_queue' } 58 | let(:some_worker_instance) { nil } 59 | let(:some_message) { Hash['class', double(underscore: queue_name)] } 60 | 61 | let(:sidekiq_stats_instance_double) do 62 | double("Sidekiq::Stats", :enqueued => 1, :failed => 2, :scheduled_size => 3) 63 | end 64 | 65 | context 'when middleware is not enabled' do 66 | 67 | before(:each) { middleware.enabled = false } 68 | 69 | it { expect { |b| middleware.call(1,2,3,&b) }.to yield_with_no_args } 70 | 71 | it 'should not send any metrics' do 72 | Librato.should_not_receive(:group) 73 | end 74 | 75 | end 76 | 77 | context 'when middleware is enabled but queue is blacklisted' do 78 | 79 | before(:each) do 80 | allow(Sidekiq::Stats).to receive(:new).and_return(sidekiq_stats_instance_double) 81 | allow(Librato).to receive(:group).with('sidekiq').and_yield meter 82 | end 83 | 84 | before(:each) do 85 | middleware.enabled = true 86 | middleware.blacklist_queues = [] 87 | middleware.blacklist_queues << queue_name 88 | end 89 | 90 | it { expect { |b| middleware.call(some_worker_instance, some_message, queue_name, &b) }.to yield_with_no_args } 91 | 92 | it 'should measure increment queued metric' do 93 | expect(meter).to receive(:increment).with 'queued' 94 | middleware.call(some_worker_instance, some_message, queue_name) {} 95 | end 96 | 97 | end 98 | 99 | context 'when middleware is enabled and everything is whitlisted' do 100 | 101 | let(:sidekiq_group) { double(measure: nil, increment: nil, group: nil) } 102 | let(:queue_group) { double(measure: nil, increment: nil, timing: nil, group: nil) } 103 | let(:class_group) { double(measure: nil, increment: nil, timing: nil, group: nil) } 104 | 105 | before(:each) do 106 | middleware.enabled = true 107 | middleware.blacklist_queues = [] 108 | end 109 | 110 | before(:each) do 111 | allow(Sidekiq::Stats).to receive(:new).and_return(sidekiq_stats_instance_double) 112 | allow(Librato).to receive(:group).with('sidekiq').and_yield(sidekiq_group) 113 | allow(sidekiq_stats_instance_double).to receive(:queues) 114 | end 115 | 116 | it 'should measure queue metrics' do 117 | expect(sidekiq_group).to receive(:group).and_yield(queue_group) 118 | 119 | expect(queue_group).to receive(:increment).with "queued" 120 | 121 | middleware.call(some_worker_instance, some_message, queue_name) {} 122 | end 123 | 124 | it 'should measure class metrics' do 125 | expect(sidekiq_group).to receive(:group).and_yield(queue_group) 126 | expect(queue_group).to receive(:group).with(queue_name).and_yield(class_group) 127 | 128 | expect(class_group).to receive(:increment).with "queued" 129 | 130 | middleware.call(some_worker_instance, some_message, queue_name) {} 131 | end 132 | 133 | end 134 | 135 | end 136 | 137 | end 138 | -------------------------------------------------------------------------------- /spec/unit/middleware_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe Librato::Sidekiq::Middleware do 4 | 5 | before(:each) do 6 | stub_const "Librato::Rails", Class.new 7 | stub_const "Sidekiq", Module.new 8 | stub_const "Sidekiq::Stats", Class.new 9 | end 10 | 11 | let(:middleware) do 12 | allow(Sidekiq).to receive(:configure_server) 13 | Librato::Sidekiq::Middleware.new 14 | end 15 | 16 | describe '#intialize' do 17 | it 'should call reconfigure' do 18 | expect(Sidekiq).to receive(:configure_server) 19 | Librato::Sidekiq::Middleware.new 20 | end 21 | end 22 | 23 | describe '#configure' do 24 | 25 | before(:each) { Sidekiq.should_receive(:configure_server) } 26 | 27 | it 'should yield with it self as argument' do 28 | expect { |b| Librato::Sidekiq::Middleware.configure &b }.to yield_with_args(Librato::Sidekiq::Middleware) 29 | end 30 | 31 | it 'should return a new instance' do 32 | expect(Librato::Sidekiq::Middleware.configure).to be_an_instance_of Librato::Sidekiq::Middleware 33 | end 34 | 35 | end 36 | 37 | describe '#reconfigure' do 38 | 39 | let(:chain) { double() } 40 | let(:config) { double() } 41 | 42 | it 'should add itself to the server middleware chain' do 43 | expect(chain).to receive(:remove).with Librato::Sidekiq::Middleware 44 | expect(chain).to receive(:add).with Librato::Sidekiq::Middleware, middleware.options 45 | 46 | expect(config).to receive(:server_middleware).once.and_yield(chain) 47 | expect(Sidekiq).to receive(:configure_server).once.and_yield(config) 48 | 49 | middleware.reconfigure 50 | end 51 | end 52 | 53 | describe '#call' do 54 | 55 | let(:meter) { double(measure: nil, increment: nil, group: nil) } 56 | 57 | let(:queue_name) { 'some_awesome_queue' } 58 | let(:some_worker_instance) { nil } 59 | let(:some_message) { Hash['class', double(underscore: queue_name)] } 60 | 61 | let(:sidekiq_stats_instance_double) do 62 | double("Sidekiq::Stats", :enqueued => 1, :failed => 2, :scheduled_size => 3) 63 | end 64 | 65 | context 'when middleware is not enabled' do 66 | 67 | before(:each) { middleware.enabled = false } 68 | 69 | it { expect { |b| middleware.call(1,2,3,&b) }.to yield_with_no_args } 70 | 71 | it 'should not send any metrics' do 72 | Librato.should_not_receive(:group) 73 | end 74 | 75 | end 76 | 77 | context 'when middleware is enabled but queue is blacklisted' do 78 | 79 | before(:each) do 80 | allow(Sidekiq::Stats).to receive(:new).and_return(sidekiq_stats_instance_double) 81 | allow(Librato).to receive(:group).with('sidekiq').and_yield meter 82 | end 83 | 84 | before(:each) do 85 | middleware.enabled = true 86 | middleware.blacklist_queues = [] 87 | middleware.blacklist_queues << queue_name 88 | end 89 | 90 | it { expect { |b| middleware.call(some_worker_instance, some_message, queue_name, &b) }.to yield_with_no_args } 91 | 92 | it 'should measure increment processed metric' do 93 | expect(meter).to receive(:increment).with "processed" 94 | middleware.call(some_worker_instance, some_message, queue_name) {} 95 | end 96 | 97 | it 'should measure general metrics' do 98 | {"enqueued" => 1, "failed" => 2, "scheduled" => 3 }.each do |method, stat| 99 | expect(meter).to receive(:measure).with(method.to_s, stat) 100 | end 101 | expect(meter).to receive(:increment).with "processed" 102 | 103 | middleware.call(some_worker_instance, some_message, queue_name) {} 104 | end 105 | 106 | end 107 | 108 | context 'when middleware is enabled and everything is whitlisted' do 109 | 110 | let(:some_enqueued_value) { 20 } 111 | let(:queue_stat_hash) { Hash[queue_name, some_enqueued_value] } 112 | let(:sidekiq_group) { double(measure: nil, increment: nil, group: nil) } 113 | let(:queue_group) { double(measure: nil, increment: nil, timing: nil, group: nil) } 114 | let(:class_group) { double(measure: nil, increment: nil, timing: nil, group: nil) } 115 | 116 | before(:each) do 117 | middleware.enabled = true 118 | middleware.blacklist_queues = [] 119 | end 120 | 121 | before(:each) do 122 | allow(Sidekiq::Stats).to receive(:new).and_return(sidekiq_stats_instance_double) 123 | allow(Librato).to receive(:group).with('sidekiq').and_yield(sidekiq_group) 124 | allow(sidekiq_stats_instance_double).to receive(:queues).and_return queue_stat_hash 125 | end 126 | 127 | it 'should measure queue metrics' do 128 | expect(sidekiq_stats_instance_double).to receive(:queues).and_return queue_stat_hash 129 | 130 | expect(sidekiq_group).to receive(:group).and_yield(queue_group) 131 | 132 | expect(queue_group).to receive(:increment).with "processed" 133 | expect(queue_group).to receive(:timing).with "time", 0 134 | expect(queue_group).to receive(:measure).with "enqueued", some_enqueued_value 135 | 136 | middleware.call(some_worker_instance, some_message, queue_name) {} 137 | end 138 | 139 | it 'should measure class metrics' do 140 | expect(sidekiq_group).to receive(:group).and_yield(queue_group) 141 | expect(queue_group).to receive(:group).with(queue_name).and_yield(class_group) 142 | 143 | expect(class_group).to receive(:increment).with "processed" 144 | expect(class_group).to receive(:timing).with "time", 0 145 | 146 | middleware.call(some_worker_instance, some_message, queue_name) {} 147 | end 148 | 149 | end 150 | 151 | end 152 | 153 | end 154 | --------------------------------------------------------------------------------