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(biz): Added the value length limit function for AppId-level configuration items #5264

Conversation

youngzil
Copy link
Contributor

@youngzil youngzil commented Oct 27, 2024

What's the purpose of this PR

  • Added the appid.value.length.limit.override configuration to control the value length limit at the AppId level
  • Modified the namespace.value.length.limit.override configuration to override the AppId-level limit
  • Updated the length limit check logic in ItemService to support limits at both the AppId and Namespace levels
  • Added test cases for new features in unit tests

Which issue(s) this PR fixes:

Fixes #5254

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

Release Notes for Apollo Version 2.4.0

  • New Features

    • Introduced value length limit function for AppId-level configuration items.
    • Enhanced global search capabilities for administrators.
    • Added caching record stats function for improved performance.
    • Support for dynamic configuration of the refresh interval for admin server addresses.
    • Detailed configuration options for limiting the length of keys and values based on app IDs and namespaces.
  • Bug Fixes

    • Resolved issues with duplicate comments and blank lines in configuration management.
    • Fixed missing items in the published namespace link.
  • Documentation

    • Updated distributed deployment guide with detailed instructions for configuration and deployment processes, including Docker and Kubernetes setups.

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Oct 27, 2024
Copy link
Contributor

coderabbitai bot commented Oct 27, 2024

Walkthrough

The changes introduced in this pull request encompass enhancements to the Apollo Configuration Center, including the addition of a value length limit function for AppId-level configuration items. Updates include improved server configuration links, REST template client connection pooling, and global search capabilities for administrators. Several fixes address issues with duplicate comments and blank lines. The modifications also enhance the BizConfig and ItemService classes to better manage namespace and AppId configurations, alongside updates to documentation for clearer deployment instructions.

Changes

File Change Summary
CHANGES.md Added entry for new feature on value length limit for AppId-level configurations, updated server configuration links, and documented several fixes and enhancements.
apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/config/BizConfig.java Added methods for AppId and namespace value length limit overrides, removed an existing method for namespace limits, and introduced a static type reference for deserialization.
apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ItemService.java Updated methods to use Namespace objects instead of long IDs for item value length checks, enhancing clarity and efficiency.
apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/config/BizConfigTest.java Added new test for appIdValueLengthLimitOverride method, including various input scenarios and error handling.
apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/ItemServiceTest.java Enhanced test setup with additional dependencies, modified existing tests, and added new tests for item saving with value length limit overrides.
docs/en/deployment/distributed-deployment-guide.md Updated deployment guide with detailed configuration instructions, including MySQL version requirements and Docker/Kubernetes deployment examples.
docs/zh/deployment/distributed-deployment-guide.md Similar updates to the Chinese version of the deployment guide, enhancing clarity and detail on deployment processes and configurations.

Assessment against linked issues

