Skip to content

Commit

Permalink
fix too large bulk requests
Browse files Browse the repository at this point in the history
  • Loading branch information
megastef committed Dec 10, 2019
1 parent c2dd3ed commit 0319fbd
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/sender/spmsender.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ var containerHostname = null
* @constructor
*/
function SpmSender (spmToken, processMetricsInterval, metricsApiEndpoint) {
this.MAX_DATAPOINTS = config.maxDataPoints || 100
this.MAX_DATAPOINTS = Math.min(Number(config.maxDataPoints) || 100, 300)
this.MAX_WAIT_TIME = 60 * 1000
this.spmToken = spmToken
this.tid = null
Expand Down Expand Up @@ -228,8 +228,9 @@ SpmSender.prototype.getTagLines = function () {
SpmSender.prototype.startSender = function () {
var tid = setInterval(function () {
if (this.datapoints.length > 0) {
this.datapointsToShip = this.datapoints
this.datapoints = []
var reqSize = Math.min(this.datapoints.length, this.MAX_DATAPOINTS || 100)
this.datapointsToShip = this.datapoints.slice(0, reqSize)
this.datapoints = this.datapoints.slice(reqSize, this.datapoints.length)
this.send()
}
}.bind(this), Math.max(5000, config.transmitInterval))
Expand Down Expand Up @@ -354,8 +355,8 @@ SpmSender.prototype.retransmit = function (metrics, callback) {
url: this.metricsUrl + '&sct=APP' + dynamicUrlParameters,
headers: {
'User-Agent': 'node-spm',
'Content-Type': 'application/json'
// 'Keep-Alive': false
'Content-Type': 'application/json',
'Connection': 'Close'
},
body: this.buildBulkRequest(appData),
method: 'POST'
Expand Down

0 comments on commit 0319fbd

Please sign in to comment.