-
Notifications
You must be signed in to change notification settings - Fork 382
#858: add metrics for server request. #860
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
Open
brotherlu-xcq
wants to merge
1
commit into
nacos-group:master
Choose a base branch
from
brotherlu-xcq:feat-#858.1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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" | ||
|
|
@@ -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())) | ||
| }() | ||
|
|
||
| handlerMapping, ok := client.serverRequestHandlerMapping.Load(payLoadType) | ||
| if !ok { | ||
|
|
@@ -343,6 +349,7 @@ func (c *GrpcClient) handleServerRequest(p *nacos_grpc_service.Payload, grpcConn | |
| serverRequest.GetRequestId()) | ||
| return | ||
| } | ||
| status = rpc_response.GetGrpcResponseStatusCode(response) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 更新服务器请求处理的状态码用于监控。
📋 问题详情处理完服务器请求后,将实际的响应状态码赋值给变量 💡 解决方案确认 - // 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 { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
添加监控指标以跟踪服务器请求的处理时间与状态。
📋 问题详情
在处理服务器请求时,新增了对处理时间和响应状态的监控。通过在函数开始记录时间并在 defer 中上报监控数据,可以有效追踪每个请求类型的性能表现和成功率。这种做法有助于及时发现潜在的性能瓶颈或错误模式。
💡 解决方案
确保监控逻辑正确地捕获并报告请求处理的时间和状态。当前实现中使用了 defer 来保证监控代码总是被执行,这是合理的做法。
- // No changes needed for this section as it correctly implements monitoring有用意见👍 | 无用意见👎 | 错误意见❌