From 8945d823cbeb9cae5f458fd6a49eb43e79e08b7c Mon Sep 17 00:00:00 2001 From: Sasha Konovalova Date: Wed, 26 Sep 2018 14:42:18 -0400 Subject: [PATCH 1/4] publish 0 counts --- mbq/atomiq/management/commands/atomic_run_consumer.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/mbq/atomiq/management/commands/atomic_run_consumer.py b/mbq/atomiq/management/commands/atomic_run_consumer.py index 67cbcfa..2436753 100644 --- a/mbq/atomiq/management/commands/atomic_run_consumer.py +++ b/mbq/atomiq/management/commands/atomic_run_consumer.py @@ -62,11 +62,12 @@ def collect_metrics(self, **options): model = self.consumers[queue_type].model state_counts = collections.Counter(model.objects.values_list('state', flat=True)) - for state, count in state_counts.items(): + task_states = [state[0] for state in constants.TaskStates.CHOICES] + for task_state in task_states: _collector.gauge( 'state_total', - count, - tags={'state': state, 'queue_type': queue_type}, + state_counts.get(task_state, 0), + tags={'state': task_states, 'queue_type': queue_type}, ) def handle(self, *args, **options): From 5fd9a811105f4f4c92b1d04bc849b04c0d6583b8 Mon Sep 17 00:00:00 2001 From: Sasha Konovalova Date: Wed, 26 Sep 2018 14:42:51 -0400 Subject: [PATCH 2/4] bump version to 0.0.5 --- mbq/atomiq/__version__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mbq/atomiq/__version__.py b/mbq/atomiq/__version__.py index 8b15ba7..9b9d23b 100644 --- a/mbq/atomiq/__version__.py +++ b/mbq/atomiq/__version__.py @@ -4,4 +4,4 @@ __license__ = 'Apache 2.0' __title__ = 'mbq.atomiq' __url__ = 'https://github.com/managedbyq/mbq.atomiq' -__version__ = '0.0.4' +__version__ = '0.0.5' From 5ff72e299046700c44b986572150feb900776f3a Mon Sep 17 00:00:00 2001 From: Sasha Konovalova Date: Wed, 26 Sep 2018 14:46:44 -0400 Subject: [PATCH 3/4] typo --- mbq/atomiq/management/commands/atomic_run_consumer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mbq/atomiq/management/commands/atomic_run_consumer.py b/mbq/atomiq/management/commands/atomic_run_consumer.py index 2436753..010ab6a 100644 --- a/mbq/atomiq/management/commands/atomic_run_consumer.py +++ b/mbq/atomiq/management/commands/atomic_run_consumer.py @@ -67,7 +67,7 @@ def collect_metrics(self, **options): _collector.gauge( 'state_total', state_counts.get(task_state, 0), - tags={'state': task_states, 'queue_type': queue_type}, + tags={'state': task_state, 'queue_type': queue_type}, ) def handle(self, *args, **options): From 092559925e7da87eabec2346a59d709a726e49c3 Mon Sep 17 00:00:00 2001 From: Sasha Konovalova Date: Wed, 26 Sep 2018 14:48:15 -0400 Subject: [PATCH 4/4] use generator expression --- mbq/atomiq/management/commands/atomic_run_consumer.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mbq/atomiq/management/commands/atomic_run_consumer.py b/mbq/atomiq/management/commands/atomic_run_consumer.py index 010ab6a..05b07ce 100644 --- a/mbq/atomiq/management/commands/atomic_run_consumer.py +++ b/mbq/atomiq/management/commands/atomic_run_consumer.py @@ -62,7 +62,8 @@ def collect_metrics(self, **options): model = self.consumers[queue_type].model state_counts = collections.Counter(model.objects.values_list('state', flat=True)) - task_states = [state[0] for state in constants.TaskStates.CHOICES] + task_states = (state[0] for state in constants.TaskStates.CHOICES) + for task_state in task_states: _collector.gauge( 'state_total',