apolloconfig / apollo

Apollo is a reliable configuration management system suitable for microservice configuration management scenarios.
https://www.apolloconfig.com
Apache License 2.0
28.93k stars 10.19k forks source link

麻烦问下,有什么办法能同时读到多个环境同一个配置的值吗? #5133

Closed adgai closed 2 weeks ago

adgai commented 2 months ago

清晰简洁地描述这个问题是什么。即,当碰到xxx时,总是感觉很麻烦

我们目前项目中获取配置是使用 configService.get(key),这样的形式,需要看到key 对应的value 只能到 portal 中看,我想开发一个插件展示各个环境的值,所以想同时获取到多个环境的值。

dosubot[bot] commented 2 months ago

To simultaneously fetch and display configuration values for a specific key across multiple environments, you can develop a plugin by following these steps:

  1. Integrate with Apollo: Use Apollo client APIs to fetch configuration data for the desired key across the environments you're interested in. This involves making API calls similar to ConfigService.find_items() for each environment.

  2. Develop the User Interface: Create a UI where users can select a configuration key and multiple environments. You can take inspiration from the diff.html file, utilizing elements like the cluster selector and display format options.

  3. Fetch and Display Configurations: Implement functionality to fetch the configuration values upon form submission and display them in a user-friendly format. Adapt the table structure from diff.html for displaying the values across environments.

  4. Code Example for Fetching Configurations:

    function fetchConfigForKey(appId, envs, clusterName, namespaceName, key) {
       let promises = envs.map(env => 
           ConfigService.find_items(appId, env, clusterName, namespaceName)
           .then(items => items.find(item => item.key === key))
       );
       return Promise.all(promises);
    }
  5. Optimize User Experience: Include features like filtering, sorting, a refresh button, and possibly a search functionality to enhance the plugin's usability.

Ensure your plugin has comprehensive error handling, considers performance optimization through caching, and enforces security measures to protect sensitive configurations. This approach builds on the functionality seen in the Apollo portal's DiffConfigController.js and diff.html, extending it to focus on your specific requirement of displaying configuration keys across multiple environments.

#### Details **Sources** - [apollo-portal/src/main/resources/static/scripts/controller/config/DiffConfigController.js](https://github.com/apolloconfig/apollo/blob/master/apollo-portal/src/main/resources/static/scripts/controller/config/DiffConfigController.js) - [apollo-portal/src/main/resources/static/config/diff.html](https://github.com/apolloconfig/apollo/blob/master/apollo-portal/src/main/resources/static/config/diff.html) - [apollo-common/src/main/java/com/ctrip/framework/apollo/common/config/RefreshableConfig.java](https://github.com/apolloconfig/apollo/blob/master/apollo-common/src/main/java/com/ctrip/framework/apollo/common/config/RefreshableConfig.java) - [apollo-portal/src/main/resources/static/scripts/services/ConfigService.js](https://github.com/apolloconfig/apollo/blob/master/apollo-portal/src/main/resources/static/scripts/services/ConfigService.js) - [apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/AuthConfiguration.java](https://github.com/apolloconfig/apollo/blob/master/apollo-portal/src/main/java/com/ctrip/framework/apollo/portal/spi/configuration/AuthConfiguration.java) - [apollo-configservice/src/main/java/com/ctrip/framework/apollo/configservice/service/config/ConfigServiceWithCache.java](https://github.com/apolloconfig/apollo/blob/master/apollo-configservice/src/main/java/com/ctrip/framework/apollo/configservice/service/config/ConfigServiceWithCache.java) - [apollo-configservice/src/main/java/com/ctrip/framework/apollo/configservice/controller/ConfigFileController.java](https://github.com/apolloconfig/apollo/blob/master/apollo-configservice/src/main/java/com/ctrip/framework/apollo/configservice/controller/ConfigFileController.java) - [apollo-configservice/src/main/java/com/ctrip/framework/apollo/configservice/service/AppNamespaceServiceWithCache.java](https://github.com/apolloconfig/apollo/blob/master/apollo-configservice/src/main/java/com/ctrip/framework/apollo/configservice/service/AppNamespaceServiceWithCache.java) - [apollo-configservice/pom.xml](https://github.com/apolloconfig/apollo/blob/master/apollo-configservice/pom.xml)
**About Dosu** This response is meant to be useful and save you time. It is **not meant to be a precise solution**, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

nobodyiam commented 2 months ago

可以接入 Open API

adgai commented 2 months ago

open api 如果获取一个没配的key 会404,在获取生产环境的key的值时不太合适

stale[bot] commented 4 weeks ago

This issue has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in 7 days unless it is tagged "help wanted" or other activity occurs. Thank you for your contributions.

stale[bot] commented 2 weeks ago

This issue has been automatically closed because it has not had activity in the last 7 days. If this issue is still valid, please ping a maintainer and ask them to label it as "help wanted". Thank you for your contributions.