CARVIEW |
Navigation Menu
-
Notifications
You must be signed in to change notification settings - Fork 11
v0.6.1
Compare
New Features
This release includes the following:
Audit trail for GetChanges
and GetFiles
calls
The SDK library now provides a mechanism to keep log fields during the message exchange between lookoutd
and your analyzer.
An example of the logs fields that are kept in the message exchange would be:
{
"repository": "github.com/src-d/lookout-sdk",
"github.pr": 17
}
In practice this means that your analyzer will be able to easily add relevant information to its logs, and lookoutd
will have a context for each call you make. A sort of audit trail for each GetChanges
or GetFiles
call.
This mechanism is implemented differently in the Go SDK and in the Python SDK
Go SDK
The above mentioned mechanism is implemented by using gRPC interceptors:
pb.CtxlogUnaryClientInterceptor
,pb.CtxlogStreamClientInterceptor
,pb.CtxlogUnaryServerInterceptor
,pb.CtxlogStreamServerInterceptor
.
These interceptors are added automatically using pb.DialContext
and pb.NewServer
. There are also pb.DialContextWithInterceptors
and pb.NewServerWithInterceptors
respectively in case you want to add other interceptors. See examples/language-analyzer.go
.
In your analyzer you can then use the pb.GetLogFields
and pb.AddLogFields
to read and add log fields to the context. The log fields that you add will be available to lookoutd
.
Python SDK
The above mentioned mechanism is implemented by passing a wrapped context to each analyzer call (Notify{Review,Push}Event
), and by changing the base class of your analyzer:
- in version v0.5.0:
lookout.sdk.pb.AnalyzerServicer
->lookout.sdk.service_analyzer_pb2_grpc.AnalyzerServicer
,
in version v0.6.1:lookout.sdk.pb.AnalyzerServicer
->lookout.sdk.service_analyzer.AnalyzerServicer
.
The wrapped context is a proxy to the gRPC one. It additionally provides functionalities for adding and reading log fields that will be available to lookoutd
, once you "activate" the audit trail (see later). See lookout.sdk.grpc.log_fields.LogFieldsContext
.
This change is not a breaking change. Without updating anything the code is expected to work as before the update. In order to "activate" the audit trail you have to follow some steps. See the migration guide.
Logger interceptors
The SDK library now provides gRPC interceptors both for Go SDK and Python SDK for logging client calls and server request. See examples/language-analyzer.go
and examples/language-analyzer.py
to see how to use them.
Python SDK
An extra note must be added for the Python SDK. At time of writing gRPC for Python doesn't provide an api to add server interceptors for diffenret method types, so an api on top of that has been added to provide the user the capability to also add custom server interceptors. See lookout.sdk.grpc.interceptors.base
.
[Python SDK] Default message size for gRPC server
A new create_server
function creates a server with default values for gRPC max send and max receive message length.
Migration Guide: v0.5.0 => v0.6.1
You might want to check out the changes made to examples/language-analyzer.go
and examples/language-analyzer.py
in the comparison view.
Go SDK
Except for using pb.DialContext
and pb.NewServer
or their corresponding pb.DialContextWithInterceptors
and pb.NewServerWithInterceptors
, you don't have anything else to do in order to activate the audit trail.
Python SDK
Follow these steps to activate the audit trail.
- Rename the following:
NotifyReviewEvent
->notify_review_event
,NotifyPushEvent
->notify_push_event
.
- Use
create_server
. - Use
DataStub
imported fromlookout.sdk.service_data
and not frompb
. The returned stub has a more pythonic api. You have to rename the following calls:GetChanges
->get_changes
,GetFiles
->get_files
.
Both methods needs as first positional argument the context.