Преглед изворни кода

Stop emitting unused metrics (#2313)

Stop emitting unused metrics by default.
Significantly reduce CPU/Memory usage.

---------

Signed-off-by: r2k1 <yokree@gmail.com>
Co-authored-by: Ajay Tripathy <ajay@kubecost.com>
Artur Khantimirov пре 2 година
родитељ
комит
12b268e424
3 измењених фајлова са 22 додато и 0 уклоњено
  1. 1 0
      pkg/costmodel/metrics.go
  2. 5 0
      pkg/env/costmodelenv.go
  3. 16 0
      pkg/metrics/kubemetrics.go

+ 1 - 0
pkg/costmodel/metrics.go

@@ -345,6 +345,7 @@ func NewCostModelMetricsEmitter(promClient promclient.Client, clusterCache clust
 		EmitPodAnnotations:            env.IsEmitPodAnnotationsMetric(),
 		EmitKubeStateMetrics:          env.IsEmitKsmV1Metrics(),
 		EmitKubeStateMetricsV1Only:    env.IsEmitKsmV1MetricsOnly(),
+		EmitDeprecatedMetrics:         env.IsEmitDeprecatedMetrics(),
 	})
 
 	metrics.InitOpencostTelemetry(metricsConfig)

+ 5 - 0
pkg/env/costmodelenv.go

@@ -43,6 +43,7 @@ const (
 
 	EmitPodAnnotationsMetricEnvVar       = "EMIT_POD_ANNOTATIONS_METRIC"
 	EmitNamespaceAnnotationsMetricEnvVar = "EMIT_NAMESPACE_ANNOTATIONS_METRIC"
+	EmitDeprecatedMetrics                = "EMIT_DEPRECATED_METRICS"
 
 	EmitKsmV1MetricsEnvVar = "EMIT_KSM_V1_METRICS"
 	EmitKsmV1MetricsOnly   = "EMIT_KSM_V1_METRICS_ONLY"
@@ -252,6 +253,10 @@ func IsEmitKsmV1MetricsOnly() bool {
 	return env.GetBool(EmitKsmV1MetricsOnly, false)
 }
 
+func IsEmitDeprecatedMetrics() bool {
+	return env.GetBool(EmitDeprecatedMetrics, false)
+}
+
 // GetAWSAccessKeyID returns the environment variable value for AWSAccessKeyIDEnvVar which represents
 // the AWS access key for authentication
 func GetAWSAccessKeyID() string {

+ 16 - 0
pkg/metrics/kubemetrics.go

@@ -29,6 +29,7 @@ type KubeMetricsOpts struct {
 	EmitPodAnnotations            bool
 	EmitKubeStateMetrics          bool
 	EmitKubeStateMetricsV1Only    bool
+	EmitDeprecatedMetrics         bool
 }
 
 // DefaultKubeMetricsOpts returns KubeMetricsOpts with default values set
@@ -39,6 +40,7 @@ func DefaultKubeMetricsOpts() *KubeMetricsOpts {
 		EmitPodAnnotations:            false,
 		EmitKubeStateMetrics:          true,
 		EmitKubeStateMetricsV1Only:    false,
+		EmitDeprecatedMetrics:         false,
 	}
 }
 
@@ -49,6 +51,20 @@ func InitKubeMetrics(clusterCache clustercache.ClusterCache, metricsConfig *Metr
 	}
 
 	kubeMetricInit.Do(func() {
+		if !opts.EmitDeprecatedMetrics {
+			metricsConfig.DisabledMetrics = append(metricsConfig.DisabledMetrics,
+				"kube_pod_container_resource_limits",
+				"kube_pod_container_resource_limits_memory_bytes",
+				"kube_pod_container_resource_limits_cpu_cores",
+				"kube_pod_container_status_restarts_total",
+				"kube_node_status_condition",
+				"kube_deployment_status_replicas_available",
+				"kube_deployment_spec_replicas",
+				"kube_persistentvolume_status_phase",
+				"kube_pod_status_phase",
+			)
+		}
+
 		if opts.EmitKubecostControllerMetrics {
 			prometheus.MustRegister(KubecostServiceCollector{
 				KubeClusterCache: clusterCache,