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 923c54b
Show file tree
Hide file tree
Showing 36 changed files with 348 additions and 282 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,13 @@ 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(
configManager.m_configs, configManager.m_configLocks, configManager.m_configFiles,
configManager.m_configFileLocks);
DefaultApolloRunningParamsCollector startupCollector = new DefaultApolloRunningParamsCollector(
DefaultApolloClientNamespaceCollector namespaceCollector = new DefaultApolloClientNamespaceCollector(
configManager.m_configs, configManager.m_configFiles);
DefaultApolloClientBootstrapArgsCollector startupCollector = new DefaultApolloClientBootstrapArgsCollector(
m_configUtil);

List<MetricsCollector> collectors = Lists.newArrayList(exceptionCollector, namespaceCollector,
Expand All @@ -99,13 +98,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 +117,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,17 +16,15 @@
*/
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.APOLLO_CLIENT_NAMESPACE_USAGE;

import com.ctrip.framework.apollo.Config;
import com.ctrip.framework.apollo.ConfigFile;
import com.ctrip.framework.apollo.build.ApolloInjector;
import com.ctrip.framework.apollo.core.enums.ConfigFileFormat;
import com.ctrip.framework.apollo.monitor.internal.MonitorConstant;
import com.ctrip.framework.apollo.monitor.internal.model.MetricsEvent;
import com.ctrip.framework.apollo.spi.ConfigFactory;
import com.ctrip.framework.apollo.spi.ConfigFactoryManager;
import com.ctrip.framework.apollo.tracer.Tracer;
import com.google.common.collect.Maps;
import java.util.Map;

Expand Down Expand Up @@ -63,9 +61,7 @@ public Config getConfig(String namespace) {
}
}

MetricsEvent.builder().withName(NAMESPACE_USAGE_COUNT)
.putAttachment(MonitorConstant.NAMESPACE, namespace)
.withTag(NAMESPACE_MONITOR).push();
Tracer.logEvent(APOLLO_CLIENT_NAMESPACE_USAGE,namespace);

return config;
}
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,8 +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.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.APOLLO_CLIENT_NAMESPACE_TIMEOUT;

import com.ctrip.framework.apollo.build.ApolloInjector;
import com.ctrip.framework.apollo.core.ConfigConsts;
Expand All @@ -31,8 +31,6 @@
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.model.MetricsEvent;
import com.ctrip.framework.apollo.spi.ConfigServiceLoadBalancerClient;
import com.ctrip.framework.apollo.tracer.Tracer;
import com.ctrip.framework.apollo.tracer.spi.Transaction;
Expand Down Expand Up @@ -219,9 +217,7 @@ 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)
.putAttachment(NAMESPACE, assembleNamespaces())
.withTag(DefaultApolloNamespaceCollector.NAMESPACE_MONITOR).push();
Tracer.logEvent(APOLLO_CLIENT_NAMESPACE_TIMEOUT,assembleNamespaces());
}
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,10 @@
*/
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.APOLLO_CLIENT_NAMESPACE_FIRST_LOAD_SPEND;
import static com.ctrip.framework.apollo.monitor.internal.collector.impl.DefaultApolloClientNamespaceCollector.NAMESPACE_MONITOR;
import static com.ctrip.framework.apollo.monitor.internal.collector.impl.DefaultApolloClientNamespaceCollector.APOLLO_CLIENT_NAMESPACE_NOT_FOUND;

import com.ctrip.framework.apollo.Apollo;
import com.ctrip.framework.apollo.build.ApolloInjector;
Expand All @@ -40,7 +36,6 @@
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.model.MetricsEvent;
import com.ctrip.framework.apollo.tracer.Tracer;
import com.ctrip.framework.apollo.tracer.spi.Transaction;
Expand Down Expand Up @@ -124,10 +119,12 @@ public Properties getConfig() {
if (m_configCache.get() == null) {
long start = System.currentTimeMillis();
this.sync();
MetricsEvent.builder().withName(DefaultApolloNamespaceCollector.NAMESPACE_FIRST_LOAD_SPEND).withTag(
NAMESPACE_MONITOR)
.putAttachment(NAMESPACE, m_namespace)
.putAttachment(TIMESTAMP, System.currentTimeMillis() - start).push();
Tracer.logEvent(APOLLO_CLIENT_NAMESPACE_FIRST_LOAD_SPEND+m_namespace,
String.valueOf(System.currentTimeMillis() - start));
// MetricsEvent.builder().withName(APOLLO_CLIENT_NAMESPACE_FIRST_LOAD_SPEND).withTag(
// NAMESPACE_MONITOR)
// .putAttachment(NAMESPACE, m_namespace)
// .putAttachment(TIMESTAMP, System.currentTimeMillis() - start).push();
}
return transformApolloConfigToProperties(m_configCache.get());
}
Expand Down Expand Up @@ -278,8 +275,8 @@ private ApolloConfig loadApolloConfig() {
appId, cluster, m_namespace);
statusCodeException = new ApolloConfigStatusCodeException(ex.getStatusCode(),
message);
MetricsEvent.builder().withName(DefaultApolloNamespaceCollector.NAMESPACE_NOT_FOUND).withTag(
NAMESPACE_MONITOR).putAttachment(NAMESPACE, m_namespace).push();
Tracer.logEvent(APOLLO_CLIENT_NAMESPACE_NOT_FOUND,m_namespace);

}
Tracer.logEvent(APOLLO_CONFIG_EXCEPTION, ExceptionUtil.getDetailMessage(statusCodeException));
transaction.setStatus(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
@@ -0,0 +1,27 @@
/*
* Copyright 2022 Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.ctrip.framework.apollo.monitor.api;

import com.ctrip.framework.apollo.monitor.internal.collector.jmx.ApolloJmxBootstrapArgsMonitor;
import javax.management.MXBean;

/**
* @author Rawven
*/
public interface ApolloClientBootstrapArgsMonitorApi extends ApolloJmxBootstrapArgsMonitor {

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,16 @@
*/
package com.ctrip.framework.apollo.monitor.api;

import com.ctrip.framework.apollo.monitor.internal.collector.jmx.ApolloJmxExceptionMonitor;
import java.util.List;
import javax.management.MXBean;

/**
* @author Rawven
*/
@MXBean
public interface ApolloExceptionMonitorApi {


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

/**
* get exception details
*/
List<String> getExceptionDetails();
List<Exception> getExceptionList();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2022 Apollo Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.ctrip.framework.apollo.monitor.api;

import com.ctrip.framework.apollo.monitor.internal.collector.impl.DefaultApolloClientNamespaceCollector.NamespaceMetrics;
import com.ctrip.framework.apollo.monitor.internal.collector.jmx.ApolloJmxNamespaceMonitor;
import java.util.Map;

/**
* @author Rawven
*/
public interface ApolloClientNamespaceMonitorApi extends ApolloJmxNamespaceMonitor {

Map<String, NamespaceMetrics> getNamespaceMetrics();

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,13 @@
*/
package com.ctrip.framework.apollo.monitor.api;

import java.util.List;
import com.ctrip.framework.apollo.monitor.internal.collector.jmx.ApolloJmxThreadPoolMonitor;
import javax.management.MXBean;

/**
* @author Rawven
*/
@MXBean
public interface ApolloNamespaceMonitorApi {
public interface ApolloClientThreadPoolMonitorApi extends ApolloJmxThreadPoolMonitor {

String getNamespaceReleaseKey(String namespace);

long getNamespaceUsageCount(String namespace);

String getNamespaceLatestUpdateTime(String namespace);

long getNamespaceFirstLoadSpend(String namespace);

String getNamespace404();

String getNamespaceTimeout();

List<String> getNamespaceItemName(String namespace);

List<String> getAllNamespaceReleaseKey();

List<String> getAllNamespaceUsageCount();

List<String> getAllNamespacesLatestUpdateTime();

List<String> getAllUsedNamespaceName();

List<String> getAllNamespaceFirstLoadSpend();

List<String> getAllNamespaceItemName();
}
Loading

0 comments on commit 923c54b

Please sign in to comment.