From d6b1040de20323b785335e2e2c14c46f51c698bc Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Wed, 5 Sep 2018 11:03:47 +0200
Subject: [PATCH] refactor: improve get stats

---
 lib/platform/github/gh-got-wrapper.js | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/lib/platform/github/gh-got-wrapper.js b/lib/platform/github/gh-got-wrapper.js
index 1747272d9a..21e49bfb59 100644
--- a/lib/platform/github/gh-got-wrapper.js
+++ b/lib/platform/github/gh-got-wrapper.js
@@ -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 = {};
 };
-- 
GitLab