Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
middleware comms via context.Context #39
With the added param of context.Context in the middleware we can communicate between them. The first use-case for this would be: monitoring.
I.e. middleware proxy sets some vars in the context and the prometheus middleware picks this up from the context and sets the vars. This way we can get middleware monitoring without meddling with prometheus outside of the prometheus middleware.
This needs a key naming policy, i.e.
...But context.Context is a value and only propagates downwards, so you can't add something in a later layer and read it back in the upper one.
A second try by wrapping dns.ResponseWriter and putting metrics in there, also does not work, because it might be wrapped further by other middleware.
In the end for metrics we should maybe just have a function the calls into the metrics and add the metric. Also because even if the above would work, in the end you'll still need a metric to be defined to actually increment it.