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

Improve WaitForPos errors, don't include Result struct in message #15962

Merged
merged 3 commits into from
May 22, 2024

Conversation

rafer
Copy link
Contributor

@rafer rafer commented May 16, 2024

Description

Add more specific errors when WaitForPos receives an unexpected number of rows or columns. No longer prints the raw Result object (which isn't a particularly descriptive error for end users).

Immediate motivation is to make tests less brittle when Result object is modified (in downstream forks).

Related Issue(s)

N/A

Checklist

  • "Backport to:" labels have been added if this change should be back-ported to release branches
  • If this change is to be back-ported to previous releases, a justification is included in the PR description
  • Tests were added or are not required
  • Did the new or modified tests pass consistently locally and on CI?
  • Documentation was added or is not required

Deployment Notes

Copy link
Contributor

vitess-bot bot commented May 16, 2024

Review Checklist

Hello reviewers! 👋 Please follow this checklist when reviewing this Pull Request.

General

  • Ensure that the Pull Request has a descriptive title.
  • Ensure there is a link to an issue (except for internal cleanup and flaky test fixes), new features should have an RFC that documents use cases and test cases.

Tests

  • Bug fixes should have at least one unit or end-to-end test, enhancement and new features should have a sufficient number of tests.

Documentation

  • Apply the release notes (needs details) label if users need to know about this change.
  • New features should be documented.
  • There should be some code comments as to why things are implemented the way they are.
  • There should be a comment at the top of each new or modified test to explain what the test does.

New flags

  • Is this flag really necessary?
  • Flag names must be clear and intuitive, use dashes (-), and have a clear help text.

If a workflow is added or modified:

  • Each item in Jobs should be named in order to mark it as required.
  • If the workflow needs to be marked as required, the maintainer team must be notified.

Backward compatibility

  • Protobuf changes should be wire-compatible.
  • Changes to _vt tables and RPCs need to be backward compatible.
  • RPC changes should be compatible with vitess-operator
  • If a flag is removed, then it should also be removed from vitess-operator and arewefastyet, if used there.
  • vtctl command output order should be stable and awk-able.

@vitess-bot vitess-bot bot added NeedsBackportReason If backport labels have been applied to a PR, a justification is required NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsIssue A linked issue is missing for this Pull Request NeedsWebsiteDocsUpdate What it says labels May 16, 2024
@rafer rafer marked this pull request as draft May 16, 2024 22:27
@github-actions github-actions bot added this to the v20.0.0 milestone May 16, 2024
@rafer rafer force-pushed the wait-for-pos-error-test-refactor branch 2 times, most recently from ee2b51d to c3d4c57 Compare May 16, 2024 23:00
Signed-off-by: Rafer Hazen <rafer@ralua.com>
@rafer rafer force-pushed the wait-for-pos-error-test-refactor branch from c3d4c57 to 6053c5e Compare May 16, 2024 23:16
Copy link

codecov bot commented May 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 68.61%. Comparing base (7997d1e) to head (f46bec4).
Report is 12 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #15962      +/-   ##
==========================================
+ Coverage   68.47%   68.61%   +0.13%     
==========================================
  Files        1562     1562              
  Lines      197062   198642    +1580     
==========================================
+ Hits       134933   136289    +1356     
- Misses      62129    62353     +224     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -426,7 +426,8 @@ func TestWaitForPosError(t *testing.T) {

dbClient.ExpectRequest("select pos, state, message from _vt.vreplication where id=1", &sqltypes.Result{Rows: [][]sqltypes.Value{{}}}, nil)
err = vre.WaitForPos(context.Background(), 1, "MariaDB/0-1-1084")
want = "unexpected result: &{[] 0 0 [[]] 0 }"
want = fmt.Sprintf("unexpected result: %v", &sqltypes.Result{Rows: [][]sqltypes.Value{{}}})
Copy link
Contributor

Choose a reason for hiding this comment

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

@rafer I think we should actually fix the error message generated here. I don't think it's very clear what this is in the first place. The error message does not seem very user friendly if it contains &{[] 0 0 [[]] 0 }. I don't think that's meaningful in any way for a Vitess user?

Something along these lines maybe, so instead of:

		case len(qr.Rows) > 1 || len(qr.Rows[0]) != 3:
			return fmt.Errorf("unexpected result: %v", qr)

We do something like:

		case len(qr.Rows) > 1:
			return fmt.Errorf("more rows received than expected, got %v instead of 1", len(qr.Rows))
		case len(qr.Rows[0]) != 3:
			return fmt.Errorf("more columns received than expected, got %v instead of 3", len(qr.Rows[0]))

Copy link
Contributor

Choose a reason for hiding this comment

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

Alternatively, just printing qr.Rows instead of the whole qr already makes it look a lot better as well, since rows have a proper .String() implementation for debugging.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Update 👍

Signed-off-by: Rafer Hazen <rafer@ralua.com>
@rafer rafer changed the title Generate expected error string with actual Result object Improve WaitForPos errors, don't include Result struct in message May 21, 2024
@rafer rafer marked this pull request as ready for review May 21, 2024 01:07
@mattlord mattlord added Type: Internal Cleanup Type: Enhancement Logical improvement (somewhere between a bug and feature) Component: VReplication and removed NeedsBackportReason If backport labels have been applied to a PR, a justification is required NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsWebsiteDocsUpdate What it says NeedsIssue A linked issue is missing for this Pull Request labels May 21, 2024
Copy link
Contributor

@mattlord mattlord left a comment

Choose a reason for hiding this comment

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

Thanks, @rafer ! ❤️

Comment on lines 794 to 796
return fmt.Errorf("vreplication stream received more rows than expected, got %v instead of 1", len(qr.Rows))
case len(qr.Rows[0]) != 3:
return fmt.Errorf("vreplication stream received an unexpected number of columns, got %v instead of 3", len(qr.Rows[0]))
Copy link
Contributor

Choose a reason for hiding this comment

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

Super nitty, but we could use %d instead of %v here.

Signed-off-by: Rafer Hazen <rafer@ralua.com>
@mattlord mattlord merged commit 0d8ca1b into main May 22, 2024
181 checks passed
@mattlord mattlord deleted the wait-for-pos-error-test-refactor branch May 22, 2024 22:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: VReplication Type: Enhancement Logical improvement (somewhere between a bug and feature) Type: Internal Cleanup
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants