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

Split proxy configuration out of resource handlers #527

Merged
merged 2 commits into from
Nov 26, 2024

Conversation

K-Phoen
Copy link
Member

@K-Phoen K-Phoen commented Nov 15, 2024

I was starting to feel a bit overwhelmed by the amount of code/methods in resource handlers, which only increases for handlers that need to describe how to proxy resources for grr serve.

In this PR, I suggest to split proxy configuration code out of resource handlers and into a dedicated file/struct.

This is purely a refactoring: no bug was fixed or feature changed/introduced.

As a next step, I would like the individual ProxyConfigurator structs to describe this configuration:

var mustProxyGET = []string{
"/public/*",
"/api/datasources/proxy/*",
"/api/datasources/*",
"/api/plugins/*",
"/avatar/*",
}
var mustProxyPOST = []string{
"/api/datasources/proxy/*",
"/api/ds/query",
}
var blockJSONget = map[string]string{
"/api/ma/events": "[]",
"/api/live/publish": "[]",
"/api/live/list": "[]",
"/api/user/orgs": "[]",
"/api/annotations": "[]",
"/api/search": "[]",
"/api/usage/*": "[]",
"/api/frontend/assets": "{}",
"/api/org/preferences": "{}",
"/api/access-control/user/actions": `{"dashboards:write": true}`,
"/api/prometheus/grafana/api/v1/rules": `{
"status": "success",
"data": { "groups": [] }
}`,
"/api/folders": "[]",
"/api/recording-rules/writer": `{
"id": "cojWep7Vz",
"data_source_uid": "grafanacloud-prom",
"remote_write_path": "/api/prom/push"
}`,
"/apis/banners.grafana.app/v0alpha1/namespaces/{stack}/announcement-banners": `{
"kind": "AnnouncementBannerList",
"apiVersion": "banners.grafana.app/v0alpha1",
"metadata": {"resourceVersion": "29"}
}`,
}
var blockJSONpost = map[string]string{
"/api/frontend-metrics": "[]",
"/api/search-v2": "[]",
"/api/live/publish": "{}",
"/api/ma/events": "null",
}

It would allow to have this config close to the resource handler that requires it, instead of globally set by the server.

@K-Phoen K-Phoen self-assigned this Nov 15, 2024
@K-Phoen K-Phoen requested a review from a team as a code owner November 15, 2024 16:20
@K-Phoen K-Phoen force-pushed the proxy-handlers-refactor branch from 69ad5c6 to 67c8e05 Compare November 15, 2024 18:04
Base automatically changed from proxy-alert-rules to main November 26, 2024 13:42
@K-Phoen K-Phoen force-pushed the proxy-handlers-refactor branch from 3742e9f to dc26acf Compare November 26, 2024 13:43
@K-Phoen K-Phoen merged commit 63ec973 into main Nov 26, 2024
7 checks passed
@K-Phoen K-Phoen deleted the proxy-handlers-refactor branch November 26, 2024 13:48
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.

2 participants