Add a default handler for the / route
Before this change, if the user doesn't define a route for /, the router happily 404s at that path. This breaks GKE Ingress, which uses that request as a health check. So this change adds a handler for "GET /", unless the user already has one. Also, log the delay for slow requests.
This commit is contained in:
@@ -86,11 +86,12 @@ func (fh *functionHandler) tapService(serviceUrl *url.URL) {
|
||||
}
|
||||
err := fh.poolmgr.TapService(serviceUrl)
|
||||
if err != nil {
|
||||
log.Printf("tap service error: %v", serviceUrl.String())
|
||||
log.Printf("tap service error for %v: %v", serviceUrl.String(), err)
|
||||
}
|
||||
}
|
||||
|
||||
func (fh *functionHandler) handler(responseWriter http.ResponseWriter, request *http.Request) {
|
||||
reqStartTime := time.Now()
|
||||
|
||||
// cache lookup
|
||||
serviceUrl, err := fh.fmap.lookup(&fh.Function)
|
||||
@@ -150,5 +151,9 @@ func (fh *functionHandler) handler(responseWriter http.ResponseWriter, request *
|
||||
initalTimeout: 50 * time.Millisecond,
|
||||
},
|
||||
}
|
||||
delay := time.Now().Sub(reqStartTime)
|
||||
if delay > 100*time.Millisecond {
|
||||
log.Printf("Request delay for %v: %v", serviceUrl, delay)
|
||||
}
|
||||
proxy.ServeHTTP(responseWriter, request)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user