Skip to content

Commit

Permalink
Remove Prometheus metric deprecations
Browse files Browse the repository at this point in the history
Signed-off-by: rickbrouwer <[email protected]>
  • Loading branch information
rickbrouwer committed Nov 17, 2024
1 parent 8332446 commit 353e1fd
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 105 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
104 changes: 0 additions & 104 deletions pkg/metricscollector/prommetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,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 (
Expand All @@ -55,15 +51,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,
Expand Down Expand Up @@ -91,24 +78,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,
Expand All @@ -118,15 +87,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,
Expand All @@ -136,15 +96,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,
Expand All @@ -154,16 +105,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,
Expand All @@ -173,15 +114,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,
Expand All @@ -191,15 +123,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,
Expand Down Expand Up @@ -236,25 +159,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)
Expand All @@ -277,13 +192,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
Expand Down Expand Up @@ -312,28 +225,21 @@ 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
_, errscaler := scalerErrors.GetMetricWith(getLabels(namespace, scaledResource, scaler, triggerIndex, metric, isScaledObject))
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
func (p *PromMetrics) RecordScaledObjectError(namespace string, scaledObject string, err error) {
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
Expand All @@ -342,18 +248,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
}
Expand All @@ -379,14 +279,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()
}
}

Expand All @@ -396,7 +294,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) {
Expand All @@ -405,7 +302,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
Expand Down

0 comments on commit 353e1fd

Please sign in to comment.