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

UI: Fix infinite redirection loop on / #4208

Merged
merged 3 commits into from
May 20, 2021
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
14 changes: 14 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: 2
updates:
- package-ecosystem: "gomod"
directory: "/"
vendor: false
schedule:
interval: "weekly"
labels: ["dependencies"]
- package-ecosystem: "docker"
directory: "/"
schedule:
interval: "weekly"
labels: ["dependencies"]

4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# By default we pin to amd64 sha. Use make docker to automatically adjust for arm64 versions.
ARG SHA="fca3819d670cdaee0d785499fda202ea01c0640ca0803d26ae6dbf2a1c8c041c"
FROM quay.io/prometheus/busybox@sha256:${SHA}
ARG BASE_DOCKER_SHA="14d68ca3d69fceaa6224250c83d81d935c053fb13594c811038c461194599973"
FROM quay.io/prometheus/busybox@sha256:${BASE_DOCKER_SHA}
LABEL maintainer="The Thanos Authors"

COPY /thanos_tmp_for_docker /bin/thanos
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile.multi-stage
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# By default we pin to amd64 sha. Use make docker to automatically adjust for arm64 versions.
ARG SHA="fca3819d670cdaee0d785499fda202ea01c0640ca0803d26ae6dbf2a1c8c041c"
ARG BASE_DOCKER_SHA="14d68ca3d69fceaa6224250c83d81d935c053fb13594c811038c461194599973"
FROM golang:1.16-alpine3.12 as builder

WORKDIR $GOPATH/src/github.com/thanos-io/thanos
Expand All @@ -16,7 +16,7 @@ RUN git update-index --refresh; make build

# -----------------------------------------------------------------------------

FROM quay.io/prometheus/busybox@sha256:${SHA}
FROM quay.io/prometheus/busybox@sha256:${BASE_DOCKER_SHA}
LABEL maintainer="The Thanos Authors"

COPY --from=builder /go/bin/thanos /bin/thanos
Expand Down
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ DOCKER_IMAGE_REPO ?= quay.io/thanos/thanos
DOCKER_IMAGE_TAG ?= $(subst /,-,$(shell git rev-parse --abbrev-ref HEAD))-$(shell date +%Y-%m-%d)-$(shell git rev-parse --short HEAD)
DOCKER_CI_TAG ?= test

SHA=''
BASE_DOCKER_SHA=''
arch = $(shell uname -m)
# Run `DOCKER_CLI_EXPERIMENTAL=enabled docker manifest inspect quay.io/prometheus/busybox:latest` to get SHA or
# just visit https://quay.io/repository/prometheus/busybox?tag=latest&tab=tags.
# TODO(bwplotka): Pinning is important but somehow quay kills the old images, so make sure to update regularly (dependabot?)
# Update at 2020.2.01
# TODO(bwplotka): Pinning is important but somehow quay kills the old images, so make sure to update regularly.
# Update at 2021.6.07
ifeq ($(arch), x86_64)
# amd64
SHA="14d68ca3d69fceaa6224250c83d81d935c053fb13594c811038c461194599973"
BASE_DOCKER_SHA="de4af55df1f648a334e16437c550a2907e0aed4f0b0edf454b0b215a9349bdbb"
else ifeq ($(arch), armv8)
# arm64
SHA="4dd2d3bba195563e6cb2b286f23dc832d0fda6c6662e6de2e86df454094b44d8"
BASE_DOCKER_SHA="5591971699f6cf8abf6776495385e9d62751111a8cba56bf4946cf1d0de425ed"
else
echo >&2 "only support amd64 or arm64 arch" && exit 1
endif
Expand Down Expand Up @@ -147,7 +147,7 @@ docker: build
@echo ">> copying Thanos from $(PREFIX) to ./thanos_tmp_for_docker"
@cp $(PREFIX)/thanos ./thanos_tmp_for_docker
@echo ">> building docker image 'thanos'"
@docker build -t "thanos" --build-arg SHA=$(SHA) .
@docker build -t "thanos" --build-arg BASE_DOCKER_SHA=$(BASE_DOCKER_SHA) .
@rm ./thanos_tmp_for_docker
else
docker: docker-multi-stage
Expand All @@ -157,7 +157,7 @@ endif
docker-multi-stage: ## Builds 'thanos' docker image using multi-stage.
docker-multi-stage:
@echo ">> building docker image 'thanos' with Dockerfile.multi-stage"
@docker build -f Dockerfile.multi-stage -t "thanos" --build-arg SHA=$(SHA) .
@docker build -f Dockerfile.multi-stage -t "thanos" --build-arg BASE_DOCKER_SHA=$(BASE_DOCKER_SHA) .

