From fdad15882bf4d2d593efd72d25faf1edaca2758f 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 9f9dc03816e3..c19b895e91db 100644 --- a/pkg/cmd/roachprod/main.go +++ b/pkg/cmd/roachprod/main.go @@ -934,15 +934,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 3fd970ceb0b3..15e38617cf8f 100644 --- a/pkg/roachprod/roachprod.go +++ b/pkg/roachprod/roachprod.go @@ -1403,13 +1403,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 } @@ -1436,17 +1434,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]} @@ -1457,7 +1455,11 @@ 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 } // PrometheusSnapshot takes a snapshot of prometheus and stores the snapshot and