diff --git a/CHANGELOG.md b/CHANGELOG.md index 0bab761e749..5981ceeb376 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,7 @@ Here is an overview of all new **experimental** features: - **General**: Prevent a panic that might occur while refreshing a scaler cache ([#4092](https://github.com/kedacore/keda/issues/4092)) - **Azure Service Bus Scaler:** Use correct auth flows with pod identity ([#4026](https://github.com/kedacore/keda/issues/4026)) +- **Prometheus Metrics**: Fix exposed metric from `keda_scaled_errors` to `keda_scaled_object_errors` ([#4037](https://github.com/kedacore/keda/issues/4037)) ### Deprecations diff --git a/pkg/scaling/cache/scalers_cache.go b/pkg/scaling/cache/scalers_cache.go index 813ed7b4bfc..6b61d6f9aa5 100644 --- a/pkg/scaling/cache/scalers_cache.go +++ b/pkg/scaling/cache/scalers_cache.go @@ -235,17 +235,20 @@ func (c *ScalersCache) refreshScaler(ctx context.Context, id int) (scalers.Scale } sb := c.Scalers[id] + defer sb.Scaler.Close(ctx) ns, sConfig, err := sb.Factory() if err != nil { return nil, err } + if id < 0 || id >= len(c.Scalers) { + return nil, fmt.Errorf("scaler with id %d not found. Len = %d", id, len(c.Scalers)) + } c.Scalers[id] = ScalerBuilder{ Scaler: ns, ScalerConfig: *sConfig, Factory: sb.Factory, } - sb.Scaler.Close(ctx) return ns, nil }