From 7ec52cf6059636186b3c27d1bc6b832628675b6c Mon Sep 17 00:00:00 2001 From: rickbrouwer Date: Sun, 17 Nov 2024 20:02:41 +0100 Subject: [PATCH] Remove Prometheus metric deprecations Signed-off-by: rickbrouwer --- CHANGELOG.md | 2 +- pkg/metricscollector/prommetrics.go | 105 ---------------------------- 2 files changed, 1 insertion(+), 106 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dbba7b57a05..97106ed93b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -84,7 +84,7 @@ New deprecation(s): ### Breaking Changes -- TODO ([#XXX](https://github.com/kedacore/keda/issues/XXX)) +*General**: Remove Prometheus metric deprecations ([#5687](https://github.com/kedacore/keda/issues/5687)) ### Other diff --git a/pkg/metricscollector/prommetrics.go b/pkg/metricscollector/prommetrics.go index a5b9bc6c5b8..976be5a2ecd 100644 --- a/pkg/metricscollector/prommetrics.go +++ b/pkg/metricscollector/prommetrics.go @@ -17,7 +17,6 @@ limitations under the License. package metricscollector import ( - "fmt" "runtime" "strconv" "time" @@ -30,10 +29,6 @@ import ( "github.com/kedacore/keda/v2/version" ) -// bestPracticeDeprecatedMsg is a constant string that is used to indicate that a metric is deprecated as -// part of best practice refactoring - https://github.com/kedacore/keda/pull/5174 -const bestPracticeDeprecatedMsg = "DEPRECATED - will be removed in 2.16:" - var log = logf.Log.WithName("prometheus_server") var ( @@ -55,15 +50,6 @@ var ( }, metricLabels, ) - scalerMetricsLatencyDeprecated = prometheus.NewGaugeVec( - prometheus.GaugeOpts{ - Namespace: DefaultPromMetricsNamespace, - Subsystem: "scaler", - Name: "metrics_latency", - Help: fmt.Sprintf("%v use 'keda_scaler_metrics_latency_seconds' instead.", bestPracticeDeprecatedMsg), - }, - metricLabels, - ) scalerMetricsLatency = prometheus.NewGaugeVec( prometheus.GaugeOpts{ Namespace: DefaultPromMetricsNamespace, @@ -91,24 +77,6 @@ var ( }, []string{"namespace", "scaledObject"}, ) - scalerErrorsDeprecated = prometheus.NewCounterVec( - prometheus.CounterOpts{ - Namespace: DefaultPromMetricsNamespace, - Subsystem: "scaler", - Name: "errors", - Help: fmt.Sprintf("%v use 'keda_scaler_detail_errors_total' instead.", bestPracticeDeprecatedMsg), - }, - metricLabels, - ) - scalerErrorsTotalDeprecated = prometheus.NewCounterVec( - prometheus.CounterOpts{ - Namespace: DefaultPromMetricsNamespace, - Subsystem: "scaler", - Name: "errors_total", - Help: fmt.Sprintf("%v use use a `sum(keda_scaler_detail_errors_total{scaler!=\"\"})` over all scalers", bestPracticeDeprecatedMsg), - }, - []string{}, - ) scalerErrors = prometheus.NewCounterVec( prometheus.CounterOpts{ Namespace: DefaultPromMetricsNamespace, @@ -118,15 +86,6 @@ var ( }, metricLabels, ) - scaledObjectErrorsDeprecated = prometheus.NewCounterVec( - prometheus.CounterOpts{ - Namespace: DefaultPromMetricsNamespace, - Subsystem: "scaled_object", - Name: "errors", - Help: fmt.Sprintf("%v use 'keda_scaled_object_errors_total' instead.", bestPracticeDeprecatedMsg), - }, - []string{"namespace", "scaledObject"}, - ) scaledObjectErrors = prometheus.NewCounterVec( prometheus.CounterOpts{ Namespace: DefaultPromMetricsNamespace, @@ -136,15 +95,6 @@ var ( }, []string{"namespace", "scaledObject"}, ) - scaledJobErrorsDeprecated = prometheus.NewCounterVec( - prometheus.CounterOpts{ - Namespace: DefaultPromMetricsNamespace, - Subsystem: "scaled_job", - Name: "errors", - Help: fmt.Sprintf("%v use 'keda_scaled_job_errors_total' instead.", bestPracticeDeprecatedMsg), - }, - []string{"namespace", "scaledJob"}, - ) scaledJobErrors = prometheus.NewCounterVec( prometheus.CounterOpts{ Namespace: DefaultPromMetricsNamespace, @@ -154,16 +104,6 @@ var ( }, []string{"namespace", "scaledJob"}, ) - - triggerTotalsGaugeVecDeprecated = prometheus.NewGaugeVec( - prometheus.GaugeOpts{ - Namespace: DefaultPromMetricsNamespace, - Subsystem: "trigger", - Name: "totals", - Help: fmt.Sprintf("%v use 'keda_trigger_registered_total' instead.", bestPracticeDeprecatedMsg), - }, - []string{"type"}, - ) triggerRegistered = prometheus.NewGaugeVec( prometheus.GaugeOpts{ Namespace: DefaultPromMetricsNamespace, @@ -173,15 +113,6 @@ var ( }, []string{"type"}, ) - crdTotalsGaugeVecDeprecated = prometheus.NewGaugeVec( - prometheus.GaugeOpts{ - Namespace: DefaultPromMetricsNamespace, - Subsystem: "resource", - Name: "totals", - Help: fmt.Sprintf("%v use 'keda_resource_registered_total' instead.", bestPracticeDeprecatedMsg), - }, - []string{"type", "namespace"}, - ) crdRegistered = prometheus.NewGaugeVec( prometheus.GaugeOpts{ Namespace: DefaultPromMetricsNamespace, @@ -191,15 +122,6 @@ var ( }, []string{"type", "namespace"}, ) - internalLoopLatencyDeprecated = prometheus.NewGaugeVec( - prometheus.GaugeOpts{ - Namespace: DefaultPromMetricsNamespace, - Subsystem: "internal_scale_loop", - Name: "latency", - Help: fmt.Sprintf("%v use 'keda_internal_scale_loop_latency_seconds' instead.", bestPracticeDeprecatedMsg), - }, - []string{"namespace", "type", "resource"}, - ) internalLoopLatency = prometheus.NewGaugeVec( prometheus.GaugeOpts{ Namespace: DefaultPromMetricsNamespace, @@ -236,25 +158,17 @@ type PromMetrics struct { } func NewPromMetrics() *PromMetrics { - metrics.Registry.MustRegister(scalerErrorsTotalDeprecated) metrics.Registry.MustRegister(scalerMetricsValue) - metrics.Registry.MustRegister(scalerMetricsLatencyDeprecated) metrics.Registry.MustRegister(scalerMetricsLatency) - metrics.Registry.MustRegister(internalLoopLatencyDeprecated) metrics.Registry.MustRegister(internalLoopLatency) metrics.Registry.MustRegister(scalerActive) - metrics.Registry.MustRegister(scalerErrorsDeprecated) metrics.Registry.MustRegister(scalerErrors) - metrics.Registry.MustRegister(scaledObjectErrorsDeprecated) metrics.Registry.MustRegister(scaledObjectErrors) metrics.Registry.MustRegister(scaledObjectPaused) metrics.Registry.MustRegister(triggerRegistered) metrics.Registry.MustRegister(crdRegistered) - metrics.Registry.MustRegister(scaledJobErrorsDeprecated) metrics.Registry.MustRegister(scaledJobErrors) - metrics.Registry.MustRegister(triggerTotalsGaugeVecDeprecated) - metrics.Registry.MustRegister(crdTotalsGaugeVecDeprecated) metrics.Registry.MustRegister(buildInfo) metrics.Registry.MustRegister(cloudeventEmitted) @@ -277,13 +191,11 @@ func (p *PromMetrics) RecordScalerMetric(namespace string, scaledResource string // RecordScalerLatency create a measurement of the latency to external metric func (p *PromMetrics) RecordScalerLatency(namespace string, scaledResource string, scaler string, triggerIndex int, metric string, isScaledObject bool, value time.Duration) { scalerMetricsLatency.With(getLabels(namespace, scaledResource, scaler, triggerIndex, metric, isScaledObject)).Set(value.Seconds()) - scalerMetricsLatencyDeprecated.With(getLabels(namespace, scaledResource, scaler, triggerIndex, metric, isScaledObject)).Set(float64(value.Milliseconds())) } // RecordScalableObjectLatency create a measurement of the latency executing scalable object loop func (p *PromMetrics) RecordScalableObjectLatency(namespace string, name string, isScaledObject bool, value time.Duration) { internalLoopLatency.WithLabelValues(namespace, getResourceType(isScaledObject), name).Set(value.Seconds()) - internalLoopLatencyDeprecated.WithLabelValues(namespace, getResourceType(isScaledObject), name).Set(float64(value.Milliseconds())) } // RecordScalerActive create a measurement of the activity of the scaler @@ -312,9 +224,7 @@ func (p *PromMetrics) RecordScaledObjectPaused(namespace string, scaledObject st func (p *PromMetrics) RecordScalerError(namespace string, scaledResource string, scaler string, triggerIndex int, metric string, isScaledObject bool, err error) { if err != nil { scalerErrors.With(getLabels(namespace, scaledResource, scaler, triggerIndex, metric, isScaledObject)).Inc() - scalerErrorsDeprecated.With(getLabels(namespace, scaledResource, scaler, triggerIndex, metric, isScaledObject)).Inc() p.RecordScaledObjectError(namespace, scaledResource, err) - scalerErrorsTotalDeprecated.With(prometheus.Labels{}).Inc() return } // initialize metric with 0 if not already set @@ -322,10 +232,6 @@ func (p *PromMetrics) RecordScalerError(namespace string, scaledResource string, if errscaler != nil { log.Error(errscaler, "Unable to record metrics: %v") } - _, errscalerdep := scalerErrorsDeprecated.GetMetricWith(getLabels(namespace, scaledResource, scaler, triggerIndex, metric, isScaledObject)) - if errscalerdep != nil { - log.Error(errscaler, "Unable to record (deprecated) metrics: %v") - } } // RecordScaledObjectError counts the number of errors with the scaled object @@ -333,7 +239,6 @@ func (p *PromMetrics) RecordScaledObjectError(namespace string, scaledObject str labels := prometheus.Labels{"namespace": namespace, "scaledObject": scaledObject} if err != nil { scaledObjectErrors.With(labels).Inc() - scaledObjectErrorsDeprecated.With(labels).Inc() return } // initialize metric with 0 if not already set @@ -342,18 +247,12 @@ func (p *PromMetrics) RecordScaledObjectError(namespace string, scaledObject str log.Error(errscaledobject, "Unable to record metrics: %v") return } - _, errscaledobjectdep := scaledObjectErrorsDeprecated.GetMetricWith(labels) - if errscaledobjectdep != nil { - log.Error(errscaledobject, "Unable to record metrics: %v") - return - } } // RecordScaledJobError counts the number of errors with the scaled job func (p *PromMetrics) RecordScaledJobError(namespace string, scaledJob string, err error) { labels := prometheus.Labels{"namespace": namespace, "scaledJob": scaledJob} if err != nil { - scaledJobErrorsDeprecated.With(labels).Inc() scaledJobErrors.With(labels).Inc() return } @@ -379,14 +278,12 @@ func getResourceType(isScaledObject bool) string { func (p *PromMetrics) IncrementTriggerTotal(triggerType string) { if triggerType != "" { triggerRegistered.WithLabelValues(triggerType).Inc() - triggerTotalsGaugeVecDeprecated.WithLabelValues(triggerType).Inc() } } func (p *PromMetrics) DecrementTriggerTotal(triggerType string) { if triggerType != "" { triggerRegistered.WithLabelValues(triggerType).Dec() - triggerTotalsGaugeVecDeprecated.WithLabelValues(triggerType).Dec() } } @@ -396,7 +293,6 @@ func (p *PromMetrics) IncrementCRDTotal(crdType, namespace string) { } crdRegistered.WithLabelValues(crdType, namespace).Inc() - crdTotalsGaugeVecDeprecated.WithLabelValues(crdType, namespace).Inc() } func (p *PromMetrics) DecrementCRDTotal(crdType, namespace string) { @@ -405,7 +301,6 @@ func (p *PromMetrics) DecrementCRDTotal(crdType, namespace string) { } crdRegistered.WithLabelValues(crdType, namespace).Dec() - crdTotalsGaugeVecDeprecated.WithLabelValues(crdType, namespace).Dec() } // RecordCloudEventEmitted counts the number of cloudevent that emitted to user's sink