sidekiq_prometheus 0.9.2 → 1.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: 109c4043a6a4fec7f4240feb567b8919c97e90e92624d829d60f915787307b8e
4
- data.tar.gz: e922e320009be0ac69ffeb11c64ce78c74ea803af76bff6dbfd9ec1148cfb5d4
3
+ metadata.gz: d3f496cf0e6e5f8cd1b1642d324029bfaa2eec41eed88c54c570cda486a25d9c
4
+ data.tar.gz: 64b0a6b104b23cb4081bbb5d006b8fd958b397a18e2c35c4cdcb37c9b8ac8e25
5
5
  SHA512:
6
- metadata.gz: 8299b54bd66498be1891a5e408d1baa2b40a3277a87c676a02b49b96fd898738f1a4cd4ecd1533a0a360e4f21797cde92b3b4fb308d688fc3ba14637e8f4f27e
7
- data.tar.gz: ed121301c19da12849cd166d12f7701e81e52aa9fda24cbcde99b364b18b7650a8ebb77e1267b1a778faa827c42fcd95f5e4c00c35952facd8f62ae7aa5ba759
6
+ metadata.gz: e14cb219e363d1d13e1c1c40fd56e14e0dcbb873240482ef685f48a948f170af0f7e44d3530ceff578b421f1d938445526e98311b0b8d4280f27d7d4863bd3f9
7
+ data.tar.gz: e309be13ae7d718f1746d4fdb05977673b4d1f067e979bb37309280c0d7bf8de6b6b7f73f9cabea1ad9459d995a98b76c334ba73c2a272ec6e6e3496b6cd402a
data/.gitignore CHANGED
@@ -8,3 +8,4 @@
8
8
  /tmp/
9
9
  .rspec_status
10
10
  Gemfile.lock
11
+ /.idea/
@@ -1,5 +1,21 @@
1
1
  CHANGELOG
2
2
 
3
+ <a name="v1.0.0"></a>
4
+ ## [v1.0.0](https://github.com/fastly/sidekiq-prometheus/compare/v0.9.1...v1.0.0) (2019-10-24)
5
+
6
+ ### Pull Requests
7
+
8
+ * Merge pull request [#9](https://github.com/fastly/sidekiq-prometheus/issues/9) from we4tech/features/update-prometheus-client
9
+
10
+
11
+ <a name="v0.9.1"></a>
12
+ ## [v0.9.1](https://github.com/fastly/sidekiq-prometheus/compare/v0.9.0...v0.9.1) (2019-07-08)
13
+
14
+ ### Bug Fixes
15
+
16
+ * properly alias configure!
17
+
18
+
3
19
  <a name="v0.9.0"></a>
4
20
  ## [v0.9.0](https://github.com/fastly/sidekiq-prometheus/compare/v0.8.1...v0.9.0) (2019-03-18)
5
21
 
data/README.md CHANGED
@@ -58,24 +58,25 @@ You can configure the gem by calling `configure`:
58
58
 
59
59
  ```ruby
60
60
  SidekiqPrometheus.configure do |config|
61
- config.base_labels = { service: 'kubernandos_api' }
61
+ config.preset_labels = { service: 'kubernandos_api' }
62
62
  end
63
63
  ```
64
64
 
65
65
  `configure` will automatically call setup so
66
66
 
67
- If you are running multiple services that will be reporting Sidekiq metrics you will want to take advantage of the `base_labels` configuration option. For example:
67
+ If you are running multiple services that will be reporting Sidekiq metrics you will want to take advantage of the `preset_labels` configuration option. For example:
68
68
 
69
69
  ```ruby
70
70
  SidekiqPrometheus.configure do |config|
71
- config.base_labels = { service: 'image_api' }
71
+ config.preset_labels = { service: 'image_api' }
72
72
  config.metrics_port = 9090
73
73
  end
74
74
  ```
75
75
 
76
76
  #### Configuration options
77
77
 
78
- * `base_labels`: Hash of labels that will be included with every metric when they are registered.
78
+ * `preset_labels`: Hash of labels that will be included with every metric when they are registered.
79
+ * `custom_labels`: Array of names for each label that will be passed during the reporting.
79
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.
80
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.
81
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`.
@@ -85,7 +86,8 @@ end
85
86
 
86
87
  ```ruby
87
88
  SidekiqPrometheus.configure do |config|
88
- config.base_labels = { service: 'myapp' }
89
+ config.preset_labels = { service: 'myapp' }
90
+ config.custom_labels = [:worker_class, :job_type, :any_other_label]
89
91
  config.gc_metrics_enabled = false
90
92
  config.global_metrics_enabled = true
91
93
  config.periodic_metrics_enabled = true
@@ -94,7 +96,8 @@ SidekiqPrometheus.configure do |config|
94
96
  end
95
97
  ```
96
98
 
97
- Custom labels may be added by defining the `prometheus_labels` method in the worker class:
99
+ Custom labels may be added by defining the `prometheus_labels` method in the worker class,
100
+ prior you need to register the custom labels as of the above example:
98
101
 
99
102
  ```ruby
100
103
  class SomeWorker
@@ -164,7 +167,7 @@ which ensures that metrics are only reported once per cluster.
164
167
  | sidekiq_redis_keys | gauge | Number of redis keys |
165
168
  | sidekiq_redis_expires | gauge | Number of redis keys with expiry set |
166
169
 
167
- The global metrics are reported with the only the `base_labels` with the exception of `sidekiq_enqueued` which will add a `queue` label and record a metric per Sidekiq queue.
170
+ The global metrics are reported with the only the `preset_labels` with the exception of `sidekiq_enqueued` which will add a `queue` label and record a metric per Sidekiq queue.
168
171
 
169
172
  ## Custom Worker Metrics
170
173
 
@@ -175,14 +178,14 @@ There are a few different ways to register custom metrics with SidekiqPrometheus
175
178
  name: :metric_name,
176
179
  type: :gauge,
177
180
  docstring: 'description',
178
- base_labels: { label_name: 'label_text' },
181
+ preset_labels: { label_name: 'label_text' },
179
182
  }
180
183
  ```
181
184
 
182
185
  * `:name` (required) - Unique name of the metric and should be a symbol.
183
186
  * `:type` (required) - Prometheus metric type. Supported values are: `:counter`, `:gauge`, `:histogram`, and `:summary`.
184
187
  * `:docstring` (required) - Human readable description of the metric.
185
- * `:base_labels` (optional) - Hash of labels that will be applied to every instance of this metric.
188
+ * `:preset_labels` (optional) - Hash of labels that will be applied to every instance of this metric.
186
189
 
187
190
  #### Registering custom metrics:
188
191
 
@@ -14,10 +14,10 @@ end
14
14
 
15
15
  module SidekiqPrometheus
16
16
  class << self
17
- # @return [Hash] Base labels applied to every registered metric
18
- attr_accessor :base_labels
17
+ # @return [Hash] Preset labels applied to every registered metric
18
+ attr_accessor :preset_labels
19
19
 
20
- # @return [Hash] Custom labels applied to specific metrics
20
+ # @return [Hash{Symbol => Array<Symbol>}] Custom labels applied to specific metrics
21
21
  attr_accessor :custom_labels
22
22
 
23
23
  # @return [Array] Custom metrics that will be registered on setup.
@@ -27,12 +27,12 @@ module SidekiqPrometheus
27
27
  # name: :metric_name,
28
28
  # type: :prometheus_metric_type,
29
29
  # docstring: 'Description of the metric',
30
- # base_labels : { label: 'value' },
30
+ # preset_labels : { label: 'value' },
31
31
  # }
32
32
  # ]
33
33
  # @note Each element of the array is a hash and must have the required keys: `:name`, `:type`, and `:docstring`.
34
34
  # The values for `:name` and `:type` should be symbols and `:docstring` should be a string.
35
- # `base_labels` is optional and, if used, must be a hash of labels that will be included on every instance of this metric.
35
+ # `preset_labels` is optional and, if used, must be a hash of labels that will be included on every instance of this metric.
36
36
  attr_accessor :custom_metrics
37
37
 
38
38
  # @return [Boolean] Setting to control enabling/disabling GC metrics. Default: true
@@ -82,8 +82,8 @@ module SidekiqPrometheus
82
82
  # Configure SidekiqPrometheus and setup for reporting
83
83
  # @example
84
84
  # SidekiqPrometheus.configure do |config|
85
- # config.base_labels = { service: 'images_api' }
86
- # config.custom_labels = { sidekiq_job_count: { object_klass: nil } }
85
+ # config.preset_labels = { service: 'images_api' }
86
+ # config.custom_labels = { sidekiq_job_count: [:custom_label_1, :custom_label_2] } }
87
87
  # config.gc_metrics_enabled = true
88
88
  # end
89
89
  def configure
@@ -15,20 +15,20 @@ class SidekiqPrometheus::JobMetrics
15
15
  # In case the labels have changed after the worker perform method has been called
16
16
  labels.merge!(custom_labels(worker))
17
17
 
18
- registry[:sidekiq_job_duration].observe(labels, duration)
19
- registry[:sidekiq_job_success].increment(labels)
18
+ registry[:sidekiq_job_duration].observe(duration, labels: labels)
19
+ registry[:sidekiq_job_success].increment(labels: labels)
20
20
 
21
21
  if SidekiqPrometheus.gc_metrics_enabled?
22
22
  allocated = GC.stat(:total_allocated_objects) - before
23
- registry[:sidekiq_job_allocated_objects].observe(labels, allocated)
23
+ registry[:sidekiq_job_allocated_objects].observe(allocated, labels: labels)
24
24
  end
25
25
 
26
26
  result
27
27
  rescue StandardError => e
28
- registry[:sidekiq_job_failed].increment(labels)
28
+ registry[:sidekiq_job_failed].increment(labels: labels)
29
29
  raise e
30
30
  ensure
31
- registry[:sidekiq_job_count].increment(labels)
31
+ registry[:sidekiq_job_count].increment(labels: labels)
32
32
  end
33
33
  end
34
34
 
@@ -6,6 +6,7 @@ module SidekiqPrometheus::Metrics
6
6
  UNKNOWN = 'unknown'
7
7
 
8
8
  VALID_TYPES = %i[counter gauge histogram summary].freeze
9
+ JOB_LABELS = %i[class queue].freeze
9
10
  SIDEKIQ_GLOBAL_METRICS = [
10
11
  { name: :sidekiq_workers_size,
11
12
  type: :gauge,
@@ -15,10 +16,12 @@ module SidekiqPrometheus::Metrics
15
16
  docstring: 'Total Dead Size', },
16
17
  { name: :sidekiq_enqueued,
17
18
  type: :gauge,
18
- docstring: 'Total Size of all known queues', },
19
+ docstring: 'Total Size of all known queues',
20
+ labels: %i[queue], },
19
21
  { name: :sidekiq_queue_latency,
20
22
  type: :summary,
21
- docstring: 'Latency (in seconds) of all queues', },
23
+ docstring: 'Latency (in seconds) of all queues',
24
+ labels: %i[queue], },
22
25
  { name: :sidekiq_failed,
23
26
  type: :gauge,
24
27
  docstring: 'Number of job executions which raised an error', },
@@ -42,30 +45,37 @@ module SidekiqPrometheus::Metrics
42
45
  docstring: 'Used memory peak from Redis.info', },
43
46
  { name: :sidekiq_redis_keys,
44
47
  type: :gauge,
45
- docstring: 'Number of redis keys', },
48
+ docstring: 'Number of redis keys',
49
+ labels: %i[database], },
46
50
  { name: :sidekiq_redis_expires,
47
51
  type: :gauge,
48
- docstring: 'Number of redis keys with expiry set', },
52
+ docstring: 'Number of redis keys with expiry set',
53
+ labels: %i[database], },
49
54
  ].freeze
50
55
  SIDEKIQ_JOB_METRICS = [
51
56
  { name: :sidekiq_job_count,
52
57
  type: :counter,
53
- docstring: 'Count of Sidekiq jobs', },
58
+ docstring: 'Count of Sidekiq jobs',
59
+ labels: JOB_LABELS, },
54
60
  { name: :sidekiq_job_duration,
55
61
  type: :histogram,
56
- docstring: 'Sidekiq job processing duration', },
62
+ docstring: 'Sidekiq job processing duration',
63
+ labels: JOB_LABELS, },
57
64
  { name: :sidekiq_job_failed,
58
65
  type: :counter,
59
- docstring: 'Count of failed Sidekiq jobs', },
66
+ docstring: 'Count of failed Sidekiq jobs',
67
+ labels: JOB_LABELS, },
60
68
  { name: :sidekiq_job_success,
61
69
  type: :counter,
62
- docstring: 'Count of successful Sidekiq jobs', },
70
+ docstring: 'Count of successful Sidekiq jobs',
71
+ labels: JOB_LABELS, },
63
72
  ].freeze
64
73
  SIDEKIQ_GC_METRIC = {
65
74
  name: :sidekiq_job_allocated_objects,
66
75
  type: :histogram,
67
76
  docstring: 'Count of ruby objects allocated by a Sidekiq job',
68
77
  buckets: [10, 50, 100, 500, 1_000, 2_500, 5_000, 10_000, 50_000, 100_000, 500_000, 1_000_000, 5_000_000, 10_000_000, 25_000_000],
78
+ labels: JOB_LABELS,
69
79
  }.freeze
70
80
  SIDEKIQ_WORKER_GC_METRICS = [
71
81
  { name: :sidekiq_allocated_objects,
@@ -130,21 +140,26 @@ module SidekiqPrometheus::Metrics
130
140
  # @param types [Symbol] type of metric to register. Valid types: %w(counter gauge summary histogram)
131
141
  # @param name [Symbol] name of metric
132
142
  # @param docstring [String] help text for metric
133
- # @param base_labels [Hash] Optional hash of base labels to use for every instance of this metric
143
+ # @param labels [Array] Optionally an array of labels to configure for every instance of this metric
144
+ # @param preset_labels [Hash] Optionally a Hash of labels to use for every instance of this metric
134
145
  # @param buckets [Hash] Optional hash of bucket values. Only used for histogram metrics.
135
- def register(type:, name:, docstring:, base_labels: {}, buckets: nil)
146
+ def register(type:, name:, docstring:, labels: [], preset_labels: {}, buckets: nil)
136
147
  raise InvalidMetricType, type unless VALID_TYPES.include? type
137
148
 
138
- custom_labels = SidekiqPrometheus.custom_labels[name]
149
+ # Aggregate all preset labels
150
+ all_preset_labels = preset_labels.dup
151
+ all_preset_labels.merge!(SidekiqPrometheus.preset_labels) if SidekiqPrometheus.preset_labels
139
152
 
140
- base_labels.merge! custom_labels if custom_labels&.is_a?(Hash)
141
- base_labels.merge! SidekiqPrometheus.base_labels if SidekiqPrometheus.base_labels
153
+ # Aggregate all labels
154
+ all_labels = labels | SidekiqPrometheus.custom_labels.fetch(name, []) | all_preset_labels.keys
142
155
 
143
- args = [name.to_sym, docstring]
144
- args << base_labels
145
- args << buckets if buckets
156
+ options = { docstring: docstring,
157
+ labels: all_labels,
158
+ preset_labels: all_preset_labels, }
146
159
 
147
- registry.send(type, *args)
160
+ options[:buckets] = buckets if buckets
161
+
162
+ registry.send(type, name.to_sym, options)
148
163
  end
149
164
 
150
165
  def unregister(name:)
@@ -71,13 +71,13 @@ class SidekiqPrometheus::PeriodicMetrics
71
71
  def report_gc_metrics
72
72
  stats = GC.stat
73
73
  GC_STATS[:counters].each do |stat|
74
- SidekiqPrometheus["sidekiq_#{stat}"]&.increment({}, stats[stat])
74
+ SidekiqPrometheus["sidekiq_#{stat}"]&.increment(labels: {}, by: stats[stat])
75
75
  end
76
76
  GC_STATS[:gauges].each do |stat|
77
- SidekiqPrometheus["sidekiq_#{stat}"]&.set({}, stats[stat])
77
+ SidekiqPrometheus["sidekiq_#{stat}"]&.set(stats[stat], labels: {})
78
78
  end
79
79
 
80
- SidekiqPrometheus[:sidekiq_rss]&.set({}, rss)
80
+ SidekiqPrometheus[:sidekiq_rss]&.set(rss, labels: {})
81
81
  end
82
82
 
83
83
  ##
@@ -85,12 +85,12 @@ class SidekiqPrometheus::PeriodicMetrics
85
85
  def report_global_metrics
86
86
  current_stats = sidekiq_stats.new
87
87
  GLOBAL_STATS.each do |stat|
88
- SidekiqPrometheus["sidekiq_#{stat}"]&.set({}, current_stats.send(stat))
88
+ SidekiqPrometheus["sidekiq_#{stat}"]&.set(current_stats.send(stat), labels: {})
89
89
  end
90
90
 
91
91
  sidekiq_queue.all.each do |queue|
92
- SidekiqPrometheus[:sidekiq_enqueued]&.set({ queue: queue.name }, queue.size)
93
- SidekiqPrometheus[:sidekiq_queue_latency]&.observe({ queue: queue.name }, queue.latency)
92
+ SidekiqPrometheus[:sidekiq_enqueued]&.set(queue.size, labels: { queue: queue.name })
93
+ SidekiqPrometheus[:sidekiq_queue_latency]&.observe(queue.latency, labels: { queue: queue.name })
94
94
  end
95
95
  end
96
96
 
@@ -106,15 +106,15 @@ class SidekiqPrometheus::PeriodicMetrics
106
106
  return if redis_info.nil?
107
107
 
108
108
  REDIS_STATS.each do |stat|
109
- SidekiqPrometheus["sidekiq_redis_#{stat}"]&.set({}, redis_info[stat].to_i)
109
+ SidekiqPrometheus["sidekiq_redis_#{stat}"]&.set(redis_info[stat].to_i, labels: {})
110
110
  end
111
111
 
112
112
  db_stats = redis_info.select { |k, _v| k.match(/^db/) }
113
113
  db_stats.each do |db, stat|
114
114
  label = { database: db }
115
115
  values = stat.scan(/\d+/)
116
- SidekiqPrometheus[:sidekiq_redis_keys]&.set(label, values[0].to_i)
117
- SidekiqPrometheus[:sidekiq_redis_expires]&.set(label, values[1].to_i)
116
+ SidekiqPrometheus[:sidekiq_redis_keys]&.set(values[0].to_i, labels: label)
117
+ SidekiqPrometheus[:sidekiq_redis_expires]&.set(values[1].to_i, labels: label)
118
118
  end
119
119
  end
120
120
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SidekiqPrometheus
4
- VERSION = '0.9.2'
4
+ VERSION = '1.0.0'
5
5
  end
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
27
27
  spec.add_development_dependency 'rspec', '~> 3.0'
28
28
  spec.add_development_dependency 'rubocop', '~> 0.58.0'
29
29
 
30
- spec.add_runtime_dependency 'prometheus-client', '~> 0.8.0'
30
+ spec.add_runtime_dependency 'prometheus-client', '~> 0.10.0'
31
31
  spec.add_runtime_dependency 'rack'
32
- spec.add_runtime_dependency 'sidekiq', '> 5.1'
32
+ spec.add_runtime_dependency 'sidekiq', '~> 5.1'
33
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq_prometheus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lukas Eklund
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-30 00:00:00.000000000 Z
11
+ date: 2019-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 0.8.0
89
+ version: 0.10.0
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: 0.8.0
96
+ version: 0.10.0
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rack
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -112,14 +112,14 @@ dependencies:
112
112
  name: sidekiq
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ">"
115
+ - - "~>"
116
116
  - !ruby/object:Gem::Version
117
117
  version: '5.1'
118
118
  type: :runtime
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ">"
122
+ - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: '5.1'
125
125
  description: