Skip to content

Commit

Permalink
add back scaled_job_errors metric with deprecation message
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Wozniak <[email protected]>
  • Loading branch information
wozniakjan committed Apr 12, 2024
1 parent e8d3c37 commit 3697c27
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions pkg/metricscollector/prommetrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package metricscollector

import (
"fmt"
"runtime"
"strconv"
"time"
Expand All @@ -29,6 +30,11 @@ import (
"github.com/kedacore/keda/v2/version"
)

// deprecatedMsg 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 deprecatedMsg = "DEPRECATED - will be removed in 2.16:"

var log = logf.Log.WithName("prometheus_server")

var (
Expand All @@ -55,7 +61,7 @@ var (
Namespace: DefaultPromMetricsNamespace,
Subsystem: "scaler",
Name: "metrics_latency",
Help: "DEPRECATED - will be removed in 2.16 use 'keda_scaler_metrics_latency_seconds' instead.",
Help: fmt.Sprintf("%v use 'keda_scaler_metrics_latency_seconds' instead.", deprecatedMsg),
},
metricLabels,
)
Expand Down Expand Up @@ -91,7 +97,7 @@ var (
Namespace: DefaultPromMetricsNamespace,
Subsystem: "scaler",
Name: "errors",
Help: "DEPRECATED - will be removed in 2.16 - use 'keda_scaler_detail_errors_total' instead.",
Help: fmt.Sprintf("%v use 'keda_scaler_detail_errors_total' instead.", deprecatedMsg),
},
metricLabels,
)
Expand All @@ -100,7 +106,7 @@ var (
Namespace: DefaultPromMetricsNamespace,
Subsystem: "scaler",
Name: "errors_total",
Help: "DEPRECATED - will be removed in 2.16 - use a `sum(keda_scaler_detail_errors_total{scaler!=\"\"})` over all scalers",
Help: fmt.Sprintf("%v use use a `sum(keda_scaler_detail_errors_total{scaler!=\"\"})` over all scalers", deprecatedMsg),
},
[]string{},
)
Expand All @@ -118,7 +124,7 @@ var (
Namespace: DefaultPromMetricsNamespace,
Subsystem: "scaled_object",
Name: "errors",
Help: "DEPRECATED - will be removed in 2.16 - use 'keda_scaled_object_errors_total' instead.",
Help: fmt.Sprintf("%v use 'keda_scaled_object_errors_total' instead.", deprecatedMsg),
},
[]string{"namespace", "scaledObject"},
)
Expand All @@ -131,7 +137,15 @@ 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.", deprecatedMsg),
},
[]string{"namespace", "scaledJob"},
)
scaledJobErrors = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: DefaultPromMetricsNamespace,
Expand All @@ -147,7 +161,7 @@ var (
Namespace: DefaultPromMetricsNamespace,
Subsystem: "trigger",
Name: "totals",
Help: "DEPRECATED - will be removed in 2.16 - use 'keda_trigger_registered_total' instead.",
Help: fmt.Sprintf("%v use 'keda_trigger_registered_total' instead.", deprecatedMsg),
},
[]string{"type"},
)
Expand All @@ -165,7 +179,7 @@ var (
Namespace: DefaultPromMetricsNamespace,
Subsystem: "resource",
Name: "totals",
Help: "DEPRECATED - will be removed in 2.16 - use 'keda_resource_handled_total' instead.",
Help: fmt.Sprintf("%v use 'keda_resource_handled_total' instead."),
},
[]string{"type", "namespace"},
)
Expand All @@ -183,7 +197,7 @@ var (
Namespace: DefaultPromMetricsNamespace,
Subsystem: "internal_scale_loop",
Name: "latency",
Help: "DEPRECATED - will be removed in 2.16 - use 'keda_internal_scale_loop_latency_seconds' instead.",
Help: fmt.Sprintf("%v use 'keda_internal_scale_loop_latency_seconds' instead.", deprecatedMsg),
},
[]string{"namespace", "type", "resource"},
)
Expand Down Expand Up @@ -239,6 +253,7 @@ func NewPromMetrics() *PromMetrics {
metrics.Registry.MustRegister(triggerRegistered)
metrics.Registry.MustRegister(crdTotalsGaugeVecDeprecated)
metrics.Registry.MustRegister(crdRegistered)
metrics.Registry.MustRegister(scaledJobErrorsDeprecated)
metrics.Registry.MustRegister(scaledJobErrors)

metrics.Registry.MustRegister(buildInfo)
Expand Down Expand Up @@ -339,6 +354,7 @@ func (p *PromMetrics) RecordScaledObjectError(namespace string, scaledObject str
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 Down

0 comments on commit 3697c27

Please sign in to comment.