Skip to content

Commit

Permalink
fix: reports errors during upstream requests (#5664)
Browse files Browse the repository at this point in the history
* fix:  reports errors during upstream requests

Signed-off-by: Jorge Turrado <[email protected]>

* .

Signed-off-by: Jorge Turrado <[email protected]>

* move the metric

Signed-off-by: Jorge Turrado <[email protected]>

---------

Signed-off-by: Jorge Turrado <[email protected]>
Signed-off-by: Jorge Turrado Ferrero <[email protected]>
  • Loading branch information
JorTurFer authored Apr 10, 2024
1 parent 5ea0e25 commit 7611438
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Here is an overview of all new **experimental** features:

- **General**: Fix CVE-2024-28180 in github.com/go-jose/go-jose/v3 ([#5617](https://github.com/kedacore/keda/pull/5617))
- **General**: Log field `ScaledJob` no longer have conflicting types ([#5592](https://github.com/kedacore/keda/pull/5592))
- **General**: Prometheus metrics shows errors correctly ([#5597](https://github.com/kedacore/keda/issues/5597))
- **General**: Prometheus metrics shows errors correctly ([#5597](https://github.com/kedacore/keda/issues/5597)|[#5663](https://github.com/kedacore/keda/issues/5663))
- **General**: Validate empty array value of triggers in ScaledObject/ScaledJob creation ([#5520](https://github.com/kedacore/keda/issues/5520))
- **GitHub Runner Scaler**: Fixed `in_progress` detection on running jobs instead of just `queued` ([#5604](https://github.com/kedacore/keda/issues/5604))
- **New Relic Scaler**: Consider empty results set from query executer ([#5619](https://github.com/kedacore/keda/pull/5619))
Expand Down
12 changes: 7 additions & 5 deletions pkg/scaling/scale_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ func (h *scaleHandler) getScaledObjectState(ctx context.Context, scaledObject *k
isScaledObjectActive = true
activeTriggers = append(activeTriggers, result.TriggerName)
}
if result.IsError {
if result.Err != nil {
isScaledObjectError = true
}
matchingMetrics = append(matchingMetrics, result.Metrics...)
Expand All @@ -647,6 +647,8 @@ func (h *scaleHandler) getScaledObjectState(ctx context.Context, scaledObject *k
for k, v := range result.Records {
metricsRecord[k] = v
}

metricscollector.RecordScaledObjectError(scaledObject.Namespace, scaledObject.Name, result.Err)
}

// invalidate the cache for the ScaledObject, if we hit an error in any scaler
Expand Down Expand Up @@ -707,11 +709,11 @@ func (h *scaleHandler) getScaledObjectState(ctx context.Context, scaledObject *k
type scalerState struct {
// IsActive will be overrided by formula calculation
IsActive bool
IsError bool
TriggerName string
Metrics []external_metrics.ExternalMetricValue
Pairs map[string]string
Records map[string]metricscache.MetricsRecord
Err error
}

// getScalerState returns getStateScalerResult with the state
Expand All @@ -722,7 +724,7 @@ func (*scaleHandler) getScalerState(ctx context.Context, scaler scalers.Scaler,
cache *cache.ScalersCache, logger logr.Logger, scaledObject *kedav1alpha1.ScaledObject) scalerState {
result := scalerState{
IsActive: false,
IsError: false,
Err: nil,
TriggerName: "",
Metrics: []external_metrics.ExternalMetricValue{},
Pairs: map[string]string{},
Expand All @@ -736,7 +738,7 @@ func (*scaleHandler) getScalerState(ctx context.Context, scaler scalers.Scaler,

metricSpecs, err := cache.GetMetricSpecForScalingForScaler(ctx, triggerIndex)
if err != nil {
result.IsError = true
result.Err = err
logger.Error(err, "error getting metric spec for the scaler", "scaler", result.TriggerName)
cache.Recorder.Event(scaledObject, corev1.EventTypeWarning, eventreason.KEDAScalerFailed, err.Error())
}
Expand Down Expand Up @@ -766,7 +768,7 @@ func (*scaleHandler) getScalerState(ctx context.Context, scaler scalers.Scaler,
}

if err != nil {
result.IsError = true
result.Err = err
if scaledObject.IsUsingModifiers() {
logger.Error(err, "error getting metric source", "source", result.TriggerName)
cache.Recorder.Event(scaledObject, corev1.EventTypeWarning, eventreason.KEDAMetricSourceFailed, err.Error())
Expand Down

0 comments on commit 7611438

Please sign in to comment.