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

[VTAdmin API] Replace underscores with dashes in cluster ID #15722

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

notfelineit
Copy link
Contributor

@notfelineit notfelineit commented Apr 15, 2024

Description

VTAdmin API fails to connect to VTGate and vtctld when there are underscores _ in the VTGate & vtctld custom name resolvers. The custom name is based on the cluster ID, so this PR switches underscores for dashes - in the initial cluster ID.

This PR should be backported, since it fixes a bug that exists in v17-present.

Related Issue(s)

Fixes #15721

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

N/A

Signed-off-by: notfelineit <notfelineit@gmail.com>
Signed-off-by: notfelineit <notfelineit@gmail.com>
Signed-off-by: notfelineit <notfelineit@gmail.com>
Copy link
Contributor

vitess-bot bot commented Apr 15, 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 Apr 15, 2024
@github-actions github-actions bot added this to the v20.0.0 milestone Apr 15, 2024
@notfelineit notfelineit added Component: VTAdmin VTadmin interface go Type: Bug Backport to: release-17.0 Needs to be back ported to release-17.0 Backport to: release-18.0 Needs to be back ported to release-18.0 Backport to: release-19.0 Needs to be back ported to release-19.0 and 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 Apr 15, 2024
@notfelineit notfelineit marked this pull request as ready for review April 15, 2024 17:58
go/vt/vtadmin/cluster/config.go Outdated Show resolved Hide resolved
@@ -284,6 +288,17 @@ func (cfg Config) Merge(override Config) Config {
return merged
}

func formatID(id string) string {
if strings.Contains(id, "_") {
Copy link
Contributor

Choose a reason for hiding this comment

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

Are there any other characters that can occur in the input that will fail here as well? Is there any reference also to GRPC docs which describes what characters are valid and which ones are not?

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 couldn't find anything definitive in the gRPC repository, however with some digging:

  • gRPC Core defines custom resolver names as following URI syntacx
  • Further digging from the modifications section of the above RFC shows that gRPC naming followed ABNF, and specifically the scheme portion of the resolver does not seem to allow _ underscores: https://datatracker.ietf.org/doc/html/rfc2396#section-3.1
    • we use the cluster ID as the scheme, which is why this PR replaces all the underscores in the cluster ID. For example my_cluster_id://vtctld/ is a custom resolver name generated by vtadmin api

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 think I'd like to ship this fix, and then spend more time being thoughtful about:

  • Testing the format stated in RFC 2396
  • Implementing cluster ID validations following the format in the RFC, if it is indeed strict

Copy link
Contributor

Choose a reason for hiding this comment

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

cluster ID as the scheme

Which characters are allowed as a cluster ID? Should we add a validation on that so it wouldn't even be allowed to use anything that won't also fit into a scheme?

Copy link
Contributor

Choose a reason for hiding this comment

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

https://datatracker.ietf.org/doc/html/rfc3986#appendix-A has the allowed characters as:

   scheme        = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )

so we should just assert on that i think

Signed-off-by: notfelineit <notfelineit@gmail.com>
Copy link

codecov bot commented Apr 15, 2024

Codecov Report

Attention: Patch coverage is 71.42857% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 68.40%. Comparing base (f118ba2) to head (3dce263).
Report is 6 commits behind head on main.

Files Patch % Lines
go/vt/vtadmin/cluster/config.go 71.42% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #15722      +/-   ##
==========================================
- Coverage   68.40%   68.40%   -0.01%     
==========================================
  Files        1556     1556              
  Lines      195121   195288     +167     
==========================================
+ Hits       133479   133591     +112     
- Misses      61642    61697      +55     

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

Copy link
Contributor

@ajm188 ajm188 left a comment

Choose a reason for hiding this comment

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

awesome find! just one minor comment

@@ -237,7 +241,7 @@ func (cfg *Config) MarshalJSON() ([]byte, error) {
// config. Neither the caller or the argument are modified in any way.
func (cfg Config) Merge(override Config) Config {
merged := Config{
ID: cfg.ID,
ID: formatID(cfg.ID),
Copy link
Contributor

Choose a reason for hiding this comment

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

can we do this further up the call stack (when we parse a config) so we don't need to do this operation every time we merge two configs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes! 😄

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.

I think this fixes the noted issue so don't forget to add the Fixes keyword. The issue will then be linked and automatically closed with a note.

@@ -284,6 +288,13 @@ func (cfg Config) Merge(override Config) Config {
return merged
}

func formatID(id string) string {
// gRPC can't process custom resolver names with underscores
id = strings.Replace(id, "_", "-", -1)
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we're here, we could address the wider issue I think just as easily. We could replace any invalid chars with dashes, or remove them as well. You can see the regex to replace any unaccepted chars with dashes here: https://go.dev/play/p/qmHmZ_KSnMI

If you wanted to do that, you probably just want to make the regexp a package variable so that we don't have to compile it every time (although I don't imagine we hit this very often so probably not a practical issue even if we did).

Copy link
Contributor

Choose a reason for hiding this comment

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

Thought about this a bit more and IMO:

auto-fixing is a breaking change (what happens if I have a deployment with clusters hello_world and hello-world?), as well as its alternative of failing loudly on a "bad" name.

but the alternative is less magical, since users are having the names changed out silently beneath them, so we should maybe just do input validation and include an entry in the release notes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I agree that it's a breaking change - did you see my latest comment? I agree with input validation!

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, that plan looks good to me!

@notfelineit
Copy link
Contributor Author

notfelineit commented Apr 19, 2024

Ok, I'm back working on this!

@mattlord and @dbussink , I didn't originally intend to bundle the full fix with this PR, but I will now. The reason being I didn't want to make a decision on "break" or "fix silently" when users pass in an invalid cluster name. However, I think a reasonable first step might be to:

  • Maintain old behavior on "bad" cluster names (still spin up VTAdmin, vtctld and vtgate won't work) but add a log/notification letting the user know they should use a different cluster name

That changes things a bit, because I'm not sure if this PR should still automatically change _ to - then, because we should probably treat all invalid characters in the same way.

@ajm188 what do you think? Should we:

  • autofix the names
  • allow bad names and just notify the user
  • combination of the two: correct _ and warn on the rest

@dbussink
Copy link
Contributor

  • Maintain old behavior on "bad" cluster names (still spin up VTAdmin, vtctld and vtgate won't work) but add a log/notification letting the user know they should use a different cluster name

What about we add warning for now to not immediately break people and then we turn it into an error if you use an invalid name for the next release (v21)? That way we don't have to do anything here trying to interpret what the user intended long term.

@notfelineit
Copy link
Contributor Author

notfelineit commented Apr 22, 2024

@dbussink Yeah, I think that's a good way to go about it. Including what @ajm188 said too! Here's the plan taken from everyone's input:

  1. v20: Add warning (log & warning in the UI) on invalid cluster name
  2. v21: Turn warning into an error on vtadmin-api boot up

And for clarification, we won't plan to auto format any cluster names!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backport to: release-17.0 Needs to be back ported to release-17.0 Backport to: release-18.0 Needs to be back ported to release-18.0 Backport to: release-19.0 Needs to be back ported to release-19.0 Component: VTAdmin VTadmin interface go Type: Bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug Report: gRPC custom name resolvers don't work with underscores
4 participants