Skip to content

Commit

Permalink
grpc add log (#757)
Browse files Browse the repository at this point in the history
  • Loading branch information
binbin0325 authored Jun 2, 2024
1 parent 006f55d commit 083c02f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
3 changes: 2 additions & 1 deletion common/remote/rpc/grpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ func (c *GrpcClient) bindBiRequestStream(streamClient nacos_grpc_service.BiReque
for {
select {
case <-streamClient.Context().Done():
logger.Warnf("connectionId %s stream client close", grpcConn.getConnectionId())
return
default:
payload, err := streamClient.Recv()
Expand All @@ -276,7 +277,7 @@ func (c *GrpcClient) bindBiRequestStream(streamClient nacos_grpc_service.BiReque
return
}
} else {
logger.Infof("connectionId %s received error event, isRunning:%v, isAbandon=%v, error=%v", grpcConn.getConnectionId(), running, abandon, err)
logger.Errorf("connectionId %s received error event, isRunning:%v, isAbandon=%v, error=%v", grpcConn.getConnectionId(), running, abandon, err)
return
}
} else {
Expand Down
5 changes: 4 additions & 1 deletion common/remote/rpc/grpc_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package rpc

import (
"context"
"github.com/nacos-group/nacos-sdk-go/v2/common/logger"
"time"

"github.com/golang/protobuf/ptypes/any"
Expand Down Expand Up @@ -55,15 +56,17 @@ func (g *GrpcConnection) request(request rpc_request.IRequest, timeoutMills int6
defer cancel()
responsePayload, err := g.client.Request(ctx, p)
if err != nil {
logger.Debugf("%s grpc request nacos server failed, request=%+v, err=%v ", g.getConnectionId(), p, err)
return nil, err
}

responseFunc, ok := rpc_response.ClientResponseMapping[responsePayload.Metadata.GetType()]

if !ok {
return nil, errors.Errorf("request:%s,unsupported response type:%s", request.GetRequestType(),
responsePayload.Metadata.GetType())
}

logger.Debugf("%s grpc request nacos server success, request=%+v, response=%s", g.getConnectionId(), p, string(responsePayload.GetBody().Value))
return rpc_response.InnerResponseJsonUnmarshal(responsePayload.GetBody().Value, responseFunc)
}

Expand Down
4 changes: 3 additions & 1 deletion common/remote/rpc/server_request_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,12 @@ func (*NamingPushRequestHandler) Name() string {
return "NamingPushRequestHandler"
}

func (c *NamingPushRequestHandler) RequestReply(request rpc_request.IRequest, _ *RpcClient) rpc_response.IResponse {
func (c *NamingPushRequestHandler) RequestReply(request rpc_request.IRequest, client *RpcClient) rpc_response.IResponse {
notifySubscriberRequest, ok := request.(*rpc_request.NotifySubscriberRequest)
if ok {
c.ServiceInfoHolder.ProcessService(&notifySubscriberRequest.ServiceInfo)
logger.Debugf("%s naming push response success ackId->%s", client.currentConnection.getConnectionId(),
request.GetRequestId())
return &rpc_response.NotifySubscriberResponse{
Response: &rpc_response.Response{ResultCode: constant.RESPONSE_CODE_SUCCESS, Success: true},
}
Expand Down

0 comments on commit 083c02f

Please sign in to comment.