code: func (c *ReplicaCalculator) GetExternalMetricReplicas(currentReplicas int32, targetUtilization int64, metricName, namespace string, metricSelector *metav1.LabelSelector, podSelector labels.Selector) (replicaCount int32, utilization int64, timestamp time.Time, err error) {
  	metricLabelSelector, err := metav1.LabelSelectorAsSelector(metricSelector)
  	if err != nil {
  		return 0, 0, time.Time{}, err
  	}
  	metrics, timestamp, err := c.metricsClient.GetExternalMetric(metricName, namespace, metricLabelSelector)
  	if err != nil {
  		return 0, 0, time.Time{}, fmt.Errorf("unable to get external metric %s/%s/%+v: %s", namespace, metricName, metricSelector, err)
  	}
  	utilization = 0
  	for _, val := range metrics {
  		utilization = utilization + val
  	}
  
  	readyPodCount, err := c.getReadyPodsCount(namespace, podSelector)
  
  	if err != nil {
  		return 0, 0, time.Time{}, fmt.Errorf("unable to calculate ready pods: %s", err)
  	}
  
  	usageRatio := float64(utilization) / float64(targetUtilization)
  	if math.Abs(1.0-usageRatio) <= c.tolerance {
  		// return the current replicas if the change would be too small
  		return currentReplicas, utilization, timestamp, nil
  	}
  
  	return int32(math.Ceil(usageRatio * float64(readyPodCount))), utilization, timestamp, nil
  }
docs: // GetExternalMetricReplicas calculates the desired replica count based on a
  // target metric value (as a milli-value) for the external metric in the given
  // namespace, and the current replica count.