Skip to content

Commit

Permalink
feat:add caller/callee port in RpcContext
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklaus-dev committed Sep 20, 2024
1 parent df0f77f commit 779c0c1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public CompletionStage<Response> filter(Invoker<?> invoker, Request request) {
ConsumerInvoker consumerInvoker = (ConsumerInvoker) invoker;
// combine with DefClusterInvocationHandler#genRequest to complete the information of the request.
prepareRequestInfoBeforeInvoke(request, consumerInvoker);
contextWithRemoteCalleeIp(context, request);
contextWithRemoteCalleeAddr(context, request);
startLog(context, request);
CompletableFuture<Response> future = invoker.invoke(request).toCompletableFuture();
if (logger.isDebugEnabled()) {
Expand All @@ -66,15 +66,21 @@ public CompletionStage<Response> filter(Invoker<?> invoker, Request request) {
}

/**
* Set the request remote callee IP to RpcContext, with the key as CTX_CALLEE_REMOTE_IP.
* Set the request remote callee addr to RpcContext.
* Caller IP: CTX_CALLEE_REMOTE_IP
* Caller PORT: CTX_CALLEE_REMOTE_PORT
*
* @param context RpcContext
* @param request Request
*/
private void contextWithRemoteCalleeIp(RpcContext context, Request request) {
private void contextWithRemoteCalleeAddr(RpcContext context, Request request) {
Optional.ofNullable(request.getMeta().getRemoteAddress()).ifPresent(remoteAddr
-> RpcContextUtils.putValueMapValue(context, RpcContextValueKeys.CTX_CALLEE_REMOTE_IP,
remoteAddr.getAddress().getHostAddress()));
-> {
RpcContextUtils.putValueMapValue(context, RpcContextValueKeys.CTX_CALLEE_REMOTE_IP,
remoteAddr.getAddress().getHostAddress());
RpcContextUtils.putValueMapValue(context, RpcContextValueKeys.CTX_CALLEE_REMOTE_PORT,
remoteAddr.getPort());
});
}

private void prepareRequestInfoBeforeInvoke(Request request,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public int getOrder() {
public CompletionStage<Response> filter(Invoker<?> invoker, Request request) {
RpcServerContext serverContext = (RpcServerContext) (request.getContext());
prepareRequestInfoBeforeInvoke(request, (ProviderInvoker) invoker);
contextWithRemoteCallerIp(serverContext, request);
contextWithRemoteCallerAddr(serverContext, request);
startLog(serverContext, request);
CompletableFuture<Response> future = invoker.invoke(request).toCompletableFuture();
if (logger.isDebugEnabled()) {
Expand All @@ -62,15 +62,21 @@ public CompletionStage<Response> filter(Invoker<?> invoker, Request request) {
}

/**
* Set the request remote caller IP to RpcServerContext, with the key as CTX_CALLER_REMOTE_IP.
* Set the request remote caller addr to RpcServerContext.
* Caller IP: CTX_CALLER_REMOTE_IP
* Caller PORT: CTX_CALLER_REMOTE_PORT
*
* @param serverContext RpcServerContext
* @param request Request
*/
private void contextWithRemoteCallerIp(RpcServerContext serverContext, Request request) {
private void contextWithRemoteCallerAddr(RpcServerContext serverContext, Request request) {
Optional.ofNullable(request.getMeta().getRemoteAddress()).ifPresent(remoteAddr
-> RpcContextUtils.putValueMapValue(serverContext, RpcContextValueKeys.CTX_CALLER_REMOTE_IP,
remoteAddr.getAddress().getHostAddress()));
-> {
RpcContextUtils.putValueMapValue(serverContext, RpcContextValueKeys.CTX_CALLER_REMOTE_IP,
remoteAddr.getAddress().getHostAddress());
RpcContextUtils.putValueMapValue(serverContext, RpcContextValueKeys.CTX_CALLER_REMOTE_PORT,
remoteAddr.getPort());
});

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,18 @@ public class RpcContextValueKeys {
* Caller Remote IP.
*/
public static final String CTX_CALLER_REMOTE_IP = "ctx_caller_remote_ip";
/**
* Caller Remote PORT.
*/
public static final String CTX_CALLER_REMOTE_PORT = "ctx_caller_remote_port";
/**
* Callee Remote IP.
*/
public static final String CTX_CALLEE_REMOTE_IP = "ctx_callee_remote_ip";
/**
* Callee Remote PORT.
*/
public static final String CTX_CALLEE_REMOTE_PORT = "ctx_callee_remote_port";
/**
* Full link timeout key.
*/
Expand Down

0 comments on commit 779c0c1

Please sign in to comment.