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

refactor: improve get stats

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