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 2 times, most recently from a87d78e to c53e442 Compare May 15, 2024 13:34
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 <[email protected]>
@icio icio force-pushed the icio/tsweb-nested-stdhandler branch from c53e442 to 2cdec70 Compare May 15, 2024 13:48
})
if diff := cmp.Diff(logs[0], test.wantLog, errTransform); diff != "" {
t.Errorf("handler wrote incorrect request log (-got+want):\n%s", diff)
if diff := cmp.Diff(logs[0], test.wantLog, cmpopts.IgnoreFields(AccessLogRecord{}, "Bytes")); diff != "" {
Copy link
Contributor Author

@icio icio May 15, 2024

Choose a reason for hiding this comment

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

It seems like we weren't setting Bytes if the error handled wrote the message. Is it OK to write the error response's Bytes into this field. Surely nothing assumes this means SuccessfulBytes? 😅

If it's OK to log the correct Bytes, I'll update the test cases and remove this IgnoreFields.

@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.

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