Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions common/remote/rpc/grpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"crypto/x509"
"encoding/json"
"fmt"
"github.com/nacos-group/nacos-sdk-go/v2/common/monitor"
"google.golang.org/grpc/credentials"
"io"
"log"
Expand Down Expand Up @@ -318,6 +319,11 @@ func serverCheck(client nacos_grpc_service.RequestClient) (rpc_response.IRespons
func (c *GrpcClient) handleServerRequest(p *nacos_grpc_service.Payload, grpcConn *GrpcConnection) {
client := c.GetRpcClient()
payLoadType := p.GetMetadata().GetType()
start := time.Now()
status := "NA"
defer func() {
monitor.GetNamingRequestMonitor(constant.GRPC, payLoadType, status).Observe(float64(time.Now().Sub(start).Nanoseconds()))
}()
Comment on lines +322 to +326
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

添加监控指标以跟踪服务器请求的处理时间与状态。

🟢 Minor | 🧹 Code Smells

📋 问题详情

在处理服务器请求时,新增了对处理时间和响应状态的监控。通过在函数开始记录时间并在 defer 中上报监控数据,可以有效追踪每个请求类型的性能表现和成功率。这种做法有助于及时发现潜在的性能瓶颈或错误模式。

💡 解决方案

确保监控逻辑正确地捕获并报告请求处理的时间和状态。当前实现中使用了 defer 来保证监控代码总是被执行,这是合理的做法。

- // No changes needed for this section as it correctly implements monitoring

您的反馈对我们很重要!(建议右键在新标签页中打开以下链接)

有用意见👍无用意见👎错误意见❌


handlerMapping, ok := client.serverRequestHandlerMapping.Load(payLoadType)
if !ok {
Expand All @@ -343,6 +349,7 @@ func (c *GrpcClient) handleServerRequest(p *nacos_grpc_service.Payload, grpcConn
serverRequest.GetRequestId())
return
}
status = rpc_response.GetGrpcResponseStatusCode(response)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

更新服务器请求处理的状态码用于监控。

🟢 Minor | 🧹 Code Smells

📋 问题详情

处理完服务器请求后,将实际的响应状态码赋值给变量 status 以便于后续的监控上报。这一步是必要的,因为它确保了监控系统能够获取到准确的响应结果信息。

💡 解决方案

确认 rpc_response.GetGrpcResponseStatusCode 函数返回的是预期格式的状态码,并且该状态码能被监控系统正确解析。

- // No changes needed for this line as it properly assigns the status code

您的反馈对我们很重要!(建议右键在新标签页中打开以下链接)

有用意见👍无用意见👎错误意见❌

response.SetRequestId(serverRequest.GetRequestId())
err = grpcConn.biStreamSend(convertResponse(response))
if err != nil && err != io.EOF {
Expand Down