airbrake-ruby 3.0.0.rc.4 → 3.0.0.rc.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/airbrake-ruby.rb +19 -13
- data/lib/airbrake-ruby/notifier.rb +2 -2
- data/lib/airbrake-ruby/route_sender.rb +16 -6
- data/lib/airbrake-ruby/version.rb +1 -1
- data/spec/airbrake_spec.rb +11 -7
- data/spec/notifier_spec.rb +12 -7
- data/spec/route_sender_spec.rb +61 -17
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84d9bd8df1233ea2c15f4f299e88724431188ad4
|
4
|
+
data.tar.gz: 30e834bbd33cb36abcd8703b2eaa8b9c3035b6b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a6c6bedcb66906b4b8cbe2d3f52b1d2f610e4ef061c5533be301ad01cc9ef12e2f39a58b9758a34b081d74941ae898053cd4cbd44fd164730525f34d7d7957f
|
7
|
+
data.tar.gz: 78b0135645bf7c97265014e86878c0fdc9a67cc2aae2283d07a7f23c349d65996dbd4fd1b081804c0413c9bc53897c19e145e85d97c76176c7e7b610e8333f66
|
data/lib/airbrake-ruby.rb
CHANGED
@@ -115,7 +115,7 @@ module Airbrake
|
|
115
115
|
def merge_context(_context); end
|
116
116
|
|
117
117
|
# @macro see_public_api_method
|
118
|
-
def
|
118
|
+
def notify_request(request_info); end
|
119
119
|
end
|
120
120
|
|
121
121
|
# A Hash that holds all notifiers. The keys of the Hash are notifier
|
@@ -345,26 +345,32 @@ module Airbrake
|
|
345
345
|
@notifiers[:default].merge_context(context)
|
346
346
|
end
|
347
347
|
|
348
|
-
# Increments request
|
349
|
-
# +
|
350
|
-
#
|
348
|
+
# Increments request statistics of a certain +route+ that was invoked on
|
349
|
+
# +start_time+ and ended on +end_time+ with +method+, and returned
|
350
|
+
# +status_code+.
|
351
351
|
#
|
352
352
|
# After a certain amount of time (n seconds) the aggregated route
|
353
353
|
# information will be sent to Airbrake.
|
354
354
|
#
|
355
355
|
# @example
|
356
|
-
# Airbrake.
|
356
|
+
# Airbrake.notify_request(
|
357
|
+
# method: 'POST',
|
358
|
+
# route: '/thing/:id/create',
|
359
|
+
# status_code: 200,
|
360
|
+
# start_time: timestamp,
|
361
|
+
# end_time: Time.now
|
362
|
+
# )
|
357
363
|
#
|
358
|
-
# @param [
|
359
|
-
# @
|
360
|
-
# @
|
361
|
-
# @
|
362
|
-
#
|
363
|
-
# @
|
364
|
+
# @param [Hash{Symbol=>Object}] request_info
|
365
|
+
# @option request_info [String] :method The HTTP method that was invoked
|
366
|
+
# @option request_info [String] :route The route that was invoked
|
367
|
+
# @option request_info [Integer] :status_code The respose code that the route returned
|
368
|
+
# @option request_info [Date] :start_time When the request started
|
369
|
+
# @option request_info [Time] :end_time When the request ended (optional)
|
364
370
|
# @return [void]
|
365
371
|
# @since v3.0.0
|
366
|
-
def
|
367
|
-
@notifiers[:default].
|
372
|
+
def notify_request(request_info)
|
373
|
+
@notifiers[:default].notify_request(request_info)
|
368
374
|
end
|
369
375
|
end
|
370
376
|
end
|
@@ -100,8 +100,8 @@ module Airbrake
|
|
100
100
|
end
|
101
101
|
|
102
102
|
# @macro see_public_api_method
|
103
|
-
def
|
104
|
-
@route_sender.
|
103
|
+
def notify_request(request_info)
|
104
|
+
@route_sender.notify_request(request_info)
|
105
105
|
end
|
106
106
|
|
107
107
|
# @return [String] customized inspect to lessen the amount of clutter
|
@@ -87,14 +87,18 @@ module Airbrake
|
|
87
87
|
end
|
88
88
|
|
89
89
|
# @macro see_public_api_method
|
90
|
-
def
|
91
|
-
route = create_route_key(
|
92
|
-
|
90
|
+
def notify_request(request_info)
|
91
|
+
route = create_route_key(
|
92
|
+
request_info[:method],
|
93
|
+
request_info[:route],
|
94
|
+
request_info[:status_code],
|
95
|
+
utc_truncate_minutes(request_info[:start_time])
|
96
|
+
)
|
93
97
|
promise = Airbrake::Promise.new
|
94
98
|
|
95
99
|
@mutex.synchronize do
|
96
100
|
@routes[route] ||= RouteStat.new
|
97
|
-
increment_stats(@routes[route]
|
101
|
+
increment_stats(request_info, @routes[route])
|
98
102
|
|
99
103
|
if @flush_period > 0
|
100
104
|
schedule_flush(promise)
|
@@ -117,10 +121,10 @@ module Airbrake
|
|
117
121
|
RouteKey.new(method, route, status_code, time.rfc3339)
|
118
122
|
end
|
119
123
|
|
120
|
-
def increment_stats(
|
124
|
+
def increment_stats(request_info, stat)
|
121
125
|
stat.count += 1
|
122
126
|
|
123
|
-
ms =
|
127
|
+
ms = (request_info[:end_time] || Time.now) - request_info[:start_time]
|
124
128
|
stat.sum += ms
|
125
129
|
stat.sumsq += ms * ms
|
126
130
|
|
@@ -159,5 +163,11 @@ module Airbrake
|
|
159
163
|
URI.join(@config.host, "api/v5/projects/#{@config.project_id}/routes-stats")
|
160
164
|
)
|
161
165
|
end
|
166
|
+
|
167
|
+
def utc_truncate_minutes(time)
|
168
|
+
time_array = time.to_a
|
169
|
+
time_array[0] = 0
|
170
|
+
Time.utc(*time_array)
|
171
|
+
end
|
162
172
|
end
|
163
173
|
end
|
data/spec/airbrake_spec.rb
CHANGED
@@ -111,13 +111,17 @@ RSpec.describe Airbrake do
|
|
111
111
|
end
|
112
112
|
end
|
113
113
|
|
114
|
-
describe ".
|
115
|
-
it "forwards '
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
114
|
+
describe ".notify_request" do
|
115
|
+
it "forwards 'notify_request' to the notifier" do
|
116
|
+
params = {
|
117
|
+
method: 'GET',
|
118
|
+
route: '/foo',
|
119
|
+
status_code: 200,
|
120
|
+
start_time: Time.new(2018, 1, 1, 0, 20, 0, 0),
|
121
|
+
end_time: Time.new(2018, 1, 1, 0, 19, 0, 0)
|
122
|
+
}
|
123
|
+
expect(default_notifier).to receive(:notify_request).with(params)
|
124
|
+
described_class.notify_request(params)
|
121
125
|
end
|
122
126
|
end
|
123
127
|
end
|
data/spec/notifier_spec.rb
CHANGED
@@ -450,13 +450,18 @@ RSpec.describe Airbrake::Notifier do
|
|
450
450
|
end
|
451
451
|
end
|
452
452
|
|
453
|
-
describe "#
|
454
|
-
it "forwards '
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
453
|
+
describe "#notify_request" do
|
454
|
+
it "forwards 'notify_request' to RouteSender" do
|
455
|
+
params = {
|
456
|
+
method: 'GET',
|
457
|
+
route: '/foo',
|
458
|
+
status_code: 200,
|
459
|
+
start_time: Time.new(2018, 1, 1, 0, 20, 0, 0),
|
460
|
+
end_time: Time.new(2018, 1, 1, 0, 19, 0, 0)
|
461
|
+
}
|
462
|
+
expect_any_instance_of(Airbrake::RouteSender)
|
463
|
+
.to receive(:notify_request).with(params)
|
464
|
+
subject.notify_request(params)
|
460
465
|
end
|
461
466
|
end
|
462
467
|
|
data/spec/route_sender_spec.rb
CHANGED
@@ -13,7 +13,7 @@ RSpec.describe Airbrake::RouteSender do
|
|
13
13
|
|
14
14
|
subject { described_class.new(config) }
|
15
15
|
|
16
|
-
describe "#
|
16
|
+
describe "#notify_request" do
|
17
17
|
before do
|
18
18
|
stub_request(:put, endpoint).to_return(status: 200, body: '')
|
19
19
|
end
|
@@ -22,7 +22,12 @@ RSpec.describe Airbrake::RouteSender do
|
|
22
22
|
after { sleep 0.2 }
|
23
23
|
|
24
24
|
it "rounds time to the floor minute" do
|
25
|
-
subject.
|
25
|
+
subject.notify_request(
|
26
|
+
method: 'GET',
|
27
|
+
route: '/foo',
|
28
|
+
status_code: 200,
|
29
|
+
start_time: Time.new(2018, 1, 1, 0, 0, 20, 0)
|
30
|
+
)
|
26
31
|
sleep 0.2
|
27
32
|
expect(
|
28
33
|
a_request(:put, endpoint).with(body: /"time":"2018-01-01T00:00:00\+00:00"/)
|
@@ -30,8 +35,18 @@ RSpec.describe Airbrake::RouteSender do
|
|
30
35
|
end
|
31
36
|
|
32
37
|
it "increments routes with the same key" do
|
33
|
-
subject.
|
34
|
-
|
38
|
+
subject.notify_request(
|
39
|
+
method: 'GET',
|
40
|
+
route: '/foo',
|
41
|
+
status_code: 200,
|
42
|
+
start_time: Time.new(2018, 1, 1, 0, 0, 20, 0)
|
43
|
+
)
|
44
|
+
subject.notify_request(
|
45
|
+
method: 'GET',
|
46
|
+
route: '/foo',
|
47
|
+
status_code: 200,
|
48
|
+
start_time: Time.new(2018, 1, 1, 0, 0, 50, 0)
|
49
|
+
)
|
35
50
|
sleep 0.2
|
36
51
|
expect(
|
37
52
|
a_request(:put, endpoint).with(body: /"count":2/)
|
@@ -39,45 +54,74 @@ RSpec.describe Airbrake::RouteSender do
|
|
39
54
|
end
|
40
55
|
|
41
56
|
it "groups routes by time" do
|
42
|
-
subject.
|
43
|
-
|
57
|
+
subject.notify_request(
|
58
|
+
method: 'GET',
|
59
|
+
route: '/foo',
|
60
|
+
status_code: 200,
|
61
|
+
start_time: Time.new(2018, 1, 1, 0, 0, 49, 0),
|
62
|
+
end_time: Time.new(2018, 1, 1, 0, 0, 50, 0)
|
63
|
+
)
|
64
|
+
subject.notify_request(
|
65
|
+
method: 'GET',
|
66
|
+
route: '/foo',
|
67
|
+
status_code: 200,
|
68
|
+
start_time: Time.new(2018, 1, 1, 0, 1, 49, 0),
|
69
|
+
end_time: Time.new(2018, 1, 1, 0, 1, 55, 0)
|
70
|
+
)
|
44
71
|
sleep 0.2
|
45
72
|
expect(
|
46
73
|
a_request(:put, endpoint).with(
|
47
74
|
body: %r|\A
|
48
75
|
{"routes":\[
|
49
76
|
{"method":"GET","route":"/foo","status_code":200,
|
50
|
-
"time":"2018-01-01T00:00:00\+00:00","count":1,"sum":
|
51
|
-
"sumsq":
|
77
|
+
"time":"2018-01-01T00:00:00\+00:00","count":1,"sum":1.0,
|
78
|
+
"sumsq":1.0,"tdigest":"AAAAAkA0AAAAAAAAAAAAAT\+AAAAB"},
|
52
79
|
{"method":"GET","route":"/foo","status_code":200,
|
53
|
-
"time":"2018-01-01T00:01:00\+00:00","count":1,"sum":
|
54
|
-
"sumsq":
|
80
|
+
"time":"2018-01-01T00:01:00\+00:00","count":1,"sum":6.0,
|
81
|
+
"sumsq":36.0,"tdigest":"AAAAAkA0AAAAAAAAAAAAAUDAAAAB"}\]}
|
55
82
|
\z|x
|
56
83
|
)
|
57
84
|
).to have_been_made
|
58
85
|
end
|
59
86
|
|
60
87
|
it "groups routes by route key" do
|
61
|
-
subject.
|
62
|
-
|
88
|
+
subject.notify_request(
|
89
|
+
method: 'GET',
|
90
|
+
route: '/foo',
|
91
|
+
status_code: 200,
|
92
|
+
start_time: Time.new(2018, 1, 1, 0, 49, 0, 0),
|
93
|
+
end_time: Time.new(2018, 1, 1, 0, 50, 0, 0)
|
94
|
+
)
|
95
|
+
subject.notify_request(
|
96
|
+
method: 'POST',
|
97
|
+
route: '/foo',
|
98
|
+
status_code: 200,
|
99
|
+
start_time: Time.new(2018, 1, 1, 0, 49, 0, 0),
|
100
|
+
end_time: Time.new(2018, 1, 1, 0, 50, 0, 0)
|
101
|
+
)
|
63
102
|
sleep 0.2
|
64
103
|
expect(
|
65
104
|
a_request(:put, endpoint).with(
|
66
105
|
body: %r|\A
|
67
106
|
{"routes":\[
|
68
107
|
{"method":"GET","route":"/foo","status_code":200,
|
69
|
-
"time":"2018-01-01T00:
|
70
|
-
"sumsq":
|
108
|
+
"time":"2018-01-01T00:49:00\+00:00","count":1,"sum":60.0,
|
109
|
+
"sumsq":3600.0,"tdigest":"AAAAAkA0AAAAAAAAAAAAAUJwAAAB"},
|
71
110
|
{"method":"POST","route":"/foo","status_code":200,
|
72
|
-
"time":"2018-01-01T00:
|
73
|
-
"sumsq":
|
111
|
+
"time":"2018-01-01T00:49:00\+00:00","count":1,"sum":60.0,
|
112
|
+
"sumsq":3600.0,"tdigest":"AAAAAkA0AAAAAAAAAAAAAUJwAAAB"}\]}
|
74
113
|
\z|x
|
75
114
|
)
|
76
115
|
).to have_been_made
|
77
116
|
end
|
78
117
|
|
79
118
|
it "returns a promise" do
|
80
|
-
promise = subject.
|
119
|
+
promise = subject.notify_request(
|
120
|
+
method: 'GET',
|
121
|
+
route: '/foo',
|
122
|
+
status_code: 200,
|
123
|
+
start_time: Time.new(2018, 1, 1, 0, 49, 0, 0)
|
124
|
+
)
|
81
125
|
sleep 0.2
|
82
126
|
expect(promise).to be_an(Airbrake::Promise)
|
83
127
|
expect(promise.value).to eq('' => nil)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: airbrake-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.0.rc.
|
4
|
+
version: 3.0.0.rc.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Airbrake Technologies, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-11-
|
11
|
+
date: 2018-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tdigest
|