Call poolmgr from router while using a cached service

Poolmgr needs to know usage statistics for a function's pod.  This
change asynchronously taps poolmgr API when router uses a service.
Poolmgr can use this information to control pod expiry.  It may also
be useful later as one of the metrics for autoscaling.
This commit is contained in:
Soam Vasani
2016-11-04 23:05:29 -07:00
parent 22583481a4
commit f3eba4b825
3 changed files with 67 additions and 2 deletions
+13
View File
@@ -80,7 +80,16 @@ func (rrt RetryingRoundTripper) RoundTrip(req *http.Request) (*http.Response, er
return http.DefaultTransport.RoundTrip(req)
}
func (fh *functionHandler) tapService(serviceUrl *url.URL) {
err := fh.poolmgr.TapService(serviceUrl)
if err != nil {
log.Printf("tap service error: %v", serviceUrl.String())
}
}
func (fh *functionHandler) handler(responseWriter http.ResponseWriter, request *http.Request) {
// cache lookup
serviceUrl, err := fh.fmap.lookup(&fh.Function)
if err != nil {
// Cache miss: request the Pool Manager to make a new service.
@@ -99,6 +108,10 @@ func (fh *functionHandler) handler(responseWriter http.ResponseWriter, request *
// add it to the map
fh.fmap.assign(&fh.Function, serviceUrl)
} else {
// if we're using our cache, asynchronously tell
// poolmgr we're using this service
go fh.tapService(serviceUrl)
}
// Proxy off our request to the serviceUrl, and send the response back.