Rotate autoland logs and stop truncating them on startup (Bug 1230537) r?mdoglio draft
authorDan Minor <dminor@mozilla.com>
Wed, 16 Dec 2015 15:33:05 -0500
changeset 6402 2b984d9617f3ac5b84b4d95a161d28589cc108be
parent 6401 6794cb59ea784f390a13166c633122f2dd35b566
push id466
push userdminor@mozilla.com
push dateThu, 17 Dec 2015 14:19:00 +0000
reviewersmdoglio
bugs1230537
Rotate autoland logs and stop truncating them on startup (Bug 1230537) r?mdoglio This changes the autoland logging to use the python logging library and to stop truncating logs on startup. It also configures logrotate on the autoland instances to rotate logs automatically.
ansible/provision-autoland.yml
autoland/autoland/autoland.py
autoland/autoland/autoland_rest.py
autoland/logrotate/autoland
autoland/requirements.txt
autoland/tests/test-post-autoland-job.t
autoland/upstart/autoland.conf
testing/docker/builder-autoland/start-autoland.sh
--- a/ansible/provision-autoland.yml
+++ b/ansible/provision-autoland.yml
@@ -117,8 +117,11 @@
   - name: install autoland service
     command: cp /home/ubuntu/version-control-tools/autoland/upstart/autoland.conf /etc/init/autoland.conf
 
   - name: reload service configuration
     command: initctl reload-configuration
 
   - name: create autoland database
     shell: sudo -u postgres /home/ubuntu/version-control-tools/autoland/sql/createdb.sh chdir=/home/ubuntu/version-control-tools/autoland/sql
+
+  - name: configure autoland log rotation
+    command: cp /home/ubuntu/version-control-tools/autoland/logrotate/autoland /etc/logrotate.d/autoland
--- a/autoland/autoland/autoland.py
+++ b/autoland/autoland/autoland.py
@@ -11,17 +11,16 @@ import psycopg2
 import sys
 import time
 import traceback
 
 sys.path.insert(0, os.path.normpath(os.path.join(os.path.normpath(
                 os.path.abspath(os.path.dirname(__file__))), '..', '..',
                 'pylib', 'mozautomation')))
 from mozautomation.commitparser import parse_bugs
-from mozlog.structured import commandline
 
 import transplant
 import treestatus
 
 
 # max attempts to transplant before bailing
 MAX_TRANSPLANT_ATTEMPTS = 50
 
@@ -261,22 +260,27 @@ def get_dbconn(dsn):
 
 
 def main():
     parser = argparse.ArgumentParser()
 
     dsn = config.get('database')
 
     parser.add_argument('--dsn', default=dsn,
-                        help="Postgresql DSN connection string")
-    commandline.add_logging_group(parser)
+                        help='Postgresql DSN connection string')
+    parser.add_argument('--log-path', default='autoland.log',
+                        help='Path to which to log')
     args = parser.parse_args()
 
-    logging.basicConfig()
-    logger = commandline.setup_logging('autoland', vars(args), {})
+    logging.basicConfig(filename=args.log_path,
+                        filemode='a',
+                        format='%(asctime)s,%(msecs)d %(name)s %(levelname)s %(message)s',
+                        datefmt='%H:%M:%S',
+                        level=logging.DEBUG)
+    logger = logging.getLogger('autoland')
     logger.info('starting autoland')
 
     dbconn = get_dbconn(args.dsn)
     last_error_msg = None
     next_mozreview_update = datetime.datetime.now()
     while True:
         try:
             handle_pending_transplants(logger, dbconn)
--- a/autoland/autoland/autoland_rest.py
+++ b/autoland/autoland/autoland_rest.py
@@ -3,18 +3,16 @@ import config
 import json
 import logging
 import os
 import psycopg2
 import urlparse
 
 from flask import Flask, request, jsonify, Response, abort, make_response
 
-from mozlog.structured import commandline
-
 
 app = Flask(__name__, static_url_path='', static_folder='')
 
 
 @app.errorhandler(404)
 def not_found(error):
     return make_response(jsonify({'error': 'Not found'}), 404)
 
new file mode 100644
--- /dev/null
+++ b/autoland/logrotate/autoland
@@ -0,0 +1,9 @@
+/home/ubuntu/autoland.log {
+    rotate 7
+    weekly
+    olddir /var/log
+    missingok
+    notifempty
+    copytruncate
+    compress
+}
--- a/autoland/requirements.txt
+++ b/autoland/requirements.txt
@@ -8,19 +8,16 @@ flask==0.10.1
 github3.py==1.0.0a1
 
 # sha256: 1GR5QxZa_9EbrwcFVWkgSB1TRrl2BLq6tq128XREdMY
 mercurial==3.6.1
 
 # sha256: dQzlorS9IlvQCzOeGsUzwWsYfAgEaVuz2HjGme4rMig
 mozillapulse==1.2.2
 
-# sha256: AQCIYcygr7ac0w3NOJhD_rgX57nRRtU0UClUTPA73nI
-mozlog==2.2
-
 # sha256: as-au751fvddwuzZ2RunSVR5Qauv--af8ghqnjfUkEw
 psycopg2==2.6.1
 
 # sha256: 9DAokrK4KHzzJlhscoC56t_D0MfNP-upV0KajZsaYM4
 python-hglib==1.9
 
 # sha256: ifGx8l3Ne2j1FOjTQaWy60ZvlgrnVoIuqrSAo8GoHCg
 requests==2.8.1
--- a/autoland/tests/test-post-autoland-job.t
+++ b/autoland/tests/test-post-autoland-job.t
@@ -36,17 +36,17 @@ Create a commit to test on Try
   
   review id:  bz://1/mynick
   review url: http://*:$HGPORT1/r/1 (draft) (glob)
   (visit review url to publish these review requests so others can see them)
 
 Ensure Autoland started without errors
 
   $ mozreview exec autoland tail -n 20 /home/ubuntu/autoland.log
-   0:00.* LOG: MainThread INFO starting autoland (glob)
+  * autoland INFO starting autoland (glob)
 
 Posting a job with bad credentials should fail
 
   $ ottoland post-autoland-job $AUTOLAND_URL test-repo `hg log -r . --template "{node|short}"` try http://localhost:9898 --user blah --password blah
   (401, u'Login required')
 
 Posting a job with without both trysyntax and commit_descriptions should fail
 
--- a/autoland/upstart/autoland.conf
+++ b/autoland/upstart/autoland.conf
@@ -6,10 +6,10 @@ stop on runlevel [!2345]
 
 respawn
 
 setuid ubuntu
 setgid ubuntu
 
 script
   cd /home/ubuntu/version-control-tools/autoland/autoland
-  exec python autoland.py --log-mach=/home/ubuntu/autoland.log
+  exec python autoland.py --log-path=/home/ubuntu/autoland.log
 end script
--- a/testing/docker/builder-autoland/start-autoland.sh
+++ b/testing/docker/builder-autoland/start-autoland.sh
@@ -1,8 +1,8 @@
 #!/bin/bash
 
 cd $AUTOLAND_HOME
 . venv/bin/activate
 
 cd autoland
-python autoland.py --log-mach=/home/ubuntu/autoland.log --dsn="dbname=autoland user=postgres host=db" &
+python autoland.py --log-path=/home/ubuntu/autoland.log --dsn="dbname=autoland user=postgres host=db" &
 apache2ctl -D FOREGROUND