diff --git a/app.py b/app.py index 4a72420b4..4b2110004 100644 --- a/app.py +++ b/app.py @@ -26,7 +26,7 @@ from util.saas.exceptionlog import Sentry from util.names import urn_generator from util.config.oauth import GoogleOAuthConfig, GithubOAuthConfig, GitLabOAuthConfig from util.security.signing import Signer -from util.saas.cloudwatch import send_cloudwatch +from util.saas.cloudwatch import start_cloudwatch_sender from util.saas.metricqueue import MetricQueue from util.config.provider import FileConfigProvider, TestConfigProvider from util.config.configutil import generate_secret_key @@ -125,7 +125,11 @@ userevents = UserEventsBuilderModule(app) superusers = SuperUserManager(app) signer = Signer(app, OVERRIDE_CONFIG_DIRECTORY) metric_queue = MetricQueue() -send_cloudwatch(metric_queue, app) + +try: + start_cloudwatch_sender(metric_queue, app) +except KeyError: + logger.debug('Cloudwatch not configured') tf = app.config['DB_TRANSACTION_FACTORY'] diff --git a/util/saas/cloudwatch.py b/util/saas/cloudwatch.py index 16f93a558..ba8f01da0 100644 --- a/util/saas/cloudwatch.py +++ b/util/saas/cloudwatch.py @@ -7,7 +7,7 @@ from threading import Thread logger = logging.getLogger(__name__) -def send_cloudwatch(metrics, app): +def start_cloudwatch_sender(metrics, app): """ Starts sending from metrics to a new CloudWatchSender. """ @@ -37,6 +37,7 @@ class CloudWatchSender(Thread): connection = boto.connect_cloudwatch(self._aws_access_key, self._aws_secret_key) except: logger.exception('Failed to connect to CloudWatch.') + self._metrics.enable() while True: put_metric_args, kwargs = self._metrics.get() diff --git a/util/saas/metricqueue.py b/util/saas/metricqueue.py index f9e8efe13..d6fc4338e 100644 --- a/util/saas/metricqueue.py +++ b/util/saas/metricqueue.py @@ -11,9 +11,15 @@ logger = logging.getLogger(__name__) class MetricQueue(object): def __init__(self): - self._queue = Queue(10000) + self._queue = None + + def enable(self, maxsize=10000): + self._queue = Queue(maxsize) def put(self, *args, **kwargs): + if self._queue is None: + logging.debug('No metric queue: %s %s' %args, kwargs) + return try: self._queue.put_nowait((args, kwargs)) except Full: