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

Implement redirect handler option. #622

Merged

Conversation

espears1
Copy link
Contributor

@espears1 espears1 commented Feb 8, 2021

This fixes #131 and a significant amount of content is discussed in that issue.

This PR adds a new redirect handler utility class that deliberately forwards an unmodified request to the Location header provided by a redirect, while preserving the method, headers and data of the original request. As discussed in comments of the PR, HTTP RFC 2616 requires explicit user approval for redirects in certain situations that may alter the meaning or effect of the request. Given this, the default HTTPRedirectHandler in urllib does not honor redirects for PUT and does not preserve all headers and data.

In the case of Prometheus, many users will have some type of in-house "private" deployment of a Prometheus pushgateway server, and e.g. in a deployment infrastructure like Kubernetes where the ultimate IP-based host address could change often, there may be a need for a purely cosmetic redirect that fronts this host address with an easier static URL. In that case, the user would like to "opt in" to trusted pass-through redirects for all method types (including PUT).

This PR provides passthrough_redirect_handler to support this specific redirect option. Use of this special redirect handler would constitute the user's explicit approval for RFC2616.

Additionally, this PR adds a new "redirect" HTTPD server to the unit tests for the pushgateway, in order to simulate a real redirect during testing and confirm it is handled as expected. I've locally validated all testing and flake8 instructions - and will work to resolve any requested changes or build issues.

Signed-off-by: Ely Spears <espears@squarespace.com>
@espears1 espears1 force-pushed the espears1/issue-131-redirect-handler branch from 1b75532 to 4613dfa Compare February 8, 2021 18:12
Signed-off-by: Ely Spears <espears@squarespace.com>
@espears1 espears1 force-pushed the espears1/issue-131-redirect-handler branch from c31af42 to 67e99ff Compare February 8, 2021 18:28
Signed-off-by: Ely Spears <espears@squarespace.com>
Copy link
Member

@csmarchbanks csmarchbanks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Generally this is looking good, just a couple of questions to begin with.

prometheus_client/exposition.py Outdated Show resolved Hide resolved
tests/test_exposition.py Show resolved Hide resolved
Signed-off-by: Ely Spears <espears@squarespace.com>
Signed-off-by: Ely Spears <espears@squarespace.com>
Signed-off-by: Ely Spears <espears@squarespace.com>
Signed-off-by: Ely Spears <espears@squarespace.com>
Copy link
Member

@csmarchbanks csmarchbanks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks good to me!

tests/test_exposition.py Show resolved Hide resolved
@csmarchbanks csmarchbanks merged commit 5e3674a into prometheus:master Feb 11, 2021
@espears1 espears1 deleted the espears1/issue-131-redirect-handler branch February 11, 2021 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add HTTPRedirectHandler for pushing to gateway
2 participants