Skip to content

Commit

Permalink
Merge pull request #30 from XanderD99/28-value-is-not-a-valid-number-nan
Browse files Browse the repository at this point in the history
correctly check response and request content length
  • Loading branch information
XanderD99 authored Dec 9, 2024
2 parents cdb8f10 + 1a94ffd commit 70a5f7e
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions server/src/middlewares/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,20 @@ export default async (ctx, next) => {

httpRequestsTotal.inc({ ...labels, status: ctx.status })

const requestContentLenght = ctx.request.get('Content-Length') || ctx.request.get('content-length');
if (requestContentLenght) {
requestContentLengthBytes.observe({ ...labels, status: ctx.status }, parseInt(requestContentLenght));
const requestContentLength = ctx.request.get('Content-Length') || ctx.request.get('content-length');
if (requestContentLength) {
const parsedRequestContentLength = parseInt(requestContentLength, 10);
if (!isNaN(parsedRequestContentLength) && isFinite(parsedRequestContentLength)) {
requestContentLengthBytes.observe({ ...labels, status: ctx.status }, parsedRequestContentLength);
}
}

const responseConentLength = ctx.response.get('Content-Length') || ctx.response.get('content-length');
if (requestContentLenght) {
responseContentLengthBytes.observe({ ...labels, status: ctx.status }, parseInt(responseConentLength));

const responseContentLength = ctx.response.get('Content-Length') || ctx.response.get('content-length');
if (responseContentLength) {
const parsedResponseContentLength = parseInt(responseContentLength, 10);
if (!isNaN(parsedResponseContentLength) && isFinite(parsedResponseContentLength)) {
responseContentLengthBytes.observe({ ...labels, status: ctx.status }, parsedResponseContentLength);
}
}
});
};

0 comments on commit 70a5f7e

Please sign in to comment.