github.com/argoproj/argo-cd@v1.8.7/controller/metrics/transportwrapper.go (about)

     1  package metrics
     2  
     3  import (
     4  	"strconv"
     5  
     6  	"github.com/argoproj/pkg/kubeclientmetrics"
     7  	"k8s.io/client-go/rest"
     8  
     9  	"github.com/argoproj/argo-cd/pkg/apis/application/v1alpha1"
    10  )
    11  
    12  // AddMetricsTransportWrapper adds a transport wrapper which increments 'argocd_app_k8s_request_total' counter on each kubernetes request
    13  func AddMetricsTransportWrapper(server *MetricsServer, app *v1alpha1.Application, config *rest.Config) *rest.Config {
    14  	inc := func(resourceInfo kubeclientmetrics.ResourceInfo) error {
    15  		namespace := resourceInfo.Namespace
    16  		kind := resourceInfo.Kind
    17  		statusCode := strconv.Itoa(resourceInfo.StatusCode)
    18  		server.IncKubernetesRequest(app, resourceInfo.Server, statusCode, string(resourceInfo.Verb), kind, namespace)
    19  		return nil
    20  	}
    21  
    22  	newConfig := kubeclientmetrics.AddMetricsTransportWrapper(config, inc)
    23  	return newConfig
    24  }