-
Notifications
You must be signed in to change notification settings - Fork 759
client/resource_group: cache request source RU metrics #10588
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
base: master
Are you sure you want to change the base?
Changes from all commits
492976a
3fe18d6
11e1a6c
915f0b5
c7fbfee
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 |
|---|---|---|
|
|
@@ -142,11 +142,12 @@ var _ ResourceGroupKVInterceptor = (*ResourceGroupsController)(nil) | |
|
|
||
| // ResourceGroupsController implements ResourceGroupKVInterceptor. | ||
| type ResourceGroupsController struct { | ||
| clientUniqueID uint64 | ||
| provider ResourceGroupProvider | ||
| groupsController sync.Map | ||
| ruConfig *RUConfig | ||
| keyspaceID uint32 | ||
| clientUniqueID uint64 | ||
| provider ResourceGroupProvider | ||
| groupsController sync.Map | ||
| requestSourceStates sync.Map | ||
| ruConfig *RUConfig | ||
| keyspaceID uint32 | ||
|
|
||
| loopCtx context.Context | ||
| loopCancel func() | ||
|
|
@@ -337,6 +338,7 @@ func (c *ResourceGroupsController) Start(ctx context.Context) { | |
| /* channels */ | ||
| case <-c.loopCtx.Done(): | ||
| metrics.ResourceGroupStatusGauge.Reset() | ||
| metrics.RequestSourceRUCounter.Reset() | ||
| return | ||
| case <-c.responseDeadlineCh: | ||
| c.run.inDegradedMode.Store(true) | ||
|
|
@@ -387,7 +389,13 @@ func (c *ResourceGroupsController) Start(ctx context.Context) { | |
| continue | ||
| } | ||
| // If the resource group is marked as tombstone before, re-create the resource group controller. | ||
| newGC, err := newGroupCostController(group, c.ruConfig, c.lowTokenNotifyChan, c.tokenBucketUpdateChan) | ||
| newGC, err := newGroupCostController( | ||
| group, | ||
| c.ruConfig, | ||
| c.lowTokenNotifyChan, | ||
| c.tokenBucketUpdateChan, | ||
| c.getOrCreateRequestSourceMetricsState(name), | ||
| ) | ||
| if err != nil { | ||
| log.Warn("[resource group controller] re-create resource group cost controller for tombstone failed", | ||
| zap.String("name", name), zap.Error(err)) | ||
|
|
@@ -472,6 +480,21 @@ func (c *ResourceGroupsController) loadOrStoreGroupController(name string, gc *g | |
| return tmp.(*groupCostController), loaded | ||
| } | ||
|
|
||
| func (c *ResourceGroupsController) getOrCreateRequestSourceMetricsState(name string) *requestSourceMetricsState { | ||
|
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. Will there be a race between create and cleanup
Contributor
Author
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. Good catch. Fixed by switching to |
||
| if state, ok := c.requestSourceStates.Load(name); ok { | ||
| return state.(*requestSourceMetricsState) | ||
| } | ||
| state := newRequestSourceMetricsState(name) | ||
| actual, _ := c.requestSourceStates.LoadOrStore(name, state) | ||
| return actual.(*requestSourceMetricsState) | ||
YuhaoZhang00 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| func (c *ResourceGroupsController) cleanupRequestSourceMetricsState(name string) { | ||
| if v, loaded := c.requestSourceStates.LoadAndDelete(name); loaded { | ||
| v.(*requestSourceMetricsState).cleanup() | ||
| } | ||
| } | ||
|
|
||
| // NewResourceGroupNotExistErr returns a new error that indicates the resource group does not exist. | ||
| // It's exported for testing. | ||
| func NewResourceGroupNotExistErr(name string) error { | ||
|
|
@@ -521,7 +544,13 @@ func (c *ResourceGroupsController) tryGetResourceGroupController( | |
| return gc, nil | ||
| } | ||
| // Initialize the resource group controller. | ||
| gc, err = newGroupCostController(group, c.ruConfig, c.lowTokenNotifyChan, c.tokenBucketUpdateChan) | ||
| gc, err = newGroupCostController( | ||
| group, | ||
| c.ruConfig, | ||
| c.lowTokenNotifyChan, | ||
| c.tokenBucketUpdateChan, | ||
| c.getOrCreateRequestSourceMetricsState(name), | ||
| ) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
@@ -553,15 +582,23 @@ func (c *ResourceGroupsController) tombstoneGroupCostController(name string) { | |
| log.Warn("[resource group controller] get default resource group meta for tombstone failed", | ||
| zap.String("name", name), zap.Error(err)) | ||
| // Directly delete the resource group controller if the default group is not available. | ||
| c.cleanupRequestSourceMetricsState(name) | ||
| c.groupsController.Delete(name) | ||
| return | ||
| } | ||
| // Create a default resource group controller for the tombstone resource group independently. | ||
| gc, err := newGroupCostController(defaultGC.getMeta(), c.ruConfig, c.lowTokenNotifyChan, c.tokenBucketUpdateChan) | ||
| gc, err := newGroupCostController( | ||
| defaultGC.getMeta(), | ||
| c.ruConfig, | ||
| c.lowTokenNotifyChan, | ||
| c.tokenBucketUpdateChan, | ||
| c.getOrCreateRequestSourceMetricsState(name), | ||
| ) | ||
| if err != nil { | ||
| log.Warn("[resource group controller] create default resource group cost controller for tombstone failed", | ||
| zap.String("name", name), zap.Error(err)) | ||
| // Directly delete the resource group controller if the default group controller cannot be created. | ||
| c.cleanupRequestSourceMetricsState(name) | ||
| c.groupsController.Delete(name) | ||
| return | ||
| } | ||
|
|
@@ -583,6 +620,7 @@ func (c *ResourceGroupsController) cleanUpResourceGroup() { | |
| gc.mu.Unlock() | ||
| if equalRU(latestConsumption, *gc.run.consumption) { | ||
| if gc.inactive || gc.tombstone.Load() { | ||
| c.cleanupRequestSourceMetricsState(resourceGroupName) | ||
| c.groupsController.Delete(resourceGroupName) | ||
| metrics.ResourceGroupStatusGauge.DeleteLabelValues(resourceGroupName, resourceGroupName) | ||
| return true | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.