Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add base_url_gap for Grafana #1141

Merged
merged 7 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/config/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func (l *LokiConfig) Validate() error {

type GrafanaConfig struct {
BaseUrl *string `toml:"base_url"`
BaseUrlCI *string `toml:"base_url_github_ci"` // URL of GAP proxy used on CI for Grafana
DashboardUrl *string `toml:"dashboard_url"`
DashboardUID *string `toml:"dashboard_uid"` // UID of the dashboard to put annotations on
BearerToken *string `toml:"-"`
Expand Down
39 changes: 23 additions & 16 deletions lib/logstream/logstream_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,6 @@ func (h *LokiLogHandler) GetLogLocation(consumers map[string]*ContainerLogConsum
return "", errors.New("no Loki consumers found")
}

// if no Grafana URL has been set lets at least print query parameters that can be manually added to the dashboard url
baseUrl := ""
if h.loggingConfig.Grafana != nil && h.loggingConfig.Grafana.BaseUrl != nil {
baseUrl = *h.loggingConfig.Grafana.BaseUrl
baseUrl = strings.TrimSuffix(baseUrl, "/")
baseUrl = baseUrl + "/"
}

dabshoardUrl := ""
if h.loggingConfig.Grafana != nil && h.loggingConfig.Grafana.DashboardUrl != nil {
dabshoardUrl = *h.loggingConfig.Grafana.DashboardUrl
Expand Down Expand Up @@ -207,17 +199,32 @@ func (h *LokiLogHandler) GetLogLocation(consumers map[string]*ContainerLogConsum
sb.WriteString(fmt.Sprintf("&var-test=%s", testName))
}

var shorteningErr error
// try to shorten the URL only if we have all the required configuration parameters
if baseUrl != "" && dabshoardUrl != "" && h.loggingConfig.Grafana.BearerToken != nil {
var shortened string
shortened, shorteningErr = ShortenUrl(baseUrl, sb.String(), *h.loggingConfig.Grafana.BearerToken)
if shorteningErr == nil {
h.grafanaUrl = shortened
// Use short Grafana URL only in CI
if os.Getenv("CI") == "true" {
if h.loggingConfig.Grafana == nil || h.loggingConfig.Grafana.BaseUrlCI == nil {
return "", errors.New("grafana base URL for CI is not set in logging config")
}
baseUrl := *h.loggingConfig.Grafana.BaseUrlCI
baseUrl = strings.TrimSuffix(baseUrl, "/")
baseUrl = baseUrl + "/"

// try to shorten the URL only if we have all the required configuration parameters
shortUrl, err := ShortenUrl(baseUrl, sb.String(), *h.loggingConfig.Grafana.BearerToken)
if err != nil {
return "", err
}
h.grafanaUrl = shortUrl
} else {
if h.loggingConfig.Grafana == nil || h.loggingConfig.Grafana.BaseUrl == nil {
h.grafanaUrl = sb.String()
return h.grafanaUrl, nil
}
url := *h.loggingConfig.Grafana.BaseUrl
url = strings.TrimSuffix(url, "/")
h.grafanaUrl = url + "/" + sb.String()
}

return h.grafanaUrl, shorteningErr
return h.grafanaUrl, nil
}

func (h LokiLogHandler) GetTarget() LogTarget {
Expand Down
Loading