puppetlabs/puppetdb — pull request #785 by jantman (2014-01-04 16:17:12+00:00)
Title: PDB-106 - report processor handle failed reports / reports with no metrics

When a report comes in from a failed agent run, or an agent terminated mid-run, the report has no metrics (per the report format documentation). Currently, the report processor blindly tries to access metrics["time"]["total"], which isn't present in failed reports, so the report processor dies with:
Report processor failed: undefined method `[]' for nil:NilClass
and the report never makes it into PuppetDB. This is really bad for people who didn't know about the bug, and are checking PuppetDB to alert them of failed runs (which will never be seen).

Further evidence of this can be found in the unit tests for the report processor, which specifically stub :run_duration so this doesn't happen.

I've added a unit test for this condition, and changed run_duration to simply return 0 if the time->total metric is missing, which seems like the most logical thing to do (at least until the puppet agent starts sending metrics for failed runs too).