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
=== modified file 'adt_cloud_worker/__init__.py'
--- adt_cloud_worker/__init__.py 2015-04-14 22:34:53 +0000
+++ adt_cloud_worker/__init__.py 2015-04-15 19:15:52 +0000
@@ -38,12 +38,15 @@
38 set_config_dict,38 set_config_dict,
39 upload_tarball_to_swift_container,39 upload_tarball_to_swift_container,
40)40)
41from adt_cloud_worker.constants import (
42 API_VERSION,
43 logging_extra,
44)
4145
42ARCHITECTURES = (46ARCHITECTURES = (
43 'amd64',47 'amd64',
44 'i386'48 'i386'
45)49)
46API_VERSION = "v1"
4750
4851
49logger = logging.getLogger(__name__)52logger = logging.getLogger(__name__)
@@ -86,7 +89,9 @@
86 for later checking.89 for later checking.
87 """90 """
88 body['worker'] = self.worker_name91 body['worker'] = self.worker_name
89 logger.info('Received message request: %s', body, extra=body)92 extra = logging_extra.copy()
93 extra.update(body)
94 logger.info('Received message request: %s', body, extra=extra)
9095
91 # Run requested tests safely.96 # Run requested tests safely.
92 tarball_path = None97 tarball_path = None
@@ -105,10 +110,10 @@
105 arguments = _make_adt_argument_list(adt_kwargs)110 arguments = _make_adt_argument_list(adt_kwargs)
106 logger.info(111 logger.info(
107 'Running adt-run with: %s', ' '.join(arguments),112 'Running adt-run with: %s', ' '.join(arguments),
108 extra=body)113 extra=extra)
109 body['exit_code'] = run_adt(arguments)114 body['exit_code'] = run_adt(arguments)
110 logger.info(115 logger.info(
111 'Exit code: %s', body['exit_code'], extra=body)116 'Exit code: %s', body['exit_code'], extra=extra)
112 _create_run_metadata_file(result_dir, body)117 _create_run_metadata_file(result_dir, body)
113 tarball_path = _create_tarball_from_directory(118 tarball_path = _create_tarball_from_directory(
114 result_dir,119 result_dir,
@@ -124,9 +129,9 @@
124 # help debugging of deadletter-ed messages.129 # help debugging of deadletter-ed messages.
125 body['exit_code'] = 100130 body['exit_code'] = 100
126 body['worker_traceback'] = traceback.format_exc()131 body['worker_traceback'] = traceback.format_exc()
127 logger.error(e, exc_info=True, extra=body)132 logger.error(e, exc_info=True, extra=extra)
128 finally:133 finally:
129 logger.info('Posting results: %s', body, extra=body)134 logger.info('Posting results: %s', body, extra=extra)
130 queue = self.connection.SimpleQueue(135 queue = self.connection.SimpleQueue(
131 'adt.results.{}'.format(API_VERSION))136 'adt.results.{}'.format(API_VERSION))
132 queue.put(body)137 queue.put(body)
@@ -134,7 +139,7 @@
134 if tarball_path is not None and os.path.exists(tarball_path):139 if tarball_path is not None and os.path.exists(tarball_path):
135 os.remove(tarball_path)140 os.remove(tarball_path)
136 message.ack()141 message.ack()
137 logger.info('Done!', extra=body)142 logger.info('Done!', extra=extra)
138143
139144
140def _create_run_metadata_file(directory, request):145def _create_run_metadata_file(directory, request):
141146
=== added file 'adt_cloud_worker/constants.py'
--- adt_cloud_worker/constants.py 1970-01-01 00:00:00 +0000
+++ adt_cloud_worker/constants.py 2015-04-15 19:15:52 +0000
@@ -0,0 +1,36 @@
1# adt-cloud-worker
2# Copyright (C) 2015 Canonical
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <http://www.gnu.org/licenses/>.
16#
17
18"""Constants for this service."""
19
20import socket
21
22
23API_VERSION = "v1"
24
25SOLUTION_NAME = "proposed-migration"
26
27SERVICE_NAME = "adt-cloud-worker"
28
29HOSTNAME = socket.gethostname()
30
31
32logging_extra = {
33 'solution': SOLUTION_NAME,
34 'service': SERVICE_NAME,
35 'hostname': HOSTNAME,
36}

Subscribers

People subscribed via source and target branches