Bug 1294109 - Prefix log output with mozharness step name; r?ekyle draft
authorGregory Szorc <gps@mozilla.com>
Tue, 09 Aug 2016 17:59:29 -0700
changeset 399396 b52ca799f9d45f862f2e32ac55e3aa369672d656
parent 399395 54f53e1f7defc2cce12961b514cc0c4530b4b4cc
child 399397 885553ed6095ddfab7cd8ce33cb3a0cd47509c4e
push id25822
push userbmo:gps@mozilla.com
push dateThu, 11 Aug 2016 00:19:58 +0000
reviewersekyle
bugs1294109
milestone51.0a1
Bug 1294109 - Prefix log output with mozharness step name; r?ekyle We now scan process output for mozharness step data. When we see the beginning of a mozharness step, we change the line/log prefix to include the step name. When we see the end of a mozharness step, we restore the original prefix (which is likely "task"). This makes it much easier for humans to visually scan logs for specific steps and for automated processes to grep for lines belonging to certain steps. If we wanted to, we could print out a summary of time spent in various steps. But mozharness does that already, so let's not complicate run-task too much. MozReview-Commit-ID: 1lcWGxmmWN4
testing/docker/recipes/run-task
--- a/testing/docker/recipes/run-task
+++ b/testing/docker/recipes/run-task
@@ -22,16 +22,20 @@ import grp
 import os
 import pwd
 import re
 import subprocess
 import sys
 
 
 RE_TIME_PREFIX = re.compile('^\d{2}:\d{2}:\d{2}\s+')
+RE_MOZHARNESS_START_STEP = re.compile('\[mozharness:[^\]]+\] Running '
+                                      '(?P<step>[a-zA-Z0-9_-]+) step')
+RE_MOZHARNESS_END_STEP = re.compile('\[mozharness:[^\]]+\] Finished '
+                                    '(?P<step>[a-zA-Z0-9_-]+) step')
 
 
 def print_line(prefix, m):
     now = datetime.datetime.utcnow()
     print(b'[%s %sZ] %s' % (prefix, now.isoformat(), m), end=b'')
 
 
 def run_and_prefix_output(prefix, args):
@@ -53,26 +57,41 @@ def run_and_prefix_output(prefix, args):
                          stdout=subprocess.PIPE,
                          stderr=subprocess.STDOUT,
                          stdin=sys.stdin.fileno(),
                          cwd='/',
                          # So \r in progress bars are rendered as multiple
                          # lines, preserving progress indicators.
                          universal_newlines=True)
 
+    step = None
     while True:
         data = p.stdout.readline()
         if data == b'':
             break
 
         # Some other process is printing out times. Strip that output since
         # our lines are prefixed with the full datetime.
         data = RE_TIME_PREFIX.sub(b'', data, count=1)
 
-        print_line(prefix, data)
+        # Detect mozharness steps and change the log prefix to be the step
+        # name. This makes it easier to visually scan and grep logs for
+        # certain steps.
+        m = RE_MOZHARNESS_START_STEP.search(data)
+        if m:
+            step = m.group('step')
+
+        print_line(step or prefix, data)
+
+        # Reset the active step at the end of it so the step doesn't leak
+        # into subsequent lines (in case the next line isn't a begin step
+        # message).
+        m = RE_MOZHARNESS_END_STEP.search(data)
+        if m:
+            step = None
 
     return p.wait()
 
 
 def vcs_checkout(args):
     # TODO get VCS parameters from arguments.
     base_repo = os.environ.get('GECKO_BASE_REPOSITORY')