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

Add log fields metadata to gRPC calls #359

Merged
merged 3 commits into from
Jan 25, 2019
Merged

Conversation

carlosms
Copy link
Contributor

@carlosms carlosms commented Nov 19, 2018

WIP because it needs support from go-log, src-d/go-log#9. But I'd like to get feedback.

Fix #248.

The changes in this PR depend on fixing #357 to be really useful. But the issues are independent, the other bug can be fixed after this one is merged. In the examples below you can see the analyzer and event-id fields.

Changes in this PR include:

Improvements to already existing interceptors. Now they use a log from context, instead of the default one.
Before

[2018-11-19T11:09:35.061228511Z]  INFO unary client call started app=lookoutd grpc.method=NotifyReviewEvent grpc.service=pb.Analyzer span.kind=client system=grpc

After:

[2018-11-19T11:08:17.043544201Z]  INFO gRPC unary client call started analyzer=Dummy app=lookoutd event-id=47428977cec7253cc30466a12eee386de46f7306 event-type=*pb.ReviewEvent grpc.method=NotifyReviewEvent grpc.service=pb.Analyzer head=refs/pull/1/head provider=github repo=https://github.com/src-d/lookout-test-fixtures.git span.kind=client system=grpc

.
New interceptors to pass log fields in the gRPC metadata, encoded as JSON. Using these interceptors the logs fields go from lookoutd -> analyzer as client/server, but also from analyzer -> lookoutd.
Before:

[2018-11-19T11:23:46.423025958Z]  INFO gRPC streaming server call started app=lookoutd grpc.method=GetChanges grpc.service=pb.Data span.kind=server system=grpc
[2018-11-19T11:23:46.423263865Z]  INFO validating refs: [internal_repository_url:"https://github.com/src-d/lookout-test-fixtures.git" reference_name:"refs/heads/master" hash:"6a92946068897d0a6f6ffa6457f889163dcc51b5"  internal_repository_url:"https://github.com/src-d/lookout-test-fixtures.git" reference_name:"refs/pull/3/head" hash:"6221d2fe0bc2148debfa8d3c8c92b8c15451920d" ], validateRefName: true app=lookoutd
[2018-11-19T11:23:46.423559138Z]  INFO fetching references for repository https://github.com/src-d/lookout-test-fixtures.git: [refs/heads/master:refs/heads/master refs/pull/3/head:refs/pull/3/head] app=lookoutd
[2018-11-19T11:23:46.822346422Z]  INFO gRPC streaming server call finished app=lookoutd duration=399.322434ms grpc.code=OK grpc.method=GetChanges grpc.service=pb.Data grpc.start_time=2018-11-19T11:23:46Z span.kind=server system=grpc

After:

[2018-11-19T11:21:38.402117594Z]  INFO gRPC streaming server call started analyzer=Dummy app=lookoutd event-id=47428977cec7253cc30466a12eee386de46f7306 event-type=map[] grpc.method=GetChanges grpc.service=pb.Data head=refs/pull/1/head provider=github repo=https://github.com/src-d/lookout-test-fixtures.git span.kind=server system=grpc
[2018-11-19T11:21:38.402355891Z]  INFO validating refs: [internal_repository_url:"https://github.com/src-d/lookout-test-fixtures.git" reference_name:"refs/heads/i197-base" hash:"fa8a63d8ed4ceee82f40273090c28e31576dafda"  internal_repository_url:"https://github.com/src-d/lookout-test-fixtures.git" reference_name:"refs/pull/1/head" hash:"5fe468b62112e69bae390051e990271f7b1cc294" ], validateRefName: true analyzer=Dummy app=lookoutd event-id=47428977cec7253cc30466a12eee386de46f7306 event-type=map[] head=refs/pull/1/head provider=github repo=https://github.com/src-d/lookout-test-fixtures.git
[2018-11-19T11:21:38.402707005Z]  INFO fetching references for repository https://github.com/src-d/lookout-test-fixtures.git: [refs/heads/i197-base:refs/heads/i197-base refs/pull/1/head:refs/pull/1/head] analyzer=Dummy app=lookoutd event-id=47428977cec7253cc30466a12eee386de46f7306 event-type=map[] head=refs/pull/1/head provider=github repo=https://github.com/src-d/lookout-test-fixtures.git
[2018-11-19T11:21:39.024092952Z]  INFO gRPC streaming server call finished analyzer=Dummy app=lookoutd duration=621.987351ms event-id=47428977cec7253cc30466a12eee386de46f7306 event-type=map[] grpc.code=OK grpc.method=GetChanges grpc.service=pb.Data grpc.start_time=2018-11-19T11:21:38Z head=refs/pull/1/head provider=github repo=https://github.com/src-d/lookout-test-fixtures.git span.kind=server system=grpc

If an analyzer does not use the interceptors the log fields are not passed around, but it will not cause any problems. Since the metadata is JSON, it should be easy to add this functionality to the python SDK.

util/grpchelper/logfields.go Show resolved Hide resolved
util/grpchelper/logfields.go Show resolved Hide resolved
util/grpchelper/logfields.go Show resolved Hide resolved
util/grpchelper/logfields.go Show resolved Hide resolved

return clientStream, err
}
}

func newServerRequestLogger(l log.Logger, fullMethod string) log.Logger {
func newServerRequestLogger(ctx context.Context, fullMethod string) log.Logger {

Choose a reason for hiding this comment

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

duplicate of util/grpchelper/logger.go:104-115 (dupl)

If you have feedback about this comment, please, tell us.

}

func newClientRequestLogger(l log.Logger, fullMethod string) log.Logger {
func newClientRequestLogger(ctx context.Context, fullMethod string) log.Logger {

Choose a reason for hiding this comment

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

duplicate of util/grpchelper/logger.go:91-102 (dupl)

If you have feedback about this comment, please, tell us.

@@ -0,0 +1,90 @@
package grpchelper

Choose a reason for hiding this comment

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

file is not goimported (goimports)

If you have feedback about this comment, please, tell us.

@carlosms carlosms changed the title [WIP] Add log fields metadata to gRPC calls Add log fields metadata to gRPC calls Nov 20, 2018
Copy link
Contributor

@smacker smacker left a comment

Choose a reason for hiding this comment

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

👍 we will need that new method in go-log for #357 too

@smacker
Copy link
Contributor

smacker commented Nov 20, 2018

I just noticed that CI is green even without Fields{}. Maybe we should add test?

@carlosms
Copy link
Contributor Author

Yes, I was thinking I would wait for support in go-log. And then add some new greps to dummy_analyzer_test.go and multi_analyzer_test.go looking for log lines with grpc.method=GetChanges including the new log fields.

cmd/server-test/dummy_analyzer_test.go Show resolved Hide resolved
util/grpchelper/logfields.go Show resolved Hide resolved
util/grpchelper/logfields.go Show resolved Hide resolved
@carlosms
Copy link
Contributor Author

Pushed new commits on top of #375, with tests.

We still need to decide if we want to keep the log fields in the metadata, or as grpc fields. But at least this branch is now up to date and ready to be merged, or be adapted.

@mcuadros
Copy link
Contributor

Sorry for delaying this, you can do as you want, my only concert was not passing an instance of a logger in a context.

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.

Add ID metadata to gRPC calls, and use it in logs
4 participants