Skip to content

fix: use upstream path in modify response - #269

Open
seanbanko wants to merge 2 commits into
prometheus-community:mainfrom
seanbanko:use-upstream-path-in-modify-response
Open

fix: use upstream path in modify response#269
seanbanko wants to merge 2 commits into
prometheus-community:mainfrom
seanbanko:use-upstream-path-in-modify-response

Conversation

@seanbanko

Copy link
Copy Markdown

Some open-source projects expose a Prometheus-compatible API at at a subpath, e.g. /prometheus. We should use the upstream.Path configured when matching the resp.Request.URL.Path in ModifyResponse so that we can handle the case of a non-root upstream path when proxying /api/v1/rules and /api/v1/alerts.

@seanbanko
seanbanko force-pushed the use-upstream-path-in-modify-response branch from c12ba39 to 3b35b04 Compare February 6, 2025 21:28
@squat

squat commented Feb 6, 2025

Copy link
Copy Markdown
Member

Hi @seanbanko can you add a concrete test case? Otherwise I'm sure this will regress

@seanbanko
seanbanko force-pushed the use-upstream-path-in-modify-response branch from c8ad898 to 734ea73 Compare February 6, 2025 22:58
@seanbanko

seanbanko commented Feb 6, 2025

Copy link
Copy Markdown
Author

Hi @seanbanko can you add a concrete test case? Otherwise I'm sure this will regress

Great call. I've added a simple test case to TestRules that fails if the upstream path concatenation is removed from r.modifiers.

I copied rules_match_namespace_ns1.golden to rules_match_namespace_ns1_non_root_upstream.golden to make the purpose of the test clear, but we could also just use rules_match_namespace_ns1.golden in the test instead to make it clear that the expected result is the same.

@seanbanko

Copy link
Copy Markdown
Author

@squat just bumping this. Is that test case is sufficient?

@seanbanko

Copy link
Copy Markdown
Author

Just taking a look at recent commits, @simonpasquier are you able to review?

Comment thread injectproxy/routes.go Outdated
r.modifiers = map[string]func(*http.Response) error{
"/api/v1/rules": modifyAPIResponse(r.filterRules),
"/api/v1/alerts": modifyAPIResponse(r.filterAlerts),
upstream.Path + "/api/v1/rules": modifyAPIResponse(r.filterRules),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we use https://pkg.go.dev/net/url#JoinPath instead?

It might be the right time to use a proper struct for modifies instead of an opaque map[string]func.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Updated to use url.JoinPath.

I agree the map for modifies isn't ideal. Do you think it's better to have a separate PR for the refactor to keep scope limited? Glad to open a follow-up.

@seanbanko
seanbanko force-pushed the use-upstream-path-in-modify-response branch from 7935d27 to c918521 Compare March 21, 2025 23:28
@SuperQ

SuperQ commented Jun 5, 2025

Copy link
Copy Markdown
Contributor

Looks like the tests are failing.

@seanbanko
seanbanko force-pushed the use-upstream-path-in-modify-response branch from 7485653 to 094808b Compare June 10, 2025 20:06
@squat

squat commented Jun 16, 2025

Copy link
Copy Markdown
Member

I just re-ran the tests and they are still failing.
ping @seanbanko

@seanbanko
seanbanko force-pushed the use-upstream-path-in-modify-response branch from 09c91ac to 8bf332a Compare July 3, 2025 15:09
@seanbanko

seanbanko commented Jul 3, 2025

Copy link
Copy Markdown
Author

@squat @SuperQ fixed, sorry about that.

@seanbanko
seanbanko force-pushed the use-upstream-path-in-modify-response branch from 8bf332a to 4c789e2 Compare August 13, 2025 21:09
Signed-off-by: Sean Banko <sean.banko@gmail.com>
@seanbanko
seanbanko force-pushed the use-upstream-path-in-modify-response branch from 4c789e2 to f115f09 Compare August 13, 2025 21:10
@seanbanko

Copy link
Copy Markdown
Author

Just following up here. Anything I can do to help get this merged?

@seanbanko

Copy link
Copy Markdown
Author

@simonpasquier let me know if I can do anything to help get this over the line!

@snowdrop4

Copy link
Copy Markdown

anything additional needed to get this merged?

@seanbanko

Copy link
Copy Markdown
Author

Hi @simonpasquier , just following up on this to see if the submission is still being considered.

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.

5 participants