Add LifeCycleHooks for adding callbacks to requests#96
Add LifeCycleHooks for adding callbacks to requests#96davidpdrsn wants to merge 15 commits intomasterfrom
LifeCycleHooks for adding callbacks to requests#96Conversation
|
@tobz would you maybe be up for reviewing this? |
ade605c to
c757bf5
Compare
| - Add `metrics::Traffic` for measuring how many responses or errors a service is | ||
| producing. |
There was a problem hiding this comment.
This is potentially a more philosophical thought but Traffic feels like it should almost do all of this, plus track response latency, plus track the in-flight count. The last major thing to track, IMO, is response latency... which would bring the middleware count up to three, based on us having InFlightRequests and Traffic right now.
There was a problem hiding this comment.
Yeah I've had similar thoughts. I've considered calling it something like RequestLifecycleCallbacks 😜 but better.
The intended use case is to use this together with some metrics backend chosen by the user. At Embark we use the metrics crate and prometheus meaning all the aggregation is taken care of.
As mentioned I also do want to provide another crate that provides ready to use integration between tower-http and the metrics crate. However I don't think baking the metrics crate directly in to tower-http is appropriate.
There was a problem hiding this comment.
@tobz Do you think think RequestResponseCallbacks would be a better name?
There was a problem hiding this comment.
Hmmm, something with lifecycle in the name definitely sounds better. Just spitballing, but maybe like... lifecycle hooks? Something like that.
There was a problem hiding this comment.
I've renamed and moved some things around. This middleware is now called LifeCycleHooks and lives in tower_http::life_cycle, so doesn't live in metrics anymore. I agree I think this makes more sense.
@tobz what do you think?
Traffic middleware for measuring traffic and error ratesLifeCycleHooks for adding callbacks to requests
|
I think I'm going to close this for now. I'm not confident in the design. Specifically I think it would be cool to have something that was powerful enough to implement the |
Edit: Things have changed a bit since this description was written. See #96 (comment)
This adds
metrics::Trafficwhich is a middleware for measuring requests per second/minute and error rates. Doesn't actually aggregate anything. Just facilitates calling some callbacks that do the actual work such as sending events to prometheus.Example usage:
There are details about exactly when everything is called in the docs.
Part of #57