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

tsweb: log once per request #12141

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

tsweb: log once per request #12141

wants to merge 1 commit into from

Conversation

icio
Copy link
Contributor

@icio icio commented May 15, 2024

StdHandler/retHandler would previously emit one log line for each request. If there were multiple StdHandler in the chain, there would be one log line per instance of retHandler.

With this change, only the outermost StdHandler/logHandler actually logs the request. The error-rendering part of retHandler lives on in errorHandler, and errorHandler passes those errors up the stack to logHandler through a callback that logHandler places in the request.Context().

This change already yields the log changes desired in #19999 but we could then swap some StdHandler usage for LogHandler/Handler in various places.

Updates tailscale/corp#19999

@icio icio force-pushed the icio/tsweb-nested-stdhandler branch 3 times, most recently from c53e442 to 2cdec70 Compare May 15, 2024 13:48
tsweb/tsweb_test.go Outdated Show resolved Hide resolved
@icio icio requested a review from willnorris May 20, 2024 21:54
Copy link
Contributor

@marwan-at-work marwan-at-work left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've always wanted to separate the StdHandler into separate concerns instead of bundling logging/metrics/error-decoration all in one place, so thank you for doing this!

PR looks good to me but might be worth more expert eyes.

@icio icio force-pushed the icio/tsweb-nested-stdhandler branch from 2cdec70 to 798a6c0 Compare June 6, 2024 19:31
@icio
Copy link
Contributor Author

icio commented Jun 6, 2024

I've rebased this following the addition on OnCompletion, which I think would also suffer from repeated calls when StdHandler is nested.

Actually... I think this will have affected the StatusCodeCounters and BucketStats too...
Edit: but only if they're set on the HandlerOptions which doesn't really happen on the nested StdHandler.

StdHandler/retHandler would previously emit one log line for each request.
If there were multiple StdHandler in the chain, there would be one log line
per instance of retHandler.

With this change, only the outermost StdHandler/logHandler actually logs the
request. The error-rendering part of retHandler lives on in errorHandler, and
errorHandler passes those errors up the stack to logHandler through a callback
that logHandler places in the request.Context().

Updates tailscale/corp#19999

Signed-off-by: Paul Scott <paul@tailscale.com>
@icio icio force-pushed the icio/tsweb-nested-stdhandler branch from 798a6c0 to 5003fa4 Compare June 6, 2024 20:33
@fylie fylie requested review from creachadair and fylie June 12, 2024 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants