sidekiq-instrumental 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a71199e63e3ff0539ef7e598490f27f0715d30b8
4
- data.tar.gz: bd14c5b122c230a542cbed342e0e1e186eee2bd4
2
+ SHA256:
3
+ metadata.gz: faa7a76c550d65983211b0f20bbd198d9b7995442e2995de66f24e9240f21ac7
4
+ data.tar.gz: 58d0d2e0d6388de6bad14c218a910769372f1e0503f1b02daf5b6746da4f3538
5
5
  SHA512:
6
- metadata.gz: 509476fe83703bd76e2a4a4129c5236e63877f695125fe0cc5e8695555235781bf401230a31e90ac28d6fb8391d327913645459777c8853a2be1f62e67487498
7
- data.tar.gz: 2f9a3de47b48efa0ee50a410899f5bf59bb6b21af4baec6c73afdb6dbafcb1ddc728a91bd1ce1bd7eee21aafe103642812cf58d89498b105fb7d3ef1de5467a5
6
+ metadata.gz: 241240850476d4200464a3b1b2d86b46242c8ed715def7122124057c94327271bf72de83a48b692203bd6170aa98d70f27797cbb714ad8cd85108efde078c736
7
+ data.tar.gz: ad872a46fdee9de36cd770dff16ff6ed6838b9cf9dfa9f1f14223121b51d2ae5ee17f0f677f13b62b9793703c447312429d6434dc224e70a892aaed41f2788d1
@@ -0,0 +1,132 @@
1
+ version: 2
2
+
3
+ defaults: &defaults
4
+ docker: &ruby_image
5
+ - &ruby_image
6
+ image: circleci/ruby:2.5-stretch
7
+ environment:
8
+ RUBYOPT: '-KU -E utf-8:utf-8'
9
+ BUNDLE_PATH: vendor/bundle
10
+ BUNDLE_VERSION: 1.17.3
11
+ BUNDLE_JOBS: 4
12
+ BUNDLE_RETRY: 3
13
+
14
+ filters:
15
+ test: &filter_test
16
+ filters:
17
+ tags:
18
+ ignore: /^v.*/
19
+ beta: &filter_beta
20
+ filters:
21
+ branches:
22
+ ignore: /.*/
23
+ tags:
24
+ only: /^v[0-9]+(\.[0-9]+)+(\.[a-z].+).*/
25
+ release: &filter_release
26
+ filters:
27
+ branches:
28
+ ignore: /.*/
29
+ tags:
30
+ only: /^v[0-9]+(\.[0-9]+)+/
31
+
32
+ workflows:
33
+ version: 2
34
+ build_test:
35
+ jobs:
36
+ - "Checkout":
37
+ <<: *filter_test
38
+ context: org-global
39
+ - "Test":
40
+ <<: *filter_test
41
+ context: org-global
42
+ requires:
43
+ - "Checkout"
44
+ build_test_beta:
45
+ jobs:
46
+ - "Checkout":
47
+ <<: *filter_beta
48
+ context: org-global
49
+ - "Test":
50
+ <<: *filter_beta
51
+ context: org-global
52
+ requires:
53
+ - "Checkout"
54
+ - "Publish":
55
+ <<: *filter_beta
56
+ context: org-global
57
+ requires:
58
+ - "Test"
59
+ build_test_release:
60
+ jobs:
61
+ - "Checkout":
62
+ <<: *filter_release
63
+ context: org-global
64
+ - "Test":
65
+ <<: *filter_release
66
+ context: org-global
67
+ requires:
68
+ - "Checkout"
69
+ - "Publish":
70
+ <<: *filter_release
71
+ context: org-global
72
+ requires:
73
+ - "Test"
74
+
75
+ jobs:
76
+ "Checkout":
77
+ <<: *defaults
78
+ steps:
79
+ - attach_workspace:
80
+ at: .
81
+ - checkout
82
+
83
+ - restore_cache:
84
+ keys:
85
+ - sidekiq-instrumental-bundle-v2-{{ checksum "Gemfile" }}-{{ checksum "sidekiq-instrumental.gemspec" }}
86
+ - run:
87
+ name: Install bundler
88
+ command: gem install bundler --version=$BUNDLE_VERSION
89
+ - run:
90
+ name: Bundle Install
91
+ command: |-
92
+ bundle _${BUNDLE_VERSION}_ check || bundle _${BUNDLE_VERSION}_ install --retry=$BUNDLE_RETRY
93
+ - save_cache:
94
+ key: sidekiq-instrumental-bundle-v2-{{ checksum "Gemfile" }}-{{ checksum "sidekiq-instrumental.gemspec" }}
95
+ paths:
96
+ - vendor/bundle
97
+ - Gemfile.lock
98
+
99
+ - persist_to_workspace:
100
+ root: .
101
+ paths: .
102
+ "Test":
103
+ <<: *defaults
104
+ steps:
105
+ - attach_workspace:
106
+ at: .
107
+ - run:
108
+ name: Install bundler
109
+ command: gem install bundler --version=$BUNDLE_VERSION
110
+ - run:
111
+ name: RSpec
112
+ command: bundle exec rspec
113
+ - run:
114
+ name: Rubocop
115
+ command: bundle exec rubocop
116
+ - run:
117
+ name: Build gem
118
+ command: |-
119
+ gem build *.gemspec
120
+ "Publish":
121
+ <<: *defaults
122
+ steps:
123
+ - attach_workspace:
124
+ at: .
125
+ - run:
126
+ name: Deploy to gem server
127
+ command: |-
128
+ ./bin/tag_check.sh
129
+ ./bin/setup-rubygems.sh
130
+ rm -rf pkg
131
+ rake build
132
+ gem push pkg/*.gem
data/.rubocop.yml ADDED
@@ -0,0 +1,6 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.3
3
+ Layout/MultilineMethodCallIndentation:
4
+ EnforcedStyle: indented_relative_to_receiver
5
+ Metrics:
6
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,15 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
+ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Next]
8
+ ### Added
9
+ ### Changed
10
+ ### Fixed
11
+
12
+ ## [0.3.0]
13
+ ### Fixed
14
+ - class name calculation now uses Sidekiq's display\_class\_name to support ActiveJob jobs
15
+
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in sidekiq-instrumental.gemspec
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Gem Version](https://badge.fury.io/rb/sidekiq-instrumental.svg)](https://badge.fury.io/rb/sidekiq-instrumental)
2
+
1
3
  # Sidekiq::Instrumental
2
4
 
3
5
  sidekiq-instrumental is a simple gem to record Sidekiq queue stats into [Instrumental](https://instrumentalapp.com/).
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
- task :default => :spec
8
+ task default: :spec
data/bin/console CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require "bundler/setup"
4
- require "sidekiq/instrumental"
4
+ require 'bundler/setup'
5
+ require 'sidekiq/instrumental'
5
6
 
6
7
  # You can add fixtures and/or initialization code here to make experimenting
7
8
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +11,5 @@ require "sidekiq/instrumental"
10
11
  # require "pry"
11
12
  # Pry.start
12
13
 
13
- require "irb"
14
+ require 'irb'
14
15
  IRB.start
@@ -0,0 +1,3 @@
1
+ mkdir ~/.gem
2
+ echo -e "---\n:rubygems_api_key: $RUBYGEMS_API_KEY" > ~/.gem/credentials
3
+ chmod 0600 ~/.gem/credentials
data/bin/tag_check.sh ADDED
@@ -0,0 +1,17 @@
1
+ #!/bin/sh
2
+
3
+ tag=`git describe --tags --exact-match HEAD 2> /dev/null`
4
+
5
+ if [ $? -eq 0 ]; then
6
+ version=`grep VERSION lib/sidekiq/instrumental/version.rb | sed -e "s/.*'\([^']*\)'.*/\1/"`
7
+
8
+ if [ "v$version" = "$tag" ]; then
9
+ echo "Revision $tag Matches $version"
10
+ else
11
+ echo "Revision $tag does not match $version"
12
+ exit 2
13
+ fi
14
+ else
15
+ echo "No tag found"
16
+ exit 1
17
+ fi
@@ -1,17 +1,23 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Sidekiq
2
4
  module Instrumental
5
+ # Configuration for gem
3
6
  class Configuration
4
- ARRAY_OPTIONS = [:whitelist_queues, :blacklist_queues, :whitelist_classes, :blacklist_classes]
7
+ ARRAY_OPTIONS = %i[
8
+ whitelist_queues blacklist_queues
9
+ whitelist_classes blacklist_classes
10
+ ].freeze
5
11
 
6
12
  attr_accessor :instrumental_agent
7
13
  attr_accessor :enabled, *ARRAY_OPTIONS
8
14
 
9
- alias_method :I, :instrumental_agent
15
+ alias I instrumental_agent
10
16
 
11
17
  def initialize
12
18
  @instrumental_agent = nil
13
19
  self.enabled = true
14
- ARRAY_OPTIONS.each {|o| self.send("#{o}=", [])}
20
+ ARRAY_OPTIONS.each { |o| send("#{o}=", []) }
15
21
  end
16
22
 
17
23
  def enabled?
@@ -19,7 +25,9 @@ module Sidekiq
19
25
  end
20
26
 
21
27
  def queue_in_whitelist(queue)
22
- whitelist_queues.nil? || whitelist_queues.empty? || whitelist_queues.include?(queue.to_s)
28
+ whitelist_queues.nil? ||
29
+ whitelist_queues.empty? ||
30
+ whitelist_queues.include?(queue.to_s)
23
31
  end
24
32
 
25
33
  def queue_in_blacklist(queue)
@@ -27,7 +35,9 @@ module Sidekiq
27
35
  end
28
36
 
29
37
  def class_in_whitelist(worker_instance)
30
- whitelist_classes.nil? || whitelist_classes.empty? || whitelist_classes.include?(worker_instance.class.to_s)
38
+ whitelist_classes.nil? ||
39
+ whitelist_classes.empty? ||
40
+ whitelist_classes.include?(worker_instance.class.to_s)
31
41
  end
32
42
 
33
43
  def class_in_blacklist(worker_instance)
@@ -35,8 +45,11 @@ module Sidekiq
35
45
  end
36
46
 
37
47
  def allowed_to_submit(queue, worker_instance)
38
- class_in_whitelist(worker_instance) && !class_in_blacklist(worker_instance) && queue_in_whitelist(queue) && !queue_in_blacklist(queue)
48
+ class_in_whitelist(worker_instance) &&
49
+ !class_in_blacklist(worker_instance) &&
50
+ queue_in_whitelist(queue) &&
51
+ !queue_in_blacklist(queue)
39
52
  end
40
53
  end
41
54
  end
42
- end
55
+ end
@@ -1,8 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'sidekiq/api'
2
4
 
3
5
  module Sidekiq
4
6
  module Instrumental
5
7
  module Middleware
8
+ # Shared base code for measuring stats for server and client sidekiq
6
9
  class Base
7
10
  attr_reader :config
8
11
 
@@ -10,14 +13,19 @@ module Sidekiq
10
13
  @config = config
11
14
  end
12
15
 
13
- def call(worker_instance, msg, queue, redis_pool = nil)
16
+ def call(worker_instance, msg, queue, _redis_pool = nil)
14
17
  start_time = Time.now
15
18
  result = yield
16
19
  elapsed = (Time.now - start_time).to_f
17
20
 
18
21
  return result unless config.enabled?
19
22
 
20
- track(::Sidekiq::Stats.new, worker_instance, msg, queue, elapsed)
23
+ track(
24
+ ::Sidekiq::Stats.new,
25
+ worker_instance,
26
+ ::Sidekiq::Job.new(msg),
27
+ queue, elapsed
28
+ )
21
29
 
22
30
  result
23
31
  end
@@ -25,11 +33,11 @@ module Sidekiq
25
33
  protected
26
34
 
27
35
  def increment(*args)
28
- config.I.increment *args
36
+ config.I.increment(*args)
29
37
  end
30
38
 
31
39
  def gauge(*args)
32
- config.I.gauge *args
40
+ config.I.gauge(*args)
33
41
  end
34
42
  end
35
43
  end
@@ -1,22 +1,23 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Sidekiq
2
4
  module Instrumental
3
5
  module Middleware
6
+ # Client side sidekiq middleware
4
7
  class Client < Base
5
-
6
- def track(stats, worker_instance, msg, queue, elapsed)
7
-
8
+ def track(_stats, worker_instance, msg, queue, _elapsed)
8
9
  increment('sidekiq.queued')
9
10
 
10
11
  return unless config.allowed_to_submit queue, worker_instance
11
12
 
12
- base_key = "sidekiq.#{queue.to_s}."
13
+ base_key = "sidekiq.#{queue}."
13
14
  increment(base_key + 'queued')
14
15
 
15
- base_key += msg['class'].underscore.gsub('/', '_') + '.'
16
+ base_key += msg.display_class.underscore.gsub('/', '_') + '.'
16
17
 
17
18
  increment(base_key + 'queued')
18
19
  end
19
20
  end
20
21
  end
21
22
  end
22
- end
23
+ end
@@ -1,6 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Sidekiq
2
4
  module Instrumental
3
5
  module Middleware
6
+ # Server side sidekiq middleware
4
7
  class Server < Base
5
8
  protected
6
9
 
@@ -9,26 +12,26 @@ module Sidekiq
9
12
 
10
13
  return unless config.allowed_to_submit queue, worker_instance
11
14
 
12
- base_key = "sidekiq.#{queue.to_s}."
15
+ base_key = "sidekiq.#{queue}."
13
16
 
14
17
  increment(base_key + 'processed')
15
18
  gauge(base_key + 'time', elapsed)
16
19
  gauge(base_key + 'enqueued', stats.queues[queue].to_i)
17
20
  gauge(base_key + 'latency', Sidekiq::Queue.new(queue.to_s).latency)
18
- base_key += msg['class'].underscore.gsub('/', '_') + '.'
21
+ base_key += msg.display_class.underscore.gsub('/', '_') + '.'
19
22
 
20
23
  increment(base_key + 'processed')
21
- increment(base_key + 'time', elapsed)
24
+ gauge(base_key + 'time', elapsed)
22
25
  end
23
26
 
24
27
  def submit_general_stats(stats)
25
- increment("sidekiq.processed")
28
+ increment('sidekiq.processed')
26
29
  {
27
- enqueued: nil,
28
- failed: nil,
29
- scheduled_size: 'scheduled'
30
+ enqueued: nil,
31
+ failed: nil,
32
+ scheduled_size: 'scheduled'
30
33
  }.each do |method, name|
31
- gauge("sidekiq.#{(name || method).to_s}", stats.send(method).to_i)
34
+ gauge("sidekiq.#{(name || method)}", stats.send(method).to_i)
32
35
  end
33
36
  end
34
37
  end
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Sidekiq
2
4
  module Instrumental
3
- VERSION = "0.2.3"
5
+ VERSION = '0.3.0'
4
6
  end
5
7
  end
@@ -1,4 +1,6 @@
1
- require "sidekiq/instrumental/version"
1
+ # frozen_string_literal: true
2
+
3
+ require 'sidekiq/instrumental/version'
2
4
  require 'sidekiq/instrumental/configuration'
3
5
  require 'sidekiq/instrumental/middleware/base'
4
6
  require 'sidekiq/instrumental/middleware/client'
@@ -6,18 +8,18 @@ require 'sidekiq/instrumental/middleware/server'
6
8
  require 'sidekiq'
7
9
 
8
10
  module Sidekiq
9
- module Instrumental
11
+ module Instrumental # :nodoc:
10
12
  def self.config
11
13
  @config ||= Sidekiq::Instrumental::Configuration.new
12
14
  end
13
15
 
14
16
  def self.configure
15
- yield self.config if block_given?
16
- self.register
17
+ yield config if block_given?
18
+ register
17
19
  end
18
20
 
19
21
  def self.register
20
- new_config = self.config.dup
22
+ new_config = config.dup
21
23
 
22
24
  ::Sidekiq.configure_server do |config|
23
25
  config.server_middleware do |chain|
@@ -1,28 +1,38 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'sidekiq/instrumental/version'
5
6
 
6
7
  Gem::Specification.new do |spec|
7
- spec.name = "sidekiq-instrumental"
8
- spec.version = Sidekiq::Instrumental::VERSION
9
- spec.authors = ["Edward Rudd"]
10
- spec.email = ["urkle@outoforder.cc"]
8
+ spec.name = 'sidekiq-instrumental'
9
+ spec.version = Sidekiq::Instrumental::VERSION
10
+ spec.authors = ['Edward Rudd']
11
+ spec.email = ['urkle@outoforder.cc']
12
+
13
+ spec.summary = 'Send Sidekiq status into Instrumental after every job'
14
+ spec.homepage = 'https://github.com/NetsoftHoldings/sidekiq-instrumental/'
15
+ spec.license = 'MIT'
11
16
 
12
- spec.summary = %q{Send Sidekiq status into Instrumental after every job}
13
- spec.homepage = "https://github.com/NetsoftHoldings/sidekiq-instrumental/"
14
- spec.license = "MIT"
17
+ spec.files = `git ls-files -z`
18
+ .split("\x0")
19
+ .reject { |f| f.match(%r{^(spec)/}) }
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ['lib']
22
+ spec.test_files = Dir['spec/**/*']
15
23
 
16
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
17
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
- spec.require_paths = ["lib"]
19
- spec.test_files = Dir['spec/**/*']
24
+ spec.required_ruby_version = '>= 2.3'
20
25
 
21
- spec.add_runtime_dependency 'instrumental_agent', ">= 0.13"
26
+ spec.add_runtime_dependency 'instrumental_agent', '>= 0.13'
22
27
  spec.add_runtime_dependency 'sidekiq', '>= 3.5'
23
28
 
24
- spec.add_development_dependency "bundler", "~> 1.9"
25
- spec.add_development_dependency "simplecov", "~> 0.11"
26
- spec.add_development_dependency "rake", "~> 10.0"
27
- spec.add_development_dependency "rspec", "~> 3.4"
29
+ spec.add_development_dependency 'activesupport', '~> 5.0'
30
+ spec.add_development_dependency 'bundler', '~> 1.9'
31
+ spec.add_development_dependency 'rake', '>= 10.0'
32
+ spec.add_development_dependency 'rspec', '~> 3.4'
33
+ spec.add_development_dependency 'simplecov', '~> 0.11'
34
+ spec.add_development_dependency 'timecop', '~> 0.9.1'
35
+
36
+ spec.add_development_dependency 'rubocop', '~> 0.79.0'
37
+ spec.add_development_dependency 'rubocop-rspec', '~> 1.37.1'
28
38
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe Sidekiq::Instrumental::Configuration do
@@ -59,23 +61,38 @@ RSpec.describe Sidekiq::Instrumental::Configuration do
59
61
  expect(subject.send(method, 'other')).to eq(false)
60
62
  end
61
63
  end
62
-
63
64
  end
64
65
 
65
66
  describe '#queue_in_whitelist' do
66
- include_examples 'whitelist checks', :whitelist_queues, :queue_in_whitelist, ['default'], 'default'
67
+ include_examples 'whitelist checks',
68
+ :whitelist_queues,
69
+ :queue_in_whitelist,
70
+ ['default'],
71
+ 'default'
67
72
  end
68
73
 
69
74
  describe '#queue_in_blacklist' do
70
- include_examples 'blacklist checks', :blacklist_queues, :queue_in_blacklist, ['default'], 'default'
75
+ include_examples 'blacklist checks',
76
+ :blacklist_queues,
77
+ :queue_in_blacklist,
78
+ ['default'],
79
+ 'default'
71
80
  end
72
81
 
73
82
  describe '#class_in_whitelist' do
74
- include_examples 'whitelist checks', :whitelist_classes, :class_in_whitelist, ['Array'], []
83
+ include_examples 'whitelist checks',
84
+ :whitelist_classes,
85
+ :class_in_whitelist,
86
+ ['Array'],
87
+ []
75
88
  end
76
89
 
77
90
  describe '#class_in_blacklist' do
78
- include_examples 'blacklist checks', :blacklist_classes, :class_in_blacklist, ['Array'], []
91
+ include_examples 'blacklist checks',
92
+ :blacklist_classes,
93
+ :class_in_blacklist,
94
+ ['Array'],
95
+ []
79
96
  end
80
97
 
81
98
  describe '#allowed_to_submit' do
@@ -83,4 +100,4 @@ RSpec.describe Sidekiq::Instrumental::Configuration do
83
100
  expect(subject.allowed_to_submit('default', [])).to eq(true)
84
101
  end
85
102
  end
86
- end
103
+ end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ require 'active_support/core_ext/string/inflections'
6
+
7
+ RSpec.describe Sidekiq::Instrumental::Middleware::Client do
8
+ let(:config) { Sidekiq::Instrumental::Configuration.new }
9
+ let(:middleware) { described_class.new(config) }
10
+ let(:sidekiq_stats) { double('Sidekiq::Stats') }
11
+ let(:worker) { {} }
12
+ let(:msg) { { 'class' => 'MyClassName' } }
13
+ let(:queue) { 'default' }
14
+
15
+ before do
16
+ allow(config).to receive(:enabled?).and_return(true)
17
+ allow(middleware).to receive(:increment)
18
+ allow(::Sidekiq::Stats).to receive(:new).and_return(sidekiq_stats)
19
+ end
20
+
21
+ subject { middleware.call(worker, msg, queue) {} }
22
+
23
+ it 'increments the queued metric' do
24
+ expect(middleware).to receive(:increment).with('sidekiq.queued')
25
+
26
+ subject
27
+ end
28
+
29
+ it 'checks if the worker class is allowed to submit detailed metrics' do
30
+ expect(config).to receive(:allowed_to_submit).with(queue, worker)
31
+
32
+ subject
33
+ end
34
+
35
+ it 'increments the queued metric for the queue' do
36
+ expect(middleware).to receive(:increment).with("sidekiq.#{queue}.queued")
37
+
38
+ subject
39
+ end
40
+
41
+ it 'calls display_class to get the class name' do
42
+ expect_any_instance_of(::Sidekiq::Job)
43
+ .to receive(:display_class).and_call_original
44
+
45
+ subject
46
+ end
47
+
48
+ it 'increments the queued metric for the worker class name' do
49
+ expect(middleware).to receive(:increment)
50
+ .with("sidekiq.#{queue}.my_class_name.queued")
51
+
52
+ subject
53
+ end
54
+ end
@@ -0,0 +1,103 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ require 'active_support/core_ext/string/inflections'
6
+
7
+ RSpec.describe Sidekiq::Instrumental::Middleware::Server do
8
+ let(:config) { Sidekiq::Instrumental::Configuration.new }
9
+ let(:middleware) { described_class.new(config) }
10
+ let(:sidekiq_stats) do
11
+ instance_double('Sidekiq::Stats',
12
+ enqueued: 1,
13
+ failed: 2,
14
+ scheduled_size: 3,
15
+ queues: { queue => 4 })
16
+ end
17
+ let(:sidekiq_queue) { instance_double('Sidekiq::Queue', latency: 5) }
18
+ let(:worker) { {} }
19
+ let(:msg) { { 'class' => 'MyClassName' } }
20
+ let(:queue) { 'default' }
21
+
22
+ before do
23
+ allow(config).to receive(:enabled?).and_return(true)
24
+ allow(middleware).to receive(:increment)
25
+ allow(middleware).to receive(:gauge)
26
+ allow(::Sidekiq::Stats).to receive(:new).and_return(sidekiq_stats)
27
+ allow(::Sidekiq::Queue).to receive(:new).and_return(sidekiq_queue)
28
+ end
29
+
30
+ subject do
31
+ Timecop.freeze do
32
+ middleware.call(worker, msg, queue) do
33
+ Timecop.travel(0.5)
34
+ end
35
+ end
36
+ end
37
+
38
+ it 'submits general stats' do
39
+ expect(middleware).to receive(:gauge)
40
+ .with('sidekiq.enqueued', 1)
41
+ expect(middleware).to receive(:gauge)
42
+ .with('sidekiq.failed', 2)
43
+ expect(middleware).to receive(:gauge)
44
+ .with('sidekiq.scheduled', 3)
45
+
46
+ subject
47
+ end
48
+
49
+ it 'increments the processed metric' do
50
+ expect(middleware).to receive(:increment)
51
+ .with('sidekiq.processed')
52
+
53
+ subject
54
+ end
55
+
56
+ it 'increments the processed metric for the queue' do
57
+ expect(middleware).to receive(:increment)
58
+ .with("sidekiq.#{queue}.processed")
59
+
60
+ subject
61
+ end
62
+
63
+ it 'gauge the elapsed time metric for the queue' do
64
+ expect(middleware).to receive(:gauge)
65
+ .with(
66
+ "sidekiq.#{queue}.time",
67
+ be_within(0.001).of(0.5)
68
+ )
69
+
70
+ subject
71
+ end
72
+
73
+ it 'gauge the enqueued metric for the queue' do
74
+ expect(middleware).to receive(:gauge)
75
+ .with("sidekiq.#{queue}.enqueued", 4)
76
+
77
+ subject
78
+ end
79
+
80
+ it 'gauge the latency metric for the queue' do
81
+ expect(middleware).to receive(:gauge)
82
+ .with("sidekiq.#{queue}.latency", 5)
83
+
84
+ subject
85
+ end
86
+
87
+ it 'increments processed metric for the class' do
88
+ expect(middleware).to receive(:increment)
89
+ .with("sidekiq.#{queue}.my_class_name.processed")
90
+
91
+ subject
92
+ end
93
+
94
+ it 'gauge elapsed time metric for the class' do
95
+ expect(middleware).to receive(:gauge)
96
+ .with(
97
+ "sidekiq.#{queue}.my_class_name.time",
98
+ be_within(0.001).of(0.5)
99
+ )
100
+
101
+ subject
102
+ end
103
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'spec_helper'
2
4
 
3
5
  RSpec.describe Sidekiq::Instrumental do
@@ -8,7 +10,8 @@ RSpec.describe Sidekiq::Instrumental do
8
10
  describe '::config' do
9
11
  describe '::config' do
10
12
  it 'should return a Configuration object' do
11
- expect(described_class.config).to be_an_instance_of(described_class::Configuration)
13
+ expect(described_class.config)
14
+ .to be_an_instance_of(described_class::Configuration)
12
15
  end
13
16
  end
14
17
  end
@@ -22,7 +25,8 @@ RSpec.describe Sidekiq::Instrumental do
22
25
  end
23
26
 
24
27
  it 'should yield the configuration object' do
25
- expect { |b| described_class.configure(&b) }.to yield_with_args(described_class.config)
28
+ expect { |b| described_class.configure(&b) }
29
+ .to yield_with_args(described_class.config)
26
30
  end
27
31
  end
28
32
 
@@ -39,8 +43,13 @@ RSpec.describe Sidekiq::Instrumental do
39
43
  allow(config).to receive(:client_middleware)
40
44
  allow(Sidekiq).to receive(:configure_server).and_yield(config)
41
45
 
42
- expect(server_chain).to receive(:remove).with(described_class::Middleware::Server)
43
- expect(server_chain).to receive(:add).with(described_class::Middleware::Server, an_instance_of(described_class::Configuration))
46
+ expect(server_chain).to receive(:remove)
47
+ .with(described_class::Middleware::Server)
48
+ expect(server_chain).to receive(:add)
49
+ .with(described_class::Middleware::Server,
50
+ an_instance_of(
51
+ described_class::Configuration
52
+ ))
44
53
 
45
54
  described_class.register
46
55
  end
@@ -52,8 +61,13 @@ RSpec.describe Sidekiq::Instrumental do
52
61
  allow(config).to receive(:client_middleware).and_yield(client_chain)
53
62
  allow(Sidekiq).to receive(:configure_server).and_yield(config)
54
63
 
55
- expect(client_chain).to receive(:remove).with(described_class::Middleware::Client)
56
- expect(client_chain).to receive(:add).with(described_class::Middleware::Client, an_instance_of(described_class::Configuration))
64
+ expect(client_chain).to receive(:remove)
65
+ .with(described_class::Middleware::Client)
66
+ expect(client_chain).to receive(:add)
67
+ .with(described_class::Middleware::Client,
68
+ an_instance_of(
69
+ described_class::Configuration
70
+ ))
57
71
 
58
72
  described_class.register
59
73
  end
@@ -66,8 +80,13 @@ RSpec.describe Sidekiq::Instrumental do
66
80
  allow(config).to receive(:client_middleware).and_yield(client_chain)
67
81
  allow(Sidekiq).to receive(:configure_client).and_yield(config)
68
82
 
69
- expect(client_chain).to receive(:remove).with(described_class::Middleware::Client)
70
- expect(client_chain).to receive(:add).with(described_class::Middleware::Client, an_instance_of(described_class::Configuration))
83
+ expect(client_chain).to receive(:remove)
84
+ .with(described_class::Middleware::Client)
85
+ expect(client_chain).to receive(:add)
86
+ .with(described_class::Middleware::Client,
87
+ an_instance_of(
88
+ described_class::Configuration
89
+ ))
71
90
 
72
91
  described_class.register
73
92
  end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,11 @@
1
- $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
2
4
  require 'simplecov'
3
5
  require 'sidekiq/instrumental'
6
+ require 'timecop'
7
+
8
+ Timecop.safe_mode = true
4
9
 
5
10
  RSpec.configure do |config|
6
11
  config.expect_with :rspec do |expectations|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-instrumental
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Edward Rudd
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-29 00:00:00.000000000 Z
11
+ date: 2020-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: instrumental_agent
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +66,34 @@ dependencies:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
68
  version: '1.9'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.4'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.4'
55
97
  - !ruby/object:Gem::Dependency
56
98
  name: simplecov
57
99
  requirement: !ruby/object:Gem::Requirement
@@ -67,33 +109,47 @@ dependencies:
67
109
  - !ruby/object:Gem::Version
68
110
  version: '0.11'
69
111
  - !ruby/object:Gem::Dependency
70
- name: rake
112
+ name: timecop
71
113
  requirement: !ruby/object:Gem::Requirement
72
114
  requirements:
73
115
  - - "~>"
74
116
  - !ruby/object:Gem::Version
75
- version: '10.0'
117
+ version: 0.9.1
76
118
  type: :development
77
119
  prerelease: false
78
120
  version_requirements: !ruby/object:Gem::Requirement
79
121
  requirements:
80
122
  - - "~>"
81
123
  - !ruby/object:Gem::Version
82
- version: '10.0'
124
+ version: 0.9.1
83
125
  - !ruby/object:Gem::Dependency
84
- name: rspec
126
+ name: rubocop
85
127
  requirement: !ruby/object:Gem::Requirement
86
128
  requirements:
87
129
  - - "~>"
88
130
  - !ruby/object:Gem::Version
89
- version: '3.4'
131
+ version: 0.79.0
90
132
  type: :development
91
133
  prerelease: false
92
134
  version_requirements: !ruby/object:Gem::Requirement
93
135
  requirements:
94
136
  - - "~>"
95
137
  - !ruby/object:Gem::Version
96
- version: '3.4'
138
+ version: 0.79.0
139
+ - !ruby/object:Gem::Dependency
140
+ name: rubocop-rspec
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 1.37.1
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 1.37.1
97
153
  description:
98
154
  email:
99
155
  - urkle@outoforder.cc
@@ -101,16 +157,20 @@ executables: []
101
157
  extensions: []
102
158
  extra_rdoc_files: []
103
159
  files:
160
+ - ".circleci/config.yml"
104
161
  - ".gitignore"
105
162
  - ".rspec"
163
+ - ".rubocop.yml"
106
164
  - ".simplecov"
165
+ - CHANGELOG.md
107
166
  - Gemfile
108
167
  - LICENSE.txt
109
168
  - README.md
110
169
  - Rakefile
111
170
  - bin/console
112
171
  - bin/setup
113
- - circle.yml
172
+ - bin/setup-rubygems.sh
173
+ - bin/tag_check.sh
114
174
  - lib/sidekiq/instrumental.rb
115
175
  - lib/sidekiq/instrumental/configuration.rb
116
176
  - lib/sidekiq/instrumental/middleware/base.rb
@@ -119,6 +179,8 @@ files:
119
179
  - lib/sidekiq/instrumental/version.rb
120
180
  - sidekiq-instrumental.gemspec
121
181
  - spec/sidekiq/instrumental/configuration_spec.rb
182
+ - spec/sidekiq/instrumental/middleware/client_spec.rb
183
+ - spec/sidekiq/instrumental/middleware/server_spec.rb
122
184
  - spec/sidekiq/instrumental_spec.rb
123
185
  - spec/spec_helper.rb
124
186
  homepage: https://github.com/NetsoftHoldings/sidekiq-instrumental/
@@ -133,19 +195,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
133
195
  requirements:
134
196
  - - ">="
135
197
  - !ruby/object:Gem::Version
136
- version: '0'
198
+ version: '2.3'
137
199
  required_rubygems_version: !ruby/object:Gem::Requirement
138
200
  requirements:
139
201
  - - ">="
140
202
  - !ruby/object:Gem::Version
141
203
  version: '0'
142
204
  requirements: []
143
- rubyforge_project:
144
- rubygems_version: 2.4.8
205
+ rubygems_version: 3.0.6
145
206
  signing_key:
146
207
  specification_version: 4
147
208
  summary: Send Sidekiq status into Instrumental after every job
148
209
  test_files:
149
- - spec/sidekiq/instrumental/configuration_spec.rb
150
- - spec/sidekiq/instrumental_spec.rb
151
210
  - spec/spec_helper.rb
211
+ - spec/sidekiq/instrumental_spec.rb
212
+ - spec/sidekiq/instrumental/middleware/client_spec.rb
213
+ - spec/sidekiq/instrumental/middleware/server_spec.rb
214
+ - spec/sidekiq/instrumental/configuration_spec.rb
data/circle.yml DELETED
@@ -1,17 +0,0 @@
1
- machine:
2
- ruby:
3
- version: 2.2.5
4
- dependencies:
5
- post:
6
- - gem install geminabox
7
- test:
8
- post:
9
- - gem build sidekiq-instrumental.gemspec
10
- - rm -rf pkg
11
- - mkdir -p pkg
12
- - mv *.gem pkg
13
- deployment:
14
- release:
15
- tag: /v[0-9]+(\.[0-9]+)+/
16
- commands:
17
- - gem inabox -g ${HUBSTAFF_GEM_SERVER}