Skip to content

Commit

Permalink
add more log
Browse files Browse the repository at this point in the history
  • Loading branch information
RidRisR committed Jan 10, 2025
1 parent d9585a1 commit 4bc8740
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
2 changes: 1 addition & 1 deletion tests/e2e/br/br.go
Original file line number Diff line number Diff line change
Expand Up @@ -1826,7 +1826,7 @@ func createCompactBackupAndWaitForComplete(f *e2eframework.Framework, name, tcNa
return nil, err
}

if err := brutil.WaitForCompactComplete(f.ExtClient, ns, name, backupCompleteTimeout); err != nil {
if err := brutil.WaitForCompactComplete(f, ns, name, backupCompleteTimeout); err != nil {
return compact, err
}
return f.ExtClient.PingcapV1alpha1().CompactBackups(ns).Get(context.TODO(), name, metav1.GetOptions{})
Expand Down
35 changes: 32 additions & 3 deletions tests/e2e/br/framework/br/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import (
"context"
"encoding/binary"
"fmt"
"os"
"path"
"sort"
"time"

"github.com/pingcap/tidb-operator/pkg/apis/label"
Expand Down Expand Up @@ -348,21 +350,48 @@ func WaitBackupPodOnPhase(f *framework.Framework, backup *v1alpha1.Backup, phase
return nil
}

func WaitForCompactComplete(c versioned.Interface, ns, name string, timeout time.Duration) error {
func WaitForCompactComplete(f *framework.Framework, ns, name string, timeout time.Duration) error {
if err := wait.PollImmediate(poll, timeout, func() (bool, error) {
cpbk, err := c.PingcapV1alpha1().CompactBackups(ns).Get(context.TODO(), name, metav1.GetOptions{})
cpbk, err := f.ExtClient.PingcapV1alpha1().CompactBackups(ns).Get(context.TODO(), name, metav1.GetOptions{})
if err != nil {
return false, err
}

getEvents := func() {
events, err := f.ClientSet.CoreV1().Events(ns).List(context.TODO(), metav1.ListOptions{
FieldSelector: fmt.Sprintf("involvedObject.kind=Pod,involvedObject.name=%s", name),
})
if err != nil {
log.Logf("Error listing events: %v", err)
}

if len(events.Items) == 0 {
fmt.Printf("No events found for pod %s in namespace %s\n", name, ns)
os.Exit(0)
}

sort.Slice(events.Items, func(i, j int) bool {
timeI := events.Items[i].LastTimestamp.Time
timeJ := events.Items[j].LastTimestamp.Time
return timeI.After(timeJ)
})

latestEvent := events.Items[0]

log.Logf("Type: %s\n", latestEvent.Type)
log.Logf("Reason: %s\n", latestEvent.Reason)
log.Logf("Message: %s\n", latestEvent.Message)
log.Logf("Count: %d\n", latestEvent.Count)
}

switch cpbk.Status.State {
case string(v1alpha1.BackupComplete):
return true, nil
case string(v1alpha1.BackupFailed):
return false, fmt.Errorf("Compact failed: %s", cpbk.Status.Message)
default:
log.Logf("the current status is: %s %s", cpbk.Status.State, cpbk.Status.Progress)
log.Logf("the current message is: %s", cpbk.Status.Message)
getEvents()
//do nothing
}

Expand Down

0 comments on commit 4bc8740

Please sign in to comment.