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

fix:RefreshAdminServerAddressTask supports dynamic configuration of time interval #5248

Conversation

youngzil
Copy link
Contributor

@youngzil youngzil commented Oct 7, 2024

…ime interval

What's the purpose of this PR

XXXXX

Which issue(s) this PR fixes:

Fixes #5245

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

  • New Features

    • Enhanced configurability for refresh intervals of admin server address tasks.
    • Added methods to retrieve dynamic refresh interval values from configuration settings.
    • Support for dynamic configuration of the RefreshAdminServerAddressTask time interval.
    • Improved server configuration links and global search capabilities for administrators.
    • Introduced connection pool configuration for the portal restTemplate client.
    • Implemented limits and whitelisting for namespace counts per appid+cluster.
    • Added a cache record stats function for ConfigService.
  • Bug Fixes

    • Improved validation for refresh interval values to ensure they fall within specified bounds.
    • Resolved issues related to duplicate comments and missing items in configuration management.
  • Refactor

    • Constructor of the AdminServiceAddressLocator class updated to include new configuration dependency.

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

coderabbitai bot commented Oct 7, 2024

Walkthrough

The changes involve modifications to the AdminServiceAddressLocator and PortalConfig classes within the Apollo portal. The AdminServiceAddressLocator class now includes a new dependency on PortalConfig, which allows for dynamic configuration of refresh intervals for admin server address tasks. The previous hardcoded constants for refresh intervals have been removed and replaced with method calls to PortalConfig. The PortalConfig class has been updated to include new methods for retrieving these intervals, along with validation logic for ensuring the values are within acceptable bounds.

Changes

File Change Summary
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/AdminServiceAddressLocator.java - Constructor updated to include PortalConfig.
- Removed constants NORMAL_REFRESH_INTERVAL and OFFLINE_REFRESH_INTERVAL.
- Replaced with method calls to portalConfig.
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/config/PortalConfig.java - Added methods refreshAdminServerAddressTaskNormalIntervalSecond() and refreshAdminServerAddressTaskOfflineIntervalSecond().
- Introduced validation method checkInt().
- Added constants for default refresh intervals.
CHANGES.md - Updated to reflect Apollo version 2.4.0 release notes, highlighting dynamic configuration for RefreshAdminServerAddressTask.

Assessment against linked issues

Objective Addressed Explanation
Dynamic adjustment of RefreshAdminServerAddressTask delay time (#5245)

Possibly related PRs

Suggested labels

lgtm

Poem

In the land of code where rabbits play,
New settings bloom, brightening the day.
Refresh intervals now dance with grace,
Configurable paths in a dynamic space.
Hopping along, we cheer and sing,
For changes like these make our hearts spring! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between b96466b and 9b0bc5c.

📒 Files selected for processing (1)
  • CHANGES.md (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • CHANGES.md

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 (2)
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/config/PortalConfig.java (2)

199-202: Consider increasing the minimum allowed interval

The method successfully implements configurable normal refresh intervals, which aligns with the PR objectives. However, the minimum allowed value of 5 milliseconds seems extremely low for a production environment.

Consider increasing the minimum value to a more reasonable duration, such as 1000 milliseconds (1 second) or higher, to prevent potential system stress from overly frequent refreshes.

-    return checkInt(interval, 5, Integer.MAX_VALUE, DEFAULT_REFRESH_ADMIN_SERVER_ADDRESS_TASK_NORMAL_INTERVAL_IN_MILLI);
+    return checkInt(interval, 1000, Integer.MAX_VALUE, DEFAULT_REFRESH_ADMIN_SERVER_ADDRESS_TASK_NORMAL_INTERVAL_IN_MILLI);

204-207: Consider increasing the minimum allowed interval for consistency

The method successfully implements configurable offline refresh intervals, aligning with the PR objectives. However, similar to the normal refresh interval, the minimum allowed value of 5 milliseconds is extremely low.

For consistency with the previous suggestion and to prevent potential system stress, consider increasing the minimum value to 1000 milliseconds (1 second) or higher.

-    return checkInt(interval, 5, Integer.MAX_VALUE, DEFAULT_REFRESH_ADMIN_SERVER_ADDRESS_TASK_OFFLINE_INTERVAL_IN_MILLI);
+    return checkInt(interval, 1000, Integer.MAX_VALUE, DEFAULT_REFRESH_ADMIN_SERVER_ADDRESS_TASK_OFFLINE_INTERVAL_IN_MILLI);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 94c28af and fa1b0de.

📒 Files selected for processing (2)
  • apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/AdminServiceAddressLocator.java (3 hunks)
  • apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/config/PortalConfig.java (3 hunks)
🧰 Additional context used
🔇 Additional comments (9)
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/config/PortalConfig.java (3)

46-47: LGTM: Default refresh interval constants added

The addition of these constants provides clear default values for the normal and offline refresh intervals. The chosen values (5 minutes for normal and 10 seconds for offline) seem reasonable for their respective scenarios.


321-326: LGTM: Helpful integer validation method added

The checkInt() method is a well-implemented utility for validating integer configuration values. It promotes code reuse and ensures consistent behavior across different configuration settings.


Line range hint 46-326: Summary: Successful implementation of configurable refresh intervals

The changes in this file successfully implement configurable refresh intervals for the RefreshAdminServerAddressTask, addressing the objectives outlined in the PR and the linked issue #5245. The implementation allows for dynamic configuration of both normal and offline refresh intervals, which should improve the handling of admin service addresses in multi-AZ disaster recovery scenarios.

Key points:

  1. Default constants are well-defined.
  2. New methods for retrieving configurable intervals are implemented correctly.
  3. A helper method for integer validation promotes code reuse and consistency.

Minor suggestions have been made to increase the minimum allowed interval values to prevent potential system stress from overly frequent refreshes. Overall, the implementation is solid and achieves the desired functionality.

apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/AdminServiceAddressLocator.java (6)

19-19: Import PortalConfig for dynamic configuration.

The import statement correctly adds PortalConfig to enable dynamic refresh intervals.


58-58: Add portalConfig as a final member variable.

Introducing portalConfig as a final member variable ensures it is immutable after initialization.


64-65: Update constructor to include PortalConfig.

The constructor now accepts PortalConfig portalConfig, allowing the class to access dynamic configurations.


70-70: Assign portalConfig within the constructor.

Assigning this.portalConfig = portalConfig; correctly initializes the member variable.


110-113: Handle scheduling failures appropriately.

If both refreshSuccess and currentEnvRefreshResult are false, the task schedules using the offline interval. Ensure that this logic aligns with the desired retry strategy when refreshes fail.

Please confirm that the retry mechanism after a failed refresh operates as intended.


110-113: Use dynamic refresh intervals from PortalConfig.

Replacing hardcoded constants with dynamic values from portalConfig enhances configurability. Ensure that refreshAdminServerAddressTaskNormalIntervalInMilli() and refreshAdminServerAddressTaskOfflineIntervalInMilli() provide valid intervals.

To confirm that these methods return appropriate values, consider running the following script:

✅ Verification successful

Verification Successful: Dynamic Refresh Intervals Confirmed

The methods refreshAdminServerAddressTaskNormalIntervalInMilli() and refreshAdminServerAddressTaskOfflineIntervalInMilli() are correctly implemented to return positive integers, ensuring dynamic configurability as intended.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the refresh intervals are correctly configured and greater than zero.

# Expect: The methods should return positive integers.

# Find method implementations and check default values.
rg --type java 'public.*refreshAdminServerAddressTaskNormalIntervalInMilli\(\)' -A 5
rg --type java 'public.*refreshAdminServerAddressTaskOfflineIntervalInMilli\(\)' -A 5

Length of output: 2171

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

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

15-15: LGTM with a minor suggestion for clarity.

The new changelog entry accurately reflects the feature introduced in this PR. It's correctly formatted and placed within the document.

For slightly improved clarity, consider rewording the entry as follows:

-* [RefreshAdminServerAddressTask supports dynamic configuration of time interval](https://github.com/apolloconfig/apollo/pull/5248)
+* [Feature: RefreshAdminServerAddressTask now supports dynamic configuration of refresh intervals](https://github.com/apolloconfig/apollo/pull/5248)

This minor change:

  1. Adds the "Feature:" prefix to match the style of other feature entries.
  2. Uses "refresh intervals" instead of "time interval" to more accurately describe the multiple intervals being made configurable (NORMAL_REFRESH_INTERVAL and OFFLINE_REFRESH_INTERVAL).
  3. Slightly rephrases for better readability.
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/config/PortalConfig.java (2)

199-202: Consider renaming method for clarity and consistency

The method name refreshAdminServerAddressTaskNormalIntervalSecond() could be clearer if renamed to getRefreshAdminServerAddressTaskNormalIntervalInSeconds(). This follows standard getter naming conventions and clearly indicates that the method returns a value in seconds.

Apply this diff to rename the method:

-public int refreshAdminServerAddressTaskNormalIntervalSecond() {
+public int getRefreshAdminServerAddressTaskNormalIntervalInSeconds() {

204-207: Consider renaming method for clarity and consistency

Similarly, consider renaming refreshAdminServerAddressTaskOfflineIntervalSecond() to getRefreshAdminServerAddressTaskOfflineIntervalInSeconds() to maintain consistency and clarity in method naming.

Apply this diff to rename the method:

-public int refreshAdminServerAddressTaskOfflineIntervalSecond() {
+public int getRefreshAdminServerAddressTaskOfflineIntervalInSeconds() {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between fa1b0de and 06339a6.

📒 Files selected for processing (3)
  • CHANGES.md (1 hunks)
  • apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/AdminServiceAddressLocator.java (3 hunks)
  • apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/config/PortalConfig.java (3 hunks)
🧰 Additional context used
🔇 Additional comments (5)
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/AdminServiceAddressLocator.java (4)

19-19: Import Statement Approved

The import statement for PortalConfig is necessary for accessing configuration settings.


58-58: Field Declaration Approved

Declaring portalConfig as a final field is appropriate for configuration access throughout the class.


70-70: Field Initialization Approved

Initializing portalConfig in the constructor ensures that configuration values are accessible for scheduling tasks.


64-65: Ensure Proper Dependency Injection of PortalConfig

The constructor now requires an instance of PortalConfig. Verify that Spring's dependency injection is correctly configured to provide this dependency, to prevent any NoSuchBeanDefinitionException at runtime.

You can run the following command to check if PortalConfig is properly registered as a Spring bean:

✅ Verification successful

Dependency Injection Verified for PortalConfig

Spring's dependency injection is correctly configured for PortalConfig as it is annotated with @Component, ensuring it is properly managed by the Spring container.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that `PortalConfig` is annotated with a Spring stereotype annotation.

# Test: Search for Spring annotations in `PortalConfig.java`.
# Expect: `@Component`, `@Configuration`, or similar annotations present.

rg '@(Component|Configuration|Service)' --type java -A 2 -B 2 -g 'PortalConfig.java'

Length of output: 685

apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/config/PortalConfig.java (1)

46-47: Constants are defined appropriately

The default interval constants are correctly defined with clear values and comments indicating their purpose.

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-portal/src/main/java/com/ctrip/framework/apollo/portal/component/config/PortalConfig.java (3)

46-47: Ensure consistency in comment formatting and units

To enhance readability, consider standardizing the comments for the default interval constants. For example:

-private static final int DEFAULT_REFRESH_ADMIN_SERVER_ADDRESS_TASK_NORMAL_INTERVAL_IN_SECOND = 5 * 60; //5min
+private static final int DEFAULT_REFRESH_ADMIN_SERVER_ADDRESS_TASK_NORMAL_INTERVAL_IN_SECOND = 5 * 60; // 5 minutes
-private static final int DEFAULT_REFRESH_ADMIN_SERVER_ADDRESS_TASK_OFFLINE_INTERVAL_IN_SECOND = 10; //10s
+private static final int DEFAULT_REFRESH_ADMIN_SERVER_ADDRESS_TASK_OFFLINE_INTERVAL_IN_SECOND = 10; // 10 seconds

199-202: Add JavaDoc comments to new public method

Adding JavaDoc documentation to refreshAdminServerAddressTaskNormalIntervalSecond() will improve maintainability by providing clarity on the method's purpose, usage, and acceptable value range (minimum 5 seconds).


204-207: Add JavaDoc comments to new public method

Similarly, including JavaDoc comments for refreshAdminServerAddressTaskOfflineIntervalSecond() will enhance code readability and assist others in understanding its functionality and constraints.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 06339a6 and d52028c.

📒 Files selected for processing (1)
  • apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/config/PortalConfig.java (3 hunks)
🧰 Additional context used
🔇 Additional comments (1)
apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/component/config/PortalConfig.java (1)

321-327: Good use of input validation and logging

The checkInt method effectively validates input values and logs a warning when out-of-bounds values are provided, ensuring robustness and aiding in debugging.

@youngzil
Copy link
Contributor Author

@nobodyiam I have solved these problems, please review again

@nobodyiam
Copy link
Member

Please help to solve the conflicts in CHANGES.md

…_interval_support_config

# Conflicts:
#	CHANGES.md
@youngzil
Copy link
Contributor Author

Please help to solve the conflicts in CHANGES.md

@nobodyiam I have resolved this conflict, please help review it again

nobodyiam and others added 3 commits October 18, 2024 08:42
…_interval_support_config

# Conflicts:
#	CHANGES.md
…essTask_time_interval_support_config' into feature/refreshAdminServerAddressTask_time_interval_support_config
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 Oct 18, 2024
@nobodyiam nobodyiam merged commit 7ce173e into apolloconfig:master Oct 18, 2024
7 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Oct 18, 2024
@youngzil youngzil deleted the feature/refreshAdminServerAddressTask_time_interval_support_config branch October 18, 2024 10:44
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:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AdminServiceAddressLocator中的定时任务RefreshAdminServerAddressTask的delay时间可以动态调整
2 participants