mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Remote Alertmanager(refactor): Only parse the URL once (#78631)
* Remote Alertmanager(refactor): Only parse the URL once Exactly what it says in the tin. Signed-off-by: gotjosh <josue.abreu@gmail.com> * use the existing tests Signed-off-by: gotjosh <josue.abreu@gmail.com> --------- Signed-off-by: gotjosh <josue.abreu@gmail.com>
This commit is contained in:
@@ -55,13 +55,18 @@ func NewAlertmanager(cfg AlertmanagerConfig, orgID int64) (*Alertmanager, error)
|
||||
}
|
||||
|
||||
if cfg.URL == "" {
|
||||
return nil, fmt.Errorf("empty URL for tenant %s", cfg.TenantID)
|
||||
return nil, fmt.Errorf("empty remote Alertmanager URL for tenant '%s'", cfg.TenantID)
|
||||
}
|
||||
|
||||
u, err := url.Parse(cfg.URL)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to parse remote Alertmanager URL: %w", err)
|
||||
}
|
||||
|
||||
logger := log.New("ngalert.remote.alertmanager")
|
||||
|
||||
mcCfg := &mimirClient.Config{
|
||||
Address: cfg.URL,
|
||||
URL: u,
|
||||
TenantID: cfg.TenantID,
|
||||
Password: cfg.BasicAuthPassword,
|
||||
Logger: logger,
|
||||
@@ -72,11 +77,6 @@ func NewAlertmanager(cfg AlertmanagerConfig, orgID int64) (*Alertmanager, error)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
u, err := url.Parse(cfg.URL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
u = u.JoinPath("/alertmanager", amclient.DefaultBasePath)
|
||||
transport := httptransport.NewWithClient(u.Host, u.Path, []string{u.Scheme}, &client)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user