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

grpclog: refactor to move implementation to grpclog/internal #7465

Merged
merged 6 commits into from
Aug 14, 2024

Conversation

easwars
Copy link
Contributor

@easwars easwars commented Jul 31, 2024

Idea behind the refactor:

  • Public API for logging should be provided by the grpclog package
  • Implementation should mostly reside in grpclog/internal package
  • Any functionality that is not exposed externally, but is available to grpc packages should be in internal/grpclog
  • Package grpclog will take a dependency on grpclog/internal
  • Package internal/grpclog will take a dependency on grpclog

Also introduces a few methods for depth logging to the external grpclog package.

RELEASE NOTES: none

@easwars easwars added the Type: Internal Cleanup Refactors, etc label Jul 31, 2024
@easwars easwars added this to the 1.66 Release milestone Jul 31, 2024
@easwars
Copy link
Contributor Author

easwars commented Jul 31, 2024

Things that I'm not thrilled about with this PR:

  • Because grpclog.Logger, grpclog.LoggerV2 and grpclog.DepthLoggerV2 are now type aliases pointing to interfaces defined in the grpclog/internal package, there is one more level of clicking required to look at these interfaces from the godoc.
    • But I feel this is still OK since it improves the overall code organization and eliminates duplicated interfaces (which was also previously missing a method)
  • The implementation of the component logger is still in the grpclog package.
    • This can be moved over to grpclog/internal if we really want to, but will require exporting the componentData type because there is a type assertion for this in grpclog.SetLoggerV2

Copy link

codecov bot commented Jul 31, 2024

Codecov Report

Attention: Patch coverage is 53.17460% with 59 lines in your changes missing coverage. Please review.

Project coverage is 81.97%. Comparing base (6d7f07c) to head (f0ab028).
Report is 2 commits behind head on master.

Files Patch % Lines
grpclog/internal/loggerv2.go 52.00% 23 Missing and 1 partial ⚠️
grpclog/internal/logger.go 0.00% 20 Missing ⚠️
grpclog/grpclog.go 70.27% 9 Missing and 2 partials ⚠️
grpclog/loggerv2.go 71.42% 2 Missing ⚠️
grpclog/logger.go 0.00% 1 Missing ⚠️
internal/grpclog/prefix_logger.go 85.71% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7465      +/-   ##
==========================================
+ Coverage   81.61%   81.97%   +0.35%     
==========================================
  Files         359      360       +1     
  Lines       27532    27533       +1     
==========================================
+ Hits        22470    22569      +99     
+ Misses       3835     3778      -57     
+ Partials     1227     1186      -41     
Files Coverage Δ
grpclog/component.go 77.27% <100.00%> (ø)
grpclog/logger.go 0.00% <0.00%> (ø)
internal/grpclog/prefix_logger.go 95.83% <85.71%> (ø)
grpclog/loggerv2.go 60.00% <71.42%> (+2.50%) ⬆️
grpclog/grpclog.go 65.51% <70.27%> (+6.05%) ⬆️
grpclog/internal/logger.go 0.00% <0.00%> (ø)
grpclog/internal/loggerv2.go 52.00% <52.00%> (ø)

... and 26 files with indirect coverage changes

Copy link
Member

@arvindbr8 arvindbr8 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 nits

Comment on lines 21 to 23
import (
"google.golang.org/grpc/grpclog/internal"
)
Copy link
Member

Choose a reason for hiding this comment

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

nit:

Suggested change
import (
"google.golang.org/grpc/grpclog/internal"
)
import "google.golang.org/grpc/grpclog/internal"

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.

scripts/vet.sh Outdated
@@ -148,6 +148,7 @@ Target is deprecated: Use the Target field in the BuildOptions instead.
UpdateAddresses is deprecated:
UpdateSubConnState is deprecated:
balancer.ErrTransientFailure is deprecated:
internal.Logger is deprecated:
Copy link
Member

Choose a reason for hiding this comment

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

Can we do something that is specific to that one usage? example: https://github.com/grpc/grpc-go/blob/master/scripts/vet.sh#L125

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. But I also had to leave the current line in there.

  • New check with fail if there are any usages of the deprecated Logger interface from anywhere other than prefix_logger.go.
  • Once that check passes, this will ensure that the usage in prefix_logger.go does not cause vet to fail.

Comment on lines 70 to 73
if pl == nil {
return true
}
return pl.logger.V(l)
Copy link
Member

Choose a reason for hiding this comment

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

nit: to stick to the other patterns how about?

Suggested change
if pl == nil {
return true
}
return pl.logger.V(l)
if pl != nil {
return pl.logger.V(l)
}
return true

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.

@arvindbr8 arvindbr8 assigned easwars and unassigned arvindbr8 Aug 13, 2024
@easwars easwars merged commit c98235b into grpc:master Aug 14, 2024
13 checks passed
@easwars easwars deleted the grpclog_refactor branch August 14, 2024 23:54
infovivek2020 pushed a commit to infovivek2020/grpc-go that referenced this pull request Aug 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants