Skip to content

Commit

Permalink
Deflake metrics e2e test
Browse files Browse the repository at this point in the history
Signed-off-by: Sascha Grunert <[email protected]>
  • Loading branch information
saschagrunert authored and k8s-ci-robot committed Jul 2, 2021
1 parent cd71f46 commit 169e68f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion test/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,16 @@ func (e *e2e) getSpodMetrics() string {
for i := range b {
b[i] = letters[rand.Intn(len(letters))] // nolint: gosec
}
return e.kubectlRunOperatorNS("pod-"+string(b), "--", "bash", "-c", curlSpodCMD)
// Sometimes the metrics command does not output anything in CI. We fix
// that by retrying the metrics retrieval several times.
for i := 0; i < 5; i++ {
output := e.kubectlRunOperatorNS("pod-"+string(b), "--", "bash", "-c", curlSpodCMD)
if len(strings.Split(output, "\n")) > 1 {
return output
}
}
e.Fail("unable to retrieve SPOD metrics")
return ""
}

func (e *e2e) waitFor(args ...string) {
Expand Down
2 changes: 1 addition & 1 deletion test/tc_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (e *e2e) testCaseSelinuxMetrics(nodes []string) {
e.assertSelinuxPolicyIsRemoved(nodes, rawPolicyName, maxNodeIterations, sleepBetweenIterations)

e.logf("Retrieving spo metrics for validation")
outputSpod := e.kubectlRunOperatorNS("pod", "--", "bash", "-c", curlSpodCMD)
outputSpod := e.getSpodMetrics()
e.Contains(outputSpod, "promhttp_metric_handler_requests_total")

e.logf("Asserting metrics values")
Expand Down

0 comments on commit 169e68f

Please sign in to comment.