exception_handling 2.6.1 → 2.7.0.pre.1

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.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/.jenkins/Jenkinsfile +8 -24
  4. data/CHANGELOG.md +8 -1
  5. data/Gemfile +4 -4
  6. data/Gemfile.lock +19 -29
  7. data/Rakefile +6 -7
  8. data/lib/exception_handling/log_stub_error.rb +1 -2
  9. data/lib/exception_handling/logging_methods.rb +33 -0
  10. data/lib/exception_handling/methods.rb +6 -53
  11. data/lib/exception_handling/testing.rb +20 -10
  12. data/lib/exception_handling/version.rb +1 -1
  13. data/lib/exception_handling.rb +2 -2
  14. data/{spec → test}/helpers/controller_helpers.rb +0 -0
  15. data/{spec → test}/helpers/exception_helpers.rb +2 -2
  16. data/{spec → test}/rake_test_warning_false.rb +0 -0
  17. data/{spec/spec_helper.rb → test/test_helper.rb} +39 -50
  18. data/test/unit/exception_handling/exception_catalog_test.rb +85 -0
  19. data/test/unit/exception_handling/exception_description_test.rb +82 -0
  20. data/{spec/unit/exception_handling/exception_info_spec.rb → test/unit/exception_handling/exception_info_test.rb} +107 -105
  21. data/{spec/unit/exception_handling/honeybadger_callbacks_spec.rb → test/unit/exception_handling/honeybadger_callbacks_test.rb} +20 -20
  22. data/{spec/unit/exception_handling/log_error_stub_spec.rb → test/unit/exception_handling/log_error_stub_test.rb} +22 -38
  23. data/test/unit/exception_handling/logging_methods_test.rb +37 -0
  24. data/{spec/unit/exception_handling/mailer_spec.rb → test/unit/exception_handling/mailer_test.rb} +17 -17
  25. data/test/unit/exception_handling/methods_test.rb +105 -0
  26. data/test/unit/exception_handling/sensu_test.rb +52 -0
  27. data/{spec/unit/exception_handling_spec.rb → test/unit/exception_handling_test.rb} +329 -325
  28. metadata +36 -34
  29. data/.rspec +0 -3
  30. data/spec/unit/exception_handling/exception_catalog_spec.rb +0 -85
  31. data/spec/unit/exception_handling/exception_description_spec.rb +0 -82
  32. data/spec/unit/exception_handling/methods_spec.rb +0 -84
  33. data/spec/unit/exception_handling/sensu_spec.rb +0 -51
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exception_handling
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.1
4
+ version: 2.7.0.pre.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Invoca
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-14 00:00:00.000000000 Z
11
+ date: 2020-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionmailer
@@ -122,7 +122,6 @@ files:
122
122
  - ".gitignore"
123
123
  - ".jenkins/Jenkinsfile"
124
124
  - ".jenkins/ruby_build_pod.yml"
125
- - ".rspec"
126
125
  - ".rubocop.yml"
127
126
  - ".ruby-version"
128
127
  - Appraisals
@@ -144,24 +143,26 @@ files:
144
143
  - lib/exception_handling/exception_info.rb
145
144
  - lib/exception_handling/honeybadger_callbacks.rb
146
145
  - lib/exception_handling/log_stub_error.rb
146
+ - lib/exception_handling/logging_methods.rb
147
147
  - lib/exception_handling/mailer.rb
148
148
  - lib/exception_handling/methods.rb
149
149
  - lib/exception_handling/sensu.rb
150
150
  - lib/exception_handling/testing.rb
151
151
  - lib/exception_handling/version.rb
152
- - spec/helpers/controller_helpers.rb
153
- - spec/helpers/exception_helpers.rb
154
- - spec/rake_test_warning_false.rb
155
- - spec/spec_helper.rb
156
- - spec/unit/exception_handling/exception_catalog_spec.rb
157
- - spec/unit/exception_handling/exception_description_spec.rb
158
- - spec/unit/exception_handling/exception_info_spec.rb
159
- - spec/unit/exception_handling/honeybadger_callbacks_spec.rb
160
- - spec/unit/exception_handling/log_error_stub_spec.rb
161
- - spec/unit/exception_handling/mailer_spec.rb
162
- - spec/unit/exception_handling/methods_spec.rb
163
- - spec/unit/exception_handling/sensu_spec.rb
164
- - spec/unit/exception_handling_spec.rb
152
+ - test/helpers/controller_helpers.rb
153
+ - test/helpers/exception_helpers.rb
154
+ - test/rake_test_warning_false.rb
155
+ - test/test_helper.rb
156
+ - test/unit/exception_handling/exception_catalog_test.rb
157
+ - test/unit/exception_handling/exception_description_test.rb
158
+ - test/unit/exception_handling/exception_info_test.rb
159
+ - test/unit/exception_handling/honeybadger_callbacks_test.rb
160
+ - test/unit/exception_handling/log_error_stub_test.rb
161
+ - test/unit/exception_handling/logging_methods_test.rb
162
+ - test/unit/exception_handling/mailer_test.rb
163
+ - test/unit/exception_handling/methods_test.rb
164
+ - test/unit/exception_handling/sensu_test.rb
165
+ - test/unit/exception_handling_test.rb
165
166
  - views/exception_handling/mailer/escalate_custom.html.erb
166
167
  - views/exception_handling/mailer/escalation_notification.html.erb
167
168
  - views/exception_handling/mailer/log_parser_exception_notification.html.erb
@@ -170,7 +171,7 @@ licenses: []
170
171
  metadata:
171
172
  source_code_uri: https://github.com/Invoca/exception_handling
172
173
  allowed_push_host: https://rubygems.org
173
- post_install_message:
174
+ post_install_message:
174
175
  rdoc_options: []
175
176
  require_paths:
176
177
  - lib
@@ -181,26 +182,27 @@ required_ruby_version: !ruby/object:Gem::Requirement
181
182
  version: '0'
182
183
  required_rubygems_version: !ruby/object:Gem::Requirement
183
184
  requirements:
184
- - - ">="
185
+ - - ">"
185
186
  - !ruby/object:Gem::Version
186
- version: '0'
187
+ version: 1.3.1
187
188
  requirements: []
188
189
  rubygems_version: 3.0.3
189
- signing_key:
190
+ signing_key:
190
191
  specification_version: 4
191
192
  summary: Invoca's exception handling logger/emailer layer, based on exception_notifier.
192
193
  Works with Rails or EventMachine or EventMachine+Synchrony.
193
194
  test_files:
