Merge pull request #57752 from mattjmcnaughton/mattjmcnaughton/clarify-error-messages-metrics-hpa

Automatic merge from submit-queue (batch tested with PRs 57810, 57752). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

Clarify error messages in HPA metrics

**What this PR does / why we need it**:

With the introduction of the RESTMetrics client, there are two ways to
fetch metrics for auto-scaling. However, they previously shared error
messages. This could be misleading. Make the error message more clearly
show which method is in use.

**Special notes for your reviewer**:

@DirectXMan12 re conversation in #56827 

**Release note**:

```release-note
NONE
```
pull/6/head
Kubernetes Submit Queue 2018-01-04 13:01:30 -08:00 committed by GitHub
commit 91a6fbcdac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 6 deletions

View File

@ -58,11 +58,11 @@ type resourceMetricsClient struct {
func (c *resourceMetricsClient) GetResourceMetric(resource v1.ResourceName, namespace string, selector labels.Selector) (PodMetricsInfo, time.Time, error) {
metrics, err := c.client.PodMetricses(namespace).List(metav1.ListOptions{LabelSelector: selector.String()})
if err != nil {
return nil, time.Time{}, fmt.Errorf("unable to fetch metrics from API: %v", err)
return nil, time.Time{}, fmt.Errorf("unable to fetch metrics from resource metrics API: %v", err)
}
if len(metrics.Items) == 0 {
return nil, time.Time{}, fmt.Errorf("no metrics returned from heapster")
return nil, time.Time{}, fmt.Errorf("no metrics returned from resource metrics API")
}
res := make(PodMetricsInfo, len(metrics.Items))
@ -101,7 +101,7 @@ type customMetricsClient struct {
func (c *customMetricsClient) GetRawMetric(metricName string, namespace string, selector labels.Selector) (PodMetricsInfo, time.Time, error) {
metrics, err := c.client.NamespacedMetrics(namespace).GetForObjects(schema.GroupKind{Kind: "Pod"}, selector, metricName)
if err != nil {
return nil, time.Time{}, fmt.Errorf("unable to fetch metrics from API: %v", err)
return nil, time.Time{}, fmt.Errorf("unable to fetch metrics from custom metrics API: %v", err)
}
if len(metrics.Items) == 0 {
@ -134,7 +134,7 @@ func (c *customMetricsClient) GetObjectMetric(metricName string, namespace strin
}
if err != nil {
return 0, time.Time{}, fmt.Errorf("unable to fetch metrics from API: %v", err)
return 0, time.Time{}, fmt.Errorf("unable to fetch metrics from custom metrics API: %v", err)
}
return metricValue.Value.MilliValue(), metricValue.Timestamp.Time, nil

View File

@ -252,7 +252,7 @@ func TestRESTClientQpsSumEqualZero(t *testing.T) {
func TestRESTClientCPUEmptyMetrics(t *testing.T) {
tc := restClientTestCase{
resourceName: v1.ResourceCPU,
desiredError: fmt.Errorf("no metrics returned from heapster"),
desiredError: fmt.Errorf("no metrics returned from resource metrics API"),
reportedMetricPoints: []metricPoint{},
reportedPodMetrics: [][]int64{},
}

View File

@ -579,7 +579,7 @@ func TestReplicaCalcMissingMetrics(t *testing.T) {
func TestReplicaCalcEmptyMetrics(t *testing.T) {
tc := replicaCalcTestCase{
currentReplicas: 4,
expectedError: fmt.Errorf("unable to get metrics for resource cpu: no metrics returned from heapster"),
expectedError: fmt.Errorf("unable to get metrics for resource cpu: no metrics returned from resource metrics API"),
resource: &resourceInfo{
name: v1.ResourceCPU,
requests: []resource.Quantity{resource.MustParse("1.0"), resource.MustParse("1.0"), resource.MustParse("1.0")},