Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
grpc_logsettable contains a thread-safe wrapper around grpc-logging infrastructure.
Go-grpc library assumes that logger can be only configured once as the
SetLoggerV2
method is:Not mutex-protected, should be called before any gRPC functions.
This provided package allows to supply parent logger once ("before any grpc"), but after change underlying implementation in thread-safe way when needed.
It's in particular useful for testing, where each testcase might need its own logger.
settable_test.go shows e2e usage of the enhanced infrastructure.
Case study:
In etcd we found it challenging to properly configure grpc logging in scope of the test framework.
When test fails we want to get all relevant logs from the test-case alone.
ZAP allows to wrap testing.T with zapttest.Logger. This needs to happen in each test-case.
When we try to use that zap-logger as grpc logger, we observe following RACEs:
The fact that server is property shutdown (GracefulStop + Stop), does not mitigate the reality that there is no synchronization between the connection goroutines and the next test-case start in terms of 'logger' memory.
The supplied implementation allows to configure it 'properly', on the cost of additional layer of indirection in the tests only.