From cb109e1631ba711fa02c5ceb968ae221b58c80a0 Mon Sep 17 00:00:00 2001 From: Maura Hubbell Date: Sat, 18 Jul 2020 07:59:13 -0700 Subject: [PATCH 1/3] Remove metriks --- Gemfile.lock | 5 -- lib/qless/middleware/metriks.rb | 45 -------------- spec/unit/middleware/metriks_spec.rb | 91 ---------------------------- 3 files changed, 141 deletions(-) delete mode 100644 lib/qless/middleware/metriks.rb delete mode 100644 spec/unit/middleware/metriks_spec.rb diff --git a/Gemfile.lock b/Gemfile.lock index 3d3ce390..ec6a0fde 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,7 +2,6 @@ PATH remote: . specs: qless (0.11.0) - metriks (~> 0.9) redis (>= 2.2, < 4.0.0.rc1) rusage (~> 0.2.0) sentry-raven (~> 0.15.6) @@ -55,10 +54,6 @@ GEM hitimes (1.2.6) http_parser.rb (0.5.3) method_source (0.8.2) - metriks (0.9.9.8) - atomic (~> 1.0) - avl_tree (~> 1.2.0) - hitimes (~> 1.1) mime-types (1.25) mini_portile (0.5.1) multi_json (1.12.2) diff --git a/lib/qless/middleware/metriks.rb b/lib/qless/middleware/metriks.rb deleted file mode 100644 index 10d347fc..00000000 --- a/lib/qless/middleware/metriks.rb +++ /dev/null @@ -1,45 +0,0 @@ -# Encoding: utf-8 - -require 'metriks' - -module Qless - module Middleware - module Metriks - - # Tracks the time jobs take, grouping the timings by the job class. - module TimeJobsByClass - def around_perform(job) - ::Metriks.timer("qless.job-times.#{job.klass_name}").time do - super - end - end - end - - # Increments a counter each time an instance of a particular job class - # completes. - # - # Usage: - # - # Qless::Worker.class_eval do - # include Qless::Middleware::CountEvents.new( - # SomeJobClass => "event_name", - # SomeOtherJobClass => "some_other_event" - # ) - # end - class CountEvents < Module - def initialize(class_to_event_map) - module_eval do # eval the block within the module instance - define_method :around_perform do |job| - super(job) - return unless job.state == 'complete' - return unless event_name = class_to_event_map[job.klass] - - counter = ::Metriks.counter("qless.job-events.#{event_name}") - counter.increment - end - end - end - end - end - end -end diff --git a/spec/unit/middleware/metriks_spec.rb b/spec/unit/middleware/metriks_spec.rb deleted file mode 100644 index d1dd187c..00000000 --- a/spec/unit/middleware/metriks_spec.rb +++ /dev/null @@ -1,91 +0,0 @@ -# Encoding: utf-8 - -require 'spec_helper' -require 'qless/middleware/metriks' -require 'qless/worker' - -module Qless - module Middleware - module Metriks - shared_context 'isolate metriks' do - before { ::Metriks::Registry.default.clear } - end - - describe TimeJobsByClass do - include_context 'isolate metriks' - - it 'tracks the time taken by the job, grouped by the class name' do - stub_const('JobABC', Class.new) - job = Qless::Job.build(double, JobABC, {}) - - base_class = Class.new do - def around_perform(job) - sleep 0.05 - end - end - - worker = Class.new(base_class) do - include TimeJobsByClass - end - - worker.new.around_perform(job) - - timer = ::Metriks.timer('qless.job-times.JobABC') - expect(timer.max).to be_within(10).percent_of(0.05) - end - end - - describe CountEvents do - include_context 'isolate metriks' - - before do - stub_const('Class1', Class.new) - stub_const('Class2', Class.new) - stub_const('Class3', Class.new) - end - - def worker(result = :complete) - base_class = Class.new do - define_method :around_perform do |job| - job.instance_variable_set(:@state, result.to_s) - end - end - - Class.new(base_class) do - include CountEvents.new( - Class1 => 'foo', - Class2 => 'bar' - ) - end - end - - def create_job_and_perform(klass, job_result = :complete) - job = Qless::Job.build(double, klass, {}) - worker(job_result).new.around_perform(job) - end - - it 'increments an event counter when a particular job completes' do - create_job_and_perform(Class1) - - expect(::Metriks.counter('qless.job-events.foo').count).to eq(1) - expect(::Metriks.counter('qless.job-events.bar').count).to eq(0) - - create_job_and_perform(Class2) - - expect(::Metriks.counter('qless.job-events.foo').count).to eq(1) - expect(::Metriks.counter('qless.job-events.bar').count).to eq(1) - end - - it 'does not increment the counter if the job fails' do - create_job_and_perform(Class1, :failed) - expect(::Metriks.counter('qless.job-events.foo').count).to eq(0) - end - - it 'does not increment a counter if it is not in the given map' do - create_job_and_perform(Class3) - expect(::Metriks::Registry.default.each.to_a).to eq([]) - end - end - end - end -end From 0260a685e945472c5d1477f12bdba9deff5cac3b Mon Sep 17 00:00:00 2001 From: Maura Hubbell Date: Sat, 18 Jul 2020 08:28:06 -0700 Subject: [PATCH 2/3] Remove atomic --- Gemfile.lock | 3 --- qless.gemspec | 1 - 2 files changed, 4 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index ec6a0fde..f89ba70a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -15,9 +15,6 @@ GEM remote: http://rubygems.org/ specs: ast (2.3.0) - atomic (1.1.99) - avl_tree (1.2.1) - atomic (~> 1.1) binding_of_caller (0.7.2) debug_inspector (>= 0.0.1) byebug (2.7.0) diff --git a/qless.gemspec b/qless.gemspec index c49419dd..797edee7 100644 --- a/qless.gemspec +++ b/qless.gemspec @@ -36,7 +36,6 @@ language-specific extension will also remain up to date. s.test_files = s.files.grep(/^(test|spec|features)\//) s.require_paths = ['lib'] - s.add_dependency 'metriks', '~> 0.9' s.add_dependency 'redis', ['>= 2.2', '< 4.0.0.rc1'] s.add_dependency 'rusage', '~> 0.2.0' s.add_dependency 'sentry-raven', '~> 0.15.6' From 2ed0a214540ac25d6aa5441e76a700e02b384a4d Mon Sep 17 00:00:00 2001 From: Maura Hubbell Date: Tue, 21 Jul 2020 10:57:21 -0700 Subject: [PATCH 3/3] Add no-op metriks middleware --- lib/qless/middleware/metriks.rb | 39 +++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 lib/qless/middleware/metriks.rb diff --git a/lib/qless/middleware/metriks.rb b/lib/qless/middleware/metriks.rb new file mode 100644 index 00000000..eb429125 --- /dev/null +++ b/lib/qless/middleware/metriks.rb @@ -0,0 +1,39 @@ +# Encoding: utf-8 + +# This middleware is now a no-op because +# the metriks dependency breaks builds. + +module Qless + module Middleware + module Metriks + + # Tracks the time jobs take, grouping the timings by the job class. + module TimeJobsByClass + def around_perform(job) + super + end + end + + # Increments a counter each time an instance of a particular job class + # completes. + # + # Usage: + # + # Qless::Worker.class_eval do + # include Qless::Middleware::CountEvents.new( + # SomeJobClass => "event_name", + # SomeOtherJobClass => "some_other_event" + # ) + # end + class CountEvents < Module + def initialize(class_to_event_map) + module_eval do # eval the block within the module instance + define_method :around_perform do |job| + super(job) + end + end + end + end + end + end +end