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

Optimization dubbo meter pull delay and add dubbo version meter #11457

Merged
merged 41 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
8539673
fix MetericsService resource location bug
songxiaosheng Nov 30, 2022
9ce8e99
Merge branch 'apache:3.2' into 3.2
songxiaosheng Jan 8, 2023
e9e6ee9
:art:为jvm指标增加dubbo应用名称
songxiaosheng Jan 8, 2023
31da007
Merge branch '3.2' of github.com:songxiaosheng/dubbo into 3.2
songxiaosheng Jan 8, 2023
7be6dff
:art: jvm meter add application name label
songxiaosheng Jan 8, 2023
fdad9c8
fix unit test failure
songxiaosheng Jan 9, 2023
bca179a
Merge branch 'apache:3.2' into 3.2
songxiaosheng Jan 9, 2023
c7ff71f
Merge branch '3.2' of github.com:apache/dubbo into 3.2
songxiaosheng Jan 29, 2023
baa4801
:bug: fix metrics filter path
songxiaosheng Jan 29, 2023
87fa520
Merge branch '3.2' of github.com:songxiaosheng/dubbo into 3.2
songxiaosheng Jan 29, 2023
a3d8f89
Merge branch 'apache:3.2' into 3.2
songxiaosheng Jan 30, 2023
696da1b
Merge branch 'apache:3.2' into 3.2
songxiaosheng Jan 30, 2023
59db532
Merge branch 'apache:3.2' into 3.2
songxiaosheng Jan 30, 2023
19d82f2
:bento: :bento: provider collector to FrameworkModel scope
songxiaosheng Jan 30, 2023
80f8b30
:bento:provider collector to FrameworkModel scope
songxiaosheng Jan 30, 2023
edf7446
:bento:provider collector to FrameworkModel scope
songxiaosheng Jan 30, 2023
df26987
:bento:provider collector to FrameworkModel scope
songxiaosheng Jan 30, 2023
503ee0a
:bento:provider collector to FrameworkModel scope
songxiaosheng Jan 31, 2023
d1b7410
:bento:provider collector to FrameworkModel scope
songxiaosheng Jan 31, 2023
1138fb6
Merge branch 'apache:3.2' into 3.2
songxiaosheng Jan 31, 2023
4c96de7
Merge branch '3.2' of github.com:apache/dubbo into 3.2
songxiaosheng Jan 31, 2023
f61db6b
Merge branch '3.2' of github.com:songxiaosheng/dubbo into 3.2
songxiaosheng Feb 1, 2023
6f99220
:bento:provider collector to FrameworkModel scope
songxiaosheng Feb 1, 2023
88033b8
resolve pr conflicts
songxiaosheng Feb 1, 2023
85adc20
resolve pr conflicts
songxiaosheng Feb 1, 2023
ba0ba83
resolve pr conflicts
songxiaosheng Feb 1, 2023
1a9907d
Merge branch 'apache:3.2' into 3.2
songxiaosheng Feb 3, 2023
cae4122
:sparkles: add application meter and fix pull delay
songxiaosheng Feb 4, 2023
c74aded
Merge branch '3.2' of github.com:songxiaosheng/dubbo into 3.2
songxiaosheng Feb 4, 2023
cc5e218
:sparkles: add application meter and fix pull delay
songxiaosheng Feb 5, 2023
aa15fd0
:sparkles: add application meter and fix pull delay
songxiaosheng Feb 5, 2023
14e5ff9
:sparkles: add application meter and fix pull delay
songxiaosheng Feb 6, 2023
dede11e
Merge branch 'apache:3.2' into 3.2
songxiaosheng Feb 6, 2023
cf88fca
:sparkles: add application meter and fix pull delay
songxiaosheng Feb 6, 2023
3f1915d
Merge branch '3.2' of github.com:songxiaosheng/dubbo into 3.2
songxiaosheng Feb 6, 2023
600b8d1
:sparkles: add application meter and fix pull delay
songxiaosheng Feb 6, 2023
54a8576
Merge branch '3.2' of github.com:apache/dubbo into 3.2
songxiaosheng Feb 6, 2023
cce870b
✨ add application meter and fix pull delay
songxiaosheng Feb 6, 2023
fe41423
Merge branch '3.2' of github.com:apache/dubbo into 3.2
songxiaosheng Feb 7, 2023
3643780
✨ add application meter and fix pull delay
songxiaosheng Feb 7, 2023
172bbe2
:white_check_mark: fix unit test error
songxiaosheng Feb 8, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public interface MetricsConstants {

String TAG_VERSION_KEY = "version";

String TAG_APPLICATION_VERSION_KEY = "application.version";

String ENABLE_JVM_METRICS_KEY = "enable.jvm.metrics";

String AGGREGATION_COLLECTOR_KEY = "aggregation";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.apache.dubbo.config.deploy;

import org.apache.dubbo.common.URL;
import org.apache.dubbo.common.Version;
import org.apache.dubbo.common.config.ConfigurationUtils;
import org.apache.dubbo.common.config.Environment;
import org.apache.dubbo.common.config.ReferenceCache;
Expand Down Expand Up @@ -364,6 +365,7 @@ private void initMetricsReporter() {
// TODO compatible with old usage of metrics, remove protocol check after new metrics is ready for use.
if (metricsConfig != null && PROTOCOL_PROMETHEUS.equals(metricsConfig.getProtocol())) {
collector.setCollectEnabled(true);
collector.addApplicationInfo(applicationModel.getApplicationName(), Version.getVersion());
String protocol = metricsConfig.getProtocol();
if (StringUtils.isNotEmpty(protocol)) {
MetricsReporterFactory metricsReporterFactory = getExtensionLoader(MetricsReporterFactory.class).getAdaptiveExtension();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,7 @@ public interface MetricsStatHandler {
MetricsEvent increase(String applicationName, Invocation invocation);

MetricsEvent decrease(String applicationName, Invocation invocation);

MetricsEvent addApplication(String applicationName, String version);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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.metrics.event;

public class ApplicationEvent extends MetricsEvent{
private ApplicationEvent.Type type;

public ApplicationEvent(Object source, ApplicationEvent.Type type) {
super(source);
this.type = type;
}

public ApplicationEvent.Type getType() {
return type;
}

public void setType(ApplicationEvent.Type type) {
this.type = type;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,16 @@ public Object getSource() {
public String toString() {
return getClass().getName() + "[source=" + source + "]";
}

public enum Type {
TOTAL,
SUCCEED,
BUSINESS_FAILED,
REQUEST_TIMEOUT,
REQUEST_LIMIT,
PROCESSING,
UNKNOWN_FAILED,
TOTAL_FAILED,
APPLICATION_INFO
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,5 @@ public void setType(Type type) {
this.type = type;
}

public enum Type {
TOTAL,
SUCCEED,
BUSINESS_FAILED,
REQUEST_TIMEOUT,
REQUEST_LIMIT,
PROCESSING,
UNKNOWN_FAILED,
TOTAL_FAILED
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* 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.metrics.model;

import java.util.HashMap;
import java.util.Map;

import static org.apache.dubbo.common.constants.MetricsConstants.TAG_HOSTNAME;
import static org.apache.dubbo.common.constants.MetricsConstants.TAG_APPLICATION_VERSION_KEY;
import static org.apache.dubbo.common.constants.MetricsConstants.TAG_APPLICATION_NAME;
import static org.apache.dubbo.common.constants.MetricsConstants.TAG_IP;
import static org.apache.dubbo.common.utils.NetUtils.getLocalHost;
import static org.apache.dubbo.common.utils.NetUtils.getLocalHostName;

public class ApplicationMetric implements Metric {
private String applicationName;
private String version;

public ApplicationMetric(String applicationName, String version) {
this.applicationName = applicationName;
this.version = version;
}

public String getApplicationName() {
return applicationName;
}

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

public String getData() {
return version;
}

public void setData(String version) {
this.version = version;
}

@Override
public Map<String, String> getTags() {
Map<String, String> tags = new HashMap<>();
tags.put(TAG_IP, getLocalHost());
tags.put(TAG_HOSTNAME, getLocalHostName());
tags.put(TAG_APPLICATION_NAME, applicationName);

tags.put(TAG_APPLICATION_VERSION_KEY, version);
return tags;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
/**
* Metric class for method.
*/
public class MethodMetric {
public class MethodMetric implements Metric {
private String applicationName;
private String interfaceName;
private String methodName;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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.metrics.model;

import java.util.Map;

public interface Metric {
Map<String, String> getTags();
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ public enum MetricsCategory {
RT,
QPS,
REQUESTS,
APPLICATION
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.dubbo.metrics.model;

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"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private void onRTEvent(RTEvent event) {

private void onRequestEvent(RequestEvent event) {
MethodMetric metric = (MethodMetric) event.getSource();
RequestEvent.Type type = event.getType();
MetricsEvent.Type type = event.getType();
TimeWindowCounter counter = null;
switch (type) {
case TOTAL:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.apache.dubbo.metrics.collector.stat.MetricsStatHandler;
import org.apache.dubbo.metrics.event.EmptyEvent;
import org.apache.dubbo.metrics.event.MetricsEvent;
import org.apache.dubbo.metrics.event.RequestEvent;
import org.apache.dubbo.metrics.event.SimpleMetricsEventMulticaster;
import org.apache.dubbo.metrics.listener.MetricsListener;
import org.apache.dubbo.metrics.model.MetricsKey;
Expand All @@ -36,6 +35,7 @@
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Function;

import static org.apache.dubbo.metrics.model.MetricsCategory.APPLICATION;
import static org.apache.dubbo.metrics.model.MetricsCategory.REQUESTS;
import static org.apache.dubbo.metrics.model.MetricsCategory.RT;

Expand Down Expand Up @@ -63,85 +63,96 @@ public Boolean isCollectEnabled() {
}

public void increaseTotalRequests(String applicationName, Invocation invocation) {
increaseAndPublishEvent(applicationName, RequestEvent.Type.TOTAL, invocation);
increaseAndPublishEvent(applicationName, MetricsEvent.Type.TOTAL, invocation);
}

public void increaseSucceedRequests(String applicationName, Invocation invocation) {
increaseAndPublishEvent(applicationName, RequestEvent.Type.SUCCEED, invocation);
increaseAndPublishEvent(applicationName, MetricsEvent.Type.SUCCEED, invocation);
}

public void increaseUnknownFailedRequests(String applicationName, Invocation invocation) {
increaseAndPublishEvent(applicationName, RequestEvent.Type.UNKNOWN_FAILED, invocation);
increaseAndPublishEvent(applicationName, MetricsEvent.Type.UNKNOWN_FAILED, invocation);
}

public void businessFailedRequests(String applicationName, Invocation invocation) {
increaseAndPublishEvent(applicationName, RequestEvent.Type.BUSINESS_FAILED, invocation);
increaseAndPublishEvent(applicationName, MetricsEvent.Type.BUSINESS_FAILED, invocation);
}

public void timeoutRequests(String applicationName, Invocation invocation) {
increaseAndPublishEvent(applicationName,RequestEvent.Type.REQUEST_TIMEOUT, invocation);
increaseAndPublishEvent(applicationName,MetricsEvent.Type.REQUEST_TIMEOUT, invocation);
}

public void limitRequests(String applicationName, Invocation invocation) {
increaseAndPublishEvent(applicationName,RequestEvent.Type.REQUEST_LIMIT, invocation);
increaseAndPublishEvent(applicationName,MetricsEvent.Type.REQUEST_LIMIT, invocation);
}

public void increaseProcessingRequests(String applicationName, Invocation invocation) {
increaseAndPublishEvent(applicationName,RequestEvent.Type.PROCESSING, invocation);
increaseAndPublishEvent(applicationName,MetricsEvent.Type.PROCESSING, invocation);
}

public void decreaseProcessingRequests(String applicationName, Invocation invocation) {
decreaseAndPublishEvent(applicationName,RequestEvent.Type.PROCESSING, invocation);
decreaseAndPublishEvent(applicationName,MetricsEvent.Type.PROCESSING, invocation);
}

public void totalFailedRequests(String applicationName, Invocation invocation) {
increaseAndPublishEvent(applicationName,RequestEvent.Type.TOTAL_FAILED, invocation);
increaseAndPublishEvent(applicationName,MetricsEvent.Type.TOTAL_FAILED, invocation);
}

private void increaseAndPublishEvent(String applicationName, RequestEvent.Type total, Invocation invocation) {
private void increaseAndPublishEvent(String applicationName, MetricsEvent.Type total, Invocation invocation) {
this.eventMulticaster.publishEvent(doExecute(total, statHandler -> statHandler.increase(applicationName,invocation)));
}

private void decreaseAndPublishEvent(String applicationName, RequestEvent.Type total, Invocation invocation) {
this.eventMulticaster.publishEvent(doExecute(total, statHandler -> statHandler.decrease(applicationName,invocation)));
private void decreaseAndPublishEvent(String applicationName, MetricsEvent.Type type, Invocation invocation) {
this.eventMulticaster.publishEvent(doExecute(type, statHandler -> statHandler.decrease(applicationName,invocation)));
}

public void addRT(String applicationName,Invocation invocation, Long responseTime) {
this.eventMulticaster.publishEvent(stats.addRtAndRetrieveEvent(applicationName,invocation, responseTime));
}

public void addApplicationInfo(String applicationName, String version) {
doExecute(MetricsEvent.Type.APPLICATION_INFO, statHandler -> statHandler.addApplication(applicationName,version));
}
@Override
public List<MetricSample> collect() {
List<MetricSample> list = new ArrayList<>();
collectApplication(list);
collectRequests(list);
collectRT(list);

return list;
}

private void collectApplication(List<MetricSample> list) {
doCollect(MetricsEvent.Type.APPLICATION_INFO, MetricsStatHandler::get).filter(e -> !e.isEmpty())
.ifPresent(map -> map.forEach((k, v) -> list.add(new GaugeMetricSample(MetricsKey.APPLICATION_METRIC_INFO, k.getTags(),
APPLICATION, v::get))));


}

private void collectRequests(List<MetricSample> list) {
doCollect(RequestEvent.Type.TOTAL, MetricsStatHandler::get).filter(e -> !e.isEmpty())
doCollect(MetricsEvent.Type.TOTAL, MetricsStatHandler::get).filter(e -> !e.isEmpty())
.ifPresent(map -> map.forEach((k, v) -> list.add(new GaugeMetricSample(MetricsKey.PROVIDER_METRIC_REQUESTS, k.getTags(), REQUESTS, v::get))));

doCollect(RequestEvent.Type.SUCCEED, MetricsStatHandler::get).filter(e -> !e.isEmpty())
doCollect(MetricsEvent.Type.SUCCEED, MetricsStatHandler::get).filter(e -> !e.isEmpty())
.ifPresent(map -> map.forEach((k, v) -> list.add(new GaugeMetricSample(MetricsKey.PROVIDER_METRIC_REQUESTS_SUCCEED, k.getTags(), REQUESTS, v::get))));

doCollect(RequestEvent.Type.UNKNOWN_FAILED, MetricsStatHandler::get).filter(e -> !e.isEmpty())
doCollect(MetricsEvent.Type.UNKNOWN_FAILED, MetricsStatHandler::get).filter(e -> !e.isEmpty())
.ifPresent(map -> map.forEach((k, v) -> list.add(new GaugeMetricSample(MetricsKey.PROVIDER_METRIC_REQUESTS_FAILED, k.getTags(), REQUESTS, v::get))));

doCollect(RequestEvent.Type.PROCESSING, MetricsStatHandler::get).filter(e -> !e.isEmpty())
doCollect(MetricsEvent.Type.PROCESSING, MetricsStatHandler::get).filter(e -> !e.isEmpty())
.ifPresent(map -> map.forEach((k, v) -> list.add(new GaugeMetricSample(MetricsKey.PROVIDER_METRIC_REQUESTS_PROCESSING, k.getTags(), REQUESTS, v::get))));

doCollect(RequestEvent.Type.BUSINESS_FAILED, MetricsStatHandler::get).filter(e -> !e.isEmpty())
doCollect(MetricsEvent.Type.BUSINESS_FAILED, MetricsStatHandler::get).filter(e -> !e.isEmpty())
.ifPresent(map -> map.forEach((k, v) -> list.add(new GaugeMetricSample(MetricsKey.PROVIDER_METRIC_REQUEST_BUSINESS_FAILED, k.getTags(), REQUESTS, v::get))));

doCollect(RequestEvent.Type.REQUEST_TIMEOUT, MetricsStatHandler::get).filter(e -> !e.isEmpty())
doCollect(MetricsEvent.Type.REQUEST_TIMEOUT, MetricsStatHandler::get).filter(e -> !e.isEmpty())
.ifPresent(map -> map.forEach((k, v) -> list.add(new GaugeMetricSample(MetricsKey.PROVIDER_METRIC_REQUESTS_TIMEOUT, k.getTags(), REQUESTS, v::get))));

doCollect(RequestEvent.Type.REQUEST_LIMIT, MetricsStatHandler::get).filter(e -> !e.isEmpty())
doCollect(MetricsEvent.Type.REQUEST_LIMIT, MetricsStatHandler::get).filter(e -> !e.isEmpty())
.ifPresent(map -> map.forEach((k, v) -> list.add(new GaugeMetricSample(MetricsKey.PROVIDER_METRIC_REQUESTS_LIMIT, k.getTags(), REQUESTS, v::get))));

doCollect(RequestEvent.Type.TOTAL_FAILED, MetricsStatHandler::get).filter(e -> !e.isEmpty())
doCollect(MetricsEvent.Type.TOTAL_FAILED, MetricsStatHandler::get).filter(e -> !e.isEmpty())
.ifPresent(map -> map.forEach((k, v) -> list.add(new GaugeMetricSample(MetricsKey.PROVIDER_METRIC_REQUESTS_TOTAL_FAILED, k.getTags(), REQUESTS, v::get))));

}
Expand All @@ -162,19 +173,19 @@ private void collectRT(List<MetricSample> list) {
}

private <
T> Optional<T> doCollect(RequestEvent.Type requestType, Function<MetricsStatHandler, T> statExecutor) {
T> Optional<T> doCollect(MetricsEvent.Type metricsEventType, Function<MetricsStatHandler, T> statExecutor) {
if (isCollectEnabled()) {
MetricsStatHandler handler = stats.getHandler(requestType);
MetricsStatHandler handler = stats.getHandler(metricsEventType);
T result = statExecutor.apply(handler);
return Optional.ofNullable(result);
}
return Optional.empty();
}

private MetricsEvent doExecute(RequestEvent.Type
requestType, Function<MetricsStatHandler, MetricsEvent> statExecutor) {
private MetricsEvent doExecute(MetricsEvent.Type metricsEventType,
Function<MetricsStatHandler, MetricsEvent> statExecutor) {
if (isCollectEnabled()) {
MetricsStatHandler handler = stats.getHandler(requestType);
MetricsStatHandler handler = stats.getHandler(metricsEventType);
return statExecutor.apply(handler);
}
return EmptyEvent.instance();
Expand Down
Loading