Skip to content
This repository has been archived by the owner on Dec 8, 2023. It is now read-only.

Commit

Permalink
Merge pull request #79 from librato/bugfix/fix-method-name
Browse files Browse the repository at this point in the history
Fix issue when data > maxBatchSize wouldn't send
  • Loading branch information
bryanmikaelian authored Apr 11, 2017
2 parents 3272924 + a5a8bdf commit f87c9dc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/librato.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
}
Expand Down
17 changes: 17 additions & 0 deletions test/librato_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module.exports = {
token: '-',
api: 'http://127.0.0.1:' + serverPort,
writeToLegacy: false,
batchSize: 5,
},
}, this.emitter);
},
Expand Down Expand Up @@ -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();
},
};

0 comments on commit f87c9dc

Please sign in to comment.