Add option for exhaustive gitserver logging#61270
Conversation
commit-id:92fb433c
mmanela
left a comment
There was a problem hiding this comment.
Looks good, but I have one question and comment
9adc726 to
b6788a9
Compare
a23f5c3 to
85a61a4
Compare
85a61a4 to
56c4813
Compare
2c33079 to
8604dd8
Compare
89adce0 to
86d0d41
Compare
eseliger
left a comment
There was a problem hiding this comment.
This seems like a useful tool for emergency cases where we have no further way to debug what's happening, nice 👍
I'm not sure how I feel yet about how verbose with a limited number of methods this already is (810loc for the logger alone, yet-another-location-to-not-forget-to-update-when-adding-an-endpoint).
If we could make this a bit more transparent I think that would be nice, and largely reusable for all our gRPC services. Using an interceptor I believe we can get duration, error, status code, and traceID generically. For the request fields, we might be able to use a similar approach I used in the transparent proxy where we could use reflection to get field names and use an annotation to mark things as PII.
But that's not a blocker for getting us a debugging tool earlier, so approved.
Left a few small suggestions inline.
| # visibility = ["//cmd/gitserver:__subpackages__"], | ||
| visibility = ["//visibility:public"], |
There was a problem hiding this comment.
This wasn't intentional. Just the result of running sg bazel configure
| # Test requires localhost database | ||
| "requires-network", |
There was a problem hiding this comment.
have we actually gotten rid of all the DB stuff in here? That'd be real nice
There was a problem hiding this comment.
This wasn't intentional. Just the result of running sg bazel configure
| "github.com/sourcegraph/sourcegraph/lib/pointers" | ||
| ) | ||
|
|
||
| var envGitserverExhaustiveLoggingEnabled = env.MustGetBool("SRC_GITSERVER_EXHAUSTIVE_LOGGING_ENABLED", false, "enable exhaustive request logging in gitserver") |
There was a problem hiding this comment.
can we move this to the cmd/gitserver/shared/config.go file? https://sourcegraph.sourcegraph.com/-/editor?remote_url=github.com%2Fsourcegraph%2Fsourcegraph&branch=main&file=cmd%2Fgitserver%2Fshared%2Fconfig.go&editor=VSCode&version=2.2.16&start_row=18&start_col=0&end_row=18&end_col=0
| start := time.Now() | ||
|
|
||
| defer func() { | ||
| elapsed := time.Since(start) | ||
|
|
||
| l.doLog( | ||
| proto.GitserverService_ResolveRevision_FullMethodName, | ||
| status.Code(err), | ||
| trace.Context(ctx).TraceID, | ||
| elapsed, | ||
|
|
||
| resolveRevisionRequestToLogFields(request)..., | ||
| ) | ||
|
|
||
| }() |
There was a problem hiding this comment.
After having read through a lot of these now, they are all very similar and it's kind of repetitive, I wonder if we could make this a little less verbose bu doing something like
func (l *loggingGRPCServer) ResolveRevision(ctx context.Context, request *proto.ResolveRevisionRequest) (response *proto.ResolveRevisionResponse, err error) {
collector := l.logCollect(ctx, proto.GitserverService_ResolveRevision_FullMethodName, &err)
defer collector(resolveRevisionRequestToLogFields(request))
}
The duration tracking, status code from err, and traceID from ctx seem to always be the same.
8ba9ca4 to
56f5502
Compare
3745840 to
a52ab8c
Compare
edf47f9 to
f34693b
Compare
df66498 to
16c1963
Compare
) This PR builds on https://github.com/sourcegraph/sourcegraph/pull/61270, and adds the request logging funcionality to the repository grpc server in gitserver. ## Test plan Local testing: Ran `env SRC_GITSERVER_EXHAUSTIVE_LOGGING_ENABLED=true SRC_LOG_SCOPE_LEVEL=gitserver.gRPCRequestLogger=debug sg start` locally, and saw the following output from the logger in my terminal (note that specifically the repository service is mentioned): ``` [ gitserver-0] DEBUG gitserver.gRPCRequestLogger internal/server_grpc_logger.go:46 Handled FetchRepository RPC {"server": "gitserver.v1.GitserverRepositoryService", "method": "FetchRepository", "status": "OK", "traceID": "67f1aa837367fa7ea72b164e70a67419", "duration": "1.068438833s", "request": {"repoName": "github.com/sgtest/megarepo"}} ```
Closes https://github.com/sourcegraph/sourcegraph/issues/62025
This PR adds exhaustive gRPC logging for gitserver when the SRC_GITSERVER_EXHAUSTIVE_LOGGING_ENABLED environment variable is set to true.
Each RPC now logs the method name, duration, status code, and request contents. (I've taken care to omit certain sensitive fields / redact where appropriate - but I'd appreciate a close review here).
Test plan
env SRC_GITSERVER_EXHAUSTIVE_LOGGING_ENABLED=true sg startand the following diff appliedI then saw the following logs: