Skip to content
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

test: Log input to json.Unmarshal when it fails #16099

Merged
merged 1 commit into from May 17, 2021

Conversation

pchaigno
Copy link
Member

json.Unmarshal sometimes fails to parse its input. We should log the input in such cases to figure out what happened. This is currently causing a test to (rarely) flake (cf. #16088).

@pchaigno pchaigno added area/CI-improvement Topic or proposal to improve the Continuous Integration workflow release-note/ci This PR makes changes to the CI. labels May 11, 2021
@pchaigno pchaigno requested a review from a team as a code owner May 11, 2021 22:06
@pchaigno pchaigno requested a review from christarazi May 11, 2021 22:06
test/helpers/cmd.go Outdated Show resolved Hide resolved
@pchaigno pchaigno force-pushed the log-non-json-input-for-flake branch from 2632ef5 to 742f3dd Compare May 12, 2021 08:17
@@ -85,7 +85,7 @@ func (b *CmdStreamBuffer) Filter(filter string) (*FilterBuffer, error) {

err := json.Unmarshal(b.Bytes(), &data)
if err != nil {
return nil, fmt.Errorf("could not parse JSON from command %q", b.Cmd())
return nil, fmt.Errorf("could not parse JSON from command %q\n%s\n%s", b.Cmd(), err, b.Bytes())
Copy link
Member

Choose a reason for hiding this comment

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

Sorry one more nit, %w for errors

Copy link
Member Author

Choose a reason for hiding this comment

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

That doesn't seem consistent across the codebase. We're using %s, %v, and %w according to git grep -P "fmt.Errorf.*, err". https://github.com/golang/go/wiki/CodeReviewComments also points to %v.

I'm happy to change but not sure to understand the logic. I also don't think it will scale if we rely solely on reviews to catch this.

Copy link
Member

Choose a reason for hiding this comment

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

@pchaigno It's relatively new and it seems like the code review doc hasn't been updated for it :/

Unfortunately, yes there's inconsistency in the codebase as it sometimes slips by. In this case, consistency is not better--we should just use the correct format specifier when we can :)

Doubly unfortunate in terms of enforcement, we have gone back and forth on this. We used to have some linter that would look at these things, but we removed it because it was too noisy with unhelpful suggestions. @sayboras Do you know if our GH Actions Go linter can pick this up?

json.Unmarshal sometimes fails to parse its input. We should log the
input in such cases to figure out what happened. This is currently
causing a test to (rarely) flake.

Signed-off-by: Paul Chaignon <paul@cilium.io>
@pchaigno pchaigno force-pushed the log-non-json-input-for-flake branch from 742f3dd to b929023 Compare May 12, 2021 18:53
@pchaigno pchaigno requested a review from christarazi May 12, 2021 18:53
@pchaigno
Copy link
Member Author

test-me-please

@pchaigno
Copy link
Member Author

k8s-1.20-kernel-4.19 failed due to #16154. Other failing tests are not required and not affected by these changes anyway. Reviews are in. Marking as ready to merge.

@pchaigno pchaigno added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label May 14, 2021
@tklauser tklauser merged commit 80fbcac into cilium:master May 17, 2021
@pchaigno pchaigno deleted the log-non-json-input-for-flake branch May 17, 2021 10:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/CI-improvement Topic or proposal to improve the Continuous Integration workflow ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-note/ci This PR makes changes to the CI.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants