Skip to content

Fix redirects on /ring page by using relative targets. #1896

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

Merged
merged 4 commits into from
Dec 11, 2019
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* `ruler.rule-path` has been added to specify where the prometheus rule manager will sync rule files
* `ruler.storage.type` has beem added to specify the rule store backend type, currently only the configdb.
* `ruler.poll-interval` has been added to specify the interval in which to poll new rule groups.
* [CHANGE] Use relative links from /ring page to make it work when used behind reverse proxy. #1896
* [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
* [BUGFIX] Fixed unnecessary CAS operations done by the HA tracker when the jitter is enabled. #1861

Expand Down
12 changes: 9 additions & 3 deletions pkg/ring/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ const tpl = `
</table>
<br>
{{ if .ShowTokens }}
<input type="button" value="Hide Ingester Tokens" onclick="window.location.href = '/ring'" />
<input type="button" value="Hide Ingester Tokens" onclick="window.location.href = '?tokens=false' " />
{{ else }}
<input type="button" value="Show Ingester Tokens" onclick="window.location.href = '/ring?tokens=true'" />
<input type="button" value="Show Ingester Tokens" onclick="window.location.href = '?tokens=true'" />
{{ end }}
<pre>{{ .Ring }}</pre>
</form>
Expand Down Expand Up @@ -98,7 +98,13 @@ func (r *Ring) ServeHTTP(w http.ResponseWriter, req *http.Request) {

// Implement PRG pattern to prevent double-POST and work with CSRF middleware.
// https://en.wikipedia.org/wiki/Post/Redirect/Get
http.Redirect(w, req, req.RequestURI, http.StatusFound)

// http.Redirect() would convert our relative URL to absolute, which is not what we want.
// Browser knows how to do that, and it also knows real URL. Furthermore it will also preserve tokens parameter.
// Note that relative Location URLs are explicitly allowed by specification, so we're not doing anything wrong here.
w.Header().Set("Location", "#")
w.WriteHeader(http.StatusFound)

return
}

Expand Down