Comparing version 3.0.2 to 3.0.3
137
lib/agent.js
@@ -124,2 +124,4 @@ 'use strict'; | ||
this.pause = false; | ||
// hidden class | ||
@@ -148,4 +150,13 @@ this.harvesterHandle = null; | ||
logger.info('remote command received %d : %s', cmdId, cmdData) | ||
logger.info('remote command received %d : %s', cmdId, cmdData); | ||
var rt = function(id, cid) { | ||
var c = {}; | ||
c[cid] = {}; | ||
var payload = [id, c]; | ||
agent.collector.results(payload, function cb_results(error) { | ||
if(error) logger.warn('error send result of commands. %s', error); | ||
}); | ||
} | ||
if (cmdData.name === 'restart') { | ||
@@ -164,2 +175,8 @@ logger.info('restarting'); | ||
}); | ||
} else if (cmdData.name === 'pause') { | ||
agent.pause = true; | ||
rt(agent.config.run_id, cmdId); | ||
} else if(cmdData.name === 'resume') { | ||
agent.pause = false; | ||
rt(agent.config.run_id, cmdId); | ||
} else { | ||
@@ -528,10 +545,14 @@ logger.warn('command type %s not supported', cmdData.name); | ||
this.collector.metricData(payload, function cb_metricData(error, rules) { | ||
if (error) agent.metrics.merge(metrics); | ||
if (agent.pause) { | ||
process.nextTick(function cb_nextTick() { callback(null); }); | ||
} else { | ||
this.collector.metricData(payload, function cb_metricData(error, rules) { | ||
if (error) agent.metrics.merge(metrics); | ||
// send data and get metric mapper to be used | ||
if (rules) agent.mapper.load(rules); | ||
// send data and get metric mapper to be used | ||
if (rules) agent.mapper.load(rules); | ||
callback(error); | ||
}); | ||
callback(error); | ||
}); | ||
} | ||
} | ||
@@ -568,6 +589,10 @@ else { | ||
this.collector.topoData(payload, function cb_topoData(error, rules) { | ||
if (error) agent.topo.merge(topo); | ||
callback(error); | ||
}); | ||
if (agent.pause) { | ||
process.nextTick(function cb_nextTick() { callback(null); }); | ||
} else { | ||
this.collector.topoData(payload, function cb_topoData(error, rules) { | ||
if (error) agent.topo.merge(topo); | ||
callback(error); | ||
}); | ||
} | ||
} | ||
@@ -608,8 +633,12 @@ else { | ||
this.collector.errorData(payload, function cb_errorData(error) { | ||
// will merging old errors create memory leak ? | ||
if (error) agent.errors.merge(errors); | ||
if (agent.pause) { | ||
process.nextTick(function cb_nextTick() { callback(null); }); | ||
} else { | ||
this.collector.errorData(payload, function cb_errorData(error) { | ||
// will merging old errors create memory leak ? | ||
if (error) agent.errors.merge(errors); | ||
callback(error); | ||
}); | ||
callback(error); | ||
}); | ||
} | ||
} | ||
@@ -650,6 +679,10 @@ else { | ||
var payload = [agent.config.run_id, [encoded]]; | ||
agent.collector.transactionSampleData(payload, function cb_transactionSampleData(error) { | ||
if (!error) agent.traces.reset(trace); | ||
callback(error); | ||
}); | ||
if (agent.pause) { | ||
process.nextTick(function cb_nextTick() { callback(null); }); | ||
} else { | ||
agent.collector.transactionSampleData(payload, function cb_transactionSampleData(error) { | ||
if (!error) agent.traces.reset(trace); | ||
callback(error); | ||
}); | ||
} | ||
}); | ||
@@ -686,6 +719,10 @@ } | ||
agent.collector.queryData([data], function handleResponse(error) { | ||
if (error) agent.queries.merge(queries) | ||
callback(error) | ||
}) | ||
if (agent.pause) { | ||
process.nextTick(function cb_nextTick() { callback(null); }); | ||
} else { | ||
agent.collector.queryData([data], function handleResponse(error) { | ||
if (error) agent.queries.merge(queries) | ||
callback(error) | ||
}) | ||
} | ||
}) | ||
@@ -712,30 +749,34 @@ } | ||
// send data to collector | ||
agent.collector.analyticsEvents(payload, function cb_analyticsEvents(err) { | ||
if (agent.pause) { | ||
process.nextTick(function cb_nextTick() { callback(null); }); | ||
} else { | ||
// send data to collector | ||
agent.collector.analyticsEvents(payload, function cb_analyticsEvents(err) { | ||
if (err && err.statusCode === 413) { | ||
logger.warn('request too large; event data dropped'); | ||
} | ||
else if (err) { | ||
logger.warn('analytics events failed to send; re-sampling'); | ||
if (err && err.statusCode === 413) { | ||
logger.warn('request too large; event data dropped'); | ||
} | ||
else if (err) { | ||
logger.warn('analytics events failed to send; re-sampling'); | ||
// boost the limit if a connection fails | ||
// and re-aggregate on failure | ||
var newlimit = agent.config.transaction_events.max_samples_stored; | ||
agent.events.limit = newlimit; | ||
// boost the limit if a connection fails | ||
// and re-aggregate on failure | ||
var newlimit = agent.config.transaction_events.max_samples_stored; | ||
agent.events.limit = newlimit; | ||
for (var k = 0; k < sample.length; k++) agent.events.add(sample[k]); | ||
} | ||
else { | ||
// if we had to limit events and sample them, emit a warning | ||
var diff = events.overflow(); | ||
if (diff > 0) logger.warn( | ||
'analytics event overflow, dropped %d events; ' + | ||
'try increasing your limit above %d', | ||
diff, events.limit | ||
); | ||
} | ||
for (var k = 0; k < sample.length; k++) agent.events.add(sample[k]); | ||
} | ||
else { | ||
// if we had to limit events and sample them, emit a warning | ||
var diff = events.overflow(); | ||
if (diff > 0) logger.warn( | ||
'analytics event overflow, dropped %d events; ' + | ||
'try increasing your limit above %d', | ||
diff, events.limit | ||
); | ||
} | ||
callback(err); | ||
}); | ||
callback(err); | ||
}); | ||
} | ||
} | ||
@@ -742,0 +783,0 @@ else { |
@@ -19,27 +19,3 @@ 'use strict'; | ||
var BACKOFFS = [{ | ||
interval: 15, | ||
warn: false | ||
}, | ||
{ | ||
interval: 15, | ||
warn: false | ||
}, | ||
{ | ||
interval: 30, | ||
warn: false | ||
}, | ||
{ | ||
interval: 60, | ||
warn: true | ||
}, | ||
{ | ||
interval: 120, | ||
warn: false | ||
}, | ||
{ | ||
interval: 300, | ||
warn: false | ||
} | ||
]; | ||
var BACKOFFS = [30, 120, 300, 600]; | ||
@@ -90,3 +66,4 @@ var ERRORS = { | ||
events: new RemoteMethod('analytic_event_data', agent.config), | ||
commands: new RemoteMethod('get_agent_commands', agent.config) | ||
commands: new RemoteMethod('get_agent_commands', agent.config), | ||
results: new RemoteMethod('agent_command_results', agent.config) | ||
}; | ||
@@ -106,3 +83,3 @@ } | ||
if (!error || attempts >= max) { | ||
if (!error) { | ||
dumpErrors(errors, 'connect'); | ||
@@ -112,3 +89,2 @@ return callback(error, response, body); | ||
// failing high-security mode compliance will cause a disconnect | ||
if (error.class === ERRORS.DISCONNECT) { | ||
@@ -120,19 +96,11 @@ logger.error("The OneAPM collector rejected this agent."); | ||
var backoff = BACKOFFS[attempts - 1]; | ||
if (backoff.warn) { | ||
logger.warn( | ||
"No connection has been established to OneAPM after %s attempts.", | ||
attempts | ||
); | ||
} | ||
logger.debug( | ||
"Failed attempting to connect to OneAPM, waiting %ss to retry.", | ||
backoff.interval | ||
backoff | ||
); | ||
if (attempts < max) { attempts++; } | ||
attempts++; | ||
setTimeout(function again() { | ||
api._login(retry); | ||
}, backoff.interval * TO_MILLIS); | ||
}, backoff * TO_MILLIS); | ||
} | ||
@@ -279,2 +247,8 @@ | ||
CollectorAPI.prototype.results = function results(results, callback) { | ||
if (!results) throw new TypeError("must pass results to send"); | ||
if (!callback) throw new TypeError("callback is required"); | ||
this._runLifecycle(this._methods.results, results, callback); | ||
}; | ||
/** | ||
@@ -281,0 +255,0 @@ * Send already-formatted slow trace data by calling |
{ | ||
"name": "oneapm", | ||
"version": "3.0.2", | ||
"version": "3.0.3", | ||
"author": "OneAPM Node.js agent team <nodejs@oneapm.com>", | ||
@@ -5,0 +5,0 @@ "description": "OneAPM agent", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
368359
8931