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

[Merged by Bors] - Use ctxzap in GRPC services #4816

Closed
wants to merge 9 commits into from

Conversation

poszu
Copy link
Contributor

@poszu poszu commented Aug 11, 2023

Motivation

The start of GRPC calls was manually logged. It can be automated and enriched with contextual information about the GRPC connection using middleware. We already use Zap's UnaryServerInterceptor that appends a logger into the Context of a GRPC call. It can be later extracted with ctxzap.

Changes

  • log start of GRPC call with middleware
  • use context-aware logging in GRPC services with ctxzap
  • give time to send a response on AdminService/Recover before shutting down
  • shutdown with os.Exit instead of panic on /Recover

Test Plan

  • existing tests pass
  • added test for AdminService/Recover

- log start of GRPC call with middleware
- use context-aware logging in GRPC services with ctxzap
- give time to send response on AdminService/Recover before shutting
down
- shutdown with os.Exit instead of panic on /Recover
@codecov
Copy link

codecov bot commented Aug 11, 2023

Codecov Report

Merging #4816 (ce3c3dd) into develop (403f8c4) will decrease coverage by 0.1%.
The diff coverage is 50.0%.

@@            Coverage Diff            @@
##           develop   #4816     +/-   ##
=========================================
- Coverage     76.9%   76.8%   -0.1%     
=========================================
  Files          261     261             
  Lines        30259   30215     -44     
=========================================
- Hits         23274   23212     -62     
- Misses        5485    5501     +16     
- Partials      1500    1502      +2     
Files Changed Coverage Δ
common/types/activation.go 56.7% <0.0%> (-1.3%) ⬇️
api/grpcserver/transaction_service.go 60.5% <25.0%> (-0.2%) ⬇️
api/grpcserver/mesh_service.go 75.7% <30.7%> (-1.2%) ⬇️
api/grpcserver/node_service.go 65.7% <33.3%> (-2.2%) ⬇️
api/grpcserver/admin_service.go 65.1% <40.0%> (-1.5%) ⬇️
api/grpcserver/smesher_service.go 74.7% <40.0%> (-2.1%) ⬇️
api/grpcserver/activation_service.go 77.3% <44.4%> (-2.3%) ⬇️
api/grpcserver/globalstate_service.go 69.3% <52.3%> (-0.8%) ⬇️
api/grpcserver/debug_service.go 73.9% <100.0%> (-0.8%) ⬇️
log/zap.go 76.3% <100.0%> (+0.1%) ⬆️
... and 1 more

... and 6 files with indirect coverage changes

api/grpcserver/admin_service.go Outdated Show resolved Hide resolved
node/node.go Outdated Show resolved Hide resolved
api/grpcserver/transaction_service.go Show resolved Hide resolved
api/grpcserver/transaction_service.go Show resolved Hide resolved
api/grpcserver/mesh_service.go Outdated Show resolved Hide resolved
api/grpcserver/mesh_service.go Outdated Show resolved Hide resolved
@poszu
Copy link
Contributor Author

poszu commented Aug 17, 2023

@fasmat is there anything else you require changes for? Regarding Zap() func, I tried different approaches but everything is worse. I think it's fine to have it in the transition period (as we discussed offline). Wdyt?

Copy link
Member

@fasmat fasmat left a comment

Choose a reason for hiding this comment

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

For now it's probably OK. There is already an issue in the backlog regarding removing the global logger: #4751

Maybe we can update that issue to completely remove the log package?

@poszu
Copy link
Contributor Author

poszu commented Aug 17, 2023

bors merge

bors bot pushed a commit that referenced this pull request Aug 17, 2023
## Motivation
The start of GRPC calls was manually logged. It can be automated and enriched with contextual information about the GRPC connection using middleware. We already use Zap's [UnaryServerInterceptor](https://pkg.go.dev/github.com/grpc-ecosystem/go-grpc-middleware@v1.4.0/logging/zap#UnaryServerInterceptor) that appends a logger into the `Context` of a GRPC call. It can be later extracted with [ctxzap](https://pkg.go.dev/github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap).

## Changes
- log start of GRPC call with middleware
- use context-aware logging in GRPC services with ctxzap
- give time to send a response on AdminService/Recover before shutting down
- shutdown with os.Exit instead of panic on /Recover

## Test Plan
- existing tests pass
- added test for AdminService/Recover
@bors
Copy link

bors bot commented Aug 17, 2023

Build failed:

@poszu
Copy link
Contributor Author

poszu commented Aug 18, 2023

bors merge

bors bot pushed a commit that referenced this pull request Aug 18, 2023
## Motivation
The start of GRPC calls was manually logged. It can be automated and enriched with contextual information about the GRPC connection using middleware. We already use Zap's [UnaryServerInterceptor](https://pkg.go.dev/github.com/grpc-ecosystem/go-grpc-middleware@v1.4.0/logging/zap#UnaryServerInterceptor) that appends a logger into the `Context` of a GRPC call. It can be later extracted with [ctxzap](https://pkg.go.dev/github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap).

## Changes
- log start of GRPC call with middleware
- use context-aware logging in GRPC services with ctxzap
- give time to send a response on AdminService/Recover before shutting down
- shutdown with os.Exit instead of panic on /Recover

## Test Plan
- existing tests pass
- added test for AdminService/Recover
@bors
Copy link

bors bot commented Aug 18, 2023

Build failed:

@poszu
Copy link
Contributor Author

poszu commented Aug 18, 2023

bors try

bors bot added a commit that referenced this pull request Aug 18, 2023
@poszu
Copy link
Contributor Author

poszu commented Aug 18, 2023

@countvonzero could you please check my changes around recovery? I changed it to quit asynchronously after 1 second to give time to send a GRPC response. Do you see any potential problems with it?

@bors
Copy link

bors bot commented Aug 18, 2023

try

Build failed:

@poszu
Copy link
Contributor Author

poszu commented Aug 18, 2023

bors try

bors bot added a commit that referenced this pull request Aug 18, 2023
@bors
Copy link

bors bot commented Aug 18, 2023

try

Build failed:

@countvonzero
Copy link
Contributor

@countvonzero could you please check my changes around recovery? I changed it to quit asynchronously after 1 second to give time to send a GRPC response. Do you see any potential problems with it?

thanks for double-checking. there is no problem with Recover() RPC. it's also only used for systest.

@poszu poszu force-pushed the use-middleware-to-log-grpc-start branch from dd39156 to c7100ec Compare August 21, 2023 15:33
@poszu poszu force-pushed the use-middleware-to-log-grpc-start branch from 15a89e2 to ce3c3dd Compare August 21, 2023 21:21
@poszu
Copy link
Contributor Author

poszu commented Aug 21, 2023

Bors merge

bors bot pushed a commit that referenced this pull request Aug 21, 2023
## Motivation
The start of GRPC calls was manually logged. It can be automated and enriched with contextual information about the GRPC connection using middleware. We already use Zap's [UnaryServerInterceptor](https://pkg.go.dev/github.com/grpc-ecosystem/go-grpc-middleware@v1.4.0/logging/zap#UnaryServerInterceptor) that appends a logger into the `Context` of a GRPC call. It can be later extracted with [ctxzap](https://pkg.go.dev/github.com/grpc-ecosystem/go-grpc-middleware/logging/zap/ctxzap).

## Changes
- log start of GRPC call with middleware
- use context-aware logging in GRPC services with ctxzap
- give time to send a response on AdminService/Recover before shutting down
- shutdown with os.Exit instead of panic on /Recover

## Test Plan
- existing tests pass
- added test for AdminService/Recover
@bors
Copy link

bors bot commented Aug 21, 2023

Pull request successfully merged into develop.

Build succeeded!

The publicly hosted instance of bors-ng is deprecated and will go away soon.

If you want to self-host your own instance, instructions are here.
For more help, visit the forum.

If you want to switch to GitHub's built-in merge queue, visit their help page.

@bors bors bot changed the title Use ctxzap in GRPC services [Merged by Bors] - Use ctxzap in GRPC services Aug 21, 2023
@bors bors bot closed this Aug 21, 2023
@bors bors bot deleted the use-middleware-to-log-grpc-start branch August 21, 2023 22:41
@poszu poszu mentioned this pull request Jul 27, 2023
3 tasks
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

3 participants