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: support RepositoryChangeListener for SPI #3883

Closed
wants to merge 1 commit into from

Conversation

qxo
Copy link

@qxo qxo commented Aug 10, 2021

提供SPI扩展,以便具体项目通过此SPI中来实现敏感信息(如密码)的解密处理

SPI实现类配置文件位置:META-INF\services\com.ctrip.framework.apollo.internals.RepositoryChangeListener

What's the purpose of this PR

XXXXX

Which issue(s) this PR fixes:

Fixes #

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 configuration management by allowing dynamic discovery and registration of change listeners, improving responsiveness to configuration updates.

@github-actions
Copy link

CLA Assistant Lite bot:
Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


You can retrigger this bot by commenting recheck in this Pull Request

提供SPI扩展,以便具体项目通过此SPI中来实现敏感信息(如密码)的解密处理

SPI实现类配置文件位置:META-INF\services\com.ctrip.framework.apollo.internals.RepositoryChangeListener

I have read the CLA Document and I hereby sign the CLA
@nobodyiam
Copy link
Member

RepositoryChangeListener 应该没法实现这个需求吧,可行的方式可以参考 com.ctrip.framework.apollo.config.data.internals.PureApolloConfigFactory,通过 ApolloInjectorCustomizer 来自定义一个 Config 类实现出来

@qxo
Copy link
Author

qxo commented Aug 11, 2021

RepositoryChangeListener 应该没法实现这个需求吧,可行的方式可以参考 com.ctrip.framework.apollo.config.data.internals.PureApolloConfigFactory,通过 ApolloInjectorCustomizer 来自定义一个 Config 类实现出来

经过此PR, 是可能实现对apollo中获取配置项进行解码处理再交由程序来处理。

API应提供扩展点以便具体项目进行个性化改造(而不用修改源码)

以下是切入点调用链供参考
//启动时的SPI切入点:

       at com.ctrip.framework.apollo.internals.AbstractConfigRepository.fireRepositoryChange(AbstractConfigRepository.java:53) ~[apollo-client-1.8.0.jar:1.8.0]
       at com.ctrip.framework.apollo.internals.RemoteConfigRepository.sync(RemoteConfigRepository.java:148) ~[classes/:1.8.0]
       at com.ctrip.framework.apollo.internals.AbstractConfigRepository.trySync(AbstractConfigRepository.java:25) ~[apollo-client-1.8.0.jar:1.8.0]
       at com.ctrip.framework.apollo.internals.RemoteConfigRepository.<init>(RemoteConfigRepository.java:97) ~[classes/:1.8.0]
       at com.ctrip.framework.apollo.spi.DefaultConfigFactory.createRemoteConfigRepository(DefaultConfigFactory.java:77) ~[apollo-client-1.8.0.jar:1.8.0]
       at com.ctrip.framework.apollo.spi.DefaultConfigFactory.createLocalConfigRepository(DefaultConfigFactory.java:73) ~[apollo-client-1.8.0.jar:1.8.0]
       at com.ctrip.framework.apollo.spi.DefaultConfigFactory.create(DefaultConfigFactory.java:42) ~[apollo-client-1.8.0.jar:1.8.0]
       at com.ctrip.framework.apollo.internals.DefaultConfigManager.getConfig(DefaultConfigManager.java:37) ~[apollo-client-1.8.0.jar:1.8.0]
       at com.ctrip.framework.apollo.ConfigService.getConfig(ConfigService.java:61) ~[apollo-client-1.8.0.jar:1.8.0]
       at com.ctrip.framework.apollo.spring.boot.ApolloApplicationContextInitializer.initialize(ApolloApplicationContextInitializer.java:104) ~[apollo-client-1.8.0.jar:1.8.0]
       at com.ctrip.framework.apollo.spring.boot.ApolloApplicationContextInitializer.initialize(ApolloApplicationContextInitializer.java:82) ~[apollo-client-1.8.0.jar:1.8.0]
       at org.springframework.boot.SpringApplication.applyInitializers(SpringApplication.java:623) ~[spring-boot-2.3.12.RELEASE.jar:2.3.12.RELEASE]
       at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:367) ~[spring-boot-2.3.12.RELEASE.jar:2.3.12.RELEASE]
       at org.springframework.boot.SpringApplication.run(SpringApplication.java:311) ~[spring-boot-2.3.12.RELEASE.jar:2.3.12.RELEASE]
       at org.springframework.boot.SpringApplication.run(SpringApplication.java:1247) ~[spring-boot-2.3.12.RELEASE.jar:2.3.12.RELEASE]
       at org.springframework.boot.SpringApplication.run(SpringApplication.java:1236) ~[spring-boot-2.3.12.RELEASE.jar:2.3.12.RELEASE]

//更变时的切入点:

       at com.ctrip.framework.apollo.internals.AbstractConfigRepository.fireRepositoryChange(AbstractConfigRepository.java:53) ~[apollo-client-1.8.0.jar:1.8.0]
       at com.ctrip.framework.apollo.internals.RemoteConfigRepository.sync(RemoteConfigRepository.java:148) ~[classes/:1.8.0]
       at com.ctrip.framework.apollo.internals.AbstractConfigRepository.trySync(AbstractConfigRepository.java:25) ~[apollo-client-1.8.0.jar:1.8.0]
       at com.ctrip.framework.apollo.internals.RemoteConfigRepository$2.run(RemoteConfigRepository.java:329) ~[classes/:1.8.0]
       at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) ~[na:na]
       at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na]
       at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) ~[na:na]
       at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na]
       at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na]
       at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]

@nobodyiam
Copy link
Member

@qxo 通过 onRepositoryChange 应该无法实现诸如敏感信息(如密码)的解密处理,这里传入的 properties 对象虽然目前是可写的,但是从语义上而言只能当作是 readonly 的,所以如果要解密的话,还是需要通过自定义 Config 类来实现的,或者在 fireRepositoryChange 中增加一个新的 spi,专门用于对 properties 进行加工处理

@qxo
Copy link
Author

qxo commented Aug 14, 2021

@qxo 通过 onRepositoryChange 应该无法实现诸如敏感信息(如密码)的解密处理,这里传入的 properties 对象虽然目前是可写的,但是从语义上而言只能当作是 readonly 的,所以如果要解密的话,还是需要通过自定义 Config 类来实现的,或者在 fireRepositoryChange 中增加一个新的 spi,专门用于对 properties 进行加工处理

这样啊,新增一个spi也行, 请项目主管理方决策:)

@nobodyiam nobodyiam added the discussion Categorizes issue as related to discussion label Aug 15, 2021
@nobodyiam
Copy link
Member

我加了 discussion 标签,开放一段时间看看大家的想法吧~

@nobodyiam nobodyiam added this to the 1.10.0 milestone Aug 21, 2021
@nobodyiam nobodyiam removed this from the 2.0.0 milestone Nov 6, 2021
@nobodyiam nobodyiam removed the discussion Categorizes issue as related to discussion label Aug 17, 2024
Copy link

stale bot commented Sep 17, 2024

This pull request has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in 14 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@stale stale bot added the stale label Sep 17, 2024
Copy link
Contributor

coderabbitai bot commented Sep 17, 2024

Walkthrough

The changes to the RemoteConfigRepository constructor introduce a mechanism for loading and registering RepositoryChangeListener instances using Java's ServiceLoader. This allows the repository to dynamically discover and add listeners that can respond to configuration changes, enhancing its functionality and flexibility in handling updates.

Changes

File Path Change Summary
apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java Added a ServiceLoader<RepositoryChangeListener> spiList to facilitate dynamic loading of listeners.

Poem

In the code where changes bloom,
A rabbit hops to clear the gloom.
Listeners now can join the fray,
Responding swiftly, come what may.
With each new change, we cheer and play! 🐇✨


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2c9b4dc and 5604d31.

Files selected for processing (1)
  • apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java (1 hunks)
Additional comments not posted (1)
apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java (1)

107-111: Excellent use of ServiceLoader for dynamic listener registration!

The changes introduce a clean and effective way to discover and register RepositoryChangeListener implementations using ServiceLoader. This approach enhances the flexibility and extensibility of the RemoteConfigRepository by allowing it to dynamically respond to configuration changes through the registered listeners.

The use of the current thread's context class loader ensures that the listeners are loaded from the appropriate classpath, making the code more robust and adaptable to different deployment scenarios.

Great job on improving the repository's capabilities!


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 generate interesting stats about this repository and render them as a table.
    -- @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.

@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Sep 17, 2024
Copy link

stale bot commented Oct 5, 2024

This pull request has been automatically closed because it has not had activity in the last 14 days. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions!

@stale stale bot closed this Oct 5, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Oct 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
size:XS This PR changes 0-9 lines, ignoring generated files. stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants