Skip to content

Commit f1c4787

Browse files
committed
Resolve comments
1 parent d91c009 commit f1c4787

File tree

1 file changed

+33
-20
lines changed

1 file changed

+33
-20
lines changed

test/ginkgo-e2e/utils/kubernetes_api_utils.go

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import (
2121
)
2222

2323
// categorizeErrors categorizes error lines into expected intermittent errors (with counts) and unexpected errors.
24-
// Returns unexpected errors and an error if any pattern exceeds the threshold.
25-
func categorizeErrors(errorLines []string, threshold int) ([]string, error) {
24+
// Returns an error if any pattern exceeds the threshold or if there are unexpected errors.
25+
func categorizeErrors(errorLines []string, threshold int) error {
2626
errorCounts := make(map[string]int)
2727
unexpectedErrors := []string{}
2828

@@ -49,14 +49,38 @@ func categorizeErrors(errorLines []string, threshold int) ([]string, error) {
4949
}
5050

5151
// Check if any expected error pattern exceeded the threshold
52+
var exceededErrors []string
5253
for pattern, count := range errorCounts {
5354
if count > threshold {
54-
return unexpectedErrors, fmt.Errorf("expected intermittent error '%s' exceeded threshold: count=%d (threshold=%d)",
55-
pattern, count, threshold)
55+
exceededErrors = append(exceededErrors, fmt.Sprintf("'%s': %d occurrences (threshold: %d)", pattern, count, threshold))
5656
}
5757
}
5858

59-
return unexpectedErrors, nil
59+
// Build error message if there are exceeded or unexpected errors
60+
if len(exceededErrors) > 0 || len(unexpectedErrors) > 0 {
61+
var errorMsg strings.Builder
62+
63+
if len(exceededErrors) > 0 {
64+
errorMsg.WriteString("Expected errors exceeding threshold:\n")
65+
for _, err := range exceededErrors {
66+
errorMsg.WriteString(" - " + err + "\n")
67+
}
68+
}
69+
70+
if len(unexpectedErrors) > 0 {
71+
if len(exceededErrors) > 0 {
72+
errorMsg.WriteString("\n")
73+
}
74+
errorMsg.WriteString("Unexpected errors:\n")
75+
for _, err := range unexpectedErrors {
76+
errorMsg.WriteString(" - " + err + "\n")
77+
}
78+
}
79+
80+
return fmt.Errorf("%s", strings.TrimSuffix(errorMsg.String(), "\n"))
81+
}
82+
83+
return nil
6084
}
6185

6286
/*
@@ -88,14 +112,9 @@ func CheckContainerLogsForErrors(clientset *kubernetes.Clientset, namespace, lab
88112
}
89113

90114
// Categorize errors and check thresholds
91-
unexpectedErrors, err := categorizeErrors(errorLines, IntermittentErrorThreshold)
115+
err = categorizeErrors(errorLines, IntermittentErrorThreshold)
92116
if err != nil {
93-
return fmt.Errorf("logs for container %s in pod %s: %v", container.Name, pod.Name, err)
94-
}
95-
96-
// If there are any unexpected errors, fail immediately
97-
if len(unexpectedErrors) > 0 {
98-
return fmt.Errorf("logs for container %s in pod %s contain errors:\n %s", container.Name, pod.Name, strings.Join(unexpectedErrors, "\n"))
117+
return fmt.Errorf("logs for container %s in pod %s:\n%v", container.Name, pod.Name, err)
99118
}
100119
}
101120
}
@@ -552,15 +571,9 @@ func CheckFileForErrors(clientset *kubernetes.Clientset, Cfg *rest.Config, names
552571
if stdout != "" {
553572
// Parse the stdout and categorize errors
554573
lines := strings.Split(stdout, "\n")
555-
unexpectedErrors, err := categorizeErrors(lines, IntermittentErrorThreshold)
574+
err = categorizeErrors(lines, IntermittentErrorThreshold)
556575
if err != nil {
557-
return fmt.Errorf("in file %s in pod %s, container %s: %v", filePath, pod.Name, containerName, err)
558-
}
559-
560-
// If there are any unexpected errors, fail immediately
561-
if len(unexpectedErrors) > 0 {
562-
return fmt.Errorf("unexpected errors found in file %s in pod %s, container %s: %s",
563-
filePath, pod.Name, containerName, strings.Join(unexpectedErrors, "\n"))
576+
return fmt.Errorf("in file %s in pod %s, container %s:\n%v", filePath, pod.Name, containerName, err)
564577
}
565578
}
566579
}

0 commit comments

Comments
 (0)