Skip to content
This repository was archived by the owner on Mar 10, 2023. It is now read-only.

Commit ff1aa45

Browse files
committed
Fix namespace for metrics invocations
The metrics for OpenFaaS now have a namespace suffix so that it is needed when looking up Prometheus metrics. This change also fixes the proxy issue with create-react-app now deprecating proxy settings in the package.json Fixes: #700 Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
1 parent 40adc94 commit ff1aa45

File tree

4 files changed

+49
-15
lines changed

4 files changed

+49
-15
lines changed

dashboard/client/src/components/FunctionDetailSummary/FunctionDetailSummary.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ const FunctionDetailSummary = ({
149149
const fnLogsButton = (
150150
<Button outline color="secondary" size="xs" tag={Link} to={toFnLogs}>
151151
<FontAwesomeIcon icon="folder-open" className="mr-2" />
152-
<span>Invocation Logs</span>
152+
<span>Logs</span>
153153
</Button>
154154
);
155155

@@ -178,7 +178,7 @@ const FunctionDetailSummary = ({
178178
</div>
179179
<div className="col-lg-4">
180180
<FunctionOverviewPanel
181-
headerText="Invocations"
181+
headerText="Runtime"
182182
headerIcon={invocationsIcon}
183183
button={fnLogsButton}
184184
>

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
module github.com/openfaas/openfaas-cloud
22

33
go 1.13
4+
5+
require github.com/openfaas/openfaas-cloud/metrics v0.0.0-20201201105924-2f2413a8b8ab // indirect

go.sum

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 h1:xJ4a3vCFaGF/jqvzLMYoU8P317H5OQ+Via4RmuPwCS0=
2+
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
3+
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
4+
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
5+
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
6+
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
7+
github.com/openfaas/faas v0.0.0-20191227175319-80b6976c1063 h1:9dxY2GyAGl6j3+g4RN0gHsDIk3dEHuKmqlB2mkGlJ7c=
8+
github.com/openfaas/faas v0.0.0-20191227175319-80b6976c1063/go.mod h1:E0m2rLup0Vvxg53BKxGgaYAGcZa3Xl+vvL7vSi5yQ14=
9+
github.com/openfaas/faas-provider v0.0.0-20191011092439-98c25c3919da h1:IgAWwOVcLrPNc495areghkleecv3JjciOkEHpavm7go=
10+
github.com/openfaas/faas-provider v0.0.0-20191011092439-98c25c3919da/go.mod h1:W4OIp33RUOpR7wW+omJB/7GhIydRmYXvKf/VqUKI4yM=
11+
github.com/openfaas/openfaas-cloud/metrics v0.0.0-20201201105924-2f2413a8b8ab h1:xDX+6thocabwas9PrC9qcs59xzLgBcnhjLFhowP3Mp8=
12+
github.com/openfaas/openfaas-cloud/metrics v0.0.0-20201201105924-2f2413a8b8ab/go.mod h1:U+JISKIa+CMKs8ykMHarPuz+k/uVz5wTNWCUywpK944=
13+
github.com/prometheus/client_golang v0.8.0 h1:1921Yw9Gc3iSc4VQh3PIoOqgPCZS7G/4xQNVUp8Mda8=
14+
github.com/prometheus/client_golang v0.8.0/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
15+
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910 h1:idejC8f05m9MGOsuEi1ATq9shN03HrxNkD/luQvxCv8=
16+
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
17+
github.com/prometheus/common v0.0.0-20180801064454-c7de2306084e h1:n/3MEhJQjQxrOUCzh1Y3Re6aJUUWRp2M9+Oc3eVn/54=
18+
github.com/prometheus/common v0.0.0-20180801064454-c7de2306084e/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
19+
github.com/prometheus/procfs v0.0.0-20180725123919-05ee40e3a273 h1:agujYaXJSxSo18YNX3jzl+4G6Bstwt+kqv47GS12uL0=
20+
github.com/prometheus/procfs v0.0.0-20180725123919-05ee40e3a273/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=

metrics/handler.go

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net/url"
99
"os"
1010
"strconv"
11+
"strings"
1112

1213
"github.com/openfaas/faas/gateway/metrics"
1314
)
@@ -19,11 +20,14 @@ type Metrics struct {
1920

2021
// Handle exposes the OpenFaaS instance metrics
2122
func Handle(req []byte) string {
22-
fnName, err := parseFunctionName()
23-
23+
fnName, ns, err := parseFunctionName()
2424
if err != nil {
2525
log.Fatalf("couldn't parse function name from query: %t", err)
2626
}
27+
if ns == "" {
28+
// TODO: read from env-var for environments where this is overridden
29+
ns = "openfaas-fn"
30+
}
2731

2832
host := os.Getenv("prometheus_host")
2933
envPort := os.Getenv("prometheus_port")
@@ -32,18 +36,19 @@ func Handle(req []byte) string {
3236
log.Fatalf("Could not convert env-var prometheus_port to int. Env-var value: %s. Error: %t", envPort, err)
3337
}
3438

35-
metricsQuery := metrics.NewPrometheusQuery(host, port, &http.Client{})
39+
metricsQuery := metrics.NewPrometheusQuery(host, port, http.DefaultClient)
3640
metricsWindow := parseMetricsWindow()
37-
38-
fnMetrics, err := getMetrics(fnName, metricsQuery, metricsWindow)
41+
key := fnName + "." + ns
42+
fnMetrics, err := getMetrics(key, metricsQuery, metricsWindow)
3943
if err != nil {
40-
log.Fatalf("Couldn't get metrics from Prometheus for function %s, %t", fnName, err)
44+
log.Fatalf("Couldn't get metrics from Prometheus for function %s, %t", key, err)
4145
}
4246

4347
res, err := json.Marshal(fnMetrics)
4448
if err != nil {
4549
log.Fatalf("Couldn't marshal json %t", err)
4650
}
51+
4752
return string(res)
4853
}
4954

@@ -67,20 +72,27 @@ func parseMetricsWindow() string {
6772
return metricsWindow
6873
}
6974

70-
func parseFunctionName() (functionName string, error error) {
75+
func parseFunctionName() (name, namespace string, error error) {
7176
if query, exists := os.LookupEnv("Http_Query"); exists {
72-
vals, _ := url.ParseQuery(query)
77+
val, err := url.ParseQuery(query)
78+
if err != nil {
79+
return "", "", err
80+
}
7381

74-
functionNameQuery := vals.Get("function")
82+
if functionName := val.Get("function"); len(functionName) > 0 {
83+
name = functionName
84+
if index := strings.Index(functionName, "."); index > -1 {
85+
name = functionName[:index]
86+
namespace = functionName[index:]
87+
}
7588

76-
if len(functionNameQuery) > 0 {
77-
return functionNameQuery, nil
89+
return name, namespace, nil
7890
}
7991

80-
return "", fmt.Errorf("there is no `function` inside env var Http_Query")
92+
return "", "", fmt.Errorf("there is no `function` inside env var Http_Query")
8193
}
8294

83-
return "", fmt.Errorf("unable to parse Http_Query")
95+
return "", "", fmt.Errorf("unable to parse Http_Query")
8496
}
8597

8698
func getMetrics(fnName string, metricsQuery metrics.PrometheusQueryFetcher, metricsWindow string) (*Metrics, error) {

0 commit comments

Comments
 (0)