Skip to content

Commit

Permalink
fix: hoxton agent support polaris logging and support stat properties (
Browse files Browse the repository at this point in the history
…#136)

* fix: hoxton agent support polaris logging

* fix: support stat properties

---------

Co-authored-by: shedfreewu <shedfreewu@tencent.com>
  • Loading branch information
shedfreewu and shedfreez authored Mar 15, 2024
1 parent 617b068 commit a627b57
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 176 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
import com.tencent.cloud.polaris.context.PolarisConfigModifier;
import com.tencent.cloud.polaris.context.PolarisSDKContextManager;
import com.tencent.cloud.polaris.context.config.PolarisContextProperties;
import com.tencent.cloud.rpc.enhancement.stat.config.PolarisStatProperties;
import com.tencent.cloud.rpc.enhancement.stat.config.StatConfigModifier;
import com.tencent.polaris.api.utils.StringUtils;
import com.tencent.polaris.logging.LoggingConsts;
import com.tencent.polaris.logging.PolarisLogging;

import org.springframework.boot.context.properties.bind.Bindable;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.cloud.client.HostInfoEnvironmentPostProcessor;
Expand All @@ -53,6 +54,8 @@ public class Holder {

private static StaticMetadataManager staticMetadataManager;

private static PolarisStatProperties polarisStatProperties;

private static PolarisContextProperties polarisContextProperties;

private static LosslessProperties losslessProperties;
Expand All @@ -69,6 +72,7 @@ private static void initProperties() {
polarisContextProperties = new PolarisContextProperties();
localProperties = new MetadataLocalProperties();
losslessProperties = new LosslessProperties();
polarisStatProperties = new PolarisStatProperties();
}

public static void init() {
Expand All @@ -84,6 +88,9 @@ public static void init() {
bindObject("spring.cloud.polaris", polarisContextProperties, environment);
staticMetadataManager = new StaticMetadataManager(localProperties, null);

// 监控
bindObject("spring.cloud.polaris.stat", polarisStatProperties, environment);

// lossless
bindObject("spring.cloud.polaris.lossless", losslessProperties, environment);

Expand Down Expand Up @@ -129,28 +136,13 @@ private static void bindObject(String prefix, Object bean, Environment environme

private static void runConfigModifiers(Environment environment) throws IOException {

String logConfig = "";
try {
Class.forName(PolarisLogging.LOGBACK_CLASSIC_LOGGER);
logConfig = Holder.class.getClassLoader().getResource("polaris-logback.xml").getFile();
}
catch (ClassNotFoundException e) {
try {
Class.forName(PolarisLogging.LOG4J2_CLASSIC_LOGGER);
logConfig = Holder.class.getClassLoader().getResource("polaris-log4j2.xml").getFile();
}
catch (ClassNotFoundException e1) {
logConfig = Holder.class.getClassLoader().getResource("polaris-log4j.xml").getFile();
}
}
System.setProperty(LoggingConsts.LOGGING_CONFIG_PROPERTY, logConfig);

if (StringUtils.isBlank(polarisContextProperties.getLocalIpAddress())) {
polarisContextProperties.setLocalIpAddress(environment.getProperty("spring.cloud.client.ip-address"));
}

List<PolarisConfigModifier> modifiers = new ArrayList<>(Arrays.asList(
new ModifyAddress(polarisContextProperties),
new StatConfigModifier(polarisStatProperties, environment),
new LosslessConfigModifier(losslessProperties)
));

Expand All @@ -162,6 +154,10 @@ public static Environment getEnvironment() {
return environment;
}

public static PolarisStatProperties getPolarisStatProperties() {
return polarisStatProperties;
}

public static MetadataLocalProperties getLocalProperties() {
return localProperties;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
import cn.polarismesh.agent.plugin.spring.cloud.common.Holder;
import cn.polarismesh.agent.plugin.spring.cloud.interceptor.BaseInterceptor;
import com.tencent.cloud.common.util.ApplicationContextAwareUtils;
import com.tencent.polaris.api.utils.StringUtils;
import com.tencent.polaris.logging.LoggingConsts;
import com.tencent.polaris.logging.PolarisLogging;

import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
Expand All @@ -42,5 +46,12 @@ public void onAfter(Object target, Object[] args, Object result, Throwable throw

// 设置为真正的 ApplicationContext
utils.setApplicationContext(context);

// init polaris logging
String loggingPath = Holder.getEnvironment().getProperty("spring.cloud.polaris.logging.path");
if (StringUtils.isNotBlank(loggingPath)) {
System.setProperty(LoggingConsts.LOGGING_PATH_PROPERTY, loggingPath);
}
PolarisLogging.getInstance().loadConfiguration();
}
}

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit a627b57

Please sign in to comment.