From 4d0979664a073bf12f23fbc9a011740324bdb1e8 Mon Sep 17 00:00:00 2001 From: Simon Westphahl Date: Wed, 10 Oct 2018 13:23:20 +0200 Subject: [PATCH] Include enqueue and report timestamps in MQTT msg Having the enqueue and report timestamp allows for better reporting regarding the livecycle of a change. Change-Id: Ia3915ea35853f007181d5660c361417175c29507 --- tests/unit/test_connection.py | 2 ++ zuul/driver/mqtt/mqttreporter.py | 3 +++ 2 files changed, 5 insertions(+) diff --git a/tests/unit/test_connection.py b/tests/unit/test_connection.py index 1afcb101f5..cef9c29495 100644 --- a/tests/unit/test_connection.py +++ b/tests/unit/test_connection.py @@ -492,6 +492,8 @@ class TestMQTTConnection(ZuulTestCase): 'test') self.assertEquals(mqtt_payload['buildset']['builds'][0]['result'], 'SUCCESS') + self.assertIn('timestamp', mqtt_payload) + self.assertIn('enqueue_time', mqtt_payload) def test_mqtt_invalid_topic(self): in_repo_conf = textwrap.dedent( diff --git a/zuul/driver/mqtt/mqttreporter.py b/zuul/driver/mqtt/mqttreporter.py index 024da436ba..75af2d35a9 100644 --- a/zuul/driver/mqtt/mqttreporter.py +++ b/zuul/driver/mqtt/mqttreporter.py @@ -13,6 +13,7 @@ # under the License. import logging +import time import voluptuous as v from zuul.reporter import BaseReporter @@ -28,6 +29,7 @@ class MQTTReporter(BaseReporter): self.log.debug("Report change %s, params %s" % (item.change, self.config)) message = { + 'timestamp': time.time(), 'action': self._action, 'tenant': item.pipeline.tenant.name, 'zuul_ref': item.current_build_set.ref, @@ -40,6 +42,7 @@ class MQTTReporter(BaseReporter): 'ref': getattr(item.change, 'ref', ''), 'message': self._formatItemReport( item, with_jobs=False), + 'enqueue_time': item.enqueue_time, 'buildset': { 'uuid': item.current_build_set.uuid, 'builds': []