Skip to content

Commit

Permalink
download grafana dashboard v2 automatically
Browse files Browse the repository at this point in the history
metrics: install dashboard v2 (fix var)
  • Loading branch information
fmartingr committed Dec 13, 2024
1 parent 4247ec2 commit 56a526f
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions deployment/terraform/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"net"
"net/http"
"os"
"regexp"
"strconv"
"strings"
"text/template"
Expand Down Expand Up @@ -352,6 +353,29 @@ func (t *Terraform) setupMetrics(extAgent *ssh.ExtAgent) error {
return fmt.Errorf("error while uploading dashboard_json: output: %s, error: %w", out, err)
}

// Download dashboard v2 from and upload it
dashboardv2Resp, err := http.Get("https://grafana.com/api/dashboards/15582/revisions/latest/download")
if err != nil {
return fmt.Errorf("error downloading latest grafana v2 dashboard: %w", err)
}
defer dashboardv2Resp.Body.Close()

var dashboardV2Contents bytes.Buffer

_, err = io.Copy(&dashboardV2Contents, dashboardv2Resp.Body)
if err != nil {
return fmt.Errorf("error while reading dashboard v2: %w", err)
}

// Removes the DS_PROMETHEUS variable requirement to allow grafana to use the only prometheus
// datasource available in the load-test envionment.
re := regexp.MustCompile(`,\r?\n\s+\"uid\":\s?\"\$\{DS_PROMETHEUS\}\"`)
result := re.ReplaceAll(dashboardV2Contents.Bytes(), []byte(``))

if out, err := sshc.Upload(bytes.NewReader(result), "/var/lib/grafana/dashboards/dashboard_v2.json", true); err != nil {
return fmt.Errorf("error while uploading dashboard v2: output: %s, error: %w", out, err)
}

// Upload coordinator metrics dashboard
coordConfig, err := coordinator.ReadConfig("")
if err != nil {
Expand Down

0 comments on commit 56a526f

Please sign in to comment.