Merge lp:~cprov/core-image-publisher/sane-logging into lp:core-image-publisher

Proposed by Celso Providelo
Status: Merged
Approved by: Celso Providelo
Approved revision: 18
Merged at revision: 18
Proposed branch: lp:~cprov/core-image-publisher/sane-logging
Merge into: lp:core-image-publisher
Diff against target: 185 lines (+55/-18)
4 files modified
core_image_publisher/__init__.py (+0/-2)
core_image_publisher/constants.py (+31/-0)
core_image_publisher/queue.py (+8/-4)
core_image_publisher/worker.py (+16/-12)
To merge this branch: bzr merge lp:~cprov/core-image-publisher/sane-logging
Reviewer Review Type Date Requested Status
Paul Larson Approve
Review via email: mp+254801@code.launchpad.net

Commit message

Improving logging on core-image-publishing by adding standard logging extra keys (solution, service and hostname).

Description of the change

Improving logging on core-image-publishing by adding standard logging extra keys (solution, service and hostname).

It still a little too verbose IMO, specially the INFO points during the image handling, but we can silent it later, if necessary.

To post a comment you must log in.
Revision history for this message
Paul Larson (pwlars) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'core_image_publisher/__init__.py'
2--- core_image_publisher/__init__.py 2015-03-30 05:48:43 +0000
3+++ core_image_publisher/__init__.py 2015-03-31 16:50:17 +0000
4@@ -30,8 +30,6 @@
5 )
6 from core_image_publisher import worker
7
8-logger = logging.getLogger(__name__)
9-
10
11 def read_config():
12 parser = argparse.ArgumentParser(description='Core image publisher.')
13
14=== modified file 'core_image_publisher/constants.py'
15--- core_image_publisher/constants.py 2015-03-30 06:17:13 +0000
16+++ core_image_publisher/constants.py 2015-03-31 16:50:17 +0000
17@@ -20,3 +20,34 @@
18 API_VERSION = "v1"
19
20 RETRY_COUNT = 3
21+
22+SOLUTION_NAME = "core-image-testing"
23+
24+SERVICE_NAME = "core-image-publisher"
25+
26+def _get_hostname():
27+ """Return sanitized contents of /etc/hostname.
28+
29+ It is necessary because current juju hostnames (juju-<env-name>-machine-#)
30+ are too big due to our long environment names ('<spec_name>-<MD5>').
31+ Linux (DNS for RFC1035, really) only supports labels up to 64 chars and
32+ the fallback varies from tool to tool, `cloud-init` chokes on longer
33+ names and sets 'ubuntu', `hostnamectl` (systemd) would truncate the
34+ given data.
35+
36+ None of this is ideal to our applications, that's why we will operate
37+ on the pristine /etc/hostname and remove the 'juju-' and '-machine' terms
38+ added by juju.
39+ """
40+ with open('/etc/hostname') as fd:
41+ hostname = fd.read()
42+ return hostname.replace('juju-', '').replace('-machine', '').strip()
43+
44+
45+HOSTNAME = _get_hostname()
46+
47+LOGGING_EXTRA = {
48+ 'solution': SOLUTION_NAME,
49+ 'service': SERVICE_NAME,
50+ 'hostname': HOSTNAME,
51+}
52
53=== modified file 'core_image_publisher/queue.py'
54--- core_image_publisher/queue.py 2015-03-30 21:39:47 +0000
55+++ core_image_publisher/queue.py 2015-03-31 16:50:17 +0000
56@@ -88,9 +88,11 @@
57 Run requested tests and posts results to the 'adt_results' queue
58 for later checking.
59 """
60- logger.info('Got: %r', body, extra=body)
61+ extra = constants.LOGGING_EXTRA.copy()
62+ extra.update(body)
63+ logger.info('Got: %r', body, extra=extra)
64 try:
65- requested_action = self.on_message_cb(message.payload)
66+ requested_action = self.on_message_cb(body)
67 if requested_action == MessageActions.Retry:
68 self.maybe_requeue_message(message)
69 elif requested_action == MessageActions.Acknowledge:
70@@ -102,7 +104,7 @@
71 logger.error(
72 "Caught unhandled exception while processing message: %s",
73 e,
74- extra=message.payload
75+ extra=extra
76 )
77 message.requeue()
78
79@@ -119,6 +121,8 @@
80 stage of the system.
81
82 """
83+ extra = constants.LOGGING_EXTRA.copy()
84+ extra.update(message.payload)
85 retry_key = "{}_retry_count".format(
86 message.delivery_info.get('routing_key', '')
87 )
88@@ -134,7 +138,7 @@
89 logger.error(
90 "Rejecting message due to retry count exceeding maximum. "
91 "Message will reside on the dead letter queue",
92- extra=message.payload
93+ extra=extra
94 )
95 queue = self.connection.SimpleQueue(
96 'core.deadletters.{}'.format(constants.API_VERSION))
97
98=== modified file 'core_image_publisher/worker.py'
99--- core_image_publisher/worker.py 2015-03-30 21:38:58 +0000
100+++ core_image_publisher/worker.py 2015-03-31 16:50:17 +0000
101@@ -22,10 +22,12 @@
102 import subprocess
103 import tempfile
104
105+from core_image_publisher.constants import LOGGING_EXTRA
106+from core_image_publisher.cloud import get_glance_client
107 from core_image_publisher.queue import MessageActions
108-from core_image_publisher.cloud import get_glance_client
109 from core_image_publisher.utils import check_call
110
111+
112 logger = logging.getLogger(__name__)
113
114
115@@ -38,7 +40,8 @@
116 self.publish_results = publisher
117
118 def __call__(self, payload):
119- logger.info("Got %r", payload, extra=payload)
120+ extra = LOGGING_EXTRA.copy()
121+ extra.update(payload)
122 try:
123 image_name = payload['image_name']
124 channel = payload['channel']
125@@ -48,12 +51,12 @@
126 "Unable to deserialize message payload - "
127 "rejecting message: %s",
128 e,
129- extra=payload
130+ extra=extra
131 )
132 return MessageActions.Retry
133
134 with tempfile.TemporaryDirectory() as tmpdir:
135- logger.info("Beginning image download.", extra=payload)
136+ logger.info("Beginning image download.", extra=extra)
137 try:
138 image_path = download_image(
139 image_name,
140@@ -65,10 +68,10 @@
141 logger.error(
142 "Unable to download core image: %s",
143 e,
144- extra=payload
145+ extra=extra
146 )
147 return MessageActions.Retry
148- logger.info("Ubuntu Core image downloaded OK.", extra=payload)
149+ logger.info("Ubuntu Core image downloaded OK.", extra=extra)
150
151 try:
152 nova_image_path = convert_nova_image(image_path)
153@@ -76,12 +79,13 @@
154 logger.error(
155 "Unable to convert core image to qcow2 image: %s",
156 e,
157- extra=payload)
158+ extra=extra)
159 return MessageActions.Retry
160- logger.info("Image converted to qcow2 OK.", extra=payload)
161+ logger.info("Image converted to qcow2 OK.", extra=extra)
162
163 try:
164- logger.info("Beginning image upload to glance...")
165+ logger.info("Beginning image upload to glance...",
166+ extra=extra)
167 glance_image_name = upload_image_to_glance(
168 nova_image_path,
169 self._config
170@@ -90,14 +94,14 @@
171 logger.error(
172 "Unable to upload image to glance: %s",
173 e,
174- extra=payload
175+ extra=extra
176 )
177 return MessageActions.Retry
178- logger.info("Image uploaded to glance OK.", extra=payload)
179+ logger.info("Image uploaded to glance OK.", extra=extra)
180
181 payload['nova_image'] = glance_image_name
182 self.publish_results(payload)
183- logger.info("Processing completed.", extra=payload)
184+ logger.info("Processing completed.", extra=extra)
185 return MessageActions.Acknowledge
186
187

Subscribers

People subscribed via source and target branches