freno-client 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/.rubocop.yml +54 -177
- data/.travis.yml +3 -6
- data/CONTRIBUTING.md +2 -2
- data/Gemfile +7 -1
- data/README.md +5 -5
- data/Rakefile +5 -23
- data/freno-client.gemspec +16 -30
- data/lib/freno/client.rb +32 -11
- data/lib/freno/client/request.rb +8 -4
- data/lib/freno/client/requests/check.rb +6 -0
- data/lib/freno/client/requests/check_read.rb +6 -0
- data/lib/freno/client/version.rb +1 -1
- data/lib/freno/throttler.rb +15 -5
- metadata +11 -65
- data/script/bootstrap +0 -9
- data/script/cibuild +0 -19
- data/script/cibuild-lint +0 -19
- data/script/console +0 -2
- data/script/release +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b67b5e48efee8e0a92ee1a1ef8c4b464b8bfe7001b31a2e53f6fc59aaee2fbc4
|
4
|
+
data.tar.gz: 00f039825fdcc34faabb9028e0e74db49e4ebba1490c6f50e135272564f97a7e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37abf885c12930338060fa3b075bcbb832eacc7197a27dd7546bee2f4b49e1fb3f8476b69babee89538251b637bf077ae21138ec5fe20067593da71aec457dd2
|
7
|
+
data.tar.gz: a9e5de834594a57be0db6de4e229536c2a7ad1f99a20d11c4bce96e62efb183c0462bb19c615783a25019acd4d90920658b7a3419d578eacf91dd64f8ce403e8
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -1,182 +1,132 @@
|
|
1
|
+
require: rubocop-performance
|
2
|
+
|
1
3
|
AllCops:
|
2
4
|
DisabledByDefault: true
|
5
|
+
TargetRubyVersion: 2.5
|
3
6
|
|
4
7
|
Bundler/DuplicatedGem:
|
5
8
|
Enabled: true
|
6
|
-
|
7
9
|
Bundler/OrderedGems:
|
8
10
|
Enabled: true
|
9
11
|
|
10
|
-
|
12
|
+
Layout/BlockAlignment:
|
13
|
+
Enabled: true
|
14
|
+
Layout/BlockEndNewline:
|
15
|
+
Enabled: true
|
16
|
+
Layout/ConditionPosition:
|
17
|
+
Enabled: true
|
18
|
+
Layout/DefEndAlignment:
|
19
|
+
Enabled: true
|
20
|
+
Layout/EndOfLine:
|
21
|
+
Enabled: true
|
22
|
+
Layout/IndentationStyle:
|
23
|
+
Enabled: true
|
24
|
+
Layout/InitialIndentation:
|
25
|
+
Enabled: true
|
26
|
+
Layout/SpaceAfterColon:
|
27
|
+
Enabled: true
|
28
|
+
Layout/SpaceAfterComma:
|
29
|
+
Enabled: true
|
30
|
+
Layout/SpaceAfterMethodName:
|
31
|
+
Enabled: true
|
32
|
+
Layout/SpaceAfterNot:
|
33
|
+
Enabled: true
|
34
|
+
Layout/SpaceAfterSemicolon:
|
35
|
+
Enabled: true
|
36
|
+
Layout/SpaceAroundBlockParameters:
|
37
|
+
Enabled: true
|
38
|
+
Layout/SpaceAroundEqualsInParameterDefault:
|
39
|
+
Enabled: true
|
40
|
+
Layout/SpaceInsideArrayPercentLiteral:
|
41
|
+
Enabled: true
|
42
|
+
Layout/SpaceInsideParens:
|
43
|
+
Enabled: true
|
44
|
+
Layout/SpaceInsideRangeLiteral:
|
45
|
+
Enabled: true
|
46
|
+
Layout/TrailingEmptyLines:
|
47
|
+
Enabled: true
|
48
|
+
Layout/TrailingWhitespace:
|
11
49
|
Enabled: true
|
12
50
|
|
51
|
+
Lint/CircularArgumentReference:
|
52
|
+
Enabled: true
|
13
53
|
Lint/Debugger:
|
14
54
|
Enabled: true
|
15
|
-
|
16
55
|
Lint/DeprecatedClassMethods:
|
17
56
|
Enabled: true
|
18
|
-
|
19
|
-
Lint/DuplicateMethods:
|
57
|
+
Lint/DuplicateHashKey:
|
20
58
|
Enabled: true
|
21
|
-
|
22
|
-
Lint/DuplicatedKey:
|
59
|
+
Lint/DuplicateMethods:
|
23
60
|
Enabled: true
|
24
|
-
|
25
61
|
Lint/EachWithObjectArgument:
|
26
62
|
Enabled: true
|
27
|
-
|
28
63
|
Lint/ElseLayout:
|
29
64
|
Enabled: true
|
30
|
-
|
31
65
|
Lint/EmptyEnsure:
|
32
66
|
Enabled: true
|
33
|
-
|
34
|
-
Lint/EndInMethod:
|
35
|
-
Enabled: true
|
36
|
-
|
37
67
|
Lint/EmptyInterpolation:
|
38
68
|
Enabled: true
|
39
|
-
|
40
69
|
Lint/EnsureReturn:
|
41
70
|
Enabled: true
|
42
|
-
|
43
|
-
Lint/FloatOutOfRange:
|
44
|
-
Enabled: true
|
45
|
-
|
46
71
|
Lint/FlipFlop:
|
47
72
|
Enabled: true
|
48
|
-
|
49
|
-
Lint/FormatParameterMismatch:
|
73
|
+
Lint/FloatOutOfRange:
|
50
74
|
Enabled: true
|
51
|
-
|
52
|
-
Style/HashSyntax:
|
75
|
+
Lint/FormatParameterMismatch:
|
53
76
|
Enabled: true
|
54
|
-
EnforcedStyle: ruby19
|
55
|
-
|
56
77
|
Lint/LiteralInInterpolation:
|
57
78
|
Enabled: true
|
58
|
-
|
59
79
|
Lint/Loop:
|
60
80
|
Enabled: true
|
61
|
-
|
62
81
|
Lint/NextWithoutAccumulator:
|
63
82
|
Enabled: true
|
64
|
-
|
65
83
|
Lint/RandOne:
|
66
84
|
Enabled: true
|
67
|
-
|
85
|
+
Lint/RedundantSplatExpansion:
|
86
|
+
Enabled: true
|
87
|
+
Lint/RedundantStringCoercion:
|
88
|
+
Enabled: true
|
68
89
|
Lint/RequireParentheses:
|
69
90
|
Enabled: true
|
70
|
-
|
71
91
|
Lint/RescueException:
|
72
92
|
Enabled: true
|
73
|
-
|
74
|
-
Lint/StringConversionInInterpolation:
|
75
|
-
Enabled: true
|
76
|
-
|
77
93
|
Lint/UnderscorePrefixedVariableName:
|
78
94
|
Enabled: true
|
79
|
-
|
80
|
-
Lint/UnneededSplatExpansion:
|
81
|
-
Enabled: true
|
82
|
-
|
83
95
|
Lint/UnreachableCode:
|
84
96
|
Enabled: true
|
85
|
-
|
86
97
|
Lint/UselessComparison:
|
87
98
|
Enabled: true
|
88
|
-
|
89
99
|
Lint/UselessSetterCall:
|
90
100
|
Enabled: true
|
91
|
-
|
92
101
|
Lint/Void:
|
93
102
|
Enabled: true
|
94
103
|
|
95
|
-
Metrics/AbcSize:
|
96
|
-
Enabled: false
|
97
|
-
|
98
|
-
Metrics/BlockLength:
|
99
|
-
Enabled: false
|
100
|
-
|
101
|
-
Metrics/BlockNesting:
|
102
|
-
Enabled: false
|
103
|
-
|
104
|
-
Metrics/ClassLength:
|
105
|
-
Enabled: false
|
106
|
-
|
107
|
-
Metrics/CyclomaticComplexity:
|
108
|
-
Enabled: false
|
109
|
-
|
110
|
-
Metrics/LineLength:
|
111
|
-
Enabled: false
|
112
|
-
|
113
|
-
Metrics/MethodLength:
|
114
|
-
Enabled: false
|
115
|
-
|
116
|
-
Metrics/ModuleLength:
|
117
|
-
Enabled: false
|
118
|
-
|
119
|
-
Metrics/ParameterLists:
|
120
|
-
Enabled: false
|
121
|
-
|
122
|
-
Metrics/PerceivedComplexity:
|
123
|
-
Enabled: false
|
124
|
-
|
125
104
|
Naming/AsciiIdentifiers:
|
126
105
|
Enabled: true
|
127
|
-
|
128
106
|
Naming/ClassAndModuleCamelCase:
|
129
107
|
Enabled: true
|
130
|
-
|
131
108
|
Naming/FileName:
|
132
109
|
Enabled: true
|
133
|
-
|
134
110
|
Naming/MethodName:
|
135
111
|
Enabled: true
|
136
112
|
|
137
|
-
Performance/CaseWhenSplat:
|
138
|
-
Enabled: false
|
139
|
-
|
140
113
|
Performance/Count:
|
141
114
|
Enabled: true
|
142
|
-
|
143
115
|
Performance/Detect:
|
144
116
|
Enabled: true
|
145
|
-
|
146
117
|
Performance/DoubleStartEndWith:
|
147
118
|
Enabled: true
|
148
|
-
|
149
119
|
Performance/EndWith:
|
150
120
|
Enabled: true
|
151
|
-
|
152
121
|
Performance/FlatMap:
|
153
122
|
Enabled: true
|
154
|
-
|
155
|
-
Performance/LstripRstrip:
|
156
|
-
Enabled: true
|
157
|
-
|
158
|
-
Performance/RangeInclude:
|
159
|
-
Enabled: false
|
160
|
-
|
161
|
-
Performance/RedundantMatch:
|
162
|
-
Enabled: false
|
163
|
-
|
164
123
|
Performance/RedundantMerge:
|
165
124
|
Enabled: true
|
166
125
|
MaxKeyValuePairs: 1
|
167
|
-
|
168
|
-
Performance/RedundantSortBy:
|
169
|
-
Enabled: true
|
170
|
-
|
171
126
|
Performance/ReverseEach:
|
172
127
|
Enabled: true
|
173
|
-
|
174
|
-
Performance/Sample:
|
175
|
-
Enabled: true
|
176
|
-
|
177
128
|
Performance/Size:
|
178
129
|
Enabled: true
|
179
|
-
|
180
130
|
Performance/StartWith:
|
181
131
|
Enabled: true
|
182
132
|
|
@@ -185,118 +135,45 @@ Security/Eval:
|
|
185
135
|
|
186
136
|
Style/ArrayJoin:
|
187
137
|
Enabled: true
|
188
|
-
|
189
138
|
Style/BeginBlock:
|
190
139
|
Enabled: true
|
191
|
-
|
192
140
|
Style/BlockComments:
|
193
141
|
Enabled: true
|
194
|
-
|
195
142
|
Style/CaseEquality:
|
196
143
|
Enabled: true
|
197
|
-
|
198
144
|
Style/CharacterLiteral:
|
199
145
|
Enabled: true
|
200
|
-
|
201
146
|
Style/ClassMethods:
|
202
147
|
Enabled: true
|
203
|
-
|
204
|
-
Style/Copyright:
|
205
|
-
Enabled: false
|
206
|
-
|
207
148
|
Style/DefWithParentheses:
|
208
149
|
Enabled: true
|
209
|
-
|
210
150
|
Style/EndBlock:
|
211
151
|
Enabled: true
|
212
|
-
|
213
152
|
Style/For:
|
214
153
|
Enabled: true
|
215
|
-
|
216
|
-
Layout/BlockEndNewline:
|
217
|
-
Enabled: true
|
218
|
-
|
219
|
-
Layout/ConditionPosition:
|
220
|
-
Enabled: true
|
221
|
-
|
222
|
-
Layout/EndAlignment:
|
223
|
-
Enabled: false
|
224
|
-
|
225
|
-
Layout/EndOfLine:
|
226
|
-
Enabled: true
|
227
|
-
|
228
|
-
Layout/InitialIndentation:
|
154
|
+
Style/HashSyntax:
|
229
155
|
Enabled: true
|
230
|
-
|
156
|
+
EnforcedStyle: ruby19
|
231
157
|
Style/LambdaCall:
|
232
158
|
Enabled: true
|
233
|
-
|
234
159
|
Style/MethodCallWithoutArgsParentheses:
|
235
160
|
Enabled: true
|
236
|
-
|
237
161
|
Style/MethodDefParentheses:
|
238
162
|
Enabled: true
|
239
|
-
|
240
163
|
Style/MultilineIfThen:
|
241
164
|
Enabled: true
|
242
|
-
|
243
165
|
Style/NilComparison:
|
244
166
|
Enabled: true
|
245
|
-
|
246
167
|
Style/Not:
|
247
168
|
Enabled: true
|
248
|
-
|
249
169
|
Style/OneLineConditional:
|
250
170
|
Enabled: true
|
251
|
-
|
252
|
-
Layout/BlockAlignment:
|
253
|
-
Enabled: true
|
254
|
-
|
255
|
-
Layout/DefEndAlignment:
|
256
|
-
Enabled: true
|
257
|
-
|
258
|
-
Layout/SpaceAfterMethodName:
|
171
|
+
Style/RedundantSortBy:
|
259
172
|
Enabled: true
|
260
|
-
|
261
|
-
Layout/SpaceAfterColon:
|
173
|
+
Style/Sample:
|
262
174
|
Enabled: true
|
263
|
-
|
264
|
-
Layout/SpaceAfterComma:
|
265
|
-
Enabled: true
|
266
|
-
|
267
|
-
Layout/SpaceAfterNot:
|
268
|
-
Enabled: true
|
269
|
-
|
270
|
-
Layout/SpaceAfterSemicolon:
|
271
|
-
Enabled: true
|
272
|
-
|
273
|
-
Layout/SpaceAroundBlockParameters:
|
274
|
-
Enabled: true
|
275
|
-
|
276
|
-
Layout/SpaceAroundEqualsInParameterDefault:
|
277
|
-
Enabled: true
|
278
|
-
|
279
|
-
Layout/SpaceInsideArrayPercentLiteral:
|
280
|
-
Enabled: true
|
281
|
-
|
282
|
-
Layout/SpaceInsideParens:
|
283
|
-
Enabled: true
|
284
|
-
|
285
|
-
Layout/SpaceInsideRangeLiteral:
|
286
|
-
Enabled: true
|
287
|
-
|
288
175
|
Style/StabbyLambdaParentheses:
|
289
176
|
Enabled: true
|
290
|
-
|
291
177
|
Style/StringLiterals:
|
292
178
|
Enabled: true
|
293
179
|
EnforcedStyle: double_quotes
|
294
|
-
|
295
|
-
Layout/Tab:
|
296
|
-
Enabled: true
|
297
|
-
|
298
|
-
Layout/TrailingBlankLines:
|
299
|
-
Enabled: true
|
300
|
-
|
301
|
-
Layout/TrailingWhitespace:
|
302
|
-
Enabled: true
|
data/.travis.yml
CHANGED
data/CONTRIBUTING.md
CHANGED
@@ -12,8 +12,8 @@ Please note that this project is released with a [Contributor Code of Conduct][c
|
|
12
12
|
## Submitting a pull request
|
13
13
|
|
14
14
|
0. [Fork][fork] and clone the freno-client repository
|
15
|
-
0. Configure and install the dependencies: `
|
16
|
-
0. Make sure the tests pass on your machine: `
|
15
|
+
0. Configure and install the dependencies: `bin/setup`
|
16
|
+
0. Make sure the tests pass on your machine: `bin/test`
|
17
17
|
0. Create a new branch: `git checkout -b my-branch-name`
|
18
18
|
0. Make your change, add tests, and make sure the tests still pass
|
19
19
|
0. Push to your fork and [submit a pull request][pr]
|
data/Gemfile
CHANGED
@@ -2,7 +2,13 @@ source "https://rubygems.org"
|
|
2
2
|
|
3
3
|
gemspec
|
4
4
|
|
5
|
+
group :development do
|
6
|
+
gem "rake"
|
7
|
+
end
|
8
|
+
|
5
9
|
group :test do
|
10
|
+
gem "minitest", ">= 5"
|
6
11
|
gem "mocha"
|
7
|
-
gem "rubocop", require: false
|
12
|
+
gem "rubocop", "~> 0.85.1", require: false
|
13
|
+
gem "rubocop-performance", require: false
|
8
14
|
end
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Freno Client [![Build Status](https://travis-ci.org/github/freno-client.svg)](https://travis-ci.org/github/freno-client)
|
1
|
+
# Freno Client [![Build Status](https://travis-ci.org/github/freno-client.svg?branch=master)](https://travis-ci.org/github/github/freno-client)
|
2
2
|
|
3
3
|
A ruby client and throttling library for [Freno](https://github.com/github/freno): the cooperative, highly available throttler service.
|
4
4
|
|
@@ -355,7 +355,7 @@ end
|
|
355
355
|
|
356
356
|
## Development
|
357
357
|
|
358
|
-
After checking out the repo, run `
|
358
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
359
359
|
|
360
360
|
## Contributing
|
361
361
|
|
@@ -366,11 +366,11 @@ This repository is open to [contributions](CONTRIBUTING.md). Contributors are ex
|
|
366
366
|
If you are the current maintainer of this gem:
|
367
367
|
|
368
368
|
1. Create a branch for the release: `git checkout -b cut-release-vx.y.z`
|
369
|
-
1. Make sure your local dependencies are up to date: `
|
370
|
-
1. Ensure that tests are green: `
|
369
|
+
1. Make sure your local dependencies are up to date: `bin/setup`
|
370
|
+
1. Ensure that tests are green: `bin/test`
|
371
371
|
1. Bump gem version in `lib/freno/client/version.rb`
|
372
372
|
1. Merge a PR to github/freno-client containing the changes in the version file
|
373
|
-
1. Run `
|
373
|
+
1. Run `bin/release`
|
374
374
|
|
375
375
|
## License
|
376
376
|
|
data/Rakefile
CHANGED
@@ -1,26 +1,6 @@
|
|
1
|
-
|
1
|
+
require "bundler/gem_tasks"
|
2
2
|
require "rake/testtask"
|
3
|
-
require "
|
4
|
-
|
5
|
-
# gem install pkg/*.gem
|
6
|
-
# gem uninstall freno-client freno-throttler
|
7
|
-
desc "Build gem into the pkg directory"
|
8
|
-
task :build do
|
9
|
-
FileUtils.rm_rf("pkg")
|
10
|
-
Dir["*.gemspec"].each do |gemspec|
|
11
|
-
system "gem build #{gemspec}"
|
12
|
-
end
|
13
|
-
FileUtils.mkdir_p("pkg")
|
14
|
-
FileUtils.mv(Dir["*.gem"], "pkg")
|
15
|
-
end
|
16
|
-
|
17
|
-
desc "Tags version, pushes to remote, and pushes gem"
|
18
|
-
task release: :build do
|
19
|
-
sh "git", "tag", "v#{Freno::Client::VERSION}"
|
20
|
-
sh "git push origin master"
|
21
|
-
sh "git push origin v#{Freno::Client::VERSION}"
|
22
|
-
sh "ls pkg/*.gem | xargs -n 1 gem push"
|
23
|
-
end
|
3
|
+
require "rubocop/rake_task"
|
24
4
|
|
25
5
|
Rake::TestTask.new(:test) do |t|
|
26
6
|
t.libs << "test"
|
@@ -28,4 +8,6 @@ Rake::TestTask.new(:test) do |t|
|
|
28
8
|
t.test_files = FileList["test/**/*_test.rb"]
|
29
9
|
end
|
30
10
|
|
31
|
-
|
11
|
+
RuboCop::RakeTask.new(:rubocop)
|
12
|
+
|
13
|
+
task default: [:test, :rubocop]
|
data/freno-client.gemspec
CHANGED
@@ -1,38 +1,24 @@
|
|
1
|
-
# -- encoding: utf-8 --
|
2
|
-
$:.unshift File.expand_path("../lib", __FILE__)
|
3
1
|
require_relative "lib/freno/client/version"
|
4
2
|
|
5
3
|
Gem::Specification.new do |spec|
|
6
|
-
spec.name
|
7
|
-
spec.version
|
8
|
-
spec.
|
9
|
-
spec.email
|
4
|
+
spec.name = "freno-client"
|
5
|
+
spec.version = Freno::Client::VERSION
|
6
|
+
spec.author = "GitHub"
|
7
|
+
spec.email = "opensource+freno-client@github.com"
|
10
8
|
|
11
|
-
spec.summary
|
12
|
-
spec.description
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
spec.required_ruby_version = ">= 2.0.0"
|
9
|
+
spec.summary = "A library for interacting with Freno, the throttler service"
|
10
|
+
spec.description = <<~DESC.gsub(/\s+/, " ")
|
11
|
+
freno-client is a Ruby library that interacts with Freno using HTTP.
|
12
|
+
Freno is a throttling service and its source code is available at
|
13
|
+
https://github.com/github/freno
|
14
|
+
DESC
|
18
15
|
|
19
|
-
|
20
|
-
|
21
|
-
if spec.respond_to?(:metadata)
|
22
|
-
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
23
|
-
else
|
24
|
-
raise "RubyGems 2.0 or newer is required to protect against " \
|
25
|
-
"public gem pushes."
|
26
|
-
end
|
16
|
+
spec.homepage = "https://github.com/github/freno-client"
|
17
|
+
spec.license = "MIT"
|
27
18
|
|
28
|
-
spec.
|
29
|
-
f.match(%r{^(test|spec|features)/})
|
30
|
-
end
|
31
|
-
spec.executables = []
|
32
|
-
spec.require_paths = ["lib"]
|
19
|
+
spec.required_ruby_version = ">= 2.5.0"
|
33
20
|
|
34
|
-
spec.
|
35
|
-
|
36
|
-
spec.
|
37
|
-
spec.add_development_dependency "faraday", "~> 0"
|
21
|
+
spec.files = `git ls-files -z`.split("\x0").grep_v(/^(bin|test)/)
|
22
|
+
|
23
|
+
spec.add_dependency "faraday", "~> 0"
|
38
24
|
end
|
data/lib/freno/client.rb
CHANGED
@@ -31,6 +31,27 @@ module Freno
|
|
31
31
|
# end
|
32
32
|
# ```
|
33
33
|
#
|
34
|
+
# Any options set on the Client are passed through to the initialization of
|
35
|
+
# each request:
|
36
|
+
#
|
37
|
+
# ```ruby
|
38
|
+
# freno = Freno::Client.new(faraday) do |client|
|
39
|
+
# client.options = { raise_on_timeout: false }
|
40
|
+
# end
|
41
|
+
# ```
|
42
|
+
#
|
43
|
+
# These default options can be overridden per request. The given options
|
44
|
+
# are merged into the defaults. The request below would be performed with
|
45
|
+
# the options: `{ raise_on_timeout: false, low_priority: true }`
|
46
|
+
#
|
47
|
+
# ```ruby
|
48
|
+
# freno = Freno::Client.new(faraday) do |client|
|
49
|
+
# client.options = { raise_on_timeout: false }
|
50
|
+
# end
|
51
|
+
#
|
52
|
+
# freno.check?(options: { low_priority: true })
|
53
|
+
# ```
|
54
|
+
#
|
34
55
|
def initialize(faraday)
|
35
56
|
@faraday = faraday
|
36
57
|
@default_store_type = :mysql
|
@@ -47,8 +68,8 @@ module Freno
|
|
47
68
|
#
|
48
69
|
# Returns Result
|
49
70
|
#
|
50
|
-
def check(app: default_app, store_type: default_store_type, store_name: default_store_name, options:
|
51
|
-
perform :check, app: app, store_type: store_type, store_name: store_name, options: options
|
71
|
+
def check(app: default_app, store_type: default_store_type, store_name: default_store_name, options: {})
|
72
|
+
perform :check, app: app, store_type: store_type, store_name: store_name, options: self.options.merge(options)
|
52
73
|
end
|
53
74
|
|
54
75
|
# Provides an interface to Freno"s check-read request
|
@@ -57,8 +78,8 @@ module Freno
|
|
57
78
|
#
|
58
79
|
# Returns Result
|
59
80
|
#
|
60
|
-
def check_read(threshold:, app: default_app, store_type: default_store_type, store_name: default_store_name, options:
|
61
|
-
perform :check_read, app: app, store_type: store_type, store_name: store_name, threshold: threshold, options: options
|
81
|
+
def check_read(threshold:, app: default_app, store_type: default_store_type, store_name: default_store_name, options: {})
|
82
|
+
perform :check_read, app: app, store_type: store_type, store_name: store_name, threshold: threshold, options: self.options.merge(options)
|
62
83
|
end
|
63
84
|
|
64
85
|
# Implements a specific check request to retrieve the consolidated replication
|
@@ -68,8 +89,8 @@ module Freno
|
|
68
89
|
#
|
69
90
|
# Returns Float indicating the replication delay in seconds as reported by Freno.
|
70
91
|
#
|
71
|
-
def replication_delay(app: default_app, store_type: default_store_type, store_name: default_store_name, options:
|
72
|
-
perform :replication_delay, app: app, store_type: store_type, store_name: store_name, options: options
|
92
|
+
def replication_delay(app: default_app, store_type: default_store_type, store_name: default_store_name, options: {})
|
93
|
+
perform :replication_delay, app: app, store_type: store_type, store_name: store_name, options: self.options.merge(options)
|
73
94
|
end
|
74
95
|
|
75
96
|
|
@@ -77,8 +98,8 @@ module Freno
|
|
77
98
|
#
|
78
99
|
# Returns true or false.
|
79
100
|
#
|
80
|
-
def check?(app: default_app, store_type: default_store_type, store_name: default_store_name, options:
|
81
|
-
check(app: app, store_type: store_type, store_name: store_name, options: options).ok?
|
101
|
+
def check?(app: default_app, store_type: default_store_type, store_name: default_store_name, options: {})
|
102
|
+
check(app: app, store_type: store_type, store_name: store_name, options: self.options.merge(options)).ok?
|
82
103
|
end
|
83
104
|
|
84
105
|
# Determines whether it"s OK to read from replicas as replication delay is below
|
@@ -86,8 +107,8 @@ module Freno
|
|
86
107
|
#
|
87
108
|
# Returns true or false.
|
88
109
|
#
|
89
|
-
def check_read?(threshold:, app: default_app, store_type: default_store_type, store_name: default_store_name, options:
|
90
|
-
check_read(threshold: threshold, app: app, store_type: store_type, store_name: store_name, options: options).ok?
|
110
|
+
def check_read?(threshold:, app: default_app, store_type: default_store_type, store_name: default_store_name, options: {})
|
111
|
+
check_read(threshold: threshold, app: app, store_type: store_type, store_name: store_name, options: self.options.merge(options)).ok?
|
91
112
|
end
|
92
113
|
|
93
114
|
# Configures the client to extend the functionality of part or all the API
|
@@ -163,7 +184,7 @@ module Freno
|
|
163
184
|
private
|
164
185
|
|
165
186
|
def perform(request, **kwargs)
|
166
|
-
decorated(request).perform(
|
187
|
+
decorated(request).perform(faraday: faraday, **kwargs)
|
167
188
|
end
|
168
189
|
|
169
190
|
def decorated(request)
|
data/lib/freno/client/request.rb
CHANGED
@@ -12,7 +12,7 @@ module Freno
|
|
12
12
|
attr_reader :raise_on_timeout
|
13
13
|
|
14
14
|
def self.perform(**kwargs)
|
15
|
-
new(kwargs).perform
|
15
|
+
new(**kwargs).perform
|
16
16
|
end
|
17
17
|
|
18
18
|
def initialize(**kwargs)
|
@@ -25,7 +25,7 @@ module Freno
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def perform
|
28
|
-
response = request(verb, path)
|
28
|
+
response = request(verb, path, params)
|
29
29
|
process_response(response)
|
30
30
|
rescue Faraday::TimeoutError => ex
|
31
31
|
raise Freno::Error.new(ex) if raise_on_timeout
|
@@ -36,8 +36,8 @@ module Freno
|
|
36
36
|
|
37
37
|
protected
|
38
38
|
|
39
|
-
def request(verb, path)
|
40
|
-
faraday.send(verb, path)
|
39
|
+
def request(verb, path, params)
|
40
|
+
faraday.send(verb, path, params)
|
41
41
|
end
|
42
42
|
|
43
43
|
def path
|
@@ -52,6 +52,10 @@ module Freno
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
+
def params
|
56
|
+
@params ||= {}
|
57
|
+
end
|
58
|
+
|
55
59
|
def process_response(response)
|
56
60
|
Result.from_faraday_response(response)
|
57
61
|
end
|
@@ -16,6 +16,12 @@ module Freno
|
|
16
16
|
present app: app, store_type: store_type, store_name: store_name
|
17
17
|
end
|
18
18
|
|
19
|
+
# A low priority check is handled slightly differently by Freno. If
|
20
|
+
# the p=low GET parameter is passed, the check will fail for any app
|
21
|
+
# with failed checks within the last second. This failure is returned
|
22
|
+
# quickly, without checking the underlying metric.
|
23
|
+
params[:p] = "low" if options[:low_priority]
|
24
|
+
|
19
25
|
@path = "check/#{app}/#{store_type}/#{store_name}"
|
20
26
|
end
|
21
27
|
end
|
@@ -17,6 +17,12 @@ module Freno
|
|
17
17
|
present app: app, store_type: store_type, store_name: store_name, threshold: threshold
|
18
18
|
end
|
19
19
|
|
20
|
+
# A low priority check is handled slightly differently by Freno. If
|
21
|
+
# the p=low GET parameter is passed, the check will fail for any app
|
22
|
+
# with failed checks within the last second. This failure is returned
|
23
|
+
# quickly, without checking the underlying metric.
|
24
|
+
params[:p] = "low" if options[:low_priority]
|
25
|
+
|
20
26
|
@path = "check-read/#{app}/#{store_type}/#{store_name}/#{threshold.to_f.round(3)}"
|
21
27
|
end
|
22
28
|
end
|
data/lib/freno/client/version.rb
CHANGED
data/lib/freno/throttler.rb
CHANGED
@@ -112,7 +112,17 @@ module Freno
|
|
112
112
|
end
|
113
113
|
|
114
114
|
# This method receives a context to infer the set of stores that it needs to
|
115
|
-
# throttle writes to.
|
115
|
+
# throttle writes to. It can also receive additional options which are
|
116
|
+
# passed to the underlying Check request object:
|
117
|
+
#
|
118
|
+
# ```
|
119
|
+
# throttler = Throttler.new(client: freno_client, app: :my_app)
|
120
|
+
# data.find_in_batches do |batch|
|
121
|
+
# throttler.throttle(:mysqla, low_priority: true) do
|
122
|
+
# update(batch)
|
123
|
+
# end
|
124
|
+
# end
|
125
|
+
# ```
|
116
126
|
#
|
117
127
|
# With that information it asks freno whether all the stores are ok.
|
118
128
|
# In case they are, it executes the given block.
|
@@ -141,7 +151,7 @@ module Freno
|
|
141
151
|
# - "throttler.circuit_open" when the circuit breaker does not allow the
|
142
152
|
# next request, before raising `CircuitOpen`
|
143
153
|
#
|
144
|
-
def throttle(context = nil)
|
154
|
+
def throttle(context = nil, **options)
|
145
155
|
store_names = mapper.call(context)
|
146
156
|
instrument(:called, store_names: store_names)
|
147
157
|
waited = 0
|
@@ -152,7 +162,7 @@ module Freno
|
|
152
162
|
raise CircuitOpen
|
153
163
|
end
|
154
164
|
|
155
|
-
if all_stores_ok?(store_names)
|
165
|
+
if all_stores_ok?(store_names, **options)
|
156
166
|
instrument(:succeeded, store_names: store_names, waited: waited)
|
157
167
|
circuit_breaker.success
|
158
168
|
return yield
|
@@ -187,9 +197,9 @@ module Freno
|
|
187
197
|
raise ArgumentError.new(errors.join("\n")) if errors.any?
|
188
198
|
end
|
189
199
|
|
190
|
-
def all_stores_ok?(store_names)
|
200
|
+
def all_stores_ok?(store_names, **options)
|
191
201
|
store_names.all? do |store_name|
|
192
|
-
client.check?(app: app, store_name: store_name)
|
202
|
+
client.check?(app: app, store_name: store_name, options: options)
|
193
203
|
end
|
194
204
|
rescue Freno::Error => e
|
195
205
|
instrument(:freno_errored, store_names: store_names, error: e)
|
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.0
|
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: '0'
|
20
|
-
type: :development
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rake
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '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'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '5'
|
55
13
|
- !ruby/object:Gem::Dependency
|
56
14
|
name: faraday
|
57
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -59,19 +17,16 @@ 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: []
|
@@ -85,8 +40,6 @@ files:
|
|
85
40
|
- LICENSE.txt
|
86
41
|
- README.md
|
87
42
|
- Rakefile
|
88
|
-
- bin/console
|
89
|
-
- bin/setup
|
90
43
|
- freno-client.gemspec
|
91
44
|
- lib/freno/client.rb
|
92
45
|
- lib/freno/client/errors.rb
|
@@ -102,16 +55,10 @@ files:
|
|
102
55
|
- lib/freno/throttler/errors.rb
|
103
56
|
- lib/freno/throttler/instrumenter.rb
|
104
57
|
- lib/freno/throttler/mapper.rb
|
105
|
-
- script/bootstrap
|
106
|
-
- script/cibuild
|
107
|
-
- script/cibuild-lint
|
108
|
-
- script/console
|
109
|
-
- script/release
|
110
58
|
homepage: https://github.com/github/freno-client
|
111
59
|
licenses:
|
112
60
|
- MIT
|
113
|
-
metadata:
|
114
|
-
allowed_push_host: https://rubygems.org
|
61
|
+
metadata: {}
|
115
62
|
post_install_message:
|
116
63
|
rdoc_options: []
|
117
64
|
require_paths:
|
@@ -120,16 +67,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
120
67
|
requirements:
|
121
68
|
- - ">="
|
122
69
|
- !ruby/object:Gem::Version
|
123
|
-
version: 2.
|
70
|
+
version: 2.5.0
|
124
71
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
72
|
requirements:
|
126
73
|
- - ">="
|
127
74
|
- !ruby/object:Gem::Version
|
128
75
|
version: '0'
|
129
76
|
requirements: []
|
130
|
-
|
131
|
-
rubygems_version: 2.7.6
|
77
|
+
rubygems_version: 3.1.2
|
132
78
|
signing_key:
|
133
79
|
specification_version: 4
|
134
|
-
summary: A library for interacting with
|
80
|
+
summary: A library for interacting with Freno, the throttler service
|
135
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/cibuild-lint
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 rubocop
|
data/script/console
DELETED