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: 优化日志打印,增加polarisLoggingApplicationListener的配置 #177

Merged
merged 39 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
0aa8b49
fix: optimize the discovery inject logic and fix nacos config not wor…
andrewshan Apr 13, 2024
b427ba8
Merge branch 'polarismesh:main' into main
andrewshan Apr 15, 2024
761549a
feat: 删除无用的导入
andrewshan Apr 15, 2024
8e5277b
feat: 增加actuator到demo中
andrewshan Apr 15, 2024
dae0a9e
fix: add lossless healthcheck for example
andrewshan Apr 15, 2024
33c84f1
fix: add configuration comments
andrewshan Apr 15, 2024
3bbc028
Merge branch 'polarismesh:main' into main
andrewshan Apr 15, 2024
4c1533d
fix: 修复事件日志不输出的问题
andrewshan Apr 15, 2024
53c0a44
Merge branch 'polarismesh:main' into main
andrewshan Apr 15, 2024
0adca0b
release: release version to 1.7.0-RC1
andrewshan Apr 15, 2024
02150bf
Merge branch 'polarismesh:main' into main
andrewshan Apr 29, 2024
0d37c12
feat: new add java agent for hoxton
andrewshan May 3, 2024
286d397
feat: support service registry and config
andrewshan May 4, 2024
6fa3d0b
feat: refrator all inject logics into BeanInjector
andrewshan May 6, 2024
fbd5fe6
Merge branch 'polarismesh:main' into main
andrewshan May 6, 2024
1604631
feat: add gray release example & dispatch bean register into plugins
andrewshan May 7, 2024
2c8c777
Merge branch 'polarismesh:main' into main
andrewshan May 7, 2024
cada831
feat: add environment parameter to obtain the configuration
andrewshan May 8, 2024
5c6c44c
Merge branch 'polarismesh:main' into main
andrewshan May 8, 2024
1be919f
feat: 增加元数据传输相关拦截器
andrewshan May 8, 2024
32a18c4
Merge branch 'polarismesh:main' into main
andrewshan May 9, 2024
0260fdd
feat: 调整example打包脚本
andrewshan May 9, 2024
4faef54
fix: 修复脚本没法跳转的问题
andrewshan May 9, 2024
657caf1
Merge branch 'polarismesh:main' into main
andrewshan May 9, 2024
7779ff8
fix: 修正样例的配置文件
andrewshan May 9, 2024
9c1fcba
fix: 修复熔断无法加载的问题
andrewshan May 10, 2024
56c61c2
Merge branch 'main' into main
andrewshan May 10, 2024
9a54440
fix: 更新北极星的版本号依赖
andrewshan May 10, 2024
3484c70
Merge branch 'main' of https://github.com/andrewshan/polaris-java-agent
andrewshan May 10, 2024
05e58b5
Merge branch 'polarismesh:main' into main
andrewshan May 10, 2024
eb8ad9e
fix: 调整版本依赖
andrewshan May 10, 2024
dc1bea9
Merge branch 'main' of https://github.com/andrewshan/polaris-java-agent
andrewshan May 10, 2024
48a4991
Merge branch 'polarismesh:main' into main
andrewshan May 11, 2024
c26bd51
feat:对齐deployment与application中的服务名定义
andrewshan May 11, 2024
f7d2fcf
Merge branch 'polarismesh:main' into main
andrewshan May 13, 2024
c667586
feat: optimize default-plugin.conf to load once per lifecyle
andrewshan May 13, 2024
011f8b5
Merge branch 'polarismesh:main' into main
andrewshan May 13, 2024
740f1a3
Merge branch 'polarismesh:main' into main
andrewshan May 13, 2024
3ce5576
feat: 优化日志打印,增加polarisLoggingApplicationListener的配置
andrewshan May 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static <T> Class<T> getClazz(String clazzName, ClassLoader classLoader) {
try {
return (Class<T>) Class.forName(clazzName, false, classLoader);
} catch (ClassNotFoundException e) {
logger.warn(String.format("class %s not found, error %s", clazzName, e.getLocalizedMessage()));
logger.info(String.format("class %s not found", clazzName));
}
return null;
}
Expand Down
3 changes: 2 additions & 1 deletion polaris-agent-plugins/spring-cloud-plugins/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
<module>spring-cloud-2020-plugin</module>
<module>spring-cloud-hoxton-plugin</module>
<module>spring-cloud-2023-plugin</module>
</modules>
<module>spring-cloud-plugin-common</module>
</modules>

<properties>
<jdk.version>1.8</jdk.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<properties>
<spring.cloud.version>Hoxton.SR12</spring.cloud.version>
<spring.cloud.tencent.version>1.14.0-Hoxton.SR12-SNAPSHOT</spring.cloud.tencent.version>
<spring.boot.version>2.3.7.RELEASE</spring.boot.version>
<spring.boot.version>2.3.12.RELEASE</spring.boot.version>
<slf4j.vesion>1.7.30</slf4j.vesion>
</properties>

Expand Down Expand Up @@ -61,6 +61,11 @@
</dependencyManagement>

<dependencies>
<dependency>
<groupId>com.tencent.polaris</groupId>
<artifactId>spring-cloud-plugin-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import cn.polarismesh.agent.plugin.spring.cloud.interceptor.ConfigurationParserInterceptor;
import cn.polarismesh.agent.plugin.spring.cloud.interceptor.ConfigurationPostProcessorInterceptor;
import cn.polarismesh.agent.plugin.spring.cloud.interceptor.RegisterBeanInterceptor;
import cn.polarismesh.agent.plugin.spring.cloud.interceptor.SpringFactoriesLoaderInterceptor;

/**
* Polaris Spring Cloud hoxton Plugin
Expand All @@ -57,6 +58,9 @@ private void addPolarisTransformers(TransformOperations operations) {

// 注入bean定义的调整设置
operations.transform(Constant.BEAN_DEFINITION_REGISTRY, RegisterBeanDefinitionTransform.class);

// 注入JNI定义
operations.transform(Constant.SPRING_FACTORIES_LOADER, SpringFactoriesLoaderTransform.class);
}

public static class ConfigurationParserTransform implements TransformCallback {
Expand Down Expand Up @@ -100,4 +104,19 @@ public byte[] doInTransform(Instrumentor instrumentor, ClassLoader classLoader,
return target.toBytecode();
}
}

public static class SpringFactoriesLoaderTransform implements TransformCallback {

@Override
public byte[] doInTransform(Instrumentor instrumentor, ClassLoader classLoader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classFileBuffer) throws InstrumentException {
InstrumentClass target = instrumentor.getInstrumentClass(classLoader, className, classFileBuffer);
InstrumentMethod constructMethod = target.getDeclaredMethod("loadSpringFactories", "java.lang.ClassLoader");
if (constructMethod != null) {
constructMethod.addInterceptor(SpringFactoriesLoaderInterceptor.class);
}

return target.toBytecode();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
import org.springframework.core.env.Environment;

public class CircuitBreakerBeanInjector implements BeanInjector {
@Override
public String getModule() {
return "spring-cloud-starter-tencent-polaris-circuitbreaker";
}

@Override
public void onBootstrapStartup(Object configurationParser, Constructor<?> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
Object polarisCircuitBreakerBootstrapConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisCircuitBreakerBootstrapConfiguration.class, "polarisCircuitBreakerBootstrapConfiguration");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
import org.springframework.core.env.Environment;

public class CommonBeanInjector implements BeanInjector {
@Override
public String getModule() {
return "spring-cloud-tencent-commons";
}

@Override
public void onBootstrapStartup(Object configurationParser, Constructor<?> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
import org.springframework.core.env.Environment;

public class ConfigBeanInjector implements BeanInjector {
@Override
public String getModule() {
return "spring-cloud-starter-tencent-polaris-config";
}

@Override
public void onBootstrapStartup(Object configurationParser, Constructor<?> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
Object polarisConfigBootstrapAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisConfigBootstrapAutoConfiguration.class, "polarisConfigBootstrapAutoConfiguration");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
import org.springframework.core.env.Environment;

public class LoadbalancerBeanInjector implements BeanInjector {
@Override
public String getModule() {
return "spring-cloud-tencent-polaris-loadbalancer";
}

@Override
public void onBootstrapStartup(Object configurationParser, Constructor<?> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
import org.springframework.core.env.Environment;

public class LosslessBeanInjector implements BeanInjector {
@Override
public String getModule() {
return "spring-cloud-tencent-lossless-plugin";
}

@Override
public void onBootstrapStartup(Object configurationParser, Constructor<?> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
Object losslessPropertiesBootstrapConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, LosslessPropertiesBootstrapConfiguration.class, "losslessPropertiesBootstrapConfiguration");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@

public class MetadataTransferBeanInjector implements BeanInjector {

@Override
public String getModule() {
return "spring-cloud-starter-tencent-metadata-transfer";
}

@Override
public void onBootstrapStartup(Object configurationParser, Constructor<?> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.polarismesh.agent.core.common.utils.ReflectionUtils;
import cn.polarismesh.agent.plugin.spring.cloud.common.BeanInjector;
Expand All @@ -33,6 +37,18 @@
import org.springframework.core.env.Environment;

public class PolarisContextBeanInjector implements BeanInjector {
@Override
public String getModule() {
return "spring-cloud-tencent-polaris-context";
}

@Override
public Map<String, List<String>> getClassNameForType() {
Map<String, List<String>> values = new HashMap<>();
values.put("org.springframework.context.ApplicationListener", Collections.singletonList("com.tencent.cloud.polaris.context.logging.PolarisLoggingApplicationListener"));
return values;
}

@Override
public void onBootstrapStartup(Object configurationParser,
Constructor<?> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
Expand All @@ -55,13 +71,5 @@ public void onApplicationStartup(Object configurationParser,
ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisContextPostConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
registry.registerBeanDefinition("polarisContextPostConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
PolarisContextPostConfiguration.class).getBeanDefinition());
Object polarisLoggingApplicationListener = ReflectionUtils.invokeConstructor(configClassCreator, PolarisLoggingApplicationListener.class, "polarisLoggingApplicationListener");
ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisLoggingApplicationListener, Constant.DEFAULT_EXCLUSION_FILTER);
registry.registerBeanDefinition("polarisLoggingApplicationListener", BeanDefinitionBuilder.genericBeanDefinition(
PolarisLoggingApplicationListener.class).getBeanDefinition());
// Object polarisSDKContextManager = ReflectionUtils.invokeConstructor(configClassCreator, PolarisSDKContextManager.class, "polarisSDKContextManager");
// ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisSDKContextManager, Constant.DEFAULT_EXCLUSION_FILTER);
// registry.registerBeanDefinition("polarisSDKContextManager", BeanDefinitionBuilder.genericBeanDefinition(
// PolarisSDKContextManager.class).getBeanDefinition());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
import org.springframework.core.env.Environment;

public class RateLimitBeanInjector implements BeanInjector {
@Override
public String getModule() {
return "spring-cloud-starter-tencent-polaris-ratelimit";
}

@Override
public void onBootstrapStartup(Object configurationParser, Constructor<?> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
Object polarisRateLimitPropertiesBootstrapConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisRateLimitPropertiesBootstrapConfiguration.class, "polarisRateLimitPropertiesBootstrapConfiguration");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
import org.springframework.core.env.Environment;

public class RegistryBeanInjector implements BeanInjector {
@Override
public String getModule() {
return "spring-cloud-starter-tencent-polaris-discovery";
}

@Override
public void onBootstrapStartup(Object configurationParser, Constructor<?> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
Object discoveryPropertiesBootstrapAutoConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, DiscoveryPropertiesBootstrapAutoConfiguration.class, "discoveryPropertiesBootstrapAutoConfiguration");
Expand Down Expand Up @@ -65,9 +70,5 @@ public void onApplicationStartup(Object configurationParser, Constructor<?> conf
ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisDiscoveryEndpointAutoConfiguration, Constant.DEFAULT_EXCLUSION_FILTER);
registry.registerBeanDefinition("polarisDiscoveryEndpointAutoConfiguration", BeanDefinitionBuilder.genericBeanDefinition(
PolarisDiscoveryEndpointAutoConfiguration.class).getBeanDefinition());
// Object polarisFeignBeanPostProcessor = ReflectionUtils.invokeConstructor(configClassCreator, PolarisFeignBeanPostProcessor.class, "polarisFeignBeanPostProcessor");
// ReflectionUtils.invokeMethod(processConfigurationClass, configurationParser, polarisFeignBeanPostProcessor, Constant.DEFAULT_EXCLUSION_FILTER);
// registry.registerBeanDefinition("polarisFeignBeanPostProcessor", BeanDefinitionBuilder.genericBeanDefinition(
// PolarisFeignBeanPostProcessor.class).getBeanDefinition());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
import org.springframework.core.io.ClassPathResource;

public class RouterBeanInjector implements BeanInjector {
@Override
public String getModule() {
return "spring-cloud-starter-tencent-polaris-router";
}

@Override
public void onBootstrapStartup(Object configurationParser, Constructor<?> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
import org.springframework.core.env.Environment;

public class RpcEnhancementBeanInjector implements BeanInjector {
@Override
public String getModule() {
return "spring-cloud-tencent-rpc-enhancement";
}

@Override
public void onBootstrapStartup(Object configurationParser, Constructor<?> configClassCreator, Method processConfigurationClass, BeanDefinitionRegistry registry, Environment environment) {
Object polarisStatPropertiesBootstrapConfiguration = ReflectionUtils.invokeConstructor(configClassCreator, PolarisStatPropertiesBootstrapConfiguration.class, "polarisStatPropertiesBootstrapConfiguration");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import cn.polarismesh.agent.plugin.spring.cloud.inject.RegistryBeanInjector;
import cn.polarismesh.agent.plugin.spring.cloud.inject.RouterBeanInjector;
import cn.polarismesh.agent.plugin.spring.cloud.inject.RpcEnhancementBeanInjector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition;
import org.springframework.beans.factory.config.BeanDefinition;
Expand All @@ -49,6 +51,8 @@

public class ConfigurationParserInterceptor implements Interceptor {

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

private final List<BeanInjector> beanInjectors = new ArrayList<>();

public ConfigurationParserInterceptor() {
Expand Down Expand Up @@ -99,8 +103,10 @@ public void after(Object target, Object[] args, Object result, Throwable throwab
BeanDefinitionRegistry registry = (BeanDefinitionRegistry) ReflectionUtils.getObjectByFieldName(target, "registry");
Environment environment = (Environment) ReflectionUtils.getObjectByFieldName(target, "environment");
for (BeanInjector beanInjector : beanInjectors) {
LOGGER.info("[PolarisJavaAgent] start to inject bootstrap bean definitions in module {}", beanInjector.getModule());
beanInjector.onBootstrapStartup(target, constructor, processConfigurationClass, registry, environment);
}
LOGGER.info("[PolarisJavaAgent] successfully injected spring cloud tencent bootstrap bean definitions");

} else if (isMainBeanDefinition(beanDefinitionHolder)) {
Class<?> clazz = ClassUtils.getClazz("org.springframework.context.annotation.ConfigurationClass", null);
Expand All @@ -111,8 +117,10 @@ public void after(Object target, Object[] args, Object result, Throwable throwab
BeanDefinitionRegistry registry = (BeanDefinitionRegistry) ReflectionUtils.getObjectByFieldName(target, "registry");
Environment environment = (Environment) ReflectionUtils.getObjectByFieldName(target, "environment");
for (BeanInjector beanInjector : beanInjectors) {
LOGGER.info("[PolarisJavaAgent] start to inject application bean definitions in module {}", beanInjector.getModule());
beanInjector.onApplicationStartup(target, constructor, processConfigurationClass, registry, environment);
}
LOGGER.info("[PolarisJavaAgent] successfully injected spring cloud tencent application bean definitions");

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@ public void before(Object target, Object[] args) {
return;
}
for (PropertiesPropertySource propertiesPropertySource : propertySources) {
LOGGER.info("[PolarisJavaAgent] start to add propertiesPropertySource {}", propertiesPropertySource.getName());
environment.getPropertySources().addFirst(propertiesPropertySource);
}
LOGGER.info("[PolarisJavaAgent] successfully injected agent properties into environment, size is " + propertySources.size());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@ public void before(Object target, Object[] args) {
}
BeanDefinition beanDefinition = (BeanDefinition) args[1];
beanDefinition.setPrimary(true);
LOGGER.info("[PolarisJavaAgent] bean {} has been made primary", beanName);
}
}
Loading