Merge pull request #125478 from aroradaman/handle-index-error

e2e/framework/metrics: handle index out of bounds panic
This commit is contained in:
Kubernetes Prow Robot 2024-06-16 12:46:29 -07:00 committed by GitHub
commit debd99542f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 4 deletions

View File

@ -17,6 +17,8 @@ limitations under the License.
package metrics
import (
"fmt"
"k8s.io/component-base/metrics/testutil"
)
@ -24,8 +26,11 @@ import (
type KubeProxyMetrics testutil.Metrics
// GetCounterMetricValue returns value for metric type counter.
func (m *KubeProxyMetrics) GetCounterMetricValue(metricName string) float64 {
return float64(testutil.Metrics(*m)[metricName][0].Value)
func (m *KubeProxyMetrics) GetCounterMetricValue(metricName string) (float64, error) {
if len(testutil.Metrics(*m)[metricName]) == 0 {
return 0, fmt.Errorf("metric '%s' not found", metricName)
}
return float64(testutil.Metrics(*m)[metricName][0].Value), nil
}
func newKubeProxyMetricsMetrics() KubeProxyMetrics {

View File

@ -299,7 +299,8 @@ var _ = common.SIGDescribe("KubeProxy", func() {
// get value of target metric before accessing localhost nodeports
metrics, err := metricsGrabber.GrabFromKubeProxy(ctx, nodeName)
framework.ExpectNoError(err)
targetMetricBefore := metrics.GetCounterMetricValue(metricName)
targetMetricBefore, err := metrics.GetCounterMetricValue(metricName)
framework.ExpectNoError(err)
// create pod
ginkgo.By("creating test pod")
@ -359,7 +360,8 @@ var _ = common.SIGDescribe("KubeProxy", func() {
if err := wait.PollUntilContextTimeout(ctx, 10*time.Second, 2*time.Minute, true, func(_ context.Context) (bool, error) {
metrics, err := metricsGrabber.GrabFromKubeProxy(ctx, nodeName)
framework.ExpectNoError(err)
targetMetricAfter := metrics.GetCounterMetricValue(metricName)
targetMetricAfter, err := metrics.GetCounterMetricValue(metricName)
framework.ExpectNoError(err)
return targetMetricAfter > targetMetricBefore, nil
}); err != nil {
framework.Failf("expected %s metric to be updated after accessing endpoints via localhost nodeports", metricName)