From ec60d975188ecd843d82a640471388e9ee3c149f Mon Sep 17 00:00:00 2001 From: Alex Ellis Date: Wed, 25 Oct 2017 19:30:30 +0100 Subject: [PATCH] Report async execution duration Signed-off-by: Alex Ellis --- gateway/handlers/asyncreport.go | 5 +++++ gateway/handlers/proxy.go | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/gateway/handlers/asyncreport.go b/gateway/handlers/asyncreport.go index edd41f95..47e3abaa 100644 --- a/gateway/handlers/asyncreport.go +++ b/gateway/handlers/asyncreport.go @@ -7,6 +7,7 @@ import ( "encoding/json" "io/ioutil" "net/http" + "time" "github.com/openfaas/faas/gateway/metrics" "github.com/openfaas/faas/gateway/requests" @@ -22,5 +23,9 @@ func MakeAsyncReport(metrics metrics.MetricOptions) http.HandlerFunc { json.Unmarshal(bytesOut, &report) trackInvocation(report.FunctionName, metrics, report.StatusCode) + + var taken time.Duration + taken = time.Duration(report.TimeTaken) + trackTimeExact(taken, metrics, report.FunctionName) } } diff --git a/gateway/handlers/proxy.go b/gateway/handlers/proxy.go index ee968c75..62154cac 100644 --- a/gateway/handlers/proxy.go +++ b/gateway/handlers/proxy.go @@ -220,3 +220,7 @@ func trackTime(then time.Time, metrics metrics.MetricOptions, name string) { since := time.Since(then) metrics.GatewayFunctionsHistogram.WithLabelValues(name).Observe(since.Seconds()) } + +func trackTimeExact(duration time.Duration, metrics metrics.MetricOptions, name string) { + metrics.GatewayFunctionsHistogram.WithLabelValues(name).Observe(float64(duration)) +}