Fix test_queue.py tests
This restores the reporter class as was before the metrics changes.
This commit is contained in:
parent
3f6f5162e8
commit
fc671f3dde
2 changed files with 18 additions and 9 deletions
4
app.py
4
app.py
|
@ -20,7 +20,7 @@ from data.billing import Billing
|
||||||
from data.buildlogs import BuildLogs
|
from data.buildlogs import BuildLogs
|
||||||
from data.archivedlogs import LogArchive
|
from data.archivedlogs import LogArchive
|
||||||
from data.userevent import UserEventsBuilderModule
|
from data.userevent import UserEventsBuilderModule
|
||||||
from data.queue import WorkQueue
|
from data.queue import WorkQueue, MetricQueueReporter
|
||||||
from util.saas.analytics import Analytics
|
from util.saas.analytics import Analytics
|
||||||
from util.saas.exceptionlog import Sentry
|
from util.saas.exceptionlog import Sentry
|
||||||
from util.names import urn_generator
|
from util.names import urn_generator
|
||||||
|
@ -137,7 +137,7 @@ oauth_apps = [github_login, github_trigger, gitlab_trigger, google_login]
|
||||||
|
|
||||||
image_diff_queue = WorkQueue(app.config['DIFFS_QUEUE_NAME'], tf)
|
image_diff_queue = WorkQueue(app.config['DIFFS_QUEUE_NAME'], tf)
|
||||||
dockerfile_build_queue = WorkQueue(app.config['DOCKERFILE_BUILD_QUEUE_NAME'], tf,
|
dockerfile_build_queue = WorkQueue(app.config['DOCKERFILE_BUILD_QUEUE_NAME'], tf,
|
||||||
metric_queue=metric_queue)
|
reporter=MetricQueueReporter(metric_queue))
|
||||||
notification_queue = WorkQueue(app.config['NOTIFICATION_QUEUE_NAME'], tf)
|
notification_queue = WorkQueue(app.config['NOTIFICATION_QUEUE_NAME'], tf)
|
||||||
|
|
||||||
database.configure(app.config)
|
database.configure(app.config)
|
||||||
|
|
|
@ -13,11 +13,22 @@ class NoopWith:
|
||||||
def __exit__(self, type, value, traceback):
|
def __exit__(self, type, value, traceback):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
class MetricQueueReporter(object):
|
||||||
|
def __init__(self, metric_queue):
|
||||||
|
self._metric_queue = metric_queue
|
||||||
|
|
||||||
|
def __call__(self, currently_processing, running_count, total_count):
|
||||||
|
need_capacity_count = total_count - running_count
|
||||||
|
self._metric_queue.put('BuildCapacityShortage', need_capacity_count, unit='Count')
|
||||||
|
|
||||||
|
building_percent = 100 if currently_processing else 0
|
||||||
|
self._metric_queue.put('PercentBuilding', building_percent, unit='Percent')
|
||||||
|
|
||||||
class WorkQueue(object):
|
class WorkQueue(object):
|
||||||
def __init__(self, queue_name, transaction_factory,
|
def __init__(self, queue_name, transaction_factory,
|
||||||
canonical_name_match_list=None, metric_queue=None):
|
canonical_name_match_list=None, reporter=None):
|
||||||
self._queue_name = queue_name
|
self._queue_name = queue_name
|
||||||
self._metric_queue = metric_queue
|
self._reporter = reporter
|
||||||
self._transaction_factory = transaction_factory
|
self._transaction_factory = transaction_factory
|
||||||
self._currently_processing = False
|
self._currently_processing = False
|
||||||
|
|
||||||
|
@ -75,14 +86,12 @@ class WorkQueue(object):
|
||||||
return (running_count, available_not_running_count, available_count)
|
return (running_count, available_not_running_count, available_count)
|
||||||
|
|
||||||
def update_metrics(self):
|
def update_metrics(self):
|
||||||
if self._metric_queue is None:
|
if self._reporter is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
(running_count, available_not_running_count, available_count) = self.get_metrics()
|
(running_count, available_not_running_count, available_count) = self.get_metrics()
|
||||||
self._metric_queue.put('BuildCapacityShortage', available_not_running_count, unit='Count')
|
self._reporter(self._currently_processing, running_count,
|
||||||
|
running_count + available_not_running_count)
|
||||||
building_percent = 100 if self._currently_processing else 0
|
|
||||||
self._metric_queue.put('PercentBuilding', building_percent, unit='Percent')
|
|
||||||
|
|
||||||
def has_retries_remaining(self, item_id):
|
def has_retries_remaining(self, item_id):
|
||||||
""" Returns whether the queue item with the given id has any retries remaining. If the
|
""" Returns whether the queue item with the given id has any retries remaining. If the
|
||||||
|
|
Reference in a new issue