Skip to content

Conversation

@arthurschreiber
Copy link
Member

@arthurschreiber arthurschreiber commented Sep 12, 2025

Description

This pull request changes how we handle the migration from underscored to dashed CLI flags.

Previously, we defined flags twice, once with their new dashed name, and once with the legacy / deprecated underscored name. The underscored name was then marked as deprecated and hidden from things like the help output.

This worked sort of fine for regular flags, as we'd end up reusing the same memory to store the value for either the dashed or underscored flag, so specifying one or the other worked in most cases.

Unfortunately, this approach did not work at all with flags that were bound to Viper. Viper would bind to a specific flag object, and not directly to the pointer where the flag value is stored. Before accessing flag values, Viper would call .Changed on the flag that was bound, and this would only return true on the flag struct for the exact variant that was specified on the CLI. As Viper can only bind to one flag object, this would break depending on which flag variant Viper was bound to and which flag was passed in via the CLI.

We noticed this through CI failures, but users would eventually have noticed that too where deprecated flags would just break / not do anything anymore.

This pull request proposes to fix this using a different approach.

Namely, instead of defining different flag variants, we define flags once, using their dashed variant. Then we define a flag name normalizer function that translates underscored flag names to dashed flag names. This normalizer is called when flags are parsed, so internally we can just standardize on dashed names, while we still support underscored names to be passed to the CLI.

When an underscored name is encountered, we emit a deprecation message (just as before with the multiple flag variants defined).

Because there's only one flag defined, that's the flag we can bind to with Viper, and everything works just as expected.

Related Issue(s)

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

Instead of defining flags twice (once with underscores, once without), we just normalize them at the `pflag` level.

Signed-off-by: Arthur Schreiber <[email protected]>
@vitess-bot
Copy link
Contributor

vitess-bot bot commented Sep 12, 2025

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 Sep 12, 2025
@github-actions github-actions bot added this to the v23.0.0 milestone Sep 12, 2025
…ke `--tablet_types-to-wait` invalid).

Signed-off-by: Arthur Schreiber <[email protected]>
Signed-off-by: Arthur Schreiber <[email protected]>
Signed-off-by: Arthur Schreiber <[email protected]>
Signed-off-by: Arthur Schreiber <[email protected]>
Signed-off-by: Arthur Schreiber <[email protected]>
Signed-off-by: Arthur Schreiber <[email protected]>
Otherwise this breaks consumers that e.g. expect output on stdout to be valid JSON.

Signed-off-by: Arthur Schreiber <[email protected]>
Flag variations are handled at the pflag / cobra level via normalization. No need to test them in the unit tests anymore.

Signed-off-by: Arthur Schreiber <[email protected]>
We call flag parsing directly here, so the dashed/underscored handling is not set up at this point.

Signed-off-by: Arthur Schreiber <[email protected]>
@codecov
Copy link

codecov bot commented Sep 12, 2025

Codecov Report

❌ Patch coverage is 11.32075% with 47 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.53%. Comparing base (e89de50) to head (8d1da6f).
⚠️ Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
go/vt/utils/flags.go 20.00% 16 Missing ⚠️
go/cmd/mysqlctl/mysqlctl.go 0.00% 2 Missing ⚠️
go/cmd/mysqlctld/mysqlctld.go 0.00% 2 Missing ⚠️
go/cmd/vtaclcheck/cli/vtactlcheck.go 0.00% 2 Missing ⚠️
go/cmd/vtclient/vtclient.go 0.00% 2 Missing ⚠️
go/cmd/vtctl/vtctl.go 0.00% 2 Missing ⚠️
go/cmd/vtctlclient/main.go 0.00% 2 Missing ⚠️
go/cmd/mysqlctl/command/start.go 0.00% 1 Missing ⚠️
go/cmd/rulesctl/main.go 0.00% 1 Missing ⚠️
go/cmd/topo2topo/topo2topo.go 0.00% 1 Missing ⚠️
... and 16 more
Additional details and impacted files
@@            Coverage Diff            @@
##           main   #18642       +/-   ##
=========================================
+ Coverage      0   67.53%   +67.53%     
=========================================
  Files         0     1613     +1613     
  Lines         0   263778   +263778     
=========================================
+ Hits          0   178134   +178134     
- Misses        0    85644    +85644     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@arthurschreiber arthurschreiber removed 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 NeedsBackportReason If backport labels have been applied to a PR, a justification is required labels Sep 15, 2025
@arthurschreiber arthurschreiber marked this pull request as ready for review September 15, 2025 08:33
Copy link
Member

@rohit-nayak-ps rohit-nayak-ps left a comment

Choose a reason for hiding this comment

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

Great find!

arthurschreiber and others added 2 commits September 15, 2025 09:07
Signed-off-by: Arthur Schreiber <[email protected]>
Signed-off-by: Andres Taylor <[email protected]>
@arthurschreiber arthurschreiber enabled auto-merge (squash) September 15, 2025 09:48
@arthurschreiber arthurschreiber merged commit 67ced16 into vitessio:main Sep 15, 2025
103 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants