-
Notifications
You must be signed in to change notification settings - Fork 262
fix(resourcecontrol): bypass RU accounting for NextGen background activities #1930
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
YuhaoZhang00
wants to merge
10
commits into
tikv:master
Choose a base branch
from
YuhaoZhang00:rc/bypass-background-activities
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 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c4b965a
fix(resourcecontrol): extend bypass logic for internal requests
JmPotato c7e1e76
fix(resourcecontrol): add WorkloadLearning bypass and define constant…
YuhaoZhang00 dd19be2
fix(resourcecontrol): add ref comment for WorkloadLearning bypass
YuhaoZhang00 144cec6
Merge upstream/master into rc/bypass-background-activities
YuhaoZhang00 62fda1e
resource_control: add Prometheus metric for RU consumption by source
YuhaoZhang00 7c31694
resource_control: add bypassed request counter and track bypass in in…
YuhaoZhang00 e791ac6
Merge branch 'rc/resource-control-metrics' into rc/bypass-background-…
YuhaoZhang00 409d1df
Merge branch 'master' into rc/bypass-background-activities
YuhaoZhang00 d78b7fc
fix(resourcecontrol): plumb request source and bypass nextgen backgro…
YuhaoZhang00 993380a
Merge remote-tracking branch 'upstream/master' into rc/bypass-backgro…
YuhaoZhang00 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 |
|---|---|---|
|
|
@@ -19,7 +19,9 @@ import ( | |
| "sync/atomic" | ||
| "time" | ||
|
|
||
| rmpb "github.com/pingcap/kvproto/pkg/resource_manager" | ||
| "github.com/tikv/client-go/v2/internal/resourcecontrol" | ||
| "github.com/tikv/client-go/v2/metrics" | ||
| "github.com/tikv/client-go/v2/tikvrpc" | ||
| "github.com/tikv/client-go/v2/tikvrpc/interceptor" | ||
| "github.com/tikv/client-go/v2/util" | ||
|
|
@@ -63,6 +65,9 @@ func (r interceptedClient) SendRequest(ctx context.Context, addr string, req *ti | |
| ruDetails = val.(*util.RUDetails) | ||
| ruDetails.Update(consumption, waitDuration) | ||
| } | ||
| recordResourceControlMetrics(resourceGroupName, req.GetRequestSource(), consumption) | ||
| } else if reqInfo != nil && reqInfo.Bypass() { | ||
| metrics.TiKVResourceControlBypassedCounter.WithLabelValues(resourceGroupName, req.GetRequestSource()).Inc() | ||
| } | ||
|
|
||
| if ctxInterceptor := interceptor.GetRPCInterceptorFromCtx(ctx); ctxInterceptor == nil { | ||
|
|
@@ -82,6 +87,7 @@ func (r interceptedClient) SendRequest(ctx context.Context, addr string, req *ti | |
| if ruDetails != nil { | ||
| ruDetails.Update(consumption, waitDuration) | ||
| } | ||
| recordResourceControlMetrics(resourceGroupName, req.GetRequestSource(), consumption) | ||
| } | ||
|
|
||
| return resp, err | ||
|
|
@@ -111,6 +117,7 @@ func (r interceptedClient) SendRequestAsync(ctx context.Context, addr string, re | |
| ruDetails = val.(*util.RUDetails) | ||
| ruDetails.Update(consumption, waitDuration) | ||
| } | ||
| recordResourceControlMetrics(resourceGroupName, req.GetRequestSource(), consumption) | ||
|
|
||
| cb.Inject(func(resp *tikvrpc.Response, err error) (*tikvrpc.Response, error) { | ||
| if ctxInterceptor := interceptor.GetRPCInterceptorFromCtx(ctx); ctxInterceptor != nil { | ||
|
|
@@ -130,9 +137,12 @@ func (r interceptedClient) SendRequestAsync(ctx context.Context, addr string, re | |
| if ruDetails != nil { | ||
| ruDetails.Update(consumption, waitDuration) | ||
| } | ||
| recordResourceControlMetrics(resourceGroupName, req.GetRequestSource(), consumption) | ||
| } | ||
| return resp, err | ||
| }) | ||
| } else if reqInfo != nil && reqInfo.Bypass() { | ||
| metrics.TiKVResourceControlBypassedCounter.WithLabelValues(resourceGroupName, req.GetRequestSource()).Inc() | ||
|
Member
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. Ditto. |
||
| } | ||
|
|
||
| r.Client.SendRequestAsync(ctx, addr, req, cb) | ||
|
|
@@ -145,6 +155,20 @@ var ( | |
| ResourceControlInterceptor atomic.Pointer[resourceControlClient.ResourceGroupKVInterceptor] | ||
| ) | ||
|
|
||
| // recordResourceControlMetrics records RU consumption from a single resource | ||
| // control call (OnRequestWait or OnResponseWait). | ||
| func recordResourceControlMetrics(resourceGroupName, requestSource string, consumption *rmpb.Consumption) { | ||
| if consumption == nil { | ||
| return | ||
| } | ||
| if consumption.RRU > 0 { | ||
| metrics.TiKVResourceControlRUCounter.WithLabelValues(resourceGroupName, requestSource, "rru").Add(consumption.RRU) | ||
| } | ||
| if consumption.WRU > 0 { | ||
| metrics.TiKVResourceControlRUCounter.WithLabelValues(resourceGroupName, requestSource, "wru").Add(consumption.WRU) | ||
|
Member
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. Ditto. |
||
| } | ||
| } | ||
|
|
||
| func getResourceControlInfo(ctx context.Context, req *tikvrpc.Request) ( | ||
| string, | ||
| resourceControlClient.ResourceGroupKVInterceptor, | ||
|
|
@@ -169,7 +193,7 @@ func getResourceControlInfo(ctx context.Context, req *tikvrpc.Request) ( | |
| } | ||
| reqInfo := resourcecontrol.MakeRequestInfo(req) | ||
| if reqInfo.Bypass() { | ||
| return "", nil, nil | ||
| return resourceGroupName, nil, reqInfo | ||
| } | ||
| return resourceGroupName, resourceControlInterceptor, reqInfo | ||
| } | ||
|
|
||
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
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
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
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.
Avoid introducing
WithLabelValuesop on the hot path, should cache it in advance.