From 87f58e982c38fc2215a6e35451b0beebf3bf32fd Mon Sep 17 00:00:00 2001 From: Sandy Walsh Date: Mon, 5 Nov 2012 11:02:16 -0400 Subject: [PATCH] db host config, summary fix, durable queues --- etc/sample_stacktach_config.sh | 1 + etc/sample_stacktach_worker_config.json | 2 ++ settings.py | 3 ++- stacktach/stacky_server.py | 5 +++-- stacktach/views.py | 3 +++ worker/worker.py | 26 +++++++++++++------------ 6 files changed, 25 insertions(+), 15 deletions(-) diff --git a/etc/sample_stacktach_config.sh b/etc/sample_stacktach_config.sh index e1c499d..72f5c1e 100644 --- a/etc/sample_stacktach_config.sh +++ b/etc/sample_stacktach_config.sh @@ -1,4 +1,5 @@ export STACKTACH_DB_NAME="stacktach" +export STACKTACH_DB_HOST="" export STACKTACH_DB_USERNAME="root" export STACKTACH_DB_PASSWORD="password" export STACKTACH_INSTALL_DIR="/srv/www/stacktach/" diff --git a/etc/sample_stacktach_worker_config.json b/etc/sample_stacktach_worker_config.json index 568c6da..5fea92a 100644 --- a/etc/sample_stacktach_worker_config.json +++ b/etc/sample_stacktach_worker_config.json @@ -1,6 +1,7 @@ {"deployments": [ { "name": "east_coast.prod.global", + "durable_queue": false, "rabbit_host": "10.0.0.1", "rabbit_port": 5672, "rabbit_userid": "rabbit", @@ -9,6 +10,7 @@ }, { "name": "east_coast.prod.cell1", + "durable_queue": false, "rabbit_host": "10.0.1.1", "rabbit_port": 5672, "rabbit_userid": "rabbit", diff --git a/settings.py b/settings.py index e7404f0..4498856 100644 --- a/settings.py +++ b/settings.py @@ -2,6 +2,7 @@ import os db_name = os.environ['STACKTACH_DB_NAME'] +db_host = os.environ.get('STACKTACH_DB_HOST', "") db_username = os.environ['STACKTACH_DB_USERNAME'] db_password = os.environ['STACKTACH_DB_PASSWORD'] install_dir = os.environ['STACKTACH_INSTALL_DIR'] @@ -21,7 +22,7 @@ DATABASES = { 'NAME': db_name, 'USER': db_username, 'PASSWORD': db_password, - 'HOST': '', # Set to empty string for localhost. + 'HOST': db_host, # Set to empty string for localhost. 'PORT': '', # Set to empty string for default. } } diff --git a/stacktach/stacky_server.py b/stacktach/stacky_server.py index a9a2574..037b75d 100644 --- a/stacktach/stacky_server.py +++ b/stacktach/stacky_server.py @@ -149,14 +149,15 @@ def do_summary(request): for name in interesting: timings = models.Timing.objects.filter(name=name) \ - .exclude(Q(start_raw=None) | Q(end_raw=None)) + .exclude(Q(start_raw=None) | Q(end_raw=None)) \ + .exclude(diff__lt=0) if not timings: continue total, _min, _max = 0.0, None, None num = len(timings) for t in timings: - seconds = seconds_from_timing(t) + seconds = float(t.diff) total += seconds if _min is None: _min = seconds diff --git a/stacktach/views.py b/stacktach/views.py index 098cbac..8c73626 100644 --- a/stacktach/views.py +++ b/stacktach/views.py @@ -81,6 +81,9 @@ def aggregate(raw): We can use this for summarized timing reports. """ + if not raw.instance: + return + # While we hope only one lifecycle ever exists it's quite # likely we get multiple due to the workers and threads. lifecycle = None diff --git a/worker/worker.py b/worker/worker.py index 421ae84..94d7d78 100644 --- a/worker/worker.py +++ b/worker/worker.py @@ -34,18 +34,6 @@ handler = logging.handlers.TimedRotatingFileHandler('worker.log', when='h', interval=6, backupCount=4) LOG.addHandler(handler) -nova_exchange = kombu.entity.Exchange("nova", type="topic", exclusive=False, - durable=True, auto_delete=False) - -nova_queues = [ - kombu.Queue("monitor.info", nova_exchange, durable=True, - auto_delete=False, - exclusive=False, routing_key='monitor.info'), - kombu.Queue("monitor.error", nova_exchange, durable=True, - auto_delete=False, - exclusive=False, routing_key='monitor.error'), -] - class NovaConsumer(kombu.mixins.ConsumerMixin): def __init__(self, name, connection, deployment): @@ -54,6 +42,20 @@ class NovaConsumer(kombu.mixins.ConsumerMixin): self.name = name def get_consumers(self, Consumer, channel): + durable = self.deployment_config.get('durable_queue', True) + nova_exchange = kombu.entity.Exchange("nova", type="topic", + exclusive=False, durable=durable, auto_delete=False) + + + nova_queues = [ + kombu.Queue("monitor.info", nova_exchange, durable=durable, + auto_delete=False, + exclusive=False, routing_key='monitor.info'), + kombu.Queue("monitor.error", nova_exchange, durable=durable, + auto_delete=False, + exclusive=False, routing_key='monitor.error'), + ] + return [Consumer(queues=nova_queues, callbacks=[self.on_nova])] def _process(self, body, message):