code: func (d *apiVersionsFromDiscovery) chooseVersion(apiGroup *metav1.APIGroup) (schema.GroupVersion, error) {
  	var preferredVersion *schema.GroupVersion
  	if gv, present := metricVersionsToGV[apiGroup.PreferredVersion.GroupVersion]; present && len(apiGroup.PreferredVersion.GroupVersion) != 0 {
  		preferredVersion = &gv
  	} else {
  		for _, version := range apiGroup.Versions {
  			if gv, present := metricVersionsToGV[version.GroupVersion]; present {
  				preferredVersion = &gv
  				break
  			}
  		}
  	}
  
  	if preferredVersion == nil {
  		return schema.GroupVersion{}, fmt.Errorf("no known available metric versions found")
  	}
  	return *preferredVersion, nil
  }
docs: // chooseVersion sets a preferred version of the custom metrics api based on available versions.