healthier 0.2.5 → 0.2.6

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: 5f347f1274991b95aa7403f00501e5fc901d48ac74c9d6d6ae44c68a5ee7bdc6
4
- data.tar.gz: c8f8f1b4fca3b876d3ab3d134f14bc5e46514f45211d7df81a22b8202f3872df
3
+ metadata.gz: 5e6a626dfbc755b31c1c191d4d1769b76dbff70d9a6cc4e508372a6382811c1d
4
+ data.tar.gz: 557493b89ebff0f2a4937099bc44636c79145ecc1cffecb35b3b0ac17682781a
5
5
  SHA512:
6
- metadata.gz: ce524e72bfe8aec9444c0602d7488362047d0b0bb33e674e922f8398e942a626113b4241eed3647c820b1ddba1ecedcf2e3611698d936c91c38f5399c6840b4d
7
- data.tar.gz: d07d6415672d8e0c28865813d29a8ef959aace1a0491a6c439ede5c283856a0f5c25aace7cf2955184a195dc633f247dfc531d34204705a3a35aa5a26aa640e6
6
+ metadata.gz: f3834cfb189398d1682488e381b47707d97e0108afd84d02e604c514ffec9f4d0147acc97aa13a38d950800f6c278cd41df4c421fb0f0bcf0a46321f7ce4e0cc
7
+ data.tar.gz: 7897bc199ef73f63c13e0ab1cc7f0a56479d951652b99cb51d553cac3094f4f677bca6d5a6e1175890b4fbfbfc408f06dca6a11bf6d7a98854694e40ea97d200
data/README.md CHANGED
@@ -125,6 +125,271 @@ Readiness check that verifies if all configured services are healthy and the app
125
125
  true
