From fed4dbd54fe13da2ba638fdf7b8ed53814558cc5 Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Mon, 13 Mar 2023 13:31:40 +0800 Subject: [PATCH 1/6] zk add client options --- internal/startrpc/start.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/startrpc/start.go b/internal/startrpc/start.go index d47734b9c..f40944735 100644 --- a/internal/startrpc/start.go +++ b/internal/startrpc/start.go @@ -31,7 +31,7 @@ func Start(rpcPort int, rpcRegisterName string, prometheusPort int, rpcFn func(c return utils.Wrap1(err) } defer zkClient.Close() - zkClient.AddOption(grpc.WithTransportCredentials(insecure.NewCredentials())) + zkClient.AddOption(grpc.WithTransportCredentials(insecure.NewCredentials()), mw.GrpcClient()) registerIP, err := network.GetRpcRegisterIP(config.Config.RpcRegisterIP) if err != nil { return err From 8a443054405616ed2919fcdf700343b7501eabc2 Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Mon, 13 Mar 2023 13:52:25 +0800 Subject: [PATCH 2/6] zk add client options --- internal/startrpc/start.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/startrpc/start.go b/internal/startrpc/start.go index f40944735..e1127a153 100644 --- a/internal/startrpc/start.go +++ b/internal/startrpc/start.go @@ -31,7 +31,7 @@ func Start(rpcPort int, rpcRegisterName string, prometheusPort int, rpcFn func(c return utils.Wrap1(err) } defer zkClient.Close() - zkClient.AddOption(grpc.WithTransportCredentials(insecure.NewCredentials()), mw.GrpcClient()) + zkClient.AddOption(mw.GrpcClient(), grpc.WithTransportCredentials(insecure.NewCredentials())) registerIP, err := network.GetRpcRegisterIP(config.Config.RpcRegisterIP) if err != nil { return err From cf29bd62277f58372c7e40a390b2a3d3c8aec774 Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Mon, 13 Mar 2023 13:59:39 +0800 Subject: [PATCH 3/6] zk add client options --- internal/rpc/auth/auth.go | 4 ++++ pkg/common/mw/rpc.go | 1 + 2 files changed, 5 insertions(+) diff --git a/internal/rpc/auth/auth.go b/internal/rpc/auth/auth.go index ae31af027..33d302802 100644 --- a/internal/rpc/auth/auth.go +++ b/internal/rpc/auth/auth.go @@ -39,6 +39,10 @@ func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) e func (s *authServer) UserToken(ctx context.Context, req *pbAuth.UserTokenReq) (*pbAuth.UserTokenResp, error) { log.Info("", "rpc come UserToken") + operationID, ok := ctx.Value(constant.OperationID).(string) + if !ok { + log.Error("2222", "ctx missing operationID", operationID) + } resp := pbAuth.UserTokenResp{} if _, err := s.userCheck.GetUserInfo(ctx, req.UserID); err != nil { log.Info("", "UserToken err:", err.Error()) diff --git a/pkg/common/mw/rpc.go b/pkg/common/mw/rpc.go index 1ee9c8aa3..fb5a2e295 100644 --- a/pkg/common/mw/rpc.go +++ b/pkg/common/mw/rpc.go @@ -58,6 +58,7 @@ func rpcClientInterceptor(ctx context.Context, method string, req, reply interfa } operationID, ok := ctx.Value(constant.OperationID).(string) if !ok { + log.Error("1111", "ctx missing operationID") return errs.ErrArgs.Wrap("ctx missing operationID") } md := metadata.Pairs(constant.OperationID, operationID) From 8867c5e14a798e5e262f3d4c8e9e4d435a30d715 Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Mon, 13 Mar 2023 14:10:51 +0800 Subject: [PATCH 4/6] rpc add data --- pkg/common/mw/rpc.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/common/mw/rpc.go b/pkg/common/mw/rpc.go index fb5a2e295..7e5c8e647 100644 --- a/pkg/common/mw/rpc.go +++ b/pkg/common/mw/rpc.go @@ -41,6 +41,8 @@ func rpcServerInterceptor(ctx context.Context, req interface{}, info *grpc.Unary opUserID = opts[0] } ctx = tracelog.SetFuncInfos(ctx, funcName, operationID) + ctx = context.WithValue(ctx, OperationID, operationID) + ctx = context.WithValue(ctx, OpUserID, opUserID) tracelog.SetCtxInfo(ctx, funcName, err, "opUserID", opUserID, "rpcReq", rpcString(req)) resp, err = handler(ctx, req) if err != nil { From 59b99edf7995644f2ca2eab86c1c71682bf6322d Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Mon, 13 Mar 2023 14:18:33 +0800 Subject: [PATCH 5/6] rpc add data --- pkg/common/db/relation/user_model.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/common/db/relation/user_model.go b/pkg/common/db/relation/user_model.go index 697024e39..05bc519bc 100644 --- a/pkg/common/db/relation/user_model.go +++ b/pkg/common/db/relation/user_model.go @@ -45,7 +45,7 @@ func (u *UserGorm) Find(ctx context.Context, userIDs []string) (users []*relatio defer func() { tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userIDs", userIDs, "users", users) }() - err = utils.Wrap(u.DB.Where("user_id in (?)", userIDs).Find(&users).Error, "") + err = utils.Wrap(u.DB.Where("user_id in ?", userIDs).Find(&users).Error, "") return users, err } From 9a68a9645a5755592bbac2c55ecf7de5e6cc8eed Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Mon, 13 Mar 2023 14:21:41 +0800 Subject: [PATCH 6/6] rpc add data --- pkg/common/db/relation/user_model.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/common/db/relation/user_model.go b/pkg/common/db/relation/user_model.go index 05bc519bc..026417bd2 100644 --- a/pkg/common/db/relation/user_model.go +++ b/pkg/common/db/relation/user_model.go @@ -45,7 +45,7 @@ func (u *UserGorm) Find(ctx context.Context, userIDs []string) (users []*relatio defer func() { tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userIDs", userIDs, "users", users) }() - err = utils.Wrap(u.DB.Where("user_id in ?", userIDs).Find(&users).Error, "") + err = utils.Wrap(u.DB.Debug().Where("user_id in ?", userIDs).Find(&users).Error, "") return users, err }