Skip to content

Commit

Permalink
Fix deployment issue better output (#7)
Browse files Browse the repository at this point in the history
Signed-off-by: Joe Talerico (rook) <[email protected]>

Signed-off-by: Joe Talerico (rook) <[email protected]>
  • Loading branch information
jtaleric authored Sep 7, 2022
1 parent 15e09a2 commit 76f567a
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 29 deletions.
33 changes: 15 additions & 18 deletions kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,24 @@ import (
// WaitForReady accepts the client and deployment params to determine which pods to watch.
// It will return a bool based on if the pods ever become ready before we move on.
func WaitForReady(c *kubernetes.Clientset, dp DeploymentParams) (bool, error) {
d, err := c.AppsV1().Deployments(dp.namespace).Get(context.TODO(), dp.name, metav1.GetOptions{})
if err != nil {
return false, fmt.Errorf("❌ Failure to capture deployment information")
}
selector, err := metav1.LabelSelectorAsSelector(d.Spec.Selector)
fmt.Println("⏰ Waiting for Pods to become ready...")
w, err := c.CoreV1().Pods(dp.namespace).Watch(context.TODO(), metav1.ListOptions{LabelSelector: selector.String()})
fmt.Println("⏰ Checking for Pods to become ready...")
dw, err := c.AppsV1().Deployments(dp.namespace).Watch(context.TODO(), metav1.ListOptions{})
if err != nil {
panic(err)
return false, err
}
defer w.Stop()
for event := range w.ResultChan() {
p, ok := event.Object.(*apiv1.Pod)
defer dw.Stop()
for event := range dw.ResultChan() {
d, ok := event.Object.(*appsv1.Deployment)
if !ok {
fmt.Println("❌ Issue with the pod event")
fmt.Println("❌ Issue with the Deployment")
}
if p.Status.Phase == "Running" {
return true, nil
if d.Name == dp.name {
if d.Status.ReadyReplicas == 1 {
return true, nil
}
}
}
return false, fmt.Errorf("❌ Deployment had issues launching pods")
return false, fmt.Errorf("❌ Deployment had issues")
}

// GetZone will determine if we have a multiAZ/Zone cloud.
Expand Down Expand Up @@ -66,14 +63,14 @@ func GetZone(c *kubernetes.Clientset) (string, error) {
}

func CreateDeployment(dp DeploymentParams, client *kubernetes.Clientset) (*appsv1.Deployment, error) {
fmt.Printf("🚀 Starting Deployment for %s in %s\n", dp.name, dp.namespace)
d, err := client.AppsV1().Deployments(dp.namespace).Get(context.TODO(), dp.name, metav1.GetOptions{})
if err == nil {
if d.Status.Replicas > 0 {
if d.Status.ReadyReplicas > 0 {
fmt.Println("♻️ Using existing Deployment")
return d, nil
}
}
fmt.Printf("🚀 Starting Deployment for %s in %s\n", dp.name, dp.namespace)
dc := client.AppsV1().Deployments(dp.namespace)
deployment := &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -120,7 +117,7 @@ func GetPods(c *kubernetes.Clientset, dp DeploymentParams) (*apiv1.PodList, erro
if err != nil {
return nil, fmt.Errorf("❌ Failure to capture deployment label")
}
pods, err := c.CoreV1().Pods(dp.namespace).List(context.TODO(), metav1.ListOptions{LabelSelector: selector.String()})
pods, err := c.CoreV1().Pods(dp.namespace).List(context.TODO(), metav1.ListOptions{LabelSelector: selector.String(), FieldSelector: "status.phase=Running"})
if err != nil {
return nil, fmt.Errorf("❌ Failure to capture pods")
}
Expand Down
3 changes: 2 additions & 1 deletion netperf.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,8 @@ func main() {
}
sr.results = append(sr.results, npr)
}
ShowResult(sr)
ShowStreamResult(sr)
ShowRRResult(sr)
}

// Display the netperf config
Expand Down
51 changes: 41 additions & 10 deletions result.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,48 @@ func average(vals []float64) (float64, error) {
return stats.Median(vals)
}

// ShowResults accepts NetPerfResults to display to the user via stdout
func ShowResult(s ScenarioResults) {
fmt.Printf("%s\r\n", strings.Repeat("-", (18+25+75)))
fmt.Printf("%-18s | %-15s | %-15s | %-15s | %-15s | %-15s\r\n", "Scenario", "Message Size", "Same node", "Duration", "Samples", "Avg value")
fmt.Printf("%s\r\n", strings.Repeat("-", (18+25+75)))
for _, r := range s.results {
samples := len(r.Summary)
avg, _ := average(r.Summary)
fmt.Printf("📊 %-15s | %-15d | %-15t | %-15d | %-15d | %-15f (%s) \r\n", r.Profile, r.MessageSize, r.SameNode, r.Duration, samples, avg, r.Metric)
func percentile(vals []float64, ptile float64) (float64, error) {
return stats.Percentile(vals, ptile)
}

func checkResults(s ScenarioResults, check string) bool {
for t := range s.results {
if strings.Contains(s.results[t].Profile, check) {
return true
}
}
return false
}

// ShowStreamResults accepts NetPerfResults to display to the user via stdout
func ShowStreamResult(s ScenarioResults) {
if checkResults(s, "STREAM") {
fmt.Printf("%s Stream Results %s\r\n", strings.Repeat("-", (51)), strings.Repeat("-", (51)))
fmt.Printf("%-18s | %-15s | %-15s | %-15s | %-15s | %-15s\r\n", "Scenario", "Message Size", "Same node", "Duration", "Samples", "Avg value")
fmt.Printf("%s\r\n", strings.Repeat("-", (18+25+75)))
for _, r := range s.results {
if strings.Contains(r.Profile, "STREAM") {
avg, _ := average(r.Summary)
fmt.Printf("📊 %-15s | %-15d | %-15t | %-15d | %-15d | %-15f (%s) \r\n", r.Profile, r.MessageSize, r.SameNode, r.Duration, r.Samples, avg, r.Metric)
}
}
fmt.Printf("%s\r\n", strings.Repeat("-", (18+25+75)))
}
}

func ShowRRResult(s ScenarioResults) {
if checkResults(s, "RR") {
fmt.Printf("%s RR Results %s\r\n", strings.Repeat("-", (53)), strings.Repeat("-", (53)))
fmt.Printf("%-18s | %-15s | %-15s | %-15s | %-15s | %-15s\r\n", "Scenario", "Message Size", "Same node", "Duration", "Samples", "99%tile value")
fmt.Printf("%s\r\n", strings.Repeat("-", (18+25+75)))
for _, r := range s.results {
if strings.Contains(r.Profile, "RR") {
pct, _ := percentile(r.Summary, 99)
fmt.Printf("📊 %-15s | %-15d | %-15t | %-15d | %-15d | %-15f (%s) \r\n", r.Profile, r.MessageSize, r.SameNode, r.Duration, r.Samples, pct, r.Metric)
}
}
fmt.Printf("%s\r\n", strings.Repeat("-", (18+25+75)))
}
fmt.Printf("%s\r\n", strings.Repeat("-", (18+25+75)))
}

// ParseResults accepts the stdout from the execution of the benchmark. It also needs
Expand Down

0 comments on commit 76f567a

Please sign in to comment.