From 0e0b154cd6e24e77fade74b93ebdf8fc784e7496 Mon Sep 17 00:00:00 2001 From: liu Date: Sat, 3 Aug 2024 13:52:05 +0800 Subject: [PATCH] feat(client): Add more observability in apollo config client --- .../apollo/internals/AbstractConfigFile.java | 3 +- .../internals/AbstractConfigRepository.java | 3 +- .../internals/ConfigMonitorInitializer.java | 30 ++++++------- .../internals/ConfigServiceLocator.java | 5 +-- .../apollo/internals/DefaultConfig.java | 3 +- .../internals/DefaultConfigManager.java | 4 +- .../apollo/internals/DefaultInjector.java | 4 +- .../internals/LocalFileConfigRepository.java | 3 +- .../RemoteConfigLongPollService.java | 10 ++--- .../internals/RemoteConfigRepository.java | 16 +++---- .../apollo/internals/SimpleConfig.java | 3 +- .../apollo/internals/YamlConfigFile.java | 3 +- ... ApolloClientBootstrapArgsMonitorApi.java} | 4 +- ...a => ApolloClientExceptionMonitorApi.java} | 10 +---- ...a => ApolloClientNamespaceMonitorApi.java} | 6 ++- ... => ApolloClientThreadPoolMonitorApi.java} | 2 +- .../apollo/monitor/api/ConfigMonitor.java | 10 ++--- .../internal/DefaultConfigMonitor.java | 42 +++++++++---------- .../monitor/internal/MonitorConstant.java | 11 +++++ ...=> NullClientBootstrapArgsMonitorApi.java} | 6 +-- ...ava => NullClientExceptionMonitorApi.java} | 13 +++--- ...ava => NullClientNamespaceMonitorApi.java} | 14 ++++++- ...va => NullClientThreadPoolMonitorApi.java} | 4 +- ...ltApolloClientBootstrapArgsCollector.java} | 12 +++--- ...efaultApolloClientExceptionCollector.java} | 26 +++++------- ...efaultApolloClientNamespaceCollector.java} | 17 +++++--- ...faultApolloClientThreadPoolCollector.java} | 10 ++--- .../DefaultMetricsCollectorManager.java | 2 +- .../DefaultMetricsExporterFactory.java | 4 +- ...java => ClientMonitorMessageProducer.java} | 40 +++++++++--------- .../tracer/MessageProducerComposite.java | 12 +----- ...faultApolloMetricsExporterFactoryTest.java | 2 +- 32 files changed, 162 insertions(+), 172 deletions(-) rename apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/api/{ApolloRunningParamsMonitorApi.java => ApolloClientBootstrapArgsMonitorApi.java} (94%) rename apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/api/{ApolloExceptionMonitorApi.java => ApolloClientExceptionMonitorApi.java} (82%) rename apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/api/{ApolloNamespaceMonitorApi.java => ApolloClientNamespaceMonitorApi.java} (84%) rename apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/api/{ApolloThreadPoolMonitorApi.java => ApolloClientThreadPoolMonitorApi.java} (97%) rename apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/{NullRunningParamsMonitorApi.java => NullClientBootstrapArgsMonitorApi.java} (91%) rename apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/{NullExceptionMonitorApi.java => NullClientExceptionMonitorApi.java} (74%) rename apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/{NullNamespaceMonitorApi.java => NullClientNamespaceMonitorApi.java} (81%) rename apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/{NullThreadPoolMonitorApi.java => NullClientThreadPoolMonitorApi.java} (95%) rename apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/collector/{internal/DefaultApolloRunningParamsCollector.java => impl/DefaultApolloClientBootstrapArgsCollector.java} (95%) rename apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/collector/{internal/DefaultApolloExceptionCollector.java => impl/DefaultApolloClientExceptionCollector.java} (72%) rename apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/collector/{internal/DefaultApolloNamespaceCollector.java => impl/DefaultApolloClientNamespaceCollector.java} (95%) rename apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/collector/{internal/DefaultApolloThreadPoolCollector.java => impl/DefaultApolloClientThreadPoolCollector.java} (96%) rename apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/collector/{internal => impl}/DefaultMetricsCollectorManager.java (94%) rename apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/exporter/{internals => impl}/DefaultMetricsExporterFactory.java (94%) rename apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/tracer/{MonitorMessageProducer.java => ClientMonitorMessageProducer.java} (73%) diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/AbstractConfigFile.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/AbstractConfigFile.java index 8fc574cf..7a2d8fb2 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/AbstractConfigFile.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/AbstractConfigFile.java @@ -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; diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/AbstractConfigRepository.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/AbstractConfigRepository.java index 62d3e9ab..c194f1a4 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/AbstractConfigRepository.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/AbstractConfigRepository.java @@ -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; diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/ConfigMonitorInitializer.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/ConfigMonitorInitializer.java index 8256125b..7d7f78b3 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/ConfigMonitorInitializer.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/ConfigMonitorInitializer.java @@ -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; @@ -73,14 +73,14 @@ private static List 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 collectors = Lists.newArrayList(exceptionCollector, namespaceCollector, @@ -99,13 +99,13 @@ private static void initializeConfigMonitor(List 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); @@ -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)) { diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/ConfigServiceLocator.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/ConfigServiceLocator.java index 281e440e..8391f208 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/ConfigServiceLocator.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/ConfigServiceLocator.java @@ -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; diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/DefaultConfig.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/DefaultConfig.java index b859e32e..0497b3e5 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/DefaultConfig.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/DefaultConfig.java @@ -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; diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/DefaultConfigManager.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/DefaultConfigManager.java index 54243307..f050f52b 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/DefaultConfigManager.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/DefaultConfigManager.java @@ -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; diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/DefaultInjector.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/DefaultInjector.java index 8aae65e0..9903a63c 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/DefaultInjector.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/DefaultInjector.java @@ -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; diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/LocalFileConfigRepository.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/LocalFileConfigRepository.java index 13ca7929..ce9517f2 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/LocalFileConfigRepository.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/LocalFileConfigRepository.java @@ -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; diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigLongPollService.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigLongPollService.java index 1ab51080..b8eb7436 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigLongPollService.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigLongPollService.java @@ -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; @@ -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; @@ -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: {}", diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java index 6ca75336..aafa723c 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/RemoteConfigRepository.java @@ -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; @@ -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; @@ -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(); @@ -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)); diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/SimpleConfig.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/SimpleConfig.java index 10ba29af..3ec0cb99 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/SimpleConfig.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/SimpleConfig.java @@ -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; diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/YamlConfigFile.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/YamlConfigFile.java index d7757895..bd7905c8 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/YamlConfigFile.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/YamlConfigFile.java @@ -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; diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/api/ApolloRunningParamsMonitorApi.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/api/ApolloClientBootstrapArgsMonitorApi.java similarity index 94% rename from apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/api/ApolloRunningParamsMonitorApi.java rename to apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/api/ApolloClientBootstrapArgsMonitorApi.java index ff9e2205..766c2515 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/api/ApolloRunningParamsMonitorApi.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/api/ApolloClientBootstrapArgsMonitorApi.java @@ -22,7 +22,7 @@ * @author Rawven */ @MXBean -public interface ApolloRunningParamsMonitorApi { +public interface ApolloClientBootstrapArgsMonitorApi { String getStartupParams(String key); @@ -54,7 +54,7 @@ public interface ApolloRunningParamsMonitorApi { long getClientMonitorExternalExportPeriod(); - String getMeta(); + String getApolloMeta(); String getMetaLatestFreshTime(); diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/api/ApolloExceptionMonitorApi.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/api/ApolloClientExceptionMonitorApi.java similarity index 82% rename from apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/api/ApolloExceptionMonitorApi.java rename to apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/api/ApolloClientExceptionMonitorApi.java index 6a826a56..6a069b68 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/api/ApolloExceptionMonitorApi.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/api/ApolloClientExceptionMonitorApi.java @@ -23,16 +23,10 @@ * @author Rawven */ @MXBean -public interface ApolloExceptionMonitorApi { - - - /** - * get the number of exceptions - */ - Integer getExceptionNum(); +public interface ApolloClientExceptionMonitorApi { /** * get exception details */ - List getExceptionDetails(); + List getExceptionList(); } diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/api/ApolloNamespaceMonitorApi.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/api/ApolloClientNamespaceMonitorApi.java similarity index 84% rename from apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/api/ApolloNamespaceMonitorApi.java rename to apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/api/ApolloClientNamespaceMonitorApi.java index d9ce8ee9..874313da 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/api/ApolloNamespaceMonitorApi.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/api/ApolloClientNamespaceMonitorApi.java @@ -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 getNamespaceMetrics(); String getNamespaceReleaseKey(String namespace); diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/api/ApolloThreadPoolMonitorApi.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/api/ApolloClientThreadPoolMonitorApi.java similarity index 97% rename from apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/api/ApolloThreadPoolMonitorApi.java rename to apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/api/ApolloClientThreadPoolMonitorApi.java index 33c09e77..b10cb000 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/api/ApolloThreadPoolMonitorApi.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/api/ApolloClientThreadPoolMonitorApi.java @@ -22,7 +22,7 @@ * @author Rawven */ @MXBean -public interface ApolloThreadPoolMonitorApi { +public interface ApolloClientThreadPoolMonitorApi { int getRemoteConfigRepositoryThreadPoolActiveCount(); diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/api/ConfigMonitor.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/api/ConfigMonitor.java index 898f7739..a808cfb0 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/api/ConfigMonitor.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/api/ConfigMonitor.java @@ -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(); } diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/DefaultConfigMonitor.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/DefaultConfigMonitor.java index cbd33505..a71ad1f7 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/DefaultConfigMonitor.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/DefaultConfigMonitor.java @@ -16,10 +16,10 @@ */ package com.ctrip.framework.apollo.monitor.internal; -import com.ctrip.framework.apollo.monitor.api.ApolloExceptionMonitorApi; -import com.ctrip.framework.apollo.monitor.api.ApolloNamespaceMonitorApi; -import com.ctrip.framework.apollo.monitor.api.ApolloRunningParamsMonitorApi; -import com.ctrip.framework.apollo.monitor.api.ApolloThreadPoolMonitorApi; +import com.ctrip.framework.apollo.monitor.api.ApolloClientBootstrapArgsMonitorApi; +import com.ctrip.framework.apollo.monitor.api.ApolloClientExceptionMonitorApi; +import com.ctrip.framework.apollo.monitor.api.ApolloClientNamespaceMonitorApi; +import com.ctrip.framework.apollo.monitor.api.ApolloClientThreadPoolMonitorApi; import com.ctrip.framework.apollo.monitor.api.ConfigMonitor; import com.ctrip.framework.apollo.monitor.internal.exporter.MetricsExporter; @@ -31,48 +31,48 @@ public class DefaultConfigMonitor implements ConfigMonitor { private MetricsExporter reporter; - private ApolloThreadPoolMonitorApi threadPoolMonitorApi = new NullThreadPoolMonitorApi(); - private ApolloExceptionMonitorApi exceptionMonitorApi = new NullExceptionMonitorApi(); - private ApolloNamespaceMonitorApi apolloNamespaceMonitorApi = new NullNamespaceMonitorApi(); - private ApolloRunningParamsMonitorApi apolloRunningParamsMonitorApi = new NullRunningParamsMonitorApi(); + private ApolloClientThreadPoolMonitorApi threadPoolMonitorApi = new NullClientThreadPoolMonitorApi(); + private ApolloClientExceptionMonitorApi exceptionMonitorApi = new NullClientExceptionMonitorApi(); + private ApolloClientNamespaceMonitorApi apolloClientNamespaceMonitorApi = new NullClientNamespaceMonitorApi(); + private ApolloClientBootstrapArgsMonitorApi apolloClientBootstrapArgsMonitorApi = new NullClientBootstrapArgsMonitorApi(); @Override - public ApolloThreadPoolMonitorApi getThreadPoolMonitorApi() { + public ApolloClientThreadPoolMonitorApi getThreadPoolMonitorApi() { return threadPoolMonitorApi; } @Override - public ApolloExceptionMonitorApi getExceptionMonitorApi() { + public ApolloClientExceptionMonitorApi getExceptionMonitorApi() { return exceptionMonitorApi; } @Override - public ApolloNamespaceMonitorApi getNamespaceMonitorApi() { - return apolloNamespaceMonitorApi; + public ApolloClientNamespaceMonitorApi getNamespaceMonitorApi() { + return apolloClientNamespaceMonitorApi; } @Override - public ApolloRunningParamsMonitorApi getRunningParamsMonitorApi() { - return apolloRunningParamsMonitorApi; + public ApolloClientBootstrapArgsMonitorApi getRunningParamsMonitorApi() { + return apolloClientBootstrapArgsMonitorApi; } @Override - public String getDataWithCurrentMonitoringSystemFormat() { + public String getExporterData() { if (reporter == null) { return "No MonitoringSystem Use"; } return reporter.response(); } - public void init(ApolloNamespaceMonitorApi apolloNamespaceMonitorApi, - ApolloThreadPoolMonitorApi threadPoolMonitorApi, - ApolloExceptionMonitorApi exceptionMonitorApi, - ApolloRunningParamsMonitorApi apolloRunningParamsMonitorApi, + public void init(ApolloClientNamespaceMonitorApi apolloClientNamespaceMonitorApi, + ApolloClientThreadPoolMonitorApi threadPoolMonitorApi, + ApolloClientExceptionMonitorApi exceptionMonitorApi, + ApolloClientBootstrapArgsMonitorApi apolloClientBootstrapArgsMonitorApi, MetricsExporter reporter) { - this.apolloNamespaceMonitorApi = apolloNamespaceMonitorApi; + this.apolloClientNamespaceMonitorApi = apolloClientNamespaceMonitorApi; this.threadPoolMonitorApi = threadPoolMonitorApi; this.exceptionMonitorApi = exceptionMonitorApi; - this.apolloRunningParamsMonitorApi = apolloRunningParamsMonitorApi; + this.apolloClientBootstrapArgsMonitorApi = apolloClientBootstrapArgsMonitorApi; this.reporter = reporter; } } diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/MonitorConstant.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/MonitorConstant.java index ea289e1f..b2252693 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/MonitorConstant.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/MonitorConstant.java @@ -26,4 +26,15 @@ public class MonitorConstant { public static final String NAMESPACE = "namespace"; public static final String TIMESTAMP = "timestamp"; public static final String MBEAN_NAME = "apollo.client.monitor:type="; + public static final String ERROR_METRICS = "errorMetrics"; + public static final String THROWABLE = ERROR_METRICS + ".throwable"; + public static final String APOLLO_CLIENT_CONFIGCHANGES = "Apollo.Client.ConfigChanges"; + public static final String APOLLO_CONFIG_EXCEPTION = "ApolloConfigException"; + public static final String APOLLO_META_SERVICE = "Apollo.MetaService"; + public static final String APOLLO_CONFIG_SERVICES = "Apollo.Config.Services"; + public static final String APOLLO_CLIENT_VERSION = "Apollo.Client.Version"; + public static final String APOLLO_CONFIGSERVICE = "Apollo.ConfigService"; + public static final String APOLLO_CLIENT_CONFIGS = "Apollo.Client.Configs."; + public static final String APOLLO_CLIENT_CONFIGMETA = "Apollo.Client.ConfigMeta"; + public static final String HELP_STR = "periodicRefresh: "; } diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/NullRunningParamsMonitorApi.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/NullClientBootstrapArgsMonitorApi.java similarity index 91% rename from apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/NullRunningParamsMonitorApi.java rename to apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/NullClientBootstrapArgsMonitorApi.java index d5a019d5..71af4f99 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/NullRunningParamsMonitorApi.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/NullClientBootstrapArgsMonitorApi.java @@ -16,9 +16,9 @@ */ package com.ctrip.framework.apollo.monitor.internal; -import com.ctrip.framework.apollo.monitor.api.ApolloRunningParamsMonitorApi; +import com.ctrip.framework.apollo.monitor.api.ApolloClientBootstrapArgsMonitorApi; -public class NullRunningParamsMonitorApi implements ApolloRunningParamsMonitorApi { +public class NullClientBootstrapArgsMonitorApi implements ApolloClientBootstrapArgsMonitorApi { @Override public String getStartupParams(String key) { @@ -96,7 +96,7 @@ public long getClientMonitorExternalExportPeriod() { } @Override - public String getMeta() { + public String getApolloMeta() { return ""; } diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/NullExceptionMonitorApi.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/NullClientExceptionMonitorApi.java similarity index 74% rename from apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/NullExceptionMonitorApi.java rename to apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/NullClientExceptionMonitorApi.java index d700baee..33074e63 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/NullExceptionMonitorApi.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/NullClientExceptionMonitorApi.java @@ -16,19 +16,18 @@ */ package com.ctrip.framework.apollo.monitor.internal; -import com.ctrip.framework.apollo.monitor.api.ApolloExceptionMonitorApi; +import com.ctrip.framework.apollo.monitor.api.ApolloClientExceptionMonitorApi; import java.util.Collections; import java.util.List; -public class NullExceptionMonitorApi implements ApolloExceptionMonitorApi { +/** + * @author Rawven + */ +public class NullClientExceptionMonitorApi implements ApolloClientExceptionMonitorApi { - @Override - public Integer getExceptionNum() { - return 0; - } @Override - public List getExceptionDetails() { + public List getExceptionList() { return Collections.emptyList(); } } diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/NullNamespaceMonitorApi.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/NullClientNamespaceMonitorApi.java similarity index 81% rename from apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/NullNamespaceMonitorApi.java rename to apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/NullClientNamespaceMonitorApi.java index 5377b6d9..42400d82 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/NullNamespaceMonitorApi.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/NullClientNamespaceMonitorApi.java @@ -16,11 +16,21 @@ */ package com.ctrip.framework.apollo.monitor.internal; -import com.ctrip.framework.apollo.monitor.api.ApolloNamespaceMonitorApi; +import com.ctrip.framework.apollo.monitor.api.ApolloClientNamespaceMonitorApi; +import com.ctrip.framework.apollo.monitor.internal.collector.impl.DefaultApolloClientNamespaceCollector.NamespaceMetrics; import java.util.Collections; import java.util.List; +import java.util.Map; -public class NullNamespaceMonitorApi implements ApolloNamespaceMonitorApi { +/** + * @author Rawven + */ +public class NullClientNamespaceMonitorApi implements ApolloClientNamespaceMonitorApi { + + @Override + public Map getNamespaceMetrics() { + return Collections.emptyMap(); + } @Override public String getNamespaceReleaseKey(String namespace) { diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/NullThreadPoolMonitorApi.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/NullClientThreadPoolMonitorApi.java similarity index 95% rename from apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/NullThreadPoolMonitorApi.java rename to apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/NullClientThreadPoolMonitorApi.java index 34384df0..bc244cca 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/NullThreadPoolMonitorApi.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/NullClientThreadPoolMonitorApi.java @@ -16,9 +16,9 @@ */ package com.ctrip.framework.apollo.monitor.internal; -import com.ctrip.framework.apollo.monitor.api.ApolloThreadPoolMonitorApi; +import com.ctrip.framework.apollo.monitor.api.ApolloClientThreadPoolMonitorApi; -public class NullThreadPoolMonitorApi implements ApolloThreadPoolMonitorApi { +public class NullClientThreadPoolMonitorApi implements ApolloClientThreadPoolMonitorApi { @Override public int getRemoteConfigRepositoryThreadPoolActiveCount() { diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/collector/internal/DefaultApolloRunningParamsCollector.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/collector/impl/DefaultApolloClientBootstrapArgsCollector.java similarity index 95% rename from apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/collector/internal/DefaultApolloRunningParamsCollector.java rename to apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/collector/impl/DefaultApolloClientBootstrapArgsCollector.java index a5133af5..5ccc2199 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/collector/internal/DefaultApolloRunningParamsCollector.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/collector/impl/DefaultApolloClientBootstrapArgsCollector.java @@ -14,7 +14,7 @@ * limitations under the License. * */ -package com.ctrip.framework.apollo.monitor.internal.collector.internal; +package com.ctrip.framework.apollo.monitor.internal.collector.impl; import static com.ctrip.framework.apollo.core.ApolloClientSystemConsts.APOLLO_ACCESS_KEY_SECRET; import static com.ctrip.framework.apollo.core.ApolloClientSystemConsts.APOLLO_CACHE_DIR; @@ -35,7 +35,7 @@ import static com.ctrip.framework.apollo.spring.config.PropertySourcesConstants.APOLLO_BOOTSTRAP_NAMESPACES; import com.ctrip.framework.apollo.Apollo; -import com.ctrip.framework.apollo.monitor.api.ApolloRunningParamsMonitorApi; +import com.ctrip.framework.apollo.monitor.api.ApolloClientBootstrapArgsMonitorApi; import com.ctrip.framework.apollo.monitor.internal.collector.AbstractMetricsCollector; import com.ctrip.framework.apollo.monitor.internal.model.MetricsEvent; import com.ctrip.framework.apollo.util.ConfigUtil; @@ -45,8 +45,8 @@ /** * @author Rawven */ -public class DefaultApolloRunningParamsCollector extends AbstractMetricsCollector implements - ApolloRunningParamsMonitorApi { +public class DefaultApolloClientBootstrapArgsCollector extends AbstractMetricsCollector implements + ApolloClientBootstrapArgsMonitorApi { public static final String ENV = "env"; public static final String VERSION = "version"; @@ -55,7 +55,7 @@ public class DefaultApolloRunningParamsCollector extends AbstractMetricsCollecto public static final String CONFIG_SERVICE_URL = "configServiceUrl"; private final Map map = Maps.newHashMap(); - public DefaultApolloRunningParamsCollector(ConfigUtil configUtil) { + public DefaultApolloClientBootstrapArgsCollector(ConfigUtil configUtil) { super(RUNNING_PARAMS, RUNNING_PARAMS); map.put(APOLLO_ACCESS_KEY_SECRET, configUtil.getAccessKeySecret()); map.put(APOLLO_AUTO_UPDATE_INJECTED_SPRING_PROPERTIES, @@ -193,7 +193,7 @@ public long getClientMonitorExternalExportPeriod() { } @Override - public String getMeta() { + public String getApolloMeta() { return map.get(APOLLO_META).toString(); } diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/collector/internal/DefaultApolloExceptionCollector.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/collector/impl/DefaultApolloClientExceptionCollector.java similarity index 72% rename from apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/collector/internal/DefaultApolloExceptionCollector.java rename to apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/collector/impl/DefaultApolloClientExceptionCollector.java index f4895592..f2e1c1af 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/collector/internal/DefaultApolloExceptionCollector.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/collector/impl/DefaultApolloClientExceptionCollector.java @@ -14,27 +14,27 @@ * limitations under the License. * */ -package com.ctrip.framework.apollo.monitor.internal.collector.internal; +package com.ctrip.framework.apollo.monitor.internal.collector.impl; -import static com.ctrip.framework.apollo.monitor.internal.tracer.MessageProducerComposite.ERROR_METRICS; -import static com.ctrip.framework.apollo.monitor.internal.tracer.MessageProducerComposite.THROWABLE; +import static com.ctrip.framework.apollo.monitor.internal.MonitorConstant.ERROR_METRICS; +import static com.ctrip.framework.apollo.monitor.internal.MonitorConstant.THROWABLE; import com.ctrip.framework.apollo.exceptions.ApolloConfigException; -import com.ctrip.framework.apollo.monitor.api.ApolloExceptionMonitorApi; +import com.ctrip.framework.apollo.monitor.api.ApolloClientExceptionMonitorApi; import com.ctrip.framework.apollo.monitor.internal.collector.AbstractMetricsCollector; import com.ctrip.framework.apollo.monitor.internal.model.CounterModel; import com.ctrip.framework.apollo.monitor.internal.model.MetricsEvent; +import java.util.ArrayList; import java.util.List; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; import java.util.concurrent.atomic.AtomicInteger; -import java.util.stream.Collectors; /** * @author Rawven */ -public class DefaultApolloExceptionCollector extends AbstractMetricsCollector implements - ApolloExceptionMonitorApi { +public class DefaultApolloClientExceptionCollector extends AbstractMetricsCollector implements + ApolloClientExceptionMonitorApi { public static final String EXCEPTION_NUM = "exception_num"; @@ -44,19 +44,13 @@ public class DefaultApolloExceptionCollector extends AbstractMetricsCollector im private final AtomicInteger exceptionNum = new AtomicInteger(0); - public DefaultApolloExceptionCollector() { + public DefaultApolloClientExceptionCollector() { super(ERROR_METRICS, ERROR_METRICS); } @Override - public Integer getExceptionNum() { - return exceptionNum.get(); - } - - @Override - public List getExceptionDetails() { - return exceptions.stream().map(ApolloConfigException::getMessage) - .collect(Collectors.toList()); + public List getExceptionList() { + return new ArrayList<>(exceptions); } @Override diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/collector/internal/DefaultApolloNamespaceCollector.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/collector/impl/DefaultApolloClientNamespaceCollector.java similarity index 95% rename from apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/collector/internal/DefaultApolloNamespaceCollector.java rename to apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/collector/impl/DefaultApolloClientNamespaceCollector.java index 8caa5a9b..20139381 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/collector/internal/DefaultApolloNamespaceCollector.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/collector/impl/DefaultApolloClientNamespaceCollector.java @@ -14,7 +14,7 @@ * limitations under the License. * */ -package com.ctrip.framework.apollo.monitor.internal.collector.internal; +package com.ctrip.framework.apollo.monitor.internal.collector.impl; import static com.ctrip.framework.apollo.monitor.internal.MonitorConstant.NAMESPACE; @@ -24,7 +24,7 @@ import com.ctrip.framework.apollo.Config; import com.ctrip.framework.apollo.ConfigFile; import com.ctrip.framework.apollo.core.utils.DeferredLoggerFactory; -import com.ctrip.framework.apollo.monitor.api.ApolloNamespaceMonitorApi; +import com.ctrip.framework.apollo.monitor.api.ApolloClientNamespaceMonitorApi; import com.ctrip.framework.apollo.monitor.internal.MonitorConstant; import com.ctrip.framework.apollo.monitor.internal.collector.AbstractMetricsCollector; import com.ctrip.framework.apollo.monitor.internal.model.CounterModel; @@ -45,8 +45,8 @@ /** * @author Rawven */ -public class DefaultApolloNamespaceCollector extends AbstractMetricsCollector implements - ApolloNamespaceMonitorApi { +public class DefaultApolloClientNamespaceCollector extends AbstractMetricsCollector implements + ApolloClientNamespaceMonitorApi { public static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern( "yyyy-MM-dd HH:mm:ss").withZone(ZoneId.systemDefault()); @@ -60,7 +60,7 @@ public class DefaultApolloNamespaceCollector extends AbstractMetricsCollector im public static final String NAMESPACE_NOT_FOUND = "namespace_not_found"; public static final String NAMESPACE_TIMEOUT = "namespace_timeout"; private static final Logger logger = DeferredLoggerFactory.getLogger( - DefaultApolloNamespaceCollector.class); + DefaultApolloClientNamespaceCollector.class); private final Map m_configs; private final Map m_configLocks; private final Map m_configFiles; @@ -69,7 +69,7 @@ public class DefaultApolloNamespaceCollector extends AbstractMetricsCollector im private final List namespace404 = Lists.newCopyOnWriteArrayList(); private final List namespaceTimeout = Lists.newCopyOnWriteArrayList(); - public DefaultApolloNamespaceCollector(Map m_configs, + public DefaultApolloClientNamespaceCollector(Map m_configs, Map m_configLocks, Map m_configFiles, Map m_configFileLocks) { @@ -158,6 +158,11 @@ private void updateGaugeSample(String key, String namespace, Object value, } + @Override + public Map getNamespaceMetrics() { + return namespaces; + } + @Override public String getNamespaceReleaseKey(String namespace) { NamespaceMetrics namespaceMetrics = namespaces.get(namespace); diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/collector/internal/DefaultApolloThreadPoolCollector.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/collector/impl/DefaultApolloClientThreadPoolCollector.java similarity index 96% rename from apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/collector/internal/DefaultApolloThreadPoolCollector.java rename to apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/collector/impl/DefaultApolloClientThreadPoolCollector.java index 96312168..b1772241 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/collector/internal/DefaultApolloThreadPoolCollector.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/collector/impl/DefaultApolloClientThreadPoolCollector.java @@ -14,12 +14,12 @@ * limitations under the License. * */ -package com.ctrip.framework.apollo.monitor.internal.collector.internal; +package com.ctrip.framework.apollo.monitor.internal.collector.impl; import com.ctrip.framework.apollo.internals.AbstractConfig; import com.ctrip.framework.apollo.internals.AbstractConfigFile; import com.ctrip.framework.apollo.internals.RemoteConfigRepository; -import com.ctrip.framework.apollo.monitor.api.ApolloThreadPoolMonitorApi; +import com.ctrip.framework.apollo.monitor.api.ApolloClientThreadPoolMonitorApi; import com.ctrip.framework.apollo.monitor.internal.collector.AbstractMetricsCollector; import com.ctrip.framework.apollo.monitor.internal.model.GaugeModel; import com.ctrip.framework.apollo.monitor.internal.model.MetricsEvent; @@ -33,8 +33,8 @@ /** * @author Rawven */ -public class DefaultApolloThreadPoolCollector extends AbstractMetricsCollector implements - ApolloThreadPoolMonitorApi { +public class DefaultApolloClientThreadPoolCollector extends AbstractMetricsCollector implements + ApolloClientThreadPoolMonitorApi { public static final String THREAD_POOL_METRICS = "ThreadPoolMetrics"; public static final String[] THREAD_POOL_PARAMS = new String[]{"ThreadPoolName", @@ -47,7 +47,7 @@ public class DefaultApolloThreadPoolCollector extends AbstractMetricsCollector i private final ThreadPoolExecutor abstractConfigExecutorService; private final ThreadPoolExecutor abstractConfigFileExecutorService; - public DefaultApolloThreadPoolCollector( + public DefaultApolloClientThreadPoolCollector( ScheduledExecutorService remoteConfigRepositoryExecutorService, ExecutorService abstractConfigExecutorService, ExecutorService abstractConfigFileExecutorService) { diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/collector/internal/DefaultMetricsCollectorManager.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/collector/impl/DefaultMetricsCollectorManager.java similarity index 94% rename from apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/collector/internal/DefaultMetricsCollectorManager.java rename to apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/collector/impl/DefaultMetricsCollectorManager.java index 972b4da0..7cff5ced 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/collector/internal/DefaultMetricsCollectorManager.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/collector/impl/DefaultMetricsCollectorManager.java @@ -14,7 +14,7 @@ * limitations under the License. * */ -package com.ctrip.framework.apollo.monitor.internal.collector.internal; +package com.ctrip.framework.apollo.monitor.internal.collector.impl; import com.ctrip.framework.apollo.monitor.internal.collector.MetricsCollector; import com.ctrip.framework.apollo.monitor.internal.collector.MetricsCollectorManager; diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/exporter/internals/DefaultMetricsExporterFactory.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/exporter/impl/DefaultMetricsExporterFactory.java similarity index 94% rename from apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/exporter/internals/DefaultMetricsExporterFactory.java rename to apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/exporter/impl/DefaultMetricsExporterFactory.java index 5a0279b1..c6cdabe4 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/exporter/internals/DefaultMetricsExporterFactory.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/exporter/impl/DefaultMetricsExporterFactory.java @@ -14,7 +14,7 @@ * limitations under the License. * */ -package com.ctrip.framework.apollo.monitor.internal.exporter.internals; +package com.ctrip.framework.apollo.monitor.internal.exporter.impl; import static com.ctrip.framework.apollo.monitor.internal.MonitorConstant.MBEAN_NAME; @@ -22,7 +22,7 @@ import com.ctrip.framework.apollo.core.utils.DeferredLoggerFactory; import com.ctrip.framework.apollo.exceptions.ApolloConfigException; import com.ctrip.framework.apollo.monitor.internal.collector.MetricsCollector; -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.MetricsExporter; import com.ctrip.framework.apollo.monitor.internal.exporter.MetricsExporterFactory; import com.ctrip.framework.apollo.monitor.internal.util.JMXUtil; diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/tracer/MonitorMessageProducer.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/tracer/ClientMonitorMessageProducer.java similarity index 73% rename from apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/tracer/MonitorMessageProducer.java rename to apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/tracer/ClientMonitorMessageProducer.java index 83625f20..8719fc5c 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/tracer/MonitorMessageProducer.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/tracer/ClientMonitorMessageProducer.java @@ -16,27 +16,27 @@ */ package com.ctrip.framework.apollo.monitor.internal.tracer; +import static com.ctrip.framework.apollo.monitor.internal.MonitorConstant.APOLLO_CLIENT_CONFIGCHANGES; +import static com.ctrip.framework.apollo.monitor.internal.MonitorConstant.APOLLO_CLIENT_CONFIGMETA; +import static com.ctrip.framework.apollo.monitor.internal.MonitorConstant.APOLLO_CLIENT_CONFIGS; +import static com.ctrip.framework.apollo.monitor.internal.MonitorConstant.APOLLO_CLIENT_VERSION; +import static com.ctrip.framework.apollo.monitor.internal.MonitorConstant.APOLLO_CONFIGSERVICE; +import static com.ctrip.framework.apollo.monitor.internal.MonitorConstant.APOLLO_CONFIG_EXCEPTION; +import static com.ctrip.framework.apollo.monitor.internal.MonitorConstant.APOLLO_CONFIG_SERVICES; +import static com.ctrip.framework.apollo.monitor.internal.MonitorConstant.APOLLO_META_SERVICE; +import static com.ctrip.framework.apollo.monitor.internal.MonitorConstant.ERROR_METRICS; +import static com.ctrip.framework.apollo.monitor.internal.MonitorConstant.HELP_STR; import static com.ctrip.framework.apollo.monitor.internal.MonitorConstant.NAMESPACE; +import static com.ctrip.framework.apollo.monitor.internal.MonitorConstant.THROWABLE; import static com.ctrip.framework.apollo.monitor.internal.MonitorConstant.TIMESTAMP; -import static com.ctrip.framework.apollo.monitor.internal.collector.internal.DefaultApolloNamespaceCollector.DATE_FORMATTER; -import static com.ctrip.framework.apollo.monitor.internal.collector.internal.DefaultApolloNamespaceCollector.NAMESPACE_LATEST_UPDATE_TIME; -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_RELEASE_KEY; -import static com.ctrip.framework.apollo.monitor.internal.collector.internal.DefaultApolloRunningParamsCollector.CONFIG_SERVICE_URL; -import static com.ctrip.framework.apollo.monitor.internal.collector.internal.DefaultApolloRunningParamsCollector.META_FRESH; -import static com.ctrip.framework.apollo.monitor.internal.collector.internal.DefaultApolloRunningParamsCollector.RUNNING_PARAMS; -import static com.ctrip.framework.apollo.monitor.internal.collector.internal.DefaultApolloRunningParamsCollector.VERSION; -import static com.ctrip.framework.apollo.monitor.internal.tracer.MessageProducerComposite.APOLLO_CLIENT_CONFIGCHANGES; -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_CONFIGS; -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.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.tracer.MessageProducerComposite.ERROR_METRICS; -import static com.ctrip.framework.apollo.monitor.internal.tracer.MessageProducerComposite.HELP_STR; -import static com.ctrip.framework.apollo.monitor.internal.tracer.MessageProducerComposite.THROWABLE; +import static com.ctrip.framework.apollo.monitor.internal.collector.impl.DefaultApolloClientBootstrapArgsCollector.CONFIG_SERVICE_URL; +import static com.ctrip.framework.apollo.monitor.internal.collector.impl.DefaultApolloClientBootstrapArgsCollector.META_FRESH; +import static com.ctrip.framework.apollo.monitor.internal.collector.impl.DefaultApolloClientBootstrapArgsCollector.RUNNING_PARAMS; +import static com.ctrip.framework.apollo.monitor.internal.collector.impl.DefaultApolloClientBootstrapArgsCollector.VERSION; +import static com.ctrip.framework.apollo.monitor.internal.collector.impl.DefaultApolloClientNamespaceCollector.DATE_FORMATTER; +import static com.ctrip.framework.apollo.monitor.internal.collector.impl.DefaultApolloClientNamespaceCollector.NAMESPACE_LATEST_UPDATE_TIME; +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_RELEASE_KEY; import com.ctrip.framework.apollo.exceptions.ApolloConfigException; import com.ctrip.framework.apollo.monitor.internal.model.MetricsEvent; @@ -52,7 +52,7 @@ * * @author Rawven */ -public class MonitorMessageProducer implements MessageProducer { +public class ClientMonitorMessageProducer implements MessageProducer { public static final List TAGS = Collections.unmodifiableList( Arrays.asList( diff --git a/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/tracer/MessageProducerComposite.java b/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/tracer/MessageProducerComposite.java index 91a0db6b..618e4dfa 100644 --- a/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/tracer/MessageProducerComposite.java +++ b/apollo-client/src/main/java/com/ctrip/framework/apollo/monitor/internal/tracer/MessageProducerComposite.java @@ -29,17 +29,7 @@ */ public class MessageProducerComposite implements MessageProducer { - public static final String ERROR_METRICS = "errorMetrics"; - public static final String THROWABLE = ERROR_METRICS + ".throwable"; - public static final String APOLLO_CLIENT_CONFIGCHANGES = "Apollo.Client.ConfigChanges"; - public static final String APOLLO_CONFIG_EXCEPTION = "ApolloConfigException"; - public static final String APOLLO_META_SERVICE = "Apollo.MetaService"; - public static final String APOLLO_CONFIG_SERVICES = "Apollo.Config.Services"; - public static final String APOLLO_CLIENT_VERSION = "Apollo.Client.Version"; - public static final String APOLLO_CONFIGSERVICE = "Apollo.ConfigService"; - public static final String APOLLO_CLIENT_CONFIGS = "Apollo.Client.Configs."; - public static final String APOLLO_CLIENT_CONFIGMETA = "Apollo.Client.ConfigMeta"; - public static final String HELP_STR = "periodicRefresh: "; + private static final NullTransaction NULL_TRANSACTION = new NullTransaction(); private List producers; diff --git a/apollo-client/src/test/java/com/ctrip/framework/apollo/monitor/internal/exporter/DefaultApolloMetricsExporterFactoryTest.java b/apollo-client/src/test/java/com/ctrip/framework/apollo/monitor/internal/exporter/DefaultApolloMetricsExporterFactoryTest.java index ca4e807e..534e220e 100644 --- a/apollo-client/src/test/java/com/ctrip/framework/apollo/monitor/internal/exporter/DefaultApolloMetricsExporterFactoryTest.java +++ b/apollo-client/src/test/java/com/ctrip/framework/apollo/monitor/internal/exporter/DefaultApolloMetricsExporterFactoryTest.java @@ -21,7 +21,7 @@ import com.ctrip.framework.apollo.build.MockInjector; import com.ctrip.framework.apollo.core.ApolloClientSystemConsts; import com.ctrip.framework.apollo.monitor.internal.collector.MetricsCollector; -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.util.ConfigUtil; import java.util.ArrayList; import java.util.List;