Skip to content

Commit

Permalink
address comment
Browse files Browse the repository at this point in the history
Signed-off-by: husharp <jinhao.hu@pingcap.com>
  • Loading branch information
HuSharp committed Jul 11, 2023
1 parent 0c0b6f6 commit a30ce37
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 16 deletions.
2 changes: 0 additions & 2 deletions internal/client/client_interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ func buildResourceControlInterceptor(
// Build the interceptor.
interceptFn := func(next interceptor.RPCInterceptorFunc) interceptor.RPCInterceptorFunc {
return func(target string, req *tikvrpc.Request) (*tikvrpc.Response, error) {
// Background requests don't need to update the runtime stats because it will record in TiKV.
reqInfo.SetRequestSource(util.RequestSourceFromCtx(ctx))
consumption, penalty, err := resourceControlInterceptor.OnRequestWait(ctx, resourceGroupName, reqInfo)
if err != nil {
return nil, err
Expand Down
9 changes: 3 additions & 6 deletions internal/resourcecontrol/resource_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type RequestInfo struct {
// MakeRequestInfo extracts the relevant information from a BatchRequest.
func MakeRequestInfo(req *tikvrpc.Request) *RequestInfo {
if !req.IsTxnWriteRequest() && !req.IsRawWriteRequest() {
return &RequestInfo{writeBytes: -1}
return &RequestInfo{writeBytes: -1, requestSource: req.RequestSource}
}

var writeBytes int64
Expand All @@ -58,7 +58,8 @@ func MakeRequestInfo(req *tikvrpc.Request) *RequestInfo {
writeBytes += int64(len(k))
}
}
return &RequestInfo{writeBytes: writeBytes, storeID: req.Context.Peer.StoreId, replicaNumber: req.ReplicaNumber}
return &RequestInfo{writeBytes: writeBytes, storeID: req.Context.Peer.StoreId,
replicaNumber: req.ReplicaNumber, requestSource: req.RequestSource}
}

// IsWrite returns whether the request is a write request.
Expand All @@ -84,10 +85,6 @@ func (req *RequestInfo) RequestSource() string {
return req.requestSource
}

func (req *RequestInfo) SetRequestSource(requestSource string) {
req.requestSource = requestSource
}

// ResponseInfo contains information about a response that is able to calculate the RU cost
// after the response is received. Specifically, the read bytes RU cost of a read request
// could be calculated by its response size, and the KV CPU time RU cost of a request could
Expand Down
2 changes: 1 addition & 1 deletion util/request_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func WithInternalSourceType(ctx context.Context, source string) context.Context
})
}

// BuildRequestSource builds a request source from internal, source and explicitSource.
// BuildRequestSource builds a request_source from internal, source and explicitSource.
func BuildRequestSource(internal bool, source, explicitSource string) string {
requestSource := RequestSource{
RequestSourceInternal: internal,
Expand Down
14 changes: 7 additions & 7 deletions util/request_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,8 @@ func TestGetRequestSource(t *testing.T) {

func TestBuildRequestSource(t *testing.T) {
// Test internal request
expected := "unknown_default"
actual := BuildRequestSource(true, "", "")
assert.Equal(t, expected, actual)

// Test internal request
expected = "internal_test_lightning"
actual = BuildRequestSource(true, "test", "lightning")
expected := "internal_test_lightning"
actual := BuildRequestSource(true, "test", "lightning")
assert.Equal(t, expected, actual)

// Test external request
Expand All @@ -92,4 +87,9 @@ func TestBuildRequestSource(t *testing.T) {
expected = "external_unknown_lightning"
actual = BuildRequestSource(false, "", "lightning")
assert.Equal(t, expected, actual)

// Test RequestSourceType && ExplicitRequestSourceType both empty
expected = "unknown_default"
actual = BuildRequestSource(true, "", "")
assert.Equal(t, expected, actual)
}

0 comments on commit a30ce37

Please sign in to comment.