mirror of
https://github.com/grafana/grafana.git
synced 2024-11-29 12:14:08 -06:00
Alerting: Fix client to external Alertmanager to correctly build URL for Mimir Alertmanager (#63676)
This commit is contained in:
parent
dd5b115164
commit
98e1aeaebd
@ -242,6 +242,20 @@ func (d *AlertsRouter) buildExternalURL(ds *datasources.DataSource) (string, err
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to parse alertmanager datasource url: %w", err)
|
||||
}
|
||||
|
||||
// If this is a Mimir or Cortex implementation, the Alert API is under a different path than config API
|
||||
if ds.JsonData != nil {
|
||||
impl := ds.JsonData.Get("implementation").MustString("")
|
||||
switch impl {
|
||||
case "mimir", "cortex":
|
||||
if parsed.Path == "" {
|
||||
parsed.Path = "/"
|
||||
}
|
||||
parsed = parsed.JoinPath("/alertmanager")
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
// if basic auth is enabled we need to build the url with basic auth baked in
|
||||
if !ds.BasicAuth {
|
||||
return parsed.String(), nil
|
||||
|
@ -491,6 +491,42 @@ func TestBuildExternalURL(t *testing.T) {
|
||||
},
|
||||
expectedURL: "http://localhost:9000/path/to/am",
|
||||
},
|
||||
{
|
||||
name: "adds /alertmanager to path when implementation is mimir",
|
||||
ds: &datasources.DataSource{
|
||||
URL: "https://localhost:9000",
|
||||
JsonData: func() *simplejson.Json {
|
||||
r := simplejson.New()
|
||||
r.Set("implementation", "mimir")
|
||||
return r
|
||||
}(),
|
||||
},
|
||||
expectedURL: "https://localhost:9000/alertmanager",
|
||||
},
|
||||
{
|
||||
name: "adds /alertmanager to path when implementation is cortex",
|
||||
ds: &datasources.DataSource{
|
||||
URL: "https://localhost:9000/path/to/am",
|
||||
JsonData: func() *simplejson.Json {
|
||||
r := simplejson.New()
|
||||
r.Set("implementation", "cortex")
|
||||
return r
|
||||
}(),
|
||||
},
|
||||
expectedURL: "https://localhost:9000/path/to/am/alertmanager",
|
||||
},
|
||||
{
|
||||
name: "do nothing when implementation is prometheus",
|
||||
ds: &datasources.DataSource{
|
||||
URL: "https://localhost:9000/path/to/am",
|
||||
JsonData: func() *simplejson.Json {
|
||||
r := simplejson.New()
|
||||
r.Set("implementation", "prometheus")
|
||||
return r
|
||||
}(),
|
||||
},
|
||||
expectedURL: "https://localhost:9000/path/to/am",
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user