promenade 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: 235f95d0b77870a9975ff9870428ed5a995b9174380b981c2df7d8a338519ffb
4
- data.tar.gz: 7d6e327e2d602fd2b07342fb45c9be29e36ad266212ad4ed98a72eafee58bc9e
3
+ metadata.gz: c8f195d39a6967000ebf64da2a2143a85c934ad0a37b7303eb91511dd1f458bf
4
+ data.tar.gz: '030960d747dd81a33a2feea7b6f3a3460fdc3952160b4c000900645df163d402'
5
5
  SHA512:
6
- metadata.gz: e8596f53e3110b636696cb38f2d3bfa872715de3e331fdf260da62e30c31949a1753702b935c3343545c7be19da56f0e30a65d89568eefd419b94a5ef80fe2f9
7
- data.tar.gz: 7e65f494c50b2bc25b05b169794f73c02c64ad1548c3425399b1d2cb4e7077d930e0e7d9c99ea88088c76e1026bb64cfbda246ab1a6b09c057b4f2b717b130d8
6
+ metadata.gz: 3cb2cd2eaf07029afd1ac8ad574be62d5b5f848734ea67f1f94a919fe9a6f548c2bcb71d761b92a30077575114a7b505eebe21f20f380af47471401c62b898f6
7
+ data.tar.gz: 0e94c108cd6e98d0f1280e07412e2cb9a41ef7f5a0d7f33735d785c1253424246e46c5fc49ddc0757658301f697272baa1ee882f109327442d13ffa87e6f6429
@@ -9,7 +9,7 @@ jobs:
9
9
  strategy:
10
10
  fail-fast: false
11
11
  matrix:
12
- ruby: ['2.7', '3.0', "3.1"]
12
+ ruby: ['2.7', '3.0', "3.1", "3.2"]
13
13
  runs-on: ubuntu-latest
14
14
  steps:
15
15
  - uses: actions/checkout@v2
data/.rubocop.yml CHANGED
@@ -16,3 +16,7 @@ Rails/RakeEnvironment:
16
16
  Enabled: false
17
17
  Rails/EnvironmentVariableAccess:
18
18
  Enabled: false
19
+ RSpec/DescribedClass:
20
+ Enabled: false
21
+ Gemspec/DevelopmentDependencies:
22
+ Enabled: false
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- promenade (0.6.0)
4
+ promenade (0.7.0)
5
5
  actionpack
6
6
  activesupport (> 6.0, < 8.0)
7
7
  prometheus-client-mmap (~> 0.16.0)
@@ -109,6 +109,7 @@ GEM
109
109
  highline (2.0.3)
110
110
  i18n (1.10.0)
111
111
  concurrent-ruby (~> 1.0)
112
+ json (2.6.3)
112
113
  loofah (2.18.0)
113
114
  crass (~> 1.0.2)
114
115
  nokogiri (>= 1.5.9)
@@ -138,7 +139,7 @@ GEM
138
139
  mini_portile2 (~> 2.8.0)
139
140
  racc (~> 1.4)
140
141
  parallel (1.22.1)
141
- parser (3.1.2.0)
142
+ parser (3.2.1.0)
142
143
  ast (~> 2.4.1)
143
144
  prometheus-client-mmap (0.16.2)
144
145
  pry (0.14.1)
@@ -176,7 +177,7 @@ GEM
176
177
  zeitwerk (~> 2.5)
177
178
  rainbow (3.1.1)
178
179
  rake (13.0.6)
179
- regexp_parser (2.5.0)
180
+ regexp_parser (2.7.0)
180
181
  rexml (3.2.5)
181
182
  rspec (3.11.0)
182
183
  rspec-core (~> 3.11.0)
@@ -199,17 +200,20 @@ GEM
199
200
  rspec-mocks (~> 3.10)
200
201
  rspec-support (~> 3.10)
201
202
  rspec-support (3.11.0)
202
- rubocop (1.30.1)
203
+ rubocop (1.46.0)
204
+ json (~> 2.3)
203
205
  parallel (~> 1.10)
204
- parser (>= 3.1.0.0)
206
+ parser (>= 3.2.0.0)
205
207
  rainbow (>= 2.2.2, < 4.0)
206
208
  regexp_parser (>= 1.8, < 3.0)
207
209
  rexml (>= 3.2.5, < 4.0)
208
- rubocop-ast (>= 1.18.0, < 2.0)
210
+ rubocop-ast (>= 1.26.0, < 2.0)
209
211
  ruby-progressbar (~> 1.7)
