diff --git a/dashboard/client/src/components/FunctionDetailSummary/FunctionDetailSummary.jsx b/dashboard/client/src/components/FunctionDetailSummary/FunctionDetailSummary.jsx index d5a98304f..c93917a24 100644 --- a/dashboard/client/src/components/FunctionDetailSummary/FunctionDetailSummary.jsx +++ b/dashboard/client/src/components/FunctionDetailSummary/FunctionDetailSummary.jsx @@ -149,7 +149,7 @@ const FunctionDetailSummary = ({ const fnLogsButton = ( ); @@ -178,7 +178,7 @@ const FunctionDetailSummary = ({
diff --git a/go.mod b/go.mod index 701eb8847..d61537d9b 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module github.com/openfaas/openfaas-cloud go 1.13 + +require github.com/openfaas/openfaas-cloud/metrics v0.0.0-20201201105924-2f2413a8b8ab // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 000000000..3609ad0c6 --- /dev/null +++ b/go.sum @@ -0,0 +1,20 @@ +github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 h1:xJ4a3vCFaGF/jqvzLMYoU8P317H5OQ+Via4RmuPwCS0= +github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= +github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= +github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= +github.com/openfaas/faas v0.0.0-20191227175319-80b6976c1063 h1:9dxY2GyAGl6j3+g4RN0gHsDIk3dEHuKmqlB2mkGlJ7c= +github.com/openfaas/faas v0.0.0-20191227175319-80b6976c1063/go.mod h1:E0m2rLup0Vvxg53BKxGgaYAGcZa3Xl+vvL7vSi5yQ14= +github.com/openfaas/faas-provider v0.0.0-20191011092439-98c25c3919da h1:IgAWwOVcLrPNc495areghkleecv3JjciOkEHpavm7go= +github.com/openfaas/faas-provider v0.0.0-20191011092439-98c25c3919da/go.mod h1:W4OIp33RUOpR7wW+omJB/7GhIydRmYXvKf/VqUKI4yM= +github.com/openfaas/openfaas-cloud/metrics v0.0.0-20201201105924-2f2413a8b8ab h1:xDX+6thocabwas9PrC9qcs59xzLgBcnhjLFhowP3Mp8= +github.com/openfaas/openfaas-cloud/metrics v0.0.0-20201201105924-2f2413a8b8ab/go.mod h1:U+JISKIa+CMKs8ykMHarPuz+k/uVz5wTNWCUywpK944= +github.com/prometheus/client_golang v0.8.0 h1:1921Yw9Gc3iSc4VQh3PIoOqgPCZS7G/4xQNVUp8Mda8= +github.com/prometheus/client_golang v0.8.0/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= +github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910 h1:idejC8f05m9MGOsuEi1ATq9shN03HrxNkD/luQvxCv8= +github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= +github.com/prometheus/common v0.0.0-20180801064454-c7de2306084e h1:n/3MEhJQjQxrOUCzh1Y3Re6aJUUWRp2M9+Oc3eVn/54= +github.com/prometheus/common v0.0.0-20180801064454-c7de2306084e/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= +github.com/prometheus/procfs v0.0.0-20180725123919-05ee40e3a273 h1:agujYaXJSxSo18YNX3jzl+4G6Bstwt+kqv47GS12uL0= +github.com/prometheus/procfs v0.0.0-20180725123919-05ee40e3a273/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= diff --git a/metrics/handler.go b/metrics/handler.go index b015e5aba..a91b7be10 100644 --- a/metrics/handler.go +++ b/metrics/handler.go @@ -8,6 +8,7 @@ import ( "net/url" "os" "strconv" + "strings" "github.com/openfaas/faas/gateway/metrics" ) @@ -19,11 +20,14 @@ type Metrics struct { // Handle exposes the OpenFaaS instance metrics func Handle(req []byte) string { - fnName, err := parseFunctionName() - + fnName, ns, err := parseFunctionName() if err != nil { log.Fatalf("couldn't parse function name from query: %t", err) } + if ns == "" { + // TODO: read from env-var for environments where this is overridden + ns = "openfaas-fn" + } host := os.Getenv("prometheus_host") envPort := os.Getenv("prometheus_port") @@ -32,18 +36,19 @@ func Handle(req []byte) string { log.Fatalf("Could not convert env-var prometheus_port to int. Env-var value: %s. Error: %t", envPort, err) } - metricsQuery := metrics.NewPrometheusQuery(host, port, &http.Client{}) + metricsQuery := metrics.NewPrometheusQuery(host, port, http.DefaultClient) metricsWindow := parseMetricsWindow() - - fnMetrics, err := getMetrics(fnName, metricsQuery, metricsWindow) + key := fnName + "." + ns + fnMetrics, err := getMetrics(key, metricsQuery, metricsWindow) if err != nil { - log.Fatalf("Couldn't get metrics from Prometheus for function %s, %t", fnName, err) + log.Fatalf("Couldn't get metrics from Prometheus for function %s, %t", key, err) } res, err := json.Marshal(fnMetrics) if err != nil { log.Fatalf("Couldn't marshal json %t", err) } + return string(res) } @@ -67,20 +72,27 @@ func parseMetricsWindow() string { return metricsWindow } -func parseFunctionName() (functionName string, error error) { +func parseFunctionName() (name, namespace string, error error) { if query, exists := os.LookupEnv("Http_Query"); exists { - vals, _ := url.ParseQuery(query) + val, err := url.ParseQuery(query) + if err != nil { + return "", "", err + } - functionNameQuery := vals.Get("function") + if functionName := val.Get("function"); len(functionName) > 0 { + name = functionName + if index := strings.Index(functionName, "."); index > -1 { + name = functionName[:index] + namespace = functionName[index:] + } - if len(functionNameQuery) > 0 { - return functionNameQuery, nil + return name, namespace, nil } - return "", fmt.Errorf("there is no `function` inside env var Http_Query") + return "", "", fmt.Errorf("there is no `function` inside env var Http_Query") } - return "", fmt.Errorf("unable to parse Http_Query") + return "", "", fmt.Errorf("unable to parse Http_Query") } func getMetrics(fnName string, metricsQuery metrics.PrometheusQueryFetcher, metricsWindow string) (*Metrics, error) {