From 2ce479db3222c0e22c6357b9f5441a5859b5e8f5 Mon Sep 17 00:00:00 2001 From: Prashant Nayak Date: Sun, 18 Sep 2016 09:56:11 -0400 Subject: [PATCH] whitelist takes precedence over blacklist --- lib/aws-cloudwatch-statsd-backend.js | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/lib/aws-cloudwatch-statsd-backend.js b/lib/aws-cloudwatch-statsd-backend.js index 80b152e..f0de42f 100644 --- a/lib/aws-cloudwatch-statsd-backend.js +++ b/lib/aws-cloudwatch-statsd-backend.js @@ -50,6 +50,13 @@ CloudwatchBackend.prototype.processKey = function(key) { CloudwatchBackend.prototype.isBlacklisted = function(key) { var blacklisted = false; + + // First check if key is whitelisted + if (this.config.whitelist && this.config.whitelist.length > 0 && this.config.whitelist.indexOf(key) >= 0) { + // console.log("Key (counter) " + key + " is whitelisted"); + return false; + } + if (this.config.blacklist && this.config.blacklist.length > 0) { for (var i = 0; i < this.config.blacklist.length; i++) { if (key.indexOf(this.config.blacklist[i]) >= 0) { @@ -112,11 +119,6 @@ CloudwatchBackend.prototype.flush = function(timestamp, metrics) { if (key.indexOf('statsd.') == 0) continue; - if (this.config.whitelist && this.config.whitelist.length > 0 && this.config.whitelist.indexOf(key) == -1) { - // console.log("Key (counter) " + key + " not in whitelist"); - continue; - } - if (this.isBlacklisted(key)) { continue; } @@ -140,11 +142,6 @@ CloudwatchBackend.prototype.flush = function(timestamp, metrics) { for (key in timers) { if (timers[key].length > 0) { - if (this.config.whitelist && this.config.whitelist.length > 0 && this.config.whitelist.indexOf(key) == -1) { - // console.log("Key (counter) " + key + " not in whitelist"); - continue; - } - if (this.isBlacklisted(key)) { continue; } @@ -196,11 +193,6 @@ CloudwatchBackend.prototype.flush = function(timestamp, metrics) { var currentGaugeMetrics = []; for (key in gauges) { - if (this.config.whitelist && this.config.whitelist.length > 0 && this.config.whitelist.indexOf(key) == -1) { - // console.log("Key (counter) " + key + " not in whitelist"); - continue; - } - if (this.isBlacklisted(key)) { continue; } @@ -223,11 +215,6 @@ CloudwatchBackend.prototype.flush = function(timestamp, metrics) { var currentSetMetrics = []; for (key in sets) { - if (this.config.whitelist && this.config.whitelist.length > 0 && this.config.whitelist.indexOf(key) == -1) { - // console.log("Key (counter) " + key + " not in whitelist"); - continue; - } - if (this.isBlacklisted(key)) { continue; }