Skip to content

Refactor backup and restore plugins to accept logger as a parameter and remove verbosity level configuration #58

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kaovilai
Copy link
Member

@kaovilai kaovilai commented May 20, 2025

Signed-off-by: Tiger Kaovilai [email protected]

What this PR does / why we need it

So all log operations are routed to velero server and to not cause issues with go-plugin.

// newLogger returns a logger that is suitable for use within an
// Velero plugin.
func newLogger() *logrus.Logger {
logger := logrus.New()
/*
!!!DO NOT SET THE OUTPUT TO STDOUT!!!
go-plugin uses stdout for a communications protocol between client and server.
stderr is used for log messages from server to client. The velero server makes sure they are logged to stdout.
*/

Which issue(s) this PR fixes

Fixes #

Checklist

  • Subject and description added to both, commit and PR.
  • Relevant issues have been referenced.
  • This change includes docs.
  • This change includes unit tests.

Summary by CodeRabbit

  • Refactor

    • Updated internal logging approach for backup and restore plugins to use a provided logger instance.
    • Removed configuration option for backup plugin verbosity level.
    • Adjusted backup plugin validator to support the new logger type.
  • Chores

    • Simplified plugin initialization and logging configuration for improved maintainability.

Copy link

coderabbitai bot commented May 20, 2025

Walkthrough

The changes refactor the backup and restore plugin initialization to accept a logger instance as a parameter, removing internal logger creation and configuration. The PluginVerbosityLevel option is eliminated from backup plugin options and related validation logic. Structs and constructors are updated to use the logrus.FieldLogger interface for logging.

Changes

File(s) Change Summary
main.go Modified plugin initialization to pass a logger instance to backup and restore plugin constructors.
pkg/core/backup.go, pkg/core/restore.go Changed NewBackupPlugin and NewRestorePlugin to accept a logrus.FieldLogger parameter instead of creating internal loggers; removed verbosity level logic.
pkg/core/types/types.go Removed PluginVerbosityLevel field from the BackupOptions struct.
pkg/core/validation/backup.go Changed Log field in BackupPluginValidator to logrus.FieldLogger and removed setting of PluginVerbosityLevel in backup options.

Sequence Diagram(s)

sequenceDiagram
    participant Main
    participant Logger
    participant BackupPlugin
    participant RestorePlugin

    Main->>Logger: Obtain logger instance
    Main->>BackupPlugin: NewBackupPlugin(logger)
    Main->>RestorePlugin: NewRestorePlugin(logger)
    BackupPlugin->>BackupPlugin: Use provided logger
    RestorePlugin->>RestorePlugin: Use provided logger
Loading

Poem

In the warren, logs now flow with grace,
Passed from above, no more a chase.
Backup and restore, with logger in hand,
Simpler, cleaner—just as planned.
Verbosity gone, less clutter to see,
A rabbit’s delight in code harmony!
🐇✨

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@openshift-ci openshift-ci bot requested review from devguyio and enxebre May 20, 2025 17:35
Copy link

openshift-ci bot commented May 20, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: kaovilai

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 20, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🔭 Outside diff range comments (1)
pkg/core/validation/backup.go (1)

57-59: 🛠️ Refactor suggestion

Remove unused pluginVerbosityLevel handling.

The code still recognizes and logs the pluginVerbosityLevel configuration key, but no longer uses it since verbosity level configuration has been removed from the plugin options. This code should be removed for clarity.

-		case "pluginVerbosityLevel":
-			p.Log.Debugf("reading/parsing pluginVerbosityLevel %s", value)
🧹 Nitpick comments (2)
pkg/core/restore.go (1)

76-84: Consider consistent field naming.

The Log field in the validator is inconsistent with the plugin's own log field. Consider standardizing the naming convention throughout the codebase for better readability.

		validator: &validation.RestorePluginValidator{
-			Log: log,
+			Log: log, // Consider renaming to lowercase 'log' for consistency
		},
pkg/core/backup.go (1)

79-79: Consider consistent field naming.

Similar to the restore plugin, the Log field in the validator is inconsistent with the plugin's own log field. Consider standardizing the naming convention throughout the codebase.

		validator: &validation.BackupPluginValidator{Log: log}, // Consider renaming to lowercase 'log' for consistency
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between f37e2c8 and d6bbd7d.

📒 Files selected for processing (5)
  • main.go (1 hunks)
  • pkg/core/backup.go (1 hunks)
  • pkg/core/restore.go (1 hunks)
  • pkg/core/types/types.go (0 hunks)
  • pkg/core/validation/backup.go (1 hunks)
💤 Files with no reviewable changes (1)
  • pkg/core/types/types.go
🧰 Additional context used
🧬 Code Graph Analysis (1)
main.go (2)
pkg/core/backup.go (1)
  • NewBackupPlugin (47-89)
pkg/core/restore.go (1)
  • NewRestorePlugin (48-94)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Red Hat Konflux / hypershift-oadp-plugin-main-on-pull-request
🔇 Additional comments (6)
main.go (2)

18-18: Correct implementation of logger passing to the backup plugin.

The code now properly passes the logger instance to the NewBackupPlugin function, aligning with the refactoring goal to have plugins accept a logger as a parameter rather than creating their own internally.


23-23: Correct implementation of logger passing to the restore plugin.

The code now properly passes the logger instance to the NewRestorePlugin function, which is consistent with the backup plugin implementation and the overall refactoring goal.

pkg/core/validation/backup.go (1)

19-19: Good interface usage for dependency inversion.

Changing from a concrete logger type to the logrus.FieldLogger interface improves flexibility and testability by allowing any compatible logger implementation to be injected.

pkg/core/restore.go (1)

48-48: Correct implementation of logger injection.

The function signature now properly accepts a logrus.FieldLogger parameter, enabling logger injection rather than internal creation. This is consistent with the PR objectives.

pkg/core/backup.go (2)

47-47: Correct implementation of logger injection.

The function signature now properly accepts a logrus.FieldLogger parameter, enabling logger injection rather than internal creation. This change is consistent with the PR objectives and the changes in restore.go.


73-80:

✅ Verification successful

Verify all plugin options are still properly managed.

With the removal of verbosity level handling, ensure that all other plugin options (like DataUploadTimeout, DataUploadCheckPace) are still properly initialized and used throughout the code.


🏁 Script executed:

#!/bin/bash
# Description: Verify all plugin options initialization and usage

# Check which options are initialized in ValidatePluginConfig
rg -A 3 "bo\.\w+ =" pkg/core/validation/backup.go

# Check which options are used in backup.go
rg "p\.(DataUploadTimeout|DataUploadCheckPace)" pkg/core/backup.go

Length of output: 1167


Plugin options are properly managed
DataUploadTimeout and DataUploadCheckPace are both initialized in pkg/core/validation/backup.go and consumed in pkg/core/backup.go (passed to common.WaitForDataUpload and common.WaitForPodVolumeBackup). No further action required.

@weshayutin
Copy link
Contributor

weshayutin commented May 20, 2025

I found line: https://github.com/openshift/hypershift-oadp-plugin/blob/f37e2c8fd8b825949a2901d360f74378dbe2ff23/main.go#L22C14-L22C46

in https://termbin.com/ha0q

p.log.Debug("Entering Hypershift backup plugin")
Is NOT Found in backup logs

https://termbin.com/lswl
also not found in pod logs https://termbin.com/uwje

This is suspect:
velero-7b6587d898-r4wh8 velero time="2025-05-20T18:01:53Z" level=info msg="configuration for hypershift OADP plugin not found" backup=openshift-adp/test-backup-wes-log-2 cmd=/plugins/hypershift-oadp-plugin logSource="/go/src/github.com/openshift/hypershift-oadp-plugin/pkg/core/backup.go:70" pluginName=hypershift-oadp-plugin

@weshayutin
Copy link
Contributor

@jparrill can you please poke at this pr seeing some issues here.

@kaovilai
Copy link
Member Author

I found line: https://github.com/openshift/hypershift-oadp-plugin/blob/f37e2c8fd8b825949a2901d360f74378dbe2ff23/main.go#L22C14-L22C46

in https://termbin.com/ha0q

p.log.Debug("Entering Hypershift backup plugin")

Is NOT Found in backup logs
https://termbin.com/lswl also not found in pod logs https://termbin.com/uwje

This is suspect: velero-7b6587d898-r4wh8 velero time="2025-05-20T18:01:53Z" level=info msg="configuration for hypershift OADP plugin not found" backup=openshift-adp/test-backup-wes-log-2 cmd=/plugins/hypershift-oadp-plugin logSource="/go/src/github.com/openshift/hypershift-oadp-plugin/pkg/core/backup.go:70" pluginName=hypershift-oadp-plugin

It's right here boss.

@kaovilai
Copy link
Member Author

For extra clarity

time="2025-05-20T18:01:53Z" level=info msg="Initializing HCP Backup Plugin" backup=openshift-adp/test-backup-wes-log-2 cmd=/plugins/hypershift-oadp-plugin logSource="/go/src/github.com/openshift/hypershift-oadp-plugin/main.go:17" pluginName=hypershift-oadp-plugin

…nd remove verbosity level configuration

Signed-off-by: Tiger Kaovilai <[email protected]>
@kaovilai kaovilai force-pushed the use-velero-plugin-log branch from d6bbd7d to 2b3f460 Compare May 21, 2025 18:18
Copy link

openshift-ci bot commented May 21, 2025

@kaovilai: all tests passed!

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@weshayutin
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants