Skip to content

Conversation

carlosms
Copy link
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>
@@ -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")

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 {

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)

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 {

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 {

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 {

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)

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)

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 {

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 {

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
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
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
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