Skip to content

Commit

Permalink
feat: optimize default-plugin.conf to load once per lifecyle (#175)
Browse files Browse the repository at this point in the history
* fix: optimize the discovery inject logic and fix nacos config not working issue

* feat: 删除无用的导入

* feat: 增加actuator到demo中

* fix: add lossless healthcheck for example

* fix: add configuration comments

* fix: 修复事件日志不输出的问题

* release: release version to 1.7.0-RC1

* feat: new add java agent for hoxton

* feat: support service registry and config

* feat: refrator all inject logics into BeanInjector

* feat: add gray release example & dispatch bean register into plugins

* feat: add environment parameter to obtain the configuration

* feat: 增加元数据传输相关拦截器

* feat: 调整example打包脚本

* fix: 修复脚本没法跳转的问题

* fix: 修正样例的配置文件

* fix: 修复熔断无法加载的问题

* fix: 更新北极星的版本号依赖

* fix: 调整版本依赖

* feat:对齐deployment与application中的服务名定义

* feat: optimize default-plugin.conf to load once per lifecyle
  • Loading branch information
andrewshan authored May 13, 2024
1 parent 2af48e7 commit d20c354
Showing 1 changed file with 33 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;

import com.tencent.polaris.api.utils.StringUtils;
import org.slf4j.Logger;
Expand All @@ -35,36 +37,42 @@ public class PropertiesProvider {

private static final Logger LOGGER = LoggerFactory.getLogger(PropertiesProvider.class);

private static final Map<String, List<PropertiesPropertySource>> LOADED_RESOURCES = new ConcurrentHashMap<>();

private static final String CONFIG_FILE_NAME = "default-plugin.conf";

/**
* load the properties source from default application.yaml
* @return propertySources
*/
public static List<PropertiesPropertySource> loadPropertiesSource() {
InputStream stream = PropertiesProvider.class.getClassLoader().getResourceAsStream("default-plugin.conf");
Properties defaultProperties = new Properties();
try {
defaultProperties.load(stream);
} catch (IOException e) {
throw new IllegalStateException("fail to load default-plugin.conf", e);
}
List<PropertiesPropertySource> propertySources = new ArrayList<>();
propertySources.add(new PropertiesPropertySource("__default_polaris_agent_spring_cloud_tencent__", defaultProperties));
return LOADED_RESOURCES.computeIfAbsent(CONFIG_FILE_NAME, fileName -> {
InputStream stream = PropertiesProvider.class.getClassLoader().getResourceAsStream(fileName);
Properties defaultProperties = new Properties();
try {
defaultProperties.load(stream);
} catch (IOException e) {
throw new IllegalStateException("fail to load file " + fileName, e);
}
List<PropertiesPropertySource> propertySources = new ArrayList<>();
propertySources.add(new PropertiesPropertySource("__default_polaris_agent_spring_cloud_tencent__", defaultProperties));

String configPath = Paths.get(System.getProperty(Constant.AGENT_CONF_PATH), "conf").toString();
LOGGER.info("load property sources from config path " + configPath);
Properties properties = new Properties();
String confPath = Paths.get(configPath, "plugin", "spring-cloud-hoxton", "application.properties").toString();
String cmdVal = System.getProperty("polaris.agent.user.application.conf");
if (StringUtils.isNotBlank(cmdVal)) {
confPath = cmdVal;
}
try {
properties.load(Files.newInputStream(Paths.get(confPath).toFile().toPath()));
}
catch (IOException e) {
throw new IllegalStateException("fail to load config from " + configPath, e);
}
propertySources.add(new PropertiesPropertySource("__polaris_agent_spring_cloud_tencent__", properties));
return propertySources;
String configPath = Paths.get(System.getProperty(Constant.AGENT_CONF_PATH), "conf").toString();
LOGGER.info("load property sources from config path " + configPath);
Properties properties = new Properties();
String confPath = Paths.get(configPath, "plugin", "spring-cloud-hoxton", "application.properties").toString();
String cmdVal = System.getProperty("polaris.agent.user.application.conf");
if (StringUtils.isNotBlank(cmdVal)) {
confPath = cmdVal;
}
try {
properties.load(Files.newInputStream(Paths.get(confPath).toFile().toPath()));
}
catch (IOException e) {
throw new IllegalStateException("fail to load config from " + configPath, e);
}
propertySources.add(new PropertiesPropertySource("__polaris_agent_spring_cloud_tencent__", properties));
return propertySources;
});
}
}

0 comments on commit d20c354

Please sign in to comment.