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

v2:interceptors/logging: allow to separate request response payload logging #442

Conversation

michaljemala
Copy link
Contributor

@michaljemala michaljemala commented Jul 13, 2021

Logging payloads of requests on the server-side and similarly of responses on the client-side is a pretty common and desired use-case. However, logging by default payloads of both requests as well as responses in both scenarios is IMO not a very common requirement.

Consider the following PR to enable more granular control of what to log and when. This is achieved by using a special PayloadDecison type having the following values:

  • NoPayloadLogging - Payload logging is disabled.
  • LogRequest - Only logging of requests is enabled.
  • LogResponse - Only logging of responses is enabled.
  • LogRequestAndResponse - Logging of both requests and responses is enabled.
    The PayloadDecison is to be used instead of the original bool by the logging.ServerPayloadLoggingDecider and logging.ClientPayloadLoggingDecider.

NOTE: I quickly put this together to see whether it could be considered a valid approach, thus please excuse the lack of additional unit tests. I will be glad to add those once the approach is approved.

@google-cla
Copy link

google-cla bot commented Jul 13, 2021

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@michaljemala
Copy link
Contributor Author

@googlebot I fixed it.

@google-cla
Copy link

google-cla bot commented Jul 13, 2021

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and then comment @googlebot I fixed it.. If the bot doesn't comment, it means it doesn't think anything has changed.

ℹ️ Googlers: Go here for more info.

@michaljemala michaljemala force-pushed the v2_separate_request_response_payload_logs branch from 1c3e861 to 5bcaa5b Compare July 13, 2021 22:17
@michaljemala
Copy link
Contributor Author

@googlebot I fixed it.

@michaljemala michaljemala force-pushed the v2_separate_request_response_payload_logs branch from 5bcaa5b to ebc4206 Compare July 13, 2021 22:22
@codecov-commenter
Copy link

codecov-commenter commented Jul 14, 2021

Codecov Report

Merging #442 (e75d159) into v2 (6e2c2ac) will decrease coverage by 25.51%.
The diff coverage is 42.66%.

❗ Current head e75d159 differs from pull request most recent head 9f260f9. Consider uploading reports for the commit 9f260f9 to get more accurate results
Impacted file tree graph

@@             Coverage Diff             @@
##               v2     #442       +/-   ##
===========================================
- Coverage   84.01%   58.49%   -25.52%     
===========================================
  Files          30       38        +8     
  Lines         932     1706      +774     
===========================================
+ Hits          783      998      +215     
- Misses        110      636      +526     
- Partials       39       72       +33     
Impacted Files Coverage Δ
chain.go 0.00% <ø> (-90.91%) ⬇️
interceptors/auth/auth.go 100.00% <ø> (ø)
interceptors/auth/metadata.go 100.00% <ø> (ø)
interceptors/logging/options.go 82.85% <0.00%> (-7.77%) ⬇️
interceptors/ratelimit/ratelimit.go 60.00% <0.00%> (-40.00%) ⬇️
interceptors/recovery/options.go 78.57% <ø> (ø)
interceptors/retry/backoff.go 52.94% <ø> (+2.94%) ⬆️
interceptors/tags/context.go 64.00% <ø> (ø)
interceptors/tags/fieldextractor.go 15.15% <0.00%> (-70.15%) ⬇️
interceptors/tags/interceptors.go 95.65% <ø> (ø)
... and 44 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dc87da6...9f260f9. Read the comment docs.

Copy link
Collaborator

@johanbrandhorst johanbrandhorst left a comment

Choose a reason for hiding this comment

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

I quite like this, but it was @bwplotka who refactored these, so I would prefer to have his input.

Copy link
Collaborator

@yashrsharma44 yashrsharma44 left a comment

Choose a reason for hiding this comment

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

Functionally - I think using a switch case would make this code easier to read and maintainable. Otherwise looks good to me!

interceptors/logging/payload.go Outdated Show resolved Hide resolved
@yashrsharma44
Copy link
Collaborator

Hi @michaljemala !

This PR looks good to me, can you run make lint for fixing the CI changes required?
Otherwise looks good to me.

@yashrsharma44
Copy link
Collaborator

cc'ing @bwplotka for the inputs 😄

@michaljemala michaljemala force-pushed the v2_separate_request_response_payload_logs branch 3 times, most recently from 685607e to e75d159 Compare August 3, 2021 06:29
@yashrsharma44
Copy link
Collaborator

Seems like the CI build needs approval for first time contributors - https://github.blog/changelog/2021-04-22-github-actions-maintainers-must-approve-first-time-contributor-workflow-runs/

@michaljemala
Copy link
Contributor Author

Hi @yashrsharma44 is there anything else on my side to be done?

@yashrsharma44
Copy link
Collaborator

We are blocked on @bwplotka's review. Let me get back to him when he is free.

Copy link
Collaborator

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

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

LGTM, only minor nit and lint error 🤗

Thanks!

// NoPayloadLogging - Payload logging is disabled.
NoPayloadLogging PayloadDecision = iota
// LogRequest - Only logging of requests is enabled.
LogRequest
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
LogRequest
LogPayloadRequest

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

// LogRequest - Only logging of requests is enabled.
LogRequest
// LogResponse - Only logging of responses is enabled.
LogResponse
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
LogResponse
LogPayloadResponse

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

// LogResponse - Only logging of responses is enabled.
LogResponse
// LogRequestAndResponse - Logging of both requests and responses is enabled.
LogRequestAndResponse
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
LogRequestAndResponse
LogPayloadRequestAndResponse

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@bwplotka bwplotka added this to In progress in Milestone v2 Aug 6, 2021
@michaljemala michaljemala force-pushed the v2_separate_request_response_payload_logs branch from e75d159 to 9f260f9 Compare August 7, 2021 07:29
Copy link
Collaborator

@bwplotka bwplotka left a comment

Choose a reason for hiding this comment

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

Thanks!

@bwplotka bwplotka merged commit 274df59 into grpc-ecosystem:v2 Aug 7, 2021
Milestone v2 automation moved this from In progress to Done Aug 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

For Payload Logging Interceptors, consider allowing deciding on both request and response
5 participants