diff --git a/app.py b/app.py index 0fcda573c..2b7c2d643 100644 --- a/app.py +++ b/app.py @@ -142,11 +142,12 @@ dex_login = DexOAuthConfig(app.config, 'DEX_LOGIN_CONFIG') oauth_apps = [github_login, github_trigger, gitlab_trigger, google_login, dex_login] -image_diff_queue = WorkQueue(app.config['DIFFS_QUEUE_NAME'], tf) -image_replication_queue = WorkQueue(app.config['REPLICATION_QUEUE_NAME'], tf) +image_diff_queue = WorkQueue(app.config['DIFFS_QUEUE_NAME'], tf, metric_queue=metric_queue) +image_replication_queue = WorkQueue(app.config['REPLICATION_QUEUE_NAME'], tf, metric_queue=metric_queue) 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, metric_queue=metric_queue) database.configure(app.config) model.config.app_config = app.config diff --git a/data/queue.py b/data/queue.py index a2a7ba879..b787d22be 100644 --- a/data/queue.py +++ b/data/queue.py @@ -26,9 +26,10 @@ class MetricQueueReporter(object): class WorkQueue(object): def __init__(self, queue_name, transaction_factory, - canonical_name_match_list=None, reporter=None): + canonical_name_match_list=None, reporter=None, metric_queue=None): self._queue_name = queue_name self._reporter = reporter + self._metric_queue = metric_queue self._transaction_factory = transaction_factory self._currently_processing = False @@ -86,12 +87,20 @@ class WorkQueue(object): return (running_count, available_not_running_count, available_count) def update_metrics(self): - if self._reporter is None: + if self._reporter is None and self._metric_queue is None: return (running_count, available_not_running_count, available_count) = self.get_metrics() - self._reporter(self._currently_processing, running_count, - running_count + available_not_running_count) + + if self._metric_queue: + dim = {'queue': self._queue_name} + self._metric_queue.put('Running', running_count, dimensions=dim) + self._metric_queue.put('AvailableNotRunning', available_not_running_count, dimensions=dim) + self._metric_queue.put('Available', available_count, dimensions=dim) + + if self._reporter: + self._reporter(self._currently_processing, running_count, + running_count + available_not_running_count) def has_retries_remaining(self, item_id): """ Returns whether the queue item with the given id has any retries remaining. If the