From a5a8bdfbefe0375b9c3afd82da3a4fd40ed3fae5 Mon Sep 17 00:00:00 2001 From: Bryan Mikaelian Date: Tue, 11 Apr 2017 10:14:03 -0500 Subject: [PATCH] Fix batch call --- lib/librato.js | 4 ++-- test/librato_tests.js | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/librato.js b/lib/librato.js index 64a6e9f..25a528e 100644 --- a/lib/librato.js +++ b/lib/librato.js @@ -280,8 +280,8 @@ var flushStats = function libratoFlush(ts, metrics) { // Add the payload measurements.push(measure); // Post measurements and clear arrays if past batch size - if (measurements >= maxBatchSize || writeToLegacy && counters.length + gauges.length >= maxBatchSize) { - post_metrics(measureTime, gauges, counters, measurements); + if (measurements.length >= maxBatchSize || writeToLegacy && counters.length + gauges.length >= maxBatchSize) { + postMetrics(measureTime, gauges, counters, measurements); if (measurements >= maxBatchSize) { measurements = []; } diff --git a/test/librato_tests.js b/test/librato_tests.js index ce667d8..c035e17 100644 --- a/test/librato_tests.js +++ b/test/librato_tests.js @@ -38,6 +38,7 @@ module.exports = { token: '-', api: 'http://127.0.0.1:' + serverPort, writeToLegacy: false, + batchSize: 5, }, }, this.emitter); }, @@ -145,4 +146,20 @@ module.exports = { })); this.emitter.emit('flush', 123, metrics); }, + + testMaxBatchSize: function(test) { + test.expect(0); + var gauges = {}; + for (var i = 0; i < 5; i++) { + var key = 'gauge' + i; + gauges[key] = 1; + } + var metrics = {gauges: gauges}; + + this.server.once('request', this.api_mock(true, {}, function(req, res, body) { + })); + + this.emitter.emit('flush', 123, metrics); + test.done(); + }, };