freno-client 0.3.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +0 -1
- data/.rubocop.yml +179 -0
- data/.travis.yml +8 -3
- data/CONTRIBUTING.md +3 -3
- data/Gemfile +12 -1
- data/README.md +184 -9
- data/Rakefile +5 -2
- data/freno-client.gemspec +17 -31
- data/lib/freno/client.rb +56 -16
- data/lib/freno/client/errors.rb +3 -0
- data/lib/freno/client/request.rb +17 -13
- data/lib/freno/client/requests/check.rb +7 -1
- data/lib/freno/client/requests/check_read.rb +7 -1
- data/lib/freno/client/requests/replication_delay.rb +1 -1
- data/lib/freno/client/result.rb +1 -1
- data/lib/freno/client/version.rb +1 -1
- data/lib/freno/throttler.rb +218 -0
- data/lib/freno/throttler/circuit_breaker.rb +39 -0
- data/lib/freno/throttler/errors.rb +23 -0
- data/lib/freno/throttler/instrumenter.rb +27 -0
- data/lib/freno/throttler/mapper.rb +45 -0
- metadata +18 -63
- data/script/bootstrap +0 -9
- data/script/cibuild +0 -19
- data/script/console +0 -2
@@ -0,0 +1,39 @@
|
|
1
|
+
module Freno
|
2
|
+
class Throttler
|
3
|
+
|
4
|
+
# A CircuitBreaker is the entry point of the pattern with same name.
|
5
|
+
# (see https://martinfowler.com/bliki/CircuitBreaker.html)
|
6
|
+
#
|
7
|
+
# Clients that use circuit breakers to add resiliency to their processes
|
8
|
+
# send `failure` or `sucess` messages to the CircuitBreaker depending on the
|
9
|
+
# results of the last requests made.
|
10
|
+
#
|
11
|
+
# With that information, the circuit breaker determines whether or not to
|
12
|
+
# allow the next request (`allow_request?`). A circuit is said to be open
|
13
|
+
# when the next request is not allowed; and it's said to be closed when the
|
14
|
+
# next request is allowed.
|
15
|
+
#
|
16
|
+
module CircuitBreaker
|
17
|
+
|
18
|
+
# The Noop circuit breaker is the `:circuit_breaker` used by default in
|
19
|
+
# the Throttler
|
20
|
+
#
|
21
|
+
# It always allows requests, and does nothing when given `success` or
|
22
|
+
# `failure` messages. For that reason it doesn't provide any resiliency
|
23
|
+
# guarantee.
|
24
|
+
#
|
25
|
+
# See https://github.com/jnunemaker/resilient for a real ruby implementation
|
26
|
+
# of the CircuitBreaker pattern.
|
27
|
+
#
|
28
|
+
class Noop
|
29
|
+
def self.allow_request?
|
30
|
+
true
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.success; end
|
34
|
+
|
35
|
+
def self.failure; end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require "freno/client"
|
2
|
+
|
3
|
+
module Freno
|
4
|
+
class Throttler
|
5
|
+
|
6
|
+
# Any throttler-related error.
|
7
|
+
class Error < Freno::Error; end
|
8
|
+
|
9
|
+
# Raised if the throttler has waited too long for replication delay
|
10
|
+
# to catch up.
|
11
|
+
class WaitedTooLong < Error
|
12
|
+
def initialize(waited_seconds: DEFAULT_WAIT_SECONDS, max_wait_seconds: DEFAULT_MAX_WAIT_SECONDS)
|
13
|
+
super("Waited #{waited_seconds} seconds. Max allowed was #{max_wait_seconds} seconds")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Raised if the circuit breaker is open and didn't allow latest request
|
18
|
+
class CircuitOpen < Error; end
|
19
|
+
|
20
|
+
# Raised if the freno client errored.
|
21
|
+
class ClientError < Error; end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Freno
|
2
|
+
class Throttler
|
3
|
+
|
4
|
+
# An Instrumenter is an object that responds to
|
5
|
+
# `instrument(event_name, payload = {})` to receive events from the
|
6
|
+
# throttler.
|
7
|
+
#
|
8
|
+
# As an example, in a rails app one could use ActiveSupport::Notifications
|
9
|
+
# as an instrumenter and subscribe to the "freno.*" events somewhere else in
|
10
|
+
# the application.
|
11
|
+
#
|
12
|
+
module Instrumenter
|
13
|
+
|
14
|
+
# The Noop instrumenter is the `:instrumenter` used by default in the
|
15
|
+
# Throttler
|
16
|
+
#
|
17
|
+
# It does nothing but yielding the control to the block given if it is
|
18
|
+
# provided.
|
19
|
+
#
|
20
|
+
class Noop
|
21
|
+
def self.instrument(event_name, payload = {})
|
22
|
+
yield payload if block_given?
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Freno
|
2
|
+
class Throttler
|
3
|
+
|
4
|
+
# A Mapper is any object that responds to `call`, by receiving a context
|
5
|
+
# object and returning a list of strings, each of which corresponds to the
|
6
|
+
# store_name that will be checked in freno.
|
7
|
+
#
|
8
|
+
# See https://github.com/github/freno/blob/master/doc/http.md#client-requests
|
9
|
+
# for more context.
|
10
|
+
#
|
11
|
+
# As an example we could use a mapper that will receive as a context a set
|
12
|
+
# of [table, shard_id] tuples, and could return the list of all the stores
|
13
|
+
# where that shards exist.
|
14
|
+
#
|
15
|
+
module Mapper
|
16
|
+
|
17
|
+
# The Identity mapper is the one used by default in the Throttler.
|
18
|
+
#
|
19
|
+
# It works by informing the throttler to check exact same stores that it
|
20
|
+
# receives as context, without any translation.
|
21
|
+
#
|
22
|
+
# Let's use the following throttler, which uses Mapper::Identity
|
23
|
+
# implicitly.
|
24
|
+
#
|
25
|
+
# ```ruby
|
26
|
+
# throttler = Throttler.new(client: freno_client, app: :my_app)
|
27
|
+
# data.find_in_batches do |batch|
|
28
|
+
# throttler.throttle([:mysqla, :mysqlb]) do
|
29
|
+
# update(batch)
|
30
|
+
# end
|
31
|
+
# end
|
32
|
+
# ```
|
33
|
+
#
|
34
|
+
# Before each call to `update(batch)` the throttler will call freno to
|
35
|
+
# check the health of `mysqla` and `mysqlb`. And sleep if any of them is
|
36
|
+
# not ok.
|
37
|
+
#
|
38
|
+
class Identity
|
39
|
+
def self.call(context)
|
40
|
+
Array(context)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
metadata
CHANGED
@@ -1,57 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: freno-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- GitHub
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: bundler
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.14'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.14'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rake
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '10.0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '10.0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: minitest
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '5.0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '5.0'
|
55
13
|
- !ruby/object:Gem::Dependency
|
56
14
|
name: faraday
|
57
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -59,24 +17,22 @@ dependencies:
|
|
59
17
|
- - "~>"
|
60
18
|
- !ruby/object:Gem::Version
|
61
19
|
version: '0'
|
62
|
-
type: :
|
20
|
+
type: :runtime
|
63
21
|
prerelease: false
|
64
22
|
version_requirements: !ruby/object:Gem::Requirement
|
65
23
|
requirements:
|
66
24
|
- - "~>"
|
67
25
|
- !ruby/object:Gem::Version
|
68
26
|
version: '0'
|
69
|
-
description:
|
70
|
-
|
71
|
-
|
72
|
-
source code is available at https://github.com/github/freno
|
73
|
-
email:
|
74
|
-
- opensource+freno-client@github.com
|
27
|
+
description: 'freno-client is a Ruby library that interacts with Freno using HTTP.
|
28
|
+
Freno is a throttling service and its source code is available at https://github.com/github/freno '
|
29
|
+
email: opensource+freno-client@github.com
|
75
30
|
executables: []
|
76
31
|
extensions: []
|
77
32
|
extra_rdoc_files: []
|
78
33
|
files:
|
79
34
|
- ".gitignore"
|
35
|
+
- ".rubocop.yml"
|
80
36
|
- ".travis.yml"
|
81
37
|
- CODE_OF_CONDUCT.md
|
82
38
|
- CONTRIBUTING.md
|
@@ -84,10 +40,9 @@ files:
|
|
84
40
|
- LICENSE.txt
|
85
41
|
- README.md
|
86
42
|
- Rakefile
|
87
|
-
- bin/console
|
88
|
-
- bin/setup
|
89
43
|
- freno-client.gemspec
|
90
44
|
- lib/freno/client.rb
|
45
|
+
- lib/freno/client/errors.rb
|
91
46
|
- lib/freno/client/preconditions.rb
|
92
47
|
- lib/freno/client/request.rb
|
93
48
|
- lib/freno/client/requests/check.rb
|
@@ -95,14 +50,15 @@ files:
|
|
95
50
|
- lib/freno/client/requests/replication_delay.rb
|
96
51
|
- lib/freno/client/result.rb
|
97
52
|
- lib/freno/client/version.rb
|
98
|
-
-
|
99
|
-
-
|
100
|
-
-
|
53
|
+
- lib/freno/throttler.rb
|
54
|
+
- lib/freno/throttler/circuit_breaker.rb
|
55
|
+
- lib/freno/throttler/errors.rb
|
56
|
+
- lib/freno/throttler/instrumenter.rb
|
57
|
+
- lib/freno/throttler/mapper.rb
|
101
58
|
homepage: https://github.com/github/freno-client
|
102
59
|
licenses:
|
103
60
|
- MIT
|
104
|
-
metadata:
|
105
|
-
allowed_push_host: https://rubygems.org
|
61
|
+
metadata: {}
|
106
62
|
post_install_message:
|
107
63
|
rdoc_options: []
|
108
64
|
require_paths:
|
@@ -111,16 +67,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
111
67
|
requirements:
|
112
68
|
- - ">="
|
113
69
|
- !ruby/object:Gem::Version
|
114
|
-
version: 2.
|
70
|
+
version: 2.5.0
|
115
71
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
72
|
requirements:
|
117
73
|
- - ">="
|
118
74
|
- !ruby/object:Gem::Version
|
119
75
|
version: '0'
|
120
76
|
requirements: []
|
121
|
-
|
122
|
-
rubygems_version: 2.6.11
|
77
|
+
rubygems_version: 3.1.2
|
123
78
|
signing_key:
|
124
79
|
specification_version: 4
|
125
|
-
summary: A library for interacting with
|
80
|
+
summary: A library for interacting with Freno, the throttler service
|
126
81
|
test_files: []
|
data/script/bootstrap
DELETED
data/script/cibuild
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
#!/bin/sh
|
2
|
-
|
3
|
-
set -eu
|
4
|
-
|
5
|
-
test -d "/usr/share/rbenv/shims" && {
|
6
|
-
export PATH="/usr/share/rbenv/shims:$PATH"
|
7
|
-
export RBENV_VERSION="2.4.1"
|
8
|
-
}
|
9
|
-
|
10
|
-
set -x
|
11
|
-
git log -n 1 HEAD | cat
|
12
|
-
ruby -v
|
13
|
-
bundle -v
|
14
|
-
set +x
|
15
|
-
|
16
|
-
git clean -fd
|
17
|
-
|
18
|
-
script/bootstrap
|
19
|
-
bundle exec rake
|
data/script/console
DELETED