Extra debug information in HPA events
This commit is contained in:
		@@ -27,6 +27,7 @@ import (
 | 
				
			|||||||
	"k8s.io/kubernetes/pkg/api/v1"
 | 
						"k8s.io/kubernetes/pkg/api/v1"
 | 
				
			||||||
	clientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
 | 
						clientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
 | 
				
			||||||
	"k8s.io/kubernetes/pkg/labels"
 | 
						"k8s.io/kubernetes/pkg/labels"
 | 
				
			||||||
 | 
						"k8s.io/kubernetes/pkg/util/sets"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	heapster "k8s.io/heapster/metrics/api/v1/types"
 | 
						heapster "k8s.io/heapster/metrics/api/v1/types"
 | 
				
			||||||
	metrics_api "k8s.io/heapster/metrics/apis/metrics/v1alpha1"
 | 
						metrics_api "k8s.io/heapster/metrics/apis/metrics/v1alpha1"
 | 
				
			||||||
@@ -172,7 +173,21 @@ func (h *HeapsterMetricsClient) getCpuUtilizationForPods(namespace string, selec
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if len(metrics) != len(podNames) {
 | 
						if len(metrics) != len(podNames) {
 | 
				
			||||||
		return 0, time.Time{}, fmt.Errorf("metrics obtained for %d/%d of pods", len(metrics), len(podNames))
 | 
							present := sets.NewString()
 | 
				
			||||||
 | 
							for _, m := range metrics {
 | 
				
			||||||
 | 
								present.Insert(m.Name)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							missing := make([]string, 0)
 | 
				
			||||||
 | 
							for expected := range podNames {
 | 
				
			||||||
 | 
								if !present.Has(expected) {
 | 
				
			||||||
 | 
									missing = append(missing, expected)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							hint := ""
 | 
				
			||||||
 | 
							if len(missing) > 0 {
 | 
				
			||||||
 | 
								hint = fmt.Sprintf(" (sample missing pod: %s/%s)", namespace, missing[0])
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return 0, time.Time{}, fmt.Errorf("metrics obtained for %d/%d of pods%s", len(metrics), len(podNames), hint)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	sum := int64(0)
 | 
						sum := int64(0)
 | 
				
			||||||
@@ -250,7 +265,17 @@ func (h *HeapsterMetricsClient) getCustomMetricForPods(metricSpec metricDefiniti
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	sum, count, timestamp := metricSpec.aggregator(metrics)
 | 
						sum, count, timestamp := metricSpec.aggregator(metrics)
 | 
				
			||||||
	if count != len(podNames) {
 | 
						if count != len(podNames) {
 | 
				
			||||||
		return nil, time.Time{}, fmt.Errorf("metrics obtained for %d/%d of pods", count, len(podNames))
 | 
							missing := make([]string, 0)
 | 
				
			||||||
 | 
							for i, expected := range podNames {
 | 
				
			||||||
 | 
								if len(metrics.Items) > i && len(metrics.Items[i].Metrics) == 0 {
 | 
				
			||||||
 | 
									missing = append(missing, expected)
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							hint := ""
 | 
				
			||||||
 | 
							if len(missing) > 0 {
 | 
				
			||||||
 | 
								hint = fmt.Sprintf(" (sample missing pod: %s/%s)", namespace, missing[0])
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							return nil, time.Time{}, fmt.Errorf("metrics obtained for %d/%d of pods%s", count, len(podNames), hint)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return &sum, timestamp, nil
 | 
						return &sum, timestamp, nil
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -184,10 +184,12 @@ func buildPod(namespace, podName string, podLabels map[string]string, phase api.
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (tc *testCase) verifyResults(t *testing.T, val *float64, timestamp time.Time, err error) {
 | 
					func (tc *testCase) verifyResults(t *testing.T, val *float64, timestamp time.Time, err error) {
 | 
				
			||||||
	assert.Equal(t, tc.desiredError, err)
 | 
					 | 
				
			||||||
	if tc.desiredError != nil {
 | 
						if tc.desiredError != nil {
 | 
				
			||||||
 | 
							assert.Error(t, err)
 | 
				
			||||||
 | 
							assert.Contains(t, fmt.Sprintf("%v", err), fmt.Sprintf("%v", tc.desiredError))
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						assert.NoError(t, err)
 | 
				
			||||||
	assert.NotNil(t, val)
 | 
						assert.NotNil(t, val)
 | 
				
			||||||
	assert.True(t, tc.desiredValue-0.001 < *val)
 | 
						assert.True(t, tc.desiredValue-0.001 < *val)
 | 
				
			||||||
	assert.True(t, tc.desiredValue+0.001 > *val)
 | 
						assert.True(t, tc.desiredValue+0.001 > *val)
 | 
				
			||||||
@@ -426,7 +428,7 @@ func TestCPUEmptyMetricsForOnePod(t *testing.T) {
 | 
				
			|||||||
	tc := testCase{
 | 
						tc := testCase{
 | 
				
			||||||
		replicas:           3,
 | 
							replicas:           3,
 | 
				
			||||||
		targetResource:     "cpu-usage",
 | 
							targetResource:     "cpu-usage",
 | 
				
			||||||
		desiredError:       fmt.Errorf("metrics obtained for 2/3 of pods"),
 | 
							desiredError:       fmt.Errorf("metrics obtained for 2/3 of pods (sample missing pod: test-namespace/test-pod-2)"),
 | 
				
			||||||
		reportedPodMetrics: [][]int64{{100}, {300, 400}},
 | 
							reportedPodMetrics: [][]int64{{100}, {300, 400}},
 | 
				
			||||||
		useMetricsApi:      true,
 | 
							useMetricsApi:      true,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user