From b86f308b4de6aedc19ae8a14963e84ea95e7bcec Mon Sep 17 00:00:00 2001 From: Ti Chi Robot Date: Fri, 23 Aug 2024 16:01:45 +0800 Subject: [PATCH] br: add some log to record the CR we are processing (#5711) (#5712) Co-authored-by: csuzhangxc --- cmd/backup-manager/app/backup/manager.go | 11 +++++++++++ cmd/backup-manager/app/export/manager.go | 8 ++++++++ cmd/backup-manager/app/import/manager.go | 8 ++++++++ cmd/backup-manager/app/restore/manager.go | 11 +++++++++++ 4 files changed, 38 insertions(+) diff --git a/cmd/backup-manager/app/backup/manager.go b/cmd/backup-manager/app/backup/manager.go index 648727b29c8..ac02c62d041 100644 --- a/cmd/backup-manager/app/backup/manager.go +++ b/cmd/backup-manager/app/backup/manager.go @@ -34,6 +34,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" errorutils "k8s.io/apimachinery/pkg/util/errors" + "k8s.io/apimachinery/pkg/util/json" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/klog/v2" ) @@ -95,6 +96,13 @@ func (bm *Manager) ProcessBackup() error { return errorutils.NewAggregate(errs) } + crData, err := json.Marshal(backup) + if err != nil { + klog.Errorf("failed to marshal backup %v to json, err: %v", backup, err) + } else { + klog.Infof("start to process backup: %s", string(crData)) + } + // we treat snapshot backup as restarted if its status is not scheduled when backup pod just start to run // we will clean backup data before run br command if backup.Spec.Mode == v1alpha1.BackupModeSnapshot && (backup.Status.Phase != v1alpha1.BackupScheduled || v1alpha1.IsBackupRestart(backup)) { @@ -122,6 +130,9 @@ func (bm *Manager) ProcessBackup() error { return bm.performBackup(ctx, backup.DeepCopy(), nil) } + klog.Infof("start to connect to tidb server (%s:%d) as the .spec.from field is specified", + backup.Spec.From.Host, backup.Spec.From.Port) + // validate and create from db var db *sql.DB db, err = bm.validateAndCreateFromDB(ctx, backup.DeepCopy()) diff --git a/cmd/backup-manager/app/export/manager.go b/cmd/backup-manager/app/export/manager.go index 81696972fff..836a4d7d568 100644 --- a/cmd/backup-manager/app/export/manager.go +++ b/cmd/backup-manager/app/export/manager.go @@ -32,6 +32,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" errorutils "k8s.io/apimachinery/pkg/util/errors" + "k8s.io/apimachinery/pkg/util/json" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/klog/v2" ) @@ -99,6 +100,13 @@ func (bm *BackupManager) ProcessBackup() error { return errorutils.NewAggregate(errs) } + crData, err := json.Marshal(backup) + if err != nil { + klog.Errorf("failed to marshal backup %v to json, err: %v", backup, err) + } else { + klog.Infof("start to process backup: %s", string(crData)) + } + reason, err := bm.setOptions(backup) if err != nil { errs = append(errs, err) diff --git a/cmd/backup-manager/app/import/manager.go b/cmd/backup-manager/app/import/manager.go index 19d8e2acdbd..14ec57ac6da 100644 --- a/cmd/backup-manager/app/import/manager.go +++ b/cmd/backup-manager/app/import/manager.go @@ -27,6 +27,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" errorutils "k8s.io/apimachinery/pkg/util/errors" + "k8s.io/apimachinery/pkg/util/json" "k8s.io/klog/v2" ) @@ -87,6 +88,13 @@ func (rm *RestoreManager) ProcessRestore() error { return errorutils.NewAggregate(errs) } + crData, err := json.Marshal(restore) + if err != nil { + klog.Errorf("failed to marshal restore %v to json, err: %s", restore, err) + } else { + klog.Infof("start to process restore: %s", string(crData)) + } + rm.setOptions(restore) return rm.performRestore(ctx, restore.DeepCopy()) diff --git a/cmd/backup-manager/app/restore/manager.go b/cmd/backup-manager/app/restore/manager.go index 40806d2cca3..ceb55ee1dbd 100644 --- a/cmd/backup-manager/app/restore/manager.go +++ b/cmd/backup-manager/app/restore/manager.go @@ -30,6 +30,7 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" errorutils "k8s.io/apimachinery/pkg/util/errors" + "k8s.io/apimachinery/pkg/util/json" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/klog/v2" ) @@ -96,12 +97,22 @@ func (rm *Manager) ProcessRestore() error { return fmt.Errorf("no br config in %s", rm) } + crData, err := json.Marshal(restore) + if err != nil { + klog.Errorf("failed to marshal restore %v to json, err: %s", restore, err) + } else { + klog.Infof("start to process restore: %s", string(crData)) + } + if restore.Spec.To == nil { return rm.performRestore(ctx, restore.DeepCopy(), nil) } rm.setOptions(restore) + klog.Infof("start to connect to tidb server (%s:%d) as the .spec.to field is specified", + restore.Spec.To.Host, restore.Spec.To.Port) + var db *sql.DB var dsn string err = wait.PollImmediate(constants.PollInterval, constants.CheckTimeout, func() (done bool, err error) {