From 65f2f9c9796507767539b0968409f01d63a7cfc8 Mon Sep 17 00:00:00 2001 From: nolouch Date: Thu, 1 Aug 2024 18:28:02 +0800 Subject: [PATCH 1/2] resourcemanager: add metrics to show resource group configuration Signed-off-by: nolouch --- pkg/mcs/resourcemanager/server/manager.go | 10 +++++++++- pkg/mcs/resourcemanager/server/metrics.go | 9 +++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/pkg/mcs/resourcemanager/server/manager.go b/pkg/mcs/resourcemanager/server/manager.go index 8588c22b9ae..4303316a4c8 100644 --- a/pkg/mcs/resourcemanager/server/manager.go +++ b/pkg/mcs/resourcemanager/server/manager.go @@ -48,6 +48,11 @@ const ( reservedDefaultGroupName = "default" middlePriority = 8 + + // Labels for the metrics. + ruPerSec = "ru_per_sec" + ruCapacity = "ru_capacity" + priority = "priority" ) // Manager is the manager of resource group. @@ -457,6 +462,7 @@ func (m *Manager) backgroundMetricsFlush(ctx context.Context) { delete(maxPerSecTrackers, r.name) readRequestUnitMaxPerSecCost.DeleteLabelValues(r.name) writeRequestUnitMaxPerSecCost.DeleteLabelValues(r.name) + resourceGroupConfigGauge.DeletePartialMatch(prometheus.Labels{newResourceGroupNameLabel: r.name}) } } case <-availableRUTicker.C: @@ -476,8 +482,10 @@ func (m *Manager) backgroundMetricsFlush(ctx context.Context) { ru = 0 } availableRUCounter.WithLabelValues(group.Name, group.Name).Set(ru) + resourceGroupConfigGauge.WithLabelValues(group.Name, priority).Set(float64(group.Priority)) + resourceGroupConfigGauge.WithLabelValues(group.Name, ruPerSec).Set(float64(group.RUSettings.RU.Settings.FillRate)) + resourceGroupConfigGauge.WithLabelValues(group.Name, ruCapacity).Set(float64(group.RUSettings.RU.Settings.BurstLimit)) } - case <-recordMaxTicker.C: // Record the sum of RRU and WRU every second. m.RLock() diff --git a/pkg/mcs/resourcemanager/server/metrics.go b/pkg/mcs/resourcemanager/server/metrics.go index 45c94e5c735..19811b6922f 100644 --- a/pkg/mcs/resourcemanager/server/metrics.go +++ b/pkg/mcs/resourcemanager/server/metrics.go @@ -116,6 +116,14 @@ var ( Name: "available_ru", Help: "Counter of the available RU for all resource groups.", }, []string{resourceGroupNameLabel, newResourceGroupNameLabel}) + + resourceGroupConfigGauge = prometheus.NewGaugeVec( + prometheus.GaugeOpts{ + Namespace: namespace, + Subsystem: serverSubsystem, + Name: "group_config", + Help: "Config of the resource group.", + }, []string{newResourceGroupNameLabel, "type"}) ) func init() { @@ -130,4 +138,5 @@ func init() { prometheus.MustRegister(availableRUCounter) prometheus.MustRegister(readRequestUnitMaxPerSecCost) prometheus.MustRegister(writeRequestUnitMaxPerSecCost) + prometheus.MustRegister(resourceGroupConfigGauge) } From 3654d066c66d06714487576226a2a2de11f376af Mon Sep 17 00:00:00 2001 From: nolouch Date: Thu, 8 Aug 2024 14:27:18 +0800 Subject: [PATCH 2/2] address Signed-off-by: nolouch --- pkg/mcs/resourcemanager/server/manager.go | 11 +++-------- pkg/mcs/resourcemanager/server/metrics.go | 7 ++++++- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pkg/mcs/resourcemanager/server/manager.go b/pkg/mcs/resourcemanager/server/manager.go index 4303316a4c8..58b8b5426a4 100644 --- a/pkg/mcs/resourcemanager/server/manager.go +++ b/pkg/mcs/resourcemanager/server/manager.go @@ -48,11 +48,6 @@ const ( reservedDefaultGroupName = "default" middlePriority = 8 - - // Labels for the metrics. - ruPerSec = "ru_per_sec" - ruCapacity = "ru_capacity" - priority = "priority" ) // Manager is the manager of resource group. @@ -482,9 +477,9 @@ func (m *Manager) backgroundMetricsFlush(ctx context.Context) { ru = 0 } availableRUCounter.WithLabelValues(group.Name, group.Name).Set(ru) - resourceGroupConfigGauge.WithLabelValues(group.Name, priority).Set(float64(group.Priority)) - resourceGroupConfigGauge.WithLabelValues(group.Name, ruPerSec).Set(float64(group.RUSettings.RU.Settings.FillRate)) - resourceGroupConfigGauge.WithLabelValues(group.Name, ruCapacity).Set(float64(group.RUSettings.RU.Settings.BurstLimit)) + 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)) } case <-recordMaxTicker.C: // Record the sum of RRU and WRU every second. diff --git a/pkg/mcs/resourcemanager/server/metrics.go b/pkg/mcs/resourcemanager/server/metrics.go index 19811b6922f..6ed4d8ff10a 100644 --- a/pkg/mcs/resourcemanager/server/metrics.go +++ b/pkg/mcs/resourcemanager/server/metrics.go @@ -29,6 +29,11 @@ const ( tiflashTypeLabel = "ap" defaultTypeLabel = "tp" newResourceGroupNameLabel = "resource_group" + + // Labels for the config. + ruPerSecLabel = "ru_per_sec" + ruCapacityLabel = "ru_capacity" + priorityLabel = "priority" ) var ( @@ -123,7 +128,7 @@ var ( Subsystem: serverSubsystem, Name: "group_config", Help: "Config of the resource group.", - }, []string{newResourceGroupNameLabel, "type"}) + }, []string{newResourceGroupNameLabel, typeLabel}) ) func init() {