.PHONY: docker-push
docker-push: ## Pushes 'thanos' docker image build to "$(DOCKER_IMAGE_REPO):$(DOCKER_IMAGE_TAG)".
Expand Down
7 changes: 2 additions & 5 deletions pkg/ui/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,8 @@ func (b *Bucket) Register(r *route.Router, registerNewUI bool, ins extpromhttp.I
// 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.Get("/", func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, path.Join(GetWebPrefix(b.logger, b.externalPrefix, b.prefixHeader, r), b.uiPrefix), http.StatusFound)
prefix := GetWebPrefix(b.logger, b.externalPrefix, b.prefixHeader, r)
http.Redirect(w, r, path.Join("/", prefix, p)+"?"+r.URL.RawQuery, http.StatusFound)
})

registerReactApp(r, ins, b.BaseUI)
Expand Down
8 changes: 2 additions & 6 deletions pkg/ui/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,14 @@ func queryTmplFuncs() template.FuncMap {

// Register registers new GET routes for subpages and redirects from / to /graph.
func (q *Query) Register(r *route.Router, ins extpromhttp.InstrumentationMiddleware) {
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, path.Join(GetWebPrefix(q.logger, q.externalPrefix, q.prefixHeader, r), "/graph"), http.StatusFound)
})

r.Get("/classic/", func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, path.Join(GetWebPrefix(q.logger, q.externalPrefix, q.prefixHeader, r), "/classic/graph"), http.StatusFound)
http.Redirect(w, r, path.Join("/", GetWebPrefix(q.logger, q.externalPrefix, q.prefixHeader, r), "/classic/graph"), 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(q.logger, q.externalPrefix, q.prefixHeader, r), strings.TrimPrefix(p, "/new"))+"?"+r.URL.RawQuery, http.StatusFound)
http.Redirect(w, r, path.Join("/", GetWebPrefix(q.logger, q.externalPrefix, q.prefixHeader, r), p)+"?"+r.URL.RawQuery, http.StatusFound)
})

r.Get("/classic/graph", instrf("graph", ins, q.graph))
Expand Down
9 changes: 2 additions & 7 deletions pkg/ui/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"net/http"
"path"
"regexp"
"strings"
"time"

"github.com/go-kit/kit/log"
Expand Down Expand Up @@ -158,18 +157,14 @@ func (ru *Rule) rules(w http.ResponseWriter, r *http.Request) {
}

func (ru *Rule) Register(r *route.Router, ins extpromhttp.InstrumentationMiddleware) {
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, path.Join(GetWebPrefix(ru.logger, ru.externalPrefix, ru.prefixHeader, r), "/alerts"), http.StatusFound)
})

r.Get("/classic/", func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, path.Join(GetWebPrefix(ru.logger, ru.externalPrefix, ru.prefixHeader, r), "/classic/alerts"), http.StatusFound)
http.Redirect(w, r, path.Join("/", GetWebPrefix(ru.logger, ru.externalPrefix, ru.prefixHeader, r), "/classic/alerts"), 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(ru.logger, ru.externalPrefix, ru.prefixHeader, r), strings.TrimPrefix(p, "/new"))+"?"+r.URL.RawQuery, http.StatusFound)
http.Redirect(w, r, path.Join("/", GetWebPrefix(ru.logger, ru.externalPrefix, ru.prefixHeader, r), p)+"?"+r.URL.RawQuery, http.StatusFound)
})

r.Get("/classic/alerts", instrf("alerts", ins, ru.alerts))
Expand Down
1 change: 1 addition & 0 deletions pkg/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
)

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