Skip to content

Update to lookout sdk 0.6.2#598

Merged
carlosms merged 2 commits intosrc-d:masterfrom
carlosms:lookout-sdk-0.6.1
Apr 3, 2019
Merged

Update to lookout sdk 0.6.2#598
carlosms merged 2 commits intosrc-d:masterfrom
carlosms:lookout-sdk-0.6.1

Conversation

@carlosms
Copy link
Copy Markdown
Contributor

Part of src-d/lookout-sdk#84

Instead of 0.6.1 this PR uses master, to include the changes from src-d/lookout-sdk#85.
I'm opening this PR to get it reviewed and see if tests pass.
We should probably release a new version of lookout-sdk, 0.6.2, and apply it here before merging.

@carlosms carlosms marked this pull request as ready for review March 22, 2019 17:39
return pb.NewServerWithInterceptors(
[]grpc.StreamServerInterceptor{
pb.LogStreamServerInterceptor(logFn),
CtxlogStreamServerInterceptor,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is already added by pb.NewServerWithInterceptors. The only difference is that in the implementation here on lookout, we pop the "app" key. Why is it done? Maybe we need to expose an api to set which keys to exclude or something like that?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

does it mean that with this code we call both CtxlogStreamServerInterceptor from sdk and from lookout?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yup, I guess that it is actually called twice, but I haven't run it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

They look similar, but both the sdk pb.Ctxlog*Interceptor and lookout Ctxlog*Interceptor are needed.

pb.CtxlogStreamClientInterceptor takes the log fields from ctx.Value(logFieldsKeyContext), but the value for logFieldsKeyContext needs to be populated first by the lookout CtxlogStreamClientInterceptor, calling pb.AddLogFields.

Similarly, pb.CtxlogStreamServerInterceptor takes the log fields and stores them into the context with the key pb.logFieldsKeyContext. This value is now accesible with pb.GetLogFields, but the rest of the lookout code assumes that the fields are accessed with the lookout ctxlog.Get() function. So the lookout CtxlogStreamServerInterceptor is needed to copy values from the sdk pb.logFieldsKeyContext to lookout ctxlog.logFieldsKey.

About removing the app key, it is a convention we use in our deployments. Each application adds a log field app=appname. This way we can filter messages easily. The interceptors here remove them to avoid having a message from an analyzer contain that app=lookoutd field.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

pb.CtxlogStreamClientInterceptor takes the log fields from ctx.Value(logFieldsKeyContext), but the value for logFieldsKeyContext needs to be populated first by the lookout CtxlogStreamClientInterceptor, calling pb.AddLogFields

But aren't you here actually reading the log fields from the same place you're adding here?

I mean ctxlog.Fields(ctx) reads from const logFieldsKey ctxKey = 0 and pb.AddLogFields is adding them in const logFieldsKeyContext ctxKey = 0.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

They are actually 2 different types, to avoid collisions. This is the recommended way to define the keys in the context docs.

I guess we could export pb.logFieldsKeyContext and use it in lookout ctxlog, and remove the extra interceptors. But then the app field would jump over to the analyzer logs...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor

@se7entyse7en se7entyse7en Apr 3, 2019

Choose a reason for hiding this comment

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

@smacker thanks for pinging.

Sorry for delaying this 😞, I forgot that this has a pending discussion.

Instead of exporting pb.logFieldsKeyContext isn't it possible to directly use the ctxlog package of lookout with the utilities in pb.context.go? By doing this we're able to put the log fields directly with the "right" key, and we can remove the extra interceptor.

For sure even if we do this right now, we won't be able to have the same behavior as we're not able to remove the app key. But if we can get rid of the ctxlog package in favor of pb.context.go, I'd then open an issue on lookout-sdk to think about a way to filter out logfields keys.

WDYT?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We can't remove ctxlog completely. We need Get(ctx context.Context) log.Logger and WithLogFields(ctx context.Context, fields log.Fields) (context.Context, log.Logger). But I agree it would be better if we could re-use sdk/pb/context.go there.

At least it worth to try and if there are some big issues that I we don't see right now, we can merge this PR as it is and create a separate issue. But on the first glance, it should be easy to update.

I also agree that app field filtering better put in sdk. It's convention we use and better to enforce it on sdk level.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

we can merge this PR as it is and create a separate issue.

Sure, I'd open a separate issue for that. I'm gonna open an issue about trying to reuse sdk/pb/context.go

I also agree that app field filtering better put in sdk. It's convention we use and better to enforce it on sdk level.

Does this convention applies to each dependant on lookout-sdk? I mean are we going on lookout-sdk to blindly remove the app field or generically provide a way to filter whatever fields a dependant would like to remove? I'm opening an issue for this too.

},
[]grpc.UnaryServerInterceptor{
pb.LogUnaryServerInterceptor(logFn),
CtxlogUnaryServerInterceptor,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This also is already added.

// DialContext creates a client connection to the given target with custom message size
// DialContext creates a client connection to the given target with custom
// options and log interceptors
func DialContext(ctx context.Context, target string, opts ...grpc.DialOption) (*grpc.ClientConn, error) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same here

Copy link
Copy Markdown
Contributor

@dpordomingo dpordomingo left a comment

Choose a reason for hiding this comment

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

LGTM
but what @se7entyse7en pointed out should be addressed too.

Gopkg.toml Outdated
version = "1.3.5"

[[constraint]]
# TODO (carlosms) change back to [[constraint]] before this is merged
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

leaving this as a reminder before merging

carlosms added 2 commits April 3, 2019 13:25
Signed-off-by: Carlos Martín <carlos.martin.sanchez@gmail.com>
Signed-off-by: Carlos Martín <carlos.martin.sanchez@gmail.com>
@carlosms carlosms force-pushed the lookout-sdk-0.6.1 branch from d2126a3 to c8a49d3 Compare April 3, 2019 12:32
@carlosms carlosms merged commit bb5d952 into src-d:master Apr 3, 2019
@carlosms carlosms deleted the lookout-sdk-0.6.1 branch April 3, 2019 12:55
@carlosms carlosms changed the title Update to lookout sdk 0.6.1 Update to lookout sdk 0.6.2 Apr 4, 2019
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.

4 participants