Redirect /graph to /query in new UI, preserving params

Signed-off-by: Julius Volz <julius.volz@gmail.com>
This commit is contained in:
Julius Volz 2024-09-04 21:21:29 +02:00
parent 8ee70c5fa0
commit d0ee5427bd
1 changed files with 33 additions and 4 deletions

View File

@ -63,8 +63,9 @@ import (
"github.com/prometheus/prometheus/web/ui"
)
// Paths that are handled by the React / Reach router that should all be served the main React app's index.html.
var reactRouterPaths = []string{
// Paths handled by the React router that should all serve the main React app's index.html,
// no matter if agent mode is enabled or not.
var oldUIReactRouterPaths = []string{
"/config",
"/flags",
"/service-discovery",
@ -72,16 +73,31 @@ var reactRouterPaths = []string{
"/targets",
}
var newUIReactRouterPaths = []string{
"/config",
"/flags",
"/service-discovery",
"/alertmanager-discovery",
"/status",
"/targets",
}
// Paths that are handled by the React router when the Agent mode is set.
var reactRouterAgentPaths = []string{
"/agent",
}
// Paths that are handled by the React router when the Agent mode is not set.
var reactRouterServerPaths = []string{
var oldUIReactRouterServerPaths = []string{
"/alerts",
"/graph",
"/query",
"/rules",
"/tsdb-status",
}
var newUIReactRouterServerPaths = []string{
"/alerts",
"/query", // The old /graph redirects to /query on the server side.
"/rules",
"/tsdb-status",
}
@ -382,6 +398,12 @@ func New(logger log.Logger, o *Options) *Handler {
http.Redirect(w, r, path.Join(o.ExternalURL.Path, homePage), http.StatusFound)
})
if o.UseNewUI {
router.Get("/graph", func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, path.Join(o.ExternalURL.Path, "/query?"+r.URL.RawQuery), http.StatusFound)
})
}
reactAssetsRoot := "/static/react-app"
if h.options.UseNewUI {
reactAssetsRoot = "/static/mantine-ui"
@ -426,6 +448,13 @@ func New(logger log.Logger, o *Options) *Handler {
}
// Serve the React app.
reactRouterPaths := oldUIReactRouterPaths
reactRouterServerPaths := oldUIReactRouterServerPaths
if h.options.UseNewUI {
reactRouterPaths = newUIReactRouterPaths
reactRouterServerPaths = newUIReactRouterServerPaths
}
for _, p := range reactRouterPaths {
router.Get(p, serveReactApp)
}