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: openapi query namespace support not fill item #5249

Conversation

youngzil
Copy link
Contributor

@youngzil youngzil commented Oct 8, 2024

What's the purpose of this PR

openapi query namespace support not fill item

Which issue(s) this PR fixes:

Fixes #5243

Brief changelog

XXXXX

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Read the Contributing Guide before making this pull request.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit tests to verify the code.
  • Run mvn clean test to make sure this pull request doesn't break anything.
  • Update the CHANGES log.

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features
    • Enhanced namespace retrieval with detailed item options.
    • Added support for querying namespaces via OpenAPI without requiring item filling.
    • Introduced global search capabilities for administrators, with limits on namespace and item counts.
    • Implemented a connection pool configuration for the portal's RestTemplate client.
    • Added cache record stats function for the ConfigService.
  • Bug Fixes
    • Addressed issues related to duplicate comments and blank lines in configuration management.
    • Fixed missing items in the published namespace link.
  • Documentation
    • Updated method signatures to reflect new parameters for improved clarity.
  • Chores
    • Upgraded dependency version for improved compatibility and performance.

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Oct 8, 2024
Copy link
Contributor

coderabbitai bot commented Oct 8, 2024

Walkthrough

The changes in this pull request involve modifications to several classes within the Apollo project, primarily focusing on enhancing the functionality of methods related to namespace management. Key updates include the addition of a boolean parameter, fillItemDetail, to multiple method signatures, which allows for more control over the retrieval of detailed item information within namespaces. This affects the behavior of both the API endpoints and the internal service methods that interact with namespaces, as well as adjustments to corresponding test cases.

Changes

File Change Summary
.../NamespaceController.java Modified findNamespaces and loadNamespace methods to include fillItemDetail parameter with default value.
.../ConfigsExportController.java Updated exportItems method to include new boolean parameter in loadNamespaceBO method call.
.../ConfigsExportService.java Modified exportNamespaces method to include new boolean parameter in findNamespaceBOs method call.
.../NamespaceService.java Updated findNamespaceBOs, loadNamespaceBO, and transformNamespace2BO methods to include fillItemDetail parameter.
.../ConfigsExportServiceTest.java Adjusted testNamespaceExportImport method to include new parameter in findNamespaceBOs method calls.
.../NamespaceServiceTest.java Updated loadNamespaceBO method to include new boolean parameter.
pom.xml Updated apollo-java version from 2.2.0 to 2.4.0-SNAPSHOT.

Assessment against linked issues

Objective Addressed Explanation
Add parameter to control item detail retrieval in namespace API (5243)

Possibly related PRs

Suggested labels

size:M, lgtm

Suggested reviewers

  • nobodyiam

🐰 "In the code we hop and play,
New parameters lead the way.
With details filled or left behind,
Our namespaces are now refined.
A version bump, we cheer and sing,
In Apollo's realm, we bring the spring!" 🌼


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 9c38159 and 093e12d.

📒 Files selected for processing (2)
  • CHANGES.md (1 hunks)
  • apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/NamespaceController.java (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • CHANGES.md
  • apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/NamespaceController.java

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

🧹 Outside diff range and nitpick comments (11)
apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/server/service/ServerNamespaceOpenApiService.java (1)

61-63: LGTM! Consider adding method documentation.

The changes to the getNamespace method align well with the PR objectives. The new fillItemDetail parameter is correctly integrated into the method signature and passed to the loadNamespaceBO call.

Consider adding Javadoc to document the method's purpose and the new fillItemDetail parameter. For example:

/**
 * Retrieves namespace information.
 *
 * @param appId The application ID
 * @param env The environment
 * @param clusterName The cluster name
 * @param namespaceName The namespace name
 * @param fillItemDetail Whether to include detailed item information
 * @return The namespace data transfer object
 */
apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/NamespaceController.java (3)

85-87: LGTM: Method updated to support optional item detail retrieval.

The changes to findNamespaces method align well with the PR objectives. The new fillItemDetail parameter allows clients to control whether item details are populated, potentially improving performance.

Consider adding a brief Javadoc comment to explain the purpose of the fillItemDetail parameter:

/**
 * @param fillItemDetail If true, populates item details for each namespace. Defaults to true.
 */

92-94: LGTM: Method updated consistently with findNamespaces.

The changes to loadNamespace method are consistent with the modifications made to findNamespaces and align well with the PR objectives.

Similar to the suggestion for findNamespaces, consider adding a brief Javadoc comment to explain the purpose of the fillItemDetail parameter:

/**
 * @param fillItemDetail If true, populates item details for the namespace. Defaults to true.
 */

33-33: Summary: Successful implementation of optional item detail retrieval.

The changes in this file successfully implement the feature to control item detail population for namespaces. The modifications are minimal, focused, and maintain backward compatibility by defaulting fillItemDetail to true. This enhancement aligns well with the PR objectives and should improve API flexibility and potential performance.

To fully leverage this new feature:

  1. Ensure that the NamespaceOpenApiService implementation efficiently handles the fillItemDetail flag to avoid unnecessary data retrieval.
  2. Update the API documentation to clearly explain the new parameter and its performance implications.
  3. Consider adding metrics to track usage of this feature, which could inform future optimizations.

Also applies to: 85-87, 92-94

apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ConfigsExportController.java (1)

96-96: Approve change, but suggest improvements for flexibility and clarity.

The addition of the new boolean parameter aligns with the PR objectives to control item population. However, consider the following improvements:

  1. Instead of hardcoding true, introduce a configurable parameter to allow dynamic control over item population:
- namespaceService.loadNamespaceBO(appId, Env.valueOf(env), clusterName, namespaceName, true, false);
+ namespaceService.loadNamespaceBO(appId, Env.valueOf(env), clusterName, namespaceName, fillItemDetail, false);
  1. Add documentation explaining the purpose of the new fillItemDetail parameter.

  2. Update the NamespaceService import statement to reflect the new method signature, ensuring clarity for developers.

Would you like me to propose these changes in a more detailed manner?

apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/ConfigsExportServiceTest.java (1)

Line range hint 1-280: Overall assessment of changes in ConfigsExportServiceTest

The changes in this file address the addition of a new parameter (presumably fillItemDetail) to the namespaceService.findNamespaceBOs method. While this is a step in the right direction, there are opportunities to enhance the test coverage and clarity:

  1. The test method testNamespaceExportImport could be split into multiple test cases to cover different scenarios with the new parameter.
  2. Consider adding more assertions to verify the impact of the fillItemDetail parameter on the exported and imported data.
  3. Update the test class documentation to mention the new functionality being tested.

To improve the overall test coverage, consider adding the following test methods:

@Test
public void testNamespaceExportImportWithFillItemDetailTrue() {
    // Test scenario with fillItemDetail = true
}

@Test
public void testNamespaceExportImportWithFillItemDetailFalse() {
    // Test scenario with fillItemDetail = false
}

@Test
public void testNamespaceExportImportWithMixedFillItemDetail() {
    // Test scenario with a mix of true and false for fillItemDetail
}

These additional test methods would provide more comprehensive coverage of the new functionality and help ensure its correctness under various scenarios.

apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/NamespaceServiceTest.java (1)

Line range hint 268-272: LGTM! Consider adding a comment to explain the new test case.

The new test case effectively validates the behavior of loadNamespaceBO with different boolean parameters, aligning with the PR objectives. It correctly checks for a reduced number of items and modified count when not including deleted items.

Consider adding a brief comment above this new test case to explain what specific scenario it's testing. For example:

// Test loadNamespaceBO when includeDeleted is true and fillItemDetail is false
NamespaceBO namespaceBO2 = namespaceService.loadNamespaceBO(testAppId, testEnv, testClusterName, testNamespaceName, true, false);

This would improve the readability and maintainability of the test suite.

apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceService.java (4)

232-234: Confirm Default Parameter Values in Overloaded Method

In the overloaded method:

public List<NamespaceBO> findNamespaceBOs(String appId, Env env, String clusterName) {
    return findNamespaceBOs(appId, env, clusterName, true, true);
}

The default values true, true are used for fillItemDetail and includeDeletedItems. Ensure that these defaults align with the expected behavior and do not introduce unintended side effects.


263-265: Verify Default Behavior in Overloaded loadNamespaceBO Method

In the overloaded method:

public NamespaceBO loadNamespaceBO(String appId, Env env, String clusterName,
    String namespaceName) {
    return loadNamespaceBO(appId, env, clusterName, namespaceName, true, true);
}

Confirm that using true, true as default values for fillItemDetail and includeDeletedItems is intended and verify that it doesn't adversely affect performance or functionality when detailed item information is unnecessary.


Line range hint 296-324: Initialize items List Even When fillItemDetail Is False

When fillItemDetail is false, the method returns early without populating items:

if (!fillItemDetail) {
    return namespaceBO;
}

Ensure that the items list is initialized to prevent potential NullPointerException issues in downstream code that may iterate over this list.

Apply this diff to initialize the items list:

 private NamespaceBO transformNamespace2BO(Env env, NamespaceDTO namespace, boolean fillItemDetail, boolean includeDeletedItems) {
     NamespaceBO namespaceBO = new NamespaceBO();
     namespaceBO.setBaseInfo(namespace);

     String appId = namespace.getAppId();
     String clusterName = namespace.getClusterName();
     String namespaceName = namespace.getNamespaceName();

     fillAppNamespaceProperties(namespaceBO);

+    // Initialize items list to prevent NullPointerException
+    namespaceBO.setItems(new LinkedList<>());

     if (!fillItemDetail) {
         return namespaceBO;
     }

354-356: Consistent Use of Default Parameters in transformNamespace2BO

The method overload:

private NamespaceBO transformNamespace2BO(Env env, NamespaceDTO namespace) {
    return transformNamespace2BO(env, namespace, true, true);
}

Ensure that defaulting fillItemDetail and includeDeletedItems to true is appropriate for all cases where this overload is used. If there are scenarios where less detail is sufficient, consider providing additional overloads or adjusting defaults as needed.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between b32fcc6 and 71f9fa0.

📒 Files selected for processing (8)
  • apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/server/service/ServerNamespaceOpenApiService.java (1 hunks)
  • apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/NamespaceController.java (2 hunks)
  • apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ConfigsExportController.java (1 hunks)
  • apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ConfigsExportService.java (1 hunks)
  • apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceService.java (7 hunks)
  • apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/ConfigsExportServiceTest.java (1 hunks)
  • apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/NamespaceServiceTest.java (1 hunks)
  • pom.xml (2 hunks)
🧰 Additional context used
🔇 Additional comments (8)
apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/server/service/ServerNamespaceOpenApiService.java (2)

Line range hint 1-99: Overall assessment: Changes are well-implemented and align with PR objectives.

The modifications to ServerNamespaceOpenApiService successfully introduce the fillItemDetail parameter to control item information retrieval for namespaces. This implementation aligns well with the PR objectives and the linked issue #5243.

Key points:

  1. Both getNamespace and getNamespaces methods have been consistently updated.
  2. The changes maintain backward compatibility.
  3. The new parameter is correctly integrated into the underlying service calls.

To further improve the code:

  1. Add Javadoc for the modified methods as suggested in previous comments.
  2. Ensure that all callers of these methods are updated to provide the fillItemDetail parameter.
  3. Consider updating the NamespaceOpenApiService interface (if it exists) to reflect these changes.

Great job on implementing this feature!


71-74: LGTM! Consider adding method documentation and verify usage.

The changes to the getNamespaces method are consistent with the PR objectives and the modifications made to getNamespace. The new fillItemDetail parameter is correctly integrated into the method signature and passed to the findNamespaceBOs call.

Consider adding Javadoc to document the method's purpose and the new fillItemDetail parameter. For example:

/**
 * Retrieves a list of namespaces.
 *
 * @param appId The application ID
 * @param env The environment
 * @param clusterName The cluster name
 * @param fillItemDetail Whether to include detailed item information for each namespace
 * @return A list of namespace data transfer objects
 */

Let's verify the impact of these changes on other parts of the codebase:

This script will help identify any locations where these methods are called, allowing us to ensure that all calls are updated to include the new fillItemDetail parameter.

✅ Verification successful

LGTM! The getNamespaces method is correctly updated with the fillItemDetail parameter, and its usages across the codebase have been verified.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for usages of getNamespace and getNamespaces methods
# and ensure they are updated with the new fillItemDetail parameter.

# Search for getNamespace method calls
echo "Checking getNamespace method calls:"
rg --type java "getNamespace\s*\([^)]*\)" --glob "!**/ServerNamespaceOpenApiService.java"

echo "\nChecking getNamespaces method calls:"
rg --type java "getNamespaces\s*\([^)]*\)" --glob "!**/ServerNamespaceOpenApiService.java"

Length of output: 2937

apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/NamespaceController.java (1)

33-33: LGTM: Import statement added for new functionality.

The import of @RequestParam is necessary and consistent with the changes made to the method signatures.

apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ConfigsExportService.java (1)

238-238: Verify the alignment of the new parameter with PR objectives.

The addition of the new boolean parameter to namespaceService.findNamespaceBOs is in line with the updated interface. However, there are a few points to consider:

  1. The use of true for the new parameter (presumably fillItemDetail) seems to contradict the PR objective of optimizing performance by not filling item data unnecessarily. Can you clarify why true is used here?

  2. It's important to ensure that this change is consistently applied across the codebase wherever namespaceService.findNamespaceBOs is called.

To verify the consistency of this change, please run the following script:

This script will help identify any inconsistencies in the usage of namespaceService.findNamespaceBOs across the codebase.

✅ Verification successful

All usages of namespaceService.findNamespaceBOs have been consistently updated with the new parameter. No instances of the old method signature were found.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for all occurrences of namespaceService.findNamespaceBOs
# and verify if they have been updated with the new parameter.

# Search for all occurrences of namespaceService.findNamespaceBOs
echo "Occurrences of namespaceService.findNamespaceBOs:"
rg --type java "namespaceService\.findNamespaceBOs\(" -A 2

# Check if there are any occurrences with the old method signature (4 parameters)
echo "\nPotential occurrences with old method signature:"
rg --type java "namespaceService\.findNamespaceBOs\([^,]+,[^,]+,[^,]+,[^,]+\)"

Length of output: 4386

pom.xml (1)

66-66: Verify compatibility and stability with apollo-java 2.4.0-SNAPSHOT

The update of apollo-java.version from 2.2.0 to 2.4.0-SNAPSHOT is a significant change that warrants careful consideration:

  1. Compatibility: Ensure that this new version is compatible with the rest of the project and doesn't introduce breaking changes.
  2. Stability: Using a SNAPSHOT version in a production environment could lead to inconsistent builds. Consider using a stable release version instead.
  3. Features: Verify if this version update is necessary for implementing the new feature described in the PR objectives (openapi query namespace support).

To check for any potential issues, run the following commands:

apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceService.java (3)

309-312: Review Early Return Logic Based on fillItemDetail

The early return when fillItemDetail is false skips the population of item details:

if (!fillItemDetail) {
    return namespaceBO;
}

Verify that all consumers of NamespaceBO can handle scenarios where item details are absent. This is crucial to prevent any unintended exceptions or logic errors in parts of the application that expect these details.


Line range hint 189-208: Ensure All Calls to findNamespaceBOs Are Updated

The method findNamespaceBOs now includes the parameters boolean fillItemDetail and boolean includeDeletedItems. Please verify that all invocations of this method throughout the codebase have been updated to reflect the new signature to prevent any MethodNotFoundException at runtime.

Run the following script to locate all method calls to findNamespaceBOs:

#!/bin/bash
# Description: Find all invocations of findNamespaceBOs and check for correct parameters.

rg --type java 'findNamespaceBOs\s*\(' -A 2

253-258: Update Calls to loadNamespaceBO with New Parameters

The method loadNamespaceBO has been updated to include boolean fillItemDetail and boolean includeDeletedItems:

public NamespaceBO loadNamespaceBO(String appId, Env env, String clusterName,
    String namespaceName, boolean fillItemDetail, boolean includeDeletedItems)

Please ensure that all method invocations are updated accordingly to prevent runtime issues.

Run the following script to find all calls to loadNamespaceBO:

Comment on lines 149 to 152
when(namespaceService.findNamespaceBOs(appId1, Env.DEV, clusterName1, true, false)).thenReturn(app1Cluster1Namespace);
when(namespaceService.findNamespaceBOs(appId1, Env.DEV, clusterName2, true, false)).thenReturn(app1Cluster2Namespace);
when(namespaceService.findNamespaceBOs(appId2, Env.DEV, clusterName1, true, false)).thenReturn(app2Cluster1Namespace);
when(namespaceService.findNamespaceBOs(appId2, Env.DEV, clusterName2, true, false)).thenReturn(app2Cluster2Namespace);
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance test coverage for the new fillItemDetail parameter

The addition of the new boolean parameter (presumably fillItemDetail) to the namespaceService.findNamespaceBOs method calls is a good start, but the test coverage could be improved:

  1. Consider adding test cases where this parameter is set to false to ensure both scenarios are covered.
  2. Update the test method name (e.g., testNamespaceExportImportWithFillItemDetail) to reflect the new functionality being tested.
  3. Add assertions to verify the behavior differences when the new parameter is set to true vs false.

Here's a suggested refactor to improve test coverage:

@Test
public void testNamespaceExportImportWithFillItemDetail() throws FileNotFoundException {
    // ... (existing setup code)

    // Test with fillItemDetail = true
    testExportImportScenario(true);

    // Test with fillItemDetail = false
    testExportImportScenario(false);
}

private void testExportImportScenario(boolean fillItemDetail) throws FileNotFoundException {
    // ... (existing test logic)

    when(namespaceService.findNamespaceBOs(appId1, Env.DEV, clusterName1, fillItemDetail, false)).thenReturn(app1Cluster1Namespace);
    when(namespaceService.findNamespaceBOs(appId1, Env.DEV, clusterName2, fillItemDetail, false)).thenReturn(app1Cluster2Namespace);
    when(namespaceService.findNamespaceBOs(appId2, Env.DEV, clusterName1, fillItemDetail, false)).thenReturn(app2Cluster1Namespace);
    when(namespaceService.findNamespaceBOs(appId2, Env.DEV, clusterName2, fillItemDetail, false)).thenReturn(app2Cluster2Namespace);

    // ... (rest of the test logic)

    // Add assertions to verify behavior based on fillItemDetail value
    verify(namespaceService, times(4)).findNamespaceBOs(any(), any(), any(), eq(fillItemDetail), eq(false));
    // Add more specific assertions based on expected behavior when fillItemDetail is true vs false
}

This refactoring allows testing both scenarios and verifies that the fillItemDetail parameter is correctly passed to the findNamespaceBOs method.

@dosubot dosubot bot added size:XS This PR changes 0-9 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Oct 21, 2024
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:XS This PR changes 0-9 lines, ignoring generated files. labels Oct 21, 2024
@youngzil
Copy link
Contributor Author

@nobodyiam This feature requires upgrading the Java SDK version to 2.4.0-SNAPSHOT. Can you help deploy Java SDK 2.4.0-SNAPSHOT to the Maven repository?

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 (1)
apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/ConfigsExportServiceTest.java (1)

Line range hint 96-164: Enhance testExportImportScenario to verify fillItemDetail behavior

While the testExportImportScenario method now includes the fillItemDetail parameter, it doesn't explicitly verify how this parameter affects the behavior. Consider adding assertions to check the differences when fillItemDetail is true vs false. For example:

  1. Verify that the namespaceService.findNamespaceBOs method is called with the correct fillItemDetail value.
  2. If possible, add assertions to check if the exported/imported data differs based on the fillItemDetail value.

Additionally, the test setup is quite complex. Consider refactoring it into smaller, more focused helper methods to improve readability and maintainability.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 71f9fa0 and 01defd2.

📒 Files selected for processing (1)
  • apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/ConfigsExportServiceTest.java (2 hunks)
🧰 Additional context used
🔇 Additional comments (3)
apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/ConfigsExportServiceTest.java (3)

86-94: Improved test coverage for the fillItemDetail parameter

The addition of two separate test methods, testNamespaceExportImport and testNamespaceExportImportWithFillItemDetail, addresses the previous review comment about enhancing test coverage for the new fillItemDetail parameter. These methods test both scenarios (true and false) for the parameter.


161-164: Clarify the purpose of the second boolean parameter in findNamespaceBOs

The namespaceService.findNamespaceBOs method calls now include two boolean parameters, with the second one hardcoded to false. Could you please clarify:

  1. What does this second boolean parameter represent?
  2. Why is it always set to false in these test cases?
  3. Should we consider adding test cases where this parameter is set to true?

Understanding the purpose of this parameter will help ensure comprehensive test coverage.


Line range hint 1-324: Overall improvements to test coverage, with minor suggestions

The changes in this file successfully address the main objectives of the PR by adding support for controlling whether to fill item details when retrieving namespace data. The test coverage has been improved with the addition of separate test methods for different fillItemDetail values.

To further enhance the tests:

  1. Consider adding explicit assertions to verify the behavior differences when fillItemDetail is true vs false.
  2. Clarify the purpose of the second boolean parameter in the findNamespaceBOs method calls.
  3. Refactor the complex test setup in testExportImportScenario into smaller, more focused helper methods to improve readability and maintainability.

These minor improvements will ensure that the new functionality is thoroughly tested and the code remains maintainable.

@nobodyiam
Copy link
Member

@nobodyiam This feature requires upgrading the Java SDK version to 2.4.0-SNAPSHOT. Can you help deploy Java SDK 2.4.0-SNAPSHOT to the Maven repository?

It's uploaded now.

https://oss.sonatype.org/content/repositories/snapshots/com/ctrip/framework/apollo/apollo-openapi/2.4.0-SNAPSHOT/

@nobodyiam nobodyiam force-pushed the feature/query_namespace_support_not_fill_item branch from 01defd2 to ad860c8 Compare October 26, 2024 13:14
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 (7)
apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/server/service/ServerNamespaceOpenApiService.java (2)

71-74: Add JavaDoc for the new parameter.

The implementation looks good, but consider adding JavaDoc to document the purpose and impact of the fillItemDetail parameter. This would help API consumers understand the performance implications of their parameter choice.

Add documentation like this:

+ /**
+  * Get namespaces for the given app, env and cluster.
+  * @param appId The application ID
+  * @param env The environment
+  * @param clusterName The cluster name
+  * @param fillItemDetail If true, includes all item details in the response. 
+  *                      Set to false for better performance when item details aren't needed.
+  * @return List of OpenNamespaceDTO containing the requested namespace information
+  */

61-74: Consider adding metrics for performance monitoring.

To quantify the impact of this optimization and help tune default values, consider adding metrics to track:

  1. Usage frequency of fillItemDetail=true vs false
  2. Response time differences between filled and unfilled requests
  3. Resource utilization patterns for both cases

This data would be valuable for:

  • Validating the performance improvement
  • Understanding usage patterns
  • Making informed decisions about default values
  • Identifying further optimization opportunities
apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/NamespaceServiceTest.java (2)

Line range hint 268-273: LGTM! Consider adding edge case tests.

The test case effectively validates the new fillItemDetail parameter by comparing the behavior with and without deleted items. The assertions properly verify both item counts and key presence.

Consider adding test cases for edge scenarios:

  • When the namespace has no items
  • When all items are deleted
  • When the namespace doesn't exist

Line range hint 268-273: Enhance test coverage for boolean parameters.

The test should cover all combinations of the boolean parameters to ensure complete functionality validation:

  1. Rename the test method to better describe the test scenarios (e.g., testLoadNamespaceBOWithItemDetailControl)
  2. Add test cases for all parameter combinations:
// Test all combinations
@Test
public void testLoadNamespaceBOWithItemDetailControl() {
    // Existing tests...
    
    // Test includeDeleted=false scenarios
    NamespaceBO namespaceBO3 = namespaceService.loadNamespaceBO(testAppId, testEnv, testClusterName, testNamespaceName, false, false);
    // Add assertions
    
    NamespaceBO namespaceBO4 = namespaceService.loadNamespaceBO(testAppId, testEnv, testClusterName, testNamespaceName, false, true);
    // Add assertions
    
    // Test second parameter variations
    NamespaceBO namespaceBO5 = namespaceService.loadNamespaceBO(testAppId, testEnv, testClusterName, testNamespaceName, true, true);
    // Add assertions
}
  1. Add Javadoc comments explaining the purpose of each boolean parameter
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceService.java (3)

Line range hint 189-232: LGTM! Consider documenting performance characteristics.

The implementation correctly handles the new fillItemDetail parameter while maintaining thread safety. The parallel processing approach is appropriate for handling multiple namespaces.

Consider adding a comment documenting that processing time may vary significantly based on the fillItemDetail parameter, which could affect the parallel execution characteristics.


Line range hint 296-312: LGTM! Consider adding debug logging.

The early return optimization when fillItemDetail is false is well-placed and maintains the necessary base properties. This effectively achieves the performance optimization goal.

Consider adding debug-level logging before the early return to help with monitoring and debugging:

    if (!fillItemDetail) {
+     LOGGER.debug("Skipping item details for namespace: {}", namespace.getNamespaceName());
      return namespaceBO;
    }

232-232: LGTM! Consider enhancing method documentation.

The overloaded methods correctly maintain backward compatibility by defaulting fillItemDetail to true.

Consider adding Javadoc to document the behavior of the fillItemDetail parameter:

/**
 * Loads namespace business object with configurable item detail population.
 * @param fillItemDetail when true, populates all item details; when false, skips item details for better performance
 */

Also applies to: 263-263, 354-354

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 01defd2 and ad860c8.

📒 Files selected for processing (8)
  • apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/server/service/ServerNamespaceOpenApiService.java (1 hunks)
  • apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/NamespaceController.java (2 hunks)
  • apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ConfigsExportController.java (1 hunks)
  • apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ConfigsExportService.java (1 hunks)
  • apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/NamespaceService.java (7 hunks)
  • apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/ConfigsExportServiceTest.java (2 hunks)
  • apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/NamespaceServiceTest.java (1 hunks)
  • pom.xml (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/v1/controller/NamespaceController.java
  • apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/controller/ConfigsExportController.java
  • apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/service/ConfigsExportService.java
  • apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/ConfigsExportServiceTest.java
  • pom.xml
🔇 Additional comments (1)
apollo-portal/src/main/java/com/ctrip/framework/apollo/openapi/server/service/ServerNamespaceOpenApiService.java (1)

61-63: LGTM! Verify consistent parameter usage across callers.

The addition of the fillItemDetail parameter aligns well with the performance optimization goals, allowing clients to control whether item details are loaded.

Let's verify that all callers of this method are updated with the new parameter:

✅ Verification successful

Based on the previous search results, I can now provide a final response as we have found the key evidence:

✅ Parameter usage is correctly implemented across the codebase

The search results show that:

  1. The getNamespace method in ServerNamespaceOpenApiService is called by NamespaceController with the correct fillItemDetail parameter
  2. The controller sets a default value of true for the parameter via @RequestParam(defaultValue="true")
  3. There are no other direct calls to this method in the codebase
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for direct calls to getNamespace to ensure they include the new parameter
ast-grep --pattern 'getNamespace($_, $_, $_, $_, $_)'

Length of output: 55


Script:

#!/bin/bash
# Let's try a more comprehensive search for getNamespace method calls
rg "getNamespace\(" -A 2 -B 2

# Also search for the class usage to understand the context
rg "ServerNamespaceOpenApiService" -A 2 -B 2

Length of output: 14486


Script:

#!/bin/bash
# Let's search for the interface definition and its usages
rg "interface NamespaceOpenApiService" -A 5 -B 2

# Also search for the controller that uses this service to see the API endpoint
rg "class NamespaceController.*getNamespace" -A 10 -B 2

Length of output: 108

…t_not_fill_item' into feature/query_namespace_support_not_fill_item
Copy link

codecov bot commented Oct 26, 2024

Codecov Report

Attention: Patch coverage is 38.46154% with 8 lines in your changes missing coverage. Please review.

Project coverage is 51.21%. Comparing base (f55b419) to head (fce6ad1).
Report is 15 commits behind head on master.

Files with missing lines Patch % Lines
...mework/apollo/portal/service/NamespaceService.java 57.14% 2 Missing and 1 partial ⚠️
.../server/service/ServerNamespaceOpenApiService.java 0.00% 2 Missing ⚠️
...llo/openapi/v1/controller/NamespaceController.java 0.00% 2 Missing ⚠️
...llo/portal/controller/ConfigsExportController.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #5249      +/-   ##
============================================
+ Coverage     50.30%   51.21%   +0.91%     
- Complexity     2013     2098      +85     
============================================
  Files           388      393       +5     
  Lines         12228    12440     +212     
  Branches       1209     1230      +21     
============================================
+ Hits           6151     6371     +220     
+ Misses         5712     5681      -31     
- Partials        365      388      +23     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

🧹 Outside diff range and nitpick comments (1)
CHANGES.md (1)

18-18: Enhance the changelog entry with more details.

The current description could be more informative about the feature's purpose and benefits. Consider expanding it to better communicate the value to users.

Consider this improved description:

-* [Feature: openapi query namespace support not fill item](https://github.com/apolloconfig/apollo/pull/5249)
+* [Feature: Add optional item detail loading for namespace queries in OpenAPI to improve performance](https://github.com/apolloconfig/apollo/pull/5249)
🧰 Tools
🪛 Markdownlint

18-18: null
Spaces inside link text

(MD039, no-space-in-links)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between ad860c8 and fce6ad1.

📒 Files selected for processing (2)
  • CHANGES.md (1 hunks)
  • apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/ConfigsExportServiceTest.java (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/ConfigsExportServiceTest.java
🧰 Additional context used
🪛 Markdownlint
CHANGES.md

18-18: null
Spaces inside link text

(MD039, no-space-in-links)

CHANGES.md Outdated Show resolved Hide resolved
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Oct 27, 2024
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

🧹 Outside diff range and nitpick comments (2)
apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/NamespaceServiceTest.java (2)

230-237: Consider renaming test method for clarity.

The test effectively verifies namespace loading with item details. However, the method name could be more descriptive.

Consider renaming to testLoadNamespaceBOWithItemDetail to better reflect the test scenario:

-  public void testLoadNamespaceBO() {
+  public void testLoadNamespaceBOWithItemDetail() {

Line range hint 247-287: Refactor helper method to improve test maintainability.

The current implementation has several issues:

  1. Contains assertions within a helper method, which is unconventional
  2. Extensive use of any() matchers reduces test specificity
  3. Mixing setup with assertions reduces method reusability

Consider splitting into two methods:

private void setupNamespaceBoMocks(boolean fillItemDetail) {
    // Move all mock setup here
    // Use specific matchers instead of any()
    when(namespaceAPI.loadNamespace(eq(testAppId), eq(testEnv), 
        eq(testClusterName), eq(testNamespaceName))).thenReturn(namespaceDTO);
    // ... other mocks
}

private NamespaceBO loadNamespaceBO(boolean fillItemDetail) {
    setupNamespaceBoMocks(fillItemDetail);
    return namespaceService.loadNamespaceBO(testAppId, testEnv, 
        testClusterName, testNamespaceName, fillItemDetail, false);
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between fce6ad1 and 9a02b6f.

📒 Files selected for processing (2)
  • CHANGES.md (1 hunks)
  • apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/NamespaceServiceTest.java (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • CHANGES.md
🔇 Additional comments (1)
apollo-portal/src/test/java/com/ctrip/framework/apollo/portal/service/NamespaceServiceTest.java (1)

239-245: LGTM! Clear and focused test case.

The test effectively verifies that no items are returned when fillItemDetail is false.

Copy link
Member

@nobodyiam nobodyiam left a comment

Choose a reason for hiding this comment

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

LGTM

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Nov 2, 2024
@nobodyiam nobodyiam merged commit fe0ac3d into apolloconfig:master Nov 2, 2024
7 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Nov 2, 2024
@youngzil youngzil deleted the feature/query_namespace_support_not_fill_item branch November 2, 2024 11:53
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
2 participants