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

chore: refactor to use logger obj instead #445

Merged
merged 5 commits into from
Jun 27, 2024

Conversation

mojtaba-esk
Copy link
Member

@mojtaba-esk mojtaba-esk commented Jun 19, 2024

Closes #396

Summary by CodeRabbit

  • Refactor

    • Updated logging mechanism across various packages to use custom loggers instead of logrus.
    • Improved logging control and flexibility by integrating instance-specific loggers.
  • Chores

    • Removed imports and references to logrus in favor of custom logger instances in multiple files.
    • Added comments in pkg/knuu/knuu.go suggesting potential future changes for configuration functions.

@mojtaba-esk mojtaba-esk requested a review from a team June 19, 2024 15:35
@mojtaba-esk mojtaba-esk self-assigned this Jun 19, 2024
@celestia-bot celestia-bot requested review from tty47, smuu and sysrex June 19, 2024 15:36
@mojtaba-esk mojtaba-esk enabled auto-merge June 19, 2024 15:36
Copy link
Contributor

coderabbitai bot commented Jun 19, 2024

Warning

Review failed

The pull request is closed.

Walkthrough

The update involves a comprehensive refactoring across the codebase to enhance logging capabilities by replacing the global logrus logger with custom logger instances passed through structs. This change improves modularity, composability, and control over logging across multiple packages, particularly focusing on Kubernetes-related functionalities.

Changes

Files/Group Change Summary
pkg/builder/kaniko/kaniko_test.go Updated NewClientCustom call to include a new logger parameter.
pkg/instance/destroy.go, helper.go, instance.go, pool.go Changed logrus logging statements to use i.Logger for the Instance struct.
pkg/k8s/k8s.go Added a logger field to the Client struct and updated NewClient functions to accept a logger.
pkg/k8s/k8s_custom_resource.go Replaced logrus with c.logger for logging in CreateCustomResource function.
pkg/k8s/k8s_daemonset.go Replaced logrus with c.logger for logging in CreateDaemonSet, UpdateDaemonSet, and DeleteDaemonSet functions.
pkg/k8s/k8s_networkpolicy.go Replaced logrus with c.logger for logging in NetworkPolicyExists function.
pkg/k8s/k8s_pod.go Removed logrus import and updated Client struct methods to use c.logger for logging.
pkg/k8s/k8s_pvc.go Replaced logrus with c.logger for logging in CreatePersistentVolumeClaim and DeletePersistentVolumeClaim functions.
pkg/k8s/k8s_replicaset.go Converted prepareReplicaSet to a method of the Client struct and updated logging to use c.logger.
pkg/k8s/k8s_service.go Replaced logrus with c.logger for logging service-related events.
pkg/k8s/test_suite_test.go Added logrus.New() call in the SetupTest() function within the TestSuite struct.
pkg/knuu/knuu.go Updated logging statements to use logger from Knuu struct and updated setDefaults function.

Sequence Diagram(s)

Not applicable for these changes as the modifications are primarily about logging refactoring without significant control flow changes.

Assessment against linked issues

Objective (from #396) Addressed Explanation
Refactor packages to receive a logger object instead of using default logrus

Poem

In code where logs once prosperous grew,
A rabbit hopped and knew what to do.
With custom loggers bright,
It set the codes alight,
Bringing clarity to each debugging view.

🚀✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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
Contributor

@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: 3

Outside diff range and nitpick comments (3)
pkg/k8s/k8s_pod.go (3)

100-100: Switch to structured logging for consistency and enhanced readability.


281-281: Ensure the log message clearly indicates that port forwarding has started. This is crucial for understanding the state of the system at this point in the log file.


282-282: Consider adding error information to the logging for port forwarding to enhance troubleshooting capabilities.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a00e9d5 and b7cee0f.

Files selected for processing (16)
  • pkg/builder/kaniko/kaniko_test.go (2 hunks)
  • pkg/instance/destroy.go (2 hunks)
  • pkg/instance/helper.go (10 hunks)
  • pkg/instance/instance.go (34 hunks)
  • pkg/instance/pool.go (2 hunks)
  • pkg/k8s/k8s.go (3 hunks)
  • pkg/k8s/k8s_custom_resource.go (2 hunks)
  • pkg/k8s/k8s_daemonset.go (3 hunks)
  • pkg/k8s/k8s_namespace.go (3 hunks)
  • pkg/k8s/k8s_networkpolicy.go (2 hunks)
  • pkg/k8s/k8s_pod.go (14 hunks)
  • pkg/k8s/k8s_pvc.go (3 hunks)
  • pkg/k8s/k8s_replicaset.go (5 hunks)
  • pkg/k8s/k8s_service.go (4 hunks)
  • pkg/k8s/test_suite_test.go (2 hunks)
  • pkg/knuu/knuu.go (5 hunks)
Files skipped from review due to trivial changes (1)
  • pkg/k8s/k8s_service.go
Additional comments not posted (65)
pkg/k8s/k8s_namespace.go (2)

23-23: The refactored logging statement correctly uses c.logger to log namespace existence. This change aligns with the PR's objective to standardize logging across the package.


49-49: The updated logging statement in NamespaceExists function correctly utilizes c.logger and provides detailed error information, which enhances debugging capabilities.

pkg/k8s/k8s_custom_resource.go (1)

36-36: This logging update is consistent with the PR's goal of using a structured logger. It correctly logs the successful creation of a custom resource, which is crucial for monitoring and debugging.

pkg/instance/destroy.go (2)

29-29: The refactoring of this logging statement to use i.Logger is appropriate and aligns with the objective to allow more granular control over logging settings per instance. This change is crucial for debugging individual instance operations.


38-38: This log statement correctly uses i.Logger to record the final state of the instance after destruction. It's a crucial log for tracking state transitions in instances.

pkg/k8s/k8s_pvc.go (2)

40-40: This log statement is well-placed and uses the structured logger correctly, providing visibility into the lifecycle of PVCs which is essential for operational monitoring and debugging.


55-55: The logging statement after deleting a PVC correctly uses c.logger, ensuring consistency in logging practices across k8s resource management functions. This is crucial for tracking resource cleanup operations.

pkg/instance/pool.go (1)

26-26: Successfully updated the logging statement to use the instance-specific logger.

pkg/k8s/test_suite_test.go (2)

7-7: Import of logrus correctly added for use in test setup.


41-41: Correctly passed a new logrus logger instance to the NewClientCustom function.

pkg/k8s/k8s_networkpolicy.go (1)

94-94: The addition of the debug log statement using the custom logger is appropriate and follows the new logging pattern.

pkg/k8s/k8s.go (6)

36-36: Added logger field to the Client struct to support custom logging.


41-41: The NewClient function correctly accepts a logger parameter, aligning with the refactoring objectives.


61-61: Correctly delegated the creation of the Client to NewClientCustom with the necessary parameters.


70-70: Updated NewClientCustom function signature to include logger, ensuring consistency with the new logging approach.


77-77: Initialization of the logger field in the Client struct is done correctly.


82-82: Appropriate use of the debug statement to log the status of the namespace.

pkg/k8s/k8s_daemonset.go (3)

47-47: Refactored to use the instance-specific logger. Ensure that all instances of c.logger are initialized correctly before this point.


66-66: Refactored to use the instance-specific logger. Confirm that c.logger is appropriately initialized and that the logger's lifecycle is managed correctly across all methods using it.


74-74: Refactored to use the instance-specific logger. It's crucial to verify that c.logger is not only initialized but also configured correctly to handle different logging levels as expected.

pkg/builder/kaniko/kaniko_test.go (2)

9-9: Added import for logrus to support the new logger parameter in test setups. Ensure that this does not introduce any side effects in other test functions.


29-29: Logger object added to NewClientCustom function call. Ensure that the logger is correctly configured for test environments to avoid noisy logs or missing log data.

pkg/k8s/k8s_replicaset.go (2)

39-39: Added debug logging for the replacement of a ReplicaSet. This enhances traceability of operations but ensure that logging at this level is consistent with the rest of the application.


171-171: Debug statement added for prepareReplicaSet function, improving traceability of ReplicaSet preparation steps. Confirm that the log level and the information logged are appropriate and consistent throughout the application.

pkg/knuu/knuu.go (3)

68-71: Refactored loadEnvVariables to be a method of Knuu, improving encapsulation. Ensure that this method is called appropriately during the initialization to prevent runtime issues.


98-100: Added logging for cleanup operations triggered by stop signals. This is crucial for diagnosing issues during abrupt terminations. Ensure the logger is configured to capture these logs even during shutdown sequences.


169-169: Informative log added for missing .env file. This is helpful for troubleshooting and ensuring that the application behaves as expected in environments without a specific configuration file.

pkg/k8s/k8s_pod.go (6)

111-111: Good use of structured error logging to provide context about the operation being performed when it fails.


117-117: Efficient logging of successful deletion. This is crucial for debugging and auditing purposes.


297-297: Accurate and timely logging when port forwarding is ready. This helps in monitoring the progress of operations effectively.


536-536: The method for preparing init containers is well-structured and handles errors effectively, ensuring robustness.

Also applies to: 545-545


575-575: Efficient encapsulation of pod specification preparation logic. This modular approach enhances code maintainability.

Also applies to: 590-590


629-629: The method for preparing the pod configuration is well-structured, and the use of detailed debug logs aids in troubleshooting.

Also applies to: 634-634, 650-650

pkg/instance/helper.go (8)

97-97: Proper use of structured logging to indicate the start of a service. This is essential for tracking service lifecycle events.


117-117: Logging the patching of a service provides valuable feedback about the state changes in the system, which is crucial for operations and maintenance.


158-159: These log statements are crucial for understanding the sequence of operations and their outcomes, particularly in a distributed system where tracing actions can be complex.


193-193: Good practice in logging conditional actions; it provides clarity on the decision-making process within the code.


217-217: Clear logging of resource deployment actions helps in auditing and tracking resource management.


225-225: Effective logging at resource cleanup stages is crucial for monitoring and verifying the proper release of resources.


261-261: The log statement effectively indicates the completion of a configuration deployment, which is helpful for configuration management processes.


272-272: Logging the destruction of configurations aids in maintaining the integrity and cleanliness of the environment.

pkg/instance/instance.go (24)

325-325: Added TCP port logging is helpful for debugging and operational monitoring.


362-362: The retry log provides valuable information about the retry attempts which is useful for debugging port forwarding issues.


382-382: Logging the addition of UDP ports enhances traceability and debugging.


522-522: Logging file additions is a good practice for tracking changes and operations performed on instances.


566-566: Logging folder additions helps in maintaining an operational log and aids in debugging.


606-606: Logging user settings changes is crucial for audit trails and operational transparency.


647-647: Using cached images can significantly reduce build times and resource usage, and logging such actions is beneficial for debugging and performance monitoring.


649-649: The log entry for missing cached images is essential for understanding the build process and potential delays.


656-656: Logging the push of new images provides transparency and traceability of the image management lifecycle.


660-660: Indicating that no new image build was required can help in identifying unnecessary rebuilds and optimizing the deployment process.


663-663: Logging state changes is crucial for tracking the lifecycle of instances and debugging state-related issues.


674-674: The log entries for exceeding the maximum volume limit provide immediate feedback on configuration limits, which is crucial for maintaining system stability.

Also applies to: 689-689


694-694: Logging the addition of volumes with specific attributes like size and owner provides detailed traceability and aids in configuration verification.


706-706: Logging memory settings is important for performance tuning and resource management.


717-717: CPU settings are critical for performance and resource allocation; thus, logging these settings is beneficial for system monitoring.


735-735: Environment variable settings are crucial for application configuration, and logging these settings helps ensure transparency and correctness.


836-836: Setting probes and logging these actions are vital for maintaining the health and readiness of services. It aids in operational monitoring and troubleshooting.

Also applies to: 849-849, 862-862


892-892: Logging the addition of sidecars is important for understanding the composition of services and aids in configuration management.


903-903: Logging settings for telemetry and monitoring configurations like OpenTelemetry, Jaeger, and Prometheus helps in validating and troubleshooting observability setups.

Also applies to: 914-914, 927-927, 940-940, 953-953, 964-964, 975-975, 986-986


1010-1010: Enabling the Tshark collector and logging this action provides clear feedback on the operational changes, which is essential for performance analysis and troubleshooting.


1053-1053: Settings for security contexts such as privileges and capabilities are critical for security posture. Logging these settings ensures that changes are traceable and auditable.

Also applies to: 1064-1064, 1076-1076


1146-1146: Logging state transitions, especially to a 'Started' state, is crucial for operational monitoring and helps in tracking the lifecycle of instances.


1249-1249: Logging network settings adjustments like bandwidth, latency, jitter, and packet loss is crucial for network management and performance tuning.

Also applies to: 1284-1284, 1317-1317


1378-1378: Logging the transition to a 'Stopped' state is important for lifecycle management and can aid in resource allocation and troubleshooting.

pkg/k8s/k8s_pod.go Show resolved Hide resolved
pkg/instance/helper.go Outdated Show resolved Hide resolved
pkg/instance/helper.go Show resolved Hide resolved
tty47
tty47 previously approved these changes Jun 21, 2024
pkg/k8s/k8s_namespace.go Outdated Show resolved Hide resolved
pkg/knuu/knuu.go Outdated Show resolved Hide resolved
Copy link
Member

@MSevey MSevey left a comment

Choose a reason for hiding this comment

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

quick fixes.

Copy link
Contributor

@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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b7cee0f and 7966332.

Files selected for processing (2)
  • pkg/instance/instance.go (34 hunks)
  • pkg/knuu/knuu.go (5 hunks)
Files skipped from review as they are similar to previous changes (1)
  • pkg/knuu/knuu.go
Additional comments not posted (17)
pkg/instance/instance.go (17)

333-333: Logger integration in AddPortTCP method.

The logger integration here enhances debuggability by providing specific information about the TCP port addition. This is a good use of the logger object to give context-specific logging.


370-370: Logger usage in PortForwardTCP method.

The logger statement within the retry logic provides valuable debugging information about the port forwarding process. This is particularly useful in understanding the failure reasons in a retry scenario.


390-390: Logger integration in AddPortUDP method.

Similar to the TCP port addition, logging here provides clear feedback on the operation's status, which is crucial for both debugging and operational monitoring.


530-530: Logger usage in AddFile method.

The logger effectively captures the addition of files to the instance, providing transparency and traceability for file operations within the instance setup.


574-574: Logger usage in AddFolder method.

Logging here is beneficial for tracking the addition of directories, which can often be a complex operation involving multiple file interactions.


614-614: Logger usage in SetUser method.

Proper logging of user settings changes is crucial, especially when troubleshooting issues related to permissions or user-specific configurations.


655-655: Comprehensive logging during the image commit process.

The logs here provide a detailed trace of the decision-making process during the commit phase, including the use of cached images and the pushing of new images. This is essential for understanding the lifecycle of image management within instances.

Also applies to: 657-657, 664-664, 668-668, 671-671


682-682: Logging during volume management operations.

The logs provide immediate feedback if the maximum volume limit is exceeded and confirm the addition of new volumes. This is important for managing resources effectively and avoiding configuration errors.

Also applies to: 697-697, 702-702


714-714: Logging for resource configuration methods.

Logging in these methods (memory, CPU, environment variables) is crucial for operational transparency and helps in quick diagnostics during performance tuning or troubleshooting.

Also applies to: 725-725, 743-743


844-844: Logging for probe settings.

The detailed logging when setting liveness, readiness, and startup probes provides clear feedback on the configuration of health checks, which is critical for maintaining the reliability of services.

Also applies to: 857-857, 870-870


900-900: Logger usage in AddSidecar method.

The log statement when adding a sidecar is important for tracking the composition of the instance, especially when sidecars are crucial for the functionality of the main application.


911-911: Logging for configuration setters in observability settings.

Each of these logs provides crucial information about the configuration of telemetry and monitoring tools within the instance, aiding in the observability and operational management.

Also applies to: 922-922, 935-935, 948-948, 961-961, 972-972, 983-983, 994-994


1018-1018: Logging in EnableTsharkCollector method.

The log entry when enabling the Tshark collector is beneficial for confirming the activation of this feature, which is important for network monitoring and diagnostics.


1061-1061: Logging for security configurations.

Logging changes to the security context, such as setting privileged status or adding capabilities, is critical for security audits and troubleshooting.

Also applies to: 1072-1072, 1084-1084


1154-1154: Logging state changes in StartWithoutWait method.

The log message when changing the state of the instance provides a clear audit trail of the lifecycle states, which is essential for managing the instance's lifecycle.


1257-1257: Logging for network settings adjustments.

These logs are crucial for tracking changes to network settings such as bandwidth, latency, and packet loss, which are important for performance tuning and meeting SLAs.

Also applies to: 1292-1292, 1325-1325


1386-1386: Logging during the stop operation.

This log entry is important for confirming the successful transition to the stopped state, providing a clear endpoint to the operational lifecycle of the instance.

Copy link
Member

@MSevey MSevey left a comment

Choose a reason for hiding this comment

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

One unresolved comment from previous review

@mojtaba-esk mojtaba-esk requested a review from MSevey June 25, 2024 15:37
Copy link
Contributor

@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: 6

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 7966332 and 49b05ed.

Files selected for processing (3)
  • pkg/instance/helper.go (10 hunks)
  • pkg/k8s/k8s_namespace.go (3 hunks)
  • pkg/knuu/knuu.go (3 hunks)
Additional comments not posted (8)
pkg/knuu/knuu.go (1)

164-165: Clarify the comment regarding future code changes.

The comment about potentially removing this function is vague. It would be beneficial to specify under what conditions or scenarios this function might be deprecated.

- // TODO: we might remove this function in the future
- // as it the new version knuu is configured through
- // its options via the New function
+ // TODO: Consider removing this function in future versions if all configurations
+ // are successfully migrated to be handled directly via the New function's options.
pkg/instance/helper.go (7)

97-97: Approve the updated logging statement.

The change to use the instance-specific logger is appropriate and aligns with the objectives of the refactor.


117-117: Approve the updated logging statement.

This change maintains consistency in logging practices by using the instance-specific logger.


193-193: Approve the updated logging statement.

The logging update here is consistent with the refactor's goal of using instance-specific loggers.


217-217: Approve the logging change for volume deployment.

The update to use the instance-specific logger for volume deployment logs is correctly implemented.


225-225: Approve the logging change for volume destruction.

This change correctly updates the logging to use the instance-specific logger, which helps in maintaining consistency across the codebase.


261-261: Approve the logging change for configmap deployment.

The logging update to use the instance-specific logger is correctly implemented and improves consistency.


272-272: Approve the logging change for configmap destruction.

The update to use the instance-specific logger for configmap destruction logs is correctly implemented.

pkg/k8s/k8s_namespace.go Show resolved Hide resolved
pkg/k8s/k8s_namespace.go Show resolved Hide resolved
pkg/k8s/k8s_namespace.go Show resolved Hide resolved
pkg/k8s/k8s_namespace.go Show resolved Hide resolved
pkg/knuu/knuu.go Show resolved Hide resolved
pkg/instance/helper.go Show resolved Hide resolved
MSevey
MSevey previously approved these changes Jun 26, 2024
@MSevey MSevey added this to the v0.15.0 milestone Jun 26, 2024
tty47
tty47 previously approved these changes Jun 27, 2024
@mojtaba-esk mojtaba-esk added this pull request to the merge queue Jun 27, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jun 27, 2024
@mojtaba-esk mojtaba-esk dismissed stale reviews from tty47 and MSevey via 006cb72 June 27, 2024 10:10
@mojtaba-esk mojtaba-esk enabled auto-merge June 27, 2024 10:10
@mojtaba-esk mojtaba-esk disabled auto-merge June 27, 2024 10:11
@mojtaba-esk mojtaba-esk merged commit 5bfcf2d into main Jun 27, 2024
3 of 9 checks passed
@mojtaba-esk mojtaba-esk deleted the mojtaba/396-refactoring-to-receive-a-logger-object branch June 27, 2024 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Consider refactoring all pkgs to receive a logger object instead of default logrus
3 participants