sidekiq_prometheus 1.8.3 → 2.0.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: c9a7474fb0e37d8c0aa3849bc4c5df6ff3b8a173a3545fcf5027dc29f8d1c4eb
4
- data.tar.gz: 6cb664182b40af876f6e58c532c235d3169ca3cb154f9aa785faaec384c3e9db
3
+ metadata.gz: e41a25aa249fbd72437fef36b40b8ff0328a31ebb588a3e6be32b66d4af8bb37
4
+ data.tar.gz: 79093b2be152a84f528a17e36866f49db59812dc3789d81dbda8fe7d7f2d6974
5
5
  SHA512:
6
- metadata.gz: 467ce07f7b4a5b79dcb16f61d8da97076c32ed5e5bb7b892d19a9a1d397214bb254188cacdb615fa3495d7485ddad38d38ea3e6078bae6ffaf4928a513a79deb
7
- data.tar.gz: 3b47b8a80fa6569456b166374e9395db173c243e86fc63e36a25292f0d463c0a0501cd29374d51d490e5add972412b5901f77a077937436f5e1b7cfbb64a83b2
6
+ metadata.gz: b6018610e3dbf12324a123ad27f681771d93099a898ba454e9715cca4fa40fc9bccc96f3506ebd3df06501410ac3f4c8f838acbc207580a95f01c1e49187aa32
7
+ data.tar.gz: 765360b4f3e748592828c414a95afae77c30846569e0fa4dee21aae40af530dab2caf13b119befb2c0086b39c4b3e9c9a4c8a9e8b7417c89a05f1949fbf6ede1
data/.gitignore CHANGED
@@ -8,4 +8,5 @@
8
8
  /tmp/
9
9
  .rspec_status
10
10
  Gemfile.lock
11
+ *gemfile.lock
11
12
  /.idea/
data/.travis.yml CHANGED
@@ -5,3 +5,6 @@ rvm:
5
5
  - 3.0
6
6
  - 2.7
7
7
  before_install: gem install bundler -v 2.2.15
8
+ gemfile:
9
+ - sidekiq_6.gemfile
10
+ - sidekiq_7.gemfile
data/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  CHANGELOG
2
2
 
3
+ <a name="v1.9.0"></a>
4
+ ## [v1.9.0](https://github.com/fastly/sidekiq-prometheus/compare/v1.8.3...v1.9.0) (2023-08-23)
5
+
6
+ ## What's Changed
7
+ * Adds info about sidekiq_job_over_limit metric to README by @ricardogpsf in https://github.com/fastly/sidekiq-prometheus/pull/38
8
+ * Allow label sets initialization while registering metrics by @davidbrusius in https://github.com/fastly/sidekiq-prometheus/pull/40
9
+
10
+ ## New Contributors
11
+ * @ricardogpsf made their first contribution in https://github.com/fastly/sidekiq-prometheus/pull/38
12
+ * @davidbrusius made their first contribution in https://github.com/fastly/sidekiq-prometheus/pull/40
13
+
14
+ **Full Changelog**: https://github.com/fastly/sidekiq-prometheus/compare/v1.8.3...v1.9.0
15
+
16
+ <a name="v1.8.3"></a>
17
+ ## [v1.8.3](https://github.com/fastly/sidekiq-prometheus/compare/v1.8.2...v1.8.3) (2023-01-30)
18
+
19
+ ## What's Changed
20
+ * Track leader state so that can unregister when demoted by @leklund in https://github.com/fastly/sidekiq-prometheus/pull/36
21
+
22
+ **Full Changelog**: https://github.com/fastly/sidekiq-prometheus/compare/v1.8.2...v1.8.3
23
+
3
24
  <a name="v1.8.2"></a>
4
25
  ## [v1.8.2](https://github.com/fastly/sidekiq-prometheus/compare/v1.8.1...v1.8.2) (2022-11-29)
5
26
 
data/README.md CHANGED
@@ -79,6 +79,7 @@ end
79
79
  * `custom_labels`: Hash of metrics and labels that can be applied to specific metrics. The metric name must be a registered metric. `Hash{Symbol (metric name) => Array<Symbol> (label names)}`
80
80
  * `gc_metrics_enabled`: Boolean that determines whether to record object allocation metrics per job. The default is `true`. Setting this to `false` if you don't need this metric.
81
81
  * `global_metrics_enabled`: Boolean that determines whether to report global metrics from the PeriodicMetrics reporter. When `true` this will report on a number of stats from the Sidekiq API for the cluster. This requires Sidekiq::Enterprise as the reporter uses the leader election functionality to ensure that only one worker per cluster is reporting metrics.
82
+ * `init_label_sets`: Hash of metrics and label sets that are initialized by calling `metric.init_label_set` after the metric is registered. See[ prometheus-client docs](https://github.com/prometheus/client_ruby/tree/e144d6225d3c346e9a4dd0a11f41f8acde386dd8#init_label_set) for details. `Hash{Symbol (metric name) => Array<Hash> (label sets)}`.
82
83
  * `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
84
  * `periodic_reporting_interval`: interval in seconds for reporting periodic metrics. Default: `30`
84
85
  * `metrics_server_enabled`: Boolean that determines whether to run the rack server. Defaults to `true`
@@ -94,6 +95,7 @@ SidekiqPrometheus.configure do |config|
94
95
  config.custom_labels = { sidekiq_job_count: [:worker_class, :job_type, :any_other_label] }
95
96
  config.gc_metrics_enabled = false
96
97
  config.global_metrics_enabled = true
98
+ config.init_label_sets = { sidekiq_job_count: [{worker_class: "class", job_type: "single", any_other_label: "value"}, {worker_class: "class", job_type: "batch", any_other_label: "other-value"}] }
97
99
  config.periodic_metrics_enabled = true
98
100
  config.periodic_reporting_interval = 20
99
101
  config.metrics_server_enabled = true
@@ -101,7 +103,7 @@ SidekiqPrometheus.configure do |config|
101
103
  end
102
104
  ```
103
105
 
104
- Custom labels may be added by defining the `prometheus_labels` method in the worker class,
106
+ Custom labels may be added by defining the `prometheus_labels` method in the worker class,
105
107
  prior you need to register the custom labels as of the above example:
106
108
 
107
109
  ```ruby
@@ -130,10 +132,13 @@ All Sidekiq job metrics are reported with these labels:
130
132
  | sidekiq_job_success | counter | Count of successful Sidekiq jobs |
131
133
  | sidekiq_job_allocated_objects | histogram | Count of ruby objects allocated by a Sidekiq job |
132
134
  | sidekiq_job_failed | counter | Count of failed Sidekiq jobs |
135
+ | sidekiq_job_over_limit | counter | Count of over limit Sidekiq jobs |
136
+
133
137
 
134
138
  Notes:
135
139
 
136
140
  * when a job fails only `sidekiq_job_count` and `sidekiq_job_failed` will be reported.
141
+ * when a job fails due to Sidekiq::Limiter::OverLimit error, only `sidekiq_job_count` and `sidekiq_job_over_limit` will be reported.
137
142
  * `sidekiq_job_allocated_objects` will only be reported if `SidekiqPrometheus.gc_metrics_enabled? == true`
138
143
 
139
144
  ### Periodic GC Metrics
@@ -217,7 +222,7 @@ There is also a method to register more than one metric at a time:
217
222
  customer_worker_metrics = [
218
223
  {
219
224
  name: :file_count, type: :counter, docstring: 'Number of active files',
220
- name: :file_size, type: :gauge, docstring: 'Size of files in bytes',
225
+ name: :file_size, type: :gauge, docstring: 'Size of files in bytes',
221
226
  }
222
227
  ]
223
228
 
@@ -30,7 +30,7 @@ class SidekiqPrometheus::JobMetrics
30
30
 
31
31
  result
32
32
  rescue => e
33
- if e.class.to_s == "Sidekiq::Limiter::OverLimit"
33
+ if e.instance_of?(::Sidekiq::Limiter::OverLimit)
34
34
  registry[:sidekiq_job_over_limit].increment(labels: labels)
35
35
  else
36
36
  err_label = {error_class: e.class.to_s}
@@ -176,7 +176,12 @@ module SidekiqPrometheus::Metrics
176
176
 
177
177
  options[:buckets] = buckets if buckets
178
178
 
179
- registry.send(type, name.to_sym, **options)
179
+ metric = registry.send(type, name.to_sym, **options)
180
+
181
+ init_label_sets = SidekiqPrometheus.init_label_sets.fetch(name, [])
182
+ init_label_sets.each { |label_set| metric.init_label_set(label_set) }
183
+
184
+ metric
180
185
  end
181
186
 
182
187
  def unregister(name:)
@@ -12,6 +12,7 @@
12
12
 
13
13
  begin
14
14
  require "sidekiq/component"
15
+ require "redis"
15
16
  rescue LoadError
16
17
  end
17
18
 
@@ -113,7 +114,11 @@ class SidekiqPrometheus::PeriodicMetrics
113
114
  # Records metrics from Redis
114
115
  def report_redis_metrics
115
116
  redis_info = begin
116
- Sidekiq.redis_info
117
+ if SidekiqPrometheus.sidekiq_seven?
118
+ Sidekiq.default_configuration.redis_info
119
+ else
120
+ Sidekiq.redis_info
121
+ end
117
122
  rescue Redis::BaseConnectionError
118
123
  nil
119
124
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SidekiqPrometheus
4
- VERSION = "1.8.3"
4
+ VERSION = "2.0.0"
5
5
  end
@@ -42,6 +42,14 @@ module SidekiqPrometheus
42
42
  # @return [Boolean] Setting to control enabling/disabling global metrics. Default: true
43
43
  attr_accessor :global_metrics_enabled
44
44
 
45
+ # @return [Hash{Symbol => Array(Hash)}] Label sets that will be initiliazed when a metric is registered.
46
+ # @example
47
+ # {
48
+ # metric_name: [{label: 'value1', other_label: 'value1'}, {label: 'value1', other_label: 'value2'}],
49
+ # another_metric_name: [{label: 'value1', other_label: 'value1'}]
50
+ # }
51
+ attr_accessor :init_label_sets
52
+
45
53
  # @return [Boolean] Setting to control enabling/disabling periodic metrics. Default: true
46
54
  attr_accessor :periodic_metrics_enabled
47
55
 
@@ -82,6 +90,7 @@ module SidekiqPrometheus
82
90
  self.metrics_server_logger_enabled = true
83
91
  self.custom_labels = {}
84
92
  self.custom_metrics = []
93
+ self.init_label_sets = {}
85
94
 
86
95
  module_function
87
96
 
@@ -230,6 +239,10 @@ module SidekiqPrometheus
230
239
  )
231
240
  end
232
241
  end
242
+
243
+ def sidekiq_seven?
244
+ @sk7 ||= Gem::Version.new(Sidekiq::VERSION) >= Gem::Version.new("7.0")
245
+ end
233
246
  end
234
247
 
235
248
  class SidekiqPrometheus::Error < StandardError; end
data/sidekiq_6.gemfile ADDED
@@ -0,0 +1,10 @@
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 sidekiq_prometheus.gemspec
8
+ gemspec
9
+
10
+ gem "sidekiq", "< 7.0"
data/sidekiq_7.gemfile ADDED
@@ -0,0 +1,10 @@
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 sidekiq_prometheus.gemspec
8
+ gemspec
9
+
10
+ gem "sidekiq", "> 7.0"
@@ -28,7 +28,8 @@ Gem::Specification.new do |spec|
28
28
  spec.add_development_dependency "standard"
29
29
 
30
30
  spec.add_runtime_dependency "prometheus-client", ">= 2.0"
31
- spec.add_runtime_dependency "rack"
32
- spec.add_runtime_dependency "sidekiq", "> 5.1", "< 7.0"
31
+ spec.add_runtime_dependency "rack", "< 3.0"
32
+ spec.add_runtime_dependency "redis"
33
+ spec.add_runtime_dependency "sidekiq", "> 5.1"
33
34
  spec.add_runtime_dependency "webrick"
34
35
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq_prometheus
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.3
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lukas Eklund
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2023-01-30 00:00:00.000000000 Z
12
+ date: 2023-08-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -97,6 +97,20 @@ dependencies:
97
97
  version: '2.0'
98
98
  - !ruby/object:Gem::Dependency
99
99
  name: rack
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "<"
103
+ - !ruby/object:Gem::Version
104
+ version: '3.0'
105
+ type: :runtime
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - "<"
110
+ - !ruby/object:Gem::Version
111
+ version: '3.0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: redis
100
114
  requirement: !ruby/object:Gem::Requirement
101
115
  requirements:
102
116
  - - ">="
@@ -116,9 +130,6 @@ dependencies:
116
130
  - - ">"
117
131
  - !ruby/object:Gem::Version
118
132
  version: '5.1'
119
- - - "<"
120
- - !ruby/object:Gem::Version
121
- version: '7.0'
122
133
  type: :runtime
123
134
  prerelease: false
124
135
  version_requirements: !ruby/object:Gem::Requirement
@@ -126,9 +137,6 @@ dependencies:
126
137
  - - ">"
127
138
  - !ruby/object:Gem::Version
128
139
  version: '5.1'
129
- - - "<"
130
- - !ruby/object:Gem::Version
131
- version: '7.0'
132
140
  - !ruby/object:Gem::Dependency
133
141
  name: webrick
134
142
  requirement: !ruby/object:Gem::Requirement
@@ -168,6 +176,8 @@ files:
168
176
  - lib/sidekiq_prometheus/metrics.rb
169
177
  - lib/sidekiq_prometheus/periodic_metrics.rb
170
178
  - lib/sidekiq_prometheus/version.rb
179
+ - sidekiq_6.gemfile
180
+ - sidekiq_7.gemfile
171
181
  - sidekiq_prometheus.gemspec
172
182
  homepage: https://github.com/fastly/sidekiq-prometheus
173
183
  licenses:
@@ -188,7 +198,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
188
198
  - !ruby/object:Gem::Version
189
199
  version: '0'
190
200
  requirements: []
191
- rubygems_version: 3.4.1
201
+ rubygems_version: 3.3.7
192
202
  signing_key:
193
203
  specification_version: 4
194
204
  summary: Prometheus Instrumentation for Sidekiq