-
Notifications
You must be signed in to change notification settings - Fork 729
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
metrics: add region request metrics which record caller info #9117
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,8 +31,27 @@ type ( | |
const ( | ||
// TestID is used for test. | ||
TestID ID = "test" | ||
|
||
// TestComponent is used for test. | ||
TestComponent Component = "test" | ||
|
||
// client-go component | ||
CodecPDClient Component = "codec-pd-client" | ||
RegionCache Component = "region-cache" | ||
StoreCache Component = "store-cache" | ||
Oracles Component = "oracle" | ||
Rawkv Component = "rawkv" | ||
KvStore Component = "kv-store" | ||
InterceptedPDClient Component = "intercepted-pd-client" | ||
|
||
// TiDB component | ||
Pitr Component = "pitr" | ||
Ddl Component = "ddl" | ||
ImportInto Component = "import-into" | ||
TikvHandler Component = "tikv-handler" | ||
GcWorker Component = "gc-worker" | ||
GcJob Component = "gc-job" | ||
DistributedGcJob Component = "distributed-gc-job" | ||
Comment on lines
+38
to
+54
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. These names can be reviewed with these two PR https://github.com/pingcap/tidb/pull/59911/files and tikv/client-go#1516 |
||
) | ||
|
||
var processName ID | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1359,7 +1359,7 @@ func (s *GrpcServer) RegionHeartbeat(stream pdpb.PD_RegionHeartbeatServer) error | |
} | ||
|
||
// GetRegion implements gRPC PDServer. | ||
func (s *GrpcServer) GetRegion(ctx context.Context, request *pdpb.GetRegionRequest) (*pdpb.GetRegionResponse, error) { | ||
func (s *GrpcServer) GetRegion(ctx context.Context, request *pdpb.GetRegionRequest) (resp *pdpb.GetRegionResponse, err error) { | ||
failpoint.Inject("rateLimit", func() { | ||
failpoint.Return(nil, errs.ErrGRPCRateLimitExceeded(errs.ErrRateLimitExceeded)) | ||
}) | ||
|
@@ -1384,6 +1384,9 @@ func (s *GrpcServer) GetRegion(ctx context.Context, request *pdpb.GetRegionReque | |
rc *cluster.RaftCluster | ||
region *core.RegionInfo | ||
) | ||
defer func() { | ||
incRegionRequestCounter("GetRegion", request.Header, resp.Header.Error) | ||
}() | ||
if *followerHandle { | ||
rc = s.cluster | ||
if !rc.GetRegionSyncer().IsRunning() { | ||
|
@@ -1422,7 +1425,7 @@ func (s *GrpcServer) GetRegion(ctx context.Context, request *pdpb.GetRegionReque | |
} | ||
|
||
// GetPrevRegion implements gRPC PDServer | ||
func (s *GrpcServer) GetPrevRegion(ctx context.Context, request *pdpb.GetRegionRequest) (*pdpb.GetRegionResponse, error) { | ||
func (s *GrpcServer) GetPrevRegion(ctx context.Context, request *pdpb.GetRegionRequest) (resp *pdpb.GetRegionResponse, err error) { | ||
done, err := s.rateLimitCheck() | ||
if err != nil { | ||
return nil, err | ||
|
@@ -1440,6 +1443,9 @@ func (s *GrpcServer) GetPrevRegion(ctx context.Context, request *pdpb.GetRegionR | |
return rsp.(*pdpb.GetRegionResponse), err | ||
} | ||
|
||
defer func() { | ||
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. Can we extract one function for this? and get the call name by another way. 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. Isn't there only one function right now? |
||
incRegionRequestCounter("GetPrevRegion", request.Header, resp.Header.Error) | ||
}() | ||
var rc *cluster.RaftCluster | ||
if *followerHandle { | ||
// no need to check running status | ||
|
@@ -1477,7 +1483,7 @@ func (s *GrpcServer) GetPrevRegion(ctx context.Context, request *pdpb.GetRegionR | |
} | ||
|
||
// GetRegionByID implements gRPC PDServer. | ||
func (s *GrpcServer) GetRegionByID(ctx context.Context, request *pdpb.GetRegionByIDRequest) (*pdpb.GetRegionResponse, error) { | ||
func (s *GrpcServer) GetRegionByID(ctx context.Context, request *pdpb.GetRegionByIDRequest) (resp *pdpb.GetRegionResponse, err error) { | ||
done, err := s.rateLimitCheck() | ||
if err != nil { | ||
return nil, err | ||
|
@@ -1495,6 +1501,9 @@ func (s *GrpcServer) GetRegionByID(ctx context.Context, request *pdpb.GetRegionB | |
return rsp.(*pdpb.GetRegionResponse), err | ||
} | ||
|
||
defer func() { | ||
incRegionRequestCounter("GetRegionByID", request.Header, resp.Header.Error) | ||
}() | ||
var rc *cluster.RaftCluster | ||
if *followerHandle { | ||
rc = s.cluster | ||
|
@@ -1584,6 +1593,10 @@ func (s *GrpcServer) QueryRegion(stream pdpb.PD_QueryRegionServer) error { | |
PrevKeyIdMap: prevKeyIDMap, | ||
RegionsById: regionsByID, | ||
} | ||
incRegionRequestCounter("QueryRegion", request.Header, response.Header.Error) | ||
|
||
regionRequestCounter.WithLabelValues("QueryRegion", request.Header.CallerId, | ||
request.Header.CallerComponent, "").Inc() | ||
if err := stream.Send(response); err != nil { | ||
return errors.WithStack(err) | ||
} | ||
|
@@ -1592,7 +1605,7 @@ func (s *GrpcServer) QueryRegion(stream pdpb.PD_QueryRegionServer) error { | |
|
||
// Deprecated: use BatchScanRegions instead. | ||
// ScanRegions implements gRPC PDServer. | ||
func (s *GrpcServer) ScanRegions(ctx context.Context, request *pdpb.ScanRegionsRequest) (*pdpb.ScanRegionsResponse, error) { | ||
func (s *GrpcServer) ScanRegions(ctx context.Context, request *pdpb.ScanRegionsRequest) (resp *pdpb.ScanRegionsResponse, err error) { | ||
done, err := s.rateLimitCheck() | ||
if err != nil { | ||
return nil, err | ||
|
@@ -1610,6 +1623,9 @@ func (s *GrpcServer) ScanRegions(ctx context.Context, request *pdpb.ScanRegionsR | |
return rsp.(*pdpb.ScanRegionsResponse), nil | ||
} | ||
|
||
defer func() { | ||
incRegionRequestCounter("ScanRegions", request.Header, resp.Header.Error) | ||
}() | ||
var rc *cluster.RaftCluster | ||
if *followerHandle { | ||
rc = s.cluster | ||
|
@@ -1626,7 +1642,7 @@ func (s *GrpcServer) ScanRegions(ctx context.Context, request *pdpb.ScanRegionsR | |
if *followerHandle && len(regions) == 0 { | ||
return &pdpb.ScanRegionsResponse{Header: regionNotFound()}, nil | ||
} | ||
resp := &pdpb.ScanRegionsResponse{Header: wrapHeader()} | ||
resp = &pdpb.ScanRegionsResponse{Header: wrapHeader()} | ||
for _, r := range regions { | ||
leader := r.GetLeader() | ||
if leader == nil { | ||
|
@@ -1646,7 +1662,7 @@ func (s *GrpcServer) ScanRegions(ctx context.Context, request *pdpb.ScanRegionsR | |
} | ||
|
||
// BatchScanRegions implements gRPC PDServer. | ||
func (s *GrpcServer) BatchScanRegions(ctx context.Context, request *pdpb.BatchScanRegionsRequest) (*pdpb.BatchScanRegionsResponse, error) { | ||
func (s *GrpcServer) BatchScanRegions(ctx context.Context, request *pdpb.BatchScanRegionsRequest) (resp *pdpb.BatchScanRegionsResponse, err error) { | ||
done, err := s.rateLimitCheck() | ||
if err != nil { | ||
return nil, err | ||
|
@@ -1664,6 +1680,10 @@ func (s *GrpcServer) BatchScanRegions(ctx context.Context, request *pdpb.BatchSc | |
return rsp.(*pdpb.BatchScanRegionsResponse), nil | ||
} | ||
|
||
defer func() { | ||
incRegionRequestCounter("BatchScanRegions", request.Header, resp.Header.Error) | ||
}() | ||
|
||
var rc *cluster.RaftCluster | ||
if *followerHandle { | ||
rc = s.cluster | ||
|
@@ -1729,7 +1749,7 @@ func (s *GrpcServer) BatchScanRegions(ctx context.Context, request *pdpb.BatchSc | |
if *followerHandle && len(regions) == 0 { | ||
return &pdpb.BatchScanRegionsResponse{Header: regionNotFound()}, nil | ||
} | ||
resp := &pdpb.BatchScanRegionsResponse{Header: wrapHeader(), Regions: regions} | ||
resp = &pdpb.BatchScanRegionsResponse{Header: wrapHeader(), Regions: regions} | ||
return resp, nil | ||
} | ||
|
||
|
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.
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.
where is it used?
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.
It is used in other repo https://github.com/tikv/pd/pull/9117/files/ebd66e5b0042353ad6402f6239ab049a438c21a0#r1982716822
Did I misunderstand your comment? I thought what you needed was the current PR like. tikv/client-go#1516 (comment)