faulty 0.8.2 → 0.8.4
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/.github/workflows/ci.yml +5 -0
- data/CHANGELOG.md +6 -2
- data/Gemfile +2 -0
- data/README.md +35 -1
- data/lib/faulty/patch/elasticsearch.rb +63 -0
- data/lib/faulty/patch/mysql2.rb +3 -0
- data/lib/faulty/patch/redis.rb +3 -0
- data/lib/faulty/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 674bada595aee5985be78855425adc16fdb25faa2741cc548758e13ea002bb5a
|
4
|
+
data.tar.gz: 9144ec1b6051acbba1d4cc8cccd792826bd3aee831d4fa04c13b41a860150244
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75a8f4cf1608f65f326c66c3682826542e469891cbad97ba31b3854e75899f1e694dc5925e072582c5ac35ce29c9838535f0aca0e17d24c05a2bc5b9796cecae
|
7
|
+
data.tar.gz: faa2361bc38bcb52917491eee6c499ef16114f100d844385e6eb799f531097e45780d2fc0db31447330cc1a3ef982fdd4bbfa45bb5a53fdec1ef776b7ae1f010
|
data/.github/workflows/ci.yml
CHANGED
@@ -22,6 +22,11 @@ jobs:
|
|
22
22
|
image: redis
|
23
23
|
ports:
|
24
24
|
- 6379:6379
|
25
|
+
elasticsearch:
|
26
|
+
image: elasticsearch:7.13.4
|
27
|
+
ports:
|
28
|
+
- 9200:9200
|
29
|
+
options: -e="discovery.type=single-node" --health-cmd="curl http://localhost:9200/_cluster/health" --health-interval=3s --health-timeout=5s --health-retries=20
|
25
30
|
steps:
|
26
31
|
- uses: actions/checkout@v2
|
27
32
|
- uses: ruby/setup-ruby@v1
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,12 @@
|
|
1
|
-
##
|
1
|
+
## Release v0.8.4
|
2
|
+
|
3
|
+
* Add Elasticsearch client patch #44 justinhoward
|
4
|
+
|
5
|
+
## Release v0.8.2
|
2
6
|
|
3
7
|
* Fix crash for older versions of concurrent-ruby #42 justinhoward
|
4
8
|
|
5
|
-
##
|
9
|
+
## Release v0.8.1
|
6
10
|
|
7
11
|
* Add cause message to CircuitTrippedError #40 justinhoward
|
8
12
|
* Record failures for cache hits #41 justinhoward
|
data/Gemfile
CHANGED
@@ -13,6 +13,8 @@ not_jruby = %i[ruby mingw x64_mingw].freeze
|
|
13
13
|
gem 'activesupport', '>= 4.2'
|
14
14
|
gem 'bundler', '>= 1.17', '< 3'
|
15
15
|
gem 'byebug', platforms: not_jruby
|
16
|
+
# Open source licensed elasticsearch
|
17
|
+
gem 'elasticsearch', '> 7', '< 7.14'
|
16
18
|
gem 'honeybadger', '>= 2.0'
|
17
19
|
gem 'irb', '~> 1.0'
|
18
20
|
# Minimum of 0.5.0 for specific error classes
|
data/README.md
CHANGED
@@ -84,6 +84,7 @@ Also see "Release It!: Design and Deploy Production-Ready Software" by
|
|
84
84
|
* [Patches](#patches)
|
85
85
|
+ [Patch::Redis](#patchredis)
|
86
86
|
+ [Patch::Mysql2](#patchmysql2)
|
87
|
+
+ [Patch::Elasticsearch](#patchelasticsearch)
|
87
88
|
* [Event Handling](#event-handling)
|
88
89
|
+ [CallbackListener](#callbacklistener)
|
89
90
|
+ [Other Built-in Listeners](#other-built-in-listeners)
|
@@ -1046,6 +1047,38 @@ mysql = Mysql2::Client.new(host: '127.0.0.1')
|
|
1046
1047
|
mysql.query('SELECT * FROM users') # not protected by a circuit
|
1047
1048
|
```
|
1048
1049
|
|
1050
|
+
### Patch::Elasticsearch
|
1051
|
+
|
1052
|
+
[`Faulty::Patch::Elasticsearch`](https://www.rubydoc.info/gems/faulty/Faulty/Patch/Elasticsearch)
|
1053
|
+
protects a `Elasticsearch::Client` with an internal circuit. Pass a `:faulty` key along
|
1054
|
+
with your client options to enable the circuit breaker.
|
1055
|
+
|
1056
|
+
```ruby
|
1057
|
+
require 'faulty/patch/elasticsearch'
|
1058
|
+
|
1059
|
+
es = Elasticsearch::Client.new(url: 'localhost:9200', faulty: {
|
1060
|
+
# The name for the Elasticsearch::Client circuit
|
1061
|
+
name: 'elasticsearch'
|
1062
|
+
|
1063
|
+
# The faulty instance to use
|
1064
|
+
# This can also be a registered faulty instance or a constant name. See API
|
1065
|
+
# docs for more details
|
1066
|
+
instance: Faulty.default
|
1067
|
+
|
1068
|
+
# By default, circuit errors will be subclasses of
|
1069
|
+
# Elasticsearch::Transport::Transport::Error
|
1070
|
+
# To disable this behavior, set patch_errors to false and Faulty
|
1071
|
+
# will raise its default errors
|
1072
|
+
patch_errors: true
|
1073
|
+
})
|
1074
|
+
```
|
1075
|
+
|
1076
|
+
If you're using Searchkick, you can configure Faulty with `client_options`.
|
1077
|
+
|
1078
|
+
```ruby
|
1079
|
+
Searchkick.client_options[:faulty] = { name: 'searchkick' }
|
1080
|
+
```
|
1081
|
+
|
1049
1082
|
## Event Handling
|
1050
1083
|
|
1051
1084
|
Faulty uses an event-dispatching model to deliver notifications of internal
|
@@ -1300,7 +1333,8 @@ but there are and have been many other options:
|
|
1300
1333
|
- [circuit_breaker-ruby](https://github.com/scripbox/circuit_breaker-ruby) (no
|
1301
1334
|
recent activity)
|
1302
1335
|
- [stoplight](https://github.com/orgsync/stoplight) (unmaintained)
|
1303
|
-
- [circuit_breaker](https://github.com/
|
1336
|
+
- [circuit_breaker](https://github.com/wsargent/circuit_breaker) (no recent
|
1337
|
+
activity)
|
1304
1338
|
- [simple_circuit_breaker](https://github.com/soundcloud/simple_circuit_breaker)
|
1305
1339
|
(unmaintained)
|
1306
1340
|
- [breaker](https://github.com/ahawkins/breaker) (unmaintained)
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'elasticsearch'
|
4
|
+
|
5
|
+
class Faulty
|
6
|
+
module Patch
|
7
|
+
# Patch Elasticsearch to run requests in a circuit
|
8
|
+
#
|
9
|
+
# This module is not required by default
|
10
|
+
#
|
11
|
+
# Pass a `:faulty` key into your Elasticsearch client options to enable
|
12
|
+
# circuit protection. See {Patch.circuit_from_hash} for the available
|
13
|
+
# options.
|
14
|
+
#
|
15
|
+
# By default, all circuit errors raised by this patch inherit from
|
16
|
+
# `::Elasticsearch::Transport::Transport::Error`. One side effect of the way
|
17
|
+
# this patch wraps errors is that `host_unreachable_exceptions` raised by
|
18
|
+
# the inner transport adapters are converted into
|
19
|
+
# `Elasticsearch::Transport::Transport::Error` instead of the transport
|
20
|
+
# error type such as `Faraday::ConnectionFailed`.
|
21
|
+
#
|
22
|
+
# @example
|
23
|
+
# require 'faulty/patch/elasticsearch'
|
24
|
+
#
|
25
|
+
# es = Elasticsearch::Client.new(url: 'http://localhost:9200', faulty: {})
|
26
|
+
# es.search(q: 'test') # raises Faulty::CircuitError if connection fails
|
27
|
+
#
|
28
|
+
# # If the faulty key is not given, no circuit is used
|
29
|
+
# es = Elasticsearch::Client.new(url: 'http://localhost:9200', faulty: {})
|
30
|
+
# es.search(q: 'test') # not protected by a circuit
|
31
|
+
#
|
32
|
+
# # With Searchkick
|
33
|
+
# Searchkick.client_options[:faulty] = {}
|
34
|
+
#
|
35
|
+
# @see Patch.circuit_from_hash
|
36
|
+
module Elasticsearch
|
37
|
+
include Base
|
38
|
+
|
39
|
+
Patch.define_circuit_errors(self, ::Elasticsearch::Transport::Transport::Error)
|
40
|
+
|
41
|
+
def initialize(arguments = {}, &block)
|
42
|
+
super
|
43
|
+
|
44
|
+
errors = [::Elasticsearch::Transport::Transport::Error]
|
45
|
+
errors.concat(@transport.host_unreachable_exceptions)
|
46
|
+
|
47
|
+
@faulty_circuit = Patch.circuit_from_hash(
|
48
|
+
'elasticsearch',
|
49
|
+
arguments[:faulty],
|
50
|
+
errors: errors,
|
51
|
+
patched_error_module: Faulty::Patch::Elasticsearch
|
52
|
+
)
|
53
|
+
end
|
54
|
+
|
55
|
+
# Protect all elasticsearch requests
|
56
|
+
def perform_request(*args)
|
57
|
+
faulty_run { super }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
::Elasticsearch::Transport::Client.prepend(Faulty::Patch::Elasticsearch)
|
data/lib/faulty/patch/mysql2.rb
CHANGED
@@ -20,6 +20,9 @@ class Faulty
|
|
20
20
|
# protected by the circuit. This is to allow open transactions to be closed
|
21
21
|
# if possible.
|
22
22
|
#
|
23
|
+
# By default, all circuit errors raised by this patch inherit from
|
24
|
+
# `::Mysql2::Error::ConnectionError`
|
25
|
+
#
|
23
26
|
# @example
|
24
27
|
# require 'faulty/patch/mysql2'
|
25
28
|
#
|
data/lib/faulty/patch/redis.rb
CHANGED
@@ -12,6 +12,9 @@ class Faulty
|
|
12
12
|
# circuit protection. See {Patch.circuit_from_hash} for the available
|
13
13
|
# options.
|
14
14
|
#
|
15
|
+
# By default, all circuit errors raised by this patch inherit from
|
16
|
+
# `::Redis::BaseConnectionError`
|
17
|
+
#
|
15
18
|
# @example
|
16
19
|
# require 'faulty/patch/redis'
|
17
20
|
#
|
data/lib/faulty/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faulty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Howard
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -170,6 +170,7 @@ files:
|
|
170
170
|
- lib/faulty/immutable_options.rb
|
171
171
|
- lib/faulty/patch.rb
|
172
172
|
- lib/faulty/patch/base.rb
|
173
|
+
- lib/faulty/patch/elasticsearch.rb
|
173
174
|
- lib/faulty/patch/mysql2.rb
|
174
175
|
- lib/faulty/patch/redis.rb
|
175
176
|
- lib/faulty/result.rb
|