Improve logging of new job submissions
authorIustin Pop <iustin@google.com>
Wed, 31 Oct 2012 13:47:18 +0000 (14:47 +0100)
committerIustin Pop <iustin@google.com>
Thu, 1 Nov 2012 13:00:14 +0000 (14:00 +0100)
This addresses issue 290: when receiving new jobs, logging is
incomplete, and we don't have the job ID(s) and/or summaries
logged. Only later, when the job is queried for or being processed, we
know more.

This is not good when troubleshooting, so let's improve the initial
logging.

Signed-off-by: Iustin Pop <iustin@google.com>
Reviewed-by: Bernardo Dal Seno <bdalseno@google.com>

lib/server/masterd.py

index 71ddb90..40917fe 100644 (file)
@@ -66,6 +66,18 @@ EXIT_NOTMASTER = constants.EXIT_NOTMASTER
 EXIT_NODESETUP_ERROR = constants.EXIT_NODESETUP_ERROR
 
 
+def _LogNewJob(status, info, ops):
+  """Log information about a recently submitted job.
+
+  """
+  if status:
+    logging.info("New job with id %s, summary: %s",
+                 info, utils.CommaJoin(op.Summary() for op in ops))
+  else:
+    logging.info("Failed to submit job, reason: '%s', summary: %s",
+                 info, utils.CommaJoin(op.Summary() for op in ops))
+
+
 class ClientRequestWorker(workerpool.BaseWorker):
   # pylint: disable=W0221
   def RunTask(self, server, message, client):
@@ -267,18 +279,23 @@ class ClientOps:
     # TODO: Rewrite to not exit in each 'if/elif' branch
 
     if method == luxi.REQ_SUBMIT_JOB:
-      logging.info("Received new job")
+      logging.info("Receiving new job")
       (job_def, ) = args
       ops = [opcodes.OpCode.LoadOpCode(state) for state in job_def]
-      return queue.SubmitJob(ops)
+      job_id = queue.SubmitJob(ops)
+      _LogNewJob(True, job_id, ops)
+      return job_id
 
     elif method == luxi.REQ_SUBMIT_MANY_JOBS:
-      logging.info("Received multiple jobs")
+      logging.info("Receiving multiple jobs")
       (job_defs, ) = args
       jobs = []
       for ops in job_defs:
         jobs.append([opcodes.OpCode.LoadOpCode(state) for state in ops])
-      return queue.SubmitManyJobs(jobs)
+      job_ids = queue.SubmitManyJobs(jobs)
+      for ((status, job_id), ops) in zip(job_ids, jobs):
+        _LogNewJob(status, job_id, ops)
+      return job_ids
 
     elif method == luxi.REQ_CANCEL_JOB:
       (job_id, ) = args