From 330814f25cb1a46f0313a888109f44612fac928a Mon Sep 17 00:00:00 2001 From: brettlangdon Date: Tue, 11 Aug 2015 22:41:54 -0400 Subject: [PATCH] Make sure to normalize points for metric.send fixes #20 --- lib/api/metric.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/api/metric.js b/lib/api/metric.js index cfc0dab..ed47e65 100644 --- a/lib/api/metric.js +++ b/lib/api/metric.js @@ -38,6 +38,22 @@ function send(metric, points, extra, callback){ callback = extra; extra = {}; } + // Try to normalize `points` + // DEV: We need `points` to be an array of arrays regardless of what they give us + // Always wrap points in an array, this way we will get: + // 500 => [500] + // [, 500] => [[, 500]] + points = [points]; + points = points.map(function(point){ + // Make sure each point is an array, if not make array with current timestamp + // 500 => [, 500] + // [, 500] => unchanged + if(!Array.isArray(point)){ + var now = parseInt(new Date().getTime() / 1000); + point = [now, point]; + } + return point; + }); extra = extra || {}; var series = [