MCPcopy Create free account
hub / github.com/cortexproject/cortex / UpdateMetrics

Method UpdateMetrics

pkg/util/labelset/tracker.go:55–81  ·  view source on GitHub ↗

UpdateMetrics cleans up dangling user and label set from the tracker as well as metrics. It takes a function for user to customize the metrics cleanup logic when either a user or a specific label set is removed. If a user is removed then removeUser is set to true.

(userSet map[string]map[uint64]struct{}, deleteMetricFunc func(user, labelSetStr string, removeUser bool))

Source from the content-addressed store, hash-verified

53// It takes a function for user to customize the metrics cleanup logic when either a user or
54// a specific label set is removed. If a user is removed then removeUser is set to true.
55func (m *LabelSetTracker) UpdateMetrics(userSet map[string]map[uint64]struct{}, deleteMetricFunc func(user, labelSetStr string, removeUser bool)) {
56 for i := range numMetricShards {
57 shard := m.shards[i]
58 shard.Lock()
59
60 for user, userEntry := range shard.userLabelSets {
61 limits, ok := userSet[user]
62 // Remove user if it doesn't exist or has no limits anymore.
63 if !ok || len(limits) == 0 {
64 deleteMetricFunc(user, "", true)
65 delete(shard.userLabelSets, user)
66 continue
67 }
68 for h, lbls := range userEntry {
69 // This limit no longer exists.
70 if _, ok := limits[h]; !ok {
71 delete(userEntry, h)
72 labelSetStr := lbls.String()
73 deleteMetricFunc(user, labelSetStr, false)
74 continue
75 }
76 }
77 }
78
79 shard.Unlock()
80 }
81}
82
83// labelSetExists is used for testing only to check the existence of a label set.
84func (m *LabelSetTracker) labelSetExists(userId string, hash uint64, labelSet labels.Labels) bool {

Callers 4

TestLabelSetTrackerFunction · 0.95
updateLabelSetMetricsMethod · 0.45
UpdateLabelSetMethod · 0.45

Calls 1

StringMethod · 0.65

Tested by 2

TestLabelSetTrackerFunction · 0.76