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

Mesh Registry support custom group for sofa registry. #1454

Merged

Conversation

EvenLjj
Copy link
Collaborator

@EvenLjj EvenLjj commented Oct 14, 2024

Mesh Registry support custom group for sofa registry.

Summary by CodeRabbit

  • New Features

    • Enhanced service registration and unregistration processes to support service grouping.
    • New fields added to service request classes to accommodate group attributes and additional parameters.
  • Bug Fixes

    • Improved clarity and functionality in service request handling.
  • Tests

    • Updated tests to verify the inclusion of group parameters in service requests.

@sofastack-cla sofastack-cla bot added cla:yes CLA is ok size/L labels Oct 14, 2024
Copy link
Contributor

coderabbitai bot commented Oct 14, 2024

Walkthrough

The changes enhance the MeshRegistry class and related request models to support service grouping during registration and unregistration. Key methods in MeshRegistry have been updated to handle a new group attribute, which is now included in several request classes: PublishServiceRequest, SubscribeServiceRequest, UnPublishServiceRequest, and UnSubscribeServiceRequest. Additionally, tests have been modified to verify the inclusion of the group parameter in service operations.

Changes

File Change Summary
registry/registry-mesh/src/main/java/com/alipay/sofa/rpc/registry/mesh/MeshRegistry.java Updated methods to handle service grouping during registration/unregistration.
registry/registry-mesh/src/main/java/com/alipay/sofa/rpc/registry/mesh/model/PublishServiceRequest.java Added group field with getter/setter; updated toString() method.
registry/registry-mesh/src/main/java/com/alipay/sofa/rpc/registry/mesh/model/SubscribeServiceRequest.java Added fields: vipOnly, localCloudFirst, group, properties; added getters/setters; updated toString().
registry/registry-mesh/src/main/java/com/alipay/sofa/rpc/registry/mesh/model/UnPublishServiceRequest.java Added group field with getter/setter.
registry/registry-mesh/src/main/java/com/alipay/sofa/rpc/registry/mesh/model/UnSubscribeServiceRequest.java Added group field with getter/setter; updated toString() method.
registry/registry-mesh/src/test/java/com/alipay/sofa/rpc/registry/mesh/MeshRegistryTest.java Updated tests to include group parameter in service operations.

Poem

In the meadow where bunnies play,
New groups gather, hip-hip-hooray!
With requests that dance and twirl,
Service magic begins to unfurl.
Hops of joy in every line,
Together we grow, oh how divine! 🐇✨


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

🧹 Outside diff range and nitpick comments (12)
registry/registry-mesh/src/main/java/com/alipay/sofa/rpc/registry/mesh/model/UnPublishServiceRequest.java (1)

Line range hint 57-64: Update toString() method to include the group field

The toString() method should be updated to include the new group field for completeness and consistency in object representation. This will ensure that all relevant information is available when logging or debugging.

Consider updating the toString() method as follows:

 @Override
 public String toString() {
     final StringBuffer sb = new StringBuffer("UnPublishServiceRequest{");
     sb.append("serviceName='").append(serviceName).append('\'');
     sb.append(", protocolType='").append(protocolType).append('\'');
+    sb.append(", group='").append(group).append('\'');
     sb.append('}');
     return sb.toString();
 }
registry/registry-mesh/src/main/java/com/alipay/sofa/rpc/registry/mesh/model/UnSubscribeServiceRequest.java (1)

73-73: Approved with suggestion: Update to toString() method

The toString() method has been correctly updated to include the new group field, maintaining consistency with the existing implementation. However, to improve null safety, consider using Objects.toString(group, "") instead of directly appending group.

Here's a suggested improvement:

-        sb.append(", group='").append(group).append('\'');
+        sb.append(", group='").append(Objects.toString(group, "")).append('\'');

This change ensures that if group is null, an empty string will be used instead, preventing potential null pointer exceptions.

registry/registry-mesh/src/main/java/com/alipay/sofa/rpc/registry/mesh/model/PublishServiceRequest.java (1)

73-76: LGTM with suggestion: Addition of setGroup(String group) method

The setGroup(String group) method is correctly implemented, following Java naming conventions for setter methods. It provides appropriate public access to modify the group field value.

