Skip to content

Commit

Permalink
perf(proxy): improve metrics performance (#526)
Browse files Browse the repository at this point in the history
Signed-off-by: SSpirits <admin@lv5.moe>
  • Loading branch information
ShadowySpirits authored Nov 1, 2023
1 parent 871a543 commit 1a0fa73
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@

package com.automq.rocketmq.proxy.grpc;

import apache.rocketmq.v2.AckMessageResponse;
import apache.rocketmq.v2.ChangeInvisibleDurationResponse;
import apache.rocketmq.v2.EndTransactionResponse;
import apache.rocketmq.v2.HeartbeatResponse;
import apache.rocketmq.v2.QueryRouteResponse;
import apache.rocketmq.v2.ReceiveMessageResponse;
import apache.rocketmq.v2.SendMessageResponse;
import apache.rocketmq.v2.Status;
import com.automq.rocketmq.proxy.metrics.ProxyMetricsManager;
import com.automq.rocketmq.proxy.model.ProxyContextExt;
Expand All @@ -38,6 +45,22 @@ protected ProxyContext createContext() {
}

private <T> String getResponseStatus(T response) {
if (response instanceof SendMessageResponse detailResponse) {
return detailResponse.getStatus().getCode().name().toLowerCase();
} else if (response instanceof ReceiveMessageResponse detailResponse) {
return detailResponse.getStatus().getCode().name().toLowerCase();
} else if (response instanceof AckMessageResponse detailResponse) {
return detailResponse.getStatus().getCode().name().toLowerCase();
} else if (response instanceof ChangeInvisibleDurationResponse detailResponse) {
return detailResponse.getStatus().getCode().name().toLowerCase();
} else if (response instanceof EndTransactionResponse detailResponse) {
return detailResponse.getStatus().getCode().name().toLowerCase();
} else if (response instanceof QueryRouteResponse detailResponse) {
return detailResponse.getStatus().getCode().name().toLowerCase();
} else if (response instanceof HeartbeatResponse detailResponse) {
return detailResponse.getStatus().getCode().name().toLowerCase();
}

try {
Method getStatus = response.getClass().getDeclaredMethod("getStatus");
Status status = (Status) getStatus.invoke(response);
Expand Down

0 comments on commit 1a0fa73

Please sign in to comment.