From 3e757d33cfa16911b8fbc2377f5ad4152e4e4ee2 Mon Sep 17 00:00:00 2001 From: Ryan Leung Date: Mon, 9 Sep 2024 16:15:33 +0800 Subject: [PATCH] fix data race of TestWatchResourceGroup Signed-off-by: Ryan Leung --- pkg/mcs/resourcemanager/server/manager.go | 6 +++--- .../resourcemanager/server/resource_group.go | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/pkg/mcs/resourcemanager/server/manager.go b/pkg/mcs/resourcemanager/server/manager.go index 7a07714e07a..dd7151a8b05 100644 --- a/pkg/mcs/resourcemanager/server/manager.go +++ b/pkg/mcs/resourcemanager/server/manager.go @@ -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. diff --git a/pkg/mcs/resourcemanager/server/resource_group.go b/pkg/mcs/resourcemanager/server/resource_group.go index cb76a98327a..6a5d06da6f7 100644 --- a/pkg/mcs/resourcemanager/server/resource_group.go +++ b/pkg/mcs/resourcemanager/server/resource_group.go @@ -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.