Skip to content

(WIP) feat: support output the log to file #159

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
Open

Conversation

chlins
Copy link
Contributor

@chlins chlins commented Apr 21, 2025

This pull request introduces several updates to enhance logging, improve error handling, and extend functionality across multiple files. The most notable changes include adding logrus for structured logging, updating the Nydusify method to accept an additional configuration parameter, and improving error reporting in various functions.

Logging Enhancements:

  • Introduced logrus for structured logging in multiple files, including pkg/archiver/archiver.go, pkg/backend/attach.go, and pkg/backend/build.go. Added detailed logging for key operations such as tar/untar processes, file attachments, and model artifact builds. [1] [2] [3]
  • Configured logging initialization in cmd/root.go with customizable log levels and log file paths. [1] [2]

Functional Updates:

  • Updated the Nydusify method in pkg/backend/backend.go to accept a new cfg *config.Root parameter, allowing for more flexible configuration handling. [1] [2] [3] [4]

Error Handling Improvements:

  • Enhanced error reporting with detailed logrus error messages in functions such as Tar, Untar, Attach, and Build, ensuring better traceability of issues. [1] [2] [3]

Code Organization:

  • Reorganized imports in several files to maintain consistency and readability after adding logrus. [1] [2] [3]

Miscellaneous:

  • Added new command-line flags for specifying log levels and log file paths in cmd/root.go.

Summary by CodeRabbit

  • New Features

    • Added support for configurable logging level and log file location via new command-line flags and configuration options.
  • Bug Fixes

    • Corrected a typo in an error message during the prune operation.
  • Refactor

    • Updated method signatures and usage to accept additional configuration parameters.
  • Style

    • Improved import ordering for better code readability.
  • Chores

    • Enhanced logging across the application, improving runtime visibility of key operations and error conditions.
    • Updated test mocks to align with new method signatures.

@chlins chlins added the enhancement New feature or request label Apr 21, 2025
Copy link

coderabbitai bot commented Apr 21, 2025

"""

Walkthrough

This change introduces structured logging using the logrus package across the codebase, adding detailed logs for informational events, errors, and process milestones in backend operations, archiving, and processing workflows. It also adds two new configuration fields, LogLevel and LogFile, to the root configuration, with corresponding persistent command-line flags. The Nydusify method signature is updated to accept a configuration pointer, and all invocations and mocks are adjusted accordingly. Additionally, the logger is initialized at application startup, and logging output suppression in the storage distribution layer is removed.

Changes

Files/Groups Change Summary
cmd/attach.go, cmd/build.go, cmd/push.go Updated calls to the Nydusify method to include the new rootConfig argument.
cmd/root.go Initializes and configures logrus logger in PersistentPreRunE; adds log-level and log-file persistent flags bound to rootConfig; adjusts imports.
pkg/config/root.go Adds LogLevel and LogFile fields to the Root struct; updates NewRoot to set default values.
pkg/backend/backend.go, pkg/backend/nydusify.go, test/mocks/backend/backend.go Updates Nydusify method signature to accept a config pointer; updates mocks and all related method calls.
pkg/backend/attach.go, pkg/backend/build.go, pkg/backend/build/builder.go, pkg/backend/extract.go, pkg/backend/fetch.go, pkg/backend/inspect.go, pkg/backend/list.go, pkg/backend/login.go, pkg/backend/logout.go, pkg/backend/prune.go, pkg/backend/pull.go, pkg/backend/push.go, pkg/backend/rm.go, pkg/backend/tag.go, pkg/backend/processor/base.go, pkg/backend/processor/code.go, pkg/backend/processor/doc.go, pkg/backend/processor/model.go, pkg/backend/processor/model_config.go Adds structured logging using logrus throughout backend and processor methods, logging key events, errors, and process milestones.
pkg/archiver/archiver.go Adds detailed logging to Tar and Untar functions for operation milestones and errors.
pkg/storage/distribution/distribution.go Removes suppression of logging output by deleting logrus output redirection to io.Discard.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant CLI
    participant Logger
    participant Backend
    participant Config

    User->>CLI: Run command (build/push/attach)
    CLI->>Config: Load rootConfig (includes LogLevel, LogFile)
    CLI->>Logger: Initialize logrus with LogLevel/LogFile
    CLI->>Backend: Call Nydusify(ctx, target, rootConfig)
    Backend->>Logger: Log operation start
    Backend->>...: Perform backend operation (build/push/attach)
    Backend->>Logger: Log operation success or error
    Backend-->>CLI: Return result
    CLI-->>User: Output result
Loading

Possibly related PRs

  • CloudNativeAI/modctl#155: Also modifies the Nydusify method, focusing on redirecting command output and adding a new interceptor; both PRs update the same method but with different internal logic and configuration handling.

Poem

A rabbit hopped through fields of logs,
With logrus now, it clears the fogs.
From backend burrows, info flows,
Errors tracked where trouble grows.
With config flags for level and file,
This bunny debugs in logging style!
🐇✨
"""

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (1.64.8)

Error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2
Failed executing command with error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 614ee3d and f9ec826.

📒 Files selected for processing (29)
  • cmd/attach.go (1 hunks)
  • cmd/build.go (2 hunks)
  • cmd/push.go (1 hunks)
  • cmd/root.go (3 hunks)
  • pkg/archiver/archiver.go (9 hunks)
  • pkg/backend/attach.go (7 hunks)
  • pkg/backend/backend.go (1 hunks)
  • pkg/backend/build.go (7 hunks)
  • pkg/backend/build/builder.go (6 hunks)
  • pkg/backend/extract.go (4 hunks)
  • pkg/backend/fetch.go (5 hunks)
  • pkg/backend/inspect.go (3 hunks)
  • pkg/backend/list.go (3 hunks)
  • pkg/backend/login.go (3 hunks)
  • pkg/backend/logout.go (1 hunks)
  • pkg/backend/nydusify.go (3 hunks)
  • pkg/backend/processor/base.go (5 hunks)
  • pkg/backend/processor/code.go (2 hunks)
  • pkg/backend/processor/doc.go (2 hunks)
  • pkg/backend/processor/model.go (2 hunks)
  • pkg/backend/processor/model_config.go (2 hunks)
  • pkg/backend/prune.go (1 hunks)
  • pkg/backend/pull.go (4 hunks)
  • pkg/backend/push.go (4 hunks)
  • pkg/backend/rm.go (2 hunks)
  • pkg/backend/tag.go (2 hunks)
  • pkg/config/root.go (3 hunks)
  • pkg/storage/distribution/distribution.go (0 hunks)
  • test/mocks/backend/backend.go (3 hunks)
💤 Files with no reviewable changes (1)
  • pkg/storage/distribution/distribution.go
✅ Files skipped from review due to trivial changes (2)
  • pkg/backend/list.go
  • pkg/config/root.go
🚧 Files skipped from review as they are similar to previous changes (26)
  • pkg/backend/processor/model.go
  • pkg/backend/processor/doc.go
  • pkg/backend/tag.go
  • cmd/push.go
  • pkg/backend/processor/code.go
  • pkg/backend/logout.go
  • cmd/build.go
  • pkg/backend/inspect.go
  • pkg/backend/pull.go
  • pkg/backend/processor/base.go
  • pkg/backend/login.go
  • pkg/backend/nydusify.go
  • pkg/backend/prune.go
  • pkg/backend/rm.go
  • pkg/archiver/archiver.go
  • pkg/backend/extract.go
  • cmd/root.go
  • pkg/backend/fetch.go
  • pkg/backend/push.go
  • pkg/backend/build.go
  • pkg/backend/backend.go
  • pkg/backend/attach.go
  • cmd/attach.go
  • pkg/backend/build/builder.go
  • pkg/backend/processor/model_config.go
  • test/mocks/backend/backend.go
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (go)

🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 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.

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: 2

🧹 Nitpick comments (7)
pkg/backend/processor/code.go (1)

2-2: Copyright year appears incorrect

The copyright year is listed as 2025, while other files in the same package use 2024. This should be updated for consistency.

-/*
- *     Copyright 2025 The CNAI Authors
+/*
+ *     Copyright 2024 The CNAI Authors
pkg/backend/list.go (1)

82-82: Consider limiting the log verbosity for large artifact lists.

Using %#v for the entire model artifacts list could produce very verbose logs if there are many items. Consider logging just the count or a more concise representation.

-	logrus.Infof("Listed model artifacts successfully, %#v", modelArtifacts)
+	logrus.Infof("Listed model artifacts successfully, count: %d", len(modelArtifacts))
pkg/backend/prune.go (1)

40-40: Minor typo in success log message.

The success message contains a small grammatical error.

-logrus.Info("Pruned completed successfully")
+logrus.Info("Prune completed successfully")
pkg/backend/processor/base.go (2)

74-74: Consider reducing verbosity when logging matched paths.

While logging matched paths is useful, using %#v format will produce very verbose output for large arrays. Consider using a more concise representation or limiting the number of paths shown.

-logrus.Infof("Processing matched paths: %#v", matchedPaths)
+logrus.Infof("Processing %d matched paths", len(matchedPaths))

151-151: Consider reducing verbosity when logging descriptors.

Using %#v to log descriptors will produce very verbose output that may be difficult to read. Consider logging just the count or essential information.

-logrus.Infof("Processing succeed, descriptors: %#v", descriptors)
+logrus.Infof("Processing succeeded, generated %d descriptors", len(descriptors))
pkg/backend/login.go (1)

76-77: Good completion log message.

The success message provides confirmation of the operation completion, though there's a small grammatical issue.

Consider changing "Logined to registry" to "Logged in to registry" for better grammar:

-	logrus.Infof("Logined to registry %s successfully", registry)
+	logrus.Infof("Logged in to registry %s successfully", registry)
pkg/backend/nydusify.go (1)

62-63: Fix typo in success message.

There's a small typo in the success message.

Apply this small correction:

-	logrus.Infof("Nydusifyed the model artifact %s successfully", source)
+	logrus.Infof("Nydusified the model artifact %s successfully", source)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3a2aab2 and 614ee3d.

📒 Files selected for processing (29)
  • cmd/attach.go (1 hunks)
  • cmd/build.go (2 hunks)
  • cmd/push.go (1 hunks)
  • cmd/root.go (3 hunks)
  • pkg/archiver/archiver.go (9 hunks)
  • pkg/backend/attach.go (7 hunks)
  • pkg/backend/backend.go (1 hunks)
  • pkg/backend/build.go (7 hunks)
  • pkg/backend/build/builder.go (6 hunks)
  • pkg/backend/extract.go (4 hunks)
  • pkg/backend/fetch.go (5 hunks)
  • pkg/backend/inspect.go (3 hunks)
  • pkg/backend/list.go (3 hunks)
  • pkg/backend/login.go (3 hunks)
  • pkg/backend/logout.go (1 hunks)
  • pkg/backend/nydusify.go (3 hunks)
  • pkg/backend/processor/base.go (5 hunks)
  • pkg/backend/processor/code.go (2 hunks)
  • pkg/backend/processor/doc.go (2 hunks)
  • pkg/backend/processor/model.go (2 hunks)
  • pkg/backend/processor/model_config.go (2 hunks)
  • pkg/backend/prune.go (1 hunks)
  • pkg/backend/pull.go (4 hunks)
  • pkg/backend/push.go (4 hunks)
  • pkg/backend/rm.go (2 hunks)
  • pkg/backend/tag.go (2 hunks)
  • pkg/config/root.go (2 hunks)
  • pkg/storage/distribution/distribution.go (0 hunks)
  • test/mocks/backend/backend.go (3 hunks)
💤 Files with no reviewable changes (1)
  • pkg/storage/distribution/distribution.go
🧰 Additional context used
🧬 Code Graph Analysis (9)
pkg/backend/tag.go (2)
pkg/backend/referencer.go (1)
  • ParseReference (36-43)
pkg/backend/remote/client.go (1)
  • Repository (31-31)
pkg/backend/login.go (1)
pkg/config/login.go (1)
  • Login (21-27)
pkg/backend/rm.go (1)
pkg/backend/referencer.go (1)
  • ParseReference (36-43)
pkg/backend/backend.go (1)
pkg/config/root.go (1)
  • Root (24-30)
pkg/backend/nydusify.go (1)
pkg/config/root.go (1)
  • Root (24-30)
pkg/backend/extract.go (1)
pkg/backend/referencer.go (1)
  • ParseReference (36-43)
pkg/backend/push.go (3)
pkg/config/push.go (1)
  • Push (26-31)
pkg/backend/referencer.go (1)
  • ParseReference (36-43)
internal/pb/pb.go (1)
  • NormalizePrompt (30-32)
pkg/backend/prune.go (1)
pkg/config/prune.go (1)
  • Prune (19-22)
test/mocks/backend/backend.go (2)
pkg/backend/backend.go (1)
  • Backend (27-69)
pkg/config/root.go (1)
  • Root (24-30)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (go)
🔇 Additional comments (87)
pkg/backend/processor/doc.go (2)

22-24: Import addition for structured logging looks good

Added the logrus library for structured logging, which aligns with the PR objective to enhance logging capabilities across the codebase.


55-55: Good addition of structured logging

Added clear informational logging to indicate when doc file processing begins, providing the working directory for context. This improves observability without altering the control flow.

pkg/backend/processor/model.go (2)

22-24: Import addition for structured logging looks good

Added the logrus library for structured logging, maintaining consistency with other processor implementations.


55-55: Good addition of structured logging

Added clear informational logging to indicate when model file processing begins, providing the working directory for context. This improves observability without altering the control flow.

cmd/push.go (1)

84-84: Updated Nydusify method call correctly

The Nydusify method call has been updated to include rootConfig as a parameter, aligning with the updated method signature in the backend interface. This change supports the PR objective of enhancing configuration flexibility for logging.

pkg/backend/processor/code.go (2)

22-24: Import addition for structured logging looks good

Added the logrus library for structured logging, maintaining consistency with other processor implementations.


55-55: Good addition of structured logging

Added clear informational logging to indicate when code file processing begins, providing the working directory for context. This improves observability without altering the control flow.

pkg/backend/list.go (4)

28-28: Good addition of structured logging with logrus.

The import of the logrus package aligns with the PR objective of introducing structured logging across the codebase.


47-48: LGTM: Appropriate informational logging.

This log entry provides visibility into the start of the listing process.


54-55: Good error logging pattern.

Error is both logged and returned with proper context, enhancing debuggability while maintaining the original error flow.


62-63: Consistent error logging implementation.

The pattern of logging errors before returning them is consistent throughout the file.

Also applies to: 70-71

pkg/config/root.go (1)

28-29: LGTM: Good addition of logging configuration fields.

Adding LogLevel and LogFile fields to the Root struct provides a centralized way to configure logging throughout the application.

pkg/backend/tag.go (3)

25-25: Good addition of structured logging with logrus.

The import of the logrus package aligns with the PR objective of introducing structured logging across the codebase.


30-31: LGTM: Informative log statements for operation start and completion.

These log entries provide clear visibility into the tagging process, including both source and target references.

Also applies to: 74-74


34-35: Consistent error logging pattern throughout the file.

Errors are consistently logged before being returned, providing enhanced debuggability while maintaining the original error flow.

Also applies to: 40-41, 46-47, 52-53, 64-65, 70-71

cmd/attach.go (1)

87-87:

✅ Verification successful

LGTM: Updated Nydusify method call to include rootConfig parameter.

This change correctly passes the logging configuration to the Nydusify operation, aligning with the updated method signature mentioned in the PR objectives.


🏁 Script executed:

#!/bin/bash
# Verify that other similar calls to Nydusify have been updated consistently
rg -A 1 -B 1 "b\.Nydusify" --glob "cmd/*.go"

Length of output: 419


LGTM: All Nydusify calls include the new rootConfig parameter

I’ve verified that the b.Nydusify invocation in cmd/attach.go, cmd/build.go, and cmd/push.go now consistently passes rootConfig, matching the updated method signature. No further changes needed here.

pkg/backend/processor/model_config.go (2)

22-24: Good organization of imports

The imports are now properly grouped with third-party packages separate from internal packages, improving code organization.


55-55: LGTM - Added informative logging

Good addition of structured logging that provides context about the processing operation. This follows the broader pattern of enhanced logging across the codebase.

cmd/build.go (2)

27-29: Good import organization

The imports are properly organized with standard library imports, followed by third-party packages, then internal packages.


89-89: LGTM - Updated method call to match new signature

The Nydusify method call has been properly updated to include the rootConfig parameter, consistent with the interface change in pkg/backend/backend.go. This ensures logging configuration is passed down to the operation.

pkg/backend/inspect.go (4)

27-27: Good addition of logrus for structured logging

Added import for logrus to enable structured logging throughout the method.


68-69: LGTM - Added informative start logging

Good practice to log the beginning of the operation with contextual information about the target.


72-72: Good error logging implementation

Comprehensive error logging has been added at all error points, providing detailed context about what failed while maintaining the original error in the returned error.

Also applies to: 79-80, 85-86, 92-93, 99-100


127-127: LGTM - Added success logging

Good addition of success logging that includes the inspected artifact details for debugging purposes.

pkg/backend/backend.go (1)

68-68: LGTM - Updated interface method signature

The Nydusify method signature has been properly updated to accept a configuration parameter, allowing logging settings to be passed to the operation. This change is consistently implemented across the codebase based on the PR summary.

pkg/backend/logout.go (3)

22-22: Good addition of logrus package for structured logging.

The import of the logrus package enhances observability across the backend package.


28-28: Well-structured informational logging added to track operation progress.

The logrus.Info statements at the beginning and end of the Logout operation provide clear visibility into the operation lifecycle, including the target registry.

Also applies to: 42-42


32-33: Effective error logging added before error returns.

Adding detailed error logs before returning errors improves debuggability while maintaining the original error handling flow.

Also applies to: 38-39

pkg/backend/prune.go (4)

23-23: Good addition of logrus package for structured logging.

The import of the logrus package enhances observability across the backend package.


28-29: Informative start log with parameter values.

Including the dryRun and removeUntagged parameters in the initial log statement provides valuable context for understanding the operation's configuration.


31-32: Detailed error logging added before error returns.

Error logging before returning errors provides better visibility into failure points while maintaining the original error handling.


36-37: Consistent error logging pattern for purge uploads.

This follows the same error logging pattern established earlier, maintaining consistency in error reporting.

pkg/backend/processor/base.go (3)

27-31: Import organization improved with logrus and standard packages.

The imports are now better organized, with system packages first, followed by third-party packages like logrus, and then internal packages.


61-62: Clear process start logging added.

Adding a log statement at the beginning of processing provides better visibility into when processing begins and the target directory.


120-120: Effective error logging with cancellation context.

Adding error logging before cancellation provides better visibility into why processing was stopped.

pkg/backend/push.go (4)

26-30: Improved import organization with logrus.

The imports are now better organized, with system packages first, followed by third-party packages like logrus, and then internal packages.


39-39: Clear operation start logging added.

Adding a log statement at the beginning of the push operation provides better visibility into the target artifact being pushed.


43-44: Comprehensive error logging at all failure points.

Error logs have been added before all error returns, which significantly improves error traceability throughout the push operation. This consistent approach helps identify exactly where failures occur.

Also applies to: 53-54, 59-60, 65-66, 90-91, 96-97, 107-108


111-111: Operation completion log enhances observability.

Adding a success log at the end of the operation completes the logging lifecycle and confirms successful completion to operators.

pkg/backend/login.go (3)

24-24: Good addition of structured logging with logrus.

The addition of logrus for structured logging is a good practice for improving observability in the system.


35-35: Well-placed informational log at function entry point.

This log entry appropriately captures the beginning of the login operation with relevant details (registry and username).


39-41: Good error handling pattern with logging.

The changes implement a consistent pattern for error handling with appropriate logging before returning errors to the caller, which improves observability and debugging capabilities.

Also applies to: 45-47, 71-75

pkg/backend/rm.go (4)

23-23: Consistent use of logrus for structured logging.

Good addition of the logrus import to maintain consistency with the logging approach across the codebase.


29-30: Well-placed informational log at function entry point.

This log entry appropriately captures the beginning of the removal operation with the target artifact name.


33-35: Good error handling pattern with logging.

The error handling follows a consistent pattern with informative logging before returning errors to the caller, which is good for observability.

Also applies to: 49-51


53-54: Good completion log message.

The success message provides clear confirmation of the removal operation completion.

pkg/backend/nydusify.go (4)

23-26: Good organization of imports with logrus.

The imports are well-organized with the addition of logrus for structured logging.


34-36: Updated method signature to accept configuration.

The function signature has been updated to accept a configuration parameter, which is a good pattern for propagating configuration throughout the application.


52-56: Added logging configuration to command execution.

The addition of log-level and log-file parameters to the nydusify command enhances the configurability of logging in the system.


58-60: Good error handling with logging.

The error handling follows the consistent pattern with informative logging before returning errors.

pkg/backend/pull.go (4)

25-28: Well-organized imports with logrus.

The imports are well-organized with the addition of logrus for structured logging, maintaining proper grouping of standard library, third-party, and internal packages.


37-38: Well-placed informational log at function entry point.

This log entry appropriately captures the beginning of the pull operation with the target artifact name.


41-43: Comprehensive error logging across all failure points.

The changes ensure that all potential failure points during the pull operation have appropriate error logging, which significantly improves observability and debugging capabilities.

Also applies to: 48-50, 54-56, 62-64, 98-100, 110-112, 116-118, 125-127


130-132: Good completion log message.

The success message provides clear confirmation of the pull operation completion.

pkg/backend/attach.go (5)

30-30: LGTM: Added import for logrus package

Added the logrus package import to support structured logging throughout this file.


62-63: Good addition of entry log for the Attach operation

This log statement clearly identifies the start of the attach operation with relevant context about the file and source, improving observability.


66-67: Well-implemented error logging

These error logs appropriately capture error details before returning them to the caller, which will help with debugging and observability while maintaining the existing error handling flow.

Also applies to: 72-73, 103-104, 109-110, 119-120, 133-134, 159-160, 176-177


132-134: Good logging for early return case

This log message helpfully explains when an artifact is unchanged after attaching a layer, providing context for the early return.


180-181: Effective completion log message

This log clearly indicates successful completion of the operation with all relevant context information.

pkg/backend/fetch.go (5)

27-27: LGTM: Added import for logrus package

Added the logrus package import to support structured logging throughout this file.


37-37: Good addition of entry log for the Fetch operation

This log statement clearly identifies the start of the fetch operation with relevant context about the target, output path, and patterns, improving observability.


41-42: Well-implemented error logging

These error logs appropriately capture error details before returning them to the caller, which will help with debugging and observability while maintaining the existing error handling flow.

Also applies to: 48-49, 54-55, 62-63, 73-74, 85-86


102-105: Improved error handling for error group

This change enhances the error handling by explicitly checking, logging, and formatting the error from the error group wait operation, which is better than the previous implementation that returned the error without logging.


107-108: Good completion log message

This log clearly indicates successful completion of the fetch operation with relevant context.

pkg/backend/build.go (6)

26-29: LGTM: Import organization and logrus addition

The imports are properly organized, with the logrus package added to support structured logging throughout this file.


49-50: Good addition of entry log for the Build operation

This log statement clearly identifies the start of the build operation with relevant context about the modelfile path and work directory.


86-87: Informative log for nydus interceptor usage

This log provides visibility into when the nydus interceptor is enabled for the build process, which is helpful for understanding build configuration.


54-55: Well-implemented error logging

These error logs appropriately capture error details before returning them to the caller, which will help with debugging and observability while maintaining the existing error handling flow.

Also applies to: 60-61, 71-72, 92-93, 103-104, 137-138, 154-155


142-142: Variable name improvement for readability

Changed the variable name (likely from manifestDesc to desc) to improve code readability, especially when used in log messages.


158-158: Detailed completion log with digest information

This log clearly indicates successful completion of the build operation and includes the manifest digest, which is valuable for traceability.

pkg/archiver/archiver.go (5)

27-27: LGTM: Added import for logrus package

Added the logrus package import to support structured logging throughout this file.


34-34: Good entry logs for Tar and Untar operations

These log statements clearly identify the start of the tar and untar operations with relevant path information, improving observability.

Also applies to: 147-147


44-47: Comprehensive error logging in Tar function

These error logs thoroughly cover all potential error cases in the tar function, including file system operations, header creation, writing, and copying. The logs provide good context and include the specific errors, which will be invaluable for debugging.

Also applies to: 60-62, 66-68, 73-75, 80-82, 86-88, 95-98, 103-106, 111-114, 120-123, 128-131, 134-137


152-154: Thorough error logging in Untar function

These error logs comprehensively cover all potential error cases in the untar function, including directory creation, file extraction, symlink handling, and security checks. The detailed context in each log will help identify the specific point of failure during troubleshooting.

Also applies to: 162-164, 169-171, 178-180, 185-187, 196-198, 202-204, 210-212, 214-216


1-240: Overall well-implemented logging strategy

The addition of structured logging using logrus throughout the Tar and Untar functions follows a consistent pattern and provides excellent visibility into the archiving processes without altering the control flow or error handling logic. This will significantly improve debugging and monitoring capabilities.

pkg/backend/extract.go (4)

30-30: Properly added logrus dependency for structured logging

Good addition of the logrus package for structured logging throughout the file.


43-44: Well-placed start logging for extraction process

Adding an informational log at the beginning of the extraction process provides good visibility into the operation.


48-49: Consistent error logging pattern applied throughout the file

You've applied a consistent pattern of error logging before returning errors, which improves observability while maintaining the existing control flow. The error context is properly preserved.

Also applies to: 56-57, 62-63, 67-68, 85-86, 92-93, 112-113, 117-118


71-72: Added completion logging for successful operations

Good addition of success logging at the end of extraction process to indicate successful completion.

cmd/root.go (2)

27-33: Added logrus import and reorganized imports properly

The logrus package is correctly imported and the imports are well organized.


104-105: Added appropriate CLI flags for log configuration

Good addition of command-line flags for controlling log level and log file path, providing flexibility to users.

pkg/backend/build/builder.go (5)

35-35: Added logrus import for structured logging

Correctly imported the logrus package for structured logging.


122-123: Added informative operation start/end logging

Good addition of informational logs at the beginning and end of major operations, which improves visibility into the build process.

Also applies to: 224-225, 229-230, 249-250, 254-255, 283-284


126-127: Consistent error logging pattern applied throughout the builder

Applied a consistent pattern of error logging before returning errors across all builder methods, which improves observability while maintaining the existing control flow.

Also applies to: 131-132, 137-138, 145-146, 151-152, 158-159, 167-168, 178-179, 184-185, 216-217, 232-233, 238-239, 245-246, 272-273, 279-280


162-163: Added detailed progress logging during build process

Good addition of detailed logs for intermediate steps like hash calculation and reader interception, which provides valuable context for debugging.

Also applies to: 170-171, 196-197


337-338: Added logging to splitReader for better traceability

Good addition of logging in the splitReader function to track data copying operations and potential errors, which improves debugging capability.

Also applies to: 340-343, 344-345

test/mocks/backend/backend.go (1)

451-452: Updated Nydusify mock method to match interface changes

The mock's Nydusify method has been correctly updated to include the new cfg *config.Root parameter, keeping it in sync with the actual interface implementation. All related type assertions and method calls have been properly adjusted.

These changes ensure that tests using this mock will continue to work with the updated method signature in the Backend interface.

Also applies to: 453-454, 461-466, 470-472, 487-490, 492-495, 504-504

Signed-off-by: chlins <chlins.zhang@gmail.com>
@chlins chlins changed the title feat: support output the log to file (WIP) feat: support output the log to file Apr 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant