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

refactor: minimal logger interface #964

Merged
merged 2 commits into from
Jul 25, 2024
Merged

refactor: minimal logger interface #964

merged 2 commits into from
Jul 25, 2024

Conversation

julienrbrt
Copy link
Member

@julienrbrt julienrbrt commented Jul 25, 2024

ref: cosmos/cosmos-sdk#21045

Remove all logger dependency, as no With is used in iavl, define the expected logger interface directly here and kill all log dependencies.

Summary by CodeRabbit

  • New Features

    • Introduced a new logging interface and no-operation logger to enhance logging capabilities across the application.
  • Bug Fixes

    • Streamlined logger instantiation by replacing outdated logging package references, improving maintainability.
  • Refactor

    • Updated logging mechanisms within various test files, ensuring consistent usage of the new logger implementation throughout the codebase.
  • Chores

    • Adjusted dependency versions in the module configuration to ensure compatibility with updated libraries and frameworks.

@julienrbrt julienrbrt requested a review from a team as a code owner July 25, 2024 09:29
Copy link

coderabbitai bot commented Jul 25, 2024

Walkthrough

The recent updates across various files primarily involve a transition in the logging mechanism used within the IAVL package. Instances of log.NewNopLogger() have been replaced with a locally defined NewNopLogger(), streamlining dependencies and enhancing code maintainability. This refactor improves the modularity of the logging approach while maintaining the overall functionality of the components involved.

Changes

Files Change Summary
basic_test.go, benchmarks/..., cmd/go.mod, db/README.md, diff_test.go, export_test.go, immutable_tree.go, import_test.go, iterator_test.go, logger.go, migrate_test.go, mutable_tree.go, mutable_tree_test.go, nodedb.go, nodedb_test.go, proof_iavl_test.go, proof_ics23_test.go, testutils_test.go, tree_random_test.go, tree_test.go Replaced log.NewNopLogger() with NewNopLogger() across multiple files, indicating a refactor of the logging mechanism to enhance modularity and reduce dependencies. Updates made to logger types in struct definitions and function signatures across various files to align with this change.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant TestSystem
    participant Logger

    User->>TestSystem: Run Tests
    TestSystem->>Logger: Initialize Logging
    Logger-->>TestSystem: Return NewNopLogger
    TestSystem->>TestSystem: Execute Tests
    TestSystem-->>User: Return Test Results
Loading

Poem

🐇 In the forest where changes flow,
A logger hops, putting on a show.
With a new name, it’s clear to see,
The code is clean, as can be!
Hopping through tests with joyful delight,
A rabbit’s cheer for logging done right! 🌟


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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a514883 and e6b2872.

Files ignored due to path filters (2)
  • cmd/go.sum is excluded by !**/*.sum
  • go.sum is excluded by !**/*.sum
Files selected for processing (22)
  • basic_test.go (3 hunks)
  • benchmarks/bench_test.go (2 hunks)
  • benchmarks/cosmos-exim/main.go (4 hunks)
  • cmd/go.mod (3 hunks)
  • db/README.md (1 hunks)
  • diff_test.go (3 hunks)
  • export_test.go (7 hunks)
  • go.mod (2 hunks)
  • immutable_tree.go (3 hunks)
  • import_test.go (13 hunks)
  • iterator_test.go (7 hunks)
  • logger.go (1 hunks)
  • migrate_test.go (9 hunks)
  • mutable_tree.go (3 hunks)
  • mutable_tree_test.go (24 hunks)
  • nodedb.go (3 hunks)
  • nodedb_test.go (18 hunks)
  • proof_iavl_test.go (1 hunks)
  • proof_ics23_test.go (2 hunks)
  • testutils_test.go (3 hunks)
  • tree_random_test.go (2 hunks)
  • tree_test.go (38 hunks)
Files skipped from review due to trivial changes (10)
  • benchmarks/cosmos-exim/main.go
  • export_test.go
  • import_test.go
  • iterator_test.go
  • migrate_test.go
  • nodedb_test.go
  • proof_iavl_test.go
  • proof_ics23_test.go
  • tree_random_test.go
  • tree_test.go
Additional comments not posted (38)
db/README.md (1)

26-26: LGTM!

The change simplifies the logger instantiation in the example code.

go.mod (3)

6-6: Dependency update approved.

The version of cosmossdk.io/core has been updated to ensure compatibility with the newer version.


17-17: Dependency update approved.

The version of github.com/cosmos/gogoproto has been updated to ensure compatibility with the newer version.


26-26: Dependency update approved.

The version of google.golang.org/protobuf has been updated to ensure compatibility with the newer version.

logger.go (5)

3-22: LGTM!

The Logger interface is well-defined and matches the logging needs of the project.


24-27: LGTM!

The NewNopLogger function correctly returns a no-operation logger.


29-29: LGTM!

The noopLogger struct correctly represents a no-operation logger.


31-31: LGTM!

The Info method correctly represents a no-operation logger.


