Skip to content

Commit

Permalink
Merge pull request #144 from gaonkar18y/for308-add-quota-logging
Browse files Browse the repository at this point in the history
For308 add quota logging
  • Loading branch information
keyurkarnik authored Sep 27, 2019
2 parents a39763e + a48deba commit 4d9b959
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 14 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
language: node_js
node_js:
- '6.14'
- '8'
- '10'
- '12'
Expand Down
14 changes: 7 additions & 7 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"toobusy-js": "^0.5.1",
"volos-analytics-apigee": "^0.4.0",
"volos-cache-memory": "^0.10.0",
"volos-quota-apigee": "^0.13.3",
"volos-quota-common": "^0.11.7",
"volos-quota-apigee": "^0.13.4",
"volos-quota-common": "^0.11.8",
"volos-quota-memory": "^0.11.0",
"volos-spikearrest-memory": "^0.10.0",
"xml2js": "^0.4.17"
Expand Down
18 changes: 14 additions & 4 deletions quota/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,21 @@

var async = require('async');
var Quota = require('volos-quota-apigee');
var debug = require('debug')('gateway:quota');
var debugTerminal = require('debug')('gateway:quota');
var url = require('url');
const util = require('util');


module.exports.init = function(config /*, logger, stats */) {
module.exports.init = function(config, logger /*, stats */) {

const debug = (...data) => {
const formatedData = util.format(...data);
logger.debug('quota : '+formatedData);
debugTerminal(formatedData);
}

debug('quota plugin init called with config: %j', config)

const { product_to_proxy, proxies } = config;
const prodsObj = {};
var quotas = {}; // productName -> connectMiddleware
Expand All @@ -33,7 +42,7 @@ module.exports.init = function(config /*, logger, stats */) {
var product = config[productName];
if (!product.uri && !product.key && !product.secret && !product.allow && !product.interval || product.interval === "null") {
// skip non-quota config
debug('Quota not configured on the API product, skipping. This message is safe to ignore');
debug('Quota not configured on the API product: %s, skipping. This message is safe to ignore',productName);
return;
}

Expand Down Expand Up @@ -64,6 +73,7 @@ module.exports.init = function(config /*, logger, stats */) {
prodsObj[productName] = prodObj;

config[productName].request = config.request;
config[productName]['debug'] = debug;
var quota = Quota.create(config[productName]);
quotas[productName] = quota.connectMiddleware().apply(options);
//
Expand All @@ -77,7 +87,7 @@ module.exports.init = function(config /*, logger, stats */) {
return next();
}

debug('quota checking products', req.token.api_product_list);
debug('New request, quota checking products', req.token.api_product_list);

req.originalUrl = req.originalUrl || req.url; // emulate connect

Expand Down
2 changes: 2 additions & 0 deletions test/microgateway-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
/* simulating the objects of microgateway-core to avoid run time errors in travis. */
module.exports = {
logger: {
debug: function (obj, msg) { },
trace: function (obj, msg) { },
info: function (obj, msg) { },
warn: function (obj, msg) { },
error: function (obj, msg) {},
Expand Down

0 comments on commit 4d9b959

Please sign in to comment.