210
- unicode-display_width (>= 1.4.0, < 3.0)
211
- rubocop-ast (1.18.0)
212
- parser (>= 3.1.1.0)
212
+ unicode-display_width (>= 2.4.0, < 3.0)
213
+ rubocop-ast (1.27.0)
214
+ parser (>= 3.2.1.0)
215
+ rubocop-capybara (2.17.1)
216
+ rubocop (~> 1.41)
213
217
  rubocop-performance (1.14.2)
214
218
  rubocop (>= 1.7.0, < 2.0)
215
219
  rubocop-ast (>= 0.4.0)
@@ -217,6 +221,9 @@ GEM
217
221
  activesupport (>= 4.2.0)
218
222
  rack (>= 1.1)
219
223
  rubocop (>= 1.7.0, < 2.0)
224
+ rubocop-rspec (2.18.1)
225
+ rubocop (~> 1.33)
226
+ rubocop-capybara (~> 2.17)
220
227
  ruby-progressbar (1.11.0)
221
228
  simplecov (0.21.2)
222
229
  docile (~> 1.1)
@@ -236,7 +243,7 @@ GEM
236
243
  sync
237
244
  tzinfo (2.0.4)
238
245
  concurrent-ruby (~> 1.0)
239
- unicode-display_width (2.1.0)
246
+ unicode-display_width (2.4.2)
240
247
  webrick (1.7.0)
241
248
  websocket-driver (0.7.5)
242
249
  websocket-extensions (>= 0.1.0)
@@ -262,6 +269,7 @@ DEPENDENCIES
262
269
  rubocop
263
270
  rubocop-performance
264
271
  rubocop-rails
272
+ rubocop-rspec
265
273
  simplecov
266
274
  webrick
267
275
 
data/exe/promenade CHANGED
@@ -8,7 +8,7 @@ Promenade.setup
8
8
 
9
9
  app = Rack::Builder.app do
10
10
  use Rack::Deflater
11
- use ::Prometheus::Client::Rack::Exporter
11
+ use Prometheus::Client::Rack::Exporter
12
12
  map "/health" do
13
13
  run lambda { |_env| [200, { "Content-Type" => "text/plain" }, ["OK"]] }
14
14
  end
@@ -1,6 +1,6 @@
1
1
  require "action_dispatch/middleware/exception_wrapper"
2
2
  require_relative "singleton_caller"
3
- require_relative "request_labeler"
3
+ require_relative "request_controller_action_labeler"
4
4
 
5
5
  module Promenade
6
6
  module Client
@@ -8,21 +8,19 @@ module Promenade
8
8
  class ExceptionHandler
9
9
  extend SingletonCaller
10
10
 
11
- attr_reader :histogram_name, :requests_counter_name, :exceptions_counter_name, :registry
11
+ attr_reader :histogram_name, :exceptions_counter_name, :registry
12
12
 
13
- def initialize(histogram_name:, requests_counter_name:, exceptions_counter_name:, registry:)
13
+ def initialize(histogram_name:, exceptions_counter_name:, registry:)
14
14
  @histogram_name = histogram_name
15
- @requests_counter_name = requests_counter_name
16
15
  @exceptions_counter_name = exceptions_counter_name
17
16
  @registry = registry
18
17
  end
19
18
 
20
19
  def call(exception, env_hash, duration)
21
- labels = RequestLabeler.call(env_hash)
20
+ labels = RequestControllerActionLabeler.call(env_hash)
22
21
  labels.merge!(code: status_code_for_exception(exception))
23
22
 
24
23
  histogram.observe(labels, duration.to_f)
25
- requests_counter.increment(labels)
26
24
  exceptions_counter.increment(exception: exception.class.name)
27
25
 
28
26
  raise exception
@@ -34,10 +32,6 @@ module Promenade
34
32
  registry.get(histogram_name)
35
33
  end
36
34
 
37
- def requests_counter
38
- registry.get(requests_counter_name)
39
- end
40
-
41
35
  def exceptions_counter
42
36
  registry.get(exceptions_counter_name)
43
37
  end
@@ -1,6 +1,6 @@
1
1
  require "prometheus/client"
2
2
  require_relative "middleware_base"
3
- require_relative "request_labeler"
3
+ require_relative "request_controller_action_labeler"
4
4
  require_relative "exception_handler"
5
5
  require_relative "queue_time_duration"
6
6
 
@@ -10,17 +10,14 @@ module Promenade
10
10
  class HTTPRequestDurationCollector < MiddlwareBase
11
11
  REQUEST_DURATION_HISTOGRAM_NAME = :http_req_duration_seconds
12
12
 