32-34: LGTM!

The Warn, Error, and Debug methods correctly represent a no-operation logger.

cmd/go.mod (6)

50-50: Verify the impact of the google.golang.org/protobuf update.

The version has been updated to v1.34.2. Ensure that this update does not introduce breaking changes or unexpected behavior.


49-49: Verify the impact of the golang.org/x/text update.

The version has been updated to v0.16.0. Ensure that this update does not introduce breaking changes or unexpected behavior.

Verification successful

No direct usage of golang.org/x/text found.

The dependency golang.org/x/text is not directly imported in the codebase. Ensure to verify any indirect usage through other dependencies if necessary.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of the `golang.org/x/text` update.

# Test: Check for breaking changes or unexpected behavior.
rg --type go 'golang.org/x/text'

Length of output: 32


Script:

#!/bin/bash
# Description: Verify the impact of the `golang.org/x/text` update by searching for import statements.

# Test: Search for import statements of `golang.org/x/text` in Go files.
ast-grep --lang go --pattern 'import "golang.org/x/text"'

Length of output: 184


48-48: Verify the impact of the golang.org/x/sys update.

The version has been updated to v0.22.0. Ensure that this update does not introduce breaking changes or unexpected behavior.

Verification successful

Verification complete: No direct usage of golang.org/x/sys found.

The update to golang.org/x/sys v0.22.0 appears to be safe as there are no direct references to this dependency in the codebase. The dependency is likely used indirectly, and the risk of breaking changes is minimized.

  • No direct references to golang.org/x/sys found in Go source files.
  • Multiple versions of golang.org/x/sys present in go.sum, indicating historical updates.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of the `golang.org/x/sys` update.

# Test: Check for breaking changes or unexpected behavior.
rg --type go 'golang.org/x/sys'

Length of output: 31


Script:

#!/bin/bash
# Description: Verify the impact of the `golang.org/x/sys` update.

# Test 1: Check for references in go.mod and go.sum files.
rg 'golang.org/x/sys' go.mod go.sum

# Test 2: Check for indirect usage in the codebase.
rg 'sys' --type go

Length of output: 1971


21-21: Verify the impact of the github.com/cosmos/gogoproto update.

The version has been updated to v1.5.0. Ensure that this update does not introduce breaking changes or unexpected behavior.


6-6: Verify the impact of the cosmossdk.io/core update.

The version has been updated to v0.12.1-0.20240725072823-6a2d039e1212. Ensure that this update does not introduce breaking changes or unexpected behavior.


7-7: Verify the reason for the cosmossdk.io/log downgrade.

The version has been downgraded to v1.3.1. Ensure that this downgrade is intentional and does not introduce issues that were fixed in the newer version.

diff_test.go (2)

23-23: Verify the impact of the logging change in TestDiffRoundTrip.

The logging mechanism has been changed from log.NewNopLogger() to NewNopLogger(). Ensure that this change does not affect the logging behavior during the execution of the test.


32-32: Verify the impact of the logging change in TestDiffRoundTrip.

The logging mechanism has been changed from log.NewNopLogger() to NewNopLogger(). Ensure that this change does not affect the logging behavior during the execution of the test.

Verification successful

The logging change in TestDiffRoundTrip does not affect the logging behavior.

The NewNopLogger function correctly returns a no-op logger, ensuring that the logging behavior remains unchanged during the test execution.

  • The NewNopLogger function returns an instance of noopLogger, which is an empty struct with no methods, confirming it performs no operations.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of the logging change in `TestDiffRoundTrip`.

# Test: Check for changes in logging behavior.
rg --type go 'NewNopLogger'

Length of output: 10680


Script:

#!/bin/bash
# Description: Extract the implementation of the NewNopLogger function to verify its behavior.

# Extract the implementation of NewNopLogger function
ast-grep --lang go --pattern 'func NewNopLogger() Logger {
  $$$
}'

Length of output: 167


Script:

#!/bin/bash
# Description: Extract the implementation of the noopLogger struct and its methods to verify its behavior.

# Extract the implementation of noopLogger struct
ast-grep --lang go --pattern 'type noopLogger struct {
  $$$
}'

# Extract the methods of noopLogger
ast-grep --lang go --pattern 'func ($_ noopLogger) $_($_) {
  $$$
}'

Length of output: 176


Script:

#!/bin/bash
# Description: Confirm that noopLogger has no methods implemented.

# Search for any methods associated with noopLogger
rg --type go 'func (n noopLogger) '

Length of output: 37

testutils_test.go (2)

324-324: Verify the impact of the logging change in benchmarkImmutableAvlTreeWithDB.

The logging mechanism has been changed from log.NewNopLogger() to NewNopLogger(). Ensure that this change does not affect the logging behavior during the execution of the benchmark.

Verification successful

The logging change from log.NewNopLogger() to NewNopLogger() does not affect the logging behavior during the execution of the benchmark.

  • The function NewNopLogger() is used consistently across various test files, indicating it is a standard practice.
  • No new behavior is introduced by this change.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of the logging change in `benchmarkImmutableAvlTreeWithDB`.

# Test: Check for changes in logging behavior.
rg --type go 'NewNopLogger'

Length of output: 10680


46-46: Verify the impact of the logging change in getTestTree.

The logging mechanism has been changed from log.NewNopLogger() to NewNopLogger(). Ensure that this change does not affect the logging behavior during the execution of the test.

Verification successful

Verify the impact of the logging change in getTestTree.

The logging mechanism has been changed from log.NewNopLogger() to NewNopLogger(). This change is consistent across the codebase and does not affect the logging behavior during the execution of the test.

  • The instances of NewNopLogger found in various test files indicate that this change is uniformly applied.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the impact of the logging change in `getTestTree`.

# Test: Check for changes in logging behavior.
rg --type go 'NewNopLogger'

Length of output: 10680

immutable_tree.go (2)

19-19: Verify the compatibility of the new Logger type.

The logger field type has been changed from log.Logger to Logger. Ensure that the new Logger type is correctly defined and compatible with the existing logging requirements.


28-28: Verify the compatibility of the Logger type in NewImmutableTree.

The lg parameter type has been changed from log.Logger to Logger. Ensure that the new Logger type is correctly defined and compatible with the existing logging requirements in the NewImmutableTree function.

benchmarks/bench_test.go (1)

29-29: Verify the compatibility of the iavl.NewNopLogger() function.

The logger used to create a new mutable tree has been changed from log.NewNopLogger() to iavl.NewNopLogger(). Ensure that the new iavl.NewNopLogger() function is correctly defined and compatible with the existing logging requirements.

basic_test.go (2)

444-444: Verify the compatibility of the NewNopLogger() function.

The logger used to create a new mutable tree has been changed from log.NewNopLogger() to NewNopLogger(). Ensure that the new NewNopLogger() function is correctly defined and compatible with the existing logging requirements.


499-499: Verify the compatibility of the NewNopLogger() function.

The logger used to create a new mutable tree has been changed from log.NewNopLogger() to NewNopLogger(). Ensure that the new NewNopLogger() function is correctly defined and compatible with the existing logging requirements.

mutable_tree.go (2)

36-36: Change approved: Updated logger type in MutableTree struct.

The logger field type has been changed from log.Logger to Logger, which aligns with the PR objective to streamline the logging mechanism.


49-49: Change approved: Updated logger parameter type in NewMutableTree function.

The logger parameter type has been changed from log.Logger to Logger, which aligns with the PR objective to streamline the logging mechanism.

nodedb.go (2)

79-79: Change approved: Updated logger type in nodeDB struct.

The logger field type has been changed from log.Logger to Logger, which aligns with the PR objective to streamline the logging mechanism.


94-94: Change approved: Updated logger parameter type in newNodeDB function.

The logger parameter type has been changed from log.Logger to Logger, which aligns with the PR objective to streamline the logging mechanism.

mutable_tree_test.go (10)

37-37: Change approved: Use of NewNopLogger()

The change to use NewNopLogger() instead of log.NewNopLogger() aligns with the PR objective to streamline the logging mechanism.


259-259: Change approved: Use of NewNopLogger()

The change to use NewNopLogger() in TestMutableTree_InitialVersion is consistent with the refactor to use a minimal logger interface.


274-274: Change approved: Use of NewNopLogger()

The change to use NewNopLogger() in TestMutableTree_InitialVersion is consistent with the refactor to use a minimal logger interface.


280-280: Change approved: Use of NewNopLogger()

The change to use NewNopLogger() in TestMutableTree_InitialVersion is consistent with the refactor to use a minimal logger interface.


285-285: Change approved: Use of NewNopLogger()

The change to use NewNopLogger() in TestMutableTree_InitialVersion is consistent with the refactor to use a minimal logger interface.


310-310: Change approved: Use of NewNopLogger()

The change to use NewNopLogger() in BenchmarkMutableTree_Set is consistent with the refactor to use a minimal logger interface.


328-328: Change approved: Use of NewNopLogger()

The change to use NewNopLogger() in prepareTree is consistent with the refactor to use a minimal logger interface.


344-344: Change approved: Use of NewNopLogger()

The change to use NewNopLogger() in prepareTree is consistent with the refactor to use a minimal logger interface.


403-403: Change approved: Use of NewNopLogger()

The change to use NewNopLogger() in TestMutableTree_LazyLoadVersionWithEmptyTree is consistent with the refactor to use a minimal logger interface.


407-407: Change approved: Use of NewNopLogger()

The change to use NewNopLogger() in TestMutableTree_LazyLoadVersionWithEmptyTree is consistent with the refactor to use a minimal logger interface.

@julienrbrt julienrbrt merged commit 59e2992 into master Jul 25, 2024
8 checks passed
@julienrbrt julienrbrt deleted the julien/logger branch July 25, 2024 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants