airbrake-ruby 6.1.0-java → 6.1.1-java
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/filters/git_last_checkout_filter.rb +1 -1
- data/lib/airbrake-ruby/nested_exception.rb +10 -1
- data/lib/airbrake-ruby/notice.rb +5 -3
- data/lib/airbrake-ruby/version.rb +1 -1
- metadata +4 -122
- data/spec/airbrake_spec.rb +0 -522
- data/spec/async_sender_spec.rb +0 -65
- data/spec/backtrace_spec.rb +0 -430
- data/spec/benchmark_spec.rb +0 -35
- data/spec/code_hunk_spec.rb +0 -124
- data/spec/config/processor_spec.rb +0 -167
- data/spec/config/validator_spec.rb +0 -204
- data/spec/config_spec.rb +0 -188
- data/spec/context_spec.rb +0 -54
- data/spec/deploy_notifier_spec.rb +0 -50
- data/spec/file_cache_spec.rb +0 -35
- data/spec/filter_chain_spec.rb +0 -124
- data/spec/filters/context_filter_spec.rb +0 -32
- data/spec/filters/dependency_filter_spec.rb +0 -14
- data/spec/filters/exception_attributes_filter_spec.rb +0 -52
- data/spec/filters/gem_root_filter_spec.rb +0 -44
- data/spec/filters/git_last_checkout_filter_spec.rb +0 -61
- data/spec/filters/git_repository_filter_spec.rb +0 -72
- data/spec/filters/git_revision_filter_spec.rb +0 -126
- data/spec/filters/keys_allowlist_spec.rb +0 -204
- data/spec/filters/keys_blocklist_spec.rb +0 -242
- data/spec/filters/root_directory_filter_spec.rb +0 -39
- data/spec/filters/sql_filter_spec.rb +0 -274
- data/spec/filters/system_exit_filter_spec.rb +0 -16
- data/spec/filters/thread_filter_spec.rb +0 -281
- data/spec/fixtures/notroot.txt +0 -7
- data/spec/fixtures/project_root/code.rb +0 -221
- data/spec/fixtures/project_root/empty_file.rb +0 -0
- data/spec/fixtures/project_root/long_line.txt +0 -1
- data/spec/fixtures/project_root/short_file.rb +0 -3
- data/spec/fixtures/project_root/vendor/bundle/ignored_file.rb +0 -5
- data/spec/helpers.rb +0 -9
- data/spec/ignorable_spec.rb +0 -14
- data/spec/inspectable_spec.rb +0 -45
- data/spec/loggable_spec.rb +0 -17
- data/spec/monotonic_time_spec.rb +0 -25
- data/spec/nested_exception_spec.rb +0 -73
- data/spec/notice_notifier/options_spec.rb +0 -269
- data/spec/notice_notifier_spec.rb +0 -361
- data/spec/notice_spec.rb +0 -300
- data/spec/performance_breakdown_spec.rb +0 -11
- data/spec/performance_notifier_spec.rb +0 -645
- data/spec/promise_spec.rb +0 -203
- data/spec/query_spec.rb +0 -11
- data/spec/queue_spec.rb +0 -18
- data/spec/remote_settings/callback_spec.rb +0 -162
- data/spec/remote_settings/settings_data_spec.rb +0 -348
- data/spec/remote_settings_spec.rb +0 -201
- data/spec/request_spec.rb +0 -9
- data/spec/response_spec.rb +0 -110
- data/spec/spec_helper.rb +0 -100
- data/spec/stashable_spec.rb +0 -23
- data/spec/stat_spec.rb +0 -39
- data/spec/sync_sender_spec.rb +0 -168
- data/spec/tdigest_spec.rb +0 -235
- data/spec/thread_pool_spec.rb +0 -196
- data/spec/time_truncate_spec.rb +0 -30
- data/spec/timed_trace_spec.rb +0 -127
- data/spec/truncator_spec.rb +0 -267
@@ -1,645 +0,0 @@
|
|
1
|
-
RSpec.describe Airbrake::PerformanceNotifier do
|
2
|
-
subject(:perf_notifier) { described_class.new }
|
3
|
-
|
4
|
-
let(:routes) { 'https://api.airbrake.io/api/v5/projects/1/routes-stats' }
|
5
|
-
let(:queries) { 'https://api.airbrake.io/api/v5/projects/1/queries-stats' }
|
6
|
-
let(:breakdowns) { 'https://api.airbrake.io/api/v5/projects/1/routes-breakdowns' }
|
7
|
-
let(:queues) { 'https://api.airbrake.io/api/v5/projects/1/queues-stats' }
|
8
|
-
|
9
|
-
before do
|
10
|
-
stub_request(:put, routes).to_return(status: 200, body: '')
|
11
|
-
stub_request(:put, queries).to_return(status: 200, body: '')
|
12
|
-
stub_request(:put, breakdowns).to_return(status: 200, body: '')
|
13
|
-
stub_request(:put, queues).to_return(status: 200, body: '')
|
14
|
-
|
15
|
-
Airbrake::Config.instance = Airbrake::Config.new(
|
16
|
-
project_id: 1,
|
17
|
-
project_key: 'banana',
|
18
|
-
performance_stats: true,
|
19
|
-
performance_stats_flush_period: 0,
|
20
|
-
query_stats: true,
|
21
|
-
job_stats: true,
|
22
|
-
)
|
23
|
-
end
|
24
|
-
|
25
|
-
describe "#notify" do
|
26
|
-
it "sends full query" do
|
27
|
-
perf_notifier.notify(
|
28
|
-
Airbrake::Query.new(
|
29
|
-
method: 'POST',
|
30
|
-
route: '/foo',
|
31
|
-
query: 'SELECT * FROM things',
|
32
|
-
func: 'foo',
|
33
|
-
file: 'foo.rb',
|
34
|
-
line: 123,
|
35
|
-
timing: 60000,
|
36
|
-
time: Time.new(2018, 1, 1, 0, 49, 0, 0),
|
37
|
-
),
|
38
|
-
)
|
39
|
-
perf_notifier.close
|
40
|
-
|
41
|
-
expect(
|
42
|
-
a_request(:put, queries).with(body: %r|
|
43
|
-
\A{"queries":\[{
|
44
|
-
"method":"POST",
|
45
|
-
"route":"/foo",
|
46
|
-
"query":"SELECT\s\*\sFROM\sthings",
|
47
|
-
"time":"2018-01-01T00:49:00\+00:00",
|
48
|
-
"function":"foo",
|
49
|
-
"file":"foo.rb",
|
50
|
-
"line":123,
|
51
|
-
"count":1,
|
52
|
-
"sum":60000.0,
|
53
|
-
"sumsq":3600000000.0,
|
54
|
-
"tdigest":"AAAAAkA0AAAAAAAAAAAAAUdqYAAB"
|
55
|
-
}\]}\z|x),
|
56
|
-
).to have_been_made
|
57
|
-
end
|
58
|
-
|
59
|
-
it "sends full request" do
|
60
|
-
perf_notifier.notify(
|
61
|
-
Airbrake::Request.new(
|
62
|
-
method: 'POST',
|
63
|
-
route: '/foo',
|
64
|
-
status_code: 200,
|
65
|
-
timing: 60000,
|
66
|
-
time: Time.new(2018, 1, 1, 0, 49, 0, 0),
|
67
|
-
),
|
68
|
-
)
|
69
|
-
perf_notifier.close
|
70
|
-
|
71
|
-
expect(
|
72
|
-
a_request(:put, routes).with(body: %r|
|
73
|
-
\A{"routes":\[{
|
74
|
-
"method":"POST",
|
75
|
-
"route":"/foo",
|
76
|
-
"statusCode":200,
|
77
|
-
"time":"2018-01-01T00:49:00\+00:00",
|
78
|
-
"count":1,
|
79
|
-
"sum":60000.0,
|
80
|
-
"sumsq":3600000000.0,
|
81
|
-
"tdigest":"AAAAAkA0AAAAAAAAAAAAAUdqYAAB"
|
82
|
-
}\]}\z|x),
|
83
|
-
).to have_been_made
|
84
|
-
end
|
85
|
-
|
86
|
-
it "sends full performance breakdown" do
|
87
|
-
perf_notifier.notify(
|
88
|
-
Airbrake::PerformanceBreakdown.new(
|
89
|
-
method: 'DELETE',
|
90
|
-
route: '/routes-breakdowns',
|
91
|
-
response_type: 'json',
|
92
|
-
timing: 60000,
|
93
|
-
time: Time.new(2018, 1, 1, 0, 49, 0, 0),
|
94
|
-
groups: { db: 131, view: 421 },
|
95
|
-
),
|
96
|
-
)
|
97
|
-
perf_notifier.close
|
98
|
-
|
99
|
-
expect(
|
100
|
-
a_request(:put, breakdowns).with(body: %r|
|
101
|
-
\A{"routes":\[{
|
102
|
-
"method":"DELETE",
|
103
|
-
"route":"/routes-breakdowns",
|
104
|
-
"responseType":"json",
|
105
|
-
"time":"2018-01-01T00:49:00\+00:00",
|
106
|
-
"count":1,
|
107
|
-
"sum":60000.0,
|
108
|
-
"sumsq":3600000000.0,
|
109
|
-
"tdigest":"AAAAAkA0AAAAAAAAAAAAAUdqYAAB",
|
110
|
-
"groups":{
|
111
|
-
"db":{
|
112
|
-
"count":1,
|
113
|
-
"sum":131.0,
|
114
|
-
"sumsq":17161.0,
|
115
|
-
"tdigest":"AAAAAkA0AAAAAAAAAAAAAUMDAAAB"
|
116
|
-
},
|
117
|
-
"view":{
|
118
|
-
"count":1,
|
119
|
-
"sum":421.0,
|
120
|
-
"sumsq":177241.0,
|
121
|
-
"tdigest":"AAAAAkA0AAAAAAAAAAAAAUPSgAAB"
|
122
|
-
}
|
123
|
-
}
|
124
|
-
}\]}\z|x),
|
125
|
-
).to have_been_made
|
126
|
-
end
|
127
|
-
|
128
|
-
it "sends full queue" do
|
129
|
-
perf_notifier.notify(
|
130
|
-
Airbrake::Queue.new(
|
131
|
-
queue: 'emails',
|
132
|
-
error_count: 2,
|
133
|
-
groups: { redis: 131, sql: 421 },
|
134
|
-
timing: 60000,
|
135
|
-
time: Time.new(2018, 1, 1, 0, 49, 0, 0),
|
136
|
-
),
|
137
|
-
)
|
138
|
-
perf_notifier.close
|
139
|
-
|
140
|
-
expect(
|
141
|
-
a_request(:put, queues).with(body: /
|
142
|
-
\A{"queues":\[{
|
143
|
-
"queue":"emails",
|
144
|
-
"errorCount":2,
|
145
|
-
"time":"2018-01-01T00:49:00\+00:00",
|
146
|
-
"count":1,
|
147
|
-
"sum":60000.0,
|
148
|
-
"sumsq":3600000000.0,
|
149
|
-
"tdigest":"AAAAAkA0AAAAAAAAAAAAAUdqYAAB",
|
150
|
-
"groups":{
|
151
|
-
"redis":{
|
152
|
-
"count":1,
|
153
|
-
"sum":131.0,
|
154
|
-
"sumsq":17161.0,
|
155
|
-
"tdigest":"AAAAAkA0AAAAAAAAAAAAAUMDAAAB"
|
156
|
-
},
|
157
|
-
"sql":{
|
158
|
-
"count":1,
|
159
|
-
"sum":421.0,
|
160
|
-
"sumsq":177241.0,
|
161
|
-
"tdigest":"AAAAAkA0AAAAAAAAAAAAAUPSgAAB"
|
162
|
-
}
|
163
|
-
}
|
164
|
-
}\]}\z/x),
|
165
|
-
).to have_been_made
|
166
|
-
end
|
167
|
-
|
168
|
-
it "rounds time to the floor minute" do
|
169
|
-
perf_notifier.notify(
|
170
|
-
Airbrake::Request.new(
|
171
|
-
method: 'GET',
|
172
|
-
route: '/foo',
|
173
|
-
status_code: 200,
|
174
|
-
timing: 60000,
|
175
|
-
time: Time.new(2018, 1, 1, 0, 0, 20, 0),
|
176
|
-
),
|
177
|
-
)
|
178
|
-
perf_notifier.close
|
179
|
-
|
180
|
-
expect(
|
181
|
-
a_request(:put, routes).with(body: /"time":"2018-01-01T00:00:00\+00:00"/),
|
182
|
-
).to have_been_made
|
183
|
-
end
|
184
|
-
|
185
|
-
it "increments routes with the same key" do
|
186
|
-
perf_notifier.notify(
|
187
|
-
Airbrake::Request.new(
|
188
|
-
method: 'GET',
|
189
|
-
route: '/foo',
|
190
|
-
status_code: 200,
|
191
|
-
timing: 213,
|
192
|
-
),
|
193
|
-
)
|
194
|
-
perf_notifier.notify(
|
195
|
-
Airbrake::Request.new(
|
196
|
-
method: 'GET',
|
197
|
-
route: '/foo',
|
198
|
-
status_code: 200,
|
199
|
-
timing: 123,
|
200
|
-
),
|
201
|
-
)
|
202
|
-
perf_notifier.close
|
203
|
-
|
204
|
-
expect(
|
205
|
-
a_request(:put, routes).with(body: /"count":2/),
|
206
|
-
).to have_been_made
|
207
|
-
end
|
208
|
-
|
209
|
-
it "groups routes by time" do
|
210
|
-
perf_notifier.notify(
|
211
|
-
Airbrake::Request.new(
|
212
|
-
method: 'GET',
|
213
|
-
route: '/foo',
|
214
|
-
status_code: 200,
|
215
|
-
timing: 1000,
|
216
|
-
time: Time.new(2018, 1, 1, 0, 0, 49, 0),
|
217
|
-
),
|
218
|
-
)
|
219
|
-
perf_notifier.notify(
|
220
|
-
Airbrake::Request.new(
|
221
|
-
method: 'GET',
|
222
|
-
route: '/foo',
|
223
|
-
status_code: 200,
|
224
|
-
timing: 6000,
|
225
|
-
time: Time.new(2018, 1, 1, 0, 1, 49, 0),
|
226
|
-
),
|
227
|
-
)
|
228
|
-
perf_notifier.close
|
229
|
-
|
230
|
-
expect(
|
231
|
-
a_request(:put, routes).with(
|
232
|
-
body: %r|\A
|
233
|
-
{"routes":\[
|
234
|
-
{"method":"GET","route":"/foo","statusCode":200,
|
235
|
-
"time":"2018-01-01T00:00:00\+00:00","count":1,"sum":1000.0,
|
236
|
-
"sumsq":1000000.0,"tdigest":"AAAAAkA0AAAAAAAAAAAAAUR6AAAB"},
|
237
|
-
{"method":"GET","route":"/foo","statusCode":200,
|
238
|
-
"time":"2018-01-01T00:01:00\+00:00","count":1,"sum":6000.0,
|
239
|
-
"sumsq":36000000.0,"tdigest":"AAAAAkA0AAAAAAAAAAAAAUW7gAAB"}\]}
|
240
|
-
\z|x,
|
241
|
-
),
|
242
|
-
).to have_been_made
|
243
|
-
end
|
244
|
-
|
245
|
-
it "groups routes by route key" do
|
246
|
-
perf_notifier.notify(
|
247
|
-
Airbrake::Request.new(
|
248
|
-
method: 'GET',
|
249
|
-
route: '/foo',
|
250
|
-
status_code: 200,
|
251
|
-
timing: 60000,
|
252
|
-
time: Time.new(2018, 1, 1, 0, 49, 0, 0),
|
253
|
-
),
|
254
|
-
)
|
255
|
-
perf_notifier.notify(
|
256
|
-
Airbrake::Request.new(
|
257
|
-
method: 'POST',
|
258
|
-
route: '/foo',
|
259
|
-
status_code: 200,
|
260
|
-
timing: 60000,
|
261
|
-
time: Time.new(2018, 1, 1, 0, 49, 0, 0),
|
262
|
-
),
|
263
|
-
)
|
264
|
-
perf_notifier.close
|
265
|
-
|
266
|
-
expect(
|
267
|
-
a_request(:put, routes).with(
|
268
|
-
body: %r|\A
|
269
|
-
{"routes":\[
|
270
|
-
{"method":"GET","route":"/foo","statusCode":200,
|
271
|
-
"time":"2018-01-01T00:49:00\+00:00","count":1,"sum":60000.0,
|
272
|
-
"sumsq":3600000000.0,"tdigest":"AAAAAkA0AAAAAAAAAAAAAUdqYAAB"},
|
273
|
-
{"method":"POST","route":"/foo","statusCode":200,
|
274
|
-
"time":"2018-01-01T00:49:00\+00:00","count":1,"sum":60000.0,
|
275
|
-
"sumsq":3600000000.0,"tdigest":"AAAAAkA0AAAAAAAAAAAAAUdqYAAB"}\]}
|
276
|
-
\z|x,
|
277
|
-
),
|
278
|
-
).to have_been_made
|
279
|
-
end
|
280
|
-
|
281
|
-
it "groups performance breakdowns by route key" do
|
282
|
-
perf_notifier.notify(
|
283
|
-
Airbrake::PerformanceBreakdown.new(
|
284
|
-
method: 'DELETE',
|
285
|
-
route: '/routes-breakdowns',
|
286
|
-
response_type: 'json',
|
287
|
-
timing: 2000,
|
288
|
-
time: Time.new(2018, 1, 1, 0, 0, 20, 0),
|
289
|
-
groups: { db: 131, view: 421 },
|
290
|
-
),
|
291
|
-
)
|
292
|
-
perf_notifier.notify(
|
293
|
-
Airbrake::PerformanceBreakdown.new(
|
294
|
-
method: 'DELETE',
|
295
|
-
route: '/routes-breakdowns',
|
296
|
-
response_type: 'json',
|
297
|
-
timing: 2000,
|
298
|
-
time: Time.new(2018, 1, 1, 0, 0, 30, 0),
|
299
|
-
groups: { db: 55, view: 11 },
|
300
|
-
),
|
301
|
-
)
|
302
|
-
perf_notifier.close
|
303
|
-
|
304
|
-
expect(
|
305
|
-
a_request(:put, breakdowns).with(body: %r|
|
306
|
-
\A{"routes":\[{
|
307
|
-
"method":"DELETE",
|
308
|
-
"route":"/routes-breakdowns",
|
309
|
-
"responseType":"json",
|
310
|
-
"time":"2018-01-01T00:00:00\+00:00",
|
311
|
-
"count":2,
|
312
|
-
"sum":4000.0,
|
313
|
-
"sumsq":8000000.0,
|
314
|
-
"tdigest":"AAAAAkA0AAAAAAAAAAAAAUT6AAAC",
|
315
|
-
"groups":{
|
316
|
-
"db":{
|
317
|
-
"count":2,
|
318
|
-
"sum":186.0,
|
319
|
-
"sumsq":20186.0,
|
320
|
-
"tdigest":"AAAAAkA0AAAAAAAAAAAAAkJcAABCmAAAAQE="
|
321
|
-
},
|
322
|
-
"view":{
|
323
|
-
"count":2,
|
324
|
-
"sum":432.0,
|
325
|
-
"sumsq":177362.0,
|
326
|
-
"tdigest":"AAAAAkA0AAAAAAAAAAAAAkEwAABDzQAAAQE="
|
327
|
-
}
|
328
|
-
}
|
329
|
-
}\]}\z|x),
|
330
|
-
).to have_been_made
|
331
|
-
end
|
332
|
-
|
333
|
-
it "groups queues by queue key" do
|
334
|
-
perf_notifier.notify(
|
335
|
-
Airbrake::Queue.new(
|
336
|
-
queue: 'emails',
|
337
|
-
error_count: 2,
|
338
|
-
groups: { redis: 131, sql: 421 },
|
339
|
-
timing: 60000,
|
340
|
-
time: Time.new(2018, 1, 1, 0, 49, 0, 0),
|
341
|
-
),
|
342
|
-
)
|
343
|
-
perf_notifier.notify(
|
344
|
-
Airbrake::Queue.new(
|
345
|
-
queue: 'emails',
|
346
|
-
error_count: 3,
|
347
|
-
groups: { redis: 131, sql: 421 },
|
348
|
-
timing: 60000,
|
349
|
-
time: Time.new(2018, 1, 1, 0, 49, 0, 0),
|
350
|
-
),
|
351
|
-
)
|
352
|
-
perf_notifier.close
|
353
|
-
|
354
|
-
expect(
|
355
|
-
a_request(:put, queues).with(body: /
|
356
|
-
\A{"queues":\[{
|
357
|
-
"queue":"emails",
|
358
|
-
"errorCount":5,
|
359
|
-
"time":"2018-01-01T00:49:00\+00:00",
|
360
|
-
"count":2,
|
361
|
-
"sum":120000.0,
|
362
|
-
"sumsq":7200000000.0,
|
363
|
-
"tdigest":"AAAAAkA0AAAAAAAAAAAAAUdqYAAC",
|
364
|
-
"groups":{
|
365
|
-
"redis":{
|
366
|
-
"count":2,
|
367
|
-
"sum":262.0,
|
368
|
-
"sumsq":34322.0,
|
369
|
-
"tdigest":"AAAAAkA0AAAAAAAAAAAAAUMDAAAC"
|
370
|
-
},
|
371
|
-
"sql":{
|
372
|
-
"count":2,
|
373
|
-
"sum":842.0,
|
374
|
-
"sumsq":354482.0,
|
375
|
-
"tdigest":"AAAAAkA0AAAAAAAAAAAAAUPSgAAC"
|
376
|
-
}
|
377
|
-
}
|
378
|
-
}\]}\z/x),
|
379
|
-
).to have_been_made
|
380
|
-
end
|
381
|
-
|
382
|
-
it "returns a promise" do
|
383
|
-
promise = perf_notifier.notify(
|
384
|
-
Airbrake::Request.new(
|
385
|
-
method: 'GET',
|
386
|
-
route: '/foo',
|
387
|
-
status_code: 200,
|
388
|
-
timing: 123,
|
389
|
-
),
|
390
|
-
)
|
391
|
-
perf_notifier.close
|
392
|
-
|
393
|
-
expect(promise).to be_an(Airbrake::Promise)
|
394
|
-
expect(promise.value).to eq('' => '')
|
395
|
-
end
|
396
|
-
|
397
|
-
it "checks performance stat configuration" do
|
398
|
-
request = Airbrake::Request.new(
|
399
|
-
method: 'GET', route: '/foo', status_code: 200, timing: 123,
|
400
|
-
)
|
401
|
-
allow(Airbrake::Config.instance).to receive(:check_performance_options)
|
402
|
-
.and_return(Airbrake::Promise.new)
|
403
|
-
perf_notifier.notify(request)
|
404
|
-
perf_notifier.close
|
405
|
-
|
406
|
-
expect(Airbrake::Config.instance)
|
407
|
-
.to have_received(:check_performance_options).with(request)
|
408
|
-
end
|
409
|
-
|
410
|
-
it "sends environment when it's specified" do
|
411
|
-
Airbrake::Config.instance.merge(performance_stats: true, environment: 'test')
|
412
|
-
|
413
|
-
perf_notifier.notify(
|
414
|
-
Airbrake::Request.new(
|
415
|
-
method: 'POST',
|
416
|
-
route: '/foo',
|
417
|
-
status_code: 200,
|
418
|
-
timing: 123,
|
419
|
-
),
|
420
|
-
)
|
421
|
-
perf_notifier.close
|
422
|
-
|
423
|
-
expect(
|
424
|
-
a_request(:put, routes).with(
|
425
|
-
body: /\A{"routes":\[.+\],"environment":"test"}\z/x,
|
426
|
-
),
|
427
|
-
).to have_been_made
|
428
|
-
end
|
429
|
-
|
430
|
-
context "when config is invalid" do
|
431
|
-
before { Airbrake::Config.instance.merge(project_id: nil) }
|
432
|
-
|
433
|
-
it "returns a rejected promise" do
|
434
|
-
promise = perf_notifier.notify({})
|
435
|
-
expect(promise).to be_rejected
|
436
|
-
end
|
437
|
-
end
|
438
|
-
|
439
|
-
describe "payload grouping" do
|
440
|
-
let(:flush_period) { 0.5 }
|
441
|
-
|
442
|
-
it "groups payload by performance name and sends it separately" do
|
443
|
-
Airbrake::Config.instance.merge(
|
444
|
-
project_id: 1,
|
445
|
-
project_key: 'banana',
|
446
|
-
performance_stats: true,
|
447
|
-
performance_stats_flush_period: flush_period,
|
448
|
-
)
|
449
|
-
|
450
|
-
perf_notifier.notify(
|
451
|
-
Airbrake::Request.new(
|
452
|
-
method: 'GET',
|
453
|
-
route: '/foo',
|
454
|
-
status_code: 200,
|
455
|
-
timing: 123,
|
456
|
-
),
|
457
|
-
)
|
458
|
-
|
459
|
-
perf_notifier.notify(
|
460
|
-
Airbrake::Query.new(
|
461
|
-
method: 'POST',
|
462
|
-
route: '/foo',
|
463
|
-
query: 'SELECT * FROM things',
|
464
|
-
timing: 123,
|
465
|
-
),
|
466
|
-
)
|
467
|
-
|
468
|
-
sleep(flush_period + 0.5)
|
469
|
-
|
470
|
-
expect(a_request(:put, routes)).to have_been_made
|
471
|
-
expect(a_request(:put, queries)).to have_been_made
|
472
|
-
end
|
473
|
-
end
|
474
|
-
|
475
|
-
context "when an ignore filter was defined" do
|
476
|
-
before { perf_notifier.add_filter(&:ignore!) }
|
477
|
-
|
478
|
-
it "doesn't notify airbrake of requests" do
|
479
|
-
perf_notifier.notify(
|
480
|
-
Airbrake::Request.new(
|
481
|
-
method: 'GET',
|
482
|
-
route: '/foo',
|
483
|
-
status_code: 200,
|
484
|
-
timing: 1,
|
485
|
-
),
|
486
|
-
)
|
487
|
-
perf_notifier.close
|
488
|
-
|
489
|
-
expect(a_request(:put, routes)).not_to have_been_made
|
490
|
-
end
|
491
|
-
|
492
|
-
it "doesn't notify airbrake of queries" do
|
493
|
-
perf_notifier.notify(
|
494
|
-
Airbrake::Query.new(
|
495
|
-
method: 'POST',
|
496
|
-
route: '/foo',
|
497
|
-
query: 'SELECT * FROM things',
|
498
|
-
timing: 1,
|
499
|
-
),
|
500
|
-
)
|
501
|
-
perf_notifier.close
|
502
|
-
|
503
|
-
expect(a_request(:put, queries)).not_to have_been_made
|
504
|
-
end
|
505
|
-
|
506
|
-
it "returns a rejected promise" do
|
507
|
-
promise = perf_notifier.notify(
|
508
|
-
Airbrake::Query.new(
|
509
|
-
method: 'POST',
|
510
|
-
route: '/foo',
|
511
|
-
query: 'SELECT * FROM things',
|
512
|
-
timing: 1,
|
513
|
-
),
|
514
|
-
)
|
515
|
-
perf_notifier.close
|
516
|
-
|
517
|
-
expect(promise.value).to eq(
|
518
|
-
'error' => 'Airbrake::Query was ignored by a filter',
|
519
|
-
)
|
520
|
-
end
|
521
|
-
end
|
522
|
-
|
523
|
-
context "when a filter that modifies payload was defined" do
|
524
|
-
before do
|
525
|
-
perf_notifier.add_filter do |metric|
|
526
|
-
metric.route = '[Filtered]'
|
527
|
-
end
|
528
|
-
end
|
529
|
-
|
530
|
-
it "notifies airbrake with modified payload" do
|
531
|
-
perf_notifier.notify(
|
532
|
-
Airbrake::Query.new(
|
533
|
-
method: 'POST',
|
534
|
-
route: '/foo',
|
535
|
-
query: 'SELECT * FROM things',
|
536
|
-
timing: 123,
|
537
|
-
),
|
538
|
-
)
|
539
|
-
perf_notifier.close
|
540
|
-
|
541
|
-
expect(
|
542
|
-
a_request(:put, queries).with(
|
543
|
-
body: /\A{"queries":\[{"method":"POST","route":"\[Filtered\]"/,
|
544
|
-
),
|
545
|
-
).to have_been_made
|
546
|
-
end
|
547
|
-
end
|
548
|
-
|
549
|
-
context "when provided :timing is zero" do
|
550
|
-
it "doesn't notify" do
|
551
|
-
queue = Airbrake::Queue.new(queue: 'bananas', error_count: 0, timing: 0)
|
552
|
-
perf_notifier.notify(queue)
|
553
|
-
perf_notifier.close
|
554
|
-
|
555
|
-
expect(a_request(:put, queues)).not_to have_been_made
|
556
|
-
end
|
557
|
-
|
558
|
-
it "returns a rejected promise" do
|
559
|
-
queue = Airbrake::Queue.new(queue: 'bananas', error_count: 0, timing: 0)
|
560
|
-
promise = perf_notifier.notify(queue)
|
561
|
-
perf_notifier.close
|
562
|
-
|
563
|
-
expect(promise.value).to eq('error' => ':timing cannot be zero')
|
564
|
-
end
|
565
|
-
end
|
566
|
-
end
|
567
|
-
|
568
|
-
describe "#notify_sync" do
|
569
|
-
it "notifies synchronously" do
|
570
|
-
retval = perf_notifier.notify_sync(
|
571
|
-
Airbrake::Query.new(
|
572
|
-
method: 'POST',
|
573
|
-
route: '/foo',
|
574
|
-
query: 'SELECT * FROM things',
|
575
|
-
timing: 123,
|
576
|
-
),
|
577
|
-
)
|
578
|
-
|
579
|
-
expect(
|
580
|
-
a_request(:put, queries).with(
|
581
|
-
body: %r|\A{"queries":\[{"method":"POST","route":"/foo"|,
|
582
|
-
),
|
583
|
-
).to have_been_made
|
584
|
-
expect(retval).to eq('' => '')
|
585
|
-
end
|
586
|
-
end
|
587
|
-
|
588
|
-
describe "#close" do
|
589
|
-
before do
|
590
|
-
Airbrake::Config.instance.merge(performance_stats_flush_period: 0.1)
|
591
|
-
end
|
592
|
-
|
593
|
-
after do
|
594
|
-
Airbrake::Config.instance.merge(performance_stats_flush_period: 0)
|
595
|
-
end
|
596
|
-
|
597
|
-
it "kills the background thread" do
|
598
|
-
expect_any_instance_of(Thread).to receive(:kill).and_call_original
|
599
|
-
perf_notifier.notify(
|
600
|
-
Airbrake::Query.new(
|
601
|
-
method: 'POST',
|
602
|
-
route: '/foo',
|
603
|
-
query: 'SELECT * FROM things',
|
604
|
-
timing: 123,
|
605
|
-
),
|
606
|
-
)
|
607
|
-
perf_notifier.close
|
608
|
-
end
|
609
|
-
|
610
|
-
it "logs the exit message" do
|
611
|
-
allow(Airbrake::Loggable.instance).to receive(:debug)
|
612
|
-
|
613
|
-
perf_notifier.close
|
614
|
-
|
615
|
-
expect(Airbrake::Loggable.instance).to have_received(:debug).with(
|
616
|
-
/Airbrake::PerformanceNotifier thread pool closed/,
|
617
|
-
)
|
618
|
-
end
|
619
|
-
end
|
620
|
-
|
621
|
-
describe "#delete_filter" do
|
622
|
-
let(:filter) do
|
623
|
-
Class.new do
|
624
|
-
def call(metric); end
|
625
|
-
end
|
626
|
-
end
|
627
|
-
|
628
|
-
before { perf_notifier.add_filter(filter.new) }
|
629
|
-
|
630
|
-
it "deletes a filter" do
|
631
|
-
perf_notifier.delete_filter(filter)
|
632
|
-
perf_notifier.notify(
|
633
|
-
Airbrake::Request.new(
|
634
|
-
method: 'POST',
|
635
|
-
route: '/foo',
|
636
|
-
status_code: 200,
|
637
|
-
timing: 123,
|
638
|
-
),
|
639
|
-
)
|
640
|
-
perf_notifier.close
|
641
|
-
|
642
|
-
expect(a_request(:put, routes)).to have_been_made
|
643
|
-
end
|
644
|
-
end
|
645
|
-
end
|