failbot 2.5.2 → 2.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e17fb2d80a08382f07201582e708558ab9288c33c085950136d42c38ac9e47ff
4
- data.tar.gz: 664d9e980cb2901a1487518435a8c15bcd1e7fbce8d72eb16298e43db50d531c
3
+ metadata.gz: 1bae1044f6d88c6617750ffe63b606591880ebe5132d9714d2e4c9534e309962
4
+ data.tar.gz: b1d80185dae5e664c049ed38583d25086d3659f517826c38912974d93fed32a6
5
5
  SHA512:
6
- metadata.gz: 5228d0b4914759a86d5605b8573f4c55de41716b2f9fa1248c6df87c169dacff3653a46da0ad4287866ecdb8a60aac5b0ed762202c0aaff89444e3b7cbbd75da
7
- data.tar.gz: 332e27bc52d28068b62b6eda1fe30925401788ab3225f68d0a09573e07182f2caa6e7437edf6627cd94cba9fa0be04c44fd6a873e594428ea8bf78a22e2707fa
6
+ metadata.gz: 8114032ca98920f4b902447d1b3c69b28ea6bfe14b52d8b1f431d0537295d5c565d9d8a17540afa72f00f439023bc711291542baa2044ada4cd6f547e9506c35
7
+ data.tar.gz: f0040811958da514da048dd38af5de2cfd3978d6f036dc78c19b6080991b02bf69cca5b79f684ecc3a8c5b3885b577ecf77116fca445439f7ecfa06fbe5a3452
@@ -3,6 +3,7 @@ require 'digest/md5'
3
3
  require 'logger'
4
4
  require 'socket'
5
5
  require "time"
6
+ require "timeout"
6
7
  require "date"
7
8
  require "uri"
8
9
 
@@ -25,8 +26,7 @@ module Failbot
25
26
  autoload :HTTPBackend, 'failbot/http_backend'
26
27
  autoload :MemoryBackend, 'failbot/memory_backend'
27
28
  autoload :JSONBackend, 'failbot/json_backend'
28
-
29
- autoload :ThreadLocalVariable, 'failbot/thread_local_variable'
29
+ autoload :WaiterBackend, 'failbot/waiter_backend'
30
30
 
31
31
  # Public: Set an instrumenter to be called when exceptions are reported.
32
32
  #
@@ -46,6 +46,9 @@ module Failbot
46
46
  #
47
47
  attr_accessor :instrumenter
48
48
 
49
+ # prevent recursive calls to Failbot.report!
50
+ attr_accessor :already_reporting
51
+
49
52
  # Root directory of the project's source. Used to clean up stack traces if the exception format supports it
50
53
 
51
54
  def source_root=(str)
@@ -134,16 +137,9 @@ module Failbot
134
137
  return setup_deprecated(settings)
135
138
  end
136
139
 
137
- initial_context = if default_context.respond_to?(:to_hash) && !default_context.to_hash.empty?
138
- default_context.to_hash
139
- else
140
- { 'server' => hostname }
141
- end
142
-
143
- @thread_local_context = ::Failbot::ThreadLocalVariable.new do
144
- [initial_context]
140
+ if default_context.respond_to?(:to_hash) && !default_context.to_hash.empty?
141
+ context[0] = default_context.to_hash
145
142
  end
146
- @thread_local_already_reporting = ::Failbot::ThreadLocalVariable.new { false }
147
143
 
148
144
  populate_context_from_settings(settings)
149
145
 
@@ -151,6 +147,8 @@ module Failbot
151
147
  case (name = settings["FAILBOT_BACKEND"])
152
148
  when "memory"
153
149
  Failbot::MemoryBackend.new
150
+ when "waiter"
151
+ Failbot::WaiterBackend.new
154
152
  when "file"
155
153
  Failbot::FileBackend.new(settings["FAILBOT_BACKEND_FILE_PATH"])
156
154
  when "http"
@@ -165,6 +163,11 @@ module Failbot
165
163
 
166
164
  @raise_errors = !settings["FAILBOT_RAISE"].to_s.empty?
167
165
  @report_errors = settings["FAILBOT_REPORT"] != "0"
166
+ @enable_timeout = false
167
+ if settings.key?("FAILBOT_TIMEOUT_MS")
168
+ @timeout_seconds = settings["FAILBOT_TIMEOUT_MS"].to_f / 1000
169
+ @enable_timeout = (@timeout_seconds != 0.0)
170
+ end
168
171
 
169
172
  # allows overriding the 'app' value to send to single haystack bucket.
170
173
  # used primarily on ghe.io.
@@ -185,7 +188,7 @@ module Failbot
185
188
  # hashes are condensed down into one and included in the next report. Don't
186
189
  # mess with this structure directly - use the #push and #pop methods.
187
190
  def context
188
- @thread_local_context.value
191
+ @context ||= [{'server' => hostname}]
189
192
  end
190
193
 
191
194
  # Add info to be sent in the next failbot report, should one occur.
@@ -209,7 +212,7 @@ module Failbot
209
212
 
210
213
  # Reset the context stack to a pristine state.
211
214
  def reset!
212
- @thread_local_context.value = [context[0]].dup
215
+ @context = [context[0]]
213
216
  end
214
217
 
215
218
  # Loops through the stack of contexts and deletes the given key if it exists.
@@ -351,7 +354,13 @@ module Failbot
351
354
  "report_status" => "error",
352
355
  }
353
356
  begin
354
- backend.report(data)
357
+ if @enable_timeout
358
+ Timeout.timeout(@timeout_seconds) do
359
+ backend.report(data)
360
+ end
361
+ else
362
+ backend.report(data)
363
+ end
355
364
  instrumentation_data["report_status"] = "success"
356
365
  rescue Object => i
357
366
  log_failure("reporting", data, e, i)
@@ -487,14 +496,6 @@ module Failbot
487
496
  @hostname ||= Socket.gethostname
488
497
  end
489
498
 
490
- def already_reporting=(bool)
491
- @thread_local_already_reporting.value = bool
492
- end
493
-
494
- def already_reporting
495
- @thread_local_already_reporting.value
496
- end
497
-
498
499
  private
499
500
 
500
501
  # Internal: Publish an event to the instrumenter
@@ -52,6 +52,10 @@ module Failbot
52
52
 
53
53
  # push it through
54
54
  http.request(request)
55
+ ensure
56
+ if defined?(http) && http.started?
57
+ http.finish
58
+ end
55
59
  end
56
60
  end
57
61
  end
@@ -1,3 +1,3 @@
1
1
  module Failbot
2
- VERSION = "2.5.2"
2
+ VERSION = "2.5.4"
3
3
  end
@@ -0,0 +1,21 @@
1
+ module Failbot
2
+ class WaiterBackend
3
+ # This backend waits a configured amount of time before returning. This is
4
+ # intended be used to test timeouts. Delay is the number of seconds to wait.
5
+
6
+ attr_reader :reports
7
+ def initialize(delay = 5)
8
+ @delay = delay
9
+ @reports = []
10
+ end
11
+
12
+ def report(data)
13
+ @reports << data
14
+ sleep(@delay)
15
+ end
16
+
17
+ def ping
18
+ # nop
19
+ end
20
+ end
21
+ end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: failbot
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.2
4
+ version: 2.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - "@rtomayko"
8
8
  - "@atmos"
9
9
  - "@sr"
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2020-04-07 00:00:00.000000000 Z
13
+ date: 2020-08-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake
@@ -106,13 +106,13 @@ files:
106
106
  - lib/failbot/middleware.rb
107
107
  - lib/failbot/resque_failure_backend.rb
108
108
  - lib/failbot/sensitive_data_scrubber.rb
109
- - lib/failbot/thread_local_variable.rb
110
109
  - lib/failbot/version.rb
110
+ - lib/failbot/waiter_backend.rb
111
111
  homepage: http://github.com/github/failbot#readme
112
112
  licenses:
113
113
  - MIT
114
114
  metadata: {}
115
- post_install_message:
115
+ post_install_message:
116
116
  rdoc_options: []
117
117
  require_paths:
118
118
  - lib
@@ -128,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
128
  version: '0'
129
129
  requirements: []
130
130
  rubygems_version: 3.0.3
131
- signing_key:
131
+ signing_key:
132
132
  specification_version: 4
133
133
  summary: Deliver exceptions to Haystack
134
134
  test_files: []
@@ -1,24 +0,0 @@
1
- module Failbot
2
- # Public: A simplified implementation of [`::Concurrent::ThreadLocalVar`](https://github.com/ruby-concurrency/concurrent-ruby/blob/7dc6eb04142f008ffa79a59c125669c6fcbb85a8/lib/concurrent-ruby/concurrent/atomic/thread_local_var.rb)
3
- #
4
- # Why not just use `concurrent-ruby`? We wanted to minimize external dependencies to avoid conflicts with gems already installed with `github/github`.
5
- #
6
- class ThreadLocalVariable
7
- def initialize(&block)
8
- @default_block = block || proc {}
9
- @key = "_thread_local_variable##{object_id}"
10
- end
11
-
12
- def value
13
- if Thread.current.key?(@key)
14
- Thread.current[@key]
15
- else
16
- Thread.current[@key] = @default_block.call
17
- end
18
- end
19
-
20
- def value=(val)
21
- Thread.current[@key] = val
22
- end
23
- end
24
- end