Consider adding input validation for the group parameter. For example:

public void setGroup(String group) {
    if (group == null || group.trim().isEmpty()) {
        throw new IllegalArgumentException("Group cannot be null or empty");
    }
    this.group = group;
}

This ensures that the group field is always set to a meaningful value.

registry/registry-mesh/src/main/java/com/alipay/sofa/rpc/registry/mesh/model/SubscribeServiceRequest.java (3)

35-43: New fields added correctly, consider adding Javadoc comments.

The new fields vipOnly, localCloudFirst, group, and properties enhance the functionality of the SubscribeServiceRequest class. The types are appropriate, and the properties field allows for extensibility.

Consider adding Javadoc comments for each new field to explain their purpose and usage, especially for vipOnly, localCloudFirst, and group. This will improve code documentation and maintainability.


101-107: Getter and setter for properties implemented correctly, consider defensive copying.

The getProperties() and setProperties(Map<String, String> properties) methods are correctly implemented. However, to prevent external modification of the internal state, consider using defensive copying.

Consider implementing defensive copying for the properties field:

public Map<String, String> getProperties() {
    return properties == null ? null : new HashMap<>(properties);
}

public void setProperties(Map<String, String> properties) {
    this.properties = properties == null ? null : new HashMap<>(properties);
}

This approach prevents external code from modifying the internal state of the object.


118-118: Update to toString() method is correct, consider including properties.

The group field has been correctly added to the string representation. However, the properties field is not included.

Consider adding the properties field to the toString() method for completeness:

sb.append(", group='").append(group).append('\'');
sb.append(", properties=").append(properties);
sb.append('}');

This will provide a more comprehensive string representation of the object.

registry/registry-mesh/src/test/java/com/alipay/sofa/rpc/registry/mesh/MeshRegistryTest.java (3)

170-171: LGTM! Consider using a constant for the group value.

The addition of the parameter map with the SOFA_GROUP_KEY is consistent with the PR objective of adding support for custom groups.

Consider defining "SOFA_TEST" as a constant at the class level for better maintainability and to avoid magic strings in the test code.


224-225: LGTM! Comprehensive verification of SubscribeServiceRequest.

The added assertions correctly verify the group information and the presence of properties in the SubscribeServiceRequest. This ensures the custom group support is working as expected for subscriptions.

Consider adding a more specific assertion for the properties, such as checking for the presence of the SOFA_GROUP_KEY in the properties map. This would provide a more thorough verification of the group information propagation.


273-273: LGTM! Verification of group in UnSubscribeServiceRequest.

The added assertion correctly verifies that the group information ("SOFA_TEST") is set in the UnSubscribeServiceRequest, ensuring the custom group support is maintained during service unsubscription.

To complete the test coverage, consider adding similar group assertions for the batch operations (batchUnRegister and batchUnSubscribe) at the end of the test method. This would ensure that the group information is correctly handled in bulk operations as well.

registry/registry-mesh/src/main/java/com/alipay/sofa/rpc/registry/mesh/MeshRegistry.java (3)

188-191: LGTM: Group support added to PublishServiceRequest

The changes correctly implement group support for the publish service request. Good use of StringUtils.isNotBlank() to avoid potential null or empty string issues.

Consider extracting SofaRegistryConstants.SOFA_GROUP_KEY to a local constant in this class if it's used frequently, to improve readability and maintainability.


385-388: LGTM: Group support added to UnSubscribeServiceRequest

The changes correctly implement group support for the unsubscribe service request, consistent with the buildSubscribeServiceRequest method.

Consider refactoring the group extraction and setting logic into a separate method to reduce code duplication across these four methods. This would improve maintainability and ensure consistent behavior.


Line range hint 1-413: Summary: Group support successfully implemented with minor suggestions

The changes successfully implement custom group support for the sofa registry across publish, unpublish, subscribe, and unsubscribe operations. The implementation is consistent and uses appropriate null/blank checks.

Next steps:

  1. Verify the points raised in the individual comments, particularly the different methods used to retrieve the group value in provider vs. consumer contexts.
  2. Consider refactoring the group extraction and setting logic into a separate method to reduce code duplication.
  3. If SofaRegistryConstants.SOFA_GROUP_KEY is used frequently in this class, consider extracting it to a local constant for improved readability.

