mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-26 21:17:23 +00:00
Merge pull request #125478 from aroradaman/handle-index-error
e2e/framework/metrics: handle index out of bounds panic
This commit is contained in:
commit
debd99542f
@ -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 {
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user