Skip to content

Commit 1c4ceae

Browse files
relates to discussion #6565 (comment) (#7370)
the final semaphore acquisition was still missing, which resulted in loop not waiting until all metrics were gathered from each metrics API server Signed-off-by: julian GUINARD <[email protected]>
1 parent 68d5637 commit 1c4ceae

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

pkg/scalers/metrics_api_scaler.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ func (s *metricsAPIScaler) aggregateMetricsFromMultipleEndpoints(ctx context.Con
400400
var err error
401401
var firstMetricEncountered bool
402402
var aggregation float64
403+
s.logger.V(1).Info(fmt.Sprintf("start iterating %d endpoint urls", len(endpointsUrls)))
403404
for _, endpointURL := range endpointsUrls {
404405
if err := sem.Acquire(ctx, 1); err != nil {
405406
s.logger.Error(err, "Failed to acquire semaphore")
@@ -437,6 +438,11 @@ func (s *metricsAPIScaler) aggregateMetricsFromMultipleEndpoints(ctx context.Con
437438
}
438439
}(endpointURL)
439440
}
441+
// Wait that all goroutines have released their semaphore acquisition
442+
if err := sem.Acquire(ctx, maxGoroutines); err != nil {
443+
s.logger.V(1).Error(err, "final semaphore acquisition failed")
444+
}
445+
s.logger.V(1).Info(fmt.Sprintf("ENDED iterating %d endpoint urls, aggregation is now %v", len(endpointsUrls), aggregation))
440446

441447
if nbErrors > 0 && nbErrors == len(endpointsUrls) {
442448
err = fmt.Errorf("could not get any metric successfully from the %d provided endpoints", len(endpointsUrls))

0 commit comments

Comments
 (0)