From 59cc317156b05b78c1f0d7f9e078149ea31068d5 Mon Sep 17 00:00:00 2001
From: Rhys Arkins <rhys@arkins.net>
Date: Mon, 30 Aug 2021 17:09:08 +0200
Subject: [PATCH] fix: semantic host stats (#11482)

---
 lib/workers/repository/stats.ts | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/lib/workers/repository/stats.ts b/lib/workers/repository/stats.ts
index 3d15ec92fd..86995200d9 100644
--- a/lib/workers/repository/stats.ts
+++ b/lib/workers/repository/stats.ts
@@ -30,25 +30,26 @@ export function printRequestStats(): void {
     requestHosts[hostname].push(httpRequest);
   }
   logger.trace({ allRequests, requestHosts }, 'full stats');
-  const hostStats: string[] = [];
+  type HostStats = {
+    requestCount: number;
+    requestAvgMs: number;
+    queueAvgMs: number;
+  };
+  const hostStats: Record<string, HostStats> = {};
   let totalRequests = 0;
   for (const [hostname, requests] of Object.entries(requestHosts)) {
-    const hostRequests = requests.length;
-    totalRequests += hostRequests;
+    const requestCount = requests.length;
+    totalRequests += requestCount;
     const requestSum = requests
       .map(({ duration }) => duration)
       .reduce((a, b) => a + b, 0);
-    const requestAvg = Math.round(requestSum / hostRequests);
+    const requestAvgMs = Math.round(requestSum / requestCount);
 
     const queueSum = requests
       .map(({ queueDuration }) => queueDuration)
       .reduce((a, b) => a + b, 0);
-    const queueAvg = Math.round(queueSum / hostRequests);
-    const requestCount =
-      `${hostRequests} ` + (hostRequests > 1 ? 'requests' : 'request');
-    hostStats.push(
-      `${hostname}, ${requestCount}, ${requestAvg}ms request average, ${queueAvg}ms queue average`
-    );
+    const queueAvgMs = Math.round(queueSum / requestCount);
+    hostStats[hostname] = { requestCount, requestAvgMs, queueAvgMs };
   }
   logger.debug({ hostStats, totalRequests }, 'http statistics');
 }
-- 
GitLab