From 0c9f48c1ac0511e78856c819d47ca1c95d274416 Mon Sep 17 00:00:00 2001 From: Hyunsoo Kim Date: Mon, 13 May 2024 14:24:34 -0400 Subject: [PATCH] fix panic when metrics not yet ready in a cluster --- test/metric/container_insights_util.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/metric/container_insights_util.go b/test/metric/container_insights_util.go index 140c839c1..a3ddff03d 100644 --- a/test/metric/container_insights_util.go +++ b/test/metric/container_insights_util.go @@ -58,6 +58,15 @@ func ValidateMetrics(env *environment.MetaData, metricFilter string, expectedDim } results = append(results, validateMetricsAvailability(dims, metrics, actual)) for _, m := range metrics { + // this is to prevent panic with rand.Intn when metrics are not yet ready in a cluster + if _, ok := actual[m]; !ok { + results = append(results, status.TestResult{ + Name: dims, + Status: status.FAILED, + }) + log.Printf("ValidateMetrics failed with missing metric: %s", m) + continue + } // pick a random dimension set to test metric data OR test all dimension sets which might be overkill randIdx := rand.Intn(len(actual[m])) results = append(results, validateMetricValue(m, actual[m][randIdx]))