194
- - spec/helpers/controller_helpers.rb
195
- - spec/helpers/exception_helpers.rb
196
- - spec/rake_test_warning_false.rb
197
- - spec/spec_helper.rb
198
- - spec/unit/exception_handling/exception_catalog_spec.rb
199
- - spec/unit/exception_handling/exception_description_spec.rb
200
- - spec/unit/exception_handling/exception_info_spec.rb
201
- - spec/unit/exception_handling/honeybadger_callbacks_spec.rb
202
- - spec/unit/exception_handling/log_error_stub_spec.rb
203
- - spec/unit/exception_handling/mailer_spec.rb
204
- - spec/unit/exception_handling/methods_spec.rb
205
- - spec/unit/exception_handling/sensu_spec.rb
206
- - spec/unit/exception_handling_spec.rb
195
+ - test/helpers/controller_helpers.rb
196
+ - test/helpers/exception_helpers.rb
197
+ - test/rake_test_warning_false.rb
198
+ - test/test_helper.rb
199
+ - test/unit/exception_handling/exception_catalog_test.rb
200
+ - test/unit/exception_handling/exception_description_test.rb
201
+ - test/unit/exception_handling/exception_info_test.rb
202
+ - test/unit/exception_handling/honeybadger_callbacks_test.rb
203
+ - test/unit/exception_handling/log_error_stub_test.rb
204
+ - test/unit/exception_handling/logging_methods_test.rb
205
+ - test/unit/exception_handling/mailer_test.rb
206
+ - test/unit/exception_handling/methods_test.rb
207
+ - test/unit/exception_handling/sensu_test.rb
208
+ - test/unit/exception_handling_test.rb
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --require spec_helper
2
- --format progress
3
- --color
@@ -1,85 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require File.expand_path('../../spec_helper', __dir__)
4
-
5
- module ExceptionHandling
6
- describe ExceptionCatalog do
7
-
8
- context "With stubbed yaml content" do
9
- before do
10
- filter_list = { exception1: { error: "my error message" },
11
- exception2: { error: "some other message", session: "misc data" } }
12
- allow(YAML).to receive(:load_file) { filter_list }
13
-
14
- # bump modified time up to get the above filter loaded
15
- allow(File).to receive(:mtime) { incrementing_mtime }
16
- end
17
-
18
- context "with loaded data" do
19
- before do
20
- allow(File).to receive(:mtime) { incrementing_mtime }
21
- @exception_catalog = ExceptionCatalog.new(ExceptionHandling.filter_list_filename)
22
- @exception_catalog.send :load_file
23
- end
24
-
25
- it "have loaded filters" do
26
- expect(@exception_catalog.instance_eval("@filters").size).to eq(2)
27
- end
28
-
29
- it "find messages in the catalog" do
30
- expect(!@exception_catalog.find(error: "Scott says unlikely to ever match")).to be_truthy
31
- end
32
-
33
- it "find matching data" do
34
- exception_description = @exception_catalog.find(error: "this is my error message, which should match something")
35
- expect(exception_description).to be_truthy
36
- expect(exception_description.filter_name).to eq(:exception1)
37
- end
38
- end
39
-
40
- it "write errors loading the yaml file directly to the log file" do
41
- @exception_catalog = ExceptionCatalog.new(ExceptionHandling.filter_list_filename)
42
-
43
- expect(ExceptionHandling).to receive(:log_error).never
44
- expect(ExceptionHandling).to receive(:write_exception_to_log).with(anything, "ExceptionCatalog#refresh_filters: ./config/exception_filters.yml", anything)
45
- expect(@exception_catalog).to receive(:load_file) { raise "noooooo" }
46
-
47
- @exception_catalog.find({})
48
- end
49
- end
50
-
51
- context "with live yaml content" do
52
- before do
53
- @filename = File.expand_path('../../../config/exception_filters.yml', __dir__)
54
- @exception_catalog = ExceptionCatalog.new(@filename)
55
- expect do
56
- @exception_catalog.send :load_file
57
- end.not_to raise_error
58
- end
59
-
60
- it "load the filter data" do
61
- expect(!@exception_catalog.find(error: "Scott says unlikely to ever match")).to be_truthy
62
- expect(!@exception_catalog.find(error: "Scott says unlikely to ever match")).to be_truthy
63
- end
64
- end
65
-
66
- context "with no yaml content" do
67
- before do
68
- @exception_catalog = ExceptionCatalog.new(nil)
69
- end
70
-
71
- it "not load filter data" do
72
- expect(ExceptionHandling).to receive(:write_exception_to_log).with(any_args).never
73
- @exception_catalog.find(error: "Scott says unlikely to ever match")
74
- end
75
- end
76
-
77
- private
78
-
79
- def incrementing_mtime
80
- @mtime ||= Time.now
81
- @mtime += 1.day
82
- end
83
-
84
- end
85
- end
@@ -1,82 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require File.expand_path('../../spec_helper', __dir__)
4
-
5
- module ExceptionHandling
6
- describe ExceptionDescription do
7
-
8
- context "Filter" do
9
- it "allow direct matching of strings" do
10
- @f = ExceptionDescription.new(:filter1, error: "my error message")
11
- expect(@f.match?('error' => "my error message")).to be_truthy
12
- end
13
-
14
- it "allow direct matching of strings on with symbol keys" do
15
- @f = ExceptionDescription.new(:filter1, error: "my error message")
16
- expect(@f.match?(error: "my error message")).to be_truthy
17
- end
18
-
19
- it "allow wildcards to cross line boundries" do
20
- @f = ExceptionDescription.new(:filter1, error: "my error message.*with multiple lines")
21
- expect(@f.match?(error: "my error message\nwith more than one, with multiple lines")).to be_truthy
22
- end
23
-
24
- it "complain when no regexps have a value" do
25
- expect { ExceptionDescription.new(:filter1, error: nil) }.to raise_exception(ArgumentError, /has all blank regexes/)
26
- end
27
-
28
- it "report when an invalid key is passed" do
29
- expect { ExceptionDescription.new(:filter1, error: "my error message", not_a_parameter: false) }.to raise_exception(ArgumentError, "Unknown section: not_a_parameter")
30
- end
31
-
32
- it "allow send_to_honeybadger to be specified and have it disabled by default" do
33
- expect(!ExceptionDescription.new(:filter1, error: "my error message", send_to_honeybadger: false).send_to_honeybadger).to be_truthy
34
- expect(ExceptionDescription.new(:filter1, error: "my error message", send_to_honeybadger: true).send_to_honeybadger).to be_truthy
35
- expect(!ExceptionDescription.new(:filter1, error: "my error message").send_to_honeybadger).to be_truthy
36
- end
37
-
38
- it "allow send_metric to be configured" do
39
- expect(!ExceptionDescription.new(:filter1, error: "my error message", send_metric: false).send_metric).to be_truthy
40
- expect(ExceptionDescription.new(:filter1, error: "my error message").send_metric).to be_truthy
41
- end
42
-
43
- it "provide metric name" do
44
- expect(ExceptionDescription.new(:filter1, error: "my error message").metric_name).to eq("filter1")
45
- expect(ExceptionDescription.new(:filter1, error: "my error message", metric_name: :some_other_metric_name).metric_name).to eq("some_other_metric_name")
46
- end
47
-
48
- it "replace spaces in metric name" do
49
- @f = ExceptionDescription.new(:"filter has spaces", error: "my error message")
50
- expect(@f.metric_name).to eq( "filter_has_spaces")
51
- end
52
-
53
- it "allow notes to be recorded" do
54
- expect(ExceptionDescription.new(:filter1, error: "my error message").notes).to be_nil
55
- expect(ExceptionDescription.new(:filter1, error: "my error message", notes: "a long string").notes).to eq("a long string")
56
- end
57
-
58
- it "not consider config options in the filter set" do
59
- expect(ExceptionDescription.new(:filter1, error: "my error message", send_metric: false).match?(error: "my error message")).to be_truthy
60
- expect(ExceptionDescription.new(:filter1, error: "my error message", metric_name: "false").match?(error: "my error message")).to be_truthy
61
- expect(ExceptionDescription.new(:filter1, error: "my error message", notes: "hey").match?(error: "my error message")).to be_truthy
62
- end
63
-
64
- it "provide exception details" do
65
- exception_description = ExceptionDescription.new(:filter1, error: "my error message", notes: "hey")
66
-
67
- expected = { "send_metric" => true, "metric_name" => "filter1", "notes" => "hey" }
68
-
69
- expect(exception_description.exception_data).to eq( expected)
70
- end
71
-
72
- it "match multiple email addresses" do
73
- mobi = "ExceptionHandling::Warning: LoginAttempt::IPAddressLocked: failed login for 'mcc@mobistreak.com'"
74
- credit = "ExceptionHandling::Warning: LoginAttempt::IPAddressLocked: failed login for 'damon@thecreditpros.com'"
75
-
76
- exception_description = ExceptionDescription.new(:filter1, error: "ExceptionHandling::Warning: LoginAttempt::IPAddressLocked: failed login for '(mcc\@mobistreak|damon\@thecreditpros).com'")
77
- expect(exception_description.match?(error: mobi)).to be_truthy
78
- expect(exception_description.match?(error: credit)).to be_truthy
79
- end
80
- end
81
- end
82
- end
@@ -1,84 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require File.expand_path('../../spec_helper', __dir__)
4
-
5
- require "exception_handling/testing"
6
- require_relative '../../helpers/exception_helpers.rb'
7
-
8
- module ExceptionHandling
9
- describe Methods do
10
- include ExceptionHelpers
11
-
12
- def dont_stub_log_error
13
- true
14
- end
15
-
16
- context "ExceptionHandling.Methods" do
17
- before do
18
- @controller = Testing::ControllerStub.new
19
- ExceptionHandling.stub_handler = nil
20
- end
21
-
22
- it "set the around filter" do
23
- expect(Testing::ControllerStub.around_filter_method).to eq(:set_current_controller)
24
- expect(ExceptionHandling.current_controller).to be_nil
25
- @controller.simulate_around_filter do
26
- expect(ExceptionHandling.current_controller).to eq(@controller)
27
- end
28
- expect(ExceptionHandling.current_controller).to be_nil
29
- end
30
-
31
- it "use the current_controller when available" do
32
- capture_notifications
33
-
34
- expect(ExceptionHandling.logger).to receive(:fatal).with(/blah/, anything).at_least(:once)
35
- @controller.simulate_around_filter do
36
- ExceptionHandling.log_error(ArgumentError.new("blah"))
37
- expect(sent_notifications.size).to eq(1)
38
- expect(/#{Regexp.new(Regexp.escape(@controller.request.request_uri))}/).to match(sent_notifications.last.enhanced_data['request'].to_s)
39
- end
40
- end
41
-
42
- it "report long running controller action" do
43
- expect(@controller.send(:long_controller_action_timeout)).to eq(2)
44
- expect(ExceptionHandling).to receive(:log_error).with(/Long controller action detected in #{@controller.class.name.split("::").last}::test_action/, anything, anything)
45
- @controller.simulate_around_filter do
46
- sleep(3)
47
- end
48
- end
49
-
50
- it "not report long running controller actions if it is less than the timeout" do
51
- expect(@controller.send(:long_controller_action_timeout)).to eq(2)
52
- allow(ExceptionHandling).to receive(:log_error).and_return("Should not timeout")
53
- @controller.simulate_around_filter do
54
- sleep(1)
55
- end
56
- end
57
-
58
- it "default long running controller action(300/30 for test/prod)" do
59
- class DummyController
60
- include ExceptionHandling::Methods
61
- end
62
-
63
- controller = DummyController.new
64
-
65
- Rails.env = 'production'
66
- expect(controller.send(:long_controller_action_timeout)).to eq(30)
67
-
68
- Rails.env = 'test'
69
- expect(controller.send(:long_controller_action_timeout)).to eq(300)
70
- end
71
-
72
- context "#log_warning" do
73
- it "be available to the controller" do
74
- expect(@controller.methods.include?(:log_warning)).to eq(true)
75
- end
76
-
77
- it "call ExceptionHandling#log_warning" do
78
- expect(ExceptionHandling).to receive(:log_warning).with("Hi mom")
79
- @controller.send(:log_warning, "Hi mom")
80
- end
81
- end
82
- end
83
- end
84
- end
@@ -1,51 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require File.expand_path('../../spec_helper', __dir__)
4
-
5
- module ExceptionHandling
6
- describe Sensu do
7
- context "#generate_event" do
8
- it "create an event" do
9
- expect(ExceptionHandling::Sensu).to receive(:send_event).with(name: "world_is_ending", output: "stick head between knees and kiss ass goodbye", status: 1)
10
-
11
- ExceptionHandling::Sensu.generate_event("world_is_ending", "stick head between knees and kiss ass goodbye")
12
- end
13
-
14
- it "add the sensu prefix" do
15
- ExceptionHandling.sensu_prefix = "cnn_"
16
-
17
- expect(ExceptionHandling::Sensu).to receive(:send_event).with(name: "cnn_world_is_ending", output: "stick head between knees and kiss ass goodbye", status: 1)
18
-
19
- ExceptionHandling::Sensu.generate_event("world_is_ending", "stick head between knees and kiss ass goodbye")
20
- end
21
-
22
- it "allow the level to be set to critical" do
23
- expect(ExceptionHandling::Sensu).to receive(:send_event).with(name: "world_is_ending", output: "stick head between knees and kiss ass goodbye", status: 2)
24
-
25
- ExceptionHandling::Sensu.generate_event("world_is_ending", "stick head between knees and kiss ass goodbye", :critical)
26
- end
27
-
28
- it "error if an invalid level is supplied" do
29
- expect(ExceptionHandling::Sensu).to_not receive(:send_event)
30
-
31
- expect do
32
- ExceptionHandling::Sensu.generate_event("world_is_ending", "stick head between knees and kiss ass goodbye", :hair_on_fire)
33
- end.to raise_exception(RuntimeError, /Invalid alert level/)
34
- end
35
- end
36
-
37
- context "#send_event" do
38
- before do
39
- @event = { name: "world_is_ending", output: "stick head between knees and kiss ass goodbye", status: 1 }
40
- @socket = SocketStub.new
41
- end
42
-
43
- it "send event json to sensu client" do
44
- expect_any_instance_of(Addrinfo).to receive(:connect).with(any_args) { @socket }
45
- ExceptionHandling::Sensu.send_event(@event)
46
-
47
- expect(@socket.sent.first).to eq(@event.to_json)
48
- end
49
- end
50
- end
51
- end