rx-healthcheck 0.1.8 → 0.1.9

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: 3ca68e3e5241e5baf4b9b2454ece5f8cc87889f018ac31dfdb8e2243d58107da
4
- data.tar.gz: eda14ecb4304cb18e4b95f2f0431d23b14c119c1b95e25622711cf5aa193019a
3
+ metadata.gz: ebf9af8d3b43d1640503ddcba7138d1ef6c04f298faa09b39c8d93fcb0d4eb50
4
+ data.tar.gz: e22f89c795207f5a3a78bb6f63c362624e6b4104e3834f6ca928ecb1c6fd5b79
5
5
  SHA512:
6
- metadata.gz: f59ce880cd0cba664a0705b76393bdefa84a7b91e595c001b9d59bc0161be13b32d5736ffd57db204c495f2537045cc23932c0bebb51c13b94081664111fbd7b
7
- data.tar.gz: d333264758d8233c45b397cda440528a24474a2000b0ddb9950dbf87feb81444c464015e1d7aa27f241efabec21b37b231518b57fb1f3fe0fc05fc53b6c8cb12
6
+ metadata.gz: a194f56c544904474062a866aa7c91cfe6de9548b97802beaa448b4b082dab4c1fc3ffa7f41e3c0aa14b8f94c11d518e586d6984f1a82cbfaf0d2479abc9ce06
7
+ data.tar.gz: 1fc1ea21c9586cb3583d25ab7c8ab7177d0789ec085cc4de316dd136ebeb3c03872f30c2b54293c2efd254ea5ebae6d0255d86816488020a584e7c1b8c8b39f9
data/Gemfile.lock CHANGED
@@ -17,6 +17,7 @@ GEM
17
17
  simplecov_json_formatter (0.1.3)
18
18
 
19
19
  PLATFORMS
20
+ ruby
20
21
  x86_64-linux
21
22
 
22
23
  DEPENDENCIES
data/README.md CHANGED
@@ -59,6 +59,28 @@ deep_secondary: []
59
59
 
60
60
  Each collection must contain 0 or more `Rx::Check` objects. Those checks will be performed when the health check is queried. Deep checks will always also run the readiness checks.
61
61
 
62
+ ### Cache
63
+
64
+ For deep health checks Rx by default will use an in-memory cache. While this is useful when running in production, during testing it could lead to unexpected results.
65
+ You can disable the in-memory cache by setting the cache key false in the options hash.
66
+
67
+ ```ruby
68
+ Rails.application.config.middleware.insert(
69
+ Rx::Middleware,
70
+ liveness: [Rx::Check::FileSystemCheck.new],
71
+ readiness: [
72
+ Rx::Check::FileSystemCheck.new,
73
+ Rx::Check::ActiveRecordCheck.new,
74
+ Rx::Check::HttpCheck.new("http://example.com"),
75
+ Rx::Check::GenericCheck.new(-> { $redis.ping == "PONG" }, "redis")],
76
+ deep_critical: [Rx::Check::HttpCheck.new("http://criticalservice.com/health")],
77
+ deep_secondary: [Rx::Check::HttpCheck.new("http://otherservice.com/health-check")],
78
+ options: {
79
+ cache: false
80
+ }
81
+ )
82
+ ```
83
+
62
84
  ### Deep end-point authorization
63
85
 
64
86
  It is considered as a good practice to protect the deep checks with a GUID to mitigate DDOS attacks. Hence you have 2 options to enable this. One is to use the `default_authorization` by passing the token to the authorization inside options hash, which you can use in a request with the authorization_token in the header of it. The other option would be to pass a lambda with an env argument (this gives you access to hash of request data) and have your own `custom_authorization`:
@@ -2,7 +2,7 @@ require_relative "../util/heap"
2
2
 
3
3
  module Rx
4
4
  module Cache
5
- class InMemoryCache
5
+ class LRUCache
6
6
  def initialize
7
7
  @heap = Rx::Util::Heap.new do |a, b|
8
8
  a[1] < b[1]
@@ -0,0 +1,45 @@
1
+ require "thread"
2
+
3
+ module Rx
4
+ module Cache
5
+ class MapCache
6
+ def initialize
7
+ @data = {}
8
+ @lock = Mutex.new
9
+ end
10
+
11
+ def cache(k, expires_in = 60)
12
+ unless (value = get(k)).nil?
13
+ return value
14
+ end
15
+
16
+ value = yield
17
+ put(k, value, expires_in)
18
+ value
19
+ end
20
+
21
+ def get(k)
22
+ lock.synchronize do
23
+ value = data[k]
24
+ return nil unless value
25
+
26
+ if value[1] < Time.now
27
+ data.delete(k)
28
+ return nil
29
+ end
30
+
31
+ value[0]
32
+ end
33
+ end
34
+
35
+ def put(k, v, expires_in = 60)
36
+ lock.synchronize do
37
+ data[k] = [v, Time.now + expires_in]
38
+ end
39
+ end
40
+
41
+ private
42
+ attr_reader :data, :lock
43
+ end
44
+ end
45
+ end
data/lib/rx/middleware.rb CHANGED
@@ -55,11 +55,16 @@ module Rx
55
55
  :deep_secondary_checks, :options
56
56
 
57
57
  def cache_factory(options)
58
- unless options[:cache]
59
- return Rx::Cache::NoOpCache.new
58
+ case options[:cache]
59
+ when true
60
+ Rx::Cache::LRUCache.new
61
+ when "LRU"
62
+ Rx::Cache::LRUCache.new
63
+ when "MAP"
64
+ Rx::Cache::MapCache.new
65
+ else
66
+ Rx::Cache::NoOpCache.new
60
67
  end
61
-
62
- Rx::Cache::InMemoryCache.new
63
68
  end
64
69
 
65
70
  def health_check_request?(path)
data/lib/rx/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rx
4
- VERSION = "0.1.8"
4
+ VERSION = "0.1.9"
5
5
  end
data/lib/rx.rb CHANGED
@@ -2,7 +2,8 @@
2
2
 
3
3
  require_relative "rx/version"
4
4
  require_relative "rx/middleware"
5
- require_relative "rx/cache/in_memory_cache"
5
+ require_relative "rx/cache/lru_cache"
6
+ require_relative "rx/cache/map_cache"
6
7
  require_relative "rx/cache/no_op_cache"
7
8
  require_relative "rx/check/active_record_check"
8
9
  require_relative "rx/check/file_system_check"
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rx-healthcheck
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zach Pendleton
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-01-31 00:00:00.000000000 Z
11
+ date: 2022-04-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description:
13
+ description:
14
14
  email:
15
15
  - zachpendleton@gmail.com
16
16
  executables: []
@@ -26,7 +26,8 @@ files:
26
26
  - bin/console
27
27
  - bin/setup
28
28
  - lib/rx.rb
29
- - lib/rx/cache/in_memory_cache.rb
29
+ - lib/rx/cache/lru_cache.rb
30
+ - lib/rx/cache/map_cache.rb
30
31
  - lib/rx/cache/no_op_cache.rb
31
32
  - lib/rx/check/active_record_check.rb
32
33
  - lib/rx/check/file_system_check.rb
@@ -46,7 +47,7 @@ licenses:
46
47
  metadata:
47
48
  homepage_uri: https://github.com/zachpendleton/rx
48
49
  source_code_uri: https://github.com/zachpendleton/rx
49
- post_install_message:
50
+ post_install_message:
50
51
  rdoc_options: []
51
52
  require_paths:
52
53
  - lib
@@ -61,8 +62,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
62
  - !ruby/object:Gem::Version
62
63
  version: '0'
63
64
  requirements: []
64
- rubygems_version: 3.2.22
65
- signing_key:
65
+ rubygems_version: 3.1.6
66
+ signing_key:
66
67
  specification_version: 4
67
68
  summary: Standard health checks for Rails and Rack applications
68
69
  test_files: []