mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
vmselect: cover special cases for vmalert's routing in single-node version (#2845)
* vmselect: cover special cases for vmalert's routing in single-node version * remove trailing `/` from requests * redirect to vmalert's home page when `/vmalert` is requested. Signed-off-by: hagen1778 <roman@victoriametrics.com> * vmalert: fix review comments Signed-off-by: hagen1778 <roman@victoriametrics.com> * Update app/vmselect/main.go Co-authored-by: Aliaksandr Valialkin <valyala@victoriametrics.com>
This commit is contained in:
parent
5d62f5a324
commit
da10962d4c
3 changed files with 7 additions and 7 deletions
|
@ -37,7 +37,7 @@ func initLinks() {
|
||||||
{"/-/reload", "reload configuration"},
|
{"/-/reload", "reload configuration"},
|
||||||
}
|
}
|
||||||
navItems = []tpl.NavItem{
|
navItems = []tpl.NavItem{
|
||||||
{Name: "vmalert", Url: "home"},
|
{Name: "vmalert", Url: "."},
|
||||||
{Name: "Groups", Url: "groups"},
|
{Name: "Groups", Url: "groups"},
|
||||||
{Name: "Alerts", Url: "alerts"},
|
{Name: "Alerts", Url: "alerts"},
|
||||||
{Name: "Notifiers", Url: "notifiers"},
|
{Name: "Notifiers", Url: "notifiers"},
|
||||||
|
@ -67,8 +67,9 @@ func (rh *requestHandler) handler(w http.ResponseWriter, r *http.Request) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
switch r.URL.Path {
|
switch r.URL.Path {
|
||||||
case "/", "/vmalert", "/vmalert/home":
|
case "/", "/vmalert", "/vmalert/":
|
||||||
if r.Method != "GET" {
|
if r.Method != "GET" {
|
||||||
|
httpserver.Errorf(w, r, "path %q supports only GET method", r.URL.Path)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
WriteWelcome(w, r)
|
WriteWelcome(w, r)
|
||||||
|
@ -146,6 +147,7 @@ func (rh *requestHandler) handler(w http.ResponseWriter, r *http.Request) bool {
|
||||||
// TODO: to remove in next versions
|
// TODO: to remove in next versions
|
||||||
|
|
||||||
if !strings.HasSuffix(r.URL.Path, "/status") {
|
if !strings.HasSuffix(r.URL.Path, "/status") {
|
||||||
|
httpserver.Errorf(w, r, "unsupported path requested: %q ", r.URL.Path)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
alert, err := rh.alertByPath(strings.TrimPrefix(r.URL.Path, "/api/v1/"))
|
alert, err := rh.alertByPath(strings.TrimPrefix(r.URL.Path, "/api/v1/"))
|
||||||
|
|
|
@ -52,7 +52,6 @@ func TestHandler(t *testing.T) {
|
||||||
t.Run("/", func(t *testing.T) {
|
t.Run("/", func(t *testing.T) {
|
||||||
getResp(ts.URL, nil, 200)
|
getResp(ts.URL, nil, 200)
|
||||||
getResp(ts.URL+"/vmalert", nil, 200)
|
getResp(ts.URL+"/vmalert", nil, 200)
|
||||||
getResp(ts.URL+"/vmalert/home", nil, 200)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("/api/v1/alerts", func(t *testing.T) {
|
t.Run("/api/v1/alerts", func(t *testing.T) {
|
||||||
|
|
|
@ -344,12 +344,11 @@ func selectHandler(qt *querytracer.Tracer, startTime time.Time, w http.ResponseW
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
if p.Suffix == "prometheus/vmalert" {
|
if path == "/vmalert" {
|
||||||
path := "../" + p.Suffix + "/"
|
http.Redirect(w, r, path+"/", http.StatusMovedPermanently)
|
||||||
http.Redirect(w, r, path, http.StatusMovedPermanently)
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(p.Suffix, "prometheus/vmalert/") {
|
if strings.HasPrefix(path, "/vmalert/") {
|
||||||
vmalertRequests.Inc()
|
vmalertRequests.Inc()
|
||||||
if len(*vmalertProxyURL) == 0 {
|
if len(*vmalertProxyURL) == 0 {
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
|
|
Loading…
Reference in a new issue