midnight_ride 0.1.2 → 0.1.3
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/README.md +3 -1
- data/lib/midnight_ride/alert.rb +20 -2
- data/lib/midnight_ride/jobs.rb +13 -6
- data/lib/midnight_ride/version.rb +1 -1
- data/lib/midnight_ride.rb +9 -4
- 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: 3f2e2c482f35250675a4dc63f12ba46436b2e132d8cff3dc4e94aa739895689b
|
|
4
|
+
data.tar.gz: 37b3c860d3322578f1bf40143b7759e02ac4391354d04faac4386882ba5bc7db
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b6eb066d360191f6ef35452069812f96855b484a54b0d5fbd4ca6bd1b0022629a33a62dada9bd2990df63c2908c325908e0183834174f9b9b40d4d40c24f8f0e
|
|
7
|
+
data.tar.gz: 9120e4ebadbdbb87cce2f8e2b3dee1b04bb8e0c98a03ccf706fc9ec9cd4eed49a505ce568d275105f8c5dd01516188502eb0d986cadd3553fd35609b1eadbc36
|
data/README.md
CHANGED
|
@@ -123,7 +123,9 @@ MidnightRide.resolve(ids)
|
|
|
123
123
|
```
|
|
124
124
|
|
|
125
125
|
for instance with `bin/rails runner 'MidnightRide.resolve(ARGV)' 90 91`.
|
|
126
|
-
|
|
126
|
+
It also resolves the errors that count as one with those, which no commit
|
|
127
|
+
names, since only one of them was alerted about. Errors that haven’t
|
|
128
|
+
happened for a week resolve themselves anyway.
|
|
127
129
|
|
|
128
130
|
## License
|
|
129
131
|
|
data/lib/midnight_ride/alert.rb
CHANGED
|
@@ -72,12 +72,30 @@ module MidnightRide
|
|
|
72
72
|
Net::HTTP.post(URI(url), body.to_json, {"Content-Type" => "application/json"}.merge(headers))
|
|
73
73
|
end
|
|
74
74
|
|
|
75
|
-
|
|
76
|
-
|
|
75
|
+
# Errors with the same key count as one: each alerts once, and resolving
|
|
76
|
+
# one resolves them all.
|
|
77
77
|
def key
|
|
78
78
|
@key ||= "midnight_ride/#{Digest::SHA256.hexdigest([exception_class, without_values(message), without_numbers(location)].join("\n"))}"
|
|
79
79
|
end
|
|
80
80
|
|
|
81
|
+
# The ids of the alerts that count as one with an alert of the given ids
|
|
82
|
+
def self.alike alerts, ids
|
|
83
|
+
keys = alerts.select { ids.include?(it.id) }.map(&:key)
|
|
84
|
+
alerts.select { keys.include?(it.key) }.map(&:id)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# One alert for each group of alerts that count as one, the oldest's,
|
|
88
|
+
# with how often they all happened
|
|
89
|
+
def self.reminders alerts
|
|
90
|
+
alerts.group_by(&:key).values.map do |group|
|
|
91
|
+
first = group.min_by(&:id)
|
|
92
|
+
new(id: first.id, exception_class: first.exception_class, message: first.message,
|
|
93
|
+
backtrace: first.backtrace, still_happening: group.sum { it.still_happening.to_i })
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
private
|
|
98
|
+
|
|
81
99
|
def seen?
|
|
82
100
|
MidnightRide.cache.exist?(key)
|
|
83
101
|
end
|
data/lib/midnight_ride/jobs.rb
CHANGED
|
@@ -17,17 +17,20 @@ module MidnightRide
|
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
# Once a day, alerts again about each unresolved error that still happened
|
|
20
|
-
# in the last day, with how often, and starts another session for it
|
|
21
|
-
# Errors new in the last day were
|
|
20
|
+
# in the last day, with how often, and starts another session for it,
|
|
21
|
+
# once for errors that count as one. Errors new in the last day were
|
|
22
|
+
# alerted about already.
|
|
22
23
|
class RemindersJob < ActiveJob::Base
|
|
23
24
|
def perform
|
|
24
25
|
since = 1.day.ago
|
|
25
26
|
counts = SolidErrors::Occurrence.where(created_at: since..).group(:error_id).count
|
|
27
|
+
errors = SolidErrors::Error.unresolved.where(id: counts.keys, created_at: ...since)
|
|
28
|
+
alerts = errors.map { MidnightRide.alert_for(it, still_happening: counts[it.id]) }
|
|
26
29
|
|
|
27
|
-
|
|
28
|
-
|
|
30
|
+
Alert.reminders(alerts).each do |alert|
|
|
31
|
+
alert.deliver
|
|
29
32
|
rescue => e
|
|
30
|
-
MidnightRide.logger.error("MidnightRide::RemindersJob failed for error #{
|
|
33
|
+
MidnightRide.logger.error("MidnightRide::RemindersJob failed for error #{alert.id}: #{e.class}: #{e.message}")
|
|
31
34
|
end
|
|
32
35
|
end
|
|
33
36
|
end
|
|
@@ -43,12 +46,16 @@ module MidnightRide
|
|
|
43
46
|
end
|
|
44
47
|
|
|
45
48
|
def self.alert error, **options
|
|
49
|
+
alert_for(error, **options).deliver
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def self.alert_for error, **options
|
|
46
53
|
Alert.new(
|
|
47
54
|
id: error.id,
|
|
48
55
|
exception_class: error.exception_class,
|
|
49
56
|
message: error.message,
|
|
50
57
|
backtrace: error.occurrences.order(:id).last&.backtrace,
|
|
51
58
|
**options
|
|
52
|
-
)
|
|
59
|
+
)
|
|
53
60
|
end
|
|
54
61
|
end
|
data/lib/midnight_ride.rb
CHANGED
|
@@ -59,11 +59,16 @@ module MidnightRide
|
|
|
59
59
|
(@root || Rails.root).to_s
|
|
60
60
|
end
|
|
61
61
|
|
|
62
|
-
# Resolves the Solid Errors errors with the given ids,
|
|
63
|
-
#
|
|
64
|
-
#
|
|
62
|
+
# Resolves the Solid Errors errors with the given ids, and the unresolved
|
|
63
|
+
# ones that count as one with them, which no commit names, since only
|
|
64
|
+
# one of them was alerted about. They alert again if they come back. For
|
|
65
|
+
# the server's deploys, which resolve the errors the deployed commits
|
|
66
|
+
# name (see the README).
|
|
65
67
|
def resolve ids
|
|
66
|
-
|
|
68
|
+
ids = ids.map(&:to_i)
|
|
69
|
+
unresolved = SolidErrors::Error.unresolved.to_a
|
|
70
|
+
alike = Alert.alike(unresolved.map { alert_for(it) }, ids)
|
|
71
|
+
SolidErrors::Error.unresolved.where(id: ids | alike).update_all(resolved_at: Time.current)
|
|
67
72
|
end
|
|
68
73
|
end
|
|
69
74
|
|