-
Notifications
You must be signed in to change notification settings - Fork 274
benchmarks: avoid unreliable kubectl attach when fetching metrics #5296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -234,14 +234,41 @@ func Metrics(experiment *gm.Experiment, suffix string) { | |
| } | ||
|
|
||
| func getMetrics(res map[string]float64, url string, controllers ...string) { | ||
| pod := addRandomSuffix("curl") | ||
| var ( | ||
| mfs map[string]*dto.MetricFamily | ||
| parser = expfmt.NewTextParser(model.LegacyValidation) | ||
| ) | ||
| Eventually(func() error { | ||
| pod := addRandomSuffix("curl") | ||
| GinkgoWriter.Print("Fetching metrics from " + url + "\n") | ||
| out, err := k.Run("run", "--rm", "--attach", "--quiet", "--restart=Never", pod, "--image=curlimages/curl", "--namespace", "cattle-fleet-system", "--command", "--", "curl", "-s", url) | ||
|
|
||
| // Create the pod without --attach to avoid kubectl's unreliable | ||
| // attach mechanism, which can duplicate output on fallback to logs. | ||
| _, _, err := k.RunStdout("run", "--restart=Never", pod, "--image=curlimages/curl", "--namespace", "cattle-fleet-system", "--command", "--", "curl", "-sf", url) | ||
| if err != nil { | ||
| // Pod may have been created despite the error; clean up. | ||
| _, _ = k.Run("delete", "pod", "--namespace", "cattle-fleet-system", pod, "--ignore-not-found") | ||
| return fmt.Errorf("kubectl run: %w", err) | ||
| } | ||
|
|
||
| // Wait for the pod to terminate. Use condition=Ready=false to | ||
| // detect both Succeeded and Failed without blocking for the full | ||
| // timeout on a failed curl. | ||
| _, _, err = k.RunStdout("wait", "--for=condition=Ready=false", "--namespace", "cattle-fleet-system", "pod/"+pod, "--timeout=30s") | ||
| if err != nil { | ||
| _, _ = k.Run("delete", "pod", "--namespace", "cattle-fleet-system", pod, "--ignore-not-found") | ||
| return fmt.Errorf("waiting for pod: %w", err) | ||
| } | ||
|
|
||
| phase, _, _ := k.RunStdout("get", "pod", pod, "--namespace", "cattle-fleet-system", "-o", "jsonpath={.status.phase}") | ||
| if strings.TrimSpace(phase) != "Succeeded" { | ||
| _, _ = k.Run("delete", "pod", "--namespace", "cattle-fleet-system", pod, "--ignore-not-found") | ||
| return fmt.Errorf("curl pod %s finished with phase %s", pod, phase) | ||
| } | ||
|
|
||
| out, _, err := k.RunStdout("logs", "--namespace", "cattle-fleet-system", pod) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: in case we run into more troubles getting these logs, we could replace creating a new pod with a port forward for fetching metrics, as done in the dump CLI.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hope it won't be necessary, but yeah, we may have to do that. |
||
| // Always clean up the pod. | ||
| _, _ = k.Run("delete", "pod", "--namespace", "cattle-fleet-system", pod, "--ignore-not-found") | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.