Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/3.2' into rest
Browse files Browse the repository at this point in the history
* origin/3.2:
  Bump version to 3.1.8-SNAPSHOT
  Add Consumer Metrics (#11542)
  Backport of remove apache-rat-plugin. (#11523) (#11592)
  Add hessian allow
  Prepare 3.1.7 release
  • Loading branch information
mytang0 committed Feb 20, 2023
2 parents 05776e2 + c43b631 commit edf3ed2
Show file tree
Hide file tree
Showing 17 changed files with 294 additions and 168 deletions.
9 changes: 0 additions & 9 deletions .github/workflows/build-and-test-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,6 @@ jobs:
with:
name: "class-file"
path: ${{ github.workspace }}/class.zip
- name: "Pack rat file if failure"
if: failure()
run: 7z a ${{ github.workspace }}/rat.zip *rat.txt -r
- name: "Upload rat file if failure"
if: failure()
uses: actions/upload-artifact@v3
with:
name: "rat-file"
path: ${{ github.workspace }}/rat.zip
- name: "Pack checkstyle file if failure"
if: failure()
run: 7z a ${{ github.workspace }}/checkstyle.zip *checkstyle* -r
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ public Result invoke(Invocation invocation) throws RpcException {
return asyncResult;
}

public Invoker<T> getFilterInvoker() {
return filterInvoker;
}

@Override
public Class<T> getInterface() {
return filterInvoker.getInterface();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,4 @@ java.util.UUID
java.util.WeakHashMap
org.apache.dubbo
com.alibaba.dubbo
com.alibaba.com.caucho.hessian.io.java8
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.dubbo.rpc.Exporter;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.ProxyFactory;
import org.apache.dubbo.rpc.cluster.filter.FilterChainBuilder;
import org.apache.dubbo.rpc.cluster.support.registry.ZoneAwareClusterInvoker;
import org.apache.dubbo.rpc.cluster.support.wrapper.MockClusterInvoker;
import org.apache.dubbo.rpc.listener.ListenerInvokerWrapper;
Expand Down Expand Up @@ -480,8 +481,18 @@ void testCreateInvokerForLocalRefer() {
referenceConfig.init();
Assertions.assertTrue(referenceConfig.getInvoker() instanceof MockClusterInvoker);
Invoker<?> withFilter = ((MockClusterInvoker<?>) referenceConfig.getInvoker()).getDirectory().getAllInvokers().get(0);
Assertions.assertTrue(withFilter instanceof ListenerInvokerWrapper);
Assertions.assertTrue(((ListenerInvokerWrapper<?>) withFilter).getInvoker() instanceof InjvmInvoker);
Assertions.assertTrue(withFilter instanceof ListenerInvokerWrapper
|| withFilter instanceof FilterChainBuilder.CallbackRegistrationInvoker);
if (withFilter instanceof ListenerInvokerWrapper) {
Assertions.assertTrue(((ListenerInvokerWrapper<?>) withFilter).getInvoker() instanceof InjvmInvoker);
}
if (withFilter instanceof FilterChainBuilder.CallbackRegistrationInvoker) {
Invoker filterInvoker = ((FilterChainBuilder.CallbackRegistrationInvoker) withFilter).getFilterInvoker();
FilterChainBuilder.CopyOfFilterChainNode filterInvoker1 = (FilterChainBuilder.CopyOfFilterChainNode) filterInvoker;
ListenerInvokerWrapper originalInvoker = (ListenerInvokerWrapper) filterInvoker1.getOriginalInvoker();
Invoker invoker = originalInvoker.getInvoker();
Assertions.assertTrue(invoker instanceof InjvmInvoker);
}
URL url = withFilter.getUrl();
Assertions.assertEquals("application1", url.getParameter("application"));
Assertions.assertEquals("value1", url.getParameter("key1"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@

package org.apache.dubbo.metrics.model;

import org.apache.dubbo.common.constants.CommonConstants;
import org.apache.dubbo.rpc.Invocation;
import org.apache.dubbo.rpc.Invoker;
import org.apache.dubbo.rpc.RpcInvocation;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;

import static org.apache.dubbo.common.constants.CommonConstants.PROVIDER_SIDE;
import static org.apache.dubbo.common.constants.CommonConstants.GROUP_CHAR_SEPARATOR;
import static org.apache.dubbo.common.constants.CommonConstants.PATH_SEPARATOR;
import static org.apache.dubbo.common.constants.MetricsConstants.TAG_IP;
import static org.apache.dubbo.common.constants.MetricsConstants.TAG_HOSTNAME;
import static org.apache.dubbo.common.constants.MetricsConstants.TAG_APPLICATION_NAME;
Expand All @@ -41,6 +45,7 @@
*/
public class MethodMetric implements Metric {
private String applicationName;
private String side;
private String interfaceName;
private String methodName;
private String group;
Expand Down Expand Up @@ -100,30 +105,6 @@ public Map<String, String> getTags() {
return tags;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
MethodMetric that = (MethodMetric) o;
return Objects.equals(interfaceName, that.interfaceName) && Objects.equals(methodName, that.methodName)
&& Objects.equals(group, that.group) && Objects.equals(version, that.version);
}

@Override
public int hashCode() {
return Objects.hash(interfaceName, methodName, group, version);
}

@Override
public String toString() {
return "MethodMetric{" +
"interfaceName='" + interfaceName + '\'' +
", methodName='" + methodName + '\'' +
", group='" + group + '\'' +
", version='" + version + '\'' +
'}';
}

private void init(Invocation invocation) {
String serviceUniqueName = invocation.getTargetServiceUniqueName();
String methodName = invocation.getMethodName();
Expand All @@ -135,21 +116,62 @@ && isGenericCall(((RpcInvocation) invocation).getParameterTypesDesc(), methodNam
}
String group = null;
String interfaceAndVersion;
String[] arr = serviceUniqueName.split(CommonConstants.PATH_SEPARATOR);
String[] arr = serviceUniqueName.split(PATH_SEPARATOR);
if (arr.length == 2) {
group = arr[0];
interfaceAndVersion = arr[1];
} else {
interfaceAndVersion = arr[0];
}

String[] ivArr = interfaceAndVersion.split(CommonConstants.GROUP_CHAR_SEPARATOR);
String[] ivArr = interfaceAndVersion.split(GROUP_CHAR_SEPARATOR);
String interfaceName = ivArr[0];
String version = ivArr.length == 2 ? ivArr[1] : null;

Optional<? extends Invoker<?>> invoker = Optional.ofNullable(invocation.getInvoker());
this.side = invoker.isPresent() ? invoker.get().getUrl().getSide() : PROVIDER_SIDE;
this.interfaceName = interfaceName;
this.methodName = methodName;
this.group = group;
this.version = version;
}

public String getApplicationName() {
return applicationName;
}

public void setApplicationName(String applicationName) {
this.applicationName = applicationName;
}

public String getSide() {
return side;
}

public void setSide(String side) {
this.side = side;
}

@Override
public String toString() {
return "MethodMetric{" +
"applicationName='" + applicationName + '\'' +
", side='" + side + '\'' +
", interfaceName='" + interfaceName + '\'' +
", methodName='" + methodName + '\'' +
", group='" + group + '\'' +
", version='" + version + '\'' +
'}';
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
MethodMetric that = (MethodMetric) o;
return Objects.equals(applicationName, that.applicationName) && Objects.equals(side, that.side) && Objects.equals(interfaceName, that.interfaceName) && Objects.equals(methodName, that.methodName) && Objects.equals(group, that.group) && Objects.equals(version, that.version);
}

@Override
public int hashCode() {
return Objects.hash(applicationName, side, interfaceName, methodName, group, version);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,32 @@ public enum MetricsKey {
APPLICATION_METRIC_INFO("dubbo.application.info.total", "Total Application Info"),

// provider metrics key
PROVIDER_METRIC_REQUESTS("dubbo.provider.requests.total", "Total Requests"),
PROVIDER_METRIC_REQUESTS_SUCCEED("dubbo.provider.requests.succeed.total", "Succeed Requests"),
PROVIDER_METRIC_REQUEST_BUSINESS_FAILED("dubbo.provider.requests.business.failed.total","Failed Business Requests"),
PROVIDER_METRIC_REQUESTS_PROCESSING("dubbo.provider.requests.processing", "Processing Requests"),
PROVIDER_METRIC_REQUESTS_TIMEOUT("dubbo.provider.requests.timeout.total", "Total Timeout Failed Requests"),
PROVIDER_METRIC_REQUESTS_LIMIT("dubbo.provider.requests.limit.total", "Total Limit Failed Requests"),
PROVIDER_METRIC_REQUESTS_FAILED("dubbo.provider.requests.unknown.failed.total", "Unknown Failed Requests"),
PROVIDER_METRIC_REQUESTS_TOTAL_FAILED("dubbo.provider.requests.failed.total", "Total Failed Requests"),
METRIC_REQUESTS("dubbo.%s.requests.total", "Total Requests"),
METRIC_REQUESTS_SUCCEED("dubbo.%s.requests.succeed.total", "Succeed Requests"),
METRIC_REQUEST_BUSINESS_FAILED("dubbo.%s.requests.business.failed.total","Failed Business Requests"),
METRIC_REQUESTS_PROCESSING("dubbo.%s.requests.processing", "Processing Requests"),
METRIC_REQUESTS_TIMEOUT("dubbo.%s.requests.timeout.total", "Total Timeout Failed Requests"),
METRIC_REQUESTS_LIMIT("dubbo.%s.requests.limit.total", "Total Limit Failed Requests"),
METRIC_REQUESTS_FAILED("dubbo.%s.requests.unknown.failed.total", "Unknown Failed Requests"),
METRIC_REQUESTS_TOTAL_FAILED("dubbo.%s.requests.failed.total", "Total Failed Requests"),


PROVIDER_METRIC_REQUESTS_TOTAL_AGG("dubbo.provider.requests.total.aggregate", "Aggregated Total Requests"),
PROVIDER_METRIC_REQUESTS_SUCCEED_AGG("dubbo.provider.requests.succeed.aggregate", "Aggregated Succeed Requests"),
PROVIDER_METRIC_REQUESTS_FAILED_AGG("dubbo.provider.requests.failed.aggregate", "Aggregated Failed Requests"),
PROVIDER_METRIC_REQUESTS_BUSINESS_FAILED_AGG("dubbo.provider.requests.business.failed.aggregate", "Aggregated Business Failed Requests"),
PROVIDER_METRIC_REQUESTS_TIMEOUT_AGG("dubbo.provider.requests.timeout.failed.aggregate", "Aggregated timeout Failed Requests"),
PROVIDER_METRIC_REQUESTS_LIMIT_AGG("dubbo.provider.requests.limit.aggregate", "Aggregated limit Requests"),
PROVIDER_METRIC_REQUESTS_TOTAL_FAILED_AGG("dubbo.provider.requests.failed.total.aggregate", "Aggregated failed total Requests"),
METRIC_REQUESTS_TOTAL_AGG("dubbo.%s.requests.total.aggregate", "Aggregated Total Requests"),
METRIC_REQUESTS_SUCCEED_AGG("dubbo.%s.requests.succeed.aggregate", "Aggregated Succeed Requests"),
METRIC_REQUESTS_FAILED_AGG("dubbo.%s.requests.failed.aggregate", "Aggregated Failed Requests"),
METRIC_REQUESTS_BUSINESS_FAILED_AGG("dubbo.%s.requests.business.failed.aggregate", "Aggregated Business Failed Requests"),
METRIC_REQUESTS_TIMEOUT_AGG("dubbo.%s.requests.timeout.failed.aggregate", "Aggregated timeout Failed Requests"),
METRIC_REQUESTS_LIMIT_AGG("dubbo.%s.requests.limit.aggregate", "Aggregated limit Requests"),
METRIC_REQUESTS_TOTAL_FAILED_AGG("dubbo.%s.requests.failed.total.aggregate", "Aggregated failed total Requests"),

PROVIDER_METRIC_QPS("dubbo.provider.qps.seconds", "Query Per Seconds"),
PROVIDER_METRIC_RT_LAST("dubbo.provider.rt.seconds.last", "Last Response Time"),
PROVIDER_METRIC_RT_MIN("dubbo.provider.rt.seconds.min", "Min Response Time"),
PROVIDER_METRIC_RT_MAX("dubbo.provider.rt.seconds.max", "Max Response Time"),
PROVIDER_METRIC_RT_SUM("dubbo.provider.rt.seconds.sum", "Sum Response Time"),
PROVIDER_METRIC_RT_AVG("dubbo.provider.rt.seconds.avg", "Average Response Time"),
PROVIDER_METRIC_RT_P99("dubbo.provider.rt.seconds.p99", "Response Time P99"),
PROVIDER_METRIC_RT_P95("dubbo.provider.rt.seconds.p95", "Response Time P95"),
METRIC_QPS("dubbo.%s.qps.seconds", "Query Per Seconds"),
METRIC_RT_LAST("dubbo.%s.rt.seconds.last", "Last Response Time"),
METRIC_RT_MIN("dubbo.%s.rt.seconds.min", "Min Response Time"),
METRIC_RT_MAX("dubbo.%s.rt.seconds.max", "Max Response Time"),
METRIC_RT_SUM("dubbo.%s.rt.seconds.sum", "Sum Response Time"),
METRIC_RT_AVG("dubbo.%s.rt.seconds.avg", "Average Response Time"),
METRIC_RT_P99("dubbo.%s.rt.seconds.p99", "Response Time P99"),
METRIC_RT_P95("dubbo.%s.rt.seconds.p95", "Response Time P95"),

GENERIC_METRIC_REQUESTS("dubbo.%s.requests.total", "Total %s Requests"),
GENERIC_METRIC_REQUESTS_SUCCEED("dubbo.%s.requests.succeed.total", "Succeed %s Requests"),
Expand All @@ -65,17 +65,17 @@ public enum MetricsKey {
THREAD_POOL_MAX_SIZE("dubbo.thread.pool.max.size","Thread Pool Max Size"),
THREAD_POOL_ACTIVE_SIZE("dubbo.thread.pool.active.size","Thread Pool Active Size"),
THREAD_POOL_THREAD_COUNT("dubbo.thread.pool.thread.count","Thread Pool Thread Count"),
THREAD_POOL_QUEUE_SIZE("dubbo.thread.pool.queue.size","Thread Pool Queue Size"),

// consumer metrics key
;
THREAD_POOL_QUEUE_SIZE("dubbo.thread.pool.queue.size","Thread Pool Queue Size");

private final String name;
private final String description;

public final String getName() {
return this.name;
}
public final String getNameByType(String type) {
return String.format(name, type);
}

public final String getDescription() {
return this.description;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public GaugeMetricSample(MetricsKey metricsKey, Map<String, String> tags, Metric
this.supplier = supplier;
}

public GaugeMetricSample(String name, String description, Map<String, String> tags, MetricsCategory category, Supplier<Number> supplier) {
super(name, description, tags, Type.GAUGE, category);
this.supplier = supplier;
}

public GaugeMetricSample(String name, String description, Map<String, String> tags, MetricsCategory category, String baseUnit, Supplier<Number> supplier) {
super(name, description, tags, Type.GAUGE, category, baseUnit);
this.supplier = supplier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public String toString() {
'}';
}


public enum Type {
COUNTER,
GAUGE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@

package org.apache.dubbo.metrics.collector;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import org.apache.dubbo.common.utils.ConcurrentHashMapUtils;
import org.apache.dubbo.config.MetricsConfig;
import org.apache.dubbo.config.context.ConfigManager;
Expand All @@ -33,11 +38,6 @@
import org.apache.dubbo.metrics.model.sample.MetricSample;
import org.apache.dubbo.rpc.model.ApplicationModel;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import static org.apache.dubbo.metrics.model.MetricsCategory.QPS;
import static org.apache.dubbo.metrics.model.MetricsCategory.REQUESTS;
import static org.apache.dubbo.metrics.model.MetricsCategory.RT;
Expand Down Expand Up @@ -102,7 +102,7 @@ private void onRTEvent(RTEvent event) {

private void onRequestEvent(RequestEvent event) {
MethodMetric metric = (MethodMetric) event.getSource();
MetricsEvent.Type type = event.getType();
RequestEvent.Type type = event.getType();
TimeWindowCounter counter = null;
switch (type) {
case TOTAL:
Expand Down Expand Up @@ -152,23 +152,39 @@ public List<MetricSample> collect() {
}

private void collectRequests(List<MetricSample> list) {
totalRequests.forEach((k, v) -> list.add(new GaugeMetricSample(MetricsKey.PROVIDER_METRIC_REQUESTS_TOTAL_AGG, k.getTags(), REQUESTS, v::get)));
succeedRequests.forEach((k, v) -> list.add(new GaugeMetricSample(MetricsKey.PROVIDER_METRIC_REQUESTS_SUCCEED_AGG, k.getTags(), REQUESTS, v::get)));
unknownFailedRequests.forEach((k, v) -> list.add(new GaugeMetricSample(MetricsKey.PROVIDER_METRIC_REQUESTS_FAILED_AGG, k.getTags(), REQUESTS, v::get)));
businessFailedRequests.forEach((k, v) -> list.add(new GaugeMetricSample(MetricsKey.PROVIDER_METRIC_REQUESTS_BUSINESS_FAILED_AGG, k.getTags(), REQUESTS, v::get)));
timeoutRequests.forEach((k, v) -> list.add(new GaugeMetricSample(MetricsKey.PROVIDER_METRIC_REQUESTS_TIMEOUT_AGG, k.getTags(), REQUESTS, v::get)));
limitRequests.forEach((k, v) -> list.add(new GaugeMetricSample(MetricsKey.PROVIDER_METRIC_REQUESTS_LIMIT_AGG, k.getTags(), REQUESTS, v::get)));
totalFailedRequests.forEach((k, v) -> list.add(new GaugeMetricSample(MetricsKey.PROVIDER_METRIC_REQUESTS_TOTAL_FAILED_AGG, k.getTags(), REQUESTS, v::get)));
totalRequests.forEach((k, v) ->
list.add(getGaugeMetricSample(MetricsKey.METRIC_REQUESTS_TOTAL_AGG, k, v)));
succeedRequests.forEach((k, v) ->
list.add(getGaugeMetricSample(MetricsKey.METRIC_REQUESTS_SUCCEED_AGG, k, v)));
unknownFailedRequests.forEach((k, v) ->
list.add(getGaugeMetricSample(MetricsKey.METRIC_REQUESTS_FAILED_AGG, k, v)));
businessFailedRequests.forEach((k, v) ->
list.add(getGaugeMetricSample(MetricsKey.METRIC_REQUESTS_BUSINESS_FAILED_AGG, k, v)));
timeoutRequests.forEach((k, v) ->
list.add(getGaugeMetricSample(MetricsKey.METRIC_REQUESTS_TIMEOUT_AGG, k, v)));
limitRequests.forEach((k, v) ->
list.add(getGaugeMetricSample(MetricsKey.METRIC_REQUESTS_LIMIT_AGG, k, v)));
totalFailedRequests.forEach((k, v) ->
list.add(getGaugeMetricSample(MetricsKey.METRIC_REQUESTS_TOTAL_FAILED_AGG, k, v)));

}

private GaugeMetricSample getGaugeMetricSample(MetricsKey metricRequestsTotalAgg, MethodMetric k, TimeWindowCounter v) {
return new GaugeMetricSample(metricRequestsTotalAgg.getNameByType(k.getSide()),
metricRequestsTotalAgg.getDescription(), k.getTags(), REQUESTS, v::get);
}

private void collectQPS(List<MetricSample> list) {
qps.forEach((k, v) -> list.add(new GaugeMetricSample(MetricsKey.PROVIDER_METRIC_QPS, k.getTags(), QPS, () -> v.get() / v.bucketLivedSeconds())));
qps.forEach((k, v) -> list.add(new GaugeMetricSample(MetricsKey.METRIC_QPS.getNameByType(k.getSide()),
MetricsKey.METRIC_QPS.getDescription(), k.getTags(), QPS, () -> v.get() / v.bucketLivedSeconds())));
}

private void collectRT(List<MetricSample> list) {
rt.forEach((k, v) -> {
list.add(new GaugeMetricSample(MetricsKey.PROVIDER_METRIC_RT_P99, k.getTags(), RT, () -> v.quantile(0.99)));
list.add(new GaugeMetricSample(MetricsKey.PROVIDER_METRIC_RT_P95, k.getTags(), RT, () -> v.quantile(0.95)));
list.add(new GaugeMetricSample(MetricsKey.METRIC_RT_P99.getNameByType(k.getSide()),
MetricsKey.METRIC_RT_P99.getDescription(), k.getTags(), RT, () -> v.quantile(0.99)));
list.add(new GaugeMetricSample(MetricsKey.METRIC_RT_P95.getNameByType(k.getSide()),
MetricsKey.METRIC_RT_P95.getDescription(), k.getTags(), RT, () -> v.quantile(0.95)));
});
}
}
Loading

0 comments on commit edf3ed2

Please sign in to comment.