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] gate/tablet/vtctld FQDNs #7886

Merged
merged 12 commits into from
Apr 29, 2021

Conversation

ajm188
Copy link
Contributor

@ajm188 ajm188 commented Apr 18, 2021

Description

This PR introduces an optional FQDN field to gates/tablets/vtctld proto message types, along with options to specify a go template for generating an FQDN from the rest of the struct fields in a gate/tablet/vtctld.

For gates and vtctlds, it's up to the particular discovery implementations to populate those fields, and for tablets it is handled by the Cluster. Consequently, the gate/vtctld template flags are pushed down into the ConsulDiscovery implementation (and StaticFileDiscovery can just read the "FQDN" field directly from the static file, so I did not include an option), while the tablet template flag is parsed as part of the cluster DSN.

One note: I named the field "FQDN" rather than "fqdn" in the proto file, so that it would generate the horrid "Fqdn" Go field name; the side effect of me doing this is that when marshaling to JSON, the key is in all-caps rather than all-lowercase like the rest of the fields. If we feel that json field casing consistency is more valuable, then I can bear with the Fqdn.

I also added a generic function to package textutil to remove the duplicated "create buffer; execute template into buffer; return resulting string" that we have in like 6 places now.

Final note: I'm really bad at typing "fqdn" apparently, and kept making the typo for "fdqn", so something to keep an eye out for when reviewing.

Related Issue(s)

Checklist

  • Should this PR be backported? No
  • Tests were added or are not required N/A
  • Documentation was added or is not required

Deployment Notes

Impacted Areas in Vitess

Components that this PR will affect:

  • Query Serving
  • VReplication
  • Cluster Management
  • Build/CI
  • VTAdmin

@ajm188 ajm188 requested a review from doeg April 18, 2021 02:43
Copy link
Contributor

@doeg doeg left a comment

Choose a reason for hiding this comment

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

Thanks so much for doing this. It's going to be so useful, especially for "internal deprecation" reasons. 😼

Just a couple of minor comments + questions but otherwise this looks great! Go templates make this so much nicer than the equivalent front-end implementation.

if *vtgateFQDNTmplStr != "" {
disco.vtgateFQDNTmpl, err = template.New("consul-vtgate-fqdn-template-" + cluster.Id).Parse(*vtgateFQDNTmplStr)
if err != nil {
return nil, fmt.Errorf("failde to parse vtgate FQDN template %s: %w", *vtgateFQDNTmplStr, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: "failde" (there's another instance lower in the file)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's the Olde English of "failed" (thank you!)

if c.vtgateFQDNTmpl != nil {
vtgate.FQDN, err = textutil.ExecuteTemplate(c.vtgateFQDNTmpl, vtgate)
if err != nil {
return nil, err // TODO: wrap
Copy link
Contributor

Choose a reason for hiding this comment

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

🔪 TODO?

}

func (c *ConsulDiscovery) discoverVTGates(_ context.Context, tags []string) ([]*vtadminpb.VTGate, error) {
func (c *ConsulDiscovery) discoverVTGates(_ context.Context, tags []string, executeFQDNTemplate bool) ([]*vtadminpb.VTGate, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Despite looking all at the callsites, I'm not sure I follow why the executeFQDNTemplate boolean is necessary, or when I'd want to use true vs. false. 🤔 Maybe a comment would help? (Same comment about discoverVtctld's parameter.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In practice it's an optimization for Discover{Vtctld,VTGate}Addr. If we didn't have this flag to thread through, then we would make one ExecuteTemplate call per gate (read also "vtctld") as part of the discovery (to generate the FQDN), pick one gate, and make a final ExecuteTemplate call to generate the dialable address, for a total of N+1 calls to ExecuteTemplate.

Since everything that's available to ExecuteTemplate when we're generating the address is also available when generating the FQDN, we can force the user to (potentially*) be a little redundant in the config and save the N calls for generating FQDNs and make a single ExecuteTemplate call for the final address.

* "potentially" only because it's redundant if your dial address is something like "FQDN + gRPC port", then you would need a config of:

-fqdn-tmpl "{{ .Hostname }}.example.com"
-addr-tmpl "{{ .Hostname }}.example.com:15000"

whereas if we didn't do this optimization then you could specify something like

-fqdn-tmpl "{{ .Hostname }}.example.com"
-addr-tmpl "{{ .FQDN }}:15000"

Copy link
Contributor

Choose a reason for hiding this comment

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

I seeee. Thank you for explaining!

return nil, fmt.Errorf("DiscoverVTGates(cluster = %s): %w", c.ID, err)
}

// Not every discovery implementation will necessarily populate the Cluster
Copy link
Contributor

Choose a reason for hiding this comment

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

This is pretty nitpicky so feel free to leave it, but a more straightforward phrasing might be:

// This overwrites any "Cluster" field populated by the discovery implementation

I know that the code is right there, but the current comment (to me) more readily implies that the "Cluster" field will be populated iff it doesn't already exist from the discovery implementation. Like I said... nitpicky. 😎

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No this distinction makes sense to me! Thank you!

Signed-off-by: Andrew Mason <amason@slack-corp.com>
staticfile disco doesn't need this, because it can just read this from
the config. **Note**: the main downside is that the json key is "FQDN"
rather than "fqdn" which 🤷 ?

Signed-off-by: Andrew Mason <amason@slack-corp.com>
Signed-off-by: Andrew Mason <amason@slack-corp.com>
Signed-off-by: Andrew Mason <amason@slack-corp.com>
Signed-off-by: Andrew Mason <amason@slack-corp.com>
Signed-off-by: Andrew Mason <amason@slack-corp.com>
Signed-off-by: Andrew Mason <amason@slack-corp.com>
Signed-off-by: Andrew Mason <amason@slack-corp.com>
Signed-off-by: Andrew Mason <amason@slack-corp.com>
Signed-off-by: Andrew Mason <amason@slack-corp.com>
Signed-off-by: Andrew Mason <amason@slack-corp.com>
Signed-off-by: Andrew Mason <amason@slack-corp.com>
@ajm188 ajm188 merged commit ab54272 into vitessio:master Apr 29, 2021
@ajm188 ajm188 deleted the am_vtadmin_full_urls branch April 29, 2021 15:31
@ajm188 ajm188 added Component: VTAdmin VTadmin interface Type: Enhancement Logical improvement (somewhere between a bug and feature) labels May 21, 2021
@ajm188 ajm188 added this to In progress in VTAdmin via automation May 21, 2021
@ajm188 ajm188 moved this from In progress to Done in VTAdmin Oct 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: VTAdmin VTadmin interface Type: Enhancement Logical improvement (somewhere between a bug and feature)
Projects
Development

Successfully merging this pull request may close these issues.

None yet

2 participants