sidekiq_prometheus 1.2.0 → 1.6.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
2
  SHA256:
3
- metadata.gz: 6cef078a53e6742cd0cea7140dbe65ab96849acc8886880f530cbe208ee8fefc
4
- data.tar.gz: 63dc0623415214f85a2bcb0b37cfaef012a016bb75d430763d9bfa3ed097460a
3
+ metadata.gz: a6dc43957020461f1b740cee64cdfff9b40f624d4bfe41d57eab772a27fd2b21
4
+ data.tar.gz: adb0cb635975340d514fbea0c798e5269238eb990700a7eeae8c9a2d8d32e6e7
5
5
  SHA512:
6
- metadata.gz: 3721b3aaf34de0717d2d23639aeb2413fe5f9b9580ae1f07bcf333bcfae1d7c110425b1e0c850d06ba29459ca7506d06130322dd3ea1461e164c3264228628c0
7
- data.tar.gz: cf08ac6f8f3779c3a8789063de3073e4838945cd4d6190b7284184c19bbd2ec2f156143502a160f9b9a91fb11bb644ca2f43e20aa11533313f4ada60d80a2a21
6
+ metadata.gz: 48f466c9d2904644ce161665b5f06092dff197e4b2550d9355d6c6e57832fc779d4ef3f5c0abaa63013c91fd249bb134234f201aafe9a9271f3bb121123b25ec
7
+ data.tar.gz: c2c181822b1a9d1e2ace0084301ac4517966a8bf4672884dd48c352d7af18374e7b2cb94d5f628a799dce8e12a372dadbc814d9d0cd91be211da097b0584e765
data/.travis.yml CHANGED
@@ -1,7 +1,8 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
+ - 3.0
5
+ - 2.7
6
+ - 2.6
4
7
  - 2.5
5
- - 2.4
6
- - 2.3
7
- before_install: gem install bundler -v 1.16.1
8
+ before_install: gem install bundler -v 2.2.15
data/CHANGELOG.md CHANGED
@@ -1,5 +1,30 @@
1
1
  CHANGELOG
2
2
 
3
+
4
+ <a name="v1.5.0"></a>
5
+ ## [v1.5.0](https://github.com/fastly/sidekiq-prometheus/compare/v1.4.0...v1.5.0) (2021-08-02)
6
+
7
+ ### Pull Requests
8
+
9
+ * Merge pull request [#23](https://github.com/fastly/sidekiq-prometheus/issues/23) from fastly/rainy/add-error-class-label
10
+
11
+
12
+ <a name="v1.4.0"></a>
13
+ ## [v1.4.0](https://github.com/fastly/sidekiq-prometheus/compare/v1.3.0...v1.4.0) (2021-03-30)
14
+
15
+ ### Pull Requests
16
+
17
+ * Merge pull request [#21](https://github.com/fastly/sidekiq-prometheus/issues/21) from Kevinrob/patch-1
18
+
19
+
20
+ <a name="v1.3.0"></a>
21
+ ## [v1.3.0](https://github.com/fastly/sidekiq-prometheus/compare/v1.2.0...v1.3.0) (2021-03-26)
22
+
23
+ ### Pull Requests
24
+
25
+ * Merge pull request [#22](https://github.com/fastly/sidekiq-prometheus/issues/22) from mirubiri/add-active-job-support
26
+ * Merge pull request [#20](https://github.com/fastly/sidekiq-prometheus/issues/20) from fastly/aw/move-to-main
27
+
3
28
  <a name="v1.2.0"></a>
4
29
  ## [v1.2.0](https://github.com/fastly/sidekiq-prometheus/compare/v1.1.0...v1.2.0) (2020-10-01)
5
30
 
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Sidekiq Prometheus
2
2
 
3
3
 
4
- [![Status](https://travis-ci.org/fastly/sidekiq-prometheus.svg?branch=master)](https://travis-ci.org/fastly/sidekiq-prometheus)
4
+ [![Status](https://travis-ci.org/fastly/sidekiq-prometheus.svg?branch=main)](https://travis-ci.org/fastly/sidekiq-prometheus)
5
5
  ![Gem](https://img.shields.io/gem/v/sidekiq_prometheus.svg?color=blue)
6
6
  [![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT)
7
7
 
@@ -82,6 +82,7 @@ end
82
82
  * `periodic_metrics_enabled`: Boolean that determines whether to run the periodic metrics reporter. `PeriodicMetrics` runs a separate thread that reports on global metrics (if enabled) as well worker GC stats (if enabled). It reports metrics on the interval defined by `periodic_reporting_interval`. Defaults to `true`.
83
83
  * `periodic_reporting_interval`: interval in seconds for reporting periodic metrics. Default: `30`
84
84
  * `metrics_server_enabled`: Boolean that determines whether to run the rack server. Defaults to `true`
85
+ * `metrics_server_logging_enabled`: Boolean that determines if the metrics server will log access logs. Defaults to `true`
85
86
  * `metrics_host`: Host on which the rack server will listen. Defaults to
86
87
  `localhost`
87
88
  * `metrics_port`: Port on which the rack server will listen. Defaults to `9359`
@@ -257,6 +258,7 @@ To install this gem onto your local machine, run `bundle exec rake install`.
257
258
  * NHM Tanveer Hossain Khan ([@we4tech](https://github.com/we4tech))
258
259
  * [@Postmodern](https://github.com/postmodern)
259
260
  * Ross Jones ([@rossjones](https://github.com/rossjones))
261
+ * Alejandro Arrufat ([@mirubiri](https://github.com/mirubiri))
260
262
 
261
263
  ## Contributing
262
264
 
@@ -272,7 +274,7 @@ The gem is available as open source under the terms of the [MIT License](https:/
272
274
 
273
275
  ## Code of Conduct
274
276
 
275
- Everyone interacting in the SidekiqPrometheus project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/fastly/sidekiq-prometheus/blob/master/CODE_OF_CONDUCT.md).
277
+ Everyone interacting in the SidekiqPrometheus project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/fastly/sidekiq-prometheus/blob/main/CODE_OF_CONDUCT.md).
276
278
 
277
279
  # Metadata
278
280
 
@@ -6,6 +6,7 @@ require 'prometheus/client'
6
6
  require 'prometheus/middleware/exporter'
7
7
  require 'sidekiq'
8
8
  require 'sidekiq/api'
9
+ require 'webrick'
9
10
 
10
11
  begin
11
12
  require 'sidekiq/ent'
@@ -56,6 +57,9 @@ module SidekiqPrometheus
56
57
  # @return [Integer] Port on which the metrics server will listen. Default: 9357
57
58
  attr_accessor :metrics_port
58
59
 
60
+ # @return [Boolean] When set to false will silence the metric server access logs. Default: true
61
+ attr_accessor :metrics_server_logger_enabled
62
+
59
63
  # Override the default Prometheus::Client
60
64
  # @return [Prometheus::Client]
61
65
  attr_writer :client
@@ -75,6 +79,7 @@ module SidekiqPrometheus
75
79
  self.metrics_server_enabled = true
76
80
  self.metrics_host = 'localhost'
77
81
  self.metrics_port = 9359
82
+ self.metrics_server_logger_enabled = true
78
83
  self.custom_labels = {}
79
84
  self.custom_metrics = []
80
85
 
@@ -128,6 +133,13 @@ module SidekiqPrometheus
128
133
  metrics_server_enabled
129
134
  end
130
135
 
136
+ ##
137
+ # Helper method for +metrics_server_logger_enabled+ configuration setting
138
+ # @return [Boolean] defaults to true
139
+ def metrics_server_logger_enabled?
140
+ metrics_server_logger_enabled
141
+ end
142
+
131
143
  ##
132
144
  # Get a metric from the registry
133
145
  # @param metric [Symbol] name of metric to fetch
@@ -199,14 +211,23 @@ module SidekiqPrometheus
199
211
  # Will listen on SidekiqPrometheus.metrics_host and
200
212
  # SidekiqPrometheus.metrics_port
201
213
  def metrics_server
214
+ opts = {
215
+ Port: SidekiqPrometheus.metrics_port,
216
+ Host: SidekiqPrometheus.metrics_host,
217
+ }
218
+
219
+ unless metrics_server_logger_enabled?
220
+ opts[:Logger] = WEBrick::Log.new('/dev/null')
221
+ opts[:AccessLog] = []
222
+ end
223
+
202
224
  @_metrics_server ||= Thread.new do
203
225
  Rack::Handler::WEBrick.run(
204
226
  Rack::Builder.new {
205
227
  use Prometheus::Middleware::Exporter, registry: SidekiqPrometheus.registry
206
228
  run ->(_) { [301, { 'Location' => '/metrics' }, []] }
207
229
  },
208
- Port: SidekiqPrometheus.metrics_port,
209
- Host: SidekiqPrometheus.metrics_host,
230
+ **opts
210
231
  )
211
232
  end
212
233
  end
@@ -1,10 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class SidekiqPrometheus::JobMetrics
4
- def call(worker, _job, queue)
4
+ def call(worker, job, queue)
5
5
  before = GC.stat(:total_allocated_objects) if SidekiqPrometheus.gc_metrics_enabled?
6
6
 
7
- labels = { class: worker.class.to_s, queue: queue }
7
+ # If we're using a wrapper class, like ActiveJob, use the "wrapped"
8
+ # attribute to expose the underlying thing.
9
+ labels = {
10
+ class: job['wrapped'] || worker.class.to_s,
11
+ queue: queue,
12
+ }
8
13
 
9
14
  begin
10
15
  labels.merge!(custom_labels(worker))
@@ -25,7 +30,8 @@ class SidekiqPrometheus::JobMetrics
25
30
 
26
31
  result
27
32
  rescue StandardError => e
28
- registry[:sidekiq_job_failed].increment(labels: labels)
33
+ err_label = { :error_class => e.class.to_s }
34
+ registry[:sidekiq_job_failed].increment(labels: err_label.merge(labels))
29
35
  raise e
30
36
  ensure
31
37
  registry[:sidekiq_job_count].increment(labels: labels)
@@ -64,7 +64,7 @@ module SidekiqPrometheus::Metrics
64
64
  { name: :sidekiq_job_failed,
65
65
  type: :counter,
66
66
  docstring: 'Count of failed Sidekiq jobs',
67
- labels: JOB_LABELS, },
67
+ labels: JOB_LABELS + [:error_class], },
68
68
  { name: :sidekiq_job_success,
69
69
  type: :counter,
70
70
  docstring: 'Count of successful Sidekiq jobs',
@@ -107,7 +107,7 @@ module SidekiqPrometheus::Metrics
107
107
  end
108
108
 
109
109
  def register_sidekiq_gc_metric
110
- register SIDEKIQ_GC_METRIC
110
+ register(**SIDEKIQ_GC_METRIC)
111
111
  end
112
112
 
113
113
  def register_sidekiq_worker_gc_metrics
@@ -120,7 +120,7 @@ module SidekiqPrometheus::Metrics
120
120
 
121
121
  def register_metrics(metrics)
122
122
  metrics.each do |metric|
123
- register(metric)
123
+ register(**metric)
124
124
  end
125
125
  end
126
126
 
@@ -159,7 +159,7 @@ module SidekiqPrometheus::Metrics
159
159
 
160
160
  options[:buckets] = buckets if buckets
161
161
 
162
- registry.send(type, name.to_sym, options)
162
+ registry.send(type, name.to_sym, **options)
163
163
  end
164
164
 
165
165
  def unregister(name:)
@@ -8,7 +8,7 @@
8
8
  # one worker.
9
9
  #
10
10
  # @see https://github.com/mperham/sidekiq/wiki/Ent-Leader-Election
11
- # @see https://github.com/mperham/sidekiq/blob/master/lib/sidekiq/api.rb
11
+ # @see https://github.com/mperham/sidekiq/blob/main/lib/sidekiq/api.rb
12
12
 
13
13
  class SidekiqPrometheus::PeriodicMetrics
14
14
  # @return [Boolean] When +true+ will stop the reporting loop.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SidekiqPrometheus
4
- VERSION = '1.2.0'
4
+ VERSION = '1.6.0'
5
5
  end
@@ -23,11 +23,12 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.add_development_dependency 'bundler'
25
25
  spec.add_development_dependency 'pry'
26
- spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'rake', '~> 12.3.3'
27
27
  spec.add_development_dependency 'rspec', '~> 3.0'
28
28
  spec.add_development_dependency 'rubocop', '~> 0.58.0'
29
29
 
30
30
  spec.add_runtime_dependency 'prometheus-client', '~> 2.0'
31
31
  spec.add_runtime_dependency 'rack'
32
32
  spec.add_runtime_dependency 'sidekiq', '> 5.1'
33
+ spec.add_runtime_dependency 'webrick'
33
34
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq_prometheus
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lukas Eklund
8
8
  - NHM Tanveer Hossain Khan
9
- autorequire:
9
+ autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2020-10-01 00:00:00.000000000 Z
12
+ date: 2021-08-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -45,14 +45,14 @@ dependencies:
45
45
  requirements:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '10.0'
48
+ version: 12.3.3
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: '10.0'
55
+ version: 12.3.3
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: rspec
58
58
  requirement: !ruby/object:Gem::Requirement
@@ -123,7 +123,21 @@ dependencies:
123
123
  - - ">"
124
124
  - !ruby/object:Gem::Version
125
125
  version: '5.1'
126
- description:
126
+ - !ruby/object:Gem::Dependency
127
+ name: webrick
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ type: :runtime
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ description:
127
141
  email:
128
142
  - leklund@fastly.com
129
143
  executables: []
@@ -153,7 +167,7 @@ homepage: https://github.com/fastly/sidekiq-prometheus
153
167
  licenses:
154
168
  - MIT
155
169
  metadata: {}
156
- post_install_message:
170
+ post_install_message:
157
171
  rdoc_options: []
158
172
  require_paths:
159
173
  - lib
@@ -168,8 +182,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
182
  - !ruby/object:Gem::Version
169
183
  version: '0'
170
184
  requirements: []
171
- rubygems_version: 3.0.6
172
- signing_key:
185
+ rubygems_version: 3.1.6
186
+ signing_key:
173
187
  specification_version: 4
174
188
  summary: Prometheus Instrumentation for Sidekiq
175
189
  test_files: []