Skip to content

Commit d20c354

Browse files
authored
feat: optimize default-plugin.conf to load once per lifecyle (#175)
* 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
1 parent 2af48e7 commit d20c354

File tree

1 file changed

+33
-25
lines changed
  • polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/common

1 file changed

+33
-25
lines changed

polaris-agent-plugins/spring-cloud-plugins/spring-cloud-hoxton-plugin/src/main/java/cn/polarismesh/agent/plugin/spring/cloud/common/PropertiesProvider.java

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
import java.nio.file.Paths;
2424
import java.util.ArrayList;
2525
import java.util.List;
26+
import java.util.Map;
2627
import java.util.Properties;
28+
import java.util.concurrent.ConcurrentHashMap;
2729

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

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

40+
private static final Map<String, List<PropertiesPropertySource>> LOADED_RESOURCES = new ConcurrentHashMap<>();
41+
42+
private static final String CONFIG_FILE_NAME = "default-plugin.conf";
43+
3844
/**
3945
* load the properties source from default application.yaml
4046
* @return propertySources
4147
*/
4248
public static List<PropertiesPropertySource> loadPropertiesSource() {
43-
InputStream stream = PropertiesProvider.class.getClassLoader().getResourceAsStream("default-plugin.conf");
44-
Properties defaultProperties = new Properties();
45-
try {
46-
defaultProperties.load(stream);
47-
} catch (IOException e) {
48-
throw new IllegalStateException("fail to load default-plugin.conf", e);
49-
}
50-
List<PropertiesPropertySource> propertySources = new ArrayList<>();
51-
propertySources.add(new PropertiesPropertySource("__default_polaris_agent_spring_cloud_tencent__", defaultProperties));
49+
return LOADED_RESOURCES.computeIfAbsent(CONFIG_FILE_NAME, fileName -> {
50+
InputStream stream = PropertiesProvider.class.getClassLoader().getResourceAsStream(fileName);
51+
Properties defaultProperties = new Properties();
52+
try {
53+
defaultProperties.load(stream);
54+
} catch (IOException e) {
55+
throw new IllegalStateException("fail to load file " + fileName, e);
56+
}
57+
List<PropertiesPropertySource> propertySources = new ArrayList<>();
58+
propertySources.add(new PropertiesPropertySource("__default_polaris_agent_spring_cloud_tencent__", defaultProperties));
5259

53-
String configPath = Paths.get(System.getProperty(Constant.AGENT_CONF_PATH), "conf").toString();
54-
LOGGER.info("load property sources from config path " + configPath);
55-
Properties properties = new Properties();
56-
String confPath = Paths.get(configPath, "plugin", "spring-cloud-hoxton", "application.properties").toString();
57-
String cmdVal = System.getProperty("polaris.agent.user.application.conf");
58-
if (StringUtils.isNotBlank(cmdVal)) {
59-
confPath = cmdVal;
60-
}
61-
try {
62-
properties.load(Files.newInputStream(Paths.get(confPath).toFile().toPath()));
63-
}
64-
catch (IOException e) {
65-
throw new IllegalStateException("fail to load config from " + configPath, e);
66-
}
67-
propertySources.add(new PropertiesPropertySource("__polaris_agent_spring_cloud_tencent__", properties));
68-
return propertySources;
60+
String configPath = Paths.get(System.getProperty(Constant.AGENT_CONF_PATH), "conf").toString();
61+
LOGGER.info("load property sources from config path " + configPath);
62+
Properties properties = new Properties();
63+
String confPath = Paths.get(configPath, "plugin", "spring-cloud-hoxton", "application.properties").toString();
64+
String cmdVal = System.getProperty("polaris.agent.user.application.conf");
65+
if (StringUtils.isNotBlank(cmdVal)) {
66+
confPath = cmdVal;
67+
}
68+
try {
69+
properties.load(Files.newInputStream(Paths.get(confPath).toFile().toPath()));
70+
}
71+
catch (IOException e) {
72+
throw new IllegalStateException("fail to load config from " + configPath, e);
73+
}
74+
propertySources.add(new PropertiesPropertySource("__polaris_agent_spring_cloud_tencent__", properties));
75+
return propertySources;
76+
});
6977
}
7078
}

0 commit comments

Comments
 (0)