Skip to content

Commit

Permalink
fix data race of TestWatchResourceGroup
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Leung <[email protected]>
  • Loading branch information
rleungx committed Sep 9, 2024
1 parent 8733b55 commit 3e757d3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pkg/mcs/resourcemanager/server/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,9 +476,9 @@ func (m *Manager) backgroundMetricsFlush(ctx context.Context) {
ru = 0
}
availableRUCounter.WithLabelValues(group.Name, group.Name).Set(ru)
resourceGroupConfigGauge.WithLabelValues(group.Name, priorityLabel).Set(float64(group.Priority))
resourceGroupConfigGauge.WithLabelValues(group.Name, ruPerSecLabel).Set(float64(group.RUSettings.RU.Settings.FillRate))
resourceGroupConfigGauge.WithLabelValues(group.Name, ruCapacityLabel).Set(float64(group.RUSettings.RU.Settings.BurstLimit))
resourceGroupConfigGauge.WithLabelValues(group.Name, priorityLabel).Set(group.getPriority())
resourceGroupConfigGauge.WithLabelValues(group.Name, ruPerSecLabel).Set(group.getFillRate())
resourceGroupConfigGauge.WithLabelValues(group.Name, ruCapacityLabel).Set(group.getBurstLimit())
}
case <-recordMaxTicker.C:
// Record the sum of RRU and WRU every second.
Expand Down
18 changes: 18 additions & 0 deletions pkg/mcs/resourcemanager/server/resource_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,24 @@ func (rg *ResourceGroup) getRUToken() float64 {
return rg.RUSettings.RU.Tokens
}

func (rg *ResourceGroup) getPriority() float64 {
rg.RLock()
defer rg.RUnlock()
return float64(rg.Priority)
}

func (rg *ResourceGroup) getFillRate() float64 {
rg.RLock()
defer rg.RUnlock()
return float64(rg.RUSettings.RU.Settings.FillRate)
}

func (rg *ResourceGroup) getBurstLimit() float64 {
rg.RLock()
defer rg.RUnlock()
return float64(rg.RUSettings.RU.Settings.BurstLimit)
}

// PatchSettings patches the resource group settings.
// Only used to patch the resource group when updating.
// Note: the tokens is the delta value to patch.
Expand Down

0 comments on commit 3e757d3

Please sign in to comment.