1
0
mirror of https://github.com/rancher/norman.git synced 2025-09-05 09:10:31 +00:00

Remove controller metrics

Norman metrics' labels have too high of a cardinality as they
include object key as a label. This is a problem because metrics
produces a data row for every combination of labels. This can
have a large impact on performance and is cautioned against in
the prometheus docs. Norman now uses lasso which has metrics with
matching functionality apart from the object key, so norman
metrics will be removed in favor of lasso metrics.
This commit is contained in:
Ricardo Weir
2022-04-27 11:45:54 -07:00
parent 82478fb169
commit 20335edec8
4 changed files with 1 additions and 72 deletions

View File

@@ -7,7 +7,6 @@ import (
errors2 "github.com/pkg/errors"
"github.com/rancher/lasso/pkg/controller"
"github.com/rancher/norman/metrics"
"github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
@@ -58,12 +57,8 @@ func (g *genericController) AddHandler(ctx context.Context, name string, handler
return obj, nil
}
logrus.Tracef("%s calling handler %s %s", g.name, name, key)
metrics.IncTotalHandlerExecution(g.name, name)
result, err := handler(key, obj)
runtimeObject, _ := result.(runtime.Object)
if err != nil && !ignoreError(err, false) {
metrics.IncTotalHandlerFailure(g.name, name, key)
}
if _, ok := err.(*ForgetError); ok {
logrus.Tracef("%v %v completed with dropped err: %v", g.name, key, err)
return runtimeObject, controller.ErrIgnore

View File

@@ -1,47 +0,0 @@
package metrics
import (
"github.com/prometheus/client_golang/prometheus"
)
var (
TotalHandlerExecution = prometheus.NewCounterVec(
prometheus.CounterOpts{
Subsystem: "norman_generic_controller",
Name: "total_handler_execution",
Help: "Total count of hanlder executions",
},
[]string{"name", "handlerName"},
)
TotalHandlerFailure = prometheus.NewCounterVec(
prometheus.CounterOpts{
Subsystem: "norman_generic_controller",
Name: "total_handler_failure",
Help: "Total count of handler failures",
},
[]string{"name", "handlerName", "key"},
)
)
func IncTotalHandlerExecution(controllerName, handlerName string) {
if prometheusMetrics {
TotalHandlerExecution.With(
prometheus.Labels{
"name": controllerName,
"handlerName": handlerName},
).Inc()
}
}
func IncTotalHandlerFailure(controllerName, handlerName, key string) {
if prometheusMetrics {
TotalHandlerFailure.With(
prometheus.Labels{
"name": controllerName,
"handlerName": handlerName,
"key": key,
},
).Inc()
}
}

View File

@@ -1,20 +0,0 @@
package metrics
import (
"os"
"github.com/prometheus/client_golang/prometheus"
)
const metricsEnv = "CATTLE_PROMETHEUS_METRICS"
var prometheusMetrics = false
func init() {
if os.Getenv(metricsEnv) == "true" {
prometheusMetrics = true
// Generic controller metrics
prometheus.MustRegister(TotalHandlerExecution)
prometheus.MustRegister(TotalHandlerFailure)
}
}

View File

@@ -1,3 +1,4 @@
//go:build !linux
// +build !linux
package k8s