rails_pod_kit 0.0.1 → 0.0.3
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 +4 -4
- data/README.md +21 -5
- data/VERSION +1 -1
- data/lib/rails_pod_kit/health.rb +12 -6
- data/lib/rails_pod_kit/puma.rb +4 -2
- data/lib/rails_pod_kit.rb +13 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 24c0e428faf1a3c46646a1d7a0e693b5cde8373f6aea61f9dc005d6b6dcba192
|
|
4
|
+
data.tar.gz: 968fc08545c75f5b22f91c2c882068b20069d7bb2bb6f48d1abf2aa09f4bc71b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 266b27abb0911f031e54522dfcea870d603e1ec143465b4441a206590654087c1604a9aeb4438745bc10600bf3696b7d4938c0c936e0145322b76cb0279a5513
|
|
7
|
+
data.tar.gz: dedc4665fb51d38b9e713caead650ee875108aed4a24e9f27bb3053f2ec0152bdcc0f3840cc0ac76056858f330b723c502bc5f66d726261db47a7033e6ae2142
|
data/README.md
CHANGED
|
@@ -8,7 +8,7 @@ packaged behind a single, opinionated entry point:
|
|
|
8
8
|
worker (Sidekiq) processes — no sidecar, no separate collector process. A
|
|
9
9
|
metrics agent (e.g. the Datadog Agent via OpenMetrics autodiscovery) scrapes
|
|
10
10
|
the pod directly.
|
|
11
|
-
- **Health checks** on `/healthz` (database, cache, Redis
|
|
11
|
+
- **Health checks** on `/healthz` (database, cache, optionally Redis and Sidekiq),
|
|
12
12
|
wired for Kubernetes startup/liveness/readiness probes — a thin, opinionated
|
|
13
13
|
wrapper around [health-monitor-rails](https://github.com/lbeder/health-monitor-rails).
|
|
14
14
|
|
|
@@ -90,8 +90,10 @@ no initializers.
|
|
|
90
90
|
|
|
91
91
|
`Health.install!` configures health-monitor-rails with the kit's defaults:
|
|
92
92
|
endpoint at `/healthz`, checking **database** (health_monitor's default),
|
|
93
|
-
**cache**,
|
|
94
|
-
|
|
93
|
+
**cache**, — when a `redis:` connection is given — **Redis** (connection
|
|
94
|
+
injected by the host) and — when a `sidekiq:` thresholds hash is given —
|
|
95
|
+
**Sidekiq**. Omit `redis:` on hosts with no Redis dependency (e.g. a Solid
|
|
96
|
+
Queue stack) to get a database + cache only endpoint. The gem's Railtie mounts
|
|
95
97
|
`HealthMonitor::Engine` at `/` automatically; pass `mount: false` to keep
|
|
96
98
|
route ownership (custom mount point, constraints) and mount it yourself in
|
|
97
99
|
`config/routes.rb`. Any further tuning goes through the optional block, which
|
|
@@ -99,7 +101,9 @@ receives the `HealthMonitor` configuration.
|
|
|
99
101
|
|
|
100
102
|
```ruby
|
|
101
103
|
RailsPodKit::Health.install!(
|
|
102
|
-
redis: { url: ENV['REDIS_URL'] }, #
|
|
104
|
+
redis: { url: ENV['REDIS_URL'] }, # optional: a ready Redis/ConnectionPool
|
|
105
|
+
# object or options hash; omit for no
|
|
106
|
+
# Redis provider
|
|
103
107
|
path: :healthz, # default
|
|
104
108
|
sidekiq: { queue_size: 200, latency: 10.minutes }
|
|
105
109
|
) do |config|
|
|
@@ -107,6 +111,13 @@ RailsPodKit::Health.install!(
|
|
|
107
111
|
end
|
|
108
112
|
```
|
|
109
113
|
|
|
114
|
+
Without a `redis:` argument the endpoint checks only database and cache
|
|
115
|
+
(plus Sidekiq when its thresholds are given):
|
|
116
|
+
|
|
117
|
+
```ruby
|
|
118
|
+
RailsPodKit::Health.install!(path: :healthz) # database + cache only
|
|
119
|
+
```
|
|
120
|
+
|
|
110
121
|
Probe wiring on Kubernetes:
|
|
111
122
|
|
|
112
123
|
- **startup probe** → `/healthz` — the full check, so the pod doesn't go ready
|
|
@@ -321,7 +332,12 @@ Booting the full host app just to read a handful of Redis counters would cost
|
|
|
321
332
|
require only the config core, so the Rails-free exporter stays
|
|
322
333
|
railties-free and a `puma -C config/puma.rb` boot (which evaluates
|
|
323
334
|
`config/puma.rb` before Rails) still gets the integrations once
|
|
324
|
-
`Bundler.require` runs.
|
|
335
|
+
`Bundler.require` runs. The main file also loads the yabeda-prometheus-mmap
|
|
336
|
+
adapter at require time — before any host initializer runs — so host
|
|
337
|
+
initializers may declare Yabeda metrics (yabeda-rails, yabeda-activejob, a
|
|
338
|
+
custom collector) safely: the adapter registers itself while no metric exists
|
|
339
|
+
yet, regardless of whether the app boots via `bin/rails server` or
|
|
340
|
+
`puma -C config/puma.rb`.
|
|
325
341
|
|
|
326
342
|
## Local verification
|
|
327
343
|
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.0.
|
|
1
|
+
0.0.3
|
data/lib/rails_pod_kit/health.rb
CHANGED
|
@@ -21,7 +21,7 @@ module RailsPodKit
|
|
|
21
21
|
# )
|
|
22
22
|
#
|
|
23
23
|
# gives the app a /healthz endpoint checking database (health_monitor's
|
|
24
|
-
# default), cache
|
|
24
|
+
# default), cache and (optionally) Redis and Sidekiq — suitable as a k8s startup
|
|
25
25
|
# probe. For liveness/readiness, probe `/healthz?providers[]=none` to
|
|
26
26
|
# short-circuit the dependency checks once the pod is live, so a transient
|
|
27
27
|
# Redis hiccup doesn't restart the app. Same trick for a manual basic check:
|
|
@@ -35,8 +35,11 @@ module RailsPodKit
|
|
|
35
35
|
|
|
36
36
|
# Configures HealthMonitor with the kit's defaults.
|
|
37
37
|
#
|
|
38
|
-
# redis: Redis connection options hash (same shape the host
|
|
39
|
-
# Sidekiq) or a ready connection object (Redis /
|
|
38
|
+
# redis: optional Redis connection options hash (same shape the host
|
|
39
|
+
# passes to Sidekiq) or a ready connection object (Redis /
|
|
40
|
+
# ConnectionPool); when given the Redis provider is added. Omit
|
|
41
|
+
# entirely (or pass nil) on hosts with no Redis dependency to get
|
|
42
|
+
# a database + cache only endpoint.
|
|
40
43
|
# path: mount-relative endpoint path (default :healthz).
|
|
41
44
|
# sidekiq: optional thresholds hash; when given the Sidekiq provider is
|
|
42
45
|
# added with the provided `queue_size:` / `latency:` overrides
|
|
@@ -51,14 +54,17 @@ module RailsPodKit
|
|
|
51
54
|
#
|
|
52
55
|
# Any further host-specific tuning (extra providers, error callback, …) can
|
|
53
56
|
# be done in the block, which receives the HealthMonitor configuration.
|
|
54
|
-
def install!(redis
|
|
57
|
+
def install!(redis: nil, path: :healthz, sidekiq: nil, silence_controller_log: true, mount: true)
|
|
55
58
|
@auto_mount = mount
|
|
56
59
|
|
|
57
60
|
HealthMonitor.configure do |config|
|
|
58
61
|
config.path = path
|
|
59
62
|
config.cache
|
|
60
|
-
|
|
61
|
-
|
|
63
|
+
|
|
64
|
+
if redis
|
|
65
|
+
config.redis.configure do |redis_config|
|
|
66
|
+
redis_config.connection = build_connection(redis)
|
|
67
|
+
end
|
|
62
68
|
end
|
|
63
69
|
|
|
64
70
|
if sidekiq
|
data/lib/rails_pod_kit/puma.rb
CHANGED
|
@@ -29,8 +29,10 @@ module RailsPodKit
|
|
|
29
29
|
|
|
30
30
|
# The Puma plugin only pulls in the exporter class; we must also load the
|
|
31
31
|
# full mmap module so `Yabeda::Prometheus::Mmap.registry` exists and the
|
|
32
|
-
# mmap adapter is registered
|
|
33
|
-
#
|
|
32
|
+
# mmap adapter is registered. The gem's main entry (lib/rails_pod_kit.rb)
|
|
33
|
+
# already loaded it at Bundler.require, so this is normally a no-op — it
|
|
34
|
+
# matters only under `puma -C config/puma.rb`, where config/puma.rb runs
|
|
35
|
+
# before Rails and thus before the main entry, so this is the first require.
|
|
34
36
|
require 'yabeda/prometheus/mmap'
|
|
35
37
|
|
|
36
38
|
# The control app exposes Puma's /stats over a localhost-only socket that
|
data/lib/rails_pod_kit.rb
CHANGED
|
@@ -43,6 +43,19 @@ require 'rails_pod_kit/config'
|
|
|
43
43
|
# - under `puma -C config/puma.rb` — where Puma evaluates config/puma.rb
|
|
44
44
|
# (and thus rails_pod_kit/puma) before Rails exists — this file is still
|
|
45
45
|
# fresh for Bundler.require, so the integrations load once Rails is up.
|
|
46
|
+
|
|
47
|
+
# Load the mmap adapter here — at Bundler.require, before any host initializer
|
|
48
|
+
# runs — so its self-registration (`Yabeda.register_adapter` at require time)
|
|
49
|
+
# happens while no Yabeda metric exists yet, making it a no-op. The adapter's
|
|
50
|
+
# own `mmap.rb` requires the adapter *before* defining
|
|
51
|
+
# `Yabeda::Prometheus::Mmap.registry`; if a metric is already declared when the
|
|
52
|
+
# adapter loads, registration eagerly reaches for that not-yet-defined method
|
|
53
|
+
# and boots crash with a NoMethodError. Under `bin/rails server` Rails boots
|
|
54
|
+
# (and its initializers may declare metrics) before config/puma.rb requires the
|
|
55
|
+
# adapter, so loading it here is what makes the order-of-boot irrelevant. The
|
|
56
|
+
# lazy require in RailsPodKit::Puma.activate then degrades to a cheap no-op.
|
|
57
|
+
require 'yabeda/prometheus/mmap'
|
|
58
|
+
|
|
46
59
|
require 'rails_pod_kit/sidekiq'
|
|
47
60
|
require 'rails_pod_kit/health'
|
|
48
61
|
require 'rails_pod_kit/railtie'
|