-
Notifications
You must be signed in to change notification settings - Fork 321
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
route: Allow per-request custom context injection #61
Conversation
**Motivation** Currently, Prometheus's web API knows of two different contexts: - The main Prometheus server context which is passed into the web API and through to the query layer. - The per-request context which is generated by the route.Router. This is currently only used for storing and retrieving URL-path parameters, and it's not possible to influence this context at the top of the chain. Since merging of contexts is not a concept, we ultimately want the router to support a per-request context which: a) can be derived from the main server context, b) can be decorated with custom values/timeouts/etc. per-request The concrete motivation for b) is for Weaveworks Frankenstein to be able to extract multi-tenancy authentication headers and store user information in the context. This will then be passed on into the query layers and decide what data a user gets to see. Next step: update Prometheus to make use of this, get rid of the context in the web API itself. This will make the API package reusable by Frankenstein.
9b69d62
to
ee21c31
Compare
This is based on the common/route changes in prometheus/common#61.
} | ||
|
||
// New returns a new Router. | ||
func New(ctxFn contextFn) *Router { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you envision a use case where a context function here would be useful instead of a base context?
Seems like values passed into the context would be static to a base context anyway.
Seems like only a timeout for all requests applied to a new context would be sane.
Could be more explicit to configure as a directly. But both approaches seem equally fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I need a context function exactly for the Frankenstein case: to pull out per-request multi-tenancy information from the HTTP request headers and stuff that user info into the context.
Or did I misunderstand your question?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ping :)
@fabxc Any chance to get this and the related prometheus/prometheus#2012 merged? |
Yea, seems fine in general and doesn't break anything 👍 go ahead on both. |
Thanks! |
03cc598 Don't lint generated protobuf code. 2b55c2d Merge pull request prometheus#66 from weaveworks/reduce-test-timeout d4e163c Make timeout a flag 49a8609 Reduce test timeout 8fa15cb Merge pull request prometheus#63 from weaveworks/test-defaults b783528 Tweak test script so it can be run on a mca a3b18bf Merge pull request prometheus#65 from weaveworks/fix-integration-tests ecb5602 Fix integration tests f9dcbf6 ... without tab (clearly not my day) a6215c3 Add break I forgot 0e6832d Remove incorrectly added tab eb26c68 Merge pull request prometheus#64 from weaveworks/remove-test-package-linting f088e83 Review feedback 2c6e83e Remove test package linting 2b3a1bb Merge pull request prometheus#62 from weaveworks/revert-61-test-defaults 8c3883a Revert "Make no-go-get the default, and don't assume -tags netgo" e75c226 Fix bug in GC of firewall rules. e49754e Merge pull request prometheus#51 from weaveworks/gc-firewall-rules 191f487 Add flag to enale/disable firewall rules' GC. 567905c Add GC of firewall rules for weave-net-tests to scheduler. 03119e1 Fix typo in GC of firewall rules. bbe3844 Fix regular expression for firewall rules. c5c23ce Pre-change refactoring: splitted gc_project function into smaller methods for better readability. ed5529f GC firewall rules ed8e757 Merge pull request prometheus#61 from weaveworks/test-defaults 57856e6 Merge pull request prometheus#56 from weaveworks/remove-wcloud dd5f3e6 Add -p flag to test, run test in parallel 62f6f94 Make no-go-get the default, and don't assume -tags netgo 8946588 Merge pull request prometheus#60 from weaveworks/2647-gc-weave-net-tests 4085df9 Scheduler now also garbage-collects VMs from weave-net-tests. 4b7d5c6 Merge pull request prometheus#59 from weaveworks/57-fix-lint-properly b7f0e69 Merge pull request prometheus#58 from weaveworks/fix-lint 794702c Pin version of shfmt ab1b11d Fix lint d1a5e46 Remove wcloud cli tool 81d80f3 Merge pull request prometheus#55 from weaveworks/lint-tf 05ad5f2 Review feedback 4c0d046 Use hclfmt to lint terraform. git-subtree-dir: tools git-subtree-split: 03cc5989769d93aa03f8aed3784ddfdb1fffc1c6
Motivation
Currently, Prometheus's web API knows of two different contexts:
and through to the query layer.
is currently only used for storing and retrieving URL-path parameters,
and it's not possible to influence this context at the top of the
chain.
Since merging of contexts is not a concept, we ultimately want the
router to support a per-request context which:
a) can be derived from the main server context,
b) can be decorated with custom values/timeouts/etc. per-request
The concrete motivation for b) is for Weaveworks Frankenstein to be able
to extract multi-tenancy authentication headers and store user
information in the context. This will then be passed on into the query
layers and decide what data a user gets to see.
Next step: update Prometheus to make use of this, get rid of the context
in the web API itself. This will make the API package reusable by
Frankenstein.