Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Send remaining queue items if there are more than chunkSize #107

Merged
merged 2 commits into from
Oct 6, 2023
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
9 changes: 8 additions & 1 deletion lib/client/ingest/signal_fx_client.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,14 @@ SignalFxClient.prototype.post = function (data, postUrl, contentType) {
};

return tracing.withNonReportingScope(() => axios(postOptions).then(
(response) => response.data,
(response) => {
if (this.queue.length > 0) {
this.startAsyncSend().catch((error) => {
logger.error('Failed to send remaining datapoints: %s', error);
});
}
return response.data;
},
(error) => {
const { response } = error;
if (response) {
Expand Down
28 changes: 28 additions & 0 deletions test/ingest/signalfx.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,34 @@ describe('SignalFx client library (Protobuf mode)', function () {
setTimeout(function () {
tracingStub.called.should.be.equal(true);
requestStub.called.should.be.equal(true);
client.queue.length.should.be.equal(0);
done();
}, 2000);

});

it('Send many datapoints via queue', function (done) {
requestStub.resolves({ status: 200 });

var token = 'my token';
var client = new signalFx.Ingest(token);

var gauges = [];
// Test with more than the batchSize
for (let i = 0; i < 500; i++) {
gauges.push({
metric: `test.cpu${i}`,
value: 10,
});
}

client.send({gauges: gauges});

this.timeout(2020);
setTimeout(function () {
tracingStub.called.should.be.equal(true);
requestStub.called.should.be.equal(true);
client.queue.length.should.be.equal(0);
done();
}, 2000);

Expand Down