mirror of
https://github.com/openfaas/faas.git
synced 2025-06-21 22:33:23 +00:00
Add namespace in function name for metrics
This commit adds namespace in function names while logging metrics to prometheus, irrespective of the function is invoked with namespace suffix or not. This is also required to add multiple namespace support to faas-idler https://github.com/openfaas-incubator/faas-idler/issues/37 which is part of https://github.com/openfaas/faas-netes/issues/511 Signed-off-by: Vivek Singh <vivekkmr45@yahoo.in>
This commit is contained in:
@ -43,15 +43,21 @@ func urlToLabel(path string) string {
|
||||
// PrometheusFunctionNotifier records metrics to Prometheus
|
||||
type PrometheusFunctionNotifier struct {
|
||||
Metrics *metrics.MetricOptions
|
||||
//FunctionNamespace default namespace of the function
|
||||
FunctionNamespace string
|
||||
}
|
||||
|
||||
// Notify records metrics in Prometheus
|
||||
func (p PrometheusFunctionNotifier) Notify(method string, URL string, originalURL string, statusCode int, event string, duration time.Duration) {
|
||||
serviceName := getServiceName(originalURL)
|
||||
if len(p.FunctionNamespace) > 0 {
|
||||
if index := strings.Index(serviceName, "."); index == -1 {
|
||||
serviceName = fmt.Sprintf("%s.%s", serviceName, p.FunctionNamespace)
|
||||
}
|
||||
}
|
||||
|
||||
if event == "completed" {
|
||||
|
||||
seconds := duration.Seconds()
|
||||
serviceName := getServiceName(originalURL)
|
||||
|
||||
p.Metrics.GatewayFunctionsHistogram.
|
||||
WithLabelValues(serviceName).
|
||||
Observe(seconds)
|
||||
@ -62,7 +68,6 @@ func (p PrometheusFunctionNotifier) Notify(method string, URL string, originalUR
|
||||
With(prometheus.Labels{"function_name": serviceName, "code": code}).
|
||||
Inc()
|
||||
} else if event == "started" {
|
||||
serviceName := getServiceName(originalURL)
|
||||
p.Metrics.GatewayFunctionInvocationStarted.WithLabelValues(serviceName).Inc()
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user