Skip to content

Commit

Permalink
Remove name label from k8s client metrics
Browse files Browse the repository at this point in the history
The `name` label in the `controller_clientset_k8s_request_total` metric
produce an excessive amount of cardinality as `events` metrics generate
a new string for each event. Similarly, each new `replicasets` also
generates a new label set. This can lead to hundreds of thousands of
unique metrics over a couple weeks in a large deployment.

Signed-off-by: SuperQ <[email protected]>
  • Loading branch information
SuperQ committed Jun 19, 2023
1 parent 51c867d commit 52fcb27
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
7 changes: 1 addition & 6 deletions controller/metrics/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,15 @@ func (f *K8sRequestsCountProvider) MustRegister(registerer prometheus.Registerer

// IncKubernetesRequest increments the kubernetes client counter
func (m *K8sRequestsCountProvider) IncKubernetesRequest(resourceInfo kubeclientmetrics.ResourceInfo) error {
name := resourceInfo.Name
namespace := resourceInfo.Namespace
kind := resourceInfo.Kind
statusCode := strconv.Itoa(resourceInfo.StatusCode)
if resourceInfo.Verb == kubeclientmetrics.List {
name = "N/A"
}
if resourceInfo.Verb == kubeclientmetrics.Unknown {
namespace = "Unknown"
name = "Unknown"
kind = "Unknown"
}
if m.k8sRequestsCount != nil {
m.k8sRequestsCount.WithLabelValues(kind, namespace, name, string(resourceInfo.Verb), statusCode).Inc()
m.k8sRequestsCount.WithLabelValues(kind, namespace, string(resourceInfo.Verb), statusCode).Inc()
}
return nil
}
2 changes: 1 addition & 1 deletion controller/metrics/prommetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ var (
Name: "k8s_request_total",
Help: "Number of kubernetes requests executed during application reconciliation.",
},
[]string{"kind", "namespace", "name", "verb", "status_code"},
[]string{"kind", "namespace", "verb", "status_code"},
)
)

Expand Down

0 comments on commit 52fcb27

Please sign in to comment.