Merge lp:~cprov/adt-cloud-worker/log-cleanup into lp:adt-cloud-worker

Proposed by Celso Providelo
Status: Merged
Approved by: Celso Providelo
Approved revision: 31
Merged at revision: 29
Proposed branch: lp:~cprov/adt-cloud-worker/log-cleanup
Merge into: lp:adt-cloud-worker
Diff against target: 171 lines (+64/-20)
3 files modified
adt-service.conf (+5/-0)
adt_cloud_worker/__init__.py (+58/-20)
requirements.txt (+1/-0)
To merge this branch: bzr merge lp:~cprov/adt-cloud-worker/log-cleanup
Reviewer Review Type Date Requested Status
Thomi Richards (community) Approve
Review via email: mp+253617@code.launchpad.net

Commit message

Suppressing adt-run output from the logs, adding logstash & file logging handlers along with some messaging cleanup.

Description of the change

Suppressing adt-run output from the logs, adding logstash & file logging handlers along with some messaging cleanup.

To post a comment you must log in.
Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote :

<thomi> cprov: ok, only thing is, best practise is to do: logger.info("%s", var) not logger.info("%s" % (var)) or logger.info("{}".format(var))
<cprov> thomi: I noticed in your MPs, let me fix mine
<thomi> cprov: also, in my MPs I set 'requests' to WARNING
<thomi> best make them all the same I guess
<thomi> cprov: otherwise, looks good

Looks good - suggest you fix the above two issues.

review: Approve
30. By Celso Providelo

Fixing logging format style.

31. By Celso Providelo

'requests' logging set to WARNING.

Revision history for this message
Celso Providelo (cprov) wrote :

