mirror of
https://github.com/grafana/grafana.git
synced 2024-11-25 10:20:29 -06:00
Alerting: Only append /alertmanager
when sending alerts to mimir targets if not already present (#85543)
Don't append alertmanager if not present
This commit is contained in:
parent
5687243d0b
commit
623ee3a2be
@ -6,6 +6,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"path"
|
||||
"sort"
|
||||
"sync"
|
||||
"time"
|
||||
@ -270,7 +271,10 @@ func (d *AlertsRouter) buildExternalURL(ds *datasources.DataSource) (string, err
|
||||
if parsed.Path == "" {
|
||||
parsed.Path = "/"
|
||||
}
|
||||
parsed = parsed.JoinPath("/alertmanager")
|
||||
lastSegment := path.Base(parsed.Path)
|
||||
if lastSegment != "alertmanager" {
|
||||
parsed = parsed.JoinPath("/alertmanager")
|
||||
}
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
@ -540,6 +540,42 @@ func TestBuildExternalURL(t *testing.T) {
|
||||
},
|
||||
expectedURL: "https://localhost:9000/path/to/am",
|
||||
},
|
||||
{
|
||||
name: "do not add /alertmanager to path when last segment already contains it",
|
||||
ds: &datasources.DataSource{
|
||||
URL: "https://localhost:9000/path/to/alertmanager",
|
||||
JsonData: func() *simplejson.Json {
|
||||
r := simplejson.New()
|
||||
r.Set("implementation", "mimir")
|
||||
return r
|
||||
}(),
|
||||
},
|
||||
expectedURL: "https://localhost:9000/path/to/alertmanager",
|
||||
},
|
||||
{
|
||||
name: "add /alertmanager to path when last segment does not exactly match",
|
||||
ds: &datasources.DataSource{
|
||||
URL: "https://localhost:9000/path/to/alertmanagerasdf",
|
||||
JsonData: func() *simplejson.Json {
|
||||
r := simplejson.New()
|
||||
r.Set("implementation", "mimir")
|
||||
return r
|
||||
}(),
|
||||
},
|
||||
expectedURL: "https://localhost:9000/path/to/alertmanagerasdf/alertmanager",
|
||||
},
|
||||
{
|
||||
name: "add /alertmanager to path when exists but is not last segment",
|
||||
ds: &datasources.DataSource{
|
||||
URL: "https://localhost:9000/alertmanager/path/to/am",
|
||||
JsonData: func() *simplejson.Json {
|
||||
r := simplejson.New()
|
||||
r.Set("implementation", "mimir")
|
||||
return r
|
||||
}(),
|
||||
},
|
||||
expectedURL: "https://localhost:9000/alertmanager/path/to/am/alertmanager",
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user