13
- REQUESTS_COUNTER_NAME = :http_requests_total
14
-
15
13
  EXCEPTIONS_COUNTER_NAME = :http_exceptions_total
16
14
 
17
15
  private_constant :REQUEST_DURATION_HISTOGRAM_NAME,
18
- :REQUESTS_COUNTER_NAME,
19
16
  :EXCEPTIONS_COUNTER_NAME
20
17
 
21
18
  def initialize(app,
22
19
  registry: ::Prometheus::Client.registry,
23
- label_builder: RequestLabeler,
20
+ label_builder: RequestControllerActionLabeler,
24
21
  exception_handler: nil)
25
22
 
26
23
  @latency_buckets = Promenade.configuration.rack_latency_buckets
@@ -45,7 +42,6 @@ module Promenade
45
42
  end
46
43
 
47
44
  def record_request_duration(labels, duration)
48
- requests_counter.increment(labels)
49
45
  durations_histogram.observe(labels, duration)
50
46
  end
51
47
 
@@ -61,13 +57,7 @@ module Promenade
61
57
  registry.get(REQUEST_DURATION_HISTOGRAM_NAME)
62
58
  end
63
59
 
64
- def requests_counter
65
- registry.get(REQUESTS_COUNTER_NAME)
66
- end
67
-
68
60
  def register_metrics!
69
- registry.counter(REQUESTS_COUNTER_NAME,
70
- "A counter of the total number of HTTP requests made.")
71
61
  registry.histogram(REQUEST_DURATION_HISTOGRAM_NAME,
72
62
  "A histogram of the response latency.", {}, latency_buckets)
