Skip to content

feat(configservice): Enhanced instance configuration auditing and caching#5361

Merged
nobodyiam merged 5 commits intoapolloconfig:masterfrom
youngzil:feature/InstanceConfigAuditUtil-parameter-configurability
Mar 29, 2025
Merged

feat(configservice): Enhanced instance configuration auditing and caching#5361
nobodyiam merged 5 commits intoapolloconfig:masterfrom
youngzil:feature/InstanceConfigAuditUtil-parameter-configurability

Conversation

@youngzil
Copy link
Contributor

@youngzil youngzil commented Mar 20, 2025

What's the purpose of this PR

After starting the service and making some requests to pull configurations, access curl 127.0.0.1:8080/prometheus | grep -E 'instance_cache|instance_config_cache' and you can see the following monitoring indicator data
image

Which issue(s) this PR fixes:

Fixes #5358

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

    • Introduced new configuration options for instance auditing and caching, enhancing control over audit record management and cache sizes.
    • Added public methods to retrieve configuration parameters, improving accessibility to instance settings.
    • Updated deployment guides to include new configuration parameters, providing clearer documentation for users.
    • Added a new feature entry in release notes for Apollo version 2.5.0 regarding enhanced instance configuration auditing and caching.
  • Refactor

    • Enhanced initialization logic for configuration management and cache handling, allowing for more modular and configurable approaches.

@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Mar 20, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 20, 2025

Walkthrough

This change introduces new configurable parameters in the configuration management classes. The BizConfig class adds constants and public methods for instance audit and cache settings. The InstanceConfigAuditUtil class is updated to utilize these dynamic parameters and integrates metric monitoring via MeterRegistry. Moreover, the corresponding test cases are modified to support these new dependencies and initialization flows.

Changes

File(s) Change Summary
apollo-biz/.../BizConfig.java Added new private static final constants for default sizes and thresholds; added public getter methods that validate and return configuration values; modified longPollingTimeoutInMilli() to validate and convert timeout values.
apollo-configservice/.../InstanceConfigAuditUtil.java Updated constructor to accept BizConfig and MeterRegistry; refactored initialization logic into buildInstanceCache() and buildInstanceConfigReleaseKeyCache() methods; now uses configurable parameters from BizConfig.
apollo-configservice/.../InstanceConfigAuditUtilTest.java Added mocks for BizConfig and MeterRegistry; updated the test constructor and initialization process to align with the changes in InstanceConfigAuditUtil.

Assessment against linked issues

Objective Addressed Explanation
Configurable parameters for InstanceConfigAuditUtil (queue size, cache size, time threshold) (#5358)
Integration of instance cache monitoring using MeterRegistry (#5358)

Suggested labels

lgtm

Suggested reviewers

  • nobodyiam

Poem

Hoppity hop, the code now sings,
New configs flutter on digital wings.
Constants and methods dance in line,
With metrics and cache all feeling fine.
A rabbit’s cheer for changes true,
In every hop, a breakthrough anew!

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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 generate docstrings to generate docstrings for this 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.

@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 Mar 20, 2025
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

🧹 Nitpick comments (5)
docs/en/deployment/distributed-deployment-guide.md (1)

1636-1665: Review of New Configuration Documentation (Sections 3.2.14–3.2.17)

The newly introduced sections detailing the following configuration parameters are clear and cohesive:

  • 3.2.14 instance.config.audit.max.size: Describes the maximum queue size for audit records with specified default (10000) and minimum (10) values.
  • 3.2.15 instance.cache.max.size: Details the maximum number of instance caches with a default of 50000 and a minimum of 10.
  • 3.2.16 instance.config.cache.max.size: Specifies limitations for instance config caches identically to section 3.2.15.
  • 3.2.17 instance.config.audit.time.threshold.minutes: Explains the interval threshold (default 10, minimum 5 minutes) for saving/updating audit records.

Each section clearly states the respective default and minimum values and reminds the user that a service restart is required for the changes to take effect.

Suggestions:

  • Consistent Restart Reminder: The phrase “After the modification, you need to restart for it to take effect” is clear; however, consider rephrasing to a more concise variant such as “A restart is required for changes to take effect” for consistency and brevity across the document.
  • Impact Note (Optional): Adding a brief note on potential impacts—if any—on performance or caching behavior when modifying these parameters could further improve the documentation.

Overall, these additions enhance the usability of the deployment guide by providing detailed control over audit logging and cache management in the latest version (2.5.0 and above).

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

1575-1580: Documentation Update: Instance Config Audit Max Size Parameter
The new parameter instance.config.audit.max.size is clearly documented with a default value of 10,000 and a minimum of 10. It effectively conveys that exceeding this queue size will result in discarding the oldest audit records. Consider explicitly stating that the value refers to the number of audit records and emphasize that any modifications require a service restart.


1581-1586: Documentation Review: Instance Cache Max Size Parameter
The parameter instance.cache.max.size is specified clearly with a default of 50,000 and a minimum of 10. It explains that when the cached instances exceed this limit, an eviction mechanism is triggered. For enhanced clarity, consider adding a brief note about the eviction strategy (e.g., whether it uses FIFO, LRU, etc.) if that information is available.


1587-1592: Documentation Review: Instance Config Cache Max Size Parameter
This parameter, instance.config.cache.max.size, is well described with a default of 50,000 and a minimum of 10, detailing its role in controlling the maximum number of cached instance configurations. As with the previous parameter, a short note on the details of the eviction mechanism could further aid users in understanding its behavior during cache overflow.


1593-1606: Documentation Update: Instance Config Audit Time Threshold Parameter
The new parameter instance.config.audit.time.threshold.minutes is clearly introduced with a default value of 10 minutes and a minimum of 5 minutes. It succinctly explains that only if the interval between two configuration-pull requests exceeds this threshold will the audit record be saved or updated. For clarity, please specify whether the comparison is inclusive (i.e., if the interval is exactly 10 minutes) or exclusive.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1690d54 and bf7fefe.

📒 Files selected for processing (2)
  • docs/en/deployment/distributed-deployment-guide.md (1 hunks)
  • docs/zh/deployment/distributed-deployment-guide.md (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build (8)

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 22cfc1c and 5807c49.

📒 Files selected for processing (3)
  • apollo-configservice/src/main/java/com/ctrip/framework/apollo/configservice/util/InstanceConfigAuditUtil.java (5 hunks)
  • apollo-configservice/src/test/java/com/ctrip/framework/apollo/configservice/util/InstanceConfigAuditUtilTest.java (3 hunks)
  • docs/zh/deployment/distributed-deployment-guide.md (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build (8)
🔇 Additional comments (14)
apollo-configservice/src/test/java/com/ctrip/framework/apollo/configservice/util/InstanceConfigAuditUtilTest.java (4)

19-19: Added required imports for new dependencies.

The new imports for BizConfig and MeterRegistry are necessary to support the enhanced instance configuration auditing and caching functionality.

Also applies to: 23-23


46-49: Added mock objects for new dependencies.

The test correctly adds mock objects for BizConfig and MeterRegistry, which are now required by the InstanceConfigAuditUtil class.


65-67: Added stub configuration for mock BizConfig.

Good setup of the mock BizConfig with sensible default values for the configuration parameters that will be used by the InstanceConfigAuditUtil.


69-69: Updated constructor call with new dependencies.

The constructor call has been updated to include the new bizConfig and meterRegistry dependencies, which aligns with the changes in the implementation class.

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

1575-1582: Added new configuration for client audit queue size.

The documentation nicely explains the instance.config.audit.max.size parameter, which controls the maximum size of the queue for audit records. This is a good addition that gives users control over memory usage related to auditing.


1583-1590: Added new configuration for instance cache size.

The documentation for instance.cache.max.size is clearly explained, detailing that it controls the maximum number of instances that can be cached, with eviction mechanisms when the limit is reached.


1591-1598: Added new configuration for instance configuration cache size.

Clear explanation of instance.config.cache.max.size parameter which controls the maximum size of the instance configuration cache, similar to the instance cache configuration.


1600-1604: Added time threshold configuration for audit records.

The documentation for instance.config.audit.time.threshold.minutes explains how this parameter can optimize the auditing process by reducing unnecessary record updates.

apollo-configservice/src/main/java/com/ctrip/framework/apollo/configservice/util/InstanceConfigAuditUtil.java (6)

19-19: Added imports for new dependencies.

Necessary imports added for BizConfig, MeterRegistry, and Guava cache metrics for the enhanced auditing and monitoring functionality.

Also applies to: 34-36


59-62: Refactored field initializations.

The initialization of cache fields has been moved from field declaration to methods for better organization and to allow dynamic configuration.


64-66: Added fields for new dependencies.

Added private final fields for BizConfig and MeterRegistry to support configurable cache sizes and metrics collection.


67-78: Enhanced constructor with configuration and metrics dependencies.

The constructor now accepts BizConfig and MeterRegistry parameters, which are used to initialize the audit queue with a configurable size and set up dynamically configured caches. This enhances the flexibility of the class.


144-146: Used configurable time threshold for audit comparison.

The method now uses a threshold from bizConfig instead of a hardcoded value, making it more configurable and adaptable to different deployment scenarios.


184-194: Extracted instance cache building to a separate method.

Created a dedicated method for building the instance cache with configurable maximum size and optional statistics recording. This is a good separation of concerns and enhances maintainability.

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

🧹 Nitpick comments (1)
apollo-configservice/src/main/java/com/ctrip/framework/apollo/configservice/util/InstanceConfigAuditUtil.java (1)

36-37: Unused import should be removed.

The javax.annotation.PostConstruct import is not used in the class. According to previous review comments, there was a discussion about whether to use PostConstruct, and it was decided against it, but the import remains.

-import javax.annotation.PostConstruct;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5807c49 and 96f587f.

📒 Files selected for processing (1)
  • apollo-configservice/src/main/java/com/ctrip/framework/apollo/configservice/util/InstanceConfigAuditUtil.java (5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build (8)
🔇 Additional comments (6)
apollo-configservice/src/main/java/com/ctrip/framework/apollo/configservice/util/InstanceConfigAuditUtil.java (6)

19-19: Good addition of necessary imports for enhanced functionality.

The added imports enable the class to leverage configurable parameters via BizConfig and monitoring capabilities via MeterRegistry and GuavaCacheMetrics. These are appropriate for the enhanced auditing and caching requirements.

Also applies to: 34-36


59-65: Good refactoring of field declarations.

The fields have been properly reorganized to support the new configuration-driven approach. The audits field is now declared here but initialized in the constructor with a configurable size, while BizConfig and MeterRegistry are correctly added as final fields.


67-78: Constructor properly updated to support configurable parameters.

The constructor now correctly accepts BizConfig and MeterRegistry dependencies and initializes the audits queue with a configurable size. The extraction of cache building logic into separate methods follows good separation of concerns principles.


145-145: Good replacement of hardcoded value with configurable parameter.

Replacing the hardcoded threshold with a configurable parameter from bizConfig increases flexibility and allows for runtime adjustments without code changes.


184-194: Well-structured instance cache initialization.

Good implementation of a configurable instance cache with the following improvements:

  1. Configurable maximum size via bizConfig.getInstanceCacheMaxSize()
  2. Optional statistics recording based on configuration
  3. Proper metrics registration when statistics are enabled

The code effectively uses the builder pattern and conditional logic to create a cache tailored to current configuration settings.


196-206: Well-implemented instance config release key cache.

The implementation properly configures the cache with:

  1. Configurable maximum size via bizConfig.getInstanceConfigCacheMaxSize()
  2. Conditional statistics recording
  3. Appropriate metrics registration

The consistent pattern between this and the instance cache initialization shows good code organization.

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

@nobodyiam nobodyiam merged commit 9f91c02 into apolloconfig:master Mar 29, 2025
8 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Mar 29, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Mar 29, 2025
@youngzil youngzil deleted the feature/InstanceConfigAuditUtil-parameter-configurability branch April 2, 2025 02:20
@nobodyiam nobodyiam added this to the 2.5.0 milestone Feb 19, 2026
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.

InstanceConfigAuditUtil中的相关参数可配置化和缓存新增监控

2 participants