Skip to content

Commit 511f497

Browse files
committed
update bucket ui to use the react app by default
Signed-off-by: Augustin Husson <[email protected]>
1 parent 0c01e56 commit 511f497

File tree

7 files changed

+62
-57
lines changed

7 files changed

+62
-57
lines changed

cmd/thanos/compact.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -481,10 +481,10 @@ func runCompact(
481481
r := route.New()
482482

483483
ins := extpromhttp.NewInstrumentationMiddleware(reg, nil)
484-
compactorView.Register(r, true, ins)
484+
compactorView.Register(r, ins)
485485

486486
global := ui.NewBucketUI(logger, conf.label, conf.webConf.externalPrefix, conf.webConf.prefixHeaderName, "/global", component)
487-
global.Register(r, false, ins)
487+
global.Register(r, ins)
488488

489489
// Configure Request Logging for HTTP calls.
490490
opts := []logging.Option{logging.WithDecider(func(_ string, _ error) logging.Decision {

cmd/thanos/store.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ func runStore(
417417
ins := extpromhttp.NewInstrumentationMiddleware(reg, nil)
418418

419419
compactorView := ui.NewBucketUI(logger, "", externalPrefix, prefixHeader, "/loaded", component)
420-
compactorView.Register(r, true, ins)
420+
compactorView.Register(r, ins)
421421

422422
// Configure Request Logging for HTTP calls.
423423
logMiddleware := logging.NewHTTPServerMiddleware(logger, httpLogOpts...)

cmd/thanos/tools_bucket.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ func registerBucketWeb(app extkingpin.AppClause, objStoreConfig *extflag.PathOrC
372372
ins := extpromhttp.NewInstrumentationMiddleware(reg, nil)
373373

374374
bucketUI := ui.NewBucketUI(logger, *label, *webExternalPrefix, *webPrefixHeaderName, "", component.Bucket)
375-
bucketUI.Register(router, true, ins)
375+
bucketUI.Register(router, ins)
376376

377377
flagsMap := getFlagsMap(cmd.Flags())
378378

pkg/ui/bindata.go

+34-34
Large diffs are not rendered by default.

pkg/ui/bucket.go

+20-18
Original file line numberDiff line numberDiff line change
@@ -48,28 +48,30 @@ func NewBucketUI(logger log.Logger, label, externalPrefix, prefixHeader, uiPrefi
4848
}
4949

5050
// Register registers http routes for bucket UI.
51-
func (b *Bucket) Register(r *route.Router, registerNewUI bool, ins extpromhttp.InstrumentationMiddleware) {
52-
instrf := func(name string, next func(w http.ResponseWriter, r *http.Request)) http.HandlerFunc {
53-
return ins.NewHandler(b.externalPrefix+name, http.HandlerFunc(next))
54-
}
55-
r.WithPrefix(b.uiPrefix).Get("/", instrf("root", b.root))
56-
r.WithPrefix(b.uiPrefix).Get("/static/*filepath", instrf("static", b.serveStaticAsset))
57-
if registerNewUI {
58-
// Make sure that "<path-prefix>/new" is redirected to "<path-prefix>/new/" and
59-
// not just the naked "/new/", which would be the default behavior of the router
60-
// with the "RedirectTrailingSlash" option (https://godoc.org/github.com/julienschmidt/httprouter#Router.RedirectTrailingSlash),
61-
// and which breaks users with a --web.route-prefix that deviates from the path derived
62-
// from the external URL.
63-
r.Get("/new", func(w http.ResponseWriter, r *http.Request) {
64-
http.Redirect(w, r, path.Join(GetWebPrefix(b.logger, b.externalPrefix, b.prefixHeader, r), "new")+"/", http.StatusFound)
65-
})
66-
r.Get("/new/*filepath", instrf("react-static", b.serveReactUI))
51+
func (b *Bucket) Register(r *route.Router, ins extpromhttp.InstrumentationMiddleware) {
52+
redirectPath := "/blocks"
53+
if len(b.uiPrefix) > 0 {
54+
redirectPath = b.uiPrefix
6755
}
56+
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
57+
http.Redirect(w, r, path.Join(GetWebPrefix(b.logger, b.externalPrefix, b.prefixHeader, r), redirectPath), http.StatusFound)
58+
})
59+
// Redirect the original React UI's path (under "/new") to its new path at the root.
60+
r.Get("/new/*path", func(w http.ResponseWriter, r *http.Request) {
61+
p := route.Param(r.Context(), "path")
62+
http.Redirect(w, r, path.Join(GetWebPrefix(b.logger, b.externalPrefix, b.prefixHeader, r), strings.TrimPrefix(p, "/new"))+"?"+r.URL.RawQuery, http.StatusFound)
63+
})
64+
65+
r.Get(path.Join("/classic", b.uiPrefix), instrf("bucket", ins, b.bucket))
66+
r.WithPrefix(b.uiPrefix).Get("/classic/static/*filepath", instrf("static", ins, b.serveStaticAsset))
67+
registerReactApp(r, ins, b.BaseUI)
6868
}
6969

7070
// Handle / of bucket UIs.
71-
func (b *Bucket) root(w http.ResponseWriter, r *http.Request) {
72-
b.executeTemplate(w, "bucket.html", GetWebPrefix(b.logger, path.Join(b.externalPrefix, strings.TrimPrefix(b.uiPrefix, "/")), b.prefixHeader, r), b)
71+
func (b *Bucket) bucket(w http.ResponseWriter, r *http.Request) {
72+
prefix := GetWebPrefix(b.logger, path.Join(b.externalPrefix, strings.TrimPrefix(b.uiPrefix, "/")), b.prefixHeader, r)
73+
b.logger.Log(prefix)
74+
b.executeTemplate(w, "bucket.html", prefix, b)
7375
}
7476

7577
func (b *Bucket) Set(blocks []metadata.Meta, err error) {

pkg/ui/react-app/src/thanos/Navbar.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ const navConfig: { [component: string]: (NavConfig | NavDropDown)[] } = {
8383
const defaultClassicUIRoute: { [component: string]: string } = {
8484
query: '/classic/graph',
8585
rule: '/classic/alerts',
86-
bucket: '/',
86+
bucket: '/classic',
8787
compact: '/classic/loaded',
8888
store: '/classic/loaded',
8989
};

pkg/ui/ui.go

+3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@ import (
2424

2525
var reactRouterPaths = []string{
2626
"/alerts",
27+
"/blocks",
2728
"/config",
2829
"/flags",
30+
"/global",
2931
"/graph",
32+
"/loaded",
3033
"/rules",
3134
"/service-discovery",
3235
"/status",

0 commit comments

Comments
 (0)