Update comments

- updates comments and adds where missing
- updates locks so that unlock is done via defer instead of
at the end of the statement
- extracts timeout variable in two places
- remove makeClient() unused method from metrics package

No-harm changes tested via go build.

Signed-off-by: Alex Ellis (VMware) <alexellis2@gmail.com>
This commit is contained in:
Alex Ellis
2018-10-03 13:16:28 +01:00
parent 609ef28cad
commit bd39b9267a
9 changed files with 40 additions and 34 deletions

View File

@ -13,16 +13,10 @@ import (
"github.com/openfaas/faas/gateway/requests"
)
func makeClient() http.Client {
// Fine-tune the client to fail fast.
return http.Client{}
}
// AddMetricsHandler wraps a http.HandlerFunc with Prometheus metrics
func AddMetricsHandler(handler http.HandlerFunc, prometheusQuery PrometheusQueryFetcher) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
// log.Printf("Calling upstream for function info\n")
recorder := httptest.NewRecorder()
handler.ServeHTTP(recorder, r)
@ -56,7 +50,6 @@ func AddMetricsHandler(handler http.HandlerFunc, prometheusQuery PrometheusQuery
return
}
// log.Printf("Querying Prometheus API\n")
expr := url.QueryEscape(`sum(gateway_function_invocation_total{function_name=~".*", code=~".*"}) by (function_name, code)`)
// expr := "sum(gateway_function_invocation_total%7Bfunction_name%3D~%22.*%22%2C+code%3D~%22.*%22%7D)+by+(function_name%2C+code)"
results, fetchErr := prometheusQuery.Fetch(expr)
@ -76,7 +69,6 @@ func AddMetricsHandler(handler http.HandlerFunc, prometheusQuery PrometheusQuery
return
}
// log.Printf("Writing bytesOut: %s\n", bytesOut)
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write(bytesOut)