stoplight 2.1.3 → 2.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +35 -1
- data/lib/stoplight.rb +2 -0
- data/lib/stoplight/failure.rb +9 -5
- data/lib/stoplight/notifier/pagerduty.rb +21 -0
- data/lib/stoplight/notifier/rollbar.rb +39 -0
- data/lib/stoplight/version.rb +1 -1
- data/spec/stoplight/default_spec.rb +1 -1
- data/spec/stoplight/failure_spec.rb +5 -0
- data/spec/stoplight/notifier/bugsnag_spec.rb +1 -3
- data/spec/stoplight/notifier/pagerduty_spec.rb +40 -0
- data/spec/stoplight/notifier/rollbar_spec.rb +90 -0
- metadata +29 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e26d25f913bb759dccd62f2b12576cbe51550753c3c6428fb16cdb6052559928
|
4
|
+
data.tar.gz: 6cbfd0ccd62da40cb335e671c8ba2d84348652e206520355fa651eb2276e16ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a186fc199cd54411996a65c369c687dc1165ecb2115699c72e6aa005f1b3d5b0da3b5f90402d2c49b12d73ca708628b09f5b9ba02e57c127ce89a33f8dc16cd2
|
7
|
+
data.tar.gz: 7ee5b81cad78ed7aaa7200aedf74cba3af8aff5b1e95940c572ca93bbefa28676ceb507ef04ce63bef28d9b6e7dcb2590653dd06704cf14b561653662c9fa30b
|
data/README.md
CHANGED
@@ -32,6 +32,8 @@ Check out [stoplight-admin][] for controlling your stoplights.
|
|
32
32
|
- [HipChat](#hipchat)
|
33
33
|
- [Honeybadger](#honeybadger)
|
34
34
|
- [Logger](#logger)
|
35
|
+
- [Pagerduty](#pagerduty)
|
36
|
+
- [Rollbar](#rollbar)
|
35
37
|
- [Sentry](#sentry)
|
36
38
|
- [Slack](#slack)
|
37
39
|
- [Rails](#rails-1)
|
@@ -204,7 +206,7 @@ The default threshold is `3`.
|
|
204
206
|
### Custom cool off time
|
205
207
|
|
206
208
|
Stoplights will automatically attempt to recover after a certain amount of
|
207
|
-
time. A light in the red state for longer than the cool
|
209
|
+
time. A light in the red state for longer than the cool off period will
|
208
210
|
transition to the yellow state. This cool off time is customizable.
|
209
211
|
|
210
212
|
``` rb
|
@@ -356,6 +358,36 @@ Stoplight::Light.default_notifiers += [notifier]
|
|
356
358
|
# => [#<Stoplight::Notifier::IO:...>, #<Stoplight::Notifier::Logger:...>]
|
357
359
|
```
|
358
360
|
|
361
|
+
#### Pagerduty
|
362
|
+
|
363
|
+
Make sure you have [the Pagerduty gem][] (`~> 2.1`) installed before configuring
|
364
|
+
Stoplight.
|
365
|
+
|
366
|
+
``` rb
|
367
|
+
require 'pagerduty'
|
368
|
+
# => true
|
369
|
+
pagerduty = Pagerduty.new('http://www.example.com/webhook-url')
|
370
|
+
# => #<Pagerduty:...>
|
371
|
+
notifier = Stoplight::Notifier::Pagerduty.new(pagerduty)
|
372
|
+
# => #<Stoplight::Notifier::Pagerduty:...>
|
373
|
+
Stoplight::Light.default_notifiers += [notifier]
|
374
|
+
# => [#<Stoplight::Notifier::IO:...>, #<Stoplight::Notifier::Pagerduty:...>]
|
375
|
+
```
|
376
|
+
|
377
|
+
#### Rollbar
|
378
|
+
|
379
|
+
Make sure you have [the Rollbar gem][] (`~> 2.0`) installed before configuring
|
380
|
+
Stoplight.
|
381
|
+
|
382
|
+
``` rb
|
383
|
+
require 'rollbar'
|
384
|
+
# => true
|
385
|
+
notifier = Stoplight::Notifier::Rollbar.new(Rollbar)
|
386
|
+
# => #<Stoplight::Notifier::Rollbar:...>
|
387
|
+
Stoplight::Light.default_notifiers += [notifier]
|
388
|
+
# => [#<Stoplight::Notifier::IO:...>, #<Stoplight::Notifier::Rollbar:...>]
|
389
|
+
```
|
390
|
+
|
359
391
|
#### Sentry
|
360
392
|
|
361
393
|
Make sure you have [the Sentry gem][] (`~> 1.2`) installed before configuring
|
@@ -490,8 +522,10 @@ Stoplight is licensed under [the MIT License][].
|
|
490
522
|
[the HipChat gem]: https://rubygems.org/gems/hipchat
|
491
523
|
[the Honeybadger gem]: https://rubygems.org/gems/honeybadger
|
492
524
|
[the Logger class]: http://ruby-doc.org/stdlib-2.2.3/libdoc/logger/rdoc/Logger.html
|
525
|
+
[the Rollbar gem]: https://rubygems.org/gems/rollbar
|
493
526
|
[the Sentry gem]: https://rubygems.org/gems/sentry-raven
|
494
527
|
[the Slack gem]: https://rubygems.org/gems/slack-notifier
|
528
|
+
[the Pagerduty gem]: https://rubygems.org/gems/pagerduty
|
495
529
|
[@camdez]: https://github.com/camdez
|
496
530
|
[@tfausak]: https://github.com/tfausak
|
497
531
|
[@orgsync]: https://github.com/OrgSync
|
data/lib/stoplight.rb
CHANGED
@@ -24,7 +24,9 @@ require 'stoplight/notifier/hip_chat'
|
|
24
24
|
require 'stoplight/notifier/honeybadger'
|
25
25
|
require 'stoplight/notifier/io'
|
26
26
|
require 'stoplight/notifier/logger'
|
27
|
+
require 'stoplight/notifier/pagerduty'
|
27
28
|
require 'stoplight/notifier/raven'
|
29
|
+
require 'stoplight/notifier/rollbar'
|
28
30
|
require 'stoplight/notifier/slack'
|
29
31
|
|
30
32
|
require 'stoplight/default'
|
data/lib/stoplight/failure.rb
CHANGED
@@ -52,14 +52,18 @@ module Stoplight
|
|
52
52
|
time == other.time
|
53
53
|
end
|
54
54
|
|
55
|
+
# @param options [Object, nil]
|
55
56
|
# @return [String]
|
56
|
-
def to_json
|
57
|
+
def to_json(options = nil)
|
57
58
|
JSON.generate(
|
58
|
-
|
59
|
-
|
60
|
-
|
59
|
+
{
|
60
|
+
error: {
|
61
|
+
class: error_class,
|
62
|
+
message: error_message
|
63
|
+
},
|
64
|
+
time: time.strftime(TIME_FORMAT)
|
61
65
|
},
|
62
|
-
|
66
|
+
options
|
63
67
|
)
|
64
68
|
end
|
65
69
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module Stoplight
|
4
|
+
module Notifier
|
5
|
+
# @see Base
|
6
|
+
class Pagerduty < Base
|
7
|
+
include Generic
|
8
|
+
|
9
|
+
# @return [::Pagerduty]
|
10
|
+
def pagerduty
|
11
|
+
@object
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def put(message)
|
17
|
+
pagerduty.trigger(message)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module Stoplight
|
4
|
+
module Notifier
|
5
|
+
# @see Base
|
6
|
+
class Rollbar < Base
|
7
|
+
DEFAULT_OPTIONS = {
|
8
|
+
severity: 'info'
|
9
|
+
}.freeze
|
10
|
+
|
11
|
+
StoplightStatusChange = Class.new(Error::Base)
|
12
|
+
|
13
|
+
# @return [Proc]
|
14
|
+
attr_reader :formatter
|
15
|
+
# @return [::Rollbar]
|
16
|
+
attr_reader :rollbar
|
17
|
+
# @return [Hash{Symbol => Object}]
|
18
|
+
attr_reader :options
|
19
|
+
|
20
|
+
# @param rollbar [::Rollbar]
|
21
|
+
# @param formatter [Proc, nil]
|
22
|
+
# @param options [Hash{Symbol => Object}]
|
23
|
+
# @option options [String] :severity
|
24
|
+
def initialize(rollbar, formatter = nil, options = {})
|
25
|
+
@rollbar = rollbar
|
26
|
+
@formatter = formatter || Default::FORMATTER
|
27
|
+
@options = DEFAULT_OPTIONS.merge(options)
|
28
|
+
end
|
29
|
+
|
30
|
+
def notify(light, from_color, to_color, error)
|
31
|
+
formatter.call(light, from_color, to_color, error).tap do |message|
|
32
|
+
severity = options.fetch(:severity)
|
33
|
+
exception = StoplightStatusChange.new(message)
|
34
|
+
rollbar.__send__(severity, exception)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/stoplight/version.rb
CHANGED
@@ -89,6 +89,11 @@ RSpec.describe Stoplight::Failure do
|
|
89
89
|
expect(described_class.new(error_class, error_message, time).to_json)
|
90
90
|
.to eql(json)
|
91
91
|
end
|
92
|
+
|
93
|
+
it 'generates JSON with options' do
|
94
|
+
expect(described_class.new(error_class, error_message, time).to_json({}))
|
95
|
+
.to eql(json)
|
96
|
+
end
|
92
97
|
end
|
93
98
|
|
94
99
|
describe '::TIME_FORMAT' do
|
@@ -7,8 +7,6 @@ module Bugsnag
|
|
7
7
|
end
|
8
8
|
|
9
9
|
RSpec.describe Stoplight::Notifier::Bugsnag do
|
10
|
-
StoplightStatusChange = Stoplight::Notifier::Bugsnag::StoplightStatusChange
|
11
|
-
|
12
10
|
it 'is a class' do
|
13
11
|
expect(described_class).to be_a(Class)
|
14
12
|
end
|
@@ -65,7 +63,7 @@ RSpec.describe Stoplight::Notifier::Bugsnag do
|
|
65
63
|
end
|
66
64
|
|
67
65
|
before do
|
68
|
-
status_change = StoplightStatusChange.new(message)
|
66
|
+
status_change = described_class::StoplightStatusChange.new(message)
|
69
67
|
expect(bugsnag).to receive(:notify).with(status_change, severity: 'info')
|
70
68
|
end
|
71
69
|
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'pagerduty'
|
5
|
+
|
6
|
+
RSpec.describe Stoplight::Notifier::Pagerduty do
|
7
|
+
it_behaves_like 'a generic notifier'
|
8
|
+
|
9
|
+
it 'is a class' do
|
10
|
+
expect(described_class).to be_a(Class)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'is a subclass of Base' do
|
14
|
+
expect(described_class).to be < Stoplight::Notifier::Base
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#pagerduty' do
|
18
|
+
it 'reads Pagerduty client' do
|
19
|
+
pagerduty = Pagerduty.new('WEBHOOK_URL')
|
20
|
+
expect(described_class.new(pagerduty).pagerduty).to eql(pagerduty)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#notify' do
|
25
|
+
let(:light) { Stoplight::Light.new(name, &code) }
|
26
|
+
let(:name) { ('a'..'z').to_a.shuffle.join }
|
27
|
+
let(:code) { -> {} }
|
28
|
+
let(:from_color) { Stoplight::Color::GREEN }
|
29
|
+
let(:to_color) { Stoplight::Color::RED }
|
30
|
+
let(:notifier) { described_class.new(pagerduty) }
|
31
|
+
let(:pagerduty) { double(Pagerduty).as_null_object }
|
32
|
+
|
33
|
+
it 'pings Pagerduty' do
|
34
|
+
error = nil
|
35
|
+
message = notifier.formatter.call(light, from_color, to_color, error)
|
36
|
+
expect(pagerduty).to receive(:trigger).with(message)
|
37
|
+
notifier.notify(light, from_color, to_color, error)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
# require 'rollbar'
|
6
|
+
module Rollbar
|
7
|
+
end
|
8
|
+
|
9
|
+
RSpec.describe Stoplight::Notifier::Rollbar do
|
10
|
+
it 'is a class' do
|
11
|
+
expect(described_class).to be_a(Class)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'is a subclass of Base' do
|
15
|
+
expect(described_class).to be < Stoplight::Notifier::Base
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#formatter' do
|
19
|
+
it 'is initially the default' do
|
20
|
+
expect(described_class.new(nil, nil).formatter)
|
21
|
+
.to eql(Stoplight::Default::FORMATTER)
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'reads the formatter' do
|
25
|
+
formatter = proc {}
|
26
|
+
expect(described_class.new(nil, formatter).formatter)
|
27
|
+
.to eql(formatter)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#options' do
|
32
|
+
it 'is initially the default' do
|
33
|
+
expect(described_class.new(nil, nil).options)
|
34
|
+
.to eql(Stoplight::Notifier::Rollbar::DEFAULT_OPTIONS)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'reads the options' do
|
38
|
+
options = { key: :value }
|
39
|
+
expect(described_class.new(nil, nil, options).options)
|
40
|
+
.to eql(Stoplight::Notifier::Rollbar::DEFAULT_OPTIONS.merge(options))
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#rollbar' do
|
45
|
+
it 'reads the Rollbar client' do
|
46
|
+
client = Rollbar
|
47
|
+
expect(described_class.new(client, nil).rollbar)
|
48
|
+
.to eql(client)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '#notify' do
|
53
|
+
let(:light) { Stoplight::Light.new(name, &code) }
|
54
|
+
let(:name) { ('a'..'z').to_a.shuffle.join }
|
55
|
+
let(:code) { -> {} }
|
56
|
+
let(:from_color) { Stoplight::Color::GREEN }
|
57
|
+
let(:to_color) { Stoplight::Color::RED }
|
58
|
+
let(:notifier) { described_class.new(rollbar) }
|
59
|
+
let(:rollbar) { Rollbar }
|
60
|
+
|
61
|
+
subject(:result) do
|
62
|
+
notifier.notify(light, from_color, to_color, error)
|
63
|
+
end
|
64
|
+
|
65
|
+
before do
|
66
|
+
status_change = described_class::StoplightStatusChange.new(message)
|
67
|
+
expect(rollbar).to receive(:info).with(status_change)
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'when no error given' do
|
71
|
+
let(:error) { nil }
|
72
|
+
|
73
|
+
it 'logs message' do
|
74
|
+
expect(result).to eq(message)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'when message with an error given' do
|
79
|
+
let(:error) { ZeroDivisionError.new('divided by 0') }
|
80
|
+
|
81
|
+
it 'logs message' do
|
82
|
+
expect(result).to eq(message)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def message
|
87
|
+
notifier.formatter.call(light, from_color, to_color, error)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stoplight
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1
|
4
|
+
version: 2.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cameron Desautels
|
8
8
|
- Taylor Fausak
|
9
9
|
- Justin Steffy
|
10
|
-
autorequire:
|
10
|
+
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2020-07-16 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: benchmark-ips
|
@@ -97,19 +97,19 @@ dependencies:
|
|
97
97
|
- !ruby/object:Gem::Version
|
98
98
|
version: '2.5'
|
99
99
|
- !ruby/object:Gem::Dependency
|
100
|
-
name:
|
100
|
+
name: pagerduty
|
101
101
|
requirement: !ruby/object:Gem::Requirement
|
102
102
|
requirements:
|
103
103
|
- - "~>"
|
104
104
|
- !ruby/object:Gem::Version
|
105
|
-
version:
|
105
|
+
version: 2.1.1
|
106
106
|
type: :development
|
107
107
|
prerelease: false
|
108
108
|
version_requirements: !ruby/object:Gem::Requirement
|
109
109
|
requirements:
|
110
110
|
- - "~>"
|
111
111
|
- !ruby/object:Gem::Version
|
112
|
-
version:
|
112
|
+
version: 2.1.1
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
name: rake
|
115
115
|
requirement: !ruby/object:Gem::Requirement
|
@@ -166,6 +166,20 @@ dependencies:
|
|
166
166
|
- - "~>"
|
167
167
|
- !ruby/object:Gem::Version
|
168
168
|
version: 0.40.0
|
169
|
+
- !ruby/object:Gem::Dependency
|
170
|
+
name: sentry-raven
|
171
|
+
requirement: !ruby/object:Gem::Requirement
|
172
|
+
requirements:
|
173
|
+
- - "~>"
|
174
|
+
- !ruby/object:Gem::Version
|
175
|
+
version: '1.2'
|
176
|
+
type: :development
|
177
|
+
prerelease: false
|
178
|
+
version_requirements: !ruby/object:Gem::Requirement
|
179
|
+
requirements:
|
180
|
+
- - "~>"
|
181
|
+
- !ruby/object:Gem::Version
|
182
|
+
version: '1.2'
|
169
183
|
- !ruby/object:Gem::Dependency
|
170
184
|
name: slack-notifier
|
171
185
|
requirement: !ruby/object:Gem::Requirement
|
@@ -225,7 +239,9 @@ files:
|
|
225
239
|
- lib/stoplight/notifier/honeybadger.rb
|
226
240
|
- lib/stoplight/notifier/io.rb
|
227
241
|
- lib/stoplight/notifier/logger.rb
|
242
|
+
- lib/stoplight/notifier/pagerduty.rb
|
228
243
|
- lib/stoplight/notifier/raven.rb
|
244
|
+
- lib/stoplight/notifier/rollbar.rb
|
229
245
|
- lib/stoplight/notifier/slack.rb
|
230
246
|
- lib/stoplight/state.rb
|
231
247
|
- lib/stoplight/version.rb
|
@@ -247,7 +263,9 @@ files:
|
|
247
263
|
- spec/stoplight/notifier/honeybadger_spec.rb
|
248
264
|
- spec/stoplight/notifier/io_spec.rb
|
249
265
|
- spec/stoplight/notifier/logger_spec.rb
|
266
|
+
- spec/stoplight/notifier/pagerduty_spec.rb
|
250
267
|
- spec/stoplight/notifier/raven_spec.rb
|
268
|
+
- spec/stoplight/notifier/rollbar_spec.rb
|
251
269
|
- spec/stoplight/notifier/slack_spec.rb
|
252
270
|
- spec/stoplight/notifier_spec.rb
|
253
271
|
- spec/stoplight/state_spec.rb
|
@@ -257,7 +275,7 @@ homepage: https://github.com/orgsync/stoplight
|
|
257
275
|
licenses:
|
258
276
|
- MIT
|
259
277
|
metadata: {}
|
260
|
-
post_install_message:
|
278
|
+
post_install_message:
|
261
279
|
rdoc_options: []
|
262
280
|
require_paths:
|
263
281
|
- lib
|
@@ -272,9 +290,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
272
290
|
- !ruby/object:Gem::Version
|
273
291
|
version: '0'
|
274
292
|
requirements: []
|
275
|
-
|
276
|
-
|
277
|
-
signing_key:
|
293
|
+
rubygems_version: 3.1.2
|
294
|
+
signing_key:
|
278
295
|
specification_version: 4
|
279
296
|
summary: Traffic control for code.
|
280
297
|
test_files:
|
@@ -282,12 +299,14 @@ test_files:
|
|
282
299
|
- spec/stoplight_spec.rb
|
283
300
|
- spec/stoplight/error_spec.rb
|
284
301
|
- spec/stoplight/failure_spec.rb
|
302
|
+
- spec/stoplight/notifier/pagerduty_spec.rb
|
285
303
|
- spec/stoplight/notifier/raven_spec.rb
|
286
304
|
- spec/stoplight/notifier/io_spec.rb
|
287
305
|
- spec/stoplight/notifier/logger_spec.rb
|
288
306
|
- spec/stoplight/notifier/honeybadger_spec.rb
|
289
307
|
- spec/stoplight/notifier/generic_spec.rb
|
290
308
|
- spec/stoplight/notifier/slack_spec.rb
|
309
|
+
- spec/stoplight/notifier/rollbar_spec.rb
|
291
310
|
- spec/stoplight/notifier/base_spec.rb
|
292
311
|
- spec/stoplight/notifier/bugsnag_spec.rb
|
293
312
|
- spec/stoplight/notifier/hip_chat_spec.rb
|