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

Fix issue when data > maxBatchSize wouldn't send #79

Merged
merged 1 commit into from
Apr 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
},
};