-
Notifications
You must be signed in to change notification settings - Fork 36
Improve log fields #245
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
Improve log fields #245
Conversation
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>
@@ -371,7 +371,7 @@ func (c *ServeCommand) initDB() (*sql.DB, error) { | |||
"Use '%s migrate' to upgrade your database", dbVersion, version, build, maxVersion, name) | |||
} | |||
|
|||
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") |
There was a problem hiding this comment.
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.
@@ -50,10 +52,9 @@ type Client struct { | |||
} | |||
|
|||
// 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 { |
There was a problem hiding this comment.
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.
@@ -207,7 +207,7 @@ func (t *limitRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) | |||
t.rateLimits[category(req.URL.Path)] = rate | |||
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) |
There was a problem hiding this comment.
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.
@@ -133,7 +133,7 @@ func (s *WatcherTestSuite) TestWatch_CallbackError_Pull() { | |||
s.mux.HandleFunc("/repos/mock/test/events", emptyArrayHandler) | |||
|
|||
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 { |
There was a problem hiding this comment.
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.
@@ -150,7 +150,7 @@ func (s *WatcherTestSuite) TestWatch_CallbackError_Event() { | |||
s.mux.HandleFunc("/repos/mock/test/events", eventsHandler(&calls)) | |||
|
|||
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 { |
There was a problem hiding this comment.
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.
@@ -33,8 +32,8 @@ var ErrRefValidation = errors.NewKind("reference %v does not have a %s") | |||
|
|||
// validateReferences checks if all the References have enough information to clone a repo. | |||
// 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 { |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
@@ -53,7 +53,7 @@ func (s *Syncer) Sync(ctx context.Context, | |||
var rs config.RefSpec | |||
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) |
There was a problem hiding this comment.
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.
@@ -133,7 +133,7 @@ func (s *WatcherTestSuite) TestWatch_CallbackError_Pull() { | |||
s.mux.HandleFunc("/repos/mock/test/events", emptyArrayHandler) | |||
|
|||
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 { |
There was a problem hiding this comment.
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.
@@ -150,7 +150,7 @@ func (s *WatcherTestSuite) TestWatch_CallbackError_Event() { | |||
s.mux.HandleFunc("/repos/mock/test/events", eventsHandler(&calls)) | |||
|
|||
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏
Grpc allows to send metadata in header or trailer. There are some helpers in go-grpc-middleware for that. |
That's great. I created an issue with your suggestion so we don't forget about it: #248 |
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 theevent-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 theproto
messages.