Skip to content
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

resouce_manager: impl resource controller for tokens client #5811

Merged

Conversation

CabinfeverB
Copy link
Member

@CabinfeverB CabinfeverB commented Dec 29, 2022

Signed-off-by: Cabinfever_B cabinfeveroier@gmail.com

What problem does this PR solve?

Issue Number: ref #5851

What is changed and how does it work?

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)

Release note

None.

Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
@ti-chi-bot
Copy link
Member

ti-chi-bot commented Dec 29, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • JmPotato
  • nolouch

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added do-not-merge/needs-linked-issue release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Dec 29, 2022
@codecov
Copy link

codecov bot commented Dec 29, 2022

Codecov Report

Base: 75.51% // Head: 75.69% // Increases project coverage by +0.18% 🎉

Coverage data is based on head (91eb7b3) compared to base (6e35a4d).
Patch coverage: 70.23% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5811      +/-   ##
==========================================
+ Coverage   75.51%   75.69%   +0.18%     
==========================================
  Files         341      342       +1     
  Lines       34413    34829     +416     
==========================================
+ Hits        25986    26363     +377     
- Misses       6191     6223      +32     
- Partials     2236     2243       +7     
Flag Coverage Δ
unittests 75.69% <70.23%> (+0.18%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
pkg/mcs/resource_manager/client/client.go 68.47% <68.47%> (ø)
pkg/mcs/resource_manager/client/model.go 80.85% <71.87%> (+80.85%) ⬆️
pkg/mcs/resource_manager/client/config.go 47.36% <100.00%> (+47.36%) ⬆️
pkg/mcs/resource_manager/client/limiter.go 82.66% <100.00%> (+13.70%) ⬆️
pkg/mcs/resource_manager/server/token_bukets.go 92.68% <100.00%> (+3.49%) ⬆️
server/tso/local_allocator.go 64.86% <0.00%> (-13.52%) ⬇️
server/region_syncer/server.go 82.96% <0.00%> (-4.40%) ⬇️
pkg/id/id.go 86.44% <0.00%> (-3.39%) ⬇️
pkg/storage/kv/etcd_kv.go 72.22% <0.00%> (-3.18%) ⬇️
pkg/utils/etcdutil/etcdutil.go 86.04% <0.00%> (-2.33%) ⬇️
... and 30 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

pkg/mcs/resource_manager/tenant_client/client.go Outdated Show resolved Hide resolved
pkg/mcs/resource_manager/tenant_client/client.go Outdated Show resolved Hide resolved
pkg/mcs/resource_manager/tenant_client/client.go Outdated Show resolved Hide resolved
pkg/mcs/resource_manager/tenant_client/limiter.go Outdated Show resolved Hide resolved
Signed-off-by: JmPotato <ghzpotato@gmail.com>
@CabinfeverB CabinfeverB marked this pull request as draft January 12, 2023 02:41
@ti-chi-bot ti-chi-bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 12, 2023
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>

merge

Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
@CabinfeverB CabinfeverB force-pushed the resource-manager/tenant_side_client_1 branch from a915b08 to 9141699 Compare January 12, 2023 09:39
@ti-chi-bot ti-chi-bot added release-note-none Denotes a PR that doesn't merit a release note. and removed do-not-merge/needs-linked-issue release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Jan 12, 2023
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Copy link
Contributor

@nolouch nolouch left a comment

Choose a reason for hiding this comment

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

rest lgtm

}
log.Info("create resource group cost controller", zap.String("name", group.GetName()))
gc := newGroupCostController(group, c.config, c.lowTokenNotifyChan)
gc.initRunState()
Copy link
Contributor

Choose a reason for hiding this comment

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

A future case: If user change mode from RU to RAW mode. it need re-init?

if err != nil {
return err
}
gc.mu.Lock()
Copy link
Contributor

Choose a reason for hiding this comment

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

This is in hot path, we may need to do some benchmark later. BTW, maybe we can compare it with the buffer channel.

Copy link
Member Author

Choose a reason for hiding this comment

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

We can compare it in another PR.

}
}

func (gc *groupCostController) updateAvgResourcePerSec() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
func (gc *groupCostController) updateAvgResourcePerSec() {
func (gc *groupCostController) updateAvgRaWResourcePerSec() {


func (gc *groupCostController) updateAvgResourcePerSec() {
for typ, counter := range gc.run.resourceTokens {
if !gc.calcAvg(counter, getResourceValueFromConsumption(gc.run.consumption, typ)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if !gc.calcAvg(counter, getResourceValueFromConsumption(gc.run.consumption, typ)) {
if !gc.calcAvg(counter, getRawResourceValueFromConsumption(gc.run.consumption, typ)) {

if !gc.calcAvg(counter, getResourceValueFromConsumption(gc.run.consumption, typ)) {
continue
}
log.Debug("[resource group controllor] update avg ru per sec", zap.String("name", gc.Name), zap.String("type", rmpb.RawResourceType_name[int32(typ)]), zap.Float64("avgRUPerSec", counter.avgRUPerSec))
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
log.Debug("[resource group controllor] update avg ru per sec", zap.String("name", gc.Name), zap.String("type", rmpb.RawResourceType_name[int32(typ)]), zap.Float64("avgRUPerSec", counter.avgRUPerSec))
log.Debug("[resource group controllor] update avg raw resource per sec", zap.String("name", gc.Name), zap.String("type", rmpb.RawResourceType_name[int32(typ)]), zap.Float64("avgRUPerSec", counter.avgRUPerSec))

}

var cfg tokenBucketReconfigureArgs
if trickleTimeMs == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe we need some comments, here is main difference.

}

// Start starts resourceGroupController service
func (c *resourceGroupsController) Start(ctx context.Context) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

How about add a Stop function, I may use it when resource group features disable.

Choose a reason for hiding this comment

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

I like it

Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
TargetRequestPeriodMs: uint64(c.config.targetPeriod / time.Millisecond),
}
go func() {
log.Info("[resource group controllor] send token bucket request", zap.Time("now", now), zap.Any("req", req.Requests), zap.String("source", source))
Copy link
Contributor

Choose a reason for hiding this comment

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

Debug level.


var _ ResourceGroupKVInterceptor = (*resourceGroupsController)(nil)

type resourceGroupsController struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
type resourceGroupsController struct {
type ResourceGroupsController struct {

Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
@@ -0,0 +1,790 @@
// Copyright 2022 TiKV Project Authors.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Copyright 2022 TiKV Project Authors.
// Copyright 2023 TiKV Project Authors.

}

// Start starts resourceGroupController service
func (c *ResourceGroupsController) Start(ctx context.Context) error {
Copy link
Member

Choose a reason for hiding this comment

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

This function doesn't need to return anything.

if err != nil {
return err
}
lastedGroups := make(map[string]struct{})
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
lastedGroups := make(map[string]struct{})
latestGroups := make(map[string]struct{})

Copy link
Contributor

Choose a reason for hiding this comment

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

reaming @CabinfeverB

name := res.GetResourceGroupName()
v, ok := c.groupsController.Load(name)
if !ok {
log.Warn("A non-existent resource group was found when handle token response.", zap.String("name", name))
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we continue here?

Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Copy link
Contributor

@nolouch nolouch left a comment

Choose a reason for hiding this comment

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

lgtm

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Jan 19, 2023
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
@ti-chi-bot
Copy link
Member

@BornChanger: Thanks for your review. The bot only counts approvals from reviewers and higher roles in list, but you're still welcome to leave your comments.

In response to this:

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@ti-chi-bot ti-chi-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 19, 2023
Copy link
Member

@JmPotato JmPotato left a comment

Choose a reason for hiding this comment

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

The rest LGTM.

func (c *ResourceGroupsController) OnRequestWait(
ctx context.Context, resourceGroupName string, info RequestInfo,
) (err error) {
if _, ok := defaultWhiteList[resourceGroupName]; ok {
Copy link
Member

Choose a reason for hiding this comment

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


// OnResponse is used to consume tokens atfer receiving response
func (c *ResourceGroupsController) OnResponse(_ context.Context, resourceGroupName string, req RequestInfo, resp ResponseInfo) error {
if _, ok := defaultWhiteList[resourceGroupName]; ok {
Copy link
Member

Choose a reason for hiding this comment

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

Ditto.

Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
Signed-off-by: Cabinfever_B <cabinfeveroier@gmail.com>
@ti-chi-bot ti-chi-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 19, 2023
@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Jan 19, 2023
@JmPotato
Copy link
Member

/merge

@ti-chi-bot
Copy link
Member

@JmPotato: It seems you want to merge this PR, I will help you trigger all the tests:

/run-all-tests

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: 37abfa8

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Jan 19, 2023
@ti-chi-bot ti-chi-bot merged commit 402c2bf into tikv:master Jan 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-note-none Denotes a PR that doesn't merit a release note. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants