yabeda-sidekiq 0.1.2

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6a03934644e2fc09d12cd15f68fb2f91e919ae6012a56a858468717b0deb3f0b
4
+ data.tar.gz: 2a8224f49b33cd184f92ebf3ceec12fe16617177ef0446317b97bc3c54de0639
5
+ SHA512:
6
+ metadata.gz: c3ef7f9d8a00b01aecd0b76cccd73c48a99d066226c2ab944f340739dadf4689f8efeacdebbb9be2af5327ab93d0cc78a9f17664ef83973b46950515d4f23edc
7
+ data.tar.gz: 19e190aa609c601c76f5b3e19c282dddf8bbfc993837f0d1f53592c11058918579209eb5a1f41d5d25c908cc8c5c73568cd7a33d35de1564811e2ca0a3d58e60
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ Gemfile.lock
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,46 @@
1
+ ---
2
+ require:
3
+ - rubocop-rspec
4
+
5
+ AllCops:
6
+ TargetRubyVersion: 2.3
7
+
8
+ Metrics/BlockLength:
9
+ Exclude:
10
+ - "Gemfile"
11
+ - "spec/**/*"
12
+
13
+ Style/BracesAroundHashParameters:
14
+ EnforcedStyle: context_dependent
15
+
16
+ Style/StringLiterals:
17
+ EnforcedStyle: double_quotes
18
+
19
+ # Allow to use let!
20
+ RSpec/LetSetup:
21
+ Enabled: false
22
+
23
+ RSpec/MultipleExpectations:
24
+ Enabled: false
25
+
26
+ Bundler/OrderedGems:
27
+ Enabled: false
28
+
29
+ Style/TrailingCommaInArguments:
30
+ Description: 'Checks for trailing comma in argument lists.'
31
+ StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-params-comma'
32
+ Enabled: true
33
+ EnforcedStyleForMultiline: consistent_comma
34
+
35
+ Style/TrailingCommaInArrayLiteral:
36
+ Description: 'Checks for trailing comma in array literals.'
37
+ StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas'
38
+ Enabled: true
39
+ EnforcedStyleForMultiline: consistent_comma
40
+
41
+ Style/TrailingCommaInHashLiteral:
42
+ Description: 'Checks for trailing comma in hash literals.'
43
+ StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas'
44
+ Enabled: true
45
+ EnforcedStyleForMultiline: consistent_comma
46
+
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.1
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
+
7
+ # Specify your gem's dependencies in yabeda-sidekiq.gemspec
8
+ gemspec
9
+
10
+ group :development, :test do
11
+ gem "pry"
12
+ gem "pry-byebug", platform: :mri
13
+
14
+ gem "rubocop"
15
+ gem "rubocop-rspec"
16
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Andrey Novikov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,65 @@
1
+ # Yabeda::[Sidekiq]
2
+
3
+ Built-in metrics for [Sidekiq] monitoring out of the box! Part of the [yabeda] suite.
4
+
5
+ ## Installation
6
+
7
+ ```ruby
8
+ gem 'yabeda-rails'
9
+ # Then add monitoring system adapter, e.g.:
10
+ # gem 'yabeda-prometheus'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ **And that is it!** Sidekiq metrics are being collected!
18
+
19
+ Additionally, depending on your adapter, you may want to setup metrics export. E.g. for [yabeda-prometheus]:
20
+
21
+ ```ruby
22
+ # config/initializers/sidekiq or elsewhere
23
+ Sidekiq.configure_server do |_config|
24
+ Yabeda::Prometheus::Exporter.start_metrics_server!
25
+ end
26
+ ```
27
+
28
+ ## Metrics
29
+
30
+ - Total number of executed jobs: `sidekiq_jobs_executed_total` - (segmented by queue and class name)
31
+ - Number of jobs have been finished successfully: `sidekiq_jobs_success_total` (segmented by queue and class name)
32
+ - Number of jobs have been failed: `sidekiq_jobs_failed_total` (segmented by queue and class name)
33
+ - Time of job run: `sidekiq_job_runtime` (seconds per job execution, segmented by queue and class name)
34
+ - Number of jobs in queues: `sidekiq_jobs_waiting_count` (segmented by queue)
35
+ - Number of scheduled jobs:`sidekiq_jobs_scheduled_count`
36
+ - Number of jobs in retry set: `sidekiq_jobs_retry_count`
37
+ - Number of jobs in dead set (“morgue”): `sidekiq_jobs_dead_count`
38
+ - Active workers count: `sidekiq_active_processes`
39
+ - Active processes count: `sidekiq_active_workers_count`
40
+
41
+ # Roadmap (TODO or Help wanted)
42
+
43
+ - Implement optional segmentation of retry/schedule/dead sets
44
+
45
+ It should be disabled by default as it requires to iterate over all jobs in sets and may be very slow on large sets.
46
+
47
+ - Maybe add some hooks for ease of plugging in metrics for myriads of Sidekiq plugins?
48
+
49
+ ## Development
50
+
51
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
52
+
53
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
54
+
55
+ ## Contributing
56
+
57
+ Bug reports and pull requests are welcome on GitHub at https://github.com/yabeda-rb/yabeda-sidekiq.
58
+
59
+ ## License
60
+
61
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
62
+
63
+ [Sidekiq]: https://github.com/mperham/sidekiq/ "Simple, efficient background processing for Ruby"
64
+ [yabeda]: https://github.com/yabeda-rb/yabeda
65
+ [yabeda-prometheus]: https://github.com/yabeda-rb/yabeda-prometheus
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "yabeda/sidekiq"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yabeda
4
+ module Sidekiq
5
+ # Client middleware to count number of enqueued jobs
6
+ class ClientMiddleware
7
+ def call(worker, job, queue, _redis_pool)
8
+ labels = Yabeda::Sidekiq.labelize(worker, job, queue)
9
+ Yabeda.sidekiq_jobs_enqueued_total.increment(labels)
10
+ yield
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yabeda
4
+ module Sidekiq
5
+ # Sidekiq worker middleware
6
+ class ServerMiddleware
7
+ def call(worker, job, queue)
8
+ labels = Yabeda::Sidekiq.labelize(worker, job, queue)
9
+ start = Time.now
10
+ begin
11
+ yield
12
+ Yabeda.sidekiq_jobs_success_total.increment(labels)
13
+ rescue Exception # rubocop: disable Lint/RescueException
14
+ Yabeda.sidekiq_jobs_failed_total.increment(labels)
15
+ raise
16
+ ensure
17
+ Yabeda.sidekiq_job_runtime.measure(labels, elapsed(start))
18
+ Yabeda.sidekiq_jobs_executed_total.increment(labels)
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def elapsed(start)
25
+ (Time.now - start).round(3)
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Yabeda
4
+ module Sidekiq
5
+ VERSION = "0.1.2"
6
+ end
7
+ end
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "sidekiq"
4
+ require "sidekiq/api"
5
+
6
+ require "yabeda/sidekiq/version"
7
+ require "yabeda/sidekiq/client_middleware"
8
+ require "yabeda/sidekiq/server_middleware"
9
+
10
+ module Yabeda
11
+ module Sidekiq
12
+ LONG_RUNNING_JOB_RUNTIME_BUCKETS = [
13
+ 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10, # standard (from Prometheus)
14
+ 30, 60, 120, 300, 1800, 3600, 21_600 # Sidekiq tasks may be very long-running
15
+ ].freeze
16
+
17
+ Yabeda.configure do
18
+ group :sidekiq
19
+
20
+ counter :jobs_enqueued_total, comment: "A counter of the total number of jobs sidekiq enqueued."
21
+
22
+ next unless ::Sidekiq.server?
23
+
24
+ counter :jobs_executed_total, comment: "A counter of the total number of jobs sidekiq executed."
25
+ counter :jobs_success_total, comment: "A counter of the total number of jobs successfully processed by sidekiq."
26
+ counter :jobs_failed_total, comment: "A counter of the total number of jobs failed in sidekiq."
27
+ gauge :jobs_waiting_count, comment: "The number of jobs waiting to process in sidekiq."
28
+ gauge :active_workers_count, comment: "The number of currently running machines with sidekiq workers."
29
+ gauge :jobs_scheduled_count, comment: "The number of jobs scheduled for later execution."
30
+ gauge :jobs_retry_count, comment: "The number of failed jobs waiting to be retried"
31
+ gauge :jobs_dead_count, comment: "The number of jobs exceeded their retry count."
32
+ gauge :active_processes, comment: "The number of active Sidekiq worker processes."
33
+ histogram :job_runtime, unit: :seconds, per: :job, comment: "A histogram of the job execution time.",
34
+ buckets: LONG_RUNNING_JOB_RUNTIME_BUCKETS
35
+
36
+ collect do
37
+ stats = ::Sidekiq::Stats.new
38
+
39
+ stats.queues.each do |k, v|
40
+ sidekiq_jobs_waiting_count.set({ queue: k }, v)
41
+ end
42
+ sidekiq_active_workers_count.set({}, stats.workers_size)
43
+ sidekiq_jobs_scheduled_count.set({}, stats.scheduled_size)
44
+ sidekiq_jobs_dead_count.set({}, stats.dead_size)
45
+ sidekiq_active_processes.set({}, stats.processes_size)
46
+ sidekiq_jobs_retry_count.set({}, stats.retry_size)
47
+
48
+ # That is quite slow if your retry set is large
49
+ # I don't want to enable it by default
50
+ # retries_by_queues =
51
+ # ::Sidekiq::RetrySet.new.each_with_object(Hash.new(0)) do |job, cntr|
52
+ # cntr[job["queue"]] += 1
53
+ # end
54
+ # retries_by_queues.each do |queue, count|
55
+ # sidekiq_jobs_retry_count.set({ queue: queue }, count)
56
+ # end
57
+ end
58
+ end
59
+
60
+ ::Sidekiq.configure_server do |config|
61
+ config.server_middleware do |chain|
62
+ chain.add ServerMiddleware
63
+ end
64
+ config.client_middleware do |chain|
65
+ chain.add ClientMiddleware
66
+ end
67
+ end
68
+
69
+ ::Sidekiq.configure_client do |config|
70
+ config.client_middleware do |chain|
71
+ chain.add ClientMiddleware
72
+ end
73
+ end
74
+
75
+ class << self
76
+ def labelize(worker, job, queue)
77
+ { queue: queue, worker: worker_class(worker, job) }
78
+ end
79
+
80
+ def worker_class(worker, job)
81
+ if defined?(ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper)
82
+ return job["wrapped"] if worker.is_a?(ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper)
83
+ end
84
+ (worker.is_a?(String) ? worker : worker.class).to_s
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("lib", __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "yabeda/sidekiq/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "yabeda-sidekiq"
9
+ spec.version = Yabeda::Sidekiq::VERSION
10
+ spec.authors = ["Andrey Novikov"]
11
+ spec.email = ["envek@envek.name"]
12
+
13
+ spec.summary = "Extensible Prometheus exporter for monitoring your Sidekiq"
14
+ spec.description = "Prometheus exporter for easy collecting most important of your Sidekiq metrics"
15
+ spec.homepage = "https://github.com/yabeda-rb/yabeda-sidekiq"
16
+ spec.license = "MIT"
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
+ f.match(%r{^(test|spec|features)/})
20
+ end
21
+ spec.bindir = "exe"
22
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_dependency "yabeda"
26
+ spec.add_dependency "sidekiq"
27
+
28
+ spec.add_development_dependency "bundler", "~> 1.16"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency "rspec", "~> 3.0"
31
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yabeda-sidekiq
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Andrey Novikov
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-10-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: yabeda
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sidekiq
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ description: Prometheus exporter for easy collecting most important of your Sidekiq
84
+ metrics
85
+ email:
86
+ - envek@envek.name
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".rubocop.yml"
94
+ - ".travis.yml"
95
+ - Gemfile
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - bin/console
100
+ - bin/setup
101
+ - lib/yabeda/sidekiq.rb
102
+ - lib/yabeda/sidekiq/client_middleware.rb
103
+ - lib/yabeda/sidekiq/server_middleware.rb
104
+ - lib/yabeda/sidekiq/version.rb
105
+ - yabeda-sidekiq.gemspec
106
+ homepage: https://github.com/yabeda-rb/yabeda-sidekiq
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.7.6
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Extensible Prometheus exporter for monitoring your Sidekiq
130
+ test_files: []