73
63
  registry.counter(EXCEPTIONS_COUNTER_NAME,
@@ -81,7 +71,6 @@ module Promenade
81
71
  def default_exception_handler
82
72
  ExceptionHandler.initialize_singleton(
83
73
  histogram_name: REQUEST_DURATION_HISTOGRAM_NAME,
84
- requests_counter_name: REQUESTS_COUNTER_NAME,
85
74
  exceptions_counter_name: EXCEPTIONS_COUNTER_NAME,
86
75
  registry: registry,
87
76
  )
@@ -0,0 +1,42 @@
1
+ require_relative "request_labeler"
2
+ module Promenade
3
+ module Client
4
+ module Rack
5
+ class RequestControllerActionLabeler < RequestLabeler
6
+ PARAMS_KEY = "action_dispatch.request.parameters".freeze
7
+
8
+ PATH_PARAMS_KEY = "action_dispatch.request.path_parameters".freeze
9
+
10
+ CONTROLLER = "controller".freeze
11
+
12
+ ACTION = "action".freeze
13
+
14
+ UNKNOWN = "unknown".freeze
15
+
16
+ SEPARATOR = "#".freeze
17
+
18
+ private_constant :PARAMS_KEY, :CONTROLLER, :ACTION, :UNKNOWN, :SEPARATOR
19
+
20
+ def call(env)
21
+ super.merge({
22
+ controller_action: controller_action_from_env(env),
23
+ })
24
+ end
25
+
26
+ private
27
+
28
+ def controller_action_from_env(env)
29
+ controller = env.dig(PARAMS_KEY, CONTROLLER) ||
30
+ env.dig(PATH_PARAMS_KEY, CONTROLLER.to_sym) ||
31
+ UNKNOWN
32
+
33
+ action = env.dig(PARAMS_KEY, ACTION) ||
34
+ env.dig(PATH_PARAMS_KEY, ACTION.to_sym) ||
35
+ UNKNOWN
36
+
37
+ [controller, action].join(SEPARATOR)
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -9,41 +9,14 @@ module Promenade
9
9
 
10
10
  HTTP_HOST = "HTTP_HOST".freeze
11
11
 
12
- PARAMS_KEY = "action_dispatch.request.parameters".freeze
13
-
14
- PATH_PARAMS_KEY = "action_dispatch.request.path_parameters".freeze
15
-
16
- CONTROLLER = "controller".freeze
17
-
18
- ACTION = "action".freeze
19
-
20
- UNKNOWN = "unknown".freeze
21
-
22
- SEPARATOR = "#".freeze
23
-
24
- private_constant :REQUEST_METHOD, :HTTP_HOST, :PARAMS_KEY, :CONTROLLER, :ACTION, :UNKNOWN, :SEPARATOR
12
+ private_constant :REQUEST_METHOD, :HTTP_HOST
25
13
 
26
14
  def call(env)
27
15
  {
28
16
  method: env[REQUEST_METHOD].to_s.downcase,
29
17
  host: env[HTTP_HOST].to_s,
30
- controller_action: controller_action_from_env(env),
31
18
  }
32
19
  end
33
-
34
- private
35
-
36
- def controller_action_from_env(env)
37
- controller = env.dig(PARAMS_KEY, CONTROLLER) ||
38
- env.dig(PATH_PARAMS_KEY, CONTROLLER.to_sym) ||
39
- UNKNOWN
40
-
41
- action = env.dig(PARAMS_KEY, ACTION) ||
42
- env.dig(PATH_PARAMS_KEY, ACTION.to_sym) ||
43
- UNKNOWN
44
-
45
- [controller, action].join(SEPARATOR)
46
- end
47
20
  end
48
21
  end
49
22
  end
@@ -1,3 +1,3 @@
1
1
  module Promenade
2
- VERSION = "0.6.0".freeze
2
+ VERSION = "0.7.0".freeze
3
3
  end
data/lib/promenade.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require "promenade/version"
2
2
  require "promenade/setup"
3
3
  require "promenade/configuration"
4
- require "promenade/railtie" if defined? ::Rails::Railtie
4
+ require "promenade/railtie" if defined? Rails::Railtie
5
5
  require "promenade/prometheus"
6
6
 
7
7
  module Promenade
data/promenade.gemspec CHANGED
@@ -2,7 +2,7 @@ lib = File.expand_path("lib", __dir__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
  require "promenade/version"
4
4
 
5
- Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
5
+ Gem::Specification.new do |spec|
6
6
  spec.name = "promenade"
7
7
  spec.version = Promenade::VERSION
8
8
  spec.authors = ["Ed Robinson"]
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
22
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
23
  spec.require_paths = ["lib"]
24
24
 
25
- spec.required_ruby_version = ">= 2.7", "< 3.2"
25
+ spec.required_ruby_version = ">= 2.7"
26
26
 
27
27
  spec.add_dependency "actionpack"
28
28
  spec.add_dependency "activesupport", "> 6.0", "< 8.0"
@@ -39,6 +39,7 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
39
39
  spec.add_development_dependency "rubocop"
40
40
  spec.add_development_dependency "rubocop-performance"
41
41
  spec.add_development_dependency "rubocop-rails"
42
+ spec.add_development_dependency "rubocop-rspec"
42
43
  spec.add_development_dependency "simplecov"
43
44
  spec.metadata["rubygems_mfa_required"] = "true"
44
45
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: promenade
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
  - Ed Robinson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-08-23 00:00:00.000000000 Z
11
+ date: 2023-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -232,6 +232,20 @@ dependencies:
232
232
  - - ">="
233
233
  - !ruby/object:Gem::Version
234
234
  version: '0'
235
+ - !ruby/object:Gem::Dependency
236
+ name: rubocop-rspec
237
+ requirement: !ruby/object:Gem::Requirement
238
+ requirements:
239
+ - - ">="
240
+ - !ruby/object:Gem::Version
241
+ version: '0'
242
+ type: :development
243
+ prerelease: false
244
+ version_requirements: !ruby/object:Gem::Requirement
245
+ requirements:
246
+ - - ">="
247
+ - !ruby/object:Gem::Version
248
+ version: '0'
235
249
  - !ruby/object:Gem::Dependency
236
250
  name: simplecov
237
251
  requirement: !ruby/object:Gem::Requirement
@@ -276,6 +290,7 @@ files:
276
290
  - lib/promenade/client/rack/http_request_queue_time_collector.rb
277
291
  - lib/promenade/client/rack/middleware_base.rb
278
292
  - lib/promenade/client/rack/queue_time_duration.rb
293
+ - lib/promenade/client/rack/request_controller_action_labeler.rb
279
294
  - lib/promenade/client/rack/request_labeler.rb
280
295
  - lib/promenade/client/rack/singleton_caller.rb
281
296
  - lib/promenade/configuration.rb
@@ -306,16 +321,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
306
321
  - - ">="
307
322
  - !ruby/object:Gem::Version
308
323
  version: '2.7'
309
- - - "<"
310
- - !ruby/object:Gem::Version
311
- version: '3.2'
312
324
  required_rubygems_version: !ruby/object:Gem::Requirement
313
325
  requirements:
314
326
  - - ">="
315
327
  - !ruby/object:Gem::Version
316
328
  version: '0'
317
329
  requirements: []
318
- rubygems_version: 3.3.18
330
+ rubygems_version: 3.3.7
319
331
  signing_key:
320
332
  specification_version: 4
321
333
  summary: Promenade makes it simple to instrument Ruby apps for prometheus scraping