@@ -224,6 +224,7 @@ func getValueFromPrometheusResponse(body []byte, valueLocation string) (float64,
224224// getValueFromJSONResponse uses provided valueLocation to access the numeric value in provided body using GJSON
225225func getValueFromJSONResponse (body []byte , valueLocation string ) (float64 , error ) {
226226 r := gjson .GetBytes (body , valueLocation )
227+
227228 if r .Type == gjson .String {
228229 v , err := resource .ParseQuantity (r .String ())
229230 if err != nil {
@@ -400,6 +401,7 @@ func (s *metricsAPIScaler) aggregateMetricsFromMultipleEndpoints(ctx context.Con
400401 var err error
401402 var firstMetricEncountered bool
402403 var aggregation float64
404+ s .logger .V (1 ).Info (fmt .Sprintf ("start iterating %d endpoint urls" , len (endpointsUrls )))
403405 for _ , endpointURL := range endpointsUrls {
404406 if err := sem .Acquire (ctx , 1 ); err != nil {
405407 s .logger .Error (err , "Failed to acquire semaphore" )
@@ -437,6 +439,11 @@ func (s *metricsAPIScaler) aggregateMetricsFromMultipleEndpoints(ctx context.Con
437439 }
438440 }(endpointURL )
439441 }
442+ // Wait that all goroutines have released their semaphore acquisition
443+ if err := sem .Acquire (ctx , maxGoroutines ); err != nil {
444+ s .logger .V (1 ).Error (err , "final semaphore acquisition failed" )
445+ }
446+ s .logger .V (1 ).Info (fmt .Sprintf ("ENDED iterating %d endpoint urls, aggregation is now %v" , len (endpointsUrls ), aggregation ))
440447
441448 if nbErrors > 0 && nbErrors == len (endpointsUrls ) {
442449 err = fmt .Errorf ("could not get any metric successfully from the %d provided endpoints" , len (endpointsUrls ))
@@ -470,6 +477,7 @@ func (s *metricsAPIScaler) getMetricValueFromURL(ctx context.Context, url *strin
470477 return 0 , err
471478 }
472479 v , err := GetValueFromResponse (b , s .metadata .ValueLocation , s .metadata .Format )
480+
473481 if err != nil {
474482 return 0 , err
475483 }
0 commit comments