From b2b4242d5eaea5111407674b07d0b7ffe13c21ab Mon Sep 17 00:00:00 2001 From: Alistair Hey Date: Wed, 11 Nov 2020 20:39:17 +0000 Subject: [PATCH] Fix Invocation count wrong for multiple namespace Fixes https://github.com/openfaas/faas/issues/1413 Fixes https://github.com/openfaas/faas-netes/issues/707 This adds both namespace and non-namespace scoped counts of invocation to metric agregation and fixes the Gateway UI not updating the invocation count automatically without a page reload. Signed-off-by: Alistair Hey --- gateway/assets/index.html | 2 +- gateway/assets/script/bootstrap.js | 10 ++++++++++ gateway/metrics/add_metrics.go | 4 ++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/gateway/assets/index.html b/gateway/assets/index.html index 4a994bceff..79930748a2 100644 --- a/gateway/assets/index.html +++ b/gateway/assets/index.html @@ -124,7 +124,7 @@

- + diff --git a/gateway/assets/script/bootstrap.js b/gateway/assets/script/bootstrap.js index 68c8c657a3..7e6050a561 100644 --- a/gateway/assets/script/bootstrap.js +++ b/gateway/assets/script/bootstrap.js @@ -222,6 +222,16 @@ app.controller("home", ['$scope', '$log', '$http', '$location', '$interval', '$f $scope.selectedFunction = undefined; } } + + if ($scope.selectedFunction) { + response.data.some(function(entry) { + if (entry.name === $scope.selectedFunction.name) { + $scope.selectedFunction.invocationCount = entry.invocationCount + return true + } + }); + } + }); }; diff --git a/gateway/metrics/add_metrics.go b/gateway/metrics/add_metrics.go index 2171db2394..efeabdfa7f 100644 --- a/gateway/metrics/add_metrics.go +++ b/gateway/metrics/add_metrics.go @@ -76,6 +76,7 @@ func AddMetricsHandler(handler http.HandlerFunc, prometheusQuery PrometheusQuery } func mixIn(functions *[]types.FunctionStatus, metrics *VectorQueryResponse) { + if functions == nil { return } @@ -88,11 +89,10 @@ func mixIn(functions *[]types.FunctionStatus, metrics *VectorQueryResponse) { for i, function := range *functions { for _, v := range metrics.Data.Result { - if v.Metric.FunctionName == fmt.Sprintf("%s.%s", function.Name, function.Namespace) { + if v.Metric.FunctionName == function.Name || v.Metric.FunctionName == fmt.Sprintf("%s.%s", function.Name, function.Namespace) { metricValue := v.Value[1] switch metricValue.(type) { case string: - // log.Println("String") f, strconvErr := strconv.ParseFloat(metricValue.(string), 64) if strconvErr != nil { log.Printf("Unable to convert value for metric: %s\n", strconvErr)