Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

query/rule: improve web.route-prefix handling #2208

Merged
merged 1 commit into from
Mar 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions cmd/thanos/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"math"
"net/http"
"path"
"strings"
"time"

"github.com/go-kit/kit/log"
Expand Down Expand Up @@ -324,11 +325,15 @@ func runQuery(
{
router := route.New()

// RoutePrefix must always start with '/'.
webRoutePrefix = "/" + strings.Trim(webRoutePrefix, "/")

// Redirect from / to /webRoutePrefix.
if webRoutePrefix != "" {
if webRoutePrefix != "/" {
router.Get("/", func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, webRoutePrefix, http.StatusFound)
})
router = router.WithPrefix(webRoutePrefix)
}

flagsMap := map[string]string{
Expand All @@ -338,7 +343,7 @@ func runQuery(
}

ins := extpromhttp.NewInstrumentationMiddleware(reg)
ui.NewQueryUI(logger, reg, stores, flagsMap).Register(router.WithPrefix(webRoutePrefix), ins)
ui.NewQueryUI(logger, reg, stores, flagsMap).Register(router, ins)

api := v1.NewAPI(logger, reg, engine, queryableCreator, enableAutodownsampling, enablePartialResponse, replicaLabels, instantDefaultMaxSourceResolution)

Expand Down
8 changes: 6 additions & 2 deletions cmd/thanos/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -558,11 +558,15 @@ func runRule(
{
router := route.New()

// RoutePrefix must always start with '/'.
webRoutePrefix = "/" + strings.Trim(webRoutePrefix, "/")

// Redirect from / to /webRoutePrefix.
if webRoutePrefix != "" {
if webRoutePrefix != "/" {
router.Get("/", func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, webRoutePrefix, http.StatusFound)
})
router = router.WithPrefix(webRoutePrefix)
}

router.WithPrefix(webRoutePrefix).Post("/-/reload", func(w http.ResponseWriter, r *http.Request) {
Expand All @@ -577,7 +581,7 @@ func runRule(

ins := extpromhttp.NewInstrumentationMiddleware(reg)

ui.NewRuleUI(logger, reg, ruleMgr, alertQueryURL.String(), flagsMap).Register(router.WithPrefix(webRoutePrefix), ins)
ui.NewRuleUI(logger, reg, ruleMgr, alertQueryURL.String(), flagsMap).Register(router, ins)

api := v1.NewAPI(logger, reg, ruleMgr)
api.Register(router.WithPrefix(path.Join(webRoutePrefix, "/api/v1")), tracer, logger, ins)
Expand Down