Fix broken query in recipe metrics collection

Also adds unit tests for metrics reporting functions in beakerd

Bug: 584783
Change-Id: Iab8cb12f48224912d28c65cace87fb6a7e482bf1