mirror of https://github.com/prometheus/prometheus
Merge pull request #4256 from prometheus/routeprefix
web: restore old path prefix behaviorpull/4273/head
commit
97767eb581
|
@ -770,13 +770,7 @@ func tmplFuncs(consolesPath string, opts *Options) template_text.FuncMap {
|
||||||
return time.Since(t) / time.Millisecond * time.Millisecond
|
return time.Since(t) / time.Millisecond * time.Millisecond
|
||||||
},
|
},
|
||||||
"consolesPath": func() string { return consolesPath },
|
"consolesPath": func() string { return consolesPath },
|
||||||
"pathPrefix": func() string {
|
"pathPrefix": func() string { return opts.ExternalURL.Path },
|
||||||
if opts.RoutePrefix == "/" {
|
|
||||||
return ""
|
|
||||||
} else {
|
|
||||||
return opts.RoutePrefix
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"buildVersion": func() string { return opts.Version.Revision },
|
"buildVersion": func() string { return opts.Version.Revision },
|
||||||
"stripLabels": func(lset map[string]string, labels ...string) map[string]string {
|
"stripLabels": func(lset map[string]string, labels ...string) map[string]string {
|
||||||
for _, ln := range labels {
|
for _, ln := range labels {
|
||||||
|
|
|
@ -319,42 +319,6 @@ func TestRoutePrefix(t *testing.T) {
|
||||||
testutil.Ok(t, err)
|
testutil.Ok(t, err)
|
||||||
testutil.Equals(t, http.StatusOK, resp.StatusCode)
|
testutil.Equals(t, http.StatusOK, resp.StatusCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPathPrefix(t *testing.T) {
|
|
||||||
|
|
||||||
tests := []struct {
|
|
||||||
routePrefix string
|
|
||||||
pathPrefix string
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
routePrefix: "/",
|
|
||||||
// If we have pathPrefix as "/", URL in UI gets "//"" as prefix,
|
|
||||||
// hence doesn't remain relative path anymore.
|
|
||||||
pathPrefix: "",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
routePrefix: "/prometheus",
|
|
||||||
pathPrefix: "/prometheus",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
routePrefix: "/p1/p2/p3/p4",
|
|
||||||
pathPrefix: "/p1/p2/p3/p4",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, test := range tests {
|
|
||||||
opts := &Options{
|
|
||||||
RoutePrefix: test.routePrefix,
|
|
||||||
}
|
|
||||||
|
|
||||||
pathPrefix := tmplFuncs("", opts)["pathPrefix"].(func() string)
|
|
||||||
pp := pathPrefix()
|
|
||||||
|
|
||||||
testutil.Equals(t, test.pathPrefix, pp)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestDebugHandler(t *testing.T) {
|
func TestDebugHandler(t *testing.T) {
|
||||||
for _, tc := range []struct {
|
for _, tc := range []struct {
|
||||||
prefix, url string
|
prefix, url string
|
||||||
|
|
Loading…
Reference in New Issue