Skip to content

Commit

Permalink
fix panic when metrics not yet ready in a cluster (#408)
Browse files Browse the repository at this point in the history
  • Loading branch information
movence authored May 21, 2024
1 parent 3293ed2 commit 4045108
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions test/metric/container_insights_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down

0 comments on commit 4045108

Please sign in to comment.