@@ -6,27 +6,10 @@ module VCAP::CloudController::Metrics
66 let ( :periodic_updater ) { PeriodicUpdater . new ( start_time , log_counter , logger , statsd_updater , prometheus_updater ) }
77 let ( :statsd_updater ) { double ( :statsd_updater ) }
88 let ( :prometheus_updater ) { double ( :prometheus_updater ) }
9- let ( :threadqueue ) { double ( EventMachine ::Queue , size : 20 , num_waiting : 0 ) }
10- let ( :resultqueue ) { double ( EventMachine ::Queue , size : 0 , num_waiting : 1 ) }
119 let ( :start_time ) { Time . now . utc - 90 }
1210 let ( :log_counter ) { double ( :log_counter , counts : { } ) }
1311 let ( :logger ) { double ( :logger ) }
1412
15- before do
16- allow ( EventMachine ) . to receive ( :connection_count ) . and_return ( 123 )
17-
18- allow ( EventMachine ) . to receive ( :instance_variable_get ) do |instance_var |
19- case instance_var
20- when :@threadqueue
21- threadqueue
22- when :@resultqueue
23- resultqueue
24- else
25- raise "Unexpected call: #{ instance_var } "
26- end
27- end
28- end
29-
3013 describe 'task stats' do
3114 before do
3215 allow ( statsd_updater ) . to receive ( :update_task_stats )
@@ -73,7 +56,6 @@ module VCAP::CloudController::Metrics
7356 allow ( statsd_updater ) . to receive ( :update_user_count )
7457 allow ( statsd_updater ) . to receive ( :update_job_queue_length )
7558 allow ( statsd_updater ) . to receive ( :update_job_queue_load )
76- allow ( statsd_updater ) . to receive ( :update_thread_info_thin )
7759 allow ( statsd_updater ) . to receive ( :update_failed_job_count )
7860 allow ( statsd_updater ) . to receive ( :update_vitals )
7961 allow ( statsd_updater ) . to receive ( :update_log_counts )
@@ -83,14 +65,11 @@ module VCAP::CloudController::Metrics
8365 allow ( prometheus_updater ) . to receive ( :update_user_count )
8466 allow ( prometheus_updater ) . to receive ( :update_job_queue_length )
8567 allow ( prometheus_updater ) . to receive ( :update_job_queue_load )
86- allow ( prometheus_updater ) . to receive ( :update_thread_info_thin )
8768 allow ( prometheus_updater ) . to receive ( :update_failed_job_count )
8869 allow ( prometheus_updater ) . to receive ( :update_vitals )
8970 allow ( prometheus_updater ) . to receive ( :update_log_counts )
9071 allow ( prometheus_updater ) . to receive ( :update_task_stats )
9172 allow ( prometheus_updater ) . to receive ( :update_deploying_count )
92-
93- allow ( EventMachine ) . to receive ( :add_periodic_timer )
9473 end
9574
9675 it 'bumps the number of users and sets periodic timer' do
@@ -113,11 +92,6 @@ module VCAP::CloudController::Metrics
11392 periodic_updater . setup_updates
11493 end
11594
116- it 'updates thread count and event machine queues' do
117- expect ( periodic_updater ) . to receive ( :update_thread_info ) . once
118- periodic_updater . setup_updates
119- end
120-
12195 it 'updates the vitals' do
12296 expect ( periodic_updater ) . to receive ( :update_vitals ) . once
12397 periodic_updater . setup_updates
@@ -138,15 +112,16 @@ module VCAP::CloudController::Metrics
138112 periodic_updater . setup_updates
139113 end
140114
141- context 'when EventMachine periodic_timer tasks are run' do
115+ context 'when Concurrent::TimerTasks are run' do
142116 before do
143117 @periodic_timers = [ ]
144118
145- allow ( EventMachine ) . to receive ( :add_periodic_timer ) do |interval , &block |
119+ allow ( Concurrent :: TimerTask ) . to receive ( :new ) do |opts , &block |
146120 @periodic_timers << {
147- interval :,
148- block :
121+ interval : opts [ :execution_interval ] ,
122+ block : block
149123 }
124+ double ( 'TimerTask' , execute : nil , shutdown : nil , kill : nil , running? : false )
150125 end
151126
152127 periodic_updater . setup_updates
@@ -176,44 +151,36 @@ module VCAP::CloudController::Metrics
176151 @periodic_timers [ 2 ] [ :block ] . call
177152 end
178153
179- it 'updates thread count and event machine queues' do
180- expect ( periodic_updater ) . to receive ( :catch_error ) . once . and_call_original
181- expect ( periodic_updater ) . to receive ( :update_thread_info ) . once
182- expect ( @periodic_timers [ 3 ] [ :interval ] ) . to eq ( 30 )
183-
184- @periodic_timers [ 3 ] [ :block ] . call
185- end
186-
187154 it 'bumps the length of cc failed job queues and sets periodic timer' do
188155 expect ( periodic_updater ) . to receive ( :catch_error ) . once . and_call_original
189156 expect ( periodic_updater ) . to receive ( :update_failed_job_count ) . once
190- expect ( @periodic_timers [ 4 ] [ :interval ] ) . to eq ( 30 )
157+ expect ( @periodic_timers [ 3 ] [ :interval ] ) . to eq ( 30 )
191158
192- @periodic_timers [ 4 ] [ :block ] . call
159+ @periodic_timers [ 3 ] [ :block ] . call
193160 end
194161
195162 it 'updates the vitals' do
196163 expect ( periodic_updater ) . to receive ( :catch_error ) . once . and_call_original
197164 expect ( periodic_updater ) . to receive ( :update_vitals ) . once
198- expect ( @periodic_timers [ 5 ] [ :interval ] ) . to eq ( 30 )
165+ expect ( @periodic_timers [ 4 ] [ :interval ] ) . to eq ( 30 )
199166
200- @periodic_timers [ 5 ] [ :block ] . call
167+ @periodic_timers [ 4 ] [ :block ] . call
201168 end
202169
203170 it 'updates the log counts' do
204171 expect ( periodic_updater ) . to receive ( :catch_error ) . once . and_call_original
205172 expect ( periodic_updater ) . to receive ( :update_log_counts ) . once
206- expect ( @periodic_timers [ 6 ] [ :interval ] ) . to eq ( 30 )
173+ expect ( @periodic_timers [ 5 ] [ :interval ] ) . to eq ( 30 )
207174
208- @periodic_timers [ 6 ] [ :block ] . call
175+ @periodic_timers [ 5 ] [ :block ] . call
209176 end
210177
211178 it 'updates the task stats' do
212179 expect ( periodic_updater ) . to receive ( :catch_error ) . once . and_call_original
213180 expect ( periodic_updater ) . to receive ( :update_task_stats ) . once
214- expect ( @periodic_timers [ 7 ] [ :interval ] ) . to eq ( 30 )
181+ expect ( @periodic_timers [ 6 ] [ :interval ] ) . to eq ( 30 )
215182
216- @periodic_timers [ 7 ] [ :block ] . call
183+ @periodic_timers [ 6 ] [ :block ] . call
217184 end
218185 end
219186 end
@@ -538,75 +505,6 @@ module VCAP::CloudController::Metrics
538505 end
539506 end
540507
541- describe '#update_thread_info' do
542- before do
543- allow ( statsd_updater ) . to receive ( :update_thread_info_thin )
544- allow ( prometheus_updater ) . to receive ( :update_thread_info_thin )
545- end
546-
547- it 'contains EventMachine data and send it to all updaters' do
548- expected_thread_info = {
549- thread_count : Thread . list . size ,
550- event_machine : {
551- connection_count : 123 ,
552- threadqueue : {
553- size : 20 ,
554- num_waiting : 0
555- } ,
556- resultqueue : {
557- size : 0 ,
558- num_waiting : 1
559- }
560- }
561- }
562-
563- periodic_updater . update_thread_info
564-
565- expect ( statsd_updater ) . to have_received ( :update_thread_info_thin ) . with ( expected_thread_info )
566- expect ( prometheus_updater ) . to have_received ( :update_thread_info_thin ) . with ( expected_thread_info )
567- end
568-
569- context 'when resultqueue and/or threadqueue is not a queue' do
570- let ( :resultqueue ) { [ ] }
571- let ( :threadqueue ) { nil }
572-
573- it 'does not blow up' do
574- expected_thread_info = {
575- thread_count : Thread . list . size ,
576- event_machine : {
577- connection_count : 123 ,
578- threadqueue : {
579- size : 0 ,
580- num_waiting : 0
581- } ,
582- resultqueue : {
583- size : 0 ,
584- num_waiting : 0
585- }
586- }
587- }
588-
589- periodic_updater . update_thread_info
590-
591- expect ( statsd_updater ) . to have_received ( :update_thread_info_thin ) . with ( expected_thread_info )
592- expect ( prometheus_updater ) . to have_received ( :update_thread_info_thin ) . with ( expected_thread_info )
593- end
594- end
595-
596- context 'when Puma is configured as webserver' do
597- before do
598- TestConfig . override ( webserver : 'puma' )
599- end
600-
601- it 'does not send EventMachine data to updaters' do
602- periodic_updater . update_thread_info
603-
604- expect ( statsd_updater ) . not_to have_received ( :update_thread_info_thin )
605- expect ( prometheus_updater ) . not_to have_received ( :update_thread_info_thin )
606- end
607- end
608- end
609-
610508 describe '#update_vitals' do
611509 before do
612510 allow ( statsd_updater ) . to receive ( :update_vitals )
@@ -736,7 +634,6 @@ module VCAP::CloudController::Metrics
736634 expect ( periodic_updater ) . to receive ( :update_user_count ) . once
737635 expect ( periodic_updater ) . to receive ( :update_job_queue_length ) . once
738636 expect ( periodic_updater ) . to receive ( :update_job_queue_load ) . once
739- expect ( periodic_updater ) . to receive ( :update_thread_info ) . once
740637 expect ( periodic_updater ) . to receive ( :update_failed_job_count ) . once
741638 expect ( periodic_updater ) . to receive ( :update_vitals ) . once
742639 expect ( periodic_updater ) . to receive ( :update_log_counts ) . once
0 commit comments