Once these points are addressed, the changes will be ready for merging.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 60433bc and 77db708.

📒 Files selected for processing (6)
  • registry/registry-mesh/src/main/java/com/alipay/sofa/rpc/registry/mesh/MeshRegistry.java (5 hunks)
  • registry/registry-mesh/src/main/java/com/alipay/sofa/rpc/registry/mesh/model/PublishServiceRequest.java (2 hunks)
  • registry/registry-mesh/src/main/java/com/alipay/sofa/rpc/registry/mesh/model/SubscribeServiceRequest.java (3 hunks)
  • registry/registry-mesh/src/main/java/com/alipay/sofa/rpc/registry/mesh/model/UnPublishServiceRequest.java (2 hunks)
  • registry/registry-mesh/src/main/java/com/alipay/sofa/rpc/registry/mesh/model/UnSubscribeServiceRequest.java (2 hunks)
  • registry/registry-mesh/src/test/java/com/alipay/sofa/rpc/registry/mesh/MeshRegistryTest.java (8 hunks)
🧰 Additional context used
🔇 Additional comments (23)
registry/registry-mesh/src/main/java/com/alipay/sofa/rpc/registry/mesh/model/UnPublishServiceRequest.java (3)

30-31: LGTM: Addition of group field

The new group field aligns with the PR objective of supporting custom groups for the sofa registry. It's correctly declared as private, maintaining proper encapsulation.


48-51: LGTM: Addition of getGroup() method

The getGroup() method is correctly implemented, following Java conventions and providing appropriate read access to the private group field.


52-55: LGTM: Addition of setGroup(String group) method

The setGroup(String group) method is correctly implemented, following Java conventions and providing appropriate write access to the private group field.

registry/registry-mesh/src/main/java/com/alipay/sofa/rpc/registry/mesh/model/UnSubscribeServiceRequest.java (4)

33-34: LGTM: Addition of group field

The new group field aligns with the PR objective to support custom groups for the sofa registry. It's correctly declared as private and appropriately placed within the class structure.


59-62: LGTM: Addition of getGroup() method

The getGroup() method is correctly implemented, following Java conventions for naming and accessibility. It's appropriately placed within the class structure.


63-66: LGTM: Addition of setGroup(String group) method

The setGroup(String group) method is correctly implemented, following Java conventions for naming and accessibility. It's appropriately placed within the class structure.


Line range hint 33-73: Overall assessment: Well-implemented changes supporting custom groups

The changes to UnSubscribeServiceRequest.java effectively implement support for custom groups in the sofa registry. The new group field and its accessor methods are correctly implemented and integrated into the existing class structure. These changes enhance the flexibility of the unsubscribe service request, allowing for more granular control over service grouping.

The modifications follow Java conventions and best practices, maintaining code quality and readability. The only minor suggestion is to improve null safety in the toString() method, as mentioned in the previous comment.

These changes align well with the PR objective and should positively impact the functionality of the Mesh Registry.

registry/registry-mesh/src/main/java/com/alipay/sofa/rpc/registry/mesh/model/PublishServiceRequest.java (4)

35-36: LGTM: Addition of group field

The new group field aligns with the PR objective to support custom groups for the sofa registry. It's correctly declared as private, maintaining proper encapsulation.


69-72: LGTM: Addition of getGroup() method

The getGroup() method is correctly implemented, following Java naming conventions for getter methods. It provides appropriate public access to the group field value.


84-84: LGTM: Update to toString() method

The toString() method has been correctly updated to include the new group field. The format is consistent with the existing implementation, maintaining readability and completeness of the object's string representation.


Line range hint 1-87: Overall assessment: Changes align with PR objectives

The addition of the group field and its associated methods (getGroup(), setGroup(String group)) to the PublishServiceRequest class successfully implements support for custom groups in the sofa registry. The changes are well-integrated into the existing class structure and follow good coding practices.

A minor suggestion for input validation in the setGroup method has been made to enhance robustness. Otherwise, the implementation is sound and ready for integration.

