Skip to content

Commit

Permalink
fix ru deletion
Browse files Browse the repository at this point in the history
Signed-off-by: AmoebaProtozoa <[email protected]>
  • Loading branch information
AmoebaProtozoa committed Jan 2, 2024
1 parent 5bd84c2 commit 1d103f9
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions pkg/mcs/resourcemanager/server/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,12 @@ type Manager struct {
isTiFlash bool
}
// record update time of each resource group
consumptionRecord map[string]time.Time
consumptionRecord map[consumptionRecordKey]time.Time
}

type consumptionRecordKey struct {
name string
ruType string
}

// ConfigProvider is used to get resource manager config from the given
Expand All @@ -84,7 +89,7 @@ func NewManager[T ConfigProvider](srv bs.Server) *Manager {
isBackground bool
isTiFlash bool
}, defaultConsumptionChanSize),
consumptionRecord: make(map[string]time.Time),
consumptionRecord: make(map[consumptionRecordKey]time.Time),
}
// The first initialization after the server is started.
srv.AddStartCallback(func() {
Expand Down Expand Up @@ -411,27 +416,27 @@ func (m *Manager) backgroundMetricsFlush(ctx context.Context) {
writeRequestCountMetrics.Add(consumption.KvWriteRpcCount)
}

m.consumptionRecord[name] = time.Now()
m.consumptionRecord[consumptionRecordKey{name: name, ruType: ruLabelType}] = time.Now()

// TODO: maybe we need to distinguish background ru.
if rg := m.GetMutableResourceGroup(name); rg != nil {
rg.UpdateRUConsumption(consumptionInfo.Consumption)
}
case <-cleanUpTicker.C:
// Clean up the metrics that have not been updated for a long time.
for name, lastTime := range m.consumptionRecord {
for r, lastTime := range m.consumptionRecord {
if time.Since(lastTime) > metricsCleanupTimeout {
readRequestUnitCost.DeleteLabelValues(name, name)
writeRequestUnitCost.DeleteLabelValues(name, name)
sqlLayerRequestUnitCost.DeleteLabelValues(name, name)
readByteCost.DeleteLabelValues(name, name)
writeByteCost.DeleteLabelValues(name, name)
kvCPUCost.DeleteLabelValues(name, name)
sqlCPUCost.DeleteLabelValues(name, name)
requestCount.DeleteLabelValues(name, name, readTypeLabel)
requestCount.DeleteLabelValues(name, name, writeTypeLabel)
availableRUCounter.DeleteLabelValues(name, name)
delete(m.consumptionRecord, name)
readRequestUnitCost.DeleteLabelValues(r.name, r.name, r.ruType)
writeRequestUnitCost.DeleteLabelValues(r.name, r.name, r.ruType)
sqlLayerRequestUnitCost.DeleteLabelValues(r.name, r.name, r.ruType)
readByteCost.DeleteLabelValues(r.name, r.name, r.ruType)
writeByteCost.DeleteLabelValues(r.name, r.name, r.ruType)
kvCPUCost.DeleteLabelValues(r.name, r.name, r.ruType)
sqlCPUCost.DeleteLabelValues(r.name, r.name, r.ruType)
requestCount.DeleteLabelValues(r.name, r.name, readTypeLabel)
requestCount.DeleteLabelValues(r.name, r.name, writeTypeLabel)
availableRUCounter.DeleteLabelValues(r.name, r.name, r.ruType)
delete(m.consumptionRecord, r)
}
}
case <-availableRUTicker.C:
Expand Down

0 comments on commit 1d103f9

Please sign in to comment.