Skip to content

Commit

Permalink
agent: reset error count at end of harvest cycle regardless of error …
Browse files Browse the repository at this point in the history
…collector settings
  • Loading branch information
Wraithan (Chris McDonald) committed May 12, 2014
1 parent 481a683 commit 5c7a4fc
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,13 @@ Agent.prototype._sendErrors = function (callback) {
});
}
else {
/**
* Reset the errors object even if collection is disabled due to error
* counting. Also covers the case where the error collector gets disabled
* in the middle of a harvest cycle so the agent doesn't continue to hold
* on to the errors it had collected during the harvest cycle so far.
*/
this.errors = new ErrorTracer(agent.config);
process.nextTick(callback);
}
};
Expand Down
48 changes: 48 additions & 0 deletions test/agent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,54 @@ describe("the New Relic agent", function () {
agent.harvest(function nop() {});
});

it("resets error count after harvest", function (done) {
agent.errors.add(null, new TypeError('no method last on undefined'));
agent.errors.add(null, new Error('application code error'));
agent.errors.add(null, new RangeError('stack depth exceeded'));

agent.collector.metricData = function (payload, cb) {
// These tests do not clean up after themselves, at least call the cb
// that harvest doesn't hang.
cb();
};

var old_ed = agent.collector.errorData;
agent.collector.errorData = function (errors, cb) {
cb();
};

agent.harvest(function () {
expect(agent.errors.errorCount).equal(0);
agent.collector.errorData = old_ed;
done();
});

});

it("resets error count after harvest when error collector is off", function (done) {
agent.errors.add(null, new TypeError('no method last on undefined'));
agent.errors.add(null, new Error('application code error'));
agent.errors.add(null, new RangeError('stack depth exceeded'));

// Defaults to true, but maybe it'll change in the future.
var old_config = agent.config.error_collector.enabled;
agent.config.error_collector.enabled = false;

agent.collector.metricData = function (payload, cb) {
// These tests do not clean up after themselves, at least call the cb
// that harvest doesn't hang.
cb();
};



agent.harvest(function () {
expect(agent.errors.errorCount).equal(0);
agent.config.error_collector.enabled = old_config;
done();
});
});

it("bails out early when sending metrics fails", function (done) {
var metricData =
nock(URL)
Expand Down

0 comments on commit 5c7a4fc

Please sign in to comment.