From 009fdfbd3b5ee8669607f7d496a59c8518f1157a Mon Sep 17 00:00:00 2001 From: nikhil1raghav <44281594+nikhil1raghav@users.noreply.github.com> Date: Tue, 27 Sep 2022 23:43:37 +0530 Subject: [PATCH] fix(controller): Fix k8s clientset controller metrics. Fixes #2139 (#2261) * Add roundtripper to kubeconfig before creating kubeclient Signed-off-by: Nikhil * Check if k8sRequestsCount is nil before attempting increase Signed-off-by: Nikhil * Added Flipkart to Users.md Signed-off-by: Nikhil * gofmt controller/metrics/client.go Signed-off-by: Nikhil Signed-off-by: Nikhil --- USERS.md | 1 + cmd/rollouts-controller/main.go | 5 +++-- controller/metrics/client.go | 5 +++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/USERS.md b/USERS.md index 9d7d511bbe..be3ec11e5f 100644 --- a/USERS.md +++ b/USERS.md @@ -13,6 +13,7 @@ Organizations below are **officially** using Argo Rollouts. Please send a PR wit 1. [Databricks](https://github.com/databricks) 1. [Devtron Labs](https://github.com/devtron-labs/devtron) 1. [Farfetch](https://www.farfetch.com/) +1. [Flipkart](https://flipkart.com) 1. [Gllue](https://gllue.com) 1. [Ibotta](https://home.ibotta.com/) 1. [Intuit](https://www.intuit.com/) diff --git a/cmd/rollouts-controller/main.go b/cmd/rollouts-controller/main.go index 401b579323..65a1374542 100644 --- a/cmd/rollouts-controller/main.go +++ b/cmd/rollouts-controller/main.go @@ -107,6 +107,9 @@ func newCommand() *cobra.Command { log.Infof("Using namespace %s", namespace) } + k8sRequestProvider := &metrics.K8sRequestsCountProvider{} + kubeclientmetrics.AddMetricsTransportWrapper(config, k8sRequestProvider.IncKubernetesRequest) + kubeClient, err := kubernetes.NewForConfig(config) checkError(err) argoprojClient, err := clientset.NewForConfig(config) @@ -154,8 +157,6 @@ func newCommand() *cobra.Command { configMapInformer := controllerNamespaceInformerFactory.Core().V1().ConfigMaps() secretInformer := controllerNamespaceInformerFactory.Core().V1().Secrets() - k8sRequestProvider := &metrics.K8sRequestsCountProvider{} - kubeclientmetrics.AddMetricsTransportWrapper(config, k8sRequestProvider.IncKubernetesRequest) mode, err := ingressutil.DetermineIngressMode(ingressVersion, kubeClient.DiscoveryClient) checkError(err) ingressWrapper, err := ingressutil.NewIngressWrapper(mode, kubeClient, kubeInformerFactory) diff --git a/controller/metrics/client.go b/controller/metrics/client.go index f2e2624d20..01367745ef 100644 --- a/controller/metrics/client.go +++ b/controller/metrics/client.go @@ -35,7 +35,8 @@ func (m *K8sRequestsCountProvider) IncKubernetesRequest(resourceInfo kubeclientm name = "Unknown" kind = "Unknown" } - - m.k8sRequestsCount.WithLabelValues(kind, namespace, name, string(resourceInfo.Verb), statusCode).Inc() + if m.k8sRequestsCount != nil { + m.k8sRequestsCount.WithLabelValues(kind, namespace, name, string(resourceInfo.Verb), statusCode).Inc() + } return nil }