Skip to content

Commit

Permalink
update bucket ui to use the react app by default
Browse files Browse the repository at this point in the history
Signed-off-by: Augustin Husson <husson.augustin@gmail.com>
  • Loading branch information
Nexucis committed Apr 20, 2021
1 parent 0c01e56 commit 2ab2a74
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 56 deletions.
4 changes: 2 additions & 2 deletions cmd/thanos/compact.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,10 +481,10 @@ func runCompact(
r := route.New()

ins := extpromhttp.NewInstrumentationMiddleware(reg, nil)
compactorView.Register(r, true, ins)
compactorView.Register(r, ins)

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

// Configure Request Logging for HTTP calls.
opts := []logging.Option{logging.WithDecider(func(_ string, _ error) logging.Decision {
Expand Down
2 changes: 1 addition & 1 deletion cmd/thanos/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ func runStore(
ins := extpromhttp.NewInstrumentationMiddleware(reg, nil)

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

// Configure Request Logging for HTTP calls.
logMiddleware := logging.NewHTTPServerMiddleware(logger, httpLogOpts...)
Expand Down
2 changes: 1 addition & 1 deletion cmd/thanos/tools_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ func registerBucketWeb(app extkingpin.AppClause, objStoreConfig *extflag.PathOrC
ins := extpromhttp.NewInstrumentationMiddleware(reg, nil)

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

flagsMap := getFlagsMap(cmd.Flags())

Expand Down
68 changes: 34 additions & 34 deletions pkg/ui/bindata.go

Large diffs are not rendered by default.

30 changes: 13 additions & 17 deletions pkg/ui/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,19 @@ func NewBucketUI(logger log.Logger, label, externalPrefix, prefixHeader, uiPrefi
}

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

r.WithPrefix(b.uiPrefix).Get("/classic", instrf("root", ins, b.root))
r.WithPrefix(b.uiPrefix).Get("/classic/static/*filepath", instrf("static", ins, b.serveStaticAsset))
registerReactApp(r, ins, b.BaseUI)
}

// Handle / of bucket UIs.
Expand Down
2 changes: 1 addition & 1 deletion pkg/ui/react-app/src/thanos/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const navConfig: { [component: string]: (NavConfig | NavDropDown)[] } = {
const defaultClassicUIRoute: { [component: string]: string } = {
query: '/classic/graph',
rule: '/classic/alerts',
bucket: '/',
bucket: '/classic',
compact: '/classic/loaded',
store: '/classic/loaded',
};
Expand Down
1 change: 1 addition & 0 deletions pkg/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

var reactRouterPaths = []string{
"/alerts",
"/blocks",
"/config",
"/flags",
"/graph",
Expand Down

0 comments on commit 2ab2a74

Please sign in to comment.