Skip to content

Commit

Permalink
roachprod: simplify grafana-url computation
Browse files Browse the repository at this point in the history
There's only ever one URL.

Release note: None
  • Loading branch information
irfansharif committed Oct 24, 2022
1 parent 5135843 commit fdad158
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
7 changes: 2 additions & 5 deletions pkg/cmd/roachprod/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}),
}
Expand Down
20 changes: 11 additions & 9 deletions pkg/roachprod/roachprod.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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]}
Expand All @@ -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
Expand Down

0 comments on commit fdad158

Please sign in to comment.