Skip to content

Improves logging message for failed analysis#442

Merged
se7entyse7en merged 7 commits intomasterfrom
better-failure-logging
Jan 4, 2019
Merged

Improves logging message for failed analysis#442
se7entyse7en merged 7 commits intomasterfrom
better-failure-logging

Conversation

@se7entyse7en
Copy link
Copy Markdown
Contributor

@se7entyse7en se7entyse7en commented Dec 31, 2018

This closes #368.

@se7entyse7en se7entyse7en force-pushed the better-failure-logging branch 2 times, most recently from c7aeb3e to e586c2c Compare December 31, 2018 15:33
@se7entyse7en
Copy link
Copy Markdown
Contributor Author

se7entyse7en commented Dec 31, 2018

UPDATE: this comments now refers to #443

This PR is composed by two commits. Actually the first one is enough to close #368. Anyway with the second commit I tried to remove some duplicated code. Let me know what do you think (as obviously I don't have the big picture 😛yet), in any case it can be easily removed and it was very helpful for studying the code in depth 👍.

One thing to note regarding the duplicated code removal is that there could be a slight worsening in performance given that switch on the event type is now done once for each analyzer https://github.com/src-d/lookout/pull/442/files#diff-91bbeda7eb98a7adc57b9e47e2cf5c2bR161.

@se7entyse7en se7entyse7en force-pushed the better-failure-logging branch 3 times, most recently from c75df77 to 744eb7c Compare December 31, 2018 18:33
@se7entyse7en se7entyse7en force-pushed the better-failure-logging branch from 932fa6e to 578836d Compare December 31, 2018 19:31
@se7entyse7en se7entyse7en force-pushed the better-failure-logging branch 2 times, most recently from 42709cb to 8b79c93 Compare January 2, 2019 10:28
@se7entyse7en se7entyse7en requested a review from a team January 2, 2019 10:45
@se7entyse7en se7entyse7en force-pushed the better-failure-logging branch from 8b79c93 to 0871118 Compare January 2, 2019 11:21
@se7entyse7en
Copy link
Copy Markdown
Contributor Author

Splitted the refactor part into a separate PR.

@se7entyse7en se7entyse7en changed the title Improves logging message for failed analysis and removes duplicated logic Improves logging message for failed analysis Jan 2, 2019
@se7entyse7en se7entyse7en force-pushed the better-failure-logging branch from 0871118 to 2958e90 Compare January 2, 2019 11:38
@dpordomingo
Copy link
Copy Markdown
Contributor

I saw some messages from lookout-staging bot.
Some of them may be addressed, and others might not. In any case, we should proceed as they were posted by a real user:

  • addressing them if possible,
  • explaining why they can not be addressed, or
  • marking them as resolved if they make no sense and no explanation is needed.

@se7entyse7en
Copy link
Copy Markdown
Contributor Author

@dpordomingo Resolved and added comments on lookout-staging's messages.

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

@se7entyse7en se7entyse7en force-pushed the better-failure-logging branch from 2958e90 to e7484c6 Compare January 2, 2019 18:17
server/server.go Outdated
errMessage = fmt.Sprintf("code: %s - message: %s", grpcStatus.Code(), grpcStatus.Message())
}

aLogger.Errorf(err, "analysis failed: %s", errMessage)
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.

aren't we repeat code&message here?

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.

Are you talking about errors without a friendly message? In that case the logged message is something like this:

msg="analysis failed: code: Unknown - message: review error" analyzer=Dummy app=lookoutd error="rpc error: code = Unknown desc = review error"

so code and message are repeated in the error object of the log context. Maybe something as follows is better?

	if err != nil {
		grpcStatus := status.Convert(err)
		errMessage := "analysis failed"
		friendlyMessage, ok := logErrorMessages[grpcStatus.Code()]
		if ok {
			errMessage = fmt.Sprintf("%s: %s", errMessage, friendlyMessage)
		}

		aLogger.Errorf(err, errMessage)
		...
	}

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.

Yep. It makes more sense for me.

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.

Addressed here.


func TestErrorAnalyzerIntegrationSuite(t *testing.T) {
suite.Run(t, new(ErrorAnalyzerIntegrationSuite))
suite.Run(t, &ErrorAnalyzerIntegrationSuite{
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.

Usually Test...Suite is just a wrapper for one stretchr/testify suite. With these two suite.Run inside the same test we get:

go test -v -parallel 1 -tags='integration' github.com/src-d/lookout/cmd/server-test -run TestErrorAnalyzerIntegrationSuite/TestAnalyzerErr

=== RUN   TestErrorAnalyzerIntegrationSuite
=== RUN   TestErrorAnalyzerIntegrationSuite/TestAnalyzerErr
=== RUN   TestErrorAnalyzerIntegrationSuite/TestAnalyzerErr#01
--- PASS: TestErrorAnalyzerIntegrationSuite (15.60s)
    --- PASS: TestErrorAnalyzerIntegrationSuite/TestAnalyzerErr (8.33s)
    --- PASS: TestErrorAnalyzerIntegrationSuite/TestAnalyzerErr#01 (7.26s)

If one of the suites fails, it's hard to know which one is it. Also, it's hard to run only one of them, since they are bundled togueter.

Since you made a different mock analyzer for the timeout error, you could have two Test...Suite, probably in a different file, e.g. timeout_analyzer_test.go. startAnalyzer could be moved to common_test.go, maybe renaming it to startMockAnalyzer to avoid confusion.

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.

Addressed here

server/server.go Outdated

var grpcErrorMessages = map[lookout.EventType]map[codes.Code]string{
pb.PushEventType: map[codes.Code]string{
codes.DeadlineExceeded: "timeout exceeded, try increasing analyzerPushTimeout",
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.

analyzerPushTimeout is an internal name that will not be familiar to a user. Let's change this instead to

Suggested change
codes.DeadlineExceeded: "timeout exceeded, try increasing analyzerPushTimeout",
codes.DeadlineExceeded: "timeout exceeded, try increasing analyzer_push in config.yml",

Same for the other message below.

Copy link
Copy Markdown
Contributor Author

@se7entyse7en se7entyse7en Jan 4, 2019

Choose a reason for hiding this comment

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

Addressed here.

Signed-off-by: Lou Marvin Caraig <loumarvincaraig@gmail.com>
Signed-off-by: Lou Marvin Caraig <loumarvincaraig@gmail.com>
Signed-off-by: Lou Marvin Caraig <loumarvincaraig@gmail.com>
Signed-off-by: Lou Marvin Caraig <loumarvincaraig@gmail.com>
Signed-off-by: Lou Marvin Caraig <loumarvincaraig@gmail.com>
Signed-off-by: Lou Marvin Caraig <loumarvincaraig@gmail.com>
@se7entyse7en se7entyse7en force-pushed the better-failure-logging branch from 838465a to 091605f Compare January 4, 2019 14:41

func TestErrorAnalyzerIntegrationSuite(t *testing.T) {
suite.Run(t, new(ErrorAnalyzerIntegrationSuite))
suite.Run(t, &ErrorAnalyzerIntegrationSuite{
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.

Now that ErrorAnalyzerIntegrationSuite and TimeoutErrorAnalyzerIntegrationSuite are different types maybe we could revert the changes for the new fields (configFile, analyzer, errMessage), and call suite.Run(t, new(ErrorAnalyzerIntegrationSuite)) here.

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.

Addressed here.

…yzerIntegrationSuite

Signed-off-by: Lou Marvin Caraig <loumarvincaraig@gmail.com>
Copy link
Copy Markdown
Contributor

@carlosms carlosms left a comment

Choose a reason for hiding this comment

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

👏

@se7entyse7en
Copy link
Copy Markdown
Contributor Author

se7entyse7en commented Jan 4, 2019

I'm gonna rebase to master and squash some commits before merging 🎉.

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.

👍

@se7entyse7en se7entyse7en merged commit 7501ce9 into master Jan 4, 2019
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.

too late, but there in case you want to address it in a separated PR

suite.sendEvent(successJSON)

suite.GrepTrue(suite.r, suite.errMessage)
suite.GrepTrue(suite.r, `msg="analysis failed: timeout exceeded, try increasing analyzer_review in config.yml" analyzer=Dummy app=lookoutd error="rpc error: code = DeadlineExceeded desc = context deadline exceeded"`)
Copy link
Copy Markdown
Contributor

@dpordomingo dpordomingo Jan 8, 2019

Choose a reason for hiding this comment

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

@carlosms @se7entyse7en The config file could be a different file if passed with --config=; I'd purpose /config.yml/the config file/s, or similar, to cover those cases.

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.

[improvement] better logging

4 participants