Merge lp:~thomir-deactivatedaccount/adt-cloud-service/trunk-fix-logging into lp:adt-cloud-service

Proposed by Thomi Richards
Status: Merged
Approved by: Thomi Richards
Approved revision: 25
Merged at revision: 21
Proposed branch: lp:~thomir-deactivatedaccount/adt-cloud-service/trunk-fix-logging
Merge into: lp:adt-cloud-service
Diff against target: 161 lines (+57/-7)
6 files modified
README.rst (+8/-0)
adt-service.conf (+5/-7)
adt_cloud_service/__init__.py (+34/-0)
adt_cloud_service/queue.py (+4/-0)
adt_cloud_service/v1.py (+5/-0)
requirements.txt (+1/-0)
To merge this branch: bzr merge lp:~thomir-deactivatedaccount/adt-cloud-service/trunk-fix-logging
Reviewer Review Type Date Requested Status
Celso Providelo (community) Approve
Paul Larson Approve
Review via email: mp+253591@code.launchpad.net

Commit message

Sort out logging.

Description of the change

Sort out logging for the a-c-w:

 - we keep a separate application log.
  - we try and write to 'logs/app.log'
  - we fall back to stderr if the logs directory does not exist.
 - we configure the logstash handler if our config file contains the 'logstash' section.
 - we log every request that contains missing parameters, and every time we enqueue something to rabbit.

To post a comment you must log in.
Revision history for this message
Joe Talbott (joetalbott) wrote :

One question in-line.

Revision history for this message
Paul Larson (pwlars) wrote :

Neat, I didn't know you could send directly to logstash like that. Looks good.

review: Approve
Revision history for this message
Celso Providelo (cprov) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'README.rst'
--- README.rst 2015-03-16 20:56:36 +0000
+++ README.rst 2015-03-19 22:03:02 +0000
@@ -30,6 +30,14 @@
30 [image_mapper]30 [image_mapper]
31 url = http://127.0.0.1:123431 url = http://127.0.0.1:1234
3232
33Optionally, add a `[logstash]` section, which will enable the logstash logging handler::
34
35 [logstash]
36 host = localhost
37 port = 5959
38 version = 1
39
40
33Running::41Running::
3442
35 $ gunicorn adt_cloud_service:app43 $ gunicorn adt_cloud_service:app
3644
=== modified file 'adt-service.conf'
--- adt-service.conf 2015-03-16 20:56:36 +0000
+++ adt-service.conf 2015-03-19 22:03:02 +0000
@@ -1,6 +1,6 @@
1# `adt-cloud-worker` configuration file.1# `adt-cloud-worker` configuration file.
2[image_mapper]2[image_mapper]
3url = http://127.0.0.1:12343url = http://127.0.0.1:5000
44
5[amqp]5[amqp]
6uris = amqp://guest:guest@localhost:5672//6uris = amqp://guest:guest@localhost:5672//
@@ -8,9 +8,7 @@
8[swift]8[swift]
9public_url = http://some.swift.server.com9public_url = http://some.swift.server.com
1010
11[nova]11[logstash]
12os_username = foo12host = localhost
13os_tenant_name = foo_project13port = 5959
14os_password = xxx14version = 1
15os_auth_url = http://172.20.161.138:5000/v2.0/
16os_region_name = bot_prototype
1715
=== modified file 'adt_cloud_service/__init__.py'
--- adt_cloud_service/__init__.py 2015-03-18 18:59:21 +0000
+++ adt_cloud_service/__init__.py 2015-03-19 22:03:02 +0000
@@ -16,8 +16,11 @@
16#16#
1717
18import configparser18import configparser
19import logging
20import os.path
1921
20import flask22import flask
23import logstash
2124
22from adt_cloud_service import (25from adt_cloud_service import (
23 errors,26 errors,
@@ -33,6 +36,8 @@
33 config = configparser.ConfigParser()36 config = configparser.ConfigParser()
34 config.read('adt-service.conf')37 config.read('adt-service.conf')
3538
39 configure_logging(config)
40
36 app = flask.Flask('adt_cloud_service')41 app = flask.Flask('adt_cloud_service')
3742
38 app.add_url_rule(43 app.add_url_rule(
@@ -70,4 +75,33 @@
70 return app75 return app
7176
7277
78def configure_logging(config):
79 root_logger = logging.getLogger()
80 root_logger.setLevel(logging.INFO)
81
82 log_path = os.path.abspath(os.path.join(__file__, '../../logs/app.log'))
83 log_dir = os.path.dirname(log_path)
84 handler = None
85 if os.path.exists(log_dir):
86 handler = logging.FileHandler(log_path)
87 else:
88 print("'logs' directory '{}' does not exist, using stderr for app log.".format(log_dir))
89 handler = logging.StreamHandler()
90 handler.setFormatter(
91 logging.Formatter(
92 '%(asctime)s %(name)s %(levelname)s: %(message)s'
93 )
94 )
95 root_logger.addHandler(handler)
96
97 if 'logstash' in config:
98 root_logger.addHandler(
99 logstash.LogstashHandler(
100 config['logstash']['host'],
101 int(config['logstash']['port']),
102 int(config['logstash']['version'])
103 )
104 )
105
106
73app = create_flask_app()107app = create_flask_app()
74108
=== modified file 'adt_cloud_service/queue.py'
--- adt_cloud_service/queue.py 2015-03-17 02:47:19 +0000
+++ adt_cloud_service/queue.py 2015-03-19 22:03:02 +0000
@@ -21,6 +21,9 @@
21from kombu.pools import producers21from kombu.pools import producers
22from kombu.common import uuid22from kombu.common import uuid
2323
24import logging
25logger = logging.getLogger(__name__)
26
2427
25class RabbitQueuer(object):28class RabbitQueuer(object):
26 """A class that can send things to the rabbit queue. An instance of this29 """A class that can send things to the rabbit queue. An instance of this
@@ -78,4 +81,5 @@
78 exchange=self.adt_exchange,81 exchange=self.adt_exchange,
79 routing_key=routing_key,82 routing_key=routing_key,
80 declare=declare)83 declare=declare)
84 logger.info("Submitted payload %r", payload_copy, extra=payload_copy)
81 return payload_copy['request_id']85 return payload_copy['request_id']
8286
=== modified file 'adt_cloud_service/v1.py'
--- adt_cloud_service/v1.py 2015-03-18 20:20:47 +0000
+++ adt_cloud_service/v1.py 2015-03-19 22:03:02 +0000
@@ -17,12 +17,16 @@
1717
18"""Version 1 restful service web code."""18"""Version 1 restful service web code."""
1919
20import logging
20import urllib.parse21import urllib.parse
2122
22from flask import current_app, request, url_for, jsonify23from flask import current_app, request, url_for, jsonify
2324
24from adt_cloud_service.errors import MissingRequestParameters25from adt_cloud_service.errors import MissingRequestParameters
2526
27logger = logging.getLogger(__name__)
28
29
26def test_new():30def test_new():
27 required_keys = {31 required_keys = {
28 'package-name',32 'package-name',
@@ -32,6 +36,7 @@
32 }36 }
33 missing = required_keys.difference(set(request.form.keys()))37 missing = required_keys.difference(set(request.form.keys()))
34 if missing:38 if missing:
39 logger.error("Got request %r with missing keys %r", dict(request.form), missing)
35 raise MissingRequestParameters(missing)40 raise MissingRequestParameters(missing)
3641
37 rabbit_request = dict()42 rabbit_request = dict()
3843
=== modified file 'requirements.txt'
--- requirements.txt 2015-03-12 18:56:59 +0000
+++ requirements.txt 2015-03-19 22:03:02 +0000
@@ -1,3 +1,4 @@
1flask==0.10.11flask==0.10.1
2gunicorn==19.3.02gunicorn==19.3.0
3kombu==3.0.243kombu==3.0.24
4python-logstash==0.4.2

Subscribers

People subscribed via source and target branches

to all changes: