Skip to content

Commit 080d054

Browse files
committed
Back port socket metrics by origin cleanup
1 parent 848a2dc commit 080d054

1 file changed

Lines changed: 6 additions & 12 deletions

File tree

src/HttpClient/middlewares/request.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,28 +92,22 @@ export const requestMiddleware = (limit?: Limit) => async (ctx: MiddlewareContex
9292
ctx.response = await (limit ? limit(makeRequest) : makeRequest())
9393
}
9494

95-
function countPerOrigin (obj: { [key: string]: any[] }) {
95+
function count (obj: { [key: string]: any[] }) {
9696
try {
97-
return mapObjIndexed(val => val.length, obj)
97+
return Object.values(obj).reduce((acc, val) => acc += val.length, 0)
9898
} catch (_) {
99-
return {}
99+
return 0
100100
}
101101
}
102102

103103
export function httpAgentStats () {
104-
const socketsPerOrigin = countPerOrigin(httpAgent.sockets)
105-
const sockets = sum(values(socketsPerOrigin))
106-
const freeSocketsPerOrigin = countPerOrigin((httpAgent as any).freeSockets)
107-
const freeSockets = sum(values(freeSocketsPerOrigin))
108-
const pendingRequestsPerOrigin = countPerOrigin(httpAgent.requests)
109-
const pendingRequests = sum(values(pendingRequestsPerOrigin))
104+
const sockets = count(httpAgent.sockets)
105+
const freeSockets = count((httpAgent as any).freeSockets)
106+
const pendingRequests = count(httpAgent.requests)
110107

111108
return {
112109
freeSockets,
113-
freeSocketsPerOrigin,
114110
pendingRequests,
115-
pendingRequestsPerOrigin,
116111
sockets,
117-
socketsPerOrigin,
118112
}
119113
}

0 commit comments

Comments
 (0)