Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log the request time in nginx container logs #739

Open
seanhamlin opened this issue May 3, 2023 · 1 comment
Open

Log the request time in nginx container logs #739

seanhamlin opened this issue May 3, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@seanhamlin
Copy link
Contributor

It can be useful to log the request time in the nginx container log, as the container logs also log the pod name, and hostname. So you could in theory create a visualisation to plot response times for a particular path, by kubernetes host or pod name. This could be useful for performance reasons.

See https://github.com/uselagoon/lagoon-images/blob/main/images/nginx/nginx.conf#L19

There is a variable we can use for this (see the documentation)

$request_time
request processing time in seconds with a milliseconds resolution; time elapsed between the first bytes were read from the client and the log write after the last bytes were sent to the client
@seanhamlin seanhamlin added the enhancement New feature or request label May 3, 2023
@smlx
Copy link
Member

smlx commented May 3, 2023

This would need an associated update to the regex for parsing nginx container logs.

Because there would be a period where some nginx logs would have the $request_time and some wouldn't it would need to be put somewhere unambiguous for regex parsing.

Probably this makes sense:

-$status $body_bytes_sent "$http_referer"
+$status $body_bytes_sent $request_time "$http_referer"

Because then it is an optional bare number before the quoted referer which can be parsed like:

-(?<code>[^ ]*) (?<size>[^ ]*) "
+(?<code>[^ ]*) (?<size>[^ ]*)(?: (?<request_time>[^ ]*))? "

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants