Skip to content

Commit d8a9646

Browse files
pstibranygouthamve
authored andcommitted
Fix redirects on /ring page by using relative targets. (#1896)
* Fix redirects on /ring page by using relative targets. Signed-off-by: Peter Štibraný <peter.stibrany@grafana.com> * CHANGELOG.md Signed-off-by: Peter Štibraný <peter.stibrany@grafana.com> * CHANGELOG.md, correct order. Signed-off-by: Peter Štibraný <peter.stibrany@grafana.com> * Fix typo Signed-off-by: Peter Štibraný <peter.stibrany@grafana.com>
1 parent 335210d commit d8a9646

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* `ruler.rule-path` has been added to specify where the prometheus rule manager will sync rule files
1010
* `ruler.storage.type` has beem added to specify the rule store backend type, currently only the configdb.
1111
* `ruler.poll-interval` has been added to specify the interval in which to poll new rule groups.
12+
* [CHANGE] Use relative links from /ring page to make it work when used behind reverse proxy. #1896
1213
* [FEATURE] The distributor can now drop labels from samples (similar to the removal of the replica label for HA ingestion) per user via the `distributor.drop-label` flag. #1726
1314
* [BUGFIX] Fixed unnecessary CAS operations done by the HA tracker when the jitter is enabled. #1861
1415

pkg/ring/http.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ const tpl = `
5959
</table>
6060
<br>
6161
{{ if .ShowTokens }}
62-
<input type="button" value="Hide Ingester Tokens" onclick="window.location.href = '/ring'" />
62+
<input type="button" value="Hide Ingester Tokens" onclick="window.location.href = '?tokens=false' " />
6363
{{ else }}
64-
<input type="button" value="Show Ingester Tokens" onclick="window.location.href = '/ring?tokens=true'" />
64+
<input type="button" value="Show Ingester Tokens" onclick="window.location.href = '?tokens=true'" />
6565
{{ end }}
6666
<pre>{{ .Ring }}</pre>
6767
</form>
@@ -98,7 +98,13 @@ func (r *Ring) ServeHTTP(w http.ResponseWriter, req *http.Request) {
9898

9999
// Implement PRG pattern to prevent double-POST and work with CSRF middleware.
100100
// https://en.wikipedia.org/wiki/Post/Redirect/Get
101-
http.Redirect(w, req, req.RequestURI, http.StatusFound)
101+
102+
// http.Redirect() would convert our relative URL to absolute, which is not what we want.
103+
// Browser knows how to do that, and it also knows real URL. Furthermore it will also preserve tokens parameter.
104+
// Note that relative Location URLs are explicitly allowed by specification, so we're not doing anything wrong here.
105+
w.Header().Set("Location", "#")
106+
w.WriteHeader(http.StatusFound)
107+
102108
return
103109
}
104110

0 commit comments

Comments
 (0)