-
-
Notifications
You must be signed in to change notification settings - Fork 125
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
feat: 使用cola重构grpc的例子,对cola实践的rpc例子进行补充 #2913
Conversation
|
GitGuardian id | GitGuardian status | Secret | Commit | Filename | |
---|---|---|---|---|---|
9282265 | Triggered | Username Password | 928729e | laokou-sample/laokou-sample-grpc/laokou-sample-grpc-server/src/main/java/org/laokou/app/service/UserServiceImpl.java | View secret |
🛠 Guidelines to remediate hardcoded secrets
- Understand the implications of revoking this secret by investigating where it is used in your code.
- Replace and store your secret safely. Learn here the best practices.
- Revoke and rotate this secret.
- If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.
To avoid such incidents in the future consider
- following these best practices for managing and storing secrets including API keys and other credentials
- install secret detection on pre-commit to catch secret before it leaves your machine and ease remediation.
🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.
Caution Review failedThe pull request is closed. WalkthroughThis pull request introduces several modifications across multiple files in the Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
审核指南由 Sourcery 提供此 PR 使用 COLA 架构模式重构了 gRPC 示例。主要更改包括重构客户端代码以遵循 COLA 的分层架构、改进错误处理以及增强客户端和服务器拦截器中的跟踪功能。 gRPC 用户检索过程的序列图sequenceDiagram
actor User
participant UserController
participant UserServiceI
participant UserGetQryExe
participant UserMapper
participant UserServiceGrpc
User->>UserController: GET /user/{id}
UserController->>UserServiceI: getById(UserGetQry)
UserServiceI->>UserGetQryExe: execute(UserGetQry)
UserGetQryExe->>UserMapper: getById(Long)
UserMapper->>UserServiceGrpc: getUserById(UserGetQry)
UserServiceGrpc-->>UserMapper: Result
UserMapper-->>UserGetQryExe: UserDO
UserGetQryExe-->>UserServiceI: Result<UserCO>
UserServiceI-->>UserController: Result<UserCO>
UserController-->>User: JSON Response
更新的 gRPC 服务器拦截器的类图classDiagram
class GrpcServerInterceptor {
+<ReqT, RespT> interceptCall(ServerCall<ReqT, RespT>, Metadata, ServerCallHandler<ReqT, RespT>)
}
class WrapperTraceListener {
+WrapperTraceListener(ServerCall<R, S>, ServerCallHandler<R, S>, Metadata, TraceLogV)
+onMessage(R)
+onHalfClose()
+onComplete()
}
class Wrapper {
+Wrapper(ServerCall<R, S>)
}
GrpcServerInterceptor --> WrapperTraceListener
WrapperTraceListener --> Wrapper
note for WrapperTraceListener "替换 WrapperTrace 并添加 executeWithTrace 方法"
note for Wrapper "替换 WrapperListener"
新用户服务实现的类图classDiagram
class UserServiceImpl {
+getById(UserGetQry): Result<UserCO>
}
class UserGetQryExe {
+execute(UserGetQry): Result<UserCO>
}
class UserMapper {
+getById(Long): UserDO
}
class UserConvertor {
+toDataObject(User): UserDO
+toClientObject(UserDO): UserCO
}
UserServiceImpl --> UserGetQryExe
UserGetQryExe --> UserMapper
UserMapper --> UserConvertor
note for UserServiceImpl "实现 UserServiceI 接口"
文件级更改
提示和命令与 Sourcery 互动
自定义您的体验访问您的仪表板以:
获取帮助Original review guide in EnglishReviewer's Guide by SourceryThis PR refactors the gRPC example using the COLA architecture pattern. The main changes include restructuring the client-side code to follow COLA's layered architecture, improving error handling, and enhancing the tracing functionality in both client and server interceptors. Sequence diagram for gRPC user retrieval processsequenceDiagram
actor User
participant UserController
participant UserServiceI
participant UserGetQryExe
participant UserMapper
participant UserServiceGrpc
User->>UserController: GET /user/{id}
UserController->>UserServiceI: getById(UserGetQry)
UserServiceI->>UserGetQryExe: execute(UserGetQry)
UserGetQryExe->>UserMapper: getById(Long)
UserMapper->>UserServiceGrpc: getUserById(UserGetQry)
UserServiceGrpc-->>UserMapper: Result
UserMapper-->>UserGetQryExe: UserDO
UserGetQryExe-->>UserServiceI: Result<UserCO>
UserServiceI-->>UserController: Result<UserCO>
UserController-->>User: JSON Response
Class diagram for updated gRPC server interceptorclassDiagram
class GrpcServerInterceptor {
+<ReqT, RespT> interceptCall(ServerCall<ReqT, RespT>, Metadata, ServerCallHandler<ReqT, RespT>)
}
class WrapperTraceListener {
+WrapperTraceListener(ServerCall<R, S>, ServerCallHandler<R, S>, Metadata, TraceLogV)
+onMessage(R)
+onHalfClose()
+onComplete()
}
class Wrapper {
+Wrapper(ServerCall<R, S>)
}
GrpcServerInterceptor --> WrapperTraceListener
WrapperTraceListener --> Wrapper
note for WrapperTraceListener "Replaces WrapperTrace and adds executeWithTrace method"
note for Wrapper "Replaces WrapperListener"
Class diagram for new User service implementationclassDiagram
class UserServiceImpl {
+getById(UserGetQry): Result<UserCO>
}
class UserGetQryExe {
+execute(UserGetQry): Result<UserCO>
}
class UserMapper {
+getById(Long): UserDO
}
class UserConvertor {
+toDataObject(User): UserDO
+toClientObject(UserDO): UserCO
}
UserServiceImpl --> UserGetQryExe
UserGetQryExe --> UserMapper
UserMapper --> UserConvertor
note for UserServiceImpl "Implements UserServiceI interface"
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
嗨 @KouShenhai - 我已经审查了你的更改 - 这里有一些反馈:
总体评论:
- 考虑在整个代码库中标准化错误代码格式。目前混合使用了类似 'B_User_NotExist' 和 'S_DS_OperationError' 的格式。建议为所有错误代码选择一种一致的格式。
这是我在审查期间查看的内容
- 🟡 一般问题:发现2个问题
- 🟢 安全性:一切看起来都很好
- 🟢 测试:一切看起来都很好
- 🟢 复杂性:一切看起来都很好
- 🟢 文档:一切看起来都很好
帮助我变得更有用!请点击每条评论上的 👍 或 👎,我将使用反馈来改进你的评论。
Original comment in English
Hey @KouShenhai - I've reviewed your changes - here's some feedback:
Overall Comments:
- Consider standardizing error code formats across the codebase. Currently mixing formats like 'B_User_NotExist' and 'S_DS_OperationError'. Suggest picking one consistent format for all error codes.
Here's what I looked at during the review
- 🟡 General issues: 2 issues found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
@@ -31,71 +31,70 @@ | |||
@Slf4j | |||
public class GrpcServerInterceptor implements ServerInterceptor { | |||
|
|||
private static void executeWithTrace(TraceLogV traceLog, Runnable action) { | |||
try { | |||
MDCUtil.put(traceLog.traceId(), traceLog.traceId()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): executeWithTrace 方法在 MDCUtil.put() 的两个参数中都使用了 traceId,应该分别使用 traceId 和 spanId
Original comment in English
issue (bug_risk): The executeWithTrace method is using traceId for both parameters of MDCUtil.put(), which should use traceId and spanId separately
} | ||
else { | ||
throw new SystemException("S_Request_RPCCallFailed", | ||
String.format("RPC调用失败,%s", result.getMsg().split("\\\\")[0])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): 使用字符串拆分进行错误消息解析是脆弱的,如果消息格式更改可能会中断
考虑实现一种更健壮的错误处理机制,不依赖于字符串拆分
Original comment in English
issue (bug_risk): Error message parsing using string splitting is fragile and could break if message format changes
Consider implementing a more robust error handling mechanism that doesn't rely on string splitting
Quality Gate passedIssues Measures |
Sourcery总结
使用Cola框架重构gRPC示例,通过引入新的类来处理和转换用户数据。增强GrpcServerInterceptor以更好地管理跟踪,并更新用户服务以处理不存在的用户。调整log4j2模块的构建依赖。
新功能:
增强:
构建:
Original summary in English
Summary by Sourcery
Refactor the gRPC example using the Cola framework by introducing new classes for user data handling and conversion. Enhance the GrpcServerInterceptor for better trace management and update the user service to handle non-existent users. Adjust build dependencies for the log4j2 module.
New Features:
Enhancements:
Build:
Summary by CodeRabbit
New Features
Bug Fixes
Documentation
Chores