Skip to content
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

Separate the code for indicator monitoring #14106

Open
wants to merge 19 commits into
base: 3.3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
2b37f8d
Separate the code for indicator monitoring
walklown Apr 13, 2024
7fd84a6
Merge branch '3.3' into feature/refector-metric-export
songxiaosheng May 19, 2024
c17da8c
Adjust code based on Reviews.
walklown May 19, 2024
e411ed7
Merge branch '3.3' into feature/refector-metric-export
walklown May 27, 2024
320a564
Merge branch '3.3' into feature/refector-metric-export
walklown May 27, 2024
19db740
Allows extension of DubboEventMulticaster
walklown Jun 6, 2024
7eb1e23
ScopeModelInitializer supports Ordered sorting
walklown Jun 6, 2024
45d184b
Merge branch '3.3' into feature/refector-metric-export
songxiaosheng Jun 6, 2024
7fd5b1a
Revert "ScopeModelInitializer supports Ordered sorting"
walklown Jun 8, 2024
3b67620
Revert "Allows extension of DubboEventMulticaster"
walklown Jun 8, 2024
3f1c88d
rename DubboApplicationMulticasterRegistry
walklown Jun 8, 2024
76484fc
ScopeModelInitializer supports Ordered sorting
walklown Jun 6, 2024
c1b26d9
Merge branch '3.3' into feature/refector-metric-export
walklown Jun 11, 2024
729ab52
Merge branch '3.3' into feature/refector-metric-export
songxiaosheng Jun 15, 2024
41b2667
remote dubbo-metrics-starter
walklown Jun 16, 2024
679b37f
DefaultMetricsCollector filter RequestEvent when avalidate is false
walklown Jun 16, 2024
e6b48c8
Rollback fix for unrelated unit tests
walklown Jun 18, 2024
a6419df
Merge branch '3.3' into feature/refector-metric-export
walklown Jul 7, 2024
eafd1d2
Merge branch '3.3' into feature/refector-metric-export
songxiaosheng Jul 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .artifacts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ dubbo-metrics-prometheus
dubbo-metrics-registry
dubbo-metrics-config-center
dubbo-metrics-netty
dubbo-metrics-event
dubbo-metrics-monitor
dubbo-native
dubbo-parent
dubbo-plugin
Expand Down
12 changes: 0 additions & 12 deletions dubbo-cluster/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,6 @@
<version>${project.parent.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-metrics-registry</artifactId>
<version>${project.parent.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-metrics-default</artifactId>
<version>${project.parent.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-tracing-integration-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,14 @@
import org.apache.dubbo.common.config.Configuration;
import org.apache.dubbo.common.config.ConfigurationUtils;
import org.apache.dubbo.common.constants.LoggerCodeConstants;
import org.apache.dubbo.common.event.DubboEventBus;
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.common.threadpool.manager.FrameworkExecutorRepository;
import org.apache.dubbo.common.utils.ConcurrentHashSet;
import org.apache.dubbo.common.utils.LockUtils;
import org.apache.dubbo.common.utils.NetUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.metrics.event.MetricsEventBus;
import org.apache.dubbo.metrics.model.key.MetricsKey;
import org.apache.dubbo.metrics.registry.event.RegistryEvent;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.RpcContext;
Expand All @@ -46,7 +44,6 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -393,14 +390,13 @@ public void checkConnectivity() {
checkConnectivity();
}
});
MetricsEventBus.publish(RegistryEvent.refreshDirectoryEvent(
applicationModel, getSummary(), getDirectoryMeta()));
DubboEventBus.publish(
new DirectoryRefreshEvent(applicationModel, getSummary(), getDirectoryMeta()));
},
reconnectTaskPeriod,
TimeUnit.MILLISECONDS);
}
MetricsEventBus.publish(
RegistryEvent.refreshDirectoryEvent(applicationModel, getSummary(), getDirectoryMeta()));
DubboEventBus.publish(new DirectoryRefreshEvent(applicationModel, getSummary(), getDirectoryMeta()));
}

/**
Expand All @@ -416,8 +412,7 @@ public void refreshInvoker() {
refreshInvokerInternal();
}
});
MetricsEventBus.publish(
RegistryEvent.refreshDirectoryEvent(applicationModel, getSummary(), getDirectoryMeta()));
DubboEventBus.publish(new DirectoryRefreshEvent(applicationModel, getSummary(), getDirectoryMeta()));
}

protected Map<String, String> getDirectoryMeta() {
Expand Down Expand Up @@ -452,8 +447,7 @@ public void addDisabledInvoker(Invoker<T> invoker) {
logger.info("Disable service address: " + invoker.getUrl() + ".");
}
});
MetricsEventBus.publish(
RegistryEvent.refreshDirectoryEvent(applicationModel, getSummary(), getDirectoryMeta()));
DubboEventBus.publish(new DirectoryRefreshEvent(applicationModel, getSummary(), getDirectoryMeta()));
}

@Override
Expand All @@ -468,8 +462,7 @@ public void recoverDisabledInvoker(Invoker<T> invoker) {
}
}
});
MetricsEventBus.publish(
RegistryEvent.refreshDirectoryEvent(applicationModel, getSummary(), getDirectoryMeta()));
DubboEventBus.publish(new DirectoryRefreshEvent(applicationModel, getSummary(), getDirectoryMeta()));
}

protected final void refreshRouter(BitList<Invoker<T>> newlyInvokers, Runnable switchAction) {
Expand Down Expand Up @@ -532,8 +525,7 @@ protected void setInvokers(BitList<Invoker<T>> invokers) {
this.invokersInitialized = true;
});

MetricsEventBus.publish(
RegistryEvent.refreshDirectoryEvent(applicationModel, getSummary(), getDirectoryMeta()));
DubboEventBus.publish(new DirectoryRefreshEvent(applicationModel, getSummary(), getDirectoryMeta()));
}

protected void destroyInvokers() {
Expand All @@ -550,8 +542,7 @@ private boolean addValidInvoker(Invoker<T> invoker) {
LockUtils.safeLock(invokerRefreshLock, LockUtils.DEFAULT_TIMEOUT, () -> {
result.set(this.validInvokers.add(invoker));
});
MetricsEventBus.publish(
RegistryEvent.refreshDirectoryEvent(applicationModel, getSummary(), getDirectoryMeta()));
DubboEventBus.publish(new DirectoryRefreshEvent(applicationModel, getSummary(), getDirectoryMeta()));
return result.get();
}

Expand All @@ -560,8 +551,7 @@ private boolean removeValidInvoker(Invoker<T> invoker) {
LockUtils.safeLock(invokerRefreshLock, LockUtils.DEFAULT_TIMEOUT, () -> {
result.set(this.validInvokers.remove(invoker));
});
MetricsEventBus.publish(
RegistryEvent.refreshDirectoryEvent(applicationModel, getSummary(), getDirectoryMeta()));
DubboEventBus.publish(new DirectoryRefreshEvent(applicationModel, getSummary(), getDirectoryMeta()));
return result.get();
}

Expand All @@ -581,14 +571,13 @@ protected String joinValidInvokerAddresses() {
.collect(Collectors.joining(","));
}

private Map<MetricsKey, Map<String, Integer>> getSummary() {
Map<MetricsKey, Map<String, Integer>> summaryMap = new HashMap<>();

summaryMap.put(MetricsKey.DIRECTORY_METRIC_NUM_VALID, groupByServiceKey(getValidInvokers()));
summaryMap.put(MetricsKey.DIRECTORY_METRIC_NUM_DISABLE, groupByServiceKey(getDisabledInvokers()));
summaryMap.put(MetricsKey.DIRECTORY_METRIC_NUM_TO_RECONNECT, groupByServiceKey(getInvokersToReconnect()));
summaryMap.put(MetricsKey.DIRECTORY_METRIC_NUM_ALL, groupByServiceKey(getInvokers()));
return summaryMap;
private DirectoryRefreshEvent.Summary getSummary() {
DirectoryRefreshEvent.Summary summary = new DirectoryRefreshEvent.Summary();
summary.directoryNumValidMap = groupByServiceKey(getValidInvokers());
summary.directoryNumDisableMap = groupByServiceKey(getDisabledInvokers());
summary.directoryNumToReConnectMap = groupByServiceKey(getInvokersToReconnect());
summary.directoryNumAllMap = groupByServiceKey(getInvokers());
return summary;
}

private Map<String, Integer> groupByServiceKey(Collection<Invoker<T>> invokers) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.dubbo.rpc.cluster.directory;

import org.apache.dubbo.common.event.DubboEvent;
import org.apache.dubbo.common.utils.TimePair;
import org.apache.dubbo.rpc.model.ApplicationModel;

import java.util.Map;

public class DirectoryRefreshEvent extends DubboEvent {

private final TimePair timePair;

private final Summary summary;

private final Map<String, String> attachments;

public DirectoryRefreshEvent(ApplicationModel applicationModel, Summary summary, Map<String, String> attachments) {
super(applicationModel);
this.summary = summary;
this.attachments = attachments;
this.timePair = TimePair.start();
}

public Summary getSummary() {
return summary;
}

public Map<String, String> getAttachments() {
return attachments;
}

public TimePair getTimePair() {
return timePair;
}

public static class Summary {

public Map<String, Integer> directoryNumValidMap;

public Map<String, Integer> directoryNumDisableMap;

public Map<String, Integer> directoryNumToReConnectMap;

public Map<String, Integer> directoryNumAllMap;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
consumercontext=org.apache.dubbo.rpc.cluster.filter.support.ConsumerContextFilter
consumer-classloader=org.apache.dubbo.rpc.cluster.filter.support.ConsumerClassLoaderFilter
router-snapshot=org.apache.dubbo.rpc.cluster.router.RouterSnapshotFilter
metricsConsumerFilter=org.apache.dubbo.rpc.cluster.filter.support.MetricsConsumerFilter
router-snapshot=org.apache.dubbo.rpc.cluster.router.RouterSnapshotFilter
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.utils.Holder;
import org.apache.dubbo.common.utils.NetUtils;
import org.apache.dubbo.metrics.event.MetricsDispatcher;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.RpcInvocation;
import org.apache.dubbo.rpc.cluster.router.MockInvoker;
import org.apache.dubbo.rpc.cluster.router.condition.ConditionStateRouterFactory;
import org.apache.dubbo.rpc.cluster.router.state.BitList;
import org.apache.dubbo.rpc.cluster.router.state.StateRouter;
import org.apache.dubbo.rpc.model.ApplicationModel;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -70,7 +68,6 @@ void testStaticDirectory() {
new RpcInvocation(),
false,
new Holder<>());
ApplicationModel.defaultModel().getBeanFactory().registerBean(MetricsDispatcher.class);
StaticDirectory<String> staticDirectory = new StaticDirectory<>(filteredInvokers);
boolean isAvailable = staticDirectory.isAvailable();
Assertions.assertTrue(isAvailable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.metrics.event.MetricsDispatcher;
import org.apache.dubbo.rpc.AppResponse;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
Expand All @@ -31,7 +30,6 @@
import org.apache.dubbo.rpc.cluster.directory.StaticDirectory;
import org.apache.dubbo.rpc.cluster.router.state.StateRouterFactory;
import org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker;
import org.apache.dubbo.rpc.model.ApplicationModel;

import javax.script.ScriptEngineManager;

Expand Down Expand Up @@ -63,7 +61,6 @@ class FileRouterEngineTest {

@BeforeAll
public static void setUpBeforeClass() throws Exception {
ApplicationModel.defaultModel().getBeanFactory().registerBean(MetricsDispatcher.class);
System.setProperty(ENABLE_CONNECTIVITY_VALIDATION, "false");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.common.utils.NetUtils;
import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.metrics.event.MetricsDispatcher;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Result;
Expand All @@ -34,7 +33,6 @@
import org.apache.dubbo.rpc.cluster.loadbalance.LeastActiveLoadBalance;
import org.apache.dubbo.rpc.cluster.loadbalance.RandomLoadBalance;
import org.apache.dubbo.rpc.cluster.loadbalance.RoundRobinLoadBalance;
import org.apache.dubbo.rpc.model.ApplicationModel;

import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -109,7 +107,6 @@ public static void afterClass() {
@SuppressWarnings({"unchecked"})
@BeforeEach
public void setUp() throws Exception {
ApplicationModel.defaultModel().getBeanFactory().registerBean(MetricsDispatcher.class);
Map<String, Object> attributes = new HashMap<>();
attributes.put("application", "abstractClusterInvokerTest");
url = url.putAttribute(REFER_KEY, attributes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.common.utils.CollectionUtils;
import org.apache.dubbo.metrics.event.MetricsDispatcher;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Result;
Expand All @@ -28,7 +27,6 @@
import org.apache.dubbo.rpc.cluster.Directory;
import org.apache.dubbo.rpc.cluster.LoadBalance;
import org.apache.dubbo.rpc.cluster.directory.StaticDirectory;
import org.apache.dubbo.rpc.model.ApplicationModel;

import java.util.Collections;
import java.util.HashSet;
Expand Down Expand Up @@ -72,7 +70,6 @@ class ConnectivityValidationTest {

@BeforeEach
public void setup() {
ApplicationModel.defaultModel().getBeanFactory().registerBean(MetricsDispatcher.class);
invoker1 = Mockito.mock(Invoker.class);
invoker2 = Mockito.mock(Invoker.class);
invoker3 = Mockito.mock(Invoker.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.apache.dubbo.rpc.cluster.support;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.metrics.event.MetricsDispatcher;
import org.apache.dubbo.rpc.AppResponse;
import org.apache.dubbo.rpc.AsyncRpcResult;
import org.apache.dubbo.rpc.Invocation;
Expand All @@ -30,7 +29,6 @@
import org.apache.dubbo.rpc.cluster.SingleRouterChain;
import org.apache.dubbo.rpc.cluster.directory.StaticDirectory;
import org.apache.dubbo.rpc.cluster.router.state.BitList;
import org.apache.dubbo.rpc.model.ApplicationModel;
import org.apache.dubbo.rpc.protocol.AbstractInvoker;

import java.util.ArrayList;
Expand Down Expand Up @@ -67,7 +65,6 @@ class FailoverClusterInvokerTest {
*/
@BeforeEach
public void setUp() throws Exception {
ApplicationModel.defaultModel().getBeanFactory().registerBean(MetricsDispatcher.class);
dic = mock(Directory.class);

given(dic.getUrl()).willReturn(url);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.apache.dubbo.rpc.cluster.support;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.metrics.event.MetricsDispatcher;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Result;
Expand All @@ -26,7 +25,6 @@
import org.apache.dubbo.rpc.RpcInvocation;
import org.apache.dubbo.rpc.cluster.LoadBalance;
import org.apache.dubbo.rpc.cluster.directory.StaticDirectory;
import org.apache.dubbo.rpc.model.ApplicationModel;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -89,7 +87,6 @@ public static void afterClass() {
@SuppressWarnings({"unchecked"})
@BeforeEach
public void setUp() throws Exception {
ApplicationModel.defaultModel().getBeanFactory().registerBean(MetricsDispatcher.class);
Map<String, Object> attributes = new HashMap<>();
attributes.put("application", "abstractClusterInvokerTest");
url = url.putAttribute(REFER_KEY, attributes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.extension.ExtensionLoader;
import org.apache.dubbo.metrics.event.MetricsDispatcher;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.Protocol;
Expand All @@ -29,7 +28,6 @@
import org.apache.dubbo.rpc.cluster.LoadBalance;
import org.apache.dubbo.rpc.cluster.directory.StaticDirectory;
import org.apache.dubbo.rpc.cluster.support.AbstractClusterInvoker;
import org.apache.dubbo.rpc.model.ApplicationModel;
import org.apache.dubbo.rpc.support.MockProtocol;

import java.util.ArrayList;
Expand All @@ -51,7 +49,6 @@ class MockClusterInvokerTest {

@BeforeEach
public void beforeMethod() {
ApplicationModel.defaultModel().getBeanFactory().registerBean(MetricsDispatcher.class);
invokers.clear();
}

Expand Down
Loading
Loading