vmalert: fix bug with relative links in UI

https://github.com/VictoriaMetrics/VictoriaMetrics/issues/2167
Signed-off-by: hagen1778 <roman@victoriametrics.com>
This commit is contained in:
hagen1778 2022-02-08 21:03:42 +02:00 committed by Nikolay
parent db8c4054e5
commit 4e722c459b
3 changed files with 439 additions and 429 deletions

View file

@ -25,6 +25,9 @@ var (
func initLinks() {
pathPrefix := httpserver.GetPathPrefix()
if pathPrefix == "" {
pathPrefix = "/"
}
apiLinks = [][2]string{
{path.Join(pathPrefix, "api/v1/groups"), "list all loaded groups and rules"},
{path.Join(pathPrefix, "api/v1/alerts"), "list all active alerts"},
@ -51,6 +54,11 @@ func (rh *requestHandler) handler(w http.ResponseWriter, r *http.Request) bool {
initLinks()
})
pathPrefix := httpserver.GetPathPrefix()
if pathPrefix == "" {
pathPrefix = "/"
}
switch r.URL.Path {
case "/":
if r.Method != "GET" {
@ -59,7 +67,7 @@ func (rh *requestHandler) handler(w http.ResponseWriter, r *http.Request) bool {
WriteWelcome(w)
return true
case "/alerts":
WriteListAlerts(w, rh.groupAlerts())
WriteListAlerts(w, pathPrefix, rh.groupAlerts())
return true
case "/groups":
WriteListGroups(w, rh.groups())
@ -113,7 +121,7 @@ func (rh *requestHandler) handler(w http.ResponseWriter, r *http.Request) bool {
}
// <groupID>/<alertID>/status
WriteAlert(w, alert)
WriteAlert(w, pathPrefix, alert)
return true
}
}

View file

@ -3,6 +3,7 @@
{% import (
"time"
"sort"
"path"
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmalert/tpl"
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmalert/notifier"
@ -120,7 +121,7 @@
{% endfunc %}
{% func ListAlerts(groupAlerts []GroupAlerts) %}
{% func ListAlerts(pathPrefix string, groupAlerts []GroupAlerts) %}
{%= tpl.Header("Alerts", navItems) %}
{% if len(groupAlerts) > 0 %}
<a class="btn btn-primary" role="button" onclick="collapseAll()">Collapse All</a>
@ -185,7 +186,7 @@
</td>
<td>{%s ar.Value %}</td>
<td>
<a href="/{%s g.ID %}/{%s ar.ID %}/status">Details</a>
<a href="{%s path.Join(pathPrefix, g.ID, ar.ID, "status") %}">Details</a>
</td>
</tr>
{% endfor %}
@ -262,7 +263,7 @@
{% endfunc %}
{% func Alert(alert *APIAlert) %}
{% func Alert(pathPrefix string, alert *APIAlert) %}
{%= tpl.Header("", navItems) %}
{%code
var labelKeys []string
@ -329,7 +330,7 @@
Group
</div>
<div class="col">
<a target="_blank" href="/groups#group-{%s alert.GroupID %}">{%s alert.GroupID %}</a>
<a target="_blank" href="{%s path.Join(pathPrefix,"groups") %}#group-{%s alert.GroupID %}">{%s alert.GroupID %}</a>
</div>
</div>
</div>

File diff suppressed because it is too large Load diff