registry/registry-mesh/src/main/java/com/alipay/sofa/rpc/registry/mesh/model/SubscribeServiceRequest.java (3)

19-20: LGTM: Import statement added correctly.

The import for java.util.Map is necessary for the new properties field and is correctly placed in the import section.


93-99: LGTM: Getter and setter for group implemented correctly.

The getGroup() and setGroup(String group) methods are correctly implemented following Java conventions for accessor methods.


Line range hint 1-121: Overall, the changes enhance the SubscribeServiceRequest class effectively.

The additions of new fields (vipOnly, localCloudFirst, group, and properties) and their corresponding getter/setter methods improve the functionality of the class. The changes are well-implemented and follow Java conventions.

Consider the following suggestions for further improvement:

  1. Add Javadoc comments for the new fields to enhance documentation.
  2. Implement defensive copying for the properties field to prevent external state modification.
  3. Include the properties field in the toString() method for a complete string representation.

These minor enhancements will improve the overall quality, maintainability, and robustness of the class.

registry/registry-mesh/src/test/java/com/alipay/sofa/rpc/registry/mesh/MeshRegistryTest.java (6)

188-189: LGTM! Appropriate application of the group parameter.

The addition of setParameters(parameter) to the ProviderConfig is consistent with the PR objective and correctly applies the group information.


202-203: LGTM! Consistent application of the group parameter.

The addition of setParameters(parameter) to the ConsumerConfig is consistent with the PR objective and maintains consistency with the ProviderConfig setup.


212-212: LGTM! Proper verification of group in PublishServiceRequest.

The added assertion correctly verifies that the group information ("SOFA_TEST") is set in the PublishServiceRequest, ensuring the custom group support is working as expected.


236-236: LGTM! Verification of group in UnPublishServiceRequest.

The added assertion correctly verifies that the group information ("SOFA_TEST") is set in the UnPublishServiceRequest, ensuring the custom group support is maintained during service unpublishing.


257-258: LGTM! Consistent application of group parameter for multiple consumers.

The addition of setParameters(parameter) to the second ConsumerConfig maintains consistency in applying the group information across multiple consumers. This ensures that the custom group support is properly tested for multiple subscriptions.


Line range hint 1-337: Overall assessment: Well-implemented custom group support

The changes in this file consistently implement and verify the custom group support across various operations (publish, subscribe, unpublish, unsubscribe) in the MeshRegistry. The modifications align well with the PR objective of adding support for custom groups in the sofa registry.

Key points:

  1. Consistent application of group parameters to both provider and consumer configurations.
  2. Thorough assertions to verify group information in various service requests.
  3. Maintenance of group information across multiple consumers and operations.

Suggestions for further improvement:

  1. Consider using constants for repeated string values like "SOFA_TEST".
  2. Add more specific assertions for properties in SubscribeServiceRequest.
  3. Extend group assertions to batch operations for complete coverage.

These changes provide a solid foundation for custom group support in the Mesh Registry.

registry/registry-mesh/src/main/java/com/alipay/sofa/rpc/registry/mesh/MeshRegistry.java (3)

23-23: LGTM: Import added for StringUtils

The addition of the StringUtils import is appropriate for the new string operations in the modified methods.


241-244: LGTM: Group support added to UnPublishServiceRequest

The changes correctly implement group support for the unpublish service request, consistent with the buildPublishServiceRequest method.

Please verify if using getStaticAttr() instead of getStaticAttrs() is intentional. If it's a typo, consider changing it to getStaticAttrs() for consistency.


315-319: LGTM: Group support added to SubscribeServiceRequest

The changes correctly implement group support for the subscribe service request.

Please verify:

  1. If setting properties from consumerConfig.getParameters() is intentional and required for the subscribe request.
  2. If using consumerConfig.getParameter() for getting the group (instead of getStaticAttrs() or getStaticAttr() as in provider methods) is the correct approach for consumer configs.

Copy link

@huanglongchao huanglongchao left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@chuailiwu chuailiwu left a comment

Choose a reason for hiding this comment

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

lgtm

@EvenLjj EvenLjj merged commit ffc3b93 into sofastack:master Oct 14, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants