-
-
Notifications
You must be signed in to change notification settings - Fork 84
[OSPP]Add more observability in apollo config client #74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
bd7fe56
feat(client): Add more observability in apollo config client
Rawven ccadc30
feat(client): Add more observability in apollo config client
Rawven 7c6b4db
Merge branch 'main' into now
Rawven 77eed66
feat(client): add unit test
Rawven 02aee66
feat(client): add unit test
Rawven ea8c138
feat(client): add unit test
Rawven 0f73102
feat(client): add unit test
Rawven 2ec4630
feat(client): add unit test
Rawven a4da395
feat(): refactor
Rawven 8a09ec8
feat(): refactor
Rawven 1917cc2
feat(): refactor
Rawven 5e310b7
Merge branch 'main' into now
Rawven 75ad161
refactor(): rollback meaningless change
Rawven 004df52
docs(): add CHANGES.md
Rawven d75df39
Merge branch 'main' into now
Rawven File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 138 additions & 0 deletions
138
...o-client/src/main/java/com/ctrip/framework/apollo/internals/ConfigMonitorInitializer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| /* | ||
| * 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.internals; | ||
|
|
||
| import static com.ctrip.framework.apollo.monitor.internal.ApolloClientMonitorConstant.MBEAN_NAME; | ||
|
|
||
| import com.ctrip.framework.apollo.build.ApolloInjector; | ||
| import com.ctrip.framework.apollo.core.utils.ClassLoaderUtil; | ||
| import com.ctrip.framework.apollo.monitor.internal.exporter.AbstractApolloClientMetricsExporter; | ||
| import com.ctrip.framework.apollo.monitor.internal.exporter.ApolloClientMetricsExporter; | ||
| import com.ctrip.framework.apollo.monitor.internal.jmx.ApolloClientJmxMBeanRegister; | ||
| import com.ctrip.framework.apollo.monitor.internal.ApolloClientMonitorContext; | ||
| import com.ctrip.framework.apollo.monitor.internal.listener.impl.DefaultApolloClientBootstrapArgsApi; | ||
| import com.ctrip.framework.apollo.monitor.internal.listener.impl.DefaultApolloClientExceptionApi; | ||
| import com.ctrip.framework.apollo.monitor.internal.listener.impl.DefaultApolloClientNamespaceApi; | ||
| import com.ctrip.framework.apollo.monitor.internal.listener.impl.DefaultApolloClientThreadPoolApi; | ||
| import com.ctrip.framework.apollo.monitor.internal.exporter.ApolloClientMetricsExporterFactory; | ||
| import com.ctrip.framework.apollo.monitor.internal.tracer.ApolloClientMonitorMessageProducer; | ||
| import com.ctrip.framework.apollo.monitor.internal.tracer.ApolloClientMessageProducerComposite; | ||
| 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; | ||
| import com.ctrip.framework.apollo.tracer.spi.MessageProducer; | ||
| import com.ctrip.framework.apollo.util.ConfigUtil; | ||
| import com.ctrip.framework.foundation.internals.ServiceBootstrap; | ||
| import com.google.common.collect.Lists; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * ConfigMonitorInitializer initializes the Apollo Config Monitor. | ||
| */ | ||
| public class ConfigMonitorInitializer { | ||
|
|
||
| private static final ApolloClientMonitorContext MONITOR_CONTEXT = ApolloInjector.getInstance( | ||
| ApolloClientMonitorContext.class); | ||
| protected static volatile boolean hasInitialized = false; | ||
| private static ConfigUtil m_configUtil = ApolloInjector.getInstance(ConfigUtil.class); | ||
|
|
||
| public static void initialize() { | ||
| if (m_configUtil.isClientMonitorEnabled() && !hasInitialized) { | ||
| synchronized (ConfigMonitorInitializer.class) { | ||
| if (!hasInitialized) { | ||
| doInit(); | ||
| hasInitialized = true; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private static void doInit() { | ||
| initializeMetricsEventListener(); | ||
| initializeMetricsExporter(); | ||
| initializeJmxMonitoring(); | ||
| } | ||
|
|
||
|
|
||
| private static void initializeJmxMonitoring() { | ||
| if (m_configUtil.isClientMonitorJmxEnabled()) { | ||
| MONITOR_CONTEXT.getApolloClientMonitorEventListeners().forEach(metricsListener -> | ||
| ApolloClientJmxMBeanRegister.register( | ||
| MBEAN_NAME + metricsListener.getName(), metricsListener) | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| private static void initializeMetricsEventListener() { | ||
| ConfigManager configManager = ApolloInjector.getInstance( | ||
| ConfigManager.class); | ||
| DefaultApolloClientBootstrapArgsApi defaultApolloClientBootstrapArgsApi = new DefaultApolloClientBootstrapArgsApi( | ||
| m_configUtil); | ||
| DefaultApolloClientExceptionApi defaultApolloClientExceptionApi = new DefaultApolloClientExceptionApi(m_configUtil); | ||
| DefaultApolloClientNamespaceApi defaultApolloClientNamespaceApi = new DefaultApolloClientNamespaceApi( | ||
| configManager); | ||
| DefaultApolloClientThreadPoolApi defaultApolloClientThreadPoolApi = new DefaultApolloClientThreadPoolApi( | ||
| RemoteConfigRepository.m_executorService, | ||
| AbstractConfig.m_executorService, AbstractConfigFile.m_executorService, | ||
| AbstractApolloClientMetricsExporter.m_executorService); | ||
Rawven marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| MONITOR_CONTEXT.setApolloClientBootstrapArgsMonitorApi(defaultApolloClientBootstrapArgsApi); | ||
| MONITOR_CONTEXT.setApolloClientExceptionMonitorApi(defaultApolloClientExceptionApi); | ||
| MONITOR_CONTEXT.setApolloClientNamespaceMonitorApi(defaultApolloClientNamespaceApi); | ||
| MONITOR_CONTEXT.setApolloClientThreadPoolMonitorApi(defaultApolloClientThreadPoolApi); | ||
| MONITOR_CONTEXT.setApolloClientMonitorEventListeners( | ||
| Lists.newArrayList(defaultApolloClientBootstrapArgsApi, | ||
| defaultApolloClientNamespaceApi, defaultApolloClientThreadPoolApi, | ||
| defaultApolloClientExceptionApi)); | ||
| } | ||
|
|
||
| private static void initializeMetricsExporter( | ||
| ) { | ||
| ApolloClientMetricsExporterFactory exporterFactory = ApolloInjector.getInstance( | ||
| ApolloClientMetricsExporterFactory.class); | ||
| ApolloClientMetricsExporter metricsReporter = exporterFactory.getMetricsReporter( | ||
| MONITOR_CONTEXT.getApolloClientMonitorEventListeners()); | ||
| if (metricsReporter != null) { | ||
| MONITOR_CONTEXT.setApolloClientMetricsExporter(metricsReporter); | ||
| } | ||
| } | ||
|
|
||
| public static ApolloClientMessageProducerComposite initializeMessageProducerComposite() { | ||
| List<MessageProducer> producers = ServiceBootstrap.loadAllOrdered(MessageProducer.class); | ||
|
|
||
| if (m_configUtil.isClientMonitorEnabled()) { | ||
| producers.add(new ApolloClientMonitorMessageProducer()); | ||
| } | ||
|
|
||
| if (ClassLoaderUtil.isClassPresent(CatNames.CAT_CLASS)) { | ||
| producers.add(new CatMessageProducer()); | ||
| } | ||
|
|
||
| if (producers.isEmpty()) { | ||
| producers.add(new NullMessageProducer()); | ||
| } | ||
|
|
||
| return new ApolloClientMessageProducerComposite(producers); | ||
| } | ||
Rawven marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // for test only | ||
| protected static void reset() { | ||
| hasInitialized = false; | ||
| m_configUtil = ApolloInjector.getInstance(ConfigUtil.class); | ||
|
|
||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.