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

cli: warn the user for common mistakes around options=-ccluster #97588

Merged
merged 1 commit into from
Mar 10, 2023

Conversation

knz
Copy link
Contributor

@knz knz commented Feb 23, 2023

Fixes #97586.
Epic: CRDB-23559

Examples:

% ./cockroach sql --url='postgres://localhost:26257/?-ccluster=foo'

warning: found raw URL parameter "-ccluster"; are you sure you did not mean to use "options=-ccluster" instead?

% ./cockroach sql --url='postgres://localhost:26257/?options=-cluster=foo'

warning: found "-cluster=" in URL "options" field; are you sure you did not mean to use "options=-ccluster" instead?

Release note: None

@knz knz added the A-multitenancy Related to multi-tenancy label Feb 23, 2023
@knz knz requested review from stevendanna and rafiss February 23, 2023 20:01
@knz knz requested a review from a team as a code owner February 23, 2023 20:01
@knz knz self-assigned this Feb 23, 2023
@cockroach-teamcity
Copy link
Member

This change is Reviewable

Comment on lines +292 to +294
u.warnFn("\nwarning: found raw URL parameter \"%[1]s\"; "+
"are you sure you did not mean to use \"options=%[1]s\" instead?\n\n", optName)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

If you wanted, some of the surrounding formatting could go into the warnFn to keep it consistent as we add more checks. But I don't feel strongly about it.

// For tenant selection, the option is `-ccluster=`, not `-cluster=`.
if extraOpts := opts.Get("options"); extraOpts != "" {
if strings.Contains(extraOpts, "-cluster=") {
u.warnFn("\nwarning: found \"-cluster=\" in URL \"options\" field; " +
Copy link
Collaborator

Choose a reason for hiding this comment

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

perhaps somewhat confusingly, all of these are allowed:

  • -c cluster=
  • -ccluster=
  • --cluster=

i am not sure if we want to mention the other allowed syntaxes here. wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you clarify your question? -c cluster= and -ccluster= are equivalent (and valid)
I did not know --cluster=. Is this one valid?

Copy link
Collaborator

Choose a reason for hiding this comment

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

the point i am making is that all three of the syntaxes i listed are valid and equivalent. my question is: should our informational message mention all three of them?

(we matched the PG behavior documented at https://www.postgresql.org/docs/current/app-psql.html - look for -c command)

Copy link
Collaborator

Choose a reason for hiding this comment

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

a separate point i just thought of: if we have to pick only one to recommend, then i think options=-ccluster= is less clear than options=-c cluster=

Copy link
Contributor Author

Choose a reason for hiding this comment

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

-ccluster= can be typed in without escapes (e.g. the user can literally type in &options=-ccluster=...) whereas if we recommend a space they will have to use %20 which strains the eye.

I did not know that --cluster= was accepted. i'll add tests for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i've ended up reusing the same code as pgwire so we have consistent behavior.

@knz knz force-pushed the 20230223-url-warn branch from d8f8eec to 0c05c85 Compare March 9, 2023 18:45
@knz knz requested a review from a team March 9, 2023 18:45
@knz knz requested a review from a team as a code owner March 9, 2023 18:45
@knz knz force-pushed the 20230223-url-warn branch 2 times, most recently from de0f7f1 to 76a63d5 Compare March 9, 2023 19:03
Examples:
```
% ./cockroach sql --url='postgres://localhost:26257/?-ccluster=foo'

warning: found raw URL parameter "-ccluster"; are you sure you did not mean to use "options=-ccluster" instead?

% ./cockroach sql --url='postgres://localhost:26257/?options=-cluster=foo'

warning: found "-cluster=" in URL "options" field; are you sure you did not mean to use "options=-ccluster" instead?
```

Release note: None
@knz knz force-pushed the 20230223-url-warn branch from 76a63d5 to 05bcaa1 Compare March 9, 2023 19:21
Copy link
Collaborator

@rafiss rafiss left a comment

Choose a reason for hiding this comment

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

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @knz)


pkg/cli/clienturl/client_url.go line 299 at r1 (raw file):

Previously, knz (Raphael 'kena' Poss) wrote…

i've ended up reusing the same code as pgwire so we have consistent behavior.

that sgtm! thank you

@knz
Copy link
Contributor Author

knz commented Mar 10, 2023

TFYR!

bors r=rafiss

@craig
Copy link
Contributor

craig bot commented Mar 10, 2023

Build failed:

@knz
Copy link
Contributor Author

knz commented Mar 10, 2023

bors r=rafiss

@craig
Copy link
Contributor

craig bot commented Mar 10, 2023

Build failed:

@knz
Copy link
Contributor Author

knz commented Mar 10, 2023

bors r=rafiss

@craig
Copy link
Contributor

craig bot commented Mar 10, 2023

Build failed:

@knz
Copy link
Contributor Author

knz commented Mar 10, 2023

bors r=rafiss

@craig
Copy link
Contributor

craig bot commented Mar 10, 2023

Build succeeded:

@craig craig bot merged commit 4050ff2 into cockroachdb:master Mar 10, 2023
@knz knz deleted the 20230223-url-warn branch March 10, 2023 23:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-multitenancy Related to multi-tenancy
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cli: make it easier to spot mistakes in manually-entered options=-ccluster URL parameter
4 participants