Skip to content
This repository was archived by the owner on May 30, 2022. It is now read-only.

Commit

Permalink
Split grafana API url from embeddable url
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonkopliku committed Feb 21, 2022
1 parent 6c682a4 commit af803c3
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions internal/grafana/grafana.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,17 @@ import (
var nodeDashboard []byte

type Config struct {
URL string
User string
Password string
PublicURL string
ApiURL string
User string
Password string
}

func (config Config) BaseUrl() string {
if config.PublicURL != "" {
return config.PublicURL
}
return config.ApiURL
}

func InitGrafana(ctx context.Context, config *Config) error {
Expand All @@ -36,7 +44,7 @@ func InitGrafana(ctx context.Context, config *Config) error {
return err
}

dashboardsURL := fmt.Sprintf("%s/%s", config.URL, "api/dashboards/db")
dashboardsURL := fmt.Sprintf("%s/%s", config.ApiURL, "api/dashboards/db")
req, err := http.NewRequest("POST", dashboardsURL, bytes.NewBuffer(nodeDashboard))
if err != nil {
return err
Expand Down Expand Up @@ -78,7 +86,7 @@ func createToken(config *Config) (string, error) {
"secondsToLive": 60,
})

u, err := url.Parse(config.URL)
u, err := url.Parse(config.ApiURL)
if err != nil {
log.Fatal("Invalid Grafana URL provided")
}
Expand Down

0 comments on commit af803c3

Please sign in to comment.