@@ -110,7 +110,7 @@ class ConstantRateLimiter:
110110
111111 def __init__ (self , rate_limit_s , max_sleep_chunk_s = 5 ):
112112 """
113- :param rate_limit_s: rate limit in seconds
113+ :param rate_limit_s: rate limit in executions per second
114114 :param max_sleep_chunk_s: maximum size of each sleep chunk while waiting for the next period
115115 """
116116 self .rate_limit_s = max (rate_limit_s , 0 )
@@ -305,7 +305,9 @@ def __init__(
305305 ):
306306 self ._check = check
307307 self ._config_host = config_host
308+ # The min_collection_interval is the expected collection interval for the main check
308309 self ._min_collection_interval = min_collection_interval
310+ self ._expected_collection_interval = 1 / rate_limit if rate_limit > 0 else 0
309311 # map[dbname -> psycopg connection]
310312 self ._log = get_check_logger ()
311313 self ._job_loop_future = None
@@ -358,12 +360,12 @@ def run_job_loop(self, tags):
358360 if (
359361 hasattr (self ._check , 'health' )
360362 and self ._enable_missed_collection_event
361- and self ._min_collection_interval >= 1
363+ and self ._expected_collection_interval >= 1
362364 and self ._last_run_start
363365 ):
364366 # Assume a collection interval of less than 1 second is an attempt to run the job in a loop
365367 elapsed_time = time .time () - self ._last_run_start
366- if elapsed_time > self ._min_collection_interval :
368+ if elapsed_time > self ._expected_collection_interval :
367369 # Missed a collection interval, submit a health event for each feature that depends on this job
368370 for feature in self ._features :
369371 self ._check .health .submit_health_event (
@@ -377,8 +379,10 @@ def run_job_loop(self, tags):
377379 data = {
378380 "dbms" : self ._dbms ,
379381 "job_name" : self ._job_name ,
380- "last_run_start" : self ._last_run_start ,
381- "elapsed_time" : (time .time () - self ._last_run_start ) * 1000 ,
382+ # send in ms for consistency with other metrics
383+ "last_run_start" : self ._last_run_start * 1000 ,
384+ "elapsed_time" : elapsed_time * 1000 ,
385+ "expected_collection_interval" : self ._expected_collection_interval * 1000 ,
382386 "feature" : feature ,
383387 },
384388 )
0 commit comments