prometheus_exporter 0.6.0 → 0.7.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: f516c39448418a2216851149f0479f3f9e0f5feadae5a5468e7953fc0551d318
4
- data.tar.gz: dcc937b79e05d4cd74a64ab2135425c75c4bba1be053bec99e8db0695a3ac998
3
+ metadata.gz: 2f949348bbafc06b8f7a3dd3927693de8fef54090d85a7889afbfbf7dcb167b6
4
+ data.tar.gz: adeca8000ebb59c7225c1453135900aeab5c1760902edd5b4fecf9fa4b879a57
5
5
  SHA512:
6
- metadata.gz: 5664f24c1c4a1520bafe789e5df8a9f1c40b118933cab9b73baa953f633ec6e81c3a11bbc9fc63097a2a2acdd2390daeade9449e6451cc83207fc2162575b359
7
- data.tar.gz: ca4aeedbc6e211818569257e8a3e9fde93be363a2da246abae45749bc9cc232052ac52f0850cd54d0f600904bed193a10db1f76e4fc9567b837b20a78264158b
6
+ metadata.gz: 7d3829ad57f03a19f6081c3444f9b13906aedd4fa1c5b99237d454096e0d993c27c2df0993482c421b6034a58a55c9603620bcdf7698248e4ac23a5063d63718
7
+ data.tar.gz: fb915716acbbb4f24a152c8ebf9eb35bdc97185a7144eb986e50aafad07a36d5cc83cbbbf7c16e8b399207e9c66d90973d2e6f9ddcdc8a17cab797840d13ed8b
@@ -12,7 +12,7 @@ jobs:
12
12
  name: Ruby ${{ matrix.ruby }}
13
13
  strategy:
14
14
  matrix:
15
- ruby: ["2.7", "2.6", "2.5", "2.4"]
15
+ ruby: ["2.7", "2.6", "2.5"]
16
16
  steps:
17
17
  - uses: actions/checkout@master
18
18
  with:
@@ -23,14 +23,20 @@ jobs:
23
23
  - uses: actions/cache@v2
24
24
  with:
25
25
  path: vendor/bundle
26
- key: ${{ runner.os }}-${{ matrix.ruby }}-gems-${{ hashFiles('**/Gemfile.lock') }}
26
+ key: ${{ runner.os }}-${{ matrix.ruby }}-gems-v2-${{ hashFiles('**/Gemfile.lock') }}
27
27
  restore-keys: |
28
- ${{ runner.os }}-${{ matrix.ruby }}-gems-
28
+ ${{ runner.os }}-${{ matrix.ruby }}-gems-v2-
29
29
  - name: Setup gems
30
30
  run: |
31
+ gem install bundler
32
+ # for Ruby <= 2.6 , details https://github.com/rubygems/rubygems/issues/3284
33
+ gem update --system 3.0.8 && gem update --system
31
34
  bundle config path vendor/bundle
32
35
  bundle install --jobs 4
36
+ bundle exec appraisal install
33
37
  - name: Rubocop
34
38
  run: bundle exec rubocop
39
+ - name: install gems
40
+ run: bundle exec appraisal bundle
35
41
  - name: Run tests
36
- run: bundle exec rake
42
+ run: bundle exec appraisal rake
data/.gitignore CHANGED
@@ -7,5 +7,7 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
  Gemfile.lock
10
+ /gemfiles/*.gemfile.lock
11
+
10
12
 
11
13
  .rubocop-https---raw-githubusercontent-com-discourse-discourse-master--rubocop-yml
@@ -1,2 +1,7 @@
1
1
  inherit_gem:
2
2
  rubocop-discourse: default.yml
3
+
4
+ AllCops:
5
+ Exclude:
6
+ - 'gemfiles/**/*'
7
+ - 'vendor/**/*'
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ appraise "ar-60" do
4
+ # we are using this version as default in gemspec
5
+ # gem "activerecord", "~> 6.0.0"
6
+ end
7
+
8
+ appraise "ar-61" do
9
+ gem "activerecord", "~> 6.1.0.rc2"
10
+ end
data/CHANGELOG CHANGED
@@ -1,4 +1,12 @@
1
- 0.6.0 - 10-11-2020
1
+ 0.7.0 - 29-12-2020
2
+
3
+ - Dev: Removed support from EOL rubies, only 2.5, 2.6, 2.7 and 3.0 are supported now.
4
+ - Dev: Better support for Ruby 3.0, explicitly depending on webrick
5
+ - Dev: Rails 6.1 instrumentation support
6
+ - FEATURE: clean pattern for overriding middleware labels was introduced (in README)
7
+ - Fix: Better support for forking
8
+
9
+ 0.6.0 - 17-11-2020
2
10
 
