Skip to content

Metrics API scaler: average aggregation returns +Inf when all kube service endpoints fail #7742

@dttung2905

Description

@dttung2905

Report

When the metrics-api scaler aggregates metrics from multiple Kubernetes service endpoints with aggregationType: average (the default), and every endpoint request fails, aggregateMetricsFromMultipleEndpoints still divides the aggregated value by expectedNbMetrics after it has been decremented to 0.

if s.metadata.AggregationType == AverageAggregationType {
aggregation /= float64(expectedNbMetrics)

Expected Behavior

When no endpoint returns a successful metric:

  • The scaler should not perform average division with a zero divisor.
  • It should return a clear error (e.g. could not fetch from any endpoint).
  • The reported metric value should remain finite (e.g. 0) and must not be +Inf / NaN.

Actual Behavior

When all parallel endpoint fetches fail:

  1. Each failure decrements expectedNbMetrics.
  2. expectedNbMetrics reaches 0.
  3. The code still runs aggregation /= float64(expectedNbMetrics) for aggregationType: average.
  4. The function can return +Inf (or NaN) as the metric value.

Steps to Reproduce the Problem

.

Logs from KEDA operator

example

KEDA Version

2.19.0

Kubernetes Version

None

Platform

None

Scaler Details

metrics_api_scaler

Would you be open to contributing a fix?

Yes

Anything else?

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingscalerscaler-metrics-apiAll issues related to our Metrics API scaler

Type

No type
No fields configured for issues without a type.

Projects

Status

Ready To Ship

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions