Skip to content

Commit

Permalink
config: ensure ignored status codes are numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
Forrest L Norvell committed Feb 1, 2014
1 parent 551717b commit 7d3b835
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
20 changes: 19 additions & 1 deletion lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ function Config(config) {
// 4. override config with environment variables
this._fromEnvironment();

// 5. put the version in the config
// 5. clean up anything that requires postprocessing
this._canonicalize();

// 6. put the version in the config
this.version = require(path.join(__dirname, '..', 'package.json')).version;
}
util.inherits(Config, EventEmitter);
Expand Down Expand Up @@ -564,6 +567,21 @@ Config.prototype._fromEnvironment = function (metadata, data) {
}, this);
};

/**
* Depending on how the status codes are set, they could be strings, which
* makes strict equality testing / indexOf fail. To keep things cheap, parse
* them once, after configuration has finished loading. Other one-off shims
* based on special properties of configuration values should go here as well.
*/
Config.prototype._canonicalize = function () {
var codes = this.error_collector && this.error_collector.ignore_status_codes;
if (codes) {
this.error_collector.ignore_status_codes = codes.map(function (code) {
return parseInt(code, 10);
});
}
};

/**
* The agent will use the supportability metrics object if it's
* available.
Expand Down
2 changes: 1 addition & 1 deletion test/config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ describe("the agent configuration", function () {
idempotentEnv('NEW_RELIC_ERROR_COLLECTOR_IGNORE_ERROR_CODES',
'401,404,502', function (tc) {
should.exist(tc.error_collector.ignore_status_codes);
expect(tc.error_collector.ignore_status_codes).eql(['401', '404', '502']);
expect(tc.error_collector.ignore_status_codes).eql([401, 404, 502]);
});
});

Expand Down

0 comments on commit 7d3b835

Please sign in to comment.