Objective Addressed Explanation
Provide AppId-level parameter to skip value length checks (#5254)
Enhance configuration management for value length limits (#5254)

Possibly related PRs

Suggested labels

lgtm

Suggested reviewers

  • nobodyiam

Poem

🐇 In the garden where configs grow,
Length limits now set to flow.
AppId whispers, "Let me be free,"
With namespaces dancing in harmony.
Updates and fixes, all in a row,
Apollo's magic, watch it glow! 🌟


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

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

87-110: Consider adding positive test cases for namespace value length limits.

While the error case is well tested, consider adding a positive test case where the value length is within the limit to ensure the validation logic works correctly in both scenarios.

Example addition:

@Test
public void testSaveItemWithValidNamespaceValueLength() {
    long namespaceId = 1L;
    String itemValue = "test-demo";
    
    Map<Long, Integer> namespaceValueLengthOverride = new HashMap<>();
    namespaceValueLengthOverride.put(namespaceId, itemValue.length() + 1);
    when(bizConfig.namespaceValueLengthLimitOverride()).thenReturn(namespaceValueLengthOverride);
    when(bizConfig.itemKeyLengthLimit()).thenReturn(100);
    
    Item item = createTestItem(namespaceId, itemValue);
    Item savedItem = itemService2.save(item);
    Assert.assertEquals(itemValue, savedItem.getValue());
}

115-139: Consider adding edge cases for AppId value length limits.

The current test covers the basic error case. Consider adding tests for:

  1. Edge case where value length equals the limit
  2. Case where both namespace and AppId limits are configured

Example addition:

@Test
public void testSaveItemWithExactAppIdValueLength() {
    String appId = "testApp";
    long namespaceId = 1L;
    String itemValue = "test-demo";
    
    Map<String, Integer> appIdValueLengthOverride = new HashMap<>();
    appIdValueLengthOverride.put(appId, itemValue.length());
    when(bizConfig.appIdValueLengthLimitOverride()).thenReturn(appIdValueLengthOverride);
    when(bizConfig.itemKeyLengthLimit()).thenReturn(100);
    
    Item item = createTestItem(namespaceId, itemValue);
    Item savedItem = itemService2.save(item);
    Assert.assertEquals(itemValue, savedItem.getValue());
}
apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ItemService.java (2)

Line range hint 238-242: Fix incorrect namespace parameter in parent limit calculation.

There's a bug in the parent limit calculation. The method is passing grayNamespace to getItemValueLengthLimit instead of parentNamespace, which could result in incorrect limit calculation for gray namespaces.

Apply this fix:

-      int parentLimit = getItemValueLengthLimit(grayNamespace);
+      int parentLimit = getItemValueLengthLimit(parentNamespace);

260-271: LGTM! Well-structured hierarchical configuration.

The implementation follows a clear precedence order (namespace > appId > default) and includes proper null checks. This aligns well with the PR objectives of supporting both namespace and AppId-level configurations.

Consider documenting this precedence order in the configuration documentation to help users understand how the limits are applied.

For future scalability, consider:

  1. Extracting the configuration hierarchy logic into a separate strategy class if more levels are added in the future
  2. Adding metrics/logging to track which configuration level is being used, helping administrators understand the actual usage patterns
docs/zh/deployment/distributed-deployment-guide.md (1)

1486-1488: Add language specifier to the code block.

The code block should specify the language for proper syntax highlighting.

Apply this change:

-```
+```json
 appid.value.length.limit.override = {appId-demo1:200,aappId-demo2:300}

<details>
<summary>🧰 Tools</summary>

<details>
<summary>🪛 Markdownlint</summary><blockquote>

1486-1486: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

</blockquote></details>

</details>

</blockquote></details>
<details>
<summary>docs/en/deployment/distributed-deployment-guide.md (1)</summary><blockquote>

`1545-1547`: **Add language specification to the code block**

The code block should specify the language for better syntax highlighting and documentation consistency.

```diff
-```
+```json
 {appId-demo1:200,aappId-demo2:300}

<details>
<summary>🧰 Tools</summary>

<details>
<summary>🪛 Markdownlint</summary><blockquote>

1545-1545: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

</blockquote></details>

</details>

</blockquote></details>

</blockquote></details>

<details>
<summary>📜 Review details</summary>

**Configuration used: CodeRabbit UI**
**Review profile: CHILL**

<details>
<summary>📥 Commits</summary>

Files that changed from the base of the PR and between ced6383de19b7cf4e37ab68ab8babcde7a9cbbba and 6ab0caa721b58e9a4539e87802313ceaa3a94bd4.

</details>

<details>
<summary>📒 Files selected for processing (7)</summary>

* CHANGES.md (1 hunks)
* apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/config/BizConfig.java (2 hunks)
* apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ItemService.java (3 hunks)
* apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/config/BizConfigTest.java (3 hunks)
* apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/ItemServiceTest.java (3 hunks)
* docs/en/deployment/distributed-deployment-guide.md (1 hunks)
* docs/zh/deployment/distributed-deployment-guide.md (1 hunks)

</details>

<details>
<summary>🧰 Additional context used</summary>

<details>
<summary>🪛 Markdownlint</summary><blockquote>

<details>
<summary>docs/en/deployment/distributed-deployment-guide.md</summary><blockquote>

1545-1545: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

</blockquote></details>
<details>
<summary>docs/zh/deployment/distributed-deployment-guide.md</summary><blockquote>

1486-1486: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

</blockquote></details>

</blockquote></details>

</details>

<details>
<summary>🔇 Additional comments (11)</summary><blockquote>

<details>
<summary>CHANGES.md (1)</summary><blockquote>

`18-18`: **LGTM! The changelog entry is well-formatted and accurately describes the feature.**

The entry follows the established format and clearly communicates the addition of the AppId-level value length limit function, properly linking to PR #5264.

</blockquote></details>
<details>
<summary>apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/config/BizConfigTest.java (2)</summary><blockquote>

`21-22`: **LGTM: Import statements are appropriate.**

The added imports support the new test functionality for JSON parsing and map operations.

---

`112-143`: **LGTM: Comprehensive test coverage for AppId value length limit override.**

The test method effectively covers essential scenarios including null config, empty JSON, invalid JSON, and both single and multiple AppId overrides.

</blockquote></details>
<details>
<summary>apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/ItemServiceTest.java (2)</summary><blockquote>

`43-58`: **LGTM! Clean setup with proper dependency injection.**

The setup properly initializes all required dependencies and creates a separate ItemService instance for testing the new configuration features.

---

`61-65`: **Verify the namespaceId change impact.**

The namespaceId has been changed from 3 to 1. Please ensure this aligns with the test data in the new `namespace-test.sql` script.

<details>
<summary>✅ Verification successful</summary>

**The namespaceId change to 1 is correct and verified**

The change from namespaceId 3 to 1 is valid as the test data in `namespace-test.sql` shows:
- A namespace with ID 1 is explicitly created: `INSERT INTO "Namespace" (`Id`, `AppId`,...) VALUES(1,'testApp',...)`
- This namespace is referenced in both test files:
  - `namespace-test.sql` has an item with `NamespaceId=1`
  - `item-test.sql` has a test item with `NamespaceId=1`



</details>

<details>
<summary>🏁 Scripts executed</summary>

The following scripts were executed for the analysis:

Script:

```shell
#!/bin/bash
# Check if namespace with ID 1 exists in the test SQL
rg -A 5 "INSERT.*INTO.*namespace.*1[,)]" apollo-biz/src/test/resources/sql/namespace-test.sql

Length of output: 95


Script:

#!/bin/bash
# Let's first check if the file exists and see its content
cat apollo-biz/src/test/resources/sql/namespace-test.sql

# Also check item-test.sql as it's used together
cat apollo-biz/src/test/resources/sql/item-test.sql

# Let's also search for any namespace with ID 1 in all SQL files
rg "INSERT.*namespace.*1[,)]" apollo-biz/src/test/resources/sql/

Length of output: 4078

apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ItemService.java (1)

Line range hint 221-233: LGTM! Verify gray namespace handling.

The changes correctly support the new AppId-level configuration while maintaining existing gray namespace functionality. The code properly retrieves the value length limit using the new hierarchical approach.

Let's verify the gray namespace handling:

✅ Verification successful

Gray namespace handling is correctly implemented

The verification confirms that:

  • The gray namespace pattern [0-9]{14}-[a-zA-Z0-9]{16} is uniquely defined in ItemService and consistently used
  • The gray namespace value length limit logic is properly handled through getGrayNamespaceItemValueLengthLimit which:
    • Checks for parent namespace limits
    • Returns the higher limit between gray and parent namespace
  • The implementation aligns with the gray release functionality in the portal module
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if there are any other gray namespace patterns or special cases in the codebase
# that might need similar handling

# Search for cluster pattern usage
rg -A 3 'clusterPattern' --type java

# Search for gray namespace related code
rg -A 5 'isGray|grayNamespace|GrayNamespace' --type java

Length of output: 7319

apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/config/BizConfig.java (2)

61-63: LGTM: Type reference declaration follows established patterns

The new type reference for AppId value length override is properly implemented using TypeToken for type safety, consistent with existing patterns in the codebase.


112-132: Verify configuration override precedence and integration

The implementation addresses the requirements from issue #5254, but we should verify:

  1. The interaction between AppId and Namespace level overrides
  2. The configuration loading and refresh behavior
  3. The error scenarios and edge cases

Let's verify the configuration usage:

✅ Verification successful

Let's examine the test coverage and implementation details more thoroughly.


Configuration override implementation is properly integrated and tested

The implementation is well-structured with:

  1. Correct precedence handling in ItemService - namespace-level overrides take precedence over app-level overrides
  2. Comprehensive test coverage including:
    • Empty/invalid configuration scenarios
    • Single and multiple override entries
    • JSON parsing error handling
    • Integration with ItemService validation logic

The code successfully addresses the requirements from issue #5254 with proper validation, error handling, and precedence rules.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for usage of these configuration methods
echo "Searching for configuration usage..."
rg -l "appIdValueLengthLimitOverride|namespaceValueLengthLimitOverride" --type java

# Search for test coverage
echo "Checking test coverage..."
rg -l "appid\.value\.length\.limit\.override|namespace\.value\.length\.limit\.override" --type java --glob "*Test.java"

Length of output: 759


Script:

#!/bin/bash
# Check ItemService implementation for usage context
echo "Checking ItemService implementation..."
rg -A 10 "appIdValueLengthLimitOverride|namespaceValueLengthLimitOverride" apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ItemService.java

# Check test implementations
echo "Checking test implementations..."
rg -A 10 "appIdValueLengthLimitOverride|namespaceValueLengthLimitOverride" apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/config/BizConfigTest.java
rg -A 10 "appIdValueLengthLimitOverride|namespaceValueLengthLimitOverride" apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/ItemServiceTest.java

Length of output: 3879

docs/zh/deployment/distributed-deployment-guide.md (2)

1484-1492: LGTM: Clear documentation for AppId-level value length limit configuration.

The documentation clearly explains:

  • The purpose and scope of appid.value.length.limit.override
  • The JSON format for configuration
  • The inheritance behavior for new namespaces
🧰 Tools
🪛 Markdownlint

1486-1486: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)


1493-1495: LGTM: Clear documentation for Namespace-level value length limit configuration.

The documentation effectively describes:

  • The purpose of namespace.value.length.limit.override
  • The override behavior for both global and AppId-level configurations
  • The JSON format using namespace IDs
docs/en/deployment/distributed-deployment-guide.md (1)

1542-1554: LGTM! Clear and well-structured documentation for the new configuration items.

The documentation clearly explains:

  1. The purpose and behavior of the new configuration items
  2. The inheritance relationship between different configuration levels
  3. Provides clear examples for better understanding
🧰 Tools
🪛 Markdownlint

1545-1545: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

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

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

78-97: Add positive test case for namespace value length limit.

The current test only covers the error case when the value exceeds the limit. Consider adding a test case where the value length is within the limit to ensure the override works correctly in both scenarios.

Would you like me to help generate the additional test case?


99-120: Add positive test case and edge cases for AppId value length limit.

While the error case is covered, consider adding:

  1. A positive test case where the value length is within the limit
  2. Edge cases testing the interaction between namespace and AppId-level limits

Would you like me to help generate these additional test cases?

apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/config/BizConfig.java (1)

258-271: Consider enhancing type safety in parseOverrideConfig

The helper method is well-implemented with proper error handling, filtering, and immutability. However, the type casting could be made more robust.

Consider this enhancement:

 private <K, V> Map<K, V> parseOverrideConfig(String configValue, Type typeReference) {
   Map<K, V> result = Maps.newHashMap();
   if (!Strings.isNullOrEmpty(configValue)) {
     try {
       Map<K, V> parsed = GSON.fromJson(configValue, typeReference);
       result = parsed.entrySet().stream()
-          .filter(e -> e.getValue() != null && ((Integer) e.getValue()) > 0)
+          .filter(e -> e.getValue() != null && 
+              (e.getValue() instanceof Integer) && 
+              ((Integer) e.getValue()) > 0)
           .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
     } catch (Exception e) {
       logger.error("Invalid override config value: {}", configValue, e);
     }
   }
   return Collections.unmodifiableMap(result);
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 6ab0caa and c380c91.

📒 Files selected for processing (3)
  • apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/config/BizConfig.java (5 hunks)
  • apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/config/BizConfigTest.java (3 hunks)
  • apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/ItemServiceTest.java (4 hunks)
🔇 Additional comments (6)
apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/service/ItemServiceTest.java (3)

Line range hint 19-58: LGTM! Well-structured test setup.

The setup properly initializes both the real and mocked dependencies needed for testing the new value length limit functionality.


157-166: LGTM! Well-implemented helper method.

The createItem helper method effectively reduces code duplication and improves test maintainability, addressing the previous review feedback.


Line range hint 1-167: Verify complete test coverage across the codebase.

Let's ensure all related components have appropriate test coverage.

✅ Verification successful

Test coverage is comprehensive and properly implemented

The test coverage for value length limit functionality is complete and well-structured across the codebase:

  • BizConfigTest thoroughly tests the AppId value length limit override functionality with:
    • Empty/null configuration cases
    • Invalid JSON handling
    • Single and multiple AppId overrides
    • Edge cases (zero and negative values)
  • ItemServiceTest covers both namespace-level and AppId-level value length limit validations
  • The implementation in ItemService correctly cascades through namespace override, AppId override, and default limit checks

The test coverage adequately verifies all aspects of the value length limit feature, including configuration parsing, validation logic, and error handling.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for other test files that might need updates for the new functionality

# Look for test files that might need coverage for the new AppId-level configuration
echo "Searching for related test files..."
fd -e java -e groovy -e scala test --exec rg -l "BizConfig|ItemService|namespace\.value\.length\.limit|appid\.value\.length\.limit"

# Look for configuration test files
echo "Searching for configuration test files..."
fd -e properties -e yaml -e xml test --exec rg -l "value\.length\.limit"

Length of output: 3199


Script:

#!/bin/bash
# Let's check the BizConfig and ItemService test coverage more specifically

# Check BizConfigTest for value length limit configurations
echo "Checking BizConfigTest coverage:"
rg -A 10 "namespaceValueLengthLimitOverride|appIdValueLengthLimitOverride" ./apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/config/BizConfigTest.java

# Check ItemService implementations for value length limit validations
echo -e "\nChecking ItemService implementations:"
rg -A 5 "namespaceValueLengthLimitOverride|appIdValueLengthLimitOverride" ./apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/service/ItemService.java

# Check for any other potential test files with value length validations
echo -e "\nChecking other potential test files:"
rg -A 5 "value.*length.*limit" ./apollo-biz/src/test/java/

Length of output: 7357

apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/config/BizConfig.java (3)

34-35: LGTM: Logger and type reference additions are well-structured

The logger implementation and type reference follow the established patterns in the codebase.

Also applies to: 41-42, 65-67


204-204: LGTM: Consistent use of parseOverrideConfig

The refactoring to use the common helper method improves code maintainability.


116-124: LGTM: Override configuration methods align with requirements

The implementation properly supports both AppId and Namespace level value length limit configurations as requested in issue #5254. The methods maintain consistency with the existing configuration patterns while adding the new AppId-level functionality.

Let's verify the configuration key names are used consistently across the codebase:

✅ Verification successful

Configuration keys are used consistently across the codebase

The verification confirms that both configuration keys are used consistently:

  • appid.value.length.limit.override is properly documented in deployment guides (both English and Chinese) with correct format examples
  • namespace.value.length.limit.override is also well documented with proper usage examples
  • Both keys are correctly used in the implementation (BizConfig.java) and have corresponding test coverage (BizConfigTest.java)
  • The documentation clearly explains the override hierarchy between these configurations
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for references to the configuration keys
echo "Searching for appid.value.length.limit.override usage:"
rg "appid\.value\.length\.limit\.override"

echo -e "\nSearching for namespace.value.length.limit.override usage:"
rg "namespace\.value\.length\.limit\.override"

Length of output: 3947

Comment on lines 110 to 144
@Test
public void testAppIdValueLengthLimitOverride() {
when(environment.getProperty("appid.value.length.limit.override")).thenReturn(null);
Map<String, Integer> result = bizConfig.appIdValueLengthLimitOverride();
assertTrue(result.isEmpty());

String input = "{}";
when(environment.getProperty("appid.value.length.limit.override")).thenReturn(input);
result = bizConfig.appIdValueLengthLimitOverride();
assertTrue(result.isEmpty());

input = "invalid json";
when(environment.getProperty("appid.value.length.limit.override")).thenReturn(input);
result = bizConfig.appIdValueLengthLimitOverride();
assertTrue(result.isEmpty());

input = "{'appid1':555}";
when(environment.getProperty("appid.value.length.limit.override")).thenReturn(input);
int overrideValue = bizConfig.appIdValueLengthLimitOverride().get("appid1");
assertEquals(1, bizConfig.appIdValueLengthLimitOverride().size());
assertEquals(555, overrideValue);

input = "{'appid1':555,'appid2':666}";
when(environment.getProperty("appid.value.length.limit.override")).thenReturn(input);
overrideValue = bizConfig.appIdValueLengthLimitOverride().get("appid2");
assertEquals(2, bizConfig.appIdValueLengthLimitOverride().size());
assertEquals(666, overrideValue);

input = "{'appid1':555,'appid2':666,'appid3':0,'appid4':-1}";
when(environment.getProperty("appid.value.length.limit.override")).thenReturn(input);
overrideValue = bizConfig.appIdValueLengthLimitOverride().get("appid2");
assertEquals(2, bizConfig.appIdValueLengthLimitOverride().size());
assertEquals(666, overrideValue);

}
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

Improve test organization and documentation.

The test method is handling multiple scenarios which makes it harder to understand and maintain. Consider:

  1. Breaking down into separate focused test methods with clear @DisplayName annotations
  2. Adding Javadoc to document test scenarios
  3. Using constants for test values
  4. Using more realistic AppId examples

Example refactor:

@DisplayName("AppId value length limit override tests")
class AppIdValueLengthLimitTests {
    
    private static final String GATEWAY_APP_ID = "api-gateway";
    private static final int GATEWAY_LENGTH_LIMIT = 102400;
    
    @Test
    @DisplayName("Should return empty map for null config")
    void nullConfigReturnsEmptyMap() {
        when(environment.getProperty("appid.value.length.limit.override")).thenReturn(null);
        assertTrue(bizConfig.appIdValueLengthLimitOverride().isEmpty());
    }
    
    @Test
    @DisplayName("Should handle valid single entry")
    void validSingleEntry() {
        String input = String.format("{'%s':%d}", GATEWAY_APP_ID, GATEWAY_LENGTH_LIMIT);
        when(environment.getProperty("appid.value.length.limit.override")).thenReturn(input);
        
        Map<String, Integer> result = bizConfig.appIdValueLengthLimitOverride();
        assertEquals(1, result.size());
        assertEquals(GATEWAY_LENGTH_LIMIT, result.get(GATEWAY_APP_ID).intValue());
    }
    
    // Add more focused test methods...
}

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)
apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/config/BizConfigTest.java (1)

110-150: Good test coverage, but could be improved for maintainability.

The test method thoroughly covers the basic scenarios including null config, empty JSON, invalid JSON, and valid entries. However, consider improving maintainability by:

  1. Breaking down into focused test methods
  2. Using constants for test values
  3. Adding method documentation
  4. Using more realistic AppId examples (e.g., "api-gateway" instead of "appid1")

Example refactor:

private static final String GATEWAY_APP_ID = "api-gateway";
private static final int GATEWAY_LENGTH_LIMIT = 102400;

/**
 * Tests the AppId value length limit override functionality
 */
@Test
@DisplayName("Should handle null configuration")
public void testAppIdValueLengthLimitOverride_NullConfig() {
    when(environment.getProperty("appid.value.length.limit.override")).thenReturn(null);
    assertTrue(bizConfig.appIdValueLengthLimitOverride().isEmpty());
}

@Test
@DisplayName("Should handle valid configuration")
public void testAppIdValueLengthLimitOverride_ValidConfig() {
    String input = String.format("{'%s':%d}", GATEWAY_APP_ID, GATEWAY_LENGTH_LIMIT);
    when(environment.getProperty("appid.value.length.limit.override")).thenReturn(input);
    
    Map<String, Integer> result = bizConfig.appIdValueLengthLimitOverride();
    assertEquals(1, result.size());
    assertEquals(GATEWAY_LENGTH_LIMIT, result.get(GATEWAY_APP_ID).intValue());
}

// Additional test methods for other scenarios...
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between c380c91 and 2bb1e5f.

📒 Files selected for processing (1)
  • apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/config/BizConfigTest.java (3 hunks)
🔇 Additional comments (1)
apollo-biz/src/test/java/com/ctrip/framework/apollo/biz/config/BizConfigTest.java (1)

21-21: LGTM!

The Map import is required for the new test method.

Comment on lines +138 to +146
input = "{'appid1':555,'appid2':666,'appid3':0,'appid4':-1}";
when(environment.getProperty("appid.value.length.limit.override")).thenReturn(input);
result = bizConfig.appIdValueLengthLimitOverride();

assertTrue(result.containsKey("appid1"));
assertTrue(result.containsKey("appid2"));
assertFalse(result.containsKey("appid3"));
assertFalse(result.containsKey("appid4"));
assertEquals(2, result.size());
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

Add tests for boundary values.

While the test verifies filtering of invalid values (0, -1), it should also test boundary conditions:

@Test
@DisplayName("Should handle boundary values")
public void testAppIdValueLengthLimitOverride_Boundaries() {
    String input = String.format(
        "{'%s':1,'%s':%d,'%s':%d}",
        "min-app", "max-app", Integer.MAX_VALUE,
        "invalid-app", Integer.MIN_VALUE
    );
    when(environment.getProperty("appid.value.length.limit.override")).thenReturn(input);
    
    Map<String, Integer> result = bizConfig.appIdValueLengthLimitOverride();
    
    assertTrue(result.containsKey("min-app"));
    assertTrue(result.containsKey("max-app"));
    assertFalse(result.containsKey("invalid-app"));
    assertEquals(Integer.MAX_VALUE, result.get("max-app").intValue());
    assertEquals(1, result.get("min-app").intValue());
}

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 (3)
apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/config/BizConfig.java (1)

258-273: Consider enhancing type safety for numeric values.

The implementation is robust with good error handling and immutability. However, since this is primarily used for numeric limits, consider adding type bounds to prevent potential ClassCastException.

-  private <K, V> Map<K, V> parseOverrideConfig(String configValue, Type typeReference, Predicate<V> valueFilter) {
+  private <K, V extends Number> Map<K, V> parseOverrideConfig(String configValue, Type typeReference, Predicate<V> valueFilter) {
docs/zh/deployment/distributed-deployment-guide.md (1)

1486-1488: Add language specifier to the code block.

The code block should specify a language for better syntax highlighting.

-```
+```json
 appid.value.length.limit.override = {"appId-demo1":200,"appId-demo2":300}

<details>
<summary>🧰 Tools</summary>

<details>
<summary>🪛 Markdownlint</summary>

1486-1486: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

</details>

</details>

</blockquote></details>
<details>
<summary>docs/en/deployment/distributed-deployment-guide.md (1)</summary><blockquote>

`1545-1547`: **Add language specifier to the code block and use quotation marks in the example.**

The code block should specify a language and the JSON values should be quoted for better clarity.

```diff
-```
+```json
-appid.value.length.limit.override = {"appId-demo1":200,"appId-demo2":300}
+appid.value.length.limit.override = {"appId-demo1": "200", "appId-demo2": "300"}
🧰 Tools
🪛 Markdownlint

1545-1545: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 2bb1e5f and f4b4e9b.

📒 Files selected for processing (4)
  • CHANGES.md (1 hunks)
  • apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/config/BizConfig.java (5 hunks)
  • docs/en/deployment/distributed-deployment-guide.md (1 hunks)
  • docs/zh/deployment/distributed-deployment-guide.md (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • CHANGES.md
🧰 Additional context used
🪛 Markdownlint
docs/en/deployment/distributed-deployment-guide.md

1545-1545: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

docs/zh/deployment/distributed-deployment-guide.md

1486-1486: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

🔇 Additional comments (7)
apollo-biz/src/main/java/com/ctrip/framework/apollo/biz/config/BizConfig.java (4)

33-35: LGTM: Logger and imports are appropriate.

The new imports and logger field are correctly added to support the new functionality.

Also applies to: 41-42


65-67: LGTM: Type reference is properly defined.

The new type reference follows the existing pattern and correctly defines the type for AppId value length overrides.


204-204: LGTM: Good reuse of common parsing logic.

The existing method has been updated to use the new parsing logic, reducing code duplication.


116-124: LGTM: Configuration override methods are well implemented.

The methods correctly implement the AppId and Namespace level value length limit overrides. Let's verify the configuration keys are documented.

✅ Verification successful

Both configuration keys are properly documented

The documentation in distributed-deployment-guide.md thoroughly covers both configuration keys:

  • appid.value.length.limit.override: Documented with format, purpose, and inheritance behavior
  • namespace.value.length.limit.override: Documented with format, purpose, and override precedence
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if the new configuration keys are documented
rg -l "appid\.value\.length\.limit\.override" --type md

Length of output: 159


Script:

#!/bin/bash
# Check content of documentation files to verify if both configuration keys are properly documented
rg "appid\.value\.length\.limit\.override|namespace\.value\.length\.limit\.override" docs/en/deployment/distributed-deployment-guide.md -A 2 -B 2

Length of output: 1690

docs/zh/deployment/distributed-deployment-guide.md (1)

1484-1495: Documentation looks good!

The new sections clearly explain the configuration options for value length limits at both AppId and Namespace levels. The documentation:

  • Clearly describes the purpose and format of each configuration
  • Provides good examples
  • Explains the inheritance and override behavior
🧰 Tools
🪛 Markdownlint

1486-1486: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)

docs/en/deployment/distributed-deployment-guide.md (2)

1542-1551: LGTM! Clear documentation for appId-level value length limit override.

The documentation clearly explains:

  • Purpose of the configuration
  • JSON format structure
  • Inheritance behavior for new namespaces
🧰 Tools
🪛 Markdownlint

1545-1545: null
Fenced code blocks should have a language specified

(MD040, fenced-code-language)


1552-1554: LGTM! Clear documentation for namespace-level value length limit override.

The documentation clearly explains:

  • Purpose of the configuration
  • Override behavior for both item.value.length.limit and appid.value.length.limit.override
  • JSON format structure using namespace IDs

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 3, 2024
@nobodyiam nobodyiam merged commit 2b31ac6 into apolloconfig:master Nov 3, 2024
7 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Nov 3, 2024
@youngzil youngzil deleted the feature/item-value-length-limit-for-appid branch November 3, 2024 13:35
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
Development

Successfully merging this pull request may close these issues.

能否新增通过appid的维度来跳过对Value长度的校验
2 participants