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

feat(depinject): Add gogo support for depinject #20403

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

hieuvubk
Copy link
Collaborator

@hieuvubk hieuvubk commented May 15, 2024

Description

Closes: #20134


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • Gen app config & module config as gogo types
  • Add a depinject.Compose version that support gogo
  • Add tests

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

  • New Features

    • Introduced support for a new app configuration version (appv2), in addition to the existing appv1alpha1.
  • Enhancements

    • Improved module configuration handling for both appv1alpha1 and appv2.
  • Testing

    • Added new test cases to validate module configurations and error handling for different app config versions.
  • Internal Improvements

    • Updated internal dependencies and imports to enhance compatibility and functionality.

Copy link
Contributor

coderabbitai bot commented May 15, 2024

Walkthrough

Walkthrough

The changes introduce support for gogo protobuf in the depinject package, allowing users to avoid generating pulsar types. This update facilitates handling different versions of app configurations (appv1alpha1 and appv2) and enhances module configuration and binding processes. Additionally, new methods to retrieve type URLs and Golang bindings from ModuleConfig structs are added.

Changes

Files/Paths Change Summary
api/cosmos/app/v1alpha1/types.go Added methods GetTypeUrl() and GetGolangBindingsStrings() to ModuleConfig.
api/cosmos/app/v2/types.go Introduced methods to retrieve type URLs and Golang bindings strings from ModuleConfig.
depinject/appconfig/config.go Added appv2 support, modified LoadJSON and Compose functions, and adjusted module processing and binding logic.
depinject/appconfig/config_test.go Updated test cases, error messages, module configurations, and added a new test function TestComposeGogoTypes.
depinject/appconfig/module.go Changed import from google.golang.org/protobuf/proto to github.com/cosmos/gogoproto/proto.
depinject/internal/appconfig/registry.go Modified import statements and handling of ConfigProtoMessage in ModuleRegistry function to support different protobuf versions.

Sequence Diagram(s) (Beta)

sequenceDiagram
    participant User
    participant ConfigLoader
    participant ModuleConfig
    participant BindingsHandler

    User->>ConfigLoader: Load JSON Config
    ConfigLoader->>ModuleConfig: Parse Config (v1alpha1 or v2)
    ModuleConfig->>BindingsHandler: Retrieve Type URLs and Golang Bindings
    BindingsHandler-->>ModuleConfig: Return Bindings
    ModuleConfig-->>ConfigLoader: Return Parsed Config
    ConfigLoader-->>User: Return Loaded Config

Assessment against linked issues

Objective (Issue #) Addressed Explanation
Add gogo support to depinject to avoid generating pulsar types (#20134)
Reduce complexity of code by minimizing the need for extra proto files (#20134)

Warning

Review ran into problems

Problems (1)
  • Git: Failed to clone repository. Please contact CodeRabbit support.

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.

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

@julienrbrt
Copy link
Member

Referencing this, as it is important too: #20389 (comment)

@julienrbrt julienrbrt changed the title Add gogo support for depinject feat(depinject): Add gogo support for depinject May 16, 2024
@hieuvubk hieuvubk marked this pull request as ready for review May 27, 2024 13:12
@hieuvubk hieuvubk requested a review from a team as a code owner May 27, 2024 13:12
Copy link
Contributor

@hieuvubk your pull request is missing a changelog!

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

Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 190b20c and 8dc47f6.
Files ignored due to path filters (5)
  • api/cosmos/app/v2/config.pb.go is excluded by !**/*.pb.go
  • api/cosmos/app/v2/module.pb.go is excluded by !**/*.pb.go
  • depinject/go.mod is excluded by !**/*.mod
  • depinject/go.sum is excluded by !**/*.sum
  • depinject/internal/appconfig/testpb/test.pb.go is excluded by !**/*.pb.go
Files selected for processing (6)
  • api/cosmos/app/v1alpha1/types.go (1 hunks)
  • api/cosmos/app/v2/types.go (1 hunks)
  • depinject/appconfig/config.go (3 hunks)
  • depinject/appconfig/config_test.go (2 hunks)
  • depinject/appconfig/module.go (1 hunks)
  • depinject/internal/appconfig/registry.go (2 hunks)
Additional Context Used
Path-based Instructions (6)
api/cosmos/app/v2/types.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

api/cosmos/app/v1alpha1/types.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

depinject/internal/appconfig/registry.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

depinject/appconfig/module.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

depinject/appconfig/config.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

depinject/appconfig/config_test.go (2)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

Additional comments not posted (9)
api/cosmos/app/v2/types.go (2)

5-14: The implementation of GetTypeUrl method correctly handles nil checks for both the ModuleConfig and its Config field, providing appropriate error messages. This is a good practice for robust error handling.


16-28: The method GetGolangBindingsStrings effectively extracts interface types and their implementations from GolangBindings. Using slices with pre-allocated lengths based on the input slice ensures efficient memory usage.

api/cosmos/app/v1alpha1/types.go (2)

5-14: The GetTypeUrl method is implemented consistently with the v2 version, including comprehensive nil handling and clear error messaging. This consistency across versions helps in maintaining a uniform interface.


16-28: Similar to the v2 implementation, GetGolangBindingsStrings is well-implemented with efficient memory management and clear structure in handling the bindings. Consistency in method implementations across versions is beneficial.

depinject/internal/appconfig/registry.go (1)

35-50: The logic to handle both v1 and v2 protobuf messages using protoadapt is a clever use of the adapter pattern to ensure compatibility across different versions of protobuf messages. However, ensure that the error handling is robust enough to manage potential issues during the type assertions and conversions.

#!/bin/bash
# Description: Verify robust error handling for type assertions in registry.go.

# Test: Search for error handling related to type assertions. Expect: Proper error checks after type assertions.
rg --type go 'if _, ok := .*\.(.*); !ok {' ./depinject/internal/appconfig/registry.go
depinject/appconfig/module.go (1)

7-7: Switching the import to github.com/cosmos/gogoproto/proto aligns with the PR's goal to support gogo protobufs. This change should be reflected across all files that interact with protobufs to maintain consistency.

depinject/appconfig/config.go (2)

20-40: The updated LoadJSON function now supports both v1alpha1 and v2 configurations using respective unmarshalers. This dual support enhances the flexibility of the configuration loading but ensure that the error paths are thoroughly tested to handle any inconsistencies between the two versions.

#!/bin/bash
# Description: Verify thorough testing of error paths in LoadJSON function.

# Test: Search for test cases covering error paths in LoadJSON. Expect: Comprehensive test cases in config_test.go.
rg --type go 'LoadJSON' ./depinject/appconfig/config_test.go

63-190: The Compose function has been significantly refactored to handle different versions of configurations and their modules. The use of interfaces and type assertions is appropriate, but it's crucial to ensure that all edge cases and error conditions are covered in unit tests, especially for the new branching logic introduced.

#!/bin/bash
# Description: Verify coverage of edge cases in Compose function.

# Test: Search for test cases covering new logic in Compose. Expect: Specific tests for branching logic.
rg --type go 'Compose' ./depinject/appconfig/config_test.go
depinject/appconfig/config_test.go (1)

124-221: The new test TestComposeGogoTypes is crucial for verifying the integration of gogo types. It's well-structured to simulate various scenarios and error conditions. Ensure that these tests are comprehensive enough to cover all new logic introduced in the Compose function.

fullName := descriptor.FullName()
if _, ok := res[fullName]; ok {
return nil, fmt.Errorf("duplicate module registration for %s", fullName)
}

modDesc := proto.GetExtension(descriptor.Options(), appv1alpha1.E_Module).(*appv1alpha1.ModuleDescriptor)
modDesc := protov2.GetExtension(descriptor.Options(), appv1alpha1.E_Module).(*appv1alpha1.ModuleDescriptor)
Copy link
Contributor

Choose a reason for hiding this comment

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

The use of GetExtension to fetch module descriptors is correctly implemented. However, consider adding null checks after retrieving the extension to prevent potential nil pointer dereferences.

- modDesc := protov2.GetExtension(descriptor.Options(), appv1alpha1.E_Module).(*appv1alpha1.ModuleDescriptor)
+ modDesc, ok := protov2.GetExtension(descriptor.Options(), appv1alpha1.E_Module).(*appv1alpha1.ModuleDescriptor)
+ if !ok {
+     return nil, fmt.Errorf("failed to get module descriptor for %s", fullName)
+ }

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
modDesc := protov2.GetExtension(descriptor.Options(), appv1alpha1.E_Module).(*appv1alpha1.ModuleDescriptor)
modDesc, ok := protov2.GetExtension(descriptor.Options(), appv1alpha1.E_Module).(*appv1alpha1.ModuleDescriptor)
if !ok {
return nil, fmt.Errorf("failed to get module descriptor for %s", fullName)
}

@kocubinski kocubinski self-assigned this May 28, 2024
Copy link
Member

@kocubinski kocubinski left a comment

Choose a reason for hiding this comment

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

Great start!
Looking for some clarification on code gen and design decision to use an interface.

Copy link
Member

Choose a reason for hiding this comment

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

What command was run to generate these files? There must be counterparty protofiles in proto/cosmos/app/v2 which I don't see in this PR. Could you explain a bit on why a v2 API is needed?

Copy link
Member

Choose a reason for hiding this comment

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

This usage of interface implementation seems overly complex, can't we just type switch in depinject. We don't need support for n variations of generated proto types.

@@ -121,11 +121,122 @@ modules:
expectContainerErrorContains(t, opt, "module should have ModuleDescriptor.go_import specified")
}

func TestComposeGogoTypes(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

How is this test different from TestCompose? It looks like a lot of repeated code, maybe just include the new test cases which test the new code path, i.e. yamls like

    "@type": type.googleapis.com/testpb.TestGogoUnregisteredModule

Copy link
Member

Choose a reason for hiding this comment

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

This generated type needs counter party proto specs committed. How would I generate this locally?

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.

[Feature]: depinject with gogo
3 participants