126
126
  ```
127
127
 
128
+ ## Connectors
129
+
130
+ Healthier uses connectors to check the health of various backing services. Connectors are Ruby classes that implement a simple interface to test connectivity and health of external services.
131
+
132
+ ### Available Connectors
133
+
134
+ #### PostgreSQL (`Connectors::Postgresql`)
135
+
136
+ Checks the health of PostgreSQL database connections using ActiveRecord.
137
+
138
+ **How it works:**
139
+ - Uses `ActiveRecord::Base.connection` to establish a connection
140
+ - Returns `true` if connection succeeds, `false` on connection errors
141
+ - Automatically closes connections after checking
142
+
143
+ **Configuration:**
144
+ - Uses Rails database configuration from `config/database.yml`
145
+ - No additional configuration needed if using ActiveRecord
146
+
147
+ **Example:**
148
+ ```yaml
149
+ healthier:
150
+ depends_on:
151
+ - name: 'postgresql'
152
+ config: {}
153
+ ```
154
+
155
+ #### MongoDB (`Connectors::Mongodb`)
156
+
157
+ Checks the health of MongoDB connections using the `mongo` gem.
158
+
159
+ **How it works:**
160
+ - Creates a MongoDB client connection
161
+ - Executes a `ping` command to verify connectivity
162
+ - Closes the connection after checking
163
+
164
+ **Configuration:**
165
+ - Uses `MONGO_DB_URI` environment variable (defaults to `localhost:27017`)
166
+ - Requires the `mongo` gem to be installed
167
+
168
+ **Example:**
169
+ ```yaml
170
+ healthier:
171
+ depends_on:
172
+ - name: 'mongodb'
173
+ config: {}
174
+ ```
175
+
176
+ **Environment Variable:**
177
+ ```bash
178
+ MONGO_DB_URI=mongodb://localhost:27017
179
+ ```
180
+
181
+ #### Redis (`Connectors::Redis`)
182
+
183
+ Checks the health of Redis connections using the `redis` gem.
184
+
185
+ **How it works:**
186
+ - Creates a Redis client connection
187
+ - Executes a `PING` command and verifies `PONG` response
188
+ - Closes the connection after checking
189
+
190
+ **Configuration:**
191
+ - Uses default Redis connection settings (`localhost:6379`)
192
+ - Requires the `redis` gem to be installed
193
+
194
+ **Example:**
195
+ ```yaml
196
+ healthier:
197
+ depends_on:
198
+ - name: 'redis'
199
+ config: {}
200
+ ```
201
+
202
+ #### RabbitMQ (`Connectors::Rabbitmq`)
203
+
204
+ Checks the health of RabbitMQ message broker using the `bunny` gem.
205
+
206
+ **How it works:**
207
+ - Establishes a connection to RabbitMQ
208
+ - Creates a temporary queue with `auto_delete: true`
209
+ - Publishes a test message to verify functionality
210
+ - Cleans up the queue and closes connections after checking
211
+
212
+ **Configuration:**
213
+ - Uses default RabbitMQ connection settings
214
+ - Requires the `bunny` gem to be installed
215
+
216
+ **Example:**
217
+ ```yaml
218
+ healthier:
219
+ depends_on:
220
+ - name: 'rabbitmq'
221
+ config: {}
222
+ ```
223
+
224
+ #### Sidekiq (`Connectors::Sidekiq`)
225
+
226
+ Checks the health of Sidekiq background job processor by verifying Redis connectivity.
227
+
228
+ **How it works:**
229
+ - Uses `Sidekiq.redis` to access the Redis connection pool
230
+ - Executes a `PING` command through Sidekiq's Redis connection
231
+ - Verifies `PONG` response
232
+
233
+ **Configuration:**
234
+ - Requires Sidekiq to be configured with Redis
235
+ - Requires the `sidekiq` gem to be installed
236
+ - Sidekiq must be properly initialized in your Rails app
237
+
238
+ **Example:**
239
+ ```yaml
240
+ healthier:
241
+ depends_on:
242
+ - name: 'sidekiq'
243
+ config: {}
244
+ ```
245
+
246
+ #### ElasticSearch (`Connectors::ElasticSearch`)
247
+
248
+ Checks the health of ElasticSearch cluster using HTTP requests.
249
+
250
+ **How it works:**
251
+ - Makes an HTTP GET request to `/_cluster/health` endpoint
252
+ - Parses the JSON response
253
+ - Returns `true` if cluster status is not "red"
254
+ - Uses direct HTTP instead of the Elasticsearch gem to avoid verification issues
255
+
256
+ **Configuration:**
257
+ - Uses `ELASTICSEARCH_URL` environment variable (defaults to `http://localhost:9200`)
258
+ - No gem required (uses standard library `net/http`)
259
+
260
+ **Example:**
261
+ ```yaml
262
+ healthier:
263
+ depends_on:
264
+ - name: 'elastic_search'
265
+ config: {}
266
+ ```
267
+
268
+ **Environment Variable:**
269
+ ```bash
270
+ ELASTICSEARCH_URL=http://localhost:9200
271
+ ```
272
+
273
+ ### Creating Custom Connectors
274
+
275
+ You can create custom connectors to monitor any service. A connector must:
276
+
277
+ 1. Be placed in the `Connectors` module
278
+ 2. Implement a `connect` method that returns `true` (healthy) or `false` (unhealthy)
279
+ 3. Implement a `configured?` class method that validates required dependencies
280
+
281
+ #### Connector Template
282
+
283
+ ```ruby
284
+ # frozen_string_literal: true
285
+
286
+ module Connectors
287
+ # YourService health checker
288
+ class YourService
289
+ def connect
290
+ # Your connection logic here
291
+ # Return true if healthy, false if unhealthy
292
+ begin
293
+ # Test connection
294
+ client = YourService::Client.new
295
+ client.ping
296
+ true
297
+ rescue StandardError => e
298
+ puts "YourService Connection Error: #{e.message}"
299
+ false
300
+ ensure
301
+ # Clean up resources if needed
302
+ client&.close
303
+ end
304
+ end
305
+
306
+ def self.configured?
307
+ # Validate that required gem/class is available
308
+ raise StandardError, 'Please make sure you have YourService installed' unless defined?(::YourService::Client)
309
+
310
+ 'configured'
311
+ end
312
+ end
313
+ end
314
+ ```
315
+
316
+ #### Steps to Add a New Connector
317
+
318
+ 1. **Create the connector file:**
319
+
320
+ Create `lib/connectors/your_service.rb`:
321
+
322
+ ```ruby
323
+ # frozen_string_literal: true
324
+
325
+ module Connectors
326
+ class YourService
327
+ def connect
328
+ # Implementation here
329
+ true
330
+ end
331
+
332
+ def self.configured?
333
+ raise StandardError, 'Please install your_service gem' unless defined?(::YourService)
334
+ 'configured'
335
+ end
336
+ end
337
+ end
338
+ ```
339
+
340
+ 2. **Require the connector in the engine:**
341
+
342
+ Add to `lib/healthier/engine.rb`:
343
+
344
+ ```ruby
345
+ require_relative '../connectors/your_service'
346
+ ```
347
+
348
+ 3. **Add to your configuration:**
349
+
350
+ Update `config/healthier.yml`:
351
+
352
+ ```yaml
353
+ healthier:
354
+ depends_on:
355
+ - name: 'your_service'
356
+ config: {}
357
+ ```
358
+
359
+ 4. **Test your connector:**
360
+
361
+ ```bash
362
+ curl -u username:password http://localhost:3000/healthier/ping
363
+ ```
364
+
365
+ #### Custom Checker Methods
366
+
367
+ You can also use custom checker methods instead of the default `connect` method:
368
+
369
+ ```yaml
370
+ healthier:
371
+ depends_on:
372
+ - name: 'sidekiq'
373
+ custom_checker: 'check_redis_connection' # Calls Sidekiq.check_redis_connection
374
+ ```
375
+
376
+ Or use a Proc/lambda:
377
+
378
+ ```ruby
379
+ Healthier.setup do |config|
380
+ config.depends_on = {
381
+ 'healthier' => {
382
+ 'depends_on' => [
383
+ {
384
+ 'name' => 'custom_service',
385
+ 'custom_checker' => -> { CustomService.health_check }
386
+ }
387
+ ]
388
+ }
389
+ }
390
+ end
391
+ ```
392
+
128
393
  ## Example Usage
