sidekiq-statsd 1.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e7c691fdc841e5a3f80e8e00ad7fd9b67008f82254d8e73a7b4af06598534559
4
- data.tar.gz: c73db3ee678d3fd3078e3c5fcf934e9e3c3b786df72bd5b5402ceb8d97f7e030
3
+ metadata.gz: 2c0a8286f6068e0cde4639ae549ddb4ffea4b615b5e21be7913e8a911f7a6d5e
4
+ data.tar.gz: eeacf3e1cacfda19717958059aab50d4f64a645934188530b842c2edd98a94de
5
5
  SHA512:
6
- metadata.gz: d5058163f365e1bf7f5a96f8796388268003df228cda4cde5a4a38733d5263f58100e198244aa4d990fd0aa864c3b9fc419dd03549f8a078f97bd7b5ef8a7db0
7
- data.tar.gz: 62d253d5b5484a372d181bbf3b33cfd577ced1cb5fef22b068d605618911a2b37187cb32ccb810c9283602edbf3349f5e2f529871ea1b5beeee3da422209884b
6
+ metadata.gz: ed5110d9d73f6e0f7f4d7ba1521ab98af4187aeb271cbadc3c880af499cefab64a79da9aa87b9797ce8d75170f0c5bf209d22dc18671cc3f02f524c1e355c7fc
7
+ data.tar.gz: 5cbf10d942527cdc0e7ea3c43ee0e08ef5f14c7b6000673b81d66451c93bcbc2d66017240caea5b6d3f61e076713329f45d79e510b79235aea93ac18efa1ae78
data/.travis.yml CHANGED
@@ -6,8 +6,7 @@ rvm:
6
6
  - 2.5.0
7
7
  - 2.6.0
8
8
  env:
9
- - SIDEKIQ_VERSION="~> 2.7.0"
10
- - SIDEKIQ_VERSION="~> 3.0.0"
9
+ - SIDEKIQ_VERSION="~> 3.3.1"
11
10
  - SIDEKIQ_VERSION="~> 4.0.0"
12
11
  - SIDEKIQ_VERSION="~> 5.0.0"
13
12
  - SIDEKIQ_VERSION="~> 6.0.0"
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ # 2.0.1
2
+
3
+ * Fix stuck global stats (retries, processed, etc.)
4
+
5
+ # 2.0.0
6
+
7
+ * BREAKING: drop host/port options
8
+ * Add support for custom statsd client
9
+
1
10
  # 1.0.0
2
11
 
3
12
  * Pin minimum Ruby version to 2.4
data/README.md CHANGED
@@ -11,8 +11,11 @@ Sidekiq::Statsd is tested against [several Ruby versions](.travis.yml#L4).
11
11
 
12
12
  ## Installation
13
13
 
14
- Add this line to your application's Gemfile:
14
+ Add these lines to your application's Gemfile:
15
15
 
16
+ gem "statsd-ruby"
17
+ # or if you are using Datadog
18
+ # gem "dogstatsd-ruby"
16
19
  gem "sidekiq-statsd"
17
20
 
18
21
  And then execute:
@@ -29,9 +32,16 @@ In a Rails initializer or wherever you've configured Sidekiq, add
29
32
  Sidekiq::Statsd to your server middleware:
30
33
 
31
34
  ```ruby
35
+ require 'statsd'
36
+ statsd = Statsd.new('localhost', 8125)
37
+
38
+ # or if you are using Datadog
39
+ # require 'datadog/statsd'
40
+ # statsd = Datadog::Statsd.new('localhost', 8125)
41
+
32
42
  Sidekiq.configure_server do |config|
33
43
  config.server_middleware do |chain|
34
- chain.add Sidekiq::Statsd::ServerMiddleware, env: "production", prefix: "worker", host: "localhost", port: 8125
44
+ chain.add Sidekiq::Statsd::ServerMiddleware, env: "production", prefix: "worker", statsd: statsd
35
45
  end
36
46
  end
37
47
  ```
@@ -1,7 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'statsd'
4
-
5
3
  module Sidekiq::Statsd
6
4
  ##
7
5
  # Sidekiq StatsD is a middleware to track worker execution metrics through statsd.
@@ -11,21 +9,14 @@ module Sidekiq::Statsd
11
9
  # Initializes the middleware with options.
12
10
  #
13
11
  # @param [Hash] options The options to initialize the StatsD client.
14
- # @option options [Statsd] :statsd Existing statsd client.
12
+ # @option options [Statsd] :statsd Existing StatsD client.
15
13
  # @option options [String] :env ("production") The env to segment the metric key (e.g. env.prefix.worker_name.success|failure).
16
14
  # @option options [String] :prefix ("worker") The prefix to segment the metric key (e.g. env.prefix.worker_name.success|failure).
17
- # @option options [String] :host ("localhost") The StatsD host.
18
- # @option options [String] :port ("8125") The StatsD port.
19
15
  # @option options [String] :sidekiq_stats ("true") Send Sidekiq global stats e.g. total enqueued, processed and failed.
20
16
  def initialize(options = {})
21
- @options = { env: 'production',
22
- prefix: 'worker',
23
- host: 'localhost',
24
- port: 8125,
25
- sidekiq_stats: true }.merge options
17
+ @options = { env: 'production', prefix: 'worker', sidekiq_stats: true }.merge options
26
18
 
27
- @statsd = options[:statsd] || ::Statsd.new(@options[:host], @options[:port])
28
- @sidekiq_stats = Sidekiq::Stats.new if @options[:sidekiq_stats]
19
+ @statsd = options[:statsd] || raise("A StatsD client must be provided")
29
20
  end
30
21
 
31
22
  ##
@@ -49,32 +40,35 @@ module Sidekiq::Statsd
49
40
  b.increment prefix(worker_name, 'failure')
50
41
  raise e
51
42
  ensure
52
- if @options[:sidekiq_stats]
53
- # Queue sizes
54
- b.gauge prefix('enqueued'), @sidekiq_stats.enqueued
55
- if @sidekiq_stats.respond_to?(:retry_size)
56
- # 2.6.0 doesn't have `retry_size`
57
- b.gauge prefix('retry_set_size'), @sidekiq_stats.retry_size
58
- end
59
-
60
- # All-time counts
61
- b.gauge prefix('processed'), @sidekiq_stats.processed
62
- b.gauge prefix('failed'), @sidekiq_stats.failed
63
- end
64
-
65
- # Queue metrics
66
- queue_name = msg['queue']
67
- sidekiq_queue = Sidekiq::Queue.new(queue_name)
68
- b.gauge prefix('queues', queue_name, 'enqueued'), sidekiq_queue.size
69
- if sidekiq_queue.respond_to?(:latency)
70
- b.gauge prefix('queues', queue_name, 'latency'), sidekiq_queue.latency
71
- end
43
+ report_global_stats(b) if @options[:sidekiq_stats]
44
+ report_queue_stats(b, msg['queue'])
72
45
  end
73
46
  end
74
47
  end
75
48
 
76
49
  private
77
50
 
51
+ def report_global_stats(statsd)
52
+ sidekiq_stats = Sidekiq::Stats.new
53
+
54
+ # Queue sizes
55
+ statsd.gauge prefix('enqueued'), sidekiq_stats.enqueued
56
+ statsd.gauge prefix('retry_set_size'), sidekiq_stats.retry_size
57
+
58
+ # All-time counts
59
+ statsd.gauge prefix('processed'), sidekiq_stats.processed
60
+ statsd.gauge prefix('failed'), sidekiq_stats.failed
61
+ end
62
+
63
+ def report_queue_stats(statsd, queue_name)
64
+ sidekiq_queue = Sidekiq::Queue.new(queue_name)
65
+ statsd.gauge prefix('queues', queue_name, 'enqueued'), sidekiq_queue.size
66
+
67
+ if sidekiq_queue.respond_to?(:latency)
68
+ statsd.gauge prefix('queues', queue_name, 'latency'), sidekiq_queue.latency
69
+ end
70
+ end
71
+
78
72
  ##
79
73
  # Converts args passed to it into a metric name with prefix.
80
74
  #
@@ -1,6 +1,6 @@
1
1
  module Sidekiq
2
2
  module Statsd
3
- VERSION = '1.0.0'
3
+ VERSION = '2.0.1'
4
4
  end
5
5
  end
6
6
 
@@ -18,8 +18,7 @@ Gem::Specification.new do |gem|
18
18
  gem.require_paths = ["lib"]
19
19
 
20
20
  gem.add_dependency "activesupport"
21
- gem.add_dependency "sidekiq", ">= 2.7"
22
- gem.add_dependency "statsd-ruby", ">= 1.1.0"
21
+ gem.add_dependency "sidekiq", ">= 3.3.1"
23
22
 
24
23
  gem.required_ruby_version = '>= 2.4.0'
25
24
  end
@@ -1,12 +1,12 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe Sidekiq::Statsd::ServerMiddleware do
4
- subject(:middleware) { described_class.new }
4
+ subject(:middleware) { described_class.new(statsd: client) }
5
5
 
6
6
  let(:worker) { double "Dummy worker" }
7
7
  let(:msg) { { 'queue' => 'mailer' } }
8
8
  let(:queue) { nil }
9
- let(:client) { double(::Statsd).as_null_object }
9
+ let(:client) { double('StatsD').as_null_object }
10
10
 
11
11
  let(:worker_name) { worker.class.name.gsub("::", ".") }
12
12
 
@@ -14,28 +14,15 @@ describe Sidekiq::Statsd::ServerMiddleware do
14
14
  let(:broken_job) { ->{ raise 'error' } }
15
15
 
16
16
  before do
17
- allow_any_instance_of(::Statsd).to receive(:batch).and_yield(client)
17
+ allow(client).to receive(:batch).and_yield(client)
18
18
  end
19
19
 
20
- it "doesn't initialize a ::Statsd client if passed-in" do
21
- expect(::Statsd)
22
- .to receive(:new)
23
- .never
24
-
25
- described_class.new(statsd: client)
20
+ it "raises error if no statsd supplied" do
21
+ expect { described_class.new }.to raise_error("A StatsD client must be provided")
26
22
  end
27
23
 
28
24
  context "with customised options" do
29
25
  describe "#new" do
30
- it "uses the custom statsd host and port" do
31
- expect(::Statsd)
32
- .to receive(:new)
33
- .with('example.com', 8126)
34
- .once
35
-
36
- described_class.new(host: 'example.com', port: 8126)
37
- end
38
-
39
26
  it "uses the custom metric name prefix options" do
40
27
  expect(client)
41
28
  .to receive(:time)
@@ -44,31 +31,27 @@ describe Sidekiq::Statsd::ServerMiddleware do
44
31
  .and_yield
45
32
 
46
33
  described_class
47
- .new(env: 'development', prefix: 'application.sidekiq')
34
+ .new(statsd: client, env: 'development', prefix: 'application.sidekiq')
48
35
  .call(worker, msg, queue, &clean_job)
49
36
  end
50
37
  end
51
38
  end
52
39
 
53
40
  context 'without global sidekiq stats' do
54
- let(:sidekiq_stats) { double }
55
-
56
- it "doesn't initialze a Sidekiq::Stats instance" do
41
+ it "doesn't initialize a Sidekiq::Stats instance" do
57
42
  # Sidekiq::Stats.new calls fetch_stats!, which makes redis calls
58
- expect(described_class.new(sidekiq_stats: false).instance_variable_get(:@sidekiq_stats))
59
- .to be_nil
43
+ expect(Sidekiq::Stats).not_to receive(:new)
44
+ described_class.new(statsd: client, sidekiq_stats: false)
60
45
  end
61
46
 
62
47
  it "doesn't gauge sidekiq stats" do
63
- allow(Sidekiq::Stats).to receive(:new) { sidekiq_stats }
64
-
65
- expect(sidekiq_stats).not_to receive(:enqueued)
66
- expect(sidekiq_stats).not_to receive(:retry_size)
67
- expect(sidekiq_stats).not_to receive(:processed)
68
- expect(sidekiq_stats).not_to receive(:failed)
48
+ expect(client).not_to receive(:enqueued)
49
+ expect(client).not_to receive(:retry_size)
50
+ expect(client).not_to receive(:processed)
51
+ expect(client).not_to receive(:failed)
69
52
 
70
53
  described_class
71
- .new(sidekiq_stats: false)
54
+ .new(statsd: client, sidekiq_stats: false)
72
55
  .call(worker, msg, queue, &clean_job)
73
56
  end
74
57
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-statsd
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pablo Cantero
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-09 00:00:00.000000000 Z
11
+ date: 2019-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -30,28 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '2.7'
33
+ version: 3.3.1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '2.7'
41
- - !ruby/object:Gem::Dependency
42
- name: statsd-ruby
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: 1.1.0
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: 1.1.0
40
+ version: 3.3.1
55
41
  description: Sidekiq StatsD is a Sidekiq server middleware to send Sidekiq worker
56
42
  metrics through statsd.
57
43
  email: