Don't enable the metric queue if there's no Cloudwatch

This commit is contained in:
Matt Jibson 2015-08-12 15:14:09 -04:00
parent b483209862
commit f043bc1379
3 changed files with 15 additions and 4 deletions

8
app.py
View file

@ -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']

View file

@ -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()

View file

@ -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: