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

add metrics enable switch #12389

Merged
merged 22 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
3e8239b
add metrics enable switch
finefuture May 23, 2023
45b2339
Merge branch '3.2' into 3.2-support-metrics-enable
finefuture May 23, 2023
db8b9ea
default false
finefuture May 23, 2023
6739243
default false
finefuture May 23, 2023
69fe150
set default true and fix unit test
finefuture May 23, 2023
d2e1bcb
Merge branch '3.2' into 3.2-support-metrics-enable
finefuture May 23, 2023
6f5fc4c
xsd set default true
finefuture May 24, 2023
dd4c883
Merge branch '3.2' into 3.2-support-metrics-enable
finefuture May 24, 2023
d3df98c
Merge branch '3.2' into 3.2-support-metrics-enable
finefuture May 24, 2023
2b7d9c7
Merge branch '3.2' into 3.2-support-metrics-enable
finefuture May 24, 2023
0e6e0c7
Merge branch '3.2' into 3.2-support-metrics-enable
songxiaosheng May 25, 2023
ca8eede
rename enabled to enableRpc
finefuture May 26, 2023
70c1622
Merge branch '3.2' into 3.2-support-metrics-enable
finefuture May 26, 2023
580642a
Merge branch '3.2' into 3.2-support-metrics-enable
finefuture May 29, 2023
5d78495
make enableRpc default value to true
finefuture May 30, 2023
1e270e9
Merge branch '3.2' into 3.2-support-metrics-enable
finefuture May 30, 2023
9cc68e5
fix camel name
finefuture May 30, 2023
dd21178
Merge branch '3.2' into 3.2-support-metrics-enable
finefuture May 30, 2023
b48b366
remove default value
finefuture Jun 5, 2023
afadb20
Merge branch '3.2' into 3.2-support-metrics-enable
finefuture Jun 5, 2023
8b82f49
Merge branch '3.2' into 3.2-support-metrics-enable
songxiaosheng Jun 7, 2023
a7fda5a
Merge branch '3.2' into 3.2-support-metrics-enable
songxiaosheng Jun 7, 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 @@ -92,6 +92,7 @@ public class MetricsConfig extends AbstractConfig {
*/
private Boolean useGlobalRegistry;

private Boolean enableRpc;

public MetricsConfig() {
}
Expand Down Expand Up @@ -214,4 +215,12 @@ public Boolean getUseGlobalRegistry() {
public void setUseGlobalRegistry(Boolean useGlobalRegistry) {
this.useGlobalRegistry = useGlobalRegistry;
}

public Boolean getEnableRpc() {
return enableRpc;
}

public void setEnableRpc(Boolean enableRpc) {
this.enableRpc = enableRpc;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,12 @@
<xsd:documentation><![CDATA[ Deprecated. No longer use. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>

songxiaosheng marked this conversation as resolved.
Show resolved Hide resolved
<xsd:attribute name="enable-rpc" type="xsd:boolean" default="true">
<xsd:annotation>
<xsd:documentation><![CDATA[ Enable record rpc metrics. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>

<xsd:complexType name="tracingType">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.config.MetricsConfig;
import org.apache.dubbo.metrics.event.MetricsEventBus;
import org.apache.dubbo.metrics.event.RequestEvent;
import org.apache.dubbo.rpc.BaseFilter;
Expand All @@ -40,20 +41,24 @@
public class MetricsFilter implements Filter, BaseFilter.Listener, ScopeModelAware {

private ApplicationModel applicationModel;
private final static ErrorTypeAwareLogger LOGGER = LoggerFactory.getErrorTypeAwareLogger(MetricsFilter.class);
private static final ErrorTypeAwareLogger LOGGER = LoggerFactory.getErrorTypeAwareLogger(MetricsFilter.class);
private boolean rpcMetricsEnable;

@Override
public void setApplicationModel(ApplicationModel applicationModel) {
this.applicationModel = applicationModel;
this.rpcMetricsEnable = applicationModel.getApplicationConfigManager().getMetrics().map(MetricsConfig::getEnableRpc).orElse(true);
}

@Override
public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {
try {
RequestEvent requestEvent = RequestEvent.toRequestEvent(applicationModel, invocation);
MetricsEventBus.before(requestEvent, () -> invocation.put(METRIC_FILTER_EVENT, requestEvent));
} catch (Throwable t) {
LOGGER.warn(INTERNAL_ERROR, "", "", "Error occurred when invoke.", t);
if (rpcMetricsEnable) {
try {
RequestEvent requestEvent = RequestEvent.toRequestEvent(applicationModel, invocation);
MetricsEventBus.before(requestEvent, () -> invocation.put(METRIC_FILTER_EVENT, requestEvent));
} catch (Throwable t) {
LOGGER.warn(INTERNAL_ERROR, "", "", "Error occurred when invoke.", t);
}
}
return invoker.invoke(invocation);
}
Expand Down Expand Up @@ -84,6 +89,4 @@ public void onError(Throwable t, Invoker<?> invoker, Invocation invocation) {
}
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ public void setup() {
config.setName("MockMetrics");
applicationModel = ApplicationModel.defaultModel();
applicationModel.getApplicationConfigManager().setApplication(config);

invocation = new RpcInvocation();
filter = new MetricsFilter();

Expand Down