Skip to content
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

Pb-4844: Made changes in kdmp for it to enable debug level log messages #324

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkg/drivers/kopiabackup/kopiabackup.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,9 @@ func jobFor(
"/data",
}, " ")

// Read the config map from the job option and then add the debug level log if required
cmd = utils.CheckAndAddKopiaDebugModeEnabled(cmd, jobOption)

if jobOption.Compression != "" {
splitCmd := strings.Split(cmd, " ")
splitCmd = append(splitCmd, "--compression", jobOption.Compression)
Expand Down
2 changes: 2 additions & 0 deletions pkg/drivers/kopiadelete/kopiadelete.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ func jobFor(
jobOption.VolumeBackupDeleteNamespace,
}, " ")

cmd = utils.CheckAndAddKopiaDebugModeEnabled(cmd, jobOption)

kopiaExecutorImage, imageRegistrySecret, err := utils.GetExecutorImageAndSecret(drivers.KopiaExecutorImage,
jobOption.KopiaImageExecutorSource,
jobOption.KopiaImageExecutorSourceNs,
Expand Down
2 changes: 2 additions & 0 deletions pkg/drivers/kopiamaintenance/kopiamaintenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ func jobFor(
jobOption.MaintenanceType,
}, " ")

cmd = utils.CheckAndAddKopiaDebugModeEnabled(cmd, jobOption)

kopiaExecutorImage, imageRegistrySecret, err := utils.GetExecutorImageAndSecret(drivers.KopiaExecutorImage,
jobOption.KopiaImageExecutorSource,
jobOption.KopiaImageExecutorSourceNs,
Expand Down
4 changes: 3 additions & 1 deletion pkg/drivers/kopiarestore/kopiarestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ func jobFor(
vb.Status.SnapshotID,
}, " ")

cmd = utils.CheckAndAddKopiaDebugModeEnabled(cmd, jobOption)

kopiaExecutorImage, imageRegistrySecret, err := utils.GetExecutorImageAndSecret(drivers.KopiaExecutorImage,
jobOption.KopiaImageExecutorSource,
jobOption.KopiaImageExecutorSourceNs,
Expand Down Expand Up @@ -369,7 +371,7 @@ func roleFor() *rbacv1.Role {
},
{
APIGroups: []string{"kdmp.portworx.com"},
Resources: []string{"volumebackups"},
Resources: []string{"volumebackups", "dataexports"},
Verbs: []string{rbacv1.VerbAll},
},
},
Expand Down
1 change: 1 addition & 0 deletions pkg/drivers/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type JobOpts struct {
VolumeBackupName string
VolumeBackupNamespace string
VolumeBackupDeleteName string
KopiaDebugMode bool
VolumeBackupDeleteNamespace string
DataExportName string
SnapshotID string
Expand Down
15 changes: 15 additions & 0 deletions pkg/drivers/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ const (
PvcBoundSuccessMsg = "pvc bounded successfully"
// PvcBoundFailedMsg pvc not bounded msg
PvcBoundFailedMsg = "pvc not bounded"
// KopiaDebugModeEnabled - debug level log messages are enabled for kopia
KopiaDebugModeEnabled = "kopia-debug-mode"
// KopiaExecutorDebugModeCMKey - key present in the config maps, which enables debug log level in kopia
KopiaExecutorDebugModeCMKey = "KDMP_KOPIAEXECUTOR_ENABLE_DEBUG_MODE"
)

var (
Expand Down Expand Up @@ -876,3 +880,14 @@ func IsJobPodMountFailed(job *batchv1.Job, namespace string) bool {
}
return false
}

func CheckAndAddKopiaDebugModeEnabled(cmd string, jobOption drivers.JobOpts) string {
// check for the particular key-value pair
isKeyPresent := GetConfigValue(jobOption.JobConfigMap, jobOption.JobConfigMapNs, KopiaExecutorDebugModeCMKey)
if isKeyPresent == "true" {
splitCmd := strings.Split(cmd, " ")
splitCmd = append(splitCmd, "--log-level", "debug")
cmd = strings.Join(splitCmd, " ")
}
return cmd
}
2 changes: 2 additions & 0 deletions pkg/executor/kopia/kopia.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var (
credentials string
backupLocationName string
backupLocationNamespace string
logLevelDebug string
)

// NewCommand returns a kopia command wrapper
Expand All @@ -29,6 +30,7 @@ func NewCommand() *cobra.Command {
cmds.PersistentFlags().StringVar(&backupLocationName, "backup-location", "", "Name of the BackupLocation object, used for authentication")
cmds.PersistentFlags().StringVar(&backupLocationNamespace, "backup-location-namespace", "", "Namespace of BackupLocation object, used for authentication")
cmds.PersistentFlags().StringVar(&volumeBackupName, "volume-backup-name", "", "Provided VolumeBackup CRD will be updated with the latest backup progress details")
cmds.PersistentFlags().StringVar(&logLevelDebug, "log-level", "", "If debug mode in kopia is to be used")

cmds.AddCommand(
newBackupCommand(),
Expand Down
22 changes: 21 additions & 1 deletion pkg/executor/kopia/kopiabackup.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ func newBackupCommand() *cobra.Command {
backupCommand.Flags().StringVar(&sourcePathGlob, "source-path-glob", "", "The regexp should match only one path that will be used for backup")
backupCommand.Flags().StringVar(&compression, "compression", "", "Compression type to be used")
backupCommand.Flags().StringVar(&excludeFileList, "exclude-file-list", "", " list of dir names that need to be exclude in the kopia snapshot")

return backupCommand
}

Expand Down Expand Up @@ -249,6 +248,9 @@ func runKopiaCreateRepo(repository *executor.Repository) error {
if err != nil {
return err
}
// Now check if debug log level is to be added in the command which got prepared above.
// check if debug level exists
repoCreateCmd = addLogLevelDebugToCommand(repoCreateCmd, logLevelDebug)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we should move this adding to args in command.go file as this is commong to all flow path. We can set to enable debug mode in type Command struct and use that to fill details in all places.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@prashanthpx Initially it was being set like that only, but after talking to @vsundarraj-px he had suggested to follow the current flow instead.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine for now but flow is for few things which are very specific to command we add it and common things goes to Command struct.

// NFS doesn't need any special treatment for repo create command
// hence no case exist for it.
switch repository.Type {
Expand Down Expand Up @@ -323,6 +325,8 @@ func runKopiaBackup(repository *executor.Repository, sourcePath string) error {
if err != nil {
return err
}
// Check and add debug level logs for kopia backup command
backupCmd = addLogLevelDebugToCommand(backupCmd, logLevelDebug)
// This is needed to handle case where after kopia repo create was successful and
// the pod got terminated. Now user triggers another backup, so we need to pass
// credentials for "snapshot create".
Expand Down Expand Up @@ -386,6 +390,8 @@ func runKopiaRepositoryConnect(repository *executor.Repository) error {
if err != nil {
return err
}
// Check and add debug level logs for kopia connect command
connectCmd = addLogLevelDebugToCommand(connectCmd, logLevelDebug)

switch repository.Type {
case storkv1.BackupLocationS3:
Expand Down Expand Up @@ -430,6 +436,7 @@ func setGlobalPolicy() error {
if err != nil {
return err
}
policyCmd = addLogLevelDebugToCommand(policyCmd, logLevelDebug)
// As we don't want kopia maintenance to kick in and trigger global policy on default values
// for the repository, setting them to very high values
policyCmd = addPolicySetting(policyCmd)
Expand Down Expand Up @@ -483,6 +490,8 @@ func runKopiaExcludeFileList(repository *executor.Repository, sourcePath string)
if err != nil {
return err
}
// Check and add debug level logs for kopia exclude file list command
excludeFileListCmd = addLogLevelDebugToCommand(excludeFileListCmd, logLevelDebug)
excludeFileListExecutor := kopia.NewExcludeFileListExecutor(excludeFileListCmd)
if err := excludeFileListExecutor.Run(); err != nil {
err = fmt.Errorf("failed to run exclude file list command: %v", err)
Expand Down Expand Up @@ -529,6 +538,8 @@ func runKopiaCompression(repository *executor.Repository, sourcePath string) err
if err != nil {
return err
}
// Check and add debug level logs for kopia compression command
compressionCmd = addLogLevelDebugToCommand(compressionCmd, logLevelDebug)
compressionExecutor := kopia.NewCompressionExecutor(compressionCmd)
if err := compressionExecutor.Run(); err != nil {
err = fmt.Errorf("failed to run compression command: %v", err)
Expand Down Expand Up @@ -677,3 +688,12 @@ func addPolicySetting(policyCmd *kopia.Command) *kopia.Command {

return policyCmd
}

func addLogLevelDebugToCommand(kopiaCommand *kopia.Command, logLevelDebug string) *kopia.Command {
if logLevelDebug != "" {
// Kopia command to be run with debug log levels now.
kopiaCommand.AddArg("--log-level")
kopiaCommand.AddArg("debug")
}
return kopiaCommand
}
6 changes: 4 additions & 2 deletions pkg/executor/kopia/kopiadelete.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ func runKopiaDelete(repository *executor.Repository, snapshotID string) error {
logrus.Errorf("%s %v", fn, errMsg)
return fmt.Errorf(errMsg)
}
// Check and add debug level logs for kopia delete command
deleteCmd = addLogLevelDebugToCommand(deleteCmd, logLevelDebug)
initExecutor := kopia.NewDeleteExecutor(deleteCmd)
if err := initExecutor.Run(); err != nil {
errMsg := fmt.Sprintf("running delete backup snapshot command for snapshotID [%v] failed: %v", snapshotID, err)
Expand Down Expand Up @@ -163,11 +165,11 @@ func runKopiaSnapshotList(repository *executor.Repository) ([]string, error) {
var listCmd *kopia.Command
logrus.Infof("Executing kopia snapshot list command")
listCmd, err = kopia.GetListCommand()

if err != nil {
return nil, err
}

// Check and add bebug level logs for kopia snapshot list command
listCmd = addLogLevelDebugToCommand(listCmd, logLevelDebug)
listExecutor := kopia.NewListExecutor(listCmd)
if err := listExecutor.Run(); err != nil {
err = fmt.Errorf("failed to run snapshot list command: %v", err)
Expand Down
7 changes: 6 additions & 1 deletion pkg/executor/kopia/maintenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ func runKopiaQuickMaintenanceExecute(repository *executor.Repository) error {
logrus.Errorf("%s %v", fn, errMsg)
return fmt.Errorf(errMsg)
}

// Check and add debug log level for kopia maintenance command
maintenanceRunCmd = addLogLevelDebugToCommand(maintenanceRunCmd, logLevelDebug)
initExecutor := kopia.NewMaintenanceRunExecutor(maintenanceRunCmd)
if err := initExecutor.Run(); err != nil {
errMsg := fmt.Sprintf("running maintenance run command for [%v] failed: %v", repository.Name, err)
Expand Down Expand Up @@ -312,6 +313,8 @@ func runKopiaMaintenanceExecute(repository *executor.Repository) error {
logrus.Errorf("%s %v", fn, errMsg)
return fmt.Errorf(errMsg)
}
// Check and add debug log level for kopia maintenance command
maintenanceRunCmd = addLogLevelDebugToCommand(maintenanceRunCmd, logLevelDebug)
initExecutor := kopia.NewMaintenanceRunExecutor(maintenanceRunCmd)
if err := initExecutor.Run(); err != nil {
errMsg := fmt.Sprintf("running maintenance run command for [%v] failed: %v", repository.Name, err)
Expand Down Expand Up @@ -343,6 +346,8 @@ func runKopiaMaintenanceSet(repository *executor.Repository) error {
logrus.Errorf("%s %v", fn, errMsg)
return fmt.Errorf(errMsg)
}
// Check and add debug log level for kopia maintenance set command
maintenanceSetCmd = addLogLevelDebugToCommand(maintenanceSetCmd, logLevelDebug)
initExecutor := kopia.NewMaintenanceSetExecutor(maintenanceSetCmd)
if err := initExecutor.Run(); err != nil {
errMsg := fmt.Sprintf("running maintenance set command for failed: %v", err)
Expand Down
4 changes: 2 additions & 2 deletions pkg/executor/kopia/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func newRestoreCommand() *cobra.Command {
restoreCommand.Flags().StringVar(&targetPath, "target-path", "", "Destination path for kopia restore")
restoreCommand.Flags().StringVar(&snapshotID, "snapshot-id", "", "Snapshot id of the restore")
restoreCommand.Flags().StringVar(&appRestoreCR, "app-restore-cr", "", "ApplicationRestore CR name")

return restoreCommand
}

Expand Down Expand Up @@ -107,7 +106,8 @@ func runKopiaRestore(repository *executor.Repository, targetPath, snapshotID str
if err != nil {
return err
}

// Check and add debug level logs for kopia restore command
restoreCmd = addLogLevelDebugToCommand(restoreCmd, logLevelDebug)
initExecutor := kopia.NewRestoreExecutor(restoreCmd)
if err := initExecutor.Run(); err != nil {
err = fmt.Errorf("failed to run restore command: %v", err)
Expand Down
Loading