Skip to content

Commit

Permalink
Fix Invocation count wrong for multiple namespace
Browse files Browse the repository at this point in the history
Fixes openfaas#1413
Fixes openfaas/faas-netes#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 <[email protected]>
  • Loading branch information
Waterdrips committed Nov 11, 2020
1 parent bb9ba03 commit b2b4242
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gateway/assets/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ <h1 style="flex: 1 1 auto;"><img src="img/logo-text.svg" class="md-logo"></h1>

<md-input-container class="md-block" flex-gt-sm>
<label>Invocation count</label>
<input ng-model="function.invocationCount" type="text" readonly="readonly">
<input value="{{ function.invocationCount }}" type="text" readonly="readonly">
</md-input-container>

<md-input-container class="md-block" flex-gt-sm ng-show="allNamespaces.length > 1">
Expand Down
10 changes: 10 additions & 0 deletions gateway/assets/script/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
});
}

});
};

Expand Down
4 changes: 2 additions & 2 deletions gateway/metrics/add_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func AddMetricsHandler(handler http.HandlerFunc, prometheusQuery PrometheusQuery
}

func mixIn(functions *[]types.FunctionStatus, metrics *VectorQueryResponse) {

if functions == nil {
return
}
Expand All @@ -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)
Expand Down

0 comments on commit b2b4242

Please sign in to comment.