3
11
  - FEATURE: add support for basic-auth in the prometheus_exporter web server
4
12
 
data/README.md CHANGED
@@ -33,7 +33,7 @@ To learn more see [Instrumenting Rails with Prometheus](https://samsaffron.com/a
33
33
 
34
34
  ## Requirements
35
35
 
36
- Minimum Ruby of version 2.3.0 is required, Ruby 2.2.0 is EOL as of 2018-03-31
36
+ Minimum Ruby of version 2.5.0 is required, Ruby 2.4.0 is EOL as of 2020-04-05
37
37
 
38
38
  ## Installation
39
39
 
@@ -218,6 +218,32 @@ class MyMiddleware < PrometheusExporter::Middleware
218
218
  end
219
219
  ```
220
220
 
221
+ If you're not using Rails like framework, you can extend `PrometheusExporter::Middleware#default_labels` in a way to add more relevant labels.
222
+ For example you can mimic [prometheus-client](https://github.com/prometheus/client_ruby) labels with code like this:
223
+ ```ruby
224
+ class MyMiddleware < PrometheusExporter::Middleware
225
+ def default_labels(env, result)
226
+ status = (result && result[0]) || -1
227
+ path = [env["SCRIPT_NAME"], env["PATH_INFO"]].join
228
+ {
229
+ path: strip_ids_from_path(path),
230
+ method: env["REQUEST_METHOD"],
231
+ status: status
232
+ }
233
+ end
234
+
235
+ def strip_ids_from_path(path)
236
+ path
237
+ .gsub(%r{/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}(/|$)}, '/:uuid\\1')
238
+ .gsub(%r{/\d+(/|$)}, '/:id\\1')
239
+ end
240
+ end
241
+ ```
242
+ That way you won't have all metrics labeled with `controller=other` and `action=other`, but have labels such as
243
+ ```
244
+ ruby_http_duration_seconds{path="/api/v1/teams/:id",method="GET",status="200",quantile="0.99"} 0.009880661998977303
245
+ ```
246
+
221
247
  ¹) Only available when Redis is used.
222
248
  ²) Only available when Mysql or PostgreSQL are used.
223
249
  ³) Only available when [Instrumenting Request Queueing Time](#instrumenting-request-queueing-time) is set up.
@@ -0,0 +1,2 @@
1
+ ---
2
+ BUNDLE_RETRY: "1"
@@ -0,0 +1,5 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gemspec path: "../"
@@ -0,0 +1,7 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "activerecord", "~> 6.1.0"
6
+
7
+ gemspec path: "../"
@@ -188,7 +188,7 @@ module PrometheusExporter
188
188
 
189
189
  def close_socket!
190
190
  begin
191
- if @socket
191
+ if @socket && !@socket.closed?
192
192
  @socket.write("0\r\n")
193
193
  @socket.write("\r\n")
194
194
  @socket.flush
@@ -67,21 +67,30 @@ module PrometheusExporter::Instrumentation
67
67
  ObjectSpace.each_object(::ActiveRecord::ConnectionAdapters::ConnectionPool) do |pool|
68
68
  next if pool.connections.nil?
69
69
 
70
- labels_from_config = pool.spec.config
71
- .select { |k, v| @config_labels.include? k }
72
- .map { |k, v| [k.to_s.dup.prepend("dbconfig_"), v] }
73
-
74
- labels = @metric_labels.merge(pool_name: pool.spec.name).merge(Hash[labels_from_config])
75
-
76
70
  metric = {
77
71
  pid: pid,
78
72
  type: "active_record",
79
73
  hostname: ::PrometheusExporter.hostname,
80
- metric_labels: labels
74
+ metric_labels: labels(pool)
81
75
  }
82
76
  metric.merge!(pool.stat)
83
77
  metrics << metric
84
78
  end
85
79
  end
80
+
81
+ private
82
+
83
+ def labels(pool)
84
+ if pool.respond_to?(:spec) # ActiveRecord <= 6.0
85
+ @metric_labels.merge(pool_name: pool.spec.name).merge(pool.spec.config
86
+ .select { |k, v| @config_labels.include? k }
87
+ .map { |k, v| [k.to_s.dup.prepend("dbconfig_"), v] }.to_h)
88
+ elsif pool.respond_to?(:db_config) # ActiveRecord >= 6.1.rc1
89
+ @metric_labels.merge(pool_name: pool.db_config.name).merge(
90
+ @config_labels.each_with_object({}) { |l, acc| acc["dbconfig_#{l}"] = pool.db_config.public_send(l) })
91
+ else
92
+ raise "Unsupported connection pool"
93
+ end
94
+ end
86
95
  end
87
96
  end
@@ -36,21 +36,12 @@ class PrometheusExporter::Middleware
36
36
 
37
37
  result
38
38
  ensure
39
- status = (result && result[0]) || -1
40
- params = env["action_dispatch.request.parameters"]
41
- action, controller = nil
42
- if params
43
- action = params["action"]
44
- controller = params["controller"]
45
- end
46
39
 
47
40
  obj = {
48
41
  type: "web",
49
42
  timings: info,
50
43
  queue_time: queue_time,
51
- action: action,
52
- controller: controller,
53
- status: status
44
+ default_labels: default_labels(env, result)
54
45
  }
55
46
  labels = custom_labels(env)
56
47
  if labels
@@ -60,6 +51,22 @@ class PrometheusExporter::Middleware
60
51
  @client.send_json(obj)
61
52
  end
62
53
 
54
+ def default_labels(env, result)
55
+ status = (result && result[0]) || -1
56
+ params = env["action_dispatch.request.parameters"]
57
+ action = controller = nil
58
+ if params
59
+ action = params["action"]
60
+ controller = params["controller"]
61
+ end
62
+
63
+ {
64
+ action: action || "other",
65
+ controller: controller || "other",
66
+ status: status
67
+ }
68
+ end
69
+
63
70
  # allows subclasses to add custom labels based on env
64
71
  def custom_labels(env)
65
72
  nil
@@ -56,14 +56,11 @@ module PrometheusExporter::Server
56
56
  end
57
57
 
58
58
  def observe(obj)
59
- default_labels = {
60
- controller: obj['controller'] || 'other',
61
- action: obj['action'] || 'other'
62
- }
59
+ default_labels = obj['default_labels']
63
60
  custom_labels = obj['custom_labels']
64
61
  labels = custom_labels.nil? ? default_labels : default_labels.merge(custom_labels)
65
62
 
66
- @http_requests_total.observe(1, labels.merge(status: obj["status"]))
63
+ @http_requests_total.observe(1, labels)
67
64
 
68
65
  if timings = obj["timings"]
69
66
  @http_duration_seconds.observe(timings["total_duration"], labels)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PrometheusExporter
4
- VERSION = '0.6.0'
4
+ VERSION = '0.7.0'
5
5
  end
@@ -24,19 +24,23 @@ Gem::Specification.new do |spec|
24
24
  spec.executables = ["prometheus_exporter"]
25
25
  spec.require_paths = ["lib"]
26
26
 
27
+ spec.add_dependency "webrick"
28
+
27
29
  spec.add_development_dependency "rubocop", ">= 0.69"
28
- spec.add_development_dependency "bundler", "> 1.16"
30
+ spec.add_development_dependency "bundler", ">= 2.2.2"
29
31
  spec.add_development_dependency "rake", "~> 13.0"
30
32
  spec.add_development_dependency "minitest", "~> 5.0"
31
33
  spec.add_development_dependency "guard", "~> 2.0"
32
- spec.add_development_dependency "mini_racer", "~> 0.1"
34
+ spec.add_development_dependency "mini_racer", "~> 0.3.1"
33
35
  spec.add_development_dependency "guard-minitest", "~> 2.0"
34
36
  spec.add_development_dependency "oj", "~> 3.0"
35
37
  spec.add_development_dependency "rack-test", "~> 0.8.3"
36
38
  spec.add_development_dependency "minitest-stub-const", "~> 0.6"
37
39
  spec.add_development_dependency "rubocop-discourse", ">2"
40
+ spec.add_development_dependency "appraisal", "~> 2.3"
41
+ spec.add_development_dependency "activerecord", "~> 6.0.0"
38
42
  if !RUBY_ENGINE == 'jruby'
39
43
  spec.add_development_dependency "raindrops", "~> 0.19"
40
44
  end
41
- spec.required_ruby_version = '>= 2.3.0'
45
+ spec.required_ruby_version = '>= 2.5.0'
42
46
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prometheus_exporter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Saffron
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-16 00:00:00.000000000 Z
11
+ date: 2020-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: webrick
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'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rubocop
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -28,16 +42,16 @@ dependencies:
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
- - - ">"
45
+ - - ">="
32
46
  - !ruby/object:Gem::Version
33
- version: '1.16'
47
+ version: 2.2.2
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
- - - ">"
52
+ - - ">="
39
53
  - !ruby/object:Gem::Version
40
- version: '1.16'
54
+ version: 2.2.2
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rake
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -86,14 +100,14 @@ dependencies:
86
100
  requirements:
87
101
  - - "~>"
88
102
  - !ruby/object:Gem::Version
89
- version: '0.1'
103
+ version: 0.3.1
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
108
  - - "~>"
95
109
  - !ruby/object:Gem::Version
96
- version: '0.1'
110
+ version: 0.3.1
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: guard-minitest
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -164,6 +178,34 @@ dependencies:
164
178
  - - ">"
165
179
  - !ruby/object:Gem::Version
166
180
  version: '2'
181
+ - !ruby/object:Gem::Dependency
182
+ name: appraisal
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: '2.3'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: '2.3'
195
+ - !ruby/object:Gem::Dependency
196
+ name: activerecord
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - "~>"
200
+ - !ruby/object:Gem::Version
201
+ version: 6.0.0
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - "~>"
207
+ - !ruby/object:Gem::Version
208
+ version: 6.0.0
167
209
  description: Prometheus metric collector and exporter for Ruby
168
210
  email:
169
211
  - sam.saffron@gmail.com
@@ -175,6 +217,7 @@ files:
175
217
  - ".github/workflows/ci.yml"
176
218
  - ".gitignore"
177
219
  - ".rubocop.yml"
220
+ - Appraisals
178
221
  - CHANGELOG
179
222
  - CODE_OF_CONDUCT.md
180
223
  - Gemfile
@@ -185,6 +228,9 @@ files:
185
228
  - bench/bench.rb
186
229
  - bin/prometheus_exporter
187
230
  - examples/custom_collector.rb
231
+ - gemfiles/.bundle/config
232
+ - gemfiles/ar_60.gemfile
233
+ - gemfiles/ar_61.gemfile
188
234
  - lib/prometheus_exporter.rb
189
235
  - lib/prometheus_exporter/client.rb
190
236
  - lib/prometheus_exporter/instrumentation.rb
@@ -236,14 +282,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
236
282
  requirements:
237
283
  - - ">="
238
284
  - !ruby/object:Gem::Version
239
- version: 2.3.0
285
+ version: 2.5.0
240
286
  required_rubygems_version: !ruby/object:Gem::Requirement
241
287
  requirements:
242
288
  - - ">="
243
289
  - !ruby/object:Gem::Version
244
290
  version: '0'
245
291
  requirements: []
246
- rubygems_version: 3.0.3
292
+ rubygems_version: 3.2.2
247
293
  signing_key:
248
294
  specification_version: 4
249
295
  summary: Prometheus Exporter