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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a2c26bbe2effb0671dd84b762fa9787e8f5bc4cb
4
- data.tar.gz: 964f77831dc4162e3268f5714c11ef648c2609f5
3
+ metadata.gz: 84d9bd8df1233ea2c15f4f299e88724431188ad4
4
+ data.tar.gz: 30e834bbd33cb36abcd8703b2eaa8b9c3035b6b9
5
5
  SHA512:
6
- metadata.gz: 4979b96aa750761944b0d778a625801f808dc08cf92b81c722cdf309d0b02986c83b02786e93922ebe1dcf280acc73a500010fb21ca9192c2c709b7bfda286e0
7
- data.tar.gz: e0f39ae0d44ab1d13dfc3066caecc1eeedbb21260c3f34a923054b8bcd6240ea6f438e677be59a1dbb12d0fc7ec54e64a1a83b1861a1659bb4f3e2eacc2407e7
6
+ metadata.gz: 6a6c6bedcb66906b4b8cbe2d3f52b1d2f610e4ef061c5533be301ad01cc9ef12e2f39a58b9758a34b081d74941ae898053cd4cbd44fd164730525f34d7d7957f
7
+ data.tar.gz: 78b0135645bf7c97265014e86878c0fdc9a67cc2aae2283d07a7f23c349d65996dbd4fd1b081804c0413c9bc53897c19e145e85d97c76176c7e7b610e8333f66
@@ -115,7 +115,7 @@ module Airbrake
115
115
  def merge_context(_context); end
116
116
 
117
117
  # @macro see_public_api_method
118
- def inc_request(method, route, status_code, dur, time); end
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 count of a certain +route+ that was invoked with
349
- # +method+, and returned +status_code+ at +time+ and took +dur+
350
- # milliseconds.
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.inc_request('POST', '/thing/:id/create', 200, 123, Time.now)
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 [String] method The HTTP method that was invoked
359
- # @param [String] route The route that was invoked
360
- # @param [Integer] status_code The respose code that the route returned
361
- # @param [Float] dur How much time the processing of the request took in
362
- # milliseconds
363
- # @param [Time] time When the request happened
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 inc_request(method, route, status_code, dur, time)
367
- @notifiers[:default].inc_request(method, route, status_code, dur, time)
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 inc_request(*args)
104
- @route_sender.inc_request(*args)
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 inc_request(method, route, status_code, dur, tm)
91
- route = create_route_key(method, route, status_code, tm)
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], dur)
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(stat, dur)
124
+ def increment_stats(request_info, stat)
121
125
  stat.count += 1
122
126
 
123
- ms = dur.to_f
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
@@ -2,5 +2,5 @@
2
2
  # More information: http://semver.org/
3
3
  module Airbrake
4
4
  # @return [String] the library version
5
- AIRBRAKE_RUBY_VERSION = '3.0.0.rc.4'.freeze
5
+ AIRBRAKE_RUBY_VERSION = '3.0.0.rc.5'.freeze
6
6
  end
@@ -111,13 +111,17 @@ RSpec.describe Airbrake do
111
111
  end
112
112
  end
113
113
 
114
- describe ".inc_request" do
115
- it "forwards 'inc_request' to the notifier" do
116
- t = Time.now
117
- expect(default_notifier).to receive(:inc_request).with(
118
- 'GET', '/foo', 200, 1000, t
119
- )
120
- described_class.inc_request('GET', '/foo', 200, 1000, t)
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
@@ -450,13 +450,18 @@ RSpec.describe Airbrake::Notifier do
450
450
  end
451
451
  end
452
452
 
453
- describe "#inc_request" do
454
- it "forwards 'inc_request' to RouteSender" do
455
- t = Time.now
456
- expect_any_instance_of(Airbrake::RouteSender).to receive(:inc_request).with(
457
- 'GET', '/foo', 200, 1000, t
458
- )
459
- subject.inc_request('GET', '/foo', 200, 1000, t)
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
 
@@ -13,7 +13,7 @@ RSpec.describe Airbrake::RouteSender do
13
13
 
14
14
  subject { described_class.new(config) }
15
15
 
16
- describe "#inc_request" do
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.inc_request('GET', '/foo', 200, 24, Time.new(2018, 1, 1, 0, 0, 20, 0))
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.inc_request('GET', '/foo', 200, 24, Time.new(2018, 1, 1, 0, 0, 20, 0))
34
- subject.inc_request('GET', '/foo', 200, 24, Time.new(2018, 1, 1, 0, 0, 50, 0))
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.inc_request('GET', '/foo', 200, 24, Time.new(2018, 1, 1, 0, 0, 20, 0))
43
- subject.inc_request('GET', '/foo', 200, 10, Time.new(2018, 1, 1, 0, 1, 20, 0))
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":24.0,
51
- "sumsq":576.0,"tdigest":"AAAAAkA0AAAAAAAAAAAAAUHAAAAB"},
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":10.0,
54
- "sumsq":100.0,"tdigest":"AAAAAkA0AAAAAAAAAAAAAUEgAAAB"}\]}
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.inc_request('GET', '/foo', 200, 24, Time.new(2018, 1, 1, 0, 0, 20, 0))
62
- subject.inc_request('POST', '/foo', 200, 10, Time.new(2018, 1, 1, 0, 0, 20, 0))
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:00:00\+00:00","count":1,"sum":24.0,
70
- "sumsq":576.0,"tdigest":"AAAAAkA0AAAAAAAAAAAAAUHAAAAB"},
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:00:00\+00:00","count":1,"sum":10.0,
73
- "sumsq":100.0,"tdigest":"AAAAAkA0AAAAAAAAAAAAAUEgAAAB"}\]}
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.inc_request('GET', '/foo', 200, 24, Time.new)
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
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-06 00:00:00.000000000 Z
11
+ date: 2018-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tdigest