Skip to content

Commit

Permalink
feat(client): Add more observability in apollo config client
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawven committed Aug 3, 2024
1 parent bd7fe56 commit 0e0b154
Show file tree
Hide file tree
Showing 32 changed files with 162 additions and 172 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
package com.ctrip.framework.apollo.internals;


import static com.ctrip.framework.apollo.monitor.internal.tracer.MessageProducerComposite.APOLLO_CLIENT_CONFIGCHANGES;

import static com.ctrip.framework.apollo.monitor.internal.MonitorConstant.*;
import com.ctrip.framework.apollo.build.ApolloInjector;
import com.ctrip.framework.apollo.core.utils.DeferredLoggerFactory;
import com.ctrip.framework.apollo.enums.ConfigSourceType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
*/
package com.ctrip.framework.apollo.internals;

import static com.ctrip.framework.apollo.monitor.internal.tracer.MessageProducerComposite.APOLLO_CONFIG_EXCEPTION;

import static com.ctrip.framework.apollo.monitor.internal.MonitorConstant.*;
import com.ctrip.framework.apollo.build.ApolloInjector;
import com.ctrip.framework.apollo.util.factory.PropertiesFactory;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
import com.ctrip.framework.apollo.monitor.internal.DefaultConfigMonitor;
import com.ctrip.framework.apollo.monitor.internal.collector.MetricsCollector;
import com.ctrip.framework.apollo.monitor.internal.collector.MetricsCollectorManager;
import com.ctrip.framework.apollo.monitor.internal.collector.internal.DefaultApolloExceptionCollector;
import com.ctrip.framework.apollo.monitor.internal.collector.internal.DefaultApolloNamespaceCollector;
import com.ctrip.framework.apollo.monitor.internal.collector.internal.DefaultApolloRunningParamsCollector;
import com.ctrip.framework.apollo.monitor.internal.collector.internal.DefaultApolloThreadPoolCollector;
import com.ctrip.framework.apollo.monitor.internal.collector.internal.DefaultMetricsCollectorManager;
import com.ctrip.framework.apollo.monitor.internal.collector.impl.DefaultApolloClientExceptionCollector;
import com.ctrip.framework.apollo.monitor.internal.collector.impl.DefaultApolloClientNamespaceCollector;
import com.ctrip.framework.apollo.monitor.internal.collector.impl.DefaultApolloClientBootstrapArgsCollector;
import com.ctrip.framework.apollo.monitor.internal.collector.impl.DefaultApolloClientThreadPoolCollector;
import com.ctrip.framework.apollo.monitor.internal.collector.impl.DefaultMetricsCollectorManager;
import com.ctrip.framework.apollo.monitor.internal.exporter.MetricsExporter;
import com.ctrip.framework.apollo.monitor.internal.exporter.MetricsExporterFactory;
import com.ctrip.framework.apollo.monitor.internal.tracer.MessageProducerComposite;
import com.ctrip.framework.apollo.monitor.internal.tracer.MonitorMessageProducer;
import com.ctrip.framework.apollo.monitor.internal.tracer.ClientMonitorMessageProducer;
import com.ctrip.framework.apollo.tracer.internals.NullMessageProducer;
import com.ctrip.framework.apollo.tracer.internals.cat.CatMessageProducer;
import com.ctrip.framework.apollo.tracer.internals.cat.CatNames;
Expand Down Expand Up @@ -73,14 +73,14 @@ private static List<MetricsCollector> initializeCollectors(
DefaultMetricsCollectorManager manager) {
DefaultConfigManager configManager = (DefaultConfigManager) ApolloInjector.getInstance(
ConfigManager.class);
DefaultApolloExceptionCollector exceptionCollector = new DefaultApolloExceptionCollector();
DefaultApolloThreadPoolCollector threadPoolCollector = new DefaultApolloThreadPoolCollector(
DefaultApolloClientExceptionCollector exceptionCollector = new DefaultApolloClientExceptionCollector();
DefaultApolloClientThreadPoolCollector threadPoolCollector = new DefaultApolloClientThreadPoolCollector(
RemoteConfigRepository.m_executorService, AbstractConfig.m_executorService,
AbstractConfigFile.m_executorService);
DefaultApolloNamespaceCollector namespaceCollector = new DefaultApolloNamespaceCollector(
DefaultApolloClientNamespaceCollector namespaceCollector = new DefaultApolloClientNamespaceCollector(
configManager.m_configs, configManager.m_configLocks, configManager.m_configFiles,
configManager.m_configFileLocks);
DefaultApolloRunningParamsCollector startupCollector = new DefaultApolloRunningParamsCollector(
DefaultApolloClientBootstrapArgsCollector startupCollector = new DefaultApolloClientBootstrapArgsCollector(
m_configUtil);

List<MetricsCollector> collectors = Lists.newArrayList(exceptionCollector, namespaceCollector,
Expand All @@ -99,13 +99,13 @@ private static void initializeConfigMonitor(List<MetricsCollector> collectors,
MetricsExporter metricsExporter) {
DefaultConfigMonitor defaultConfigMonitor = (DefaultConfigMonitor) ApolloInjector.getInstance(
ConfigMonitor.class);
DefaultApolloExceptionCollector exceptionCollector = (DefaultApolloExceptionCollector) collectors.get(
DefaultApolloClientExceptionCollector exceptionCollector = (DefaultApolloClientExceptionCollector) collectors.get(
0);
DefaultApolloNamespaceCollector namespaceCollector = (DefaultApolloNamespaceCollector) collectors.get(
DefaultApolloClientNamespaceCollector namespaceCollector = (DefaultApolloClientNamespaceCollector) collectors.get(
1);
DefaultApolloThreadPoolCollector threadPoolCollector = (DefaultApolloThreadPoolCollector) collectors.get(
DefaultApolloClientThreadPoolCollector threadPoolCollector = (DefaultApolloClientThreadPoolCollector) collectors.get(
2);
DefaultApolloRunningParamsCollector startupCollector = (DefaultApolloRunningParamsCollector) collectors.get(
DefaultApolloClientBootstrapArgsCollector startupCollector = (DefaultApolloClientBootstrapArgsCollector) collectors.get(
3);
defaultConfigMonitor.init(namespaceCollector, threadPoolCollector, exceptionCollector,
startupCollector, metricsExporter);
Expand All @@ -118,7 +118,7 @@ public static MessageProducerComposite initializeMessageProducerComposite() {

// The producer that comes with the client
if (m_configUtil.isClientMonitorEnabled()) {
producers.add(new MonitorMessageProducer());
producers.add(new ClientMonitorMessageProducer());
}

if (ClassLoaderUtil.isClassPresent(CatNames.CAT_CLASS)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
*/
package com.ctrip.framework.apollo.internals;

import static com.ctrip.framework.apollo.monitor.internal.tracer.MessageProducerComposite.APOLLO_CONFIG_EXCEPTION;
import static com.ctrip.framework.apollo.monitor.internal.tracer.MessageProducerComposite.APOLLO_CONFIG_SERVICES;
import static com.ctrip.framework.apollo.monitor.internal.tracer.MessageProducerComposite.APOLLO_META_SERVICE;

import static com.ctrip.framework.apollo.monitor.internal.MonitorConstant.*;
import com.ctrip.framework.apollo.build.ApolloInjector;
import com.ctrip.framework.apollo.core.ApolloClientSystemConsts;
import com.ctrip.framework.apollo.core.ServiceNameConsts;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
*/
package com.ctrip.framework.apollo.internals;

import static com.ctrip.framework.apollo.monitor.internal.tracer.MessageProducerComposite.APOLLO_CLIENT_CONFIGCHANGES;

import static com.ctrip.framework.apollo.monitor.internal.MonitorConstant.*;
import com.ctrip.framework.apollo.core.utils.DeferredLoggerFactory;
import com.ctrip.framework.apollo.enums.ConfigSourceType;
import com.google.common.collect.Maps;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
*/
package com.ctrip.framework.apollo.internals;

import static com.ctrip.framework.apollo.monitor.internal.collector.internal.DefaultApolloNamespaceCollector.NAMESPACE_MONITOR;
import static com.ctrip.framework.apollo.monitor.internal.collector.internal.DefaultApolloNamespaceCollector.NAMESPACE_USAGE_COUNT;
import static com.ctrip.framework.apollo.monitor.internal.collector.impl.DefaultApolloClientNamespaceCollector.NAMESPACE_MONITOR;
import static com.ctrip.framework.apollo.monitor.internal.collector.impl.DefaultApolloClientNamespaceCollector.NAMESPACE_USAGE_COUNT;

import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigFile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import com.ctrip.framework.apollo.exceptions.ApolloConfigException;
import com.ctrip.framework.apollo.monitor.api.ConfigMonitor;
import com.ctrip.framework.apollo.monitor.internal.DefaultConfigMonitor;
import com.ctrip.framework.apollo.monitor.internal.exporter.internals.DefaultMetricsExporterFactory;
import com.ctrip.framework.apollo.monitor.internal.exporter.impl.DefaultMetricsExporterFactory;
import com.ctrip.framework.apollo.monitor.internal.collector.MetricsCollectorManager;
import com.ctrip.framework.apollo.monitor.internal.collector.internal.DefaultMetricsCollectorManager;
import com.ctrip.framework.apollo.monitor.internal.collector.impl.DefaultMetricsCollectorManager;
import com.ctrip.framework.apollo.monitor.internal.exporter.MetricsExporterFactory;
import com.ctrip.framework.apollo.spi.ApolloInjectorCustomizer;
import com.ctrip.framework.apollo.spi.ConfigFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
*/
package com.ctrip.framework.apollo.internals;

import static com.ctrip.framework.apollo.monitor.internal.tracer.MessageProducerComposite.APOLLO_CONFIG_EXCEPTION;

import static com.ctrip.framework.apollo.monitor.internal.MonitorConstant.*;
import com.ctrip.framework.apollo.core.utils.DeferredLoggerFactory;
import com.ctrip.framework.apollo.enums.ConfigSourceType;
import java.io.File;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
*/
package com.ctrip.framework.apollo.internals;

import static com.ctrip.framework.apollo.monitor.internal.MonitorConstant.NAMESPACE;
import static com.ctrip.framework.apollo.monitor.internal.tracer.MessageProducerComposite.APOLLO_CONFIG_EXCEPTION;

import static com.ctrip.framework.apollo.monitor.internal.MonitorConstant.*;
import com.ctrip.framework.apollo.build.ApolloInjector;
import com.ctrip.framework.apollo.core.ConfigConsts;
import com.ctrip.framework.apollo.core.dto.ApolloConfigNotification;
Expand All @@ -31,7 +29,7 @@
import com.ctrip.framework.apollo.core.utils.ApolloThreadFactory;
import com.ctrip.framework.apollo.core.utils.StringUtils;
import com.ctrip.framework.apollo.exceptions.ApolloConfigException;
import com.ctrip.framework.apollo.monitor.internal.collector.internal.DefaultApolloNamespaceCollector;
import com.ctrip.framework.apollo.monitor.internal.collector.impl.DefaultApolloClientNamespaceCollector;
import com.ctrip.framework.apollo.monitor.internal.model.MetricsEvent;
import com.ctrip.framework.apollo.spi.ConfigServiceLoadBalancerClient;
import com.ctrip.framework.apollo.tracer.Tracer;
Expand Down Expand Up @@ -219,9 +217,9 @@ private void doLongPollingRefresh(String appId, String cluster, String dataCente
transaction.setStatus(ex);
long sleepTimeInSecond = m_longPollFailSchedulePolicyInSecond.fail();
if (ex.getCause() instanceof SocketTimeoutException) {
MetricsEvent.builder().withName(DefaultApolloNamespaceCollector.NAMESPACE_TIMEOUT)
MetricsEvent.builder().withName(DefaultApolloClientNamespaceCollector.NAMESPACE_TIMEOUT)
.putAttachment(NAMESPACE, assembleNamespaces())
.withTag(DefaultApolloNamespaceCollector.NAMESPACE_MONITOR).push();
.withTag(DefaultApolloClientNamespaceCollector.NAMESPACE_MONITOR).push();
}
logger.warn(
"Long polling failed, will retry in {} seconds. appId: {}, cluster: {}, namespaces: {}, long polling url: {}, reason: {}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,8 @@
*/
package com.ctrip.framework.apollo.internals;

import static com.ctrip.framework.apollo.monitor.internal.MonitorConstant.NAMESPACE;
import static com.ctrip.framework.apollo.monitor.internal.MonitorConstant.TIMESTAMP;
import static com.ctrip.framework.apollo.monitor.internal.collector.internal.DefaultApolloNamespaceCollector.NAMESPACE_MONITOR;
import static com.ctrip.framework.apollo.monitor.internal.tracer.MessageProducerComposite.APOLLO_CLIENT_CONFIGS;
import static com.ctrip.framework.apollo.monitor.internal.tracer.MessageProducerComposite.APOLLO_CLIENT_CONFIGMETA;
import static com.ctrip.framework.apollo.monitor.internal.tracer.MessageProducerComposite.APOLLO_CLIENT_VERSION;
import static com.ctrip.framework.apollo.monitor.internal.tracer.MessageProducerComposite.APOLLO_CONFIGSERVICE;
import static com.ctrip.framework.apollo.monitor.internal.tracer.MessageProducerComposite.APOLLO_CONFIG_EXCEPTION;
import static com.ctrip.framework.apollo.monitor.internal.MonitorConstant.*;
import static com.ctrip.framework.apollo.monitor.internal.collector.impl.DefaultApolloClientNamespaceCollector.NAMESPACE_MONITOR;

import com.ctrip.framework.apollo.Apollo;
import com.ctrip.framework.apollo.build.ApolloInjector;
Expand All @@ -40,7 +34,7 @@
import com.ctrip.framework.apollo.enums.ConfigSourceType;
import com.ctrip.framework.apollo.exceptions.ApolloConfigException;
import com.ctrip.framework.apollo.exceptions.ApolloConfigStatusCodeException;
import com.ctrip.framework.apollo.monitor.internal.collector.internal.DefaultApolloNamespaceCollector;
import com.ctrip.framework.apollo.monitor.internal.collector.impl.DefaultApolloClientNamespaceCollector;
import com.ctrip.framework.apollo.monitor.internal.model.MetricsEvent;
import com.ctrip.framework.apollo.tracer.Tracer;
import com.ctrip.framework.apollo.tracer.spi.Transaction;
Expand Down Expand Up @@ -124,7 +118,7 @@ public Properties getConfig() {
if (m_configCache.get() == null) {
long start = System.currentTimeMillis();
this.sync();
MetricsEvent.builder().withName(DefaultApolloNamespaceCollector.NAMESPACE_FIRST_LOAD_SPEND).withTag(
MetricsEvent.builder().withName(DefaultApolloClientNamespaceCollector.NAMESPACE_FIRST_LOAD_SPEND).withTag(
NAMESPACE_MONITOR)
.putAttachment(NAMESPACE, m_namespace)
.putAttachment(TIMESTAMP, System.currentTimeMillis() - start).push();
Expand Down Expand Up @@ -278,7 +272,7 @@ private ApolloConfig loadApolloConfig() {
appId, cluster, m_namespace);
statusCodeException = new ApolloConfigStatusCodeException(ex.getStatusCode(),
message);
MetricsEvent.builder().withName(DefaultApolloNamespaceCollector.NAMESPACE_NOT_FOUND).withTag(
MetricsEvent.builder().withName(DefaultApolloClientNamespaceCollector.NAMESPACE_NOT_FOUND).withTag(
NAMESPACE_MONITOR).putAttachment(NAMESPACE, m_namespace).push();
}
Tracer.logEvent(APOLLO_CONFIG_EXCEPTION, ExceptionUtil.getDetailMessage(statusCodeException));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
*/
package com.ctrip.framework.apollo.internals;

import static com.ctrip.framework.apollo.monitor.internal.tracer.MessageProducerComposite.APOLLO_CLIENT_CONFIGCHANGES;

import static com.ctrip.framework.apollo.monitor.internal.MonitorConstant.*;
import com.ctrip.framework.apollo.enums.ConfigSourceType;
import java.util.Collections;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
*/
package com.ctrip.framework.apollo.internals;

import static com.ctrip.framework.apollo.monitor.internal.tracer.MessageProducerComposite.APOLLO_CONFIG_EXCEPTION;

import static com.ctrip.framework.apollo.monitor.internal.MonitorConstant.*;
import com.ctrip.framework.apollo.util.ExceptionUtil;
import java.util.Properties;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @author Rawven
*/
@MXBean
public interface ApolloRunningParamsMonitorApi {
public interface ApolloClientBootstrapArgsMonitorApi {

String getStartupParams(String key);

Expand Down Expand Up @@ -54,7 +54,7 @@ public interface ApolloRunningParamsMonitorApi {

long getClientMonitorExternalExportPeriod();

String getMeta();
String getApolloMeta();

String getMetaLatestFreshTime();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,10 @@
* @author Rawven
*/
@MXBean
public interface ApolloExceptionMonitorApi {


/**
* get the number of exceptions
*/
Integer getExceptionNum();
public interface ApolloClientExceptionMonitorApi {

/**
* get exception details
*/
List<String> getExceptionDetails();
List<Exception> getExceptionList();
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@
*/
package com.ctrip.framework.apollo.monitor.api;

import com.ctrip.framework.apollo.monitor.internal.collector.impl.DefaultApolloClientNamespaceCollector.NamespaceMetrics;
import java.util.List;
import java.util.Map;
import javax.management.MXBean;

/**
* @author Rawven
*/
@MXBean
public interface ApolloNamespaceMonitorApi {
public interface ApolloClientNamespaceMonitorApi {

Map<String, NamespaceMetrics> getNamespaceMetrics();

String getNamespaceReleaseKey(String namespace);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @author Rawven
*/
@MXBean
public interface ApolloThreadPoolMonitorApi {
public interface ApolloClientThreadPoolMonitorApi {


int getRemoteConfigRepositoryThreadPoolActiveCount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
*/
public interface ConfigMonitor {

ApolloThreadPoolMonitorApi getThreadPoolMonitorApi();
ApolloClientThreadPoolMonitorApi getThreadPoolMonitorApi();

ApolloExceptionMonitorApi getExceptionMonitorApi();
ApolloClientExceptionMonitorApi getExceptionMonitorApi();

ApolloNamespaceMonitorApi getNamespaceMonitorApi();
ApolloClientNamespaceMonitorApi getNamespaceMonitorApi();

ApolloRunningParamsMonitorApi getRunningParamsMonitorApi();
ApolloClientBootstrapArgsMonitorApi getRunningParamsMonitorApi();

String getDataWithCurrentMonitoringSystemFormat();
String getExporterData();
}
Loading

0 comments on commit 0e0b154

Please sign in to comment.