From 25b3a8f18edab32f319ce0d278e194739139ae1f Mon Sep 17 00:00:00 2001 From: irfan sharif Date: Mon, 10 Oct 2022 14:25:21 -0400 Subject: [PATCH] roachprod: simplify grafana-url computation There's only ever one URL. Release note: None --- pkg/cmd/roachprod/main.go | 7 ++----- pkg/roachprod/roachprod.go | 20 +++++++++++--------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/pkg/cmd/roachprod/main.go b/pkg/cmd/roachprod/main.go index b8de605e2803..820d257723ee 100644 --- a/pkg/cmd/roachprod/main.go +++ b/pkg/cmd/roachprod/main.go @@ -925,15 +925,12 @@ var grafanaURLCmd = &cobra.Command{ Short: `returns a url to the grafana dashboard`, Args: cobra.ExactArgs(1), Run: wrap(func(cmd *cobra.Command, args []string) error { - urls, err := roachprod.GrafanaURL(context.Background(), roachprodLibraryLogger, args[0], + url, err := roachprod.GrafanaURL(context.Background(), roachprodLibraryLogger, args[0], grafanaurlOpen) if err != nil { return err } - for _, url := range urls { - fmt.Println(url) - } - fmt.Println("username: admin; pwd: admin") + fmt.Println(url) return nil }), } diff --git a/pkg/roachprod/roachprod.go b/pkg/roachprod/roachprod.go index 1382f4b9bb93..90c5ab364d33 100644 --- a/pkg/roachprod/roachprod.go +++ b/pkg/roachprod/roachprod.go @@ -1401,13 +1401,11 @@ func StartGrafana( if err != nil { return err } - urls, err := GrafanaURL(ctx, l, clusterName, false) + url, err := GrafanaURL(ctx, l, clusterName, false) if err != nil { return err } - for i, url := range urls { - fmt.Printf("Grafana dashboard %d: %s\n", i, url) - } + fmt.Printf("Grafana dashboard: %s\n", url) return nil } @@ -1434,17 +1432,17 @@ func StopGrafana(ctx context.Context, l *logger.Logger, clusterName string, dump // GrafanaURL returns a url to the grafana dashboard func GrafanaURL( ctx context.Context, l *logger.Logger, clusterName string, openInBrowser bool, -) ([]string, error) { +) (string, error) { if err := LoadClusters(); err != nil { - return nil, err + return "", err } c, err := newCluster(l, clusterName) if err != nil { - return nil, err + return "", err } nodes, err := install.ListNodes("all", len(c.VMs)) if err != nil { - return nil, err + return "", err } // grafana is assumed to be running on the last node in the target grafanaNode := install.Nodes{nodes[len(nodes)-1]} @@ -1455,5 +1453,9 @@ func GrafanaURL( secure: false, port: 3000, } - return urlGenerator(c, l, grafanaNode, uConfig) + urls, err := urlGenerator(c, l, grafanaNode, uConfig) + if err != nil { + return "", err + } + return urls[0], nil }