Metrics event split (#12888)
* Split event-related api out of dubbo-metrics-api. * Add new module to .artifacts * Temporary remove dubbo-plugin-metrics * Fix pom * * Remove the use of dispatcher name * * Bug fix * * Bug fix * Update ScopeClusterInvokerTest.java * * Trigger test * * Fix ut --------- Co-authored-by: songxiaosheng <songxiaosheng@elastic.link>
This commit is contained in:
parent
f91246ab09
commit
bf3d4f4ca3
|
|
@ -66,6 +66,7 @@ dubbo-metrics-prometheus
|
|||
dubbo-metrics-registry
|
||||
dubbo-metrics-config-center
|
||||
dubbo-metrics-netty
|
||||
dubbo-metrics-event
|
||||
dubbo-monitor
|
||||
dubbo-monitor-api
|
||||
dubbo-monitor-common
|
||||
|
|
|
|||
|
|
@ -60,7 +60,6 @@ import static org.apache.dubbo.common.constants.CommonConstants.MONITOR_KEY;
|
|||
import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY;
|
||||
import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY;
|
||||
import static org.apache.dubbo.rpc.cluster.Constants.CLUSTER_AVAILABLE_CHECK_KEY;
|
||||
import static org.apache.dubbo.rpc.cluster.Constants.INVOCATION_NEED_MOCK;
|
||||
import static org.apache.dubbo.rpc.cluster.Constants.REFER_KEY;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.same;
|
||||
|
|
|
|||
|
|
@ -190,6 +190,13 @@
|
|||
</dependency>
|
||||
|
||||
<!-- metrics -->
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-metrics-event</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-metrics-api</artifactId>
|
||||
|
|
@ -690,6 +697,7 @@
|
|||
<include>org.apache.dubbo:dubbo-metadata-report-nacos</include>
|
||||
<include>org.apache.dubbo:dubbo-metadata-report-redis</include>
|
||||
<include>org.apache.dubbo:dubbo-metadata-report-zookeeper</include>
|
||||
<include>org.apache.dubbo:dubbo-metrics-event</include>
|
||||
<include>org.apache.dubbo:dubbo-metrics-api</include>
|
||||
<include>org.apache.dubbo:dubbo-metrics-default</include>
|
||||
<include>org.apache.dubbo:dubbo-metrics-registry</include>
|
||||
|
|
|
|||
|
|
@ -251,6 +251,11 @@
|
|||
<artifactId>dubbo-metrics-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-metrics-event</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-metrics-default</artifactId>
|
||||
|
|
|
|||
|
|
@ -36,6 +36,11 @@
|
|||
<artifactId>dubbo-common</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-metrics-event</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-rpc-api</artifactId>
|
||||
|
|
|
|||
|
|
@ -19,7 +19,10 @@ package org.apache.dubbo.metrics.collector;
|
|||
|
||||
import org.apache.dubbo.common.URL;
|
||||
import org.apache.dubbo.common.constants.CommonConstants;
|
||||
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
|
||||
import org.apache.dubbo.common.logger.LoggerFactory;
|
||||
import org.apache.dubbo.config.ApplicationConfig;
|
||||
import org.apache.dubbo.metrics.MetricsConstants;
|
||||
import org.apache.dubbo.metrics.TestMetricsInvoker;
|
||||
import org.apache.dubbo.metrics.event.MetricsDispatcher;
|
||||
import org.apache.dubbo.metrics.event.RequestEvent;
|
||||
|
|
@ -134,6 +137,9 @@ class DefaultCollectorTest {
|
|||
DefaultMetricsCollector collector = applicationModel.getBeanFactory().getOrRegisterBean(DefaultMetricsCollector.class);
|
||||
collector.setCollectEnabled(true);
|
||||
|
||||
ErrorTypeAwareLogger logger = LoggerFactory.getErrorTypeAwareLogger(DefaultCollectorTest.class);
|
||||
logger.warn("0-99","","","Test error code message.");
|
||||
|
||||
metricsFilter.invoke(new TestMetricsInvoker(side), invocation);
|
||||
try {
|
||||
Thread.sleep(50);
|
||||
|
|
@ -150,8 +156,8 @@ class DefaultCollectorTest {
|
|||
|
||||
// push finish rt +1
|
||||
List<MetricSample> metricSamples = collector.collect();
|
||||
//num(total+success+processing) + rt(5) = 8
|
||||
Assertions.assertEquals(8, metricSamples.size());
|
||||
//num(total+success+processing) + rt(5) + error code = 9
|
||||
Assertions.assertEquals(metricSamples.size(),9);
|
||||
List<String> metricsNames = metricSamples.stream().map(MetricSample::getName).collect(Collectors.toList());
|
||||
// No error will contain total+success+processing
|
||||
String REQUESTS = new MetricsKeyWrapper(METRIC_REQUESTS, MetricsPlaceValue.of(side, MetricsLevel.SERVICE)).targetKey();
|
||||
|
|
@ -192,8 +198,8 @@ class DefaultCollectorTest {
|
|||
long c2 = eventObj.getTimePair().calc();
|
||||
metricSamples = collector.collect();
|
||||
|
||||
// num(total+success+error+total_error+processing) + rt(5) = 5
|
||||
Assertions.assertEquals(10, metricSamples.size());
|
||||
// num(total+success+error+total_error+processing) + rt(5) + error code = 11
|
||||
Assertions.assertEquals(11, metricSamples.size());
|
||||
|
||||
String TIMEOUT = new MetricsKeyWrapper(METRIC_REQUESTS_TIMEOUT, MetricsPlaceValue.of(side, MetricsLevel.SERVICE)).targetKey();
|
||||
String TOTAL_FAILED = new MetricsKeyWrapper(METRIC_REQUESTS_TOTAL_FAILED, MetricsPlaceValue.of(side, MetricsLevel.SERVICE)).targetKey();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,42 @@
|
|||
<!--
|
||||
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.
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-metrics</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<artifactId>dubbo-metrics-event</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>${project.artifactId}</name>
|
||||
<description>The metrics event-related api module of dubbo project</description>
|
||||
<properties>
|
||||
<skip_maven_deploy>false</skip_maven_deploy>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-common</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
|
@ -19,7 +19,6 @@ package org.apache.dubbo.metrics.event;
|
|||
|
||||
import org.apache.dubbo.common.beans.factory.ScopeBeanFactory;
|
||||
import org.apache.dubbo.metrics.exception.MetricsNeverHappenException;
|
||||
import org.apache.dubbo.metrics.model.MethodMetric;
|
||||
import org.apache.dubbo.metrics.model.key.TypeWrapper;
|
||||
import org.apache.dubbo.rpc.model.ApplicationModel;
|
||||
|
||||
|
|
@ -33,13 +32,13 @@ import java.util.Map;
|
|||
public abstract class MetricsEvent {
|
||||
|
||||
/**
|
||||
* Metric object. (eg. {@link MethodMetric})
|
||||
* Metric object. (eg. MethodMetric)
|
||||
*/
|
||||
protected transient final ApplicationModel source;
|
||||
private boolean available = true;
|
||||
private final TypeWrapper typeWrapper;
|
||||
private final String appName;
|
||||
private final MetricsDispatcher metricsDispatcher;
|
||||
private final MetricsEventMulticaster metricsEventMulticaster;
|
||||
|
||||
private final Map<String, Object> attachments = new IdentityHashMap<>(8);
|
||||
|
||||
|
|
@ -47,7 +46,7 @@ public abstract class MetricsEvent {
|
|||
this(source, null, null, typeWrapper);
|
||||
}
|
||||
|
||||
public MetricsEvent(ApplicationModel source, String appName, MetricsDispatcher metricsDispatcher, TypeWrapper typeWrapper) {
|
||||
public MetricsEvent(ApplicationModel source, String appName, MetricsEventMulticaster metricsEventMulticaster, TypeWrapper typeWrapper) {
|
||||
this.typeWrapper = typeWrapper;
|
||||
if (source == null) {
|
||||
this.source = ApplicationModel.defaultModel();
|
||||
|
|
@ -56,20 +55,20 @@ public abstract class MetricsEvent {
|
|||
} else {
|
||||
this.source = source;
|
||||
}
|
||||
if (metricsDispatcher == null) {
|
||||
if (metricsEventMulticaster == null) {
|
||||
if (this.source.isDestroyed()) {
|
||||
this.metricsDispatcher = null;
|
||||
this.metricsEventMulticaster = null;
|
||||
} else {
|
||||
ScopeBeanFactory beanFactory = this.source.getBeanFactory();
|
||||
if (beanFactory.isDestroyed()) {
|
||||
this.metricsDispatcher = null;
|
||||
this.metricsEventMulticaster = null;
|
||||
} else {
|
||||
MetricsDispatcher dispatcher = beanFactory.getBean(MetricsDispatcher.class);
|
||||
this.metricsDispatcher = dispatcher;
|
||||
MetricsEventMulticaster dispatcher = beanFactory.getBean(MetricsEventMulticaster.class);
|
||||
this.metricsEventMulticaster = dispatcher;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.metricsDispatcher = metricsDispatcher;
|
||||
this.metricsEventMulticaster = metricsEventMulticaster;
|
||||
}
|
||||
if (appName == null) {
|
||||
this.appName = this.source.tryGetApplicationName();
|
||||
|
|
@ -115,8 +114,8 @@ public abstract class MetricsEvent {
|
|||
return source;
|
||||
}
|
||||
|
||||
public MetricsDispatcher getMetricsDispatcher() {
|
||||
return metricsDispatcher;
|
||||
public MetricsEventMulticaster getMetricsEventMulticaster() {
|
||||
return metricsEventMulticaster;
|
||||
}
|
||||
|
||||
public String appName() {
|
||||
|
|
@ -42,7 +42,7 @@ public class MetricsEventBus {
|
|||
if (event.getSource() == null) {
|
||||
return;
|
||||
}
|
||||
MetricsDispatcher dispatcher = event.getMetricsDispatcher();
|
||||
MetricsEventMulticaster dispatcher = event.getMetricsEventMulticaster();
|
||||
Optional.ofNullable(dispatcher).ifPresent(d -> {
|
||||
tryInvoke(() -> d.publishEvent(event));
|
||||
});
|
||||
|
|
@ -106,13 +106,14 @@ public class MetricsEventBus {
|
|||
* eventSaveRunner saves the event, so that the calculation rt is introverted
|
||||
*/
|
||||
public static void before(MetricsEvent event) {
|
||||
MetricsDispatcher dispatcher = validate(event);
|
||||
MetricsEventMulticaster dispatcher = validate(event);
|
||||
|
||||
if (dispatcher == null) return;
|
||||
tryInvoke(() -> dispatcher.publishEvent(event));
|
||||
}
|
||||
|
||||
public static void after(MetricsEvent event, Object result) {
|
||||
MetricsDispatcher dispatcher = validate(event);
|
||||
MetricsEventMulticaster dispatcher = validate(event);
|
||||
if (dispatcher == null) return;
|
||||
tryInvoke(() -> {
|
||||
event.customAfterPost(result);
|
||||
|
|
@ -121,13 +122,13 @@ public class MetricsEventBus {
|
|||
}
|
||||
|
||||
public static void error(MetricsEvent event) {
|
||||
MetricsDispatcher dispatcher = validate(event);
|
||||
MetricsEventMulticaster dispatcher = validate(event);
|
||||
if (dispatcher == null) return;
|
||||
tryInvoke(() -> dispatcher.publishErrorEvent((TimeCounterEvent) event));
|
||||
}
|
||||
|
||||
private static MetricsDispatcher validate(MetricsEvent event) {
|
||||
MetricsDispatcher dispatcher = event.getMetricsDispatcher();
|
||||
private static MetricsEventMulticaster validate(MetricsEvent event) {
|
||||
MetricsEventMulticaster dispatcher = event.getMetricsEventMulticaster();
|
||||
if (dispatcher == null) {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -33,7 +33,7 @@ public abstract class TimeCounterEvent extends MetricsEvent {
|
|||
this.timePair = TimePair.start();
|
||||
}
|
||||
|
||||
public TimeCounterEvent(ApplicationModel source, String appName, MetricsDispatcher metricsDispatcher, TypeWrapper typeWrapper) {
|
||||
public TimeCounterEvent(ApplicationModel source, String appName,MetricsEventMulticaster metricsDispatcher, TypeWrapper typeWrapper) {
|
||||
super(source, appName, metricsDispatcher, typeWrapper);
|
||||
this.timePair = TimePair.start();
|
||||
}
|
||||
|
|
@ -19,6 +19,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<modules>
|
||||
<module>dubbo-metrics-api</module>
|
||||
<module>dubbo-metrics-event</module>
|
||||
<module>dubbo-metrics-default</module>
|
||||
<module>dubbo-metrics-registry</module>
|
||||
<module>dubbo-metrics-metadata</module>
|
||||
|
|
|
|||
|
|
@ -181,6 +181,11 @@
|
|||
<artifactId>dubbo-metrics-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-metrics-event</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-metrics-default</artifactId>
|
||||
|
|
|
|||
Loading…
Reference in New Issue