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

[VEP-4, phase 1] Flag Deprecation Warnings #9733

Merged
merged 14 commits into from
Mar 8, 2022

Conversation

ajm188
Copy link
Contributor

@ajm188 ajm188 commented Feb 18, 2022

Description

This PR introduces a helper function, _flag.Parse to check for the flag usages that will break when we switch to flag. For more details, see VEP-4.

The general plan here is:

  1. Merge this. If I'm fast enough, get a second branch into 13.0. If not, adjust all versions in the next steps by 1.
  2. Adjust scripts in examples/ directory so they stop issuing warnings.
  3. Drop-in replace all calls to _flag.Parse with pflag.Parse. Verify all binaries start correctly.
  4. Delete this package.

Testing:

Here's the local example:

➜  local git:(andrew/flag-deprecation) ✗ ./101_initial_cluster.sh 
add /vitess/global
add /vitess/zone1
add zone1 CellInfo
W0217 09:40:27.230091   62398 flag.go:30] Use of single-dash long flags is deprecated and will be removed in the next version of Vitess. Please use --topo_global_root instead
W0217 09:40:27.230545   62398 flag.go:30] Use of single-dash long flags is deprecated and will be removed in the next version of Vitess. Please use --topo_global_server_address instead
W0217 09:40:27.230549   62398 flag.go:30] Use of single-dash long flags is deprecated and will be removed in the next version of Vitess. Please use --topo_implementation instead
W0217 09:40:27.230552   62398 flag.go:43] Detected a positional argument beginning with a dash; This will be treated as a flag argument in the next version of Vitess. Please update your invocation to include a "--" before to continue treating --root as a positional argument.
W0217 09:40:27.230567   62398 flag.go:43] Detected a positional argument beginning with a dash; This will be treated as a flag argument in the next version of Vitess. Please update your invocation to include a "--" before to continue treating --server-address as a positional argument.
W0217 09:40:27.230578   62398 vtctl.go:88] WARNING: vtctl should only be used for VDiff workflows. Consider using vtctldclient for all other commands.
Created cell: zone1

Related Issue(s)

vitessio/enhancements#7

Checklist

  • Should this PR be backported? yes, opening a branch now
  • Tests were added or are not required n/a -- did manual testing
  • Documentation was added or is not required

Deployment Notes

@ajm188 ajm188 added Type: Enhancement Logical improvement (somewhere between a bug and feature) release notes (needs details) This PR needs to be listed in the release notes in a dedicated section (deprecation notice, etc...) Component: General Changes throughout the code base labels Feb 18, 2022
@ajm188 ajm188 added this to In progress in Flag Restructure via automation Feb 18, 2022
@ajm188 ajm188 requested a review from deepthi as a code owner February 18, 2022 18:42

// Second line: usage and optional default, if not the zero value
// for the type.
buf.WriteString(usage)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you, like me, were wondering, but what if the usage is empty? does the standard library really still print a tab character? oh boy does it!!

Screen Shot 2022-02-20 at 9 34 51 AM

(playground)

Copy link
Member

Choose a reason for hiding this comment

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

haha good catch

}

if strings.HasPrefix(arg, "-") {
log.Warningf("Detected a positional argument beginning with a dash; this will be treated as a flag argument in the next version of Vitess. Please update your invocation to include a \"--\" before to continue treating %s as a positional argument.", arg)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@deepthi let me know if you have suggestions on how to improve this warning text. i don't think it's clear, but i can't think of a way to improve it, either :/

Copy link
Member

Choose a reason for hiding this comment

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

I might be overthinking, but to make it clearer I would add:
include a \"--\" before to ... -> include a \"--\" before %s to ... with %s being arg

Copy link
Member

Choose a reason for hiding this comment

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

I like this suggestion 👍

var buf strings.Builder
goflag.CommandLine.VisitAll(func(f *goflag.Flag) {
defer buf.Reset()
defer func() { fmt.Fprintf(goflag.CommandLine.Output(), "%s\n", buf.String()) }()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

we have to wrap this defer inside an anonymous function to delay the execution of buf.String()

the other thing i briefly considered was:

defer buf.Reset()

...

if bf, ok := f.Value.(maybeBoolFlag); ok && ... {
    fmt.Fprintf(...)
    goto print
}

// print first and second lines for non-bool flags to `buf`

print:
    fmt.Fprintf(goflag.CommandLine.Output(), "%s\n", buf.String())

but ended up deciding the goto was more gross than the defer func() { ... }()

Copy link
Member

Choose a reason for hiding this comment

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

IMO, the defer does not seem bad. Another alternative would be to create an anonymous function where we have the current defer, and call that function where we return.

frouioui
frouioui previously approved these changes Feb 21, 2022
Copy link
Member

@frouioui frouioui left a comment

Choose a reason for hiding this comment

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

I am excited for this VEP, phase 1 is looking good to me @ajm188 🚀

We should update the v14/v13 docs to reflect this deprecation and how the new flags should be written.

Flag Restructure automation moved this from In progress to Reviewer approved Feb 21, 2022
@ajm188
Copy link
Contributor Author

ajm188 commented Feb 22, 2022

Ugh, okay this is breaking a lot of the cluster tests that check the "first line" output of vtctl because those first few lines are now all deprecation warnings ... I'm going to fix up all their invocations and see if that helps without breaking upgrade/downgrade testing.

@ajm188
Copy link
Contributor Author

ajm188 commented Feb 22, 2022

🤞 🤞

Copy link
Member

@deepthi deepthi left a comment

Choose a reason for hiding this comment

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

We should change all the examples in the same PR. Otherwise the output will be full of warnings and difficult to parse by humans (unless you plan to fast-follow with an examples PR and want to keep PRs small and manageable).

@ajm188
Copy link
Contributor Author

ajm188 commented Feb 22, 2022

I'm gonna DoNotMerge this, since I think there's a few more things to do, in particular:

  • update all the tests to not break
  • update the example scripts i changed my mind, let's do this in a follow-up PR
  • write the release notes

when i finish those 3 things i'll un-DoNotMerge and ping you again. sound good?

@ajm188 ajm188 force-pushed the andrew/flag-deprecation branch 5 times, most recently from 50fdd45 to f76a451 Compare February 23, 2022 22:17
Andrew Mason added 7 commits March 8, 2022 06:16
This package is internal, and extremely temporary. After the
necessary backwards-compatability deprecation cycle to switch to
`pflag`, will be removed.

Signed-off-by: Andrew Mason <andrew@planetscale.com>
…ion-aware parser

Signed-off-by: Andrew Mason <andrew@planetscale.com>
Signed-off-by: Andrew Mason <andrew@planetscale.com>
…r structure

Signed-off-by: Andrew Mason <andrew@planetscale.com>
Signed-off-by: Andrew Mason <andrew@planetscale.com>
…ds compatibility

Signed-off-by: Andrew Mason <andrew@planetscale.com>
Signed-off-by: Andrew Mason <andrew@planetscale.com>
Andrew Mason added 5 commits March 8, 2022 06:16
Signed-off-by: Andrew Mason <andrew@planetscale.com>
Signed-off-by: Andrew Mason <andrew@planetscale.com>
Signed-off-by: Andrew Mason <andrew@planetscale.com>
Signed-off-by: Andrew Mason <andrew@planetscale.com>
Signed-off-by: Andrew Mason <andrew@planetscale.com>
@ajm188
Copy link
Contributor Author

ajm188 commented Mar 8, 2022

Alright, hold on to your butts, I'm force-pushing with what will, pending some back-and-forth on the release notes, be the final version of this change. I did all my debugging over in #9831, which I will close.

@frouioui frouioui self-requested a review March 8, 2022 16:36
@ajm188 ajm188 dismissed frouioui’s stale review March 8, 2022 17:12

updated all the things, this approval should in no way count (but thank you!!)

Flag Restructure automation moved this from Reviewer approved to Review in progress Mar 8, 2022
Andrew Mason added 2 commits March 8, 2022 13:52
…= v13.0.0

Signed-off-by: Andrew Mason <andrew@planetscale.com>
Signed-off-by: Andrew Mason <andrew@planetscale.com>
Copy link
Member

@deepthi deepthi left a comment

Choose a reason for hiding this comment

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

Nice work!

Flag Restructure automation moved this from Review in progress to Reviewer approved Mar 8, 2022
@deepthi deepthi merged commit 8fde81b into vitessio:main Mar 8, 2022
@deepthi deepthi deleted the andrew/flag-deprecation branch March 8, 2022 22:27
Flag Restructure automation moved this from Reviewer approved to Done Mar 8, 2022
@deepthi deepthi mentioned this pull request Mar 11, 2022
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: General Changes throughout the code base release notes (needs details) This PR needs to be listed in the release notes in a dedicated section (deprecation notice, etc...) Type: Enhancement Logical improvement (somewhere between a bug and feature)
Projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants