@@ -72,6 +72,7 @@ module VCAP::CloudController::Metrics
72
72
before do
73
73
allow ( statsd_updater ) . to receive ( :update_user_count )
74
74
allow ( statsd_updater ) . to receive ( :update_job_queue_length )
75
+ allow ( statsd_updater ) . to receive ( :update_job_queue_load )
75
76
allow ( statsd_updater ) . to receive ( :update_thread_info_thin )
76
77
allow ( statsd_updater ) . to receive ( :update_failed_job_count )
77
78
allow ( statsd_updater ) . to receive ( :update_vitals )
@@ -81,6 +82,7 @@ module VCAP::CloudController::Metrics
81
82
82
83
allow ( prometheus_updater ) . to receive ( :update_user_count )
83
84
allow ( prometheus_updater ) . to receive ( :update_job_queue_length )
85
+ allow ( prometheus_updater ) . to receive ( :update_job_queue_load )
84
86
allow ( prometheus_updater ) . to receive ( :update_thread_info_thin )
85
87
allow ( prometheus_updater ) . to receive ( :update_failed_job_count )
86
88
allow ( prometheus_updater ) . to receive ( :update_vitals )
@@ -101,6 +103,11 @@ module VCAP::CloudController::Metrics
101
103
periodic_updater . setup_updates
102
104
end
103
105
106
+ it 'bumps the load of cc job queues and sets periodic timer' do
107
+ expect ( periodic_updater ) . to receive ( :update_job_queue_load ) . once
108
+ periodic_updater . setup_updates
109
+ end
110
+
104
111
it 'bumps the length of cc failed job queues and sets periodic timer' do
105
112
expect ( periodic_updater ) . to receive ( :update_failed_job_count ) . once
106
113
periodic_updater . setup_updates
@@ -161,45 +168,53 @@ module VCAP::CloudController::Metrics
161
168
@periodic_timers [ 1 ] [ :block ] . call
162
169
end
163
170
164
- it 'updates thread count and event machine queues' do
171
+ it 'bumps the load of cc job queues and sets periodic timer ' do
165
172
expect ( periodic_updater ) . to receive ( :catch_error ) . once . and_call_original
166
- expect ( periodic_updater ) . to receive ( :update_thread_info ) . once
173
+ expect ( periodic_updater ) . to receive ( :update_job_queue_load ) . once
167
174
expect ( @periodic_timers [ 2 ] [ :interval ] ) . to eq ( 30 )
168
175
169
176
@periodic_timers [ 2 ] [ :block ] . call
170
177
end
171
178
172
- it 'bumps the length of cc failed job queues and sets periodic timer ' do
179
+ it 'updates thread count and event machine queues ' do
173
180
expect ( periodic_updater ) . to receive ( :catch_error ) . once . and_call_original
174
- expect ( periodic_updater ) . to receive ( :update_failed_job_count ) . once
181
+ expect ( periodic_updater ) . to receive ( :update_thread_info ) . once
175
182
expect ( @periodic_timers [ 3 ] [ :interval ] ) . to eq ( 30 )
176
183
177
184
@periodic_timers [ 3 ] [ :block ] . call
178
185
end
179
186
180
- it 'updates the vitals ' do
187
+ it 'bumps the length of cc failed job queues and sets periodic timer ' do
181
188
expect ( periodic_updater ) . to receive ( :catch_error ) . once . and_call_original
182
- expect ( periodic_updater ) . to receive ( :update_vitals ) . once
189
+ expect ( periodic_updater ) . to receive ( :update_failed_job_count ) . once
183
190
expect ( @periodic_timers [ 4 ] [ :interval ] ) . to eq ( 30 )
184
191
185
192
@periodic_timers [ 4 ] [ :block ] . call
186
193
end
187
194
188
- it 'updates the log counts ' do
195
+ it 'updates the vitals ' do
189
196
expect ( periodic_updater ) . to receive ( :catch_error ) . once . and_call_original
190
- expect ( periodic_updater ) . to receive ( :update_log_counts ) . once
197
+ expect ( periodic_updater ) . to receive ( :update_vitals ) . once
191
198
expect ( @periodic_timers [ 5 ] [ :interval ] ) . to eq ( 30 )
192
199
193
200
@periodic_timers [ 5 ] [ :block ] . call
194
201
end
195
202
196
- it 'updates the task stats ' do
203
+ it 'updates the log counts ' do
197
204
expect ( periodic_updater ) . to receive ( :catch_error ) . once . and_call_original
198
- expect ( periodic_updater ) . to receive ( :update_task_stats ) . once
205
+ expect ( periodic_updater ) . to receive ( :update_log_counts ) . once
199
206
expect ( @periodic_timers [ 6 ] [ :interval ] ) . to eq ( 30 )
200
207
201
208
@periodic_timers [ 6 ] [ :block ] . call
202
209
end
210
+
211
+ it 'updates the task stats' do
212
+ expect ( periodic_updater ) . to receive ( :catch_error ) . once . and_call_original
213
+ expect ( periodic_updater ) . to receive ( :update_task_stats ) . once
214
+ expect ( @periodic_timers [ 7 ] [ :interval ] ) . to eq ( 30 )
215
+
216
+ @periodic_timers [ 7 ] [ :block ] . call
217
+ end
203
218
end
204
219
end
205
220
@@ -353,6 +368,82 @@ module VCAP::CloudController::Metrics
353
368
end
354
369
end
355
370
371
+ describe '#update_job_queue_load' do
372
+ before do
373
+ allow ( statsd_updater ) . to receive ( :update_job_queue_load )
374
+ allow ( prometheus_updater ) . to receive ( :update_job_queue_load )
375
+ end
376
+
377
+ context 'when there are pending jobs ready to run in the local queue' do
378
+ it 'emits the correct count' do
379
+ Delayed ::Job . enqueue (
380
+ VCAP ::CloudController ::Jobs ::Runtime ::EventsCleanup . new ( 1 ) ,
381
+ queue : VCAP ::CloudController ::Jobs ::Queues . local ( VCAP ::CloudController ::Config . config ) ,
382
+ run_at : Time . now
383
+ )
384
+ periodic_updater . update_job_queue_load
385
+
386
+ expected_pending_job_queue_load = {
387
+ 'cc-api-0' : 1
388
+ }
389
+ expected_total = 1
390
+
391
+ expect ( statsd_updater ) . to have_received ( :update_job_queue_load ) . with ( expected_pending_job_queue_load , expected_total )
392
+ expect ( prometheus_updater ) . to have_received ( :update_job_queue_load ) . with ( expected_pending_job_queue_load )
393
+ end
394
+ end
395
+
396
+ context 'when local queue does not have pending jobs' do
397
+ it 'emits the local queue load as 0 for discoverability' do
398
+ periodic_updater . update_job_queue_load
399
+
400
+ expected_pending_job_queue_load = {
401
+ 'cc-api-0' : 0
402
+ }
403
+ expected_total = 0
404
+
405
+ expect ( statsd_updater ) . to have_received ( :update_job_queue_load ) . with ( expected_pending_job_queue_load , expected_total )
406
+ expect ( prometheus_updater ) . to have_received ( :update_job_queue_load ) . with ( expected_pending_job_queue_load )
407
+ end
408
+ end
409
+
410
+ it 'includes the load of the delayed job queue and the total' do
411
+ Delayed ::Job . enqueue ( VCAP ::CloudController ::Jobs ::Runtime ::EventsCleanup . new ( 1 ) , queue : 'cc_local' , run_at : Time . now )
412
+ Delayed ::Job . enqueue ( VCAP ::CloudController ::Jobs ::Runtime ::EventsCleanup . new ( 1 ) , queue : 'cc_local' , run_at : Time . now )
413
+ Delayed ::Job . enqueue ( VCAP ::CloudController ::Jobs ::Runtime ::EventsCleanup . new ( 1 ) , queue : 'cc_generic' , run_at : Time . now )
414
+
415
+ periodic_updater . update_job_queue_load
416
+
417
+ expected_pending_job_queue_load = {
418
+ cc_local : 2 ,
419
+ cc_generic : 1 ,
420
+ 'cc-api-0' : 0
421
+ }
422
+ expected_total = 3
423
+
424
+ expect ( statsd_updater ) . to have_received ( :update_job_queue_load ) . with ( expected_pending_job_queue_load , expected_total )
425
+ expect ( prometheus_updater ) . to have_received ( :update_job_queue_load ) . with ( expected_pending_job_queue_load )
426
+ end
427
+
428
+ it 'does not contain failed jobs in job queue load metric' do
429
+ Delayed ::Job . enqueue ( VCAP ::CloudController ::Jobs ::Runtime ::EventsCleanup . new ( 1 ) , queue : 'cc_local' , failed_at : Time . now + 60 , run_at : Time . now )
430
+ Delayed ::Job . enqueue ( VCAP ::CloudController ::Jobs ::Runtime ::EventsCleanup . new ( 1 ) , queue : 'cc_local' , run_at : Time . now )
431
+ Delayed ::Job . enqueue ( VCAP ::CloudController ::Jobs ::Runtime ::EventsCleanup . new ( 1 ) , queue : 'cc_generic' , failed_at : Time . now + 60 , run_at : Time . now )
432
+ Delayed ::Job . enqueue ( VCAP ::CloudController ::Jobs ::Runtime ::EventsCleanup . new ( 1 ) , queue : 'cc_generic' , run_at : Time . now )
433
+
434
+ periodic_updater . update_job_queue_load
435
+
436
+ expected_pending_job_queue_load = {
437
+ cc_local : 1 ,
438
+ cc_generic : 1 ,
439
+ 'cc-api-0' : 0
440
+ }
441
+ expected_total = 2
442
+ expect ( statsd_updater ) . to have_received ( :update_job_queue_load ) . with ( expected_pending_job_queue_load , expected_total )
443
+ expect ( prometheus_updater ) . to have_received ( :update_job_queue_load ) . with ( expected_pending_job_queue_load )
444
+ end
445
+ end
446
+
356
447
describe '#update_failed_job_count' do
357
448
before do
358
449
allow ( statsd_updater ) . to receive ( :update_failed_job_count )
@@ -644,6 +735,7 @@ module VCAP::CloudController::Metrics
644
735
it 'calls all update methods' do
645
736
expect ( periodic_updater ) . to receive ( :update_user_count ) . once
646
737
expect ( periodic_updater ) . to receive ( :update_job_queue_length ) . once
738
+ expect ( periodic_updater ) . to receive ( :update_job_queue_load ) . once
647
739
expect ( periodic_updater ) . to receive ( :update_thread_info ) . once
648
740
expect ( periodic_updater ) . to receive ( :update_failed_job_count ) . once
649
741
expect ( periodic_updater ) . to receive ( :update_vitals ) . once
0 commit comments