Skip to content

Commit fd8b3bb

Browse files
committed
Fix UI routing (observatorium#30)
1 parent db859f9 commit fd8b3bb

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

internal/server/server.go

+19-20
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,32 @@ func New(logger log.Logger, reg *prometheus.Registry, opts ...Option) Server {
6565

6666
registerProber(r, p)
6767

68-
uiPath := "/ui/metrics/v1"
69-
70-
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
71-
http.Redirect(w, r, path.Join(uiPath, "graph"), http.StatusMovedPermanently)
72-
})
73-
7468
r.Get("/metrics", func(w http.ResponseWriter, r *http.Request) {
7569
promhttp.InstrumentMetricHandler(reg, promhttp.HandlerFor(reg, promhttp.HandlerOpts{})).ServeHTTP(w, r)
7670
})
7771

7872
if options.metricsUIEndpoint != nil {
73+
uiPath := "/ui/metrics/v1"
74+
7975
r.Get(path.Join(uiPath, "*"),
8076
ins.newHandler("ui", proxy.New(logger, uiPath, options.metricsUIEndpoint, options.proxyOptions...)))
77+
78+
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
79+
http.Redirect(w, r, path.Join(uiPath, "graph"), http.StatusMovedPermanently)
80+
})
81+
82+
// NOTICE: Following redirects added to be compatible with existing Read UI.
83+
// Paths are explicitly specified to prevent unnecessary request to read handler.
84+
for _, p := range []string{
85+
"graph",
86+
"stores",
87+
"status",
88+
} {
89+
p := p
90+
r.Get(path.Join("/", p), func(w http.ResponseWriter, r *http.Request) {
91+
http.Redirect(w, r, path.Join(uiPath, p), http.StatusMovedPermanently)
92+
})
93+
}
8194
}
8295

8396
namespace := "/api/metrics/v1"
@@ -98,20 +111,6 @@ func New(logger log.Logger, reg *prometheus.Registry, opts ...Option) Server {
98111
ins.newHandler("write", proxy.New(logger, path.Join(namespace, writePath), options.metricsWriteEndpoint, options.proxyOptions...)))
99112
})
100113

101-
// NOTICE: Following redirects added to be compatible with existing Read UI.
102-
// Paths are explicitly specified to prevent unnecessary request to read handler.
103-
r.Get("/graph", func(w http.ResponseWriter, r *http.Request) {
104-
http.Redirect(w, r, "/ui/v1/metrics/graph", http.StatusMovedPermanently)
105-
})
106-
107-
r.Get("/stores", func(w http.ResponseWriter, r *http.Request) {
108-
http.Redirect(w, r, "/ui/v1/metrics/stores", http.StatusMovedPermanently)
109-
})
110-
111-
r.Get("/status", func(w http.ResponseWriter, r *http.Request) {
112-
http.Redirect(w, r, "/ui/v1/metrics/status", http.StatusMovedPermanently)
113-
})
114-
115114
p.Healthy()
116115

117116
return Server{

0 commit comments

Comments
 (0)