Skip to content

Improve log fields#245

Merged
carlosms merged 8 commits intosrc-d:masterfrom
carlosms:improve-logs
Sep 13, 2018
Merged

Improve log fields#245
carlosms merged 8 commits intosrc-d:masterfrom
carlosms:improve-logs

Conversation

@carlosms
Copy link
Copy Markdown
Contributor

Fix #181.

The main change in this PR is that the callbacks with EventHandler accept the context, and keep the log fields like the PR number.

The service/git methods now get the log from the context, but the problem here is that the gRPC requests come from the analyzer, and we don't have the event-id or any other field.
I didn't look much into it, so I don't know if there is a way to pass some ID fields to the analyzer and get them back when they call GetFiles/GetChanges without modifying the proto messages.

Signed-off-by: Carlos Martín <carlos.martin.sanchez@gmail.com>
Signed-off-by: Carlos Martín <carlos.martin.sanchez@gmail.com>
Signed-off-by: Carlos Martín <carlos.martin.sanchez@gmail.com>
Signed-off-by: Carlos Martín <carlos.martin.sanchez@gmail.com>
Signed-off-by: Carlos Martín <carlos.martin.sanchez@gmail.com>
Signed-off-by: Carlos Martín <carlos.martin.sanchez@gmail.com>
Signed-off-by: Carlos Martín <carlos.martin.sanchez@gmail.com>
Signed-off-by: Carlos Martín <carlos.martin.sanchez@gmail.com>
}

log.Debugf("the DB version is up to date, %v", dbVersion)
log.With(log.Fields{"db-version": dbVersion}).Debugf("the DB version is up to date")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

line is 85 characters (lll)

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


// NewClient creates new Client
func NewClient(t http.RoundTripper, cache *cache.ValidableCache, l log.Logger, watchMinInterval string) *Client {
func NewClient(t http.RoundTripper, cache *cache.ValidableCache, watchMinInterval string) *Client {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

line is 99 characters (lll)

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

t.rateMu.Unlock()

t.Log.With(logFields).Debugf("http request to %s", req.URL.Path)
ctxlog.Get(req.Context()).With(logFields).Debugf("http request to %s", req.URL.Path)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

line is 85 characters (lll)

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


w := s.newWatcher([]string{"github.com/mock/test"})
err := w.Watch(context.TODO(), func(e lookout.Event) error {
err := w.Watch(context.TODO(), func(ctx context.Context, e lookout.Event) error {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

line is 82 characters (lll)

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


w := s.newWatcher([]string{"github.com/mock/test"})
err := w.Watch(context.TODO(), func(e lookout.Event) error {
err := w.Watch(context.TODO(), func(ctx context.Context, e lookout.Event) error {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

line is 82 characters (lll)

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

// Validation of the reference name is optional.
func validateReferences(validateRefName bool, refs ...*lookout.ReferencePointer) error {
log.Infof("validating refs: %v, validateRefName: %v", refs, validateRefName)
func validateReferences(ctx context.Context, validateRefName bool, refs ...*lookout.ReferencePointer) error {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

line is 109 characters (lll)

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

func validateReferences(validateRefName bool, refs ...*lookout.ReferencePointer) error {
log.Infof("validating refs: %v, validateRefName: %v", refs, validateRefName)
func validateReferences(ctx context.Context, validateRefName bool, refs ...*lookout.ReferencePointer) error {
ctxlog.Get(ctx).Infof("validating refs: %v, validateRefName: %v", refs, validateRefName)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

line is 89 characters (lll)

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

if "" == rp.ReferenceName {
rs = config.RefSpec(fmt.Sprintf(config.DefaultFetchRefSpec, defaultRemoteName))
log.Warningf("empty ReferenceName given in %v, using default '%s' instead", rp, rs)
ctxlog.Get(ctx).Warningf("empty ReferenceName given in %v, using default '%s' instead", rp, rs)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

line is 98 characters (lll)

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


w := s.newWatcher([]string{"github.com/mock/test"})
err := w.Watch(context.TODO(), func(e lookout.Event) error {
err := w.Watch(context.TODO(), func(ctx context.Context, e lookout.Event) error {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

duplicate of /tmp/gometalint392739599/provider___.github.___watcher_test.go:153-158 (dupl)

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


w := s.newWatcher([]string{"github.com/mock/test"})
err := w.Watch(context.TODO(), func(e lookout.Event) error {
err := w.Watch(context.TODO(), func(ctx context.Context, e lookout.Event) error {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

duplicate of /tmp/gometalint392739599/provider___.github.___watcher_test.go:136-141 (dupl)

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

@src-d src-d deleted a comment from lookout-bot Sep 13, 2018
Copy link
Copy Markdown
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.

👏

@smacker
Copy link
Copy Markdown
Contributor

smacker commented Sep 13, 2018

The service/git methods now get the log from the context, but the problem here is that the gRPC requests come from the analyzer, and we don't have the event-id or any other field.
I didn't look much into it, so I don't know if there is a way to pass some ID fields to the analyzer and get them back when they call GetFiles/GetChanges without modifying the proto messages.

Grpc allows to send metadata in header or trailer. There are some helpers in go-grpc-middleware for that.
We can include it in our sdk later to pass event-id to an analyzer and send it back.

@carlosms
Copy link
Copy Markdown
Contributor Author

That's great. I created an issue with your suggestion so we don't forget about it: #248

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.

3 participants