prometheus-client 0.9.0 → 0.10.0.pre.alpha.1

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.
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Prometheus
4
4
  module Client
5
- VERSION = '0.9.0'
5
+ VERSION = '0.10.0-alpha.1'
6
6
  end
7
7
  end
@@ -20,6 +20,11 @@ module Prometheus
20
20
  #
21
21
  # The request duration metric is broken down by method and path by default.
22
22
  # Set the `:duration_label_builder` option to use a custom label builder.
23
+ #
24
+ # Label Builder functions will receive a Rack env and a status code, and must
25
+ # return a hash with the labels for that request. They must also accept an empty
26
+ # env, and return a hash with the correct keys. This is necessary to initialize
27
+ # the metrics with the correct set of labels.
23
28
  class Collector
24
29
  attr_reader :app, :registry
25
30
 
@@ -27,8 +32,6 @@ module Prometheus
27
32
  @app = app
28
33
  @registry = options[:registry] || Client.registry
29
34
  @metrics_prefix = options[:metrics_prefix] || 'http_server'
30
- @counter_lb = options[:counter_label_builder] || COUNTER_LB
31
- @duration_lb = options[:duration_label_builder] || DURATION_LB
32
35
 
33
36
  init_request_metrics
34
37
  init_exception_metrics
@@ -40,42 +43,25 @@ module Prometheus
40
43
 
41
44
  protected
42
45
 
43
- aggregation = lambda do |str|
44
- str
45
- .gsub(%r{/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}(/|$)}, '/:uuid\\1')
46
- .gsub(%r{/\d+(/|$)}, '/:id\\1')
47
- end
48
-
49
- COUNTER_LB = proc do |env, code|
50
- {
51
- code: code,
52
- method: env['REQUEST_METHOD'].downcase,
53
- path: aggregation.call(env['PATH_INFO']),
54
- }
55
- end
56
-
57
- DURATION_LB = proc do |env, _|
58
- {
59
- method: env['REQUEST_METHOD'].downcase,
60
- path: aggregation.call(env['PATH_INFO']),
61
- }
62
- end
63
-
64
46
  def init_request_metrics
65
47
  @requests = @registry.counter(
66
48
  :"#{@metrics_prefix}_requests_total",
67
- 'The total number of HTTP requests handled by the Rack application.',
49
+ docstring:
50
+ 'The total number of HTTP requests handled by the Rack application.',
51
+ labels: %i[code method path]
68
52
  )
69
53
  @durations = @registry.histogram(
70
54
  :"#{@metrics_prefix}_request_duration_seconds",
71
- 'The HTTP response duration of the Rack application.',
55
+ docstring: 'The HTTP response duration of the Rack application.',
56
+ labels: %i[method path]
72
57
  )
73
58
  end
74
59
 
75
60
  def init_exception_metrics
76
61
  @exceptions = @registry.counter(
77
62
  :"#{@metrics_prefix}_exceptions_total",
78
- 'The total number of exceptions raised by the Rack application.',
63
+ docstring: 'The total number of exceptions raised by the Rack application.',
64
+ labels: [:exception]
79
65
  )
80
66
  end
81
67
 
@@ -85,17 +71,34 @@ module Prometheus
85
71
  record(env, response.first.to_s, duration)
86
72
  return response
87
73
  rescue => exception
88
- @exceptions.increment(exception: exception.class.name)
74
+ @exceptions.increment(labels: { exception: exception.class.name })
89
75
  raise
90
76
  end
91
77
 
92
78
  def record(env, code, duration)
93
- @requests.increment(@counter_lb.call(env, code))
94
- @durations.observe(@duration_lb.call(env, code), duration)
79
+ counter_labels = {
80
+ code: code,
81
+ method: env['REQUEST_METHOD'].downcase,
82
+ path: strip_ids_from_path(env['PATH_INFO']),
83
+ }
84
+
85
+ duration_labels = {
86
+ method: env['REQUEST_METHOD'].downcase,
87
+ path: strip_ids_from_path(env['PATH_INFO']),
88
+ }
89
+
90
+ @requests.increment(labels: counter_labels)
91
+ @durations.observe(duration, labels: duration_labels)
95
92
  rescue
96
93
  # TODO: log unexpected exception during request recording
97
94
  nil
98
95
  end
96
+
97
+ def strip_ids_from_path(path)
98
+ path
99
+ .gsub(%r{/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}(/|$)}, '/:uuid\\1')
100
+ .gsub(%r{/\d+(/|$)}, '/:id\\1')
101
+ end
99
102
  end
100
103
  end
101
104
  end
metadata CHANGED
@@ -1,32 +1,50 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prometheus-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.10.0.pre.alpha.1
5
5
  platform: ruby
6
6
  authors:
7
- - Tobias Schmidt
7
+ - Ben Kochie
8
+ - Chris Sinjakli
9
+ - Daniel Magliola
8
10
  autorequire:
9
11
  bindir: bin
10
12
  cert_chain: []
11
- date: 2019-01-25 00:00:00.000000000 Z
13
+ date: 2019-05-23 00:00:00.000000000 Z
12
14
  dependencies:
13
15
  - !ruby/object:Gem::Dependency
14
- name: quantile
16
+ name: concurrent-ruby
15
17
  requirement: !ruby/object:Gem::Requirement
16
18
  requirements:
17
- - - "~>"
19
+ - - ">="
18
20
  - !ruby/object:Gem::Version
19
- version: 0.2.1
21
+ version: '0'
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
23
25
  requirements:
24
- - - "~>"
26
+ - - ">="
25
27
  - !ruby/object:Gem::Version
26
- version: 0.2.1
28
+ version: '0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: benchmark-ips
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
27
43
  description:
28
44
  email:
29
- - ts@soundcloud.com
45
+ - superq@gmail.com
46
+ - chris@gocardless.com
47
+ - dmagliola@crystalgears.com
30
48
  executables: []
31
49
  extensions: []
32
50
  extra_rdoc_files: []
@@ -34,7 +52,12 @@ files:
34
52
  - README.md
35
53
  - lib/prometheus.rb
36
54
  - lib/prometheus/client.rb
55
+ - lib/prometheus/client/config.rb
37
56
  - lib/prometheus/client/counter.rb
57
+ - lib/prometheus/client/data_stores/README.md
58
+ - lib/prometheus/client/data_stores/direct_file_store.rb
59
+ - lib/prometheus/client/data_stores/single_threaded.rb
60
+ - lib/prometheus/client/data_stores/synchronized.rb
38
61
  - lib/prometheus/client/formats/text.rb
39
62
  - lib/prometheus/client/gauge.rb
40
63
  - lib/prometheus/client/histogram.rb
@@ -61,11 +84,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
61
84
  version: '0'
62
85
  required_rubygems_version: !ruby/object:Gem::Requirement
63
86
  requirements:
64
- - - ">="
87
+ - - ">"
65
88
  - !ruby/object:Gem::Version
66
- version: '0'
89
+ version: 1.3.1
67
90
  requirements: []
68
- rubygems_version: 3.0.2
91
+ rubyforge_project:
92
+ rubygems_version: 2.7.6
69
93
  signing_key:
70
94
  specification_version: 4
71
95
  summary: A suite of instrumentation metric primitivesthat can be exposed through a