Both fixed, thanks.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'adt-service.conf'
--- adt-service.conf 2015-03-16 20:50:34 +0000
+++ adt-service.conf 2015-03-20 01:06:08 +0000
@@ -10,3 +10,8 @@
10os_auth_url = http://172.20.161.138:5000/v2.0/10os_auth_url = http://172.20.161.138:5000/v2.0/
11os_region_name = bot-prototype11os_region_name = bot-prototype
12extra_args = --net-id=415a0839-eb05-4e7a-907c-413c657f4bf512extra_args = --net-id=415a0839-eb05-4e7a-907c-413c657f4bf5
13
14[logstash]
15host = localhost
16port = 5959
17version = 1
1318
=== modified file 'adt_cloud_worker/__init__.py'
--- adt_cloud_worker/__init__.py 2015-03-19 03:08:53 +0000
+++ adt_cloud_worker/__init__.py 2015-03-20 01:06:08 +0000
@@ -23,9 +23,9 @@
23import argparse23import argparse
24import configparser24import configparser
25import kombu25import kombu
26from kombu.log import get_logger
27from kombu.mixins import ConsumerMixin26from kombu.mixins import ConsumerMixin
28from kombu.utils.debug import setup_logging27import logging
28import logstash
29import os29import os
30import socket30import socket
31import subprocess31import subprocess
@@ -44,7 +44,8 @@
44)44)
45API_VERSION = "v1"45API_VERSION = "v1"
4646
47logger = get_logger(__name__)47
48logger = logging.getLogger(__name__)
4849
4950
50class AdtNovaWorker(ConsumerMixin):51class AdtNovaWorker(ConsumerMixin):
@@ -79,8 +80,8 @@
79 Run requested tests and posts results to the 'adt_results' queue80 Run requested tests and posts results to the 'adt_results' queue
80 for later checking.81 for later checking.
81 """82 """
82 logger.info('Got: {}'.format(body))
83 body['worker'] = self.worker_name83 body['worker'] = self.worker_name
84 logger.info('Received message request: %s', body, extra=body)
8485
85 # Run requested tests safely.86 # Run requested tests safely.
86 tarball_path = None87 tarball_path = None
@@ -97,8 +98,12 @@
97 'nova', 'extra_args').split()98 'nova', 'extra_args').split()
98 adt_kwargs['nova_flavor'] = get_default_testbed_flavor()99 adt_kwargs['nova_flavor'] = get_default_testbed_flavor()
99 arguments = _make_adt_argument_list(adt_kwargs)100 arguments = _make_adt_argument_list(adt_kwargs)
100101 logger.info(
102 'Running adt-run with: %s', ' '.join(arguments),
103 extra=body)
101 body['exit_code'] = run_adt(arguments)104 body['exit_code'] = run_adt(arguments)
105 logger.info(
106 'Exit code: %s', body['exit_code'], extra=body)
102 _create_run_metadata_file(result_dir, body)107 _create_run_metadata_file(result_dir, body)
103 tarball_path = _create_tarball_from_directory(108 tarball_path = _create_tarball_from_directory(
104 result_dir,109 result_dir,
@@ -110,18 +115,19 @@
110 upload_tarball_to_swift_container(tarball_path, container_name)115 upload_tarball_to_swift_container(tarball_path, container_name)
111 except Exception as e:116 except Exception as e:
112 # Unexpected failures ...117 # Unexpected failures ...
113 logger.error(e, exc_info=True)
114 body['exit_code'] = '100'118 body['exit_code'] = '100'
119 logger.error(e, exc_info=True, extra=body)
115 finally:120 finally:
116 # The post results121 logger.info('Posting results: %s', body, extra=body)
117 # TODO: send error logging to result-checker in the message122 # TODO: send error logging to result-checker in the message.
118 queue = self.connection.SimpleQueue('adt.results.{}'.format(API_VERSION))123 queue = self.connection.SimpleQueue(
124 'adt.results.{}'.format(API_VERSION))
119 queue.put(body)125 queue.put(body)
120 queue.close()126 queue.close()
121 if tarball_path and os.path.exists(tarball_path):127 if tarball_path and os.path.exists(tarball_path):
122 os.remove(tarball_path)128 os.remove(tarball_path)
123 message.ack()129 message.ack()
124 logger.info('Done!')130 logger.info('Done!', extra=body)
125131
126132
127def _create_run_metadata_file(directory, request):133def _create_run_metadata_file(directory, request):
@@ -174,14 +180,11 @@
174180
175 Returns the exit code from adt-run.181 Returns the exit code from adt-run.
176 """182 """
177 # TODO: We probably want something more clever here:183 cmd_line = ['adt-run'] + arguments
178 try:184 proc = subprocess.Popen(
179 subprocess.check_call(['adt-run'] + arguments)185 cmd_line, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
180 except subprocess.CalledProcessError as e:186 proc.communicate()
181 # log?187 return proc.returncode
182 # TODO: filter log content to avoid leaking cloud credentials.
183 return e.returncode
184 return 0
185188
186189
187def _make_adt_argument_list(request_configuration):190def _make_adt_argument_list(request_configuration):
@@ -250,9 +253,42 @@
250 return tarball_path253 return tarball_path
251254
252255
256def configure_logging(config):
257 root_logger = logging.getLogger()
258 root_logger.setLevel(logging.INFO)
259
260 # Silence requests logging, which is created by nova, keystone and swift.
261 requests_logger = logging.getLogger('requests')
262 requests_logger.setLevel(logging.WARNING)
263
264 # If there is no ./logs directory, fallback to stderr.
265 log_path = os.path.abspath(os.path.join(__file__, '../../logs/app.log'))
266 log_dir = os.path.dirname(log_path)
267 if os.path.exists(log_dir):
268 handler = logging.FileHandler(log_path)
269 else:
270 print("'logs' directory '{}' does not exist, using stderr "
271 "for app log.".format(log_dir))
272 handler = logging.StreamHandler()
273
274 handler.setFormatter(
275 logging.Formatter(
276 '%(asctime)s %(name)s %(levelname)s: %(message)s'
277 )
278 )
279 root_logger.addHandler(handler)
280
281 if 'logstash' in config:
282 root_logger.addHandler(
283 logstash.LogstashHandler(
284 config['logstash']['host'],
285 int(config['logstash']['port']),
286 int(config['logstash']['version'])
287 )
288 )
289
290
253def main():291def main():
254 setup_logging(loglevel='DEBUG', loggers=[''])
255
256 parser = argparse.ArgumentParser(292 parser = argparse.ArgumentParser(
257 description='ADT cloud worker ...')293 description='ADT cloud worker ...')
258 parser.add_argument('-c', '--conf', default='adt-service.conf',294 parser.add_argument('-c', '--conf', default='adt-service.conf',
@@ -263,6 +299,8 @@
263 config = configparser.ConfigParser()299 config = configparser.ConfigParser()
264 config.read(args.conf)300 config.read(args.conf)
265301
302 configure_logging(config)
303
266 set_config_dict(config)304 set_config_dict(config)
267305
268 amqp_uris = config.get('amqp', 'uris').split()306 amqp_uris = config.get('amqp', 'uris').split()
269307
=== modified file 'requirements.txt'
--- requirements.txt 2015-03-08 22:20:15 +0000
+++ requirements.txt 2015-03-20 01:06:08 +0000
@@ -1,5 +1,6 @@
1kombu==3.0.241kombu==3.0.24
2python-keystoneclient==1.2.02python-keystoneclient==1.2.0
3python-logstash==0.4.2
3python-novaclient==2.22.04python-novaclient==2.22.0
4python-swiftclient==2.3.15python-swiftclient==2.3.1
56

Subscribers

People subscribed via source and target branches