Merge lp:~joetalbott/adt-cloud-worker/add_logging_extra into lp:adt-cloud-worker

Proposed by Joe Talbott
Status: Merged
Approved by: Celso Providelo
Approved revision: 37
Merged at revision: 35
Proposed branch: lp:~joetalbott/adt-cloud-worker/add_logging_extra
Merge into: lp:adt-cloud-worker
Diff against target: 106 lines (+48/-7)
2 files modified
adt_cloud_worker/__init__.py (+12/-7)
adt_cloud_worker/constants.py (+36/-0)
To merge this branch: bzr merge lp:~joetalbott/adt-cloud-worker/add_logging_extra
Reviewer Review Type Date Requested Status
Para Siva (community) Approve
Paul Larson Needs Fixing
Review via email: mp+256379@code.launchpad.net

Commit message

Add logging_extra.

Description of the change

Add logging_extra.

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

Unless I've missed something, there's some duplication introduced by this.

review: Needs Fixing
Revision history for this message
Para Siva (psivaa) wrote :

An inline comment, just to be sure. Otherwise +1 from me.

review: Approve
36. By Joe Talbott

Move description above imports.

37. By Joe Talbott

Remove duplication for API_VERSION

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'adt_cloud_worker/__init__.py'
2--- adt_cloud_worker/__init__.py 2015-04-14 22:34:53 +0000
3+++ adt_cloud_worker/__init__.py 2015-04-15 19:15:52 +0000
4@@ -38,12 +38,15 @@
5 set_config_dict,
6 upload_tarball_to_swift_container,
7 )
8+from adt_cloud_worker.constants import (
9+ API_VERSION,
10+ logging_extra,
11+)
12
13 ARCHITECTURES = (
14 'amd64',
15 'i386'
16 )
17-API_VERSION = "v1"
18
19
20 logger = logging.getLogger(__name__)
21@@ -86,7 +89,9 @@
22 for later checking.
23 """
24 body['worker'] = self.worker_name
25- logger.info('Received message request: %s', body, extra=body)
26+ extra = logging_extra.copy()
27+ extra.update(body)
28+ logger.info('Received message request: %s', body, extra=extra)
29
30 # Run requested tests safely.
31 tarball_path = None
32@@ -105,10 +110,10 @@
33 arguments = _make_adt_argument_list(adt_kwargs)
34 logger.info(
35 'Running adt-run with: %s', ' '.join(arguments),
36- extra=body)
37+ extra=extra)
38 body['exit_code'] = run_adt(arguments)
39 logger.info(
40- 'Exit code: %s', body['exit_code'], extra=body)
41+ 'Exit code: %s', body['exit_code'], extra=extra)
42 _create_run_metadata_file(result_dir, body)
43 tarball_path = _create_tarball_from_directory(
44 result_dir,
45@@ -124,9 +129,9 @@
46 # help debugging of deadletter-ed messages.
47 body['exit_code'] = 100
48 body['worker_traceback'] = traceback.format_exc()
49- logger.error(e, exc_info=True, extra=body)
50+ logger.error(e, exc_info=True, extra=extra)
51 finally:
52- logger.info('Posting results: %s', body, extra=body)
53+ logger.info('Posting results: %s', body, extra=extra)
54 queue = self.connection.SimpleQueue(
55 'adt.results.{}'.format(API_VERSION))
56 queue.put(body)
57@@ -134,7 +139,7 @@
58 if tarball_path is not None and os.path.exists(tarball_path):
59 os.remove(tarball_path)
60 message.ack()
61- logger.info('Done!', extra=body)
62+ logger.info('Done!', extra=extra)
63
64
65 def _create_run_metadata_file(directory, request):
66
67=== added file 'adt_cloud_worker/constants.py'
68--- adt_cloud_worker/constants.py 1970-01-01 00:00:00 +0000
69+++ adt_cloud_worker/constants.py 2015-04-15 19:15:52 +0000
70@@ -0,0 +1,36 @@
71+# adt-cloud-worker
72+# Copyright (C) 2015 Canonical
73+#
74+# This program is free software: you can redistribute it and/or modify
75+# it under the terms of the GNU General Public License as published by
76+# the Free Software Foundation, either version 3 of the License, or
77+# (at your option) any later version.
78+#
79+# This program is distributed in the hope that it will be useful,
80+# but WITHOUT ANY WARRANTY; without even the implied warranty of
81+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
82+# GNU General Public License for more details.
83+#
84+# You should have received a copy of the GNU General Public License
85+# along with this program. If not, see <http://www.gnu.org/licenses/>.
86+#
87+
88+"""Constants for this service."""
89+
90+import socket
91+
92+
93+API_VERSION = "v1"
94+
95+SOLUTION_NAME = "proposed-migration"
96+
97+SERVICE_NAME = "adt-cloud-worker"
98+
99+HOSTNAME = socket.gethostname()
100+
101+
102+logging_extra = {
103+ 'solution': SOLUTION_NAME,
104+ 'service': SERVICE_NAME,
105+ 'hostname': HOSTNAME,
106+}

Subscribers

People subscribed via source and target branches