sidekiq-amigo 1.12.0 → 1.12.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.
- checksums.yaml +4 -4
- data/lib/amigo/autoscaler/checkers/web_latency.rb +18 -6
- data/lib/amigo/version.rb +1 -1
- data/lib/amigo.rb +14 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ab4f66f8d1d73bf0c9d9569ba86b4041d7642f86b8d10c246aa2eb155b3b6376
|
4
|
+
data.tar.gz: 6f5726a5708706dcbff900c5dcfde0656ab797a67a698608249abb96b2e1d93f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ef0b460702cafafd2c25119434ef11fda3dc958de6ad575c2a3faae18ba5bd97de64302aa8facf27a97a87476be2ca3947faa9f5f65f68df0c078610e1d6239
|
7
|
+
data.tar.gz: cf55e3a4308cb10cd81c4f4831cc1ab967ebd2614adaf62889c192c1b439cbea694928a57b525beb4fafe992fb5a5242ab6cecad2e79ee7888341f9c9c104057
|
@@ -7,7 +7,12 @@ module Amigo
|
|
7
7
|
module Checkers
|
8
8
|
class WebLatency < Amigo::Autoscaler::Checker
|
9
9
|
NAMESPACE = "amigo/autoscaler/web_latency"
|
10
|
+
# The number of seconds requests are we averaging across.
|
10
11
|
WINDOW = 60
|
12
|
+
# The number of seconds above which we have confidence in latency measurements.
|
13
|
+
# Without this window, a single request (without any other requests) could create a latency event.
|
14
|
+
# We need to see requests from this many seconds before feeling confident.
|
15
|
+
MINIMUM_CONFIDENCE_WINDOW = 30
|
11
16
|
|
12
17
|
# Set the latency.
|
13
18
|
# @param redis [RedisClient::Common] Redis connection.
|
@@ -31,19 +36,26 @@ module Amigo
|
|
31
36
|
|
32
37
|
def get_latencies
|
33
38
|
now = Time.now.to_i
|
34
|
-
|
35
|
-
|
36
|
-
sums = 0
|
39
|
+
window = (now - (WINDOW - 1))..now
|
40
|
+
keys = window.map { |bucket| "#{@namespace}/latencies:#{bucket}" }
|
37
41
|
results = @redis.pipelined do |pipeline|
|
38
42
|
keys.each do |k|
|
39
43
|
pipeline.call("HMGET", k, "count", "sum")
|
40
44
|
end
|
41
45
|
end
|
42
|
-
|
46
|
+
counts = 0
|
47
|
+
sums = 0
|
48
|
+
first_seen_bucket = nil
|
49
|
+
last_seen_bucket = nil
|
50
|
+
results.zip(window).each do |(count, sum), bucket|
|
51
|
+
next unless count # No results for this bucket
|
43
52
|
counts += count.to_i
|
44
|
-
sums
|
53
|
+
sums += sum.to_i
|
54
|
+
first_seen_bucket ||= bucket
|
55
|
+
last_seen_bucket = bucket
|
45
56
|
end
|
46
|
-
return {} if counts.zero?
|
57
|
+
return {} if first_seen_bucket.nil? || counts.zero?
|
58
|
+
return {} if (last_seen_bucket - first_seen_bucket) < MINIMUM_CONFIDENCE_WINDOW
|
47
59
|
latency = sums.to_f / counts
|
48
60
|
return {"web" => latency.to_f / 1000}
|
49
61
|
end
|
data/lib/amigo/version.rb
CHANGED
data/lib/amigo.rb
CHANGED
@@ -164,7 +164,12 @@ module Amigo
|
|
164
164
|
self.subscribers.to_a.each do |hook|
|
165
165
|
hook.call(ev)
|
166
166
|
rescue StandardError => e
|
167
|
-
self.log(
|
167
|
+
self.log(
|
168
|
+
nil,
|
169
|
+
:error,
|
170
|
+
"amigo_subscriber_hook_error",
|
171
|
+
error: e, hook: _block_repr(hook), event: ev&.as_json,
|
172
|
+
)
|
168
173
|
raise e if self.on_publish_error.nil?
|
169
174
|
if self.on_publish_error.respond_to?(:arity) && self.on_publish_error.arity == 1
|
170
175
|
self.on_publish_error.call(e)
|
@@ -178,11 +183,18 @@ module Amigo
|
|
178
183
|
# If a subscriber errors, on_publish_error is called with the exception, event, and subscriber.
|
179
184
|
def register_subscriber(&block)
|
180
185
|
raise LocalJumpError, "no block given" unless block
|
181
|
-
self.log nil, :info, "amigo_installed_subscriber", block: block
|
186
|
+
self.log nil, :info, "amigo_installed_subscriber", block: _block_repr(block)
|
182
187
|
self.subscribers << block
|
183
188
|
return block
|
184
189
|
end
|
185
190
|
|
191
|
+
private def _block_repr(block)
|
192
|
+
return block.to_s unless block.respond_to?(:source_location)
|
193
|
+
loc = block.source_location
|
194
|
+
return block.to_s unless loc
|
195
|
+
return loc.join(":")
|
196
|
+
end
|
197
|
+
|
186
198
|
def unregister_subscriber(block_ref)
|
187
199
|
self.subscribers.delete(block_ref)
|
188
200
|
end
|