129
394
 
130
395
  ```bash
@@ -143,6 +408,107 @@ Example Curl with authentication:
143
408
  curl -H "Bearer your_token_here" -H "Content-Type: application/json" 'http://localhost:3000/healthier/ping'
144
409
  ```
145
410
 
411
+ ## Demo Application
412
+
413
+ A complete demo Rails application is included in `examples/healthier` to help you understand how to integrate and test Healthier in your own applications.
414
+
415
+ ### What's Included
416
+
417
+ The demo application showcases:
418
+ - Integration with all 6 built-in connectors (PostgreSQL, MongoDB, Redis, RabbitMQ, Sidekiq, ElasticSearch)
419
+ - Docker Compose setup for all backing services
420
+ - Basic authentication configuration
421
+ - Complete setup and testing instructions
422
+
423
+ ### Quick Start with the Demo
424
+
425
+ 1. **Navigate to the demo directory:**
426
+ ```bash
427
+ cd examples/healthier
428
+ ```
429
+
430
+ 2. **Install dependencies:**
431
+ ```bash
432
+ bundle install
433
+ ```
434
+
435
+ 3. **Start backing services:**
436
+ ```bash
437
+ docker-compose up -d
438
+ ```
439
+
440
+ Wait for services to be healthy (30-60 seconds):
441
+ ```bash
442
+ docker-compose ps
443
+ ```
444
+
445
+ 4. **Set environment variables:**
446
+ ```bash
447
+ export HEALTHIER_USERNAME=demouser
448
+ export HEALTHIER_PASSWORD=demouser@2023
449
+ ```
450
+
451
+ 5. **Setup database:**
452
+ ```bash
453
+ rails db:create db:migrate
454
+ ```
455
+
456
+ 6. **Start the Rails server:**
457
+ ```bash
458
+ rails server
459
+ ```
460
+
461
+ 7. **Test the endpoints:**
462
+ ```bash
463
+ # Live endpoint (no auth required)
464
+ curl http://localhost:3000/healthier/live
465
+
466
+ # Ready endpoint (requires auth)
467
+ curl -u demouser:demouser@2023 http://localhost:3000/healthier/ready
468
+
469
+ # Ping endpoint (requires auth)
470
+ curl -u demouser:demouser@2023 http://localhost:3000/healthier/ping
471
+ ```
472
+
473
+ ### What You Can Learn from the Demo
474
+
475
+ - **Configuration:** See how to configure `healthier.yml` with multiple services
476
+ - **Authentication:** Learn how to set up basic authentication
477
+ - **Docker Setup:** Understand how to run all backing services with Docker Compose
478
+ - **Testing:** See examples of testing all three endpoints
479
+ - **Integration:** Understand how to mount the Healthier engine in your routes
480
+
481
+ ### Demo App Structure
482
+
483
+ ```
484
+ examples/healthier/
485
+ ├── config/
486
+ │ ├── healthier.yml # Healthier configuration
487
+ │ ├── initializers/
488
+ │ │ ├── healthier.rb # Healthier setup
489
+ │ │ └── sidekiq.rb # Sidekiq configuration
490
+ │ └── routes.rb # Mounts Healthier engine
491
+ ├── docker-compose.yml # All backing services
492
+ ├── Gemfile # Includes healthier gem
493
+ └── README.md # Detailed demo instructions
494
+ ```
495
+
496
+ ### Using the Demo as a Reference
497
+
498
+ The demo application serves as a complete reference implementation. You can:
499
+
500
+ 1. **Copy configuration files** to your application:
501
+ - `config/healthier.yml` - Service configuration
502
+ - `config/initializers/healthier.rb` - Initializer setup
503
+
504
+ 2. **Reference Docker Compose setup** for running services locally
505
+
506
+ 3. **Use as a testing environment** to verify connector functionality
507
+
508
+ 4. **Study the integration** to understand how to mount and use Healthier in your app
509
+
510
+ For detailed instructions, see [`examples/healthier/README.md`](examples/healthier/README.md).
511
+
146
512
  ## Contributing
147
513
 
148
514
  Contribution directions go here.
@@ -5,7 +5,7 @@ module Healthier
5
5
  class HealthierController < ApplicationController
6
6
  include ActionController::HttpAuthentication::Basic::ControllerMethods
7
7
 
8
- before_action :authenticate_request, except: [:live]
8
+ before_action :authenticate_request, except: [:live, :ping]
9
9
 
10
10
  def ping
11
11
  render json: Healthier::Doctor.ping!
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Healthier
4
4
  # MAJOR.MINOR.PATCH
5
- VERSION = '0.2.5'
5
+ VERSION = '0.2.6'
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: healthier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nima Yonten
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-12-09 00:00:00.000000000 Z
11
+ date: 2026-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails