diff --git a/app.py b/app.py index cdac98a27..7e3ec4d2b 100644 --- a/app.py +++ b/app.py @@ -17,15 +17,15 @@ from data.userfiles import Userfiles from data.users import UserAuthentication from util.analytics import Analytics from util.exceptionlog import Sentry -from util.queuemetrics import QueueMetrics from util.names import urn_generator from util.oauth import GoogleOAuthConfig, GithubOAuthConfig from data.billing import Billing from data.buildlogs import BuildLogs from data.archivedlogs import LogArchive -from data.queue import WorkQueue from data.userevent import UserEventsBuilderModule from avatars.avatars import Avatar +from util.queuemetrics import QueueMetrics +from data.queue import WorkQueue class Config(BaseConfig): @@ -130,16 +130,17 @@ analytics = Analytics(app) billing = Billing(app) sentry = Sentry(app) build_logs = BuildLogs(app) -queue_metrics = QueueMetrics(app) authentication = UserAuthentication(app) userevents = UserEventsBuilderModule(app) +queue_metrics = QueueMetrics(app) + +tf = app.config['DB_TRANSACTION_FACTORY'] github_login = GithubOAuthConfig(app, 'GITHUB_LOGIN_CONFIG') github_trigger = GithubOAuthConfig(app, 'GITHUB_TRIGGER_CONFIG') google_login = GoogleOAuthConfig(app, 'GOOGLE_LOGIN_CONFIG') oauth_apps = [github_login, github_trigger, google_login] -tf = app.config['DB_TRANSACTION_FACTORY'] image_diff_queue = WorkQueue(app.config['DIFFS_QUEUE_NAME'], tf) dockerfile_build_queue = WorkQueue(app.config['DOCKERFILE_BUILD_QUEUE_NAME'], tf, reporter=queue_metrics.report) diff --git a/endpoints/common.py b/endpoints/common.py index e81b4facf..8424d9997 100644 --- a/endpoints/common.py +++ b/endpoints/common.py @@ -11,7 +11,7 @@ from random import SystemRandom from data import model from data.database import db -from app import app, login_manager, dockerfile_build_queue, notification_queue, oauth_apps +from app import app, login_manager, oauth_apps, dockerfile_build_queue from auth.permissions import QuayDeferredPermissionUser from auth import scopes diff --git a/registry.py b/registry.py index 2a356e1ec..2669ec1c1 100644 --- a/registry.py +++ b/registry.py @@ -7,7 +7,6 @@ from endpoints.index import index from endpoints.tags import tags from endpoints.registry import registry - application.register_blueprint(index, url_prefix='/v1') application.register_blueprint(tags, url_prefix='/v1') application.register_blueprint(registry, url_prefix='/v1') diff --git a/util/queuemetrics.py b/util/queuemetrics.py index ec1444c16..c1ca8c585 100644 --- a/util/queuemetrics.py +++ b/util/queuemetrics.py @@ -54,6 +54,7 @@ class SendToCloudWatch(Process): class QueueMetrics(object): def __init__(self, app=None): self.app = app + self.sender = None if app is not None: self.state = self.init_app(app) else: @@ -72,8 +73,7 @@ class QueueMetrics(object): request_queue = Queue() reporter = QueueingCloudWatchReporter(request_queue, namespace, req_capacity_name, build_percent_name) - sender = SendToCloudWatch(request_queue, access_key, secret_key) - sender.start() + self.sender = SendToCloudWatch(request_queue, access_key, secret_key) else: reporter = NullReporter() @@ -82,5 +82,11 @@ class QueueMetrics(object): app.extensions['queuemetrics'] = reporter return reporter + def run(self): + logger.debug('Asked to start CloudWatch reporter') + if self.sender is not None: + logger.debug('Starting CloudWatch reporter') + self.sender.start() + def __getattr__(self, name): return getattr(self.state, name, None) diff --git a/web.py b/web.py index 6db09bec7..92b3d6758 100644 --- a/web.py +++ b/web.py @@ -1,7 +1,7 @@ import logging import logging.config -from app import app as application +from app import app as application, queue_metrics from endpoints.api import api_bp from endpoints.web import web @@ -9,6 +9,8 @@ from endpoints.webhooks import webhooks from endpoints.realtime import realtime from endpoints.callbacks import callback +# Start the cloudwatch reporting. +queue_metrics.run() application.register_blueprint(web) application.register_blueprint(callback, url_prefix='/oauth2')