From a850f0085110904100af2279e8231ce707944645 Mon Sep 17 00:00:00 2001 From: Rafael Chacon Date: Mon, 21 May 2018 20:15:24 -0700 Subject: [PATCH 1/2] Make template loader public so it can be called when starting vtgate * Without this change, loadTabletUrl is only called during init method and it won't have the flag parsed yet. Signed-off-by: Rafael Chacon --- go/cmd/vtgate/vtgate.go | 1 + go/vt/discovery/healthcheck.go | 7 +++---- go/vt/discovery/healthcheck_test.go | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/go/cmd/vtgate/vtgate.go b/go/cmd/vtgate/vtgate.go index 989875499dc..dbe99a9b476 100644 --- a/go/cmd/vtgate/vtgate.go +++ b/go/cmd/vtgate/vtgate.go @@ -86,6 +86,7 @@ func main() { vtg := vtgate.Init(context.Background(), healthCheck, resilientServer, *cell, *retryCount, tabletTypes) servenv.OnRun(func() { + discovery.LoadHealthCheckTabletURLTemplate() addStatusParts(vtg) }) servenv.RunDefault() diff --git a/go/vt/discovery/healthcheck.go b/go/vt/discovery/healthcheck.go index c3b54815746..6c32a2cd630 100644 --- a/go/vt/discovery/healthcheck.go +++ b/go/vt/discovery/healthcheck.go @@ -120,12 +120,11 @@ const ( ) func init() { - loadTabletURLTemplate() + LoadHealthCheckTabletURLTemplate() } -// loadTabletURLTemplate loads or reloads the URL template. -// Should only be used independently for testing. -func loadTabletURLTemplate() { +// LoadHealthCheckTabletURLTemplate loads or reloads the URL template. +func LoadHealthCheckTabletURLTemplate() { tabletURLTemplate = template.New("") _, err := tabletURLTemplate.Parse(*tabletURLTemplateString) if err != nil { diff --git a/go/vt/discovery/healthcheck_test.go b/go/vt/discovery/healthcheck_test.go index 1e6086da33f..cece1f3aabc 100644 --- a/go/vt/discovery/healthcheck_test.go +++ b/go/vt/discovery/healthcheck_test.go @@ -574,7 +574,7 @@ func TestTemplate(t *testing.T) { func TestDebugURLFormatting(t *testing.T) { flag.Set("tablet_url_template", "https://{{.GetHostNameLevel 0}}.bastion.{{.Tablet.Alias.Cell}}.corp") - loadTabletURLTemplate() + LoadHealthCheckTabletURLTemplate() tablet := topo.NewTablet(0, "cell", "host.dc.domain") ts := []*TabletStats{ From e202ec7d29908e56e3802a6d7ee104e6cfd0956b Mon Sep 17 00:00:00 2001 From: Rafael Chacon Date: Tue, 22 May 2018 11:42:13 -0700 Subject: [PATCH 2/2] Rename function and add comments for clarity. Signed-off-by: Rafael Chacon --- go/cmd/vtgate/vtgate.go | 3 ++- go/vt/discovery/healthcheck.go | 7 ++++--- go/vt/discovery/healthcheck_test.go | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/go/cmd/vtgate/vtgate.go b/go/cmd/vtgate/vtgate.go index dbe99a9b476..2a3aa9445d3 100644 --- a/go/cmd/vtgate/vtgate.go +++ b/go/cmd/vtgate/vtgate.go @@ -86,7 +86,8 @@ func main() { vtg := vtgate.Init(context.Background(), healthCheck, resilientServer, *cell, *retryCount, tabletTypes) servenv.OnRun(func() { - discovery.LoadHealthCheckTabletURLTemplate() + // Flags are parsed now. Parse the template using the actual flag value and overwrite the current template. + discovery.ParseTabletURLTemplateFromFlag() addStatusParts(vtg) }) servenv.RunDefault() diff --git a/go/vt/discovery/healthcheck.go b/go/vt/discovery/healthcheck.go index 6c32a2cd630..7ab456d0939 100644 --- a/go/vt/discovery/healthcheck.go +++ b/go/vt/discovery/healthcheck.go @@ -120,11 +120,12 @@ const ( ) func init() { - LoadHealthCheckTabletURLTemplate() + // Flags are not parsed at this point and the default value of the flag (just the hostname) will be used. + ParseTabletURLTemplateFromFlag() } -// LoadHealthCheckTabletURLTemplate loads or reloads the URL template. -func LoadHealthCheckTabletURLTemplate() { +// ParseTabletURLTemplateFromFlag loads or reloads the URL template. +func ParseTabletURLTemplateFromFlag() { tabletURLTemplate = template.New("") _, err := tabletURLTemplate.Parse(*tabletURLTemplateString) if err != nil { diff --git a/go/vt/discovery/healthcheck_test.go b/go/vt/discovery/healthcheck_test.go index cece1f3aabc..a301bb70ee3 100644 --- a/go/vt/discovery/healthcheck_test.go +++ b/go/vt/discovery/healthcheck_test.go @@ -574,7 +574,7 @@ func TestTemplate(t *testing.T) { func TestDebugURLFormatting(t *testing.T) { flag.Set("tablet_url_template", "https://{{.GetHostNameLevel 0}}.bastion.{{.Tablet.Alias.Cell}}.corp") - LoadHealthCheckTabletURLTemplate() + ParseTabletURLTemplateFromFlag() tablet := topo.NewTablet(0, "cell", "host.dc.domain") ts := []*TabletStats{