-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
base: main
Are you sure you want to change the base?
Conversation
WalkthroughWalkthroughThe changes introduce support for gogo protobuf in the Changes
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
Warning Review ran into problemsProblems (1)
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configration File (
|
Referencing this, as it is important too: #20389 (comment) |
…os/cosmos-sdk into hieu/depinject_gogo_support
@hieuvubk your pull request is missing a changelog! |
There was a problem hiding this 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
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 ofGetTypeUrl
method correctly handles nil checks for both theModuleConfig
and itsConfig
field, providing appropriate error messages. This is a good practice for robust error handling.
16-28
: The methodGetGolangBindingsStrings
effectively extracts interface types and their implementations fromGolangBindings
. Using slices with pre-allocated lengths based on the input slice ensures efficient memory usage.api/cosmos/app/v1alpha1/types.go (2)
5-14
: TheGetTypeUrl
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 usingprotoadapt
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.godepinject/appconfig/module.go (1)
7-7
: Switching the import togithub.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 updatedLoadJSON
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
: TheCompose
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.godepinject/appconfig/config_test.go (1)
124-221
: The new testTestComposeGogoTypes
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 theCompose
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) |
There was a problem hiding this comment.
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.
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) | |
} |
There was a problem hiding this 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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
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...
depinject.Compose
version that support gogoReviewers 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...
Summary by CodeRabbit
New Features
appv2
), in addition to the existingappv1alpha1
.Enhancements
appv1alpha1
andappv2
.Testing
Internal Improvements