Skip to content
Snippets Groups Projects
Commit d6b1040d authored by Rhys Arkins's avatar Rhys Arkins
Browse files

refactor: improve get stats

parent c3a4b904
No related branches found
No related tags found
No related merge requests found
...@@ -20,7 +20,9 @@ async function get(path, options, retries = 5) { ...@@ -20,7 +20,9 @@ async function get(path, options, retries = 5) {
return cache[path]; return cache[path];
} }
logger.debug(`${method.toUpperCase()} ${path}`); logger.debug(`${method.toUpperCase()} ${path}`);
stats.requestCount = (stats.requestCount || 0) + 1; stats.requests = (stats.requests || []).concat([
method.toUpperCase() + ' ' + path.replace(opts.endpoint, ''),
]);
try { try {
if (appMode) { if (appMode) {
const appAccept = 'application/vnd.github.machine-man-preview+json'; const appAccept = 'application/vnd.github.machine-man-preview+json';
...@@ -186,8 +188,17 @@ get.reset = function reset() { ...@@ -186,8 +188,17 @@ get.reset = function reset() {
cache = null; cache = null;
cache = {}; cache = {};
// istanbul ignore if // istanbul ignore if
if (stats.requestCount) { if (stats.requests && stats.requests.length) {
logger.info({ stats }, 'Request stats'); logger.info(
{
rateLimit: stats.rateLimit,
requestCount: stats.requests.length,
rateLimitRemaining: stats.rateLimitRemaining,
},
'Request stats'
);
stats.requests.sort();
logger.debug({ requests: stats.requests }, 'All requests');
} }
stats = {}; stats = {};
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment