promenade 0.12.18 → 0.12.20

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fb19b2faa9d9feb142950fd6993cf4f5029c7350ea0b7eff7999cc6abe8a3b6f
4
- data.tar.gz: fc43cb15080915fb2a220c84d702f72977ce54e74c2122a9b8448bc0c8672ae8
3
+ metadata.gz: 2a2056081ad03ba9f766fd80b8a8da7f1637c09377ed1117a69f834daff42653
4
+ data.tar.gz: ed3dc97c43d4220464d1f3bd715d741d1180bcd27826ed4eeeaa501c98883ee0
5
5
  SHA512:
6
- metadata.gz: 17d70f9a1e536b7785e253b0384dc9e0568f13d153a9e0183d58c7e35e9760b391dad9d364638a73298e6b24b567683830a694f2d72d9b61add77a0a0992f865
7
- data.tar.gz: 334906934de06f85123301f8e6add30f9580186ae5d41440f70913af0de9a9ea38d5355dd74984aa37595ecd83975837f297e6796d91577696e63ff9bdbbb2af
6
+ metadata.gz: 3f3fa432c8d7777a3570edf94ea835862ed2935d34294fe667b588c11962de9fc3a4d6554dbf21c0ee54bde79c18958d2df5e71b3056848aaf40f5e313890d4a
7
+ data.tar.gz: a65ee4010d62a27a3d12a0f6a40a8ca25daa9735b2c7fd26194fab2ba821f8c613d765ce94b9006fb61bf06b25af2c23ec1a6a609717cbe6f3fd892fff171acf
data/README.md CHANGED
@@ -6,25 +6,22 @@
6
6
 
7
7
  Promenade is a library to simplify instrumenting Ruby applications with Prometheus.
8
8
 
9
- It is currently under development.
10
-
11
9
  ## Usage
12
10
 
13
- Add promenade to your Gemfle:
11
+ Add promenade to your Gemfile:
14
12
 
15
- ```
13
+ ```ruby
16
14
  gem "promenade"
17
15
  ```
18
16
 
19
17
  ### Built in instrumentation
20
18
 
21
- Promenade includes some built in instrumentation that can be used by requiring it (for example in an initializer).
19
+ Promenade includes built-in instrumentation for several libraries. Require the relevant file in an initializer to enable it.
22
20
 
23
- Currently there is support for [ruby-kafka](https://github.com/zendesk/ruby-kafka), but I plan to support other things soon.
24
-
25
- ```
26
- # Instrument the ruby-kafka libary
27
- require "promenade/kafka"
21
+ ```ruby
22
+ require "promenade/kafka" # ruby-kafka
23
+ require "promenade/karafka" # Karafka consumers
24
+ require "promenade/waterdrop" # WaterDrop producers
28
25
  ```
29
26
 
30
27
  ### Instrumentation DSL
@@ -52,7 +49,7 @@ class WidgetService
52
49
  end
53
50
 
54
51
  def batch_create
55
- You can increment by more than 1 at a time if you need
52
+ # You can increment by more than 1 at a time if you need
56
53
  Promenade.metric(:widgets_created).increment({ type: "guinness" }, 100)
57
54
  end
58
55
  end
@@ -86,7 +83,7 @@ of all observed values.
86
83
  class Calculator
87
84
  Promenade.histogram :calculator_time_taken do
88
85
  doc "Records how long it takes to do the adding"
89
- # promenade also has some bucket presets like :network and :memory for common usecases
86
+ # promenade also has some bucket presets like :network and :memory for common use cases
90
87
  buckets [0.25, 0.5, 1, 2, 4]
91
88
  end
92
89
 
@@ -122,13 +119,32 @@ end
122
119
 
123
120
  ### Exporter
124
121
 
125
- Because promenade is based on prometheus-client you can add the `Prometheus::Client::Rack::Exporter` middleware to your rack middleware stack to expose metrics.
126
-
127
- There is also a stand alone exporter that can be run with the `promenade` command.
128
-
129
- This is ideal if you are worried about accidentally exposing your metrics, are concerned about the performance impact prometheus scrapes might have on your application, or for applications without a web server (like background processing jobs). It does mean that you have another process to manage on your server though 🤷.
122
+ The recommended way to expose metrics is the **Go exporter sidecar** in [`exporter/`](exporter/). It runs as a separate container that reads the `.db` files written by the Ruby application and exposes them at `:9394/metrics`. This keeps scrape overhead entirely off the Ruby application process and also collects TCP connection metrics (busy/queued workers) via Linux netlink without any native extension.
123
+
124
+ The exporter sidecar shares a network namespace and tmpfs volume with your app container. See [`compose.yml`](compose.yml) for a reference deployment:
125
+
126
+ ```yaml
127
+ services:
128
+ app:
129
+ # your Ruby app; writes metrics to tmp/promenade on the shared tmpfs
130
+ volumes:
131
+ - tmp:/app/tmp
132
+ environment:
133
+ PROMETHEUS_MULTIPROC_DIR: /app/tmp/promenade
134
+ exporter:
135
+ image: ghcr.io/errm/promenade:latest
136
+ network_mode: service:app # shares the app's network namespace
137
+ volumes:
138
+ - tmp:/app/tmp
139
+ volumes:
140
+ tmp:
141
+ driver: local
142
+ driver_opts:
143
+ type: tmpfs
144
+ device: tmpfs
145
+ ```
130
146
 
131
- The exporter runs by default on port `9394` and the metrics are available at the standard path of `/metrics`, the stand-alone exporter is configured to use gzip.
147
+ The exporter is configured with `--multiprocess-dir` (or `PROMETHEUS_MULTIPROC_DIR`) and `--metrics-port` (default `9394`).
132
148
 
133
149
 
134
150
  ### Rails Middleware
@@ -137,15 +153,18 @@ Promenade provides custom Rack middleware to track HTTP response times for reque
137
153
 
138
154
  This was originally inspired by [prometheus-client-mmap](https://gitlab.com/gitlab-org/prometheus-client-mmap/-/blob/master/lib/prometheus/client/rack/collector.rb).
139
155
 
140
- **This middleware is automatically added to your Rack stack if your application is a Ruby on Rails app.**
156
+ **The following middleware is automatically added to your Rack stack if your application is a Ruby on Rails app:**
141
157
 
142
- We recommend you add the middleware after `ActionDispatch::ShowExceptions` in your stack, so you can accurately record the controller and action where an exception was raised.
158
+ - `Promenade::Client::Rack::HTTPRequestQueueTimeCollector` inserted at the front of the stack, records time spent in the request queue (via `X-Request-Start` / `X-Queue-Start` headers).
159
+ - `Promenade::Client::Rack::HTTPRequestDurationCollector` — inserted after `ActionDispatch::ShowExceptions`, records response duration and HTTP exception counts.
160
+ - `Promenade::YJIT::Middleware` — appended, records YJIT stats (enabled only when `RubyVM::YJIT` is defined).
161
+ - `Promenade::Pitchfork::Middleware` — appended, records worker and memory metrics (enabled only when Pitchfork is present).
143
162
 
144
- If you want to change the position, or customise the labels and exception handling behaviour, simply remove the middleware from the stack and re-insert it with your own preferences.
163
+ If you want to change the position of `HTTPRequestDurationCollector`, or customise its labels and exception handling behaviour, simply remove it from the stack and re-insert it with your own preferences.
145
164
 
146
165
  ``` ruby
147
- Rails.application.middleware.delete(Promenade::Client::Rack::Collector)
148
- Rails.application.middleware.insert_after(Rails::Rack::Logger, Promenade::Client::Rack::Collector)
166
+ Rails.application.middleware.delete(Promenade::Client::Rack::HTTPRequestDurationCollector)
167
+ Rails.application.middleware.insert_after(Rails::Rack::Logger, Promenade::Client::Rack::HTTPRequestDurationCollector)
149
168
  ```
150
169
 
151
170
  #### Customising the labels recorded for each request
@@ -162,29 +181,29 @@ label_builder = Proc.new do |env|
162
181
  }
163
182
  end
164
183
  Rails.application.config.middleware.insert_after ActionDispatch::ShowExceptions,
165
- Promenade::Client::Rack::Collector
184
+ Promenade::Client::Rack::HTTPRequestDurationCollector,
166
185
  label_builder: label_builder
167
186
  ```
168
187
 
169
188
  #### Customising how the middleware handles exceptions
170
189
 
171
- The default implementation will capture exceptions, count the execption class name (e.g. `"StandardError"`), and then re-raise the exception.
190
+ The default implementation will capture exceptions, count the exception class name (e.g. `"StandardError"`), and then re-raise the exception.
172
191
 
173
192
  If you would like to customise this behaviour, you may do so by customising the middleware installation:
174
193
 
175
194
  ``` ruby
176
- exception_handler = Proc.new do |exception, exception_counter, env_hash, request_duration_seconds|
177
- # This simple example just re-raises the execption
195
+ exception_handler = Proc.new do |exception, env_hash, duration|
196
+ # This simple example just re-raises the exception
178
197
  raise exception
179
198
  end
180
199
  Rails.application.config.middleware.insert_after ActionDispatch::ShowExceptions,
181
- Promenade::Client::Rack::Collector
200
+ Promenade::Client::Rack::HTTPRequestDurationCollector,
182
201
  exception_handler: exception_handler
183
202
  ```
184
203
 
185
204
  #### Customising the histogram buckets
186
205
 
187
- The default buckets cover a range of latencies from 5 ms to 10s see [Promenade::Configuration::DEFAULT_RACK_LATENCY_BUCKETS](https://github.com/errm/promenade/blob/ea7eb54c04257770a601b7e28b3e13db5d2430bb/lib/promenade/configuration.rb#L5). This is intended to capture the typical range of latencies for a web application. However, this might not be suitable for your Service-Level Agreements (SLAs), and other bucket size intervals may be required (see [histogram bins](https://en.wikipedia.org/wiki/Histogram#Number_of_bins_and_width)).
206
+ The default buckets cover a range of latencies from 5 ms to 10s see [Promenade::Configuration::DEFAULT_RACK_LATENCY_BUCKETS](https://github.com/errm/promenade/blob/master/lib/promenade/configuration.rb#L5) and [Promenade::Configuration::DEFAULT_QUEUE_TIME_BUCKETS](https://github.com/errm/promenade/blob/master/lib/promenade/configuration.rb#L7). This is intended to capture the typical range of latencies for a web application. However, this might not be suitable for your Service-Level Agreements (SLAs), and other bucket size intervals may be required (see [histogram bins](https://en.wikipedia.org/wiki/Histogram#Number_of_bins_and_width)).
188
207
 
189
208
  If you would like to customise the histogram buckets, you can do so by configuring Promenade in an initializer:
190
209
 
@@ -192,21 +211,21 @@ If you would like to customise the histogram buckets, you can do so by configuri
192
211
  # config/initializers/promenade.rb
193
212
 
194
213
  Promenade.configure do |config|
195
- config.rack_latency_buckets = [0.25, 0.350, 0.5, 1, 1.5, 2.5, 5, 10, 15, 19]
214
+ config.rack_latency_buckets = [0.1, 0.25, 0.5, 1, 2.5, 5, 10]
215
+ config.queue_time_buckets = [0.01, 0.5, 1.0, 10.0, 30.0] # optional, for queue time collector
196
216
  end
197
217
  ```
198
218
 
199
219
  ### Configuration
200
220
 
201
- If you are using rails it should load a railtie and configure promenade.
221
+ If you are using Rails it should load a railtie and configure promenade.
202
222
 
203
- If are not using rails you should call `Promenade.setup` after your environment has loaded.
223
+ If you are not using Rails you should call `Promenade.setup` after your environment has loaded.
204
224
 
205
225
  In a typical development environment there should be nothing for you to do. Promenade stores its state files in `tmp/promenade` and will create that directory if it does not exist.
206
226
 
207
227
  In a production environment you should try to store the state files on tmpfs for performance, you can configure the path that promenade will write to by setting the `PROMETHEUS_MULTIPROC_DIR` environment variable.
208
228
 
209
- If you are running the stand-alone exporter, you may also set the `PORT` environment variable to bind to a port other than the default (`9394`).
210
229
 
211
230
  ## Development
212
231
 
@@ -218,8 +237,6 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
218
237
 
219
238
  Bug reports and pull requests are welcome on GitHub at https://github.com/errm/promenade.
220
239
 
221
- This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
222
-
223
240
  ## Acknowledgements
224
241
 
225
242
  The original code for the Rack middleware collector class was copied from [Prometheus Client MMap](https://gitlab.com/gitlab-org/prometheus-client-mmap/-/blob/master/lib/prometheus/client/rack/collector.rb).
@@ -227,7 +244,3 @@ The original code for the Rack middleware collector class was copied from [Prome
227
244
  ## License
228
245
 
229
246
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
230
-
231
- ## Code of Conduct
232
-
233
- Everyone interacting in the Promenade project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/promenade/blob/master/CODE_OF_CONDUCT.md).
@@ -1,3 +1,3 @@
1
1
  module Promenade
2
- VERSION = "0.12.18".freeze
2
+ VERSION = "0.12.20".freeze
3
3
  end
data/promenade.gemspec CHANGED
@@ -31,6 +31,7 @@ Gem::Specification.new do |spec|
31
31
  spec.add_development_dependency "rake"
32
32
  spec.add_development_dependency "rspec", "~> 3.13"
33
33
  spec.add_development_dependency "rspec-rails", "~> 8.0"
34
+ spec.add_development_dependency "rspec-wait"
34
35
  spec.add_development_dependency "rubocop"
35
36
  spec.add_development_dependency "rubocop-performance"
36
37
  spec.add_development_dependency "rubocop-rails"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: promenade
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.18
4
+ version: 0.12.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ed Robinson
@@ -161,6 +161,20 @@ dependencies:
161
161
  - - "~>"
162
162
  - !ruby/object:Gem::Version
163
163
  version: '8.0'
164
+ - !ruby/object:Gem::Dependency
165
+ name: rspec-wait
166
+ requirement: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ version: '0'
171
+ type: :development
172
+ prerelease: false
173
+ version_requirements: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
164
178
  - !ruby/object:Gem::Dependency
165
179
  name: rubocop
166
180
  requirement: !ruby/object:Gem::Requirement