GetKeyToID returns a snapshot of all labels as string-based LabelKey map. This is an infrequent operation (debug, full assembly); it converts internal IDLabelKey back to LabelKey using reverse lookups.
()
| 100 | // This is an infrequent operation (debug, full assembly); it converts |
| 101 | // internal IDLabelKey back to LabelKey using reverse lookups. |
| 102 | func (l *label) GetKeyToID() map[LabelKey]int { |
| 103 | active := l.getActive() |
| 104 | |
| 105 | l.mu.RLock() |
| 106 | pendingLen := len(l.pending) |
| 107 | merged := make(map[IDLabelKey]int, len(active)+pendingLen) |
| 108 | for k, v := range active { |
| 109 | merged[k] = v |
| 110 | } |
| 111 | for k, v := range l.pending { |
| 112 | merged[k] = v |
| 113 | } |
| 114 | l.mu.RUnlock() |
| 115 | |
| 116 | result := make(map[LabelKey]int, len(merged)) |
| 117 | for idk, id := range merged { |
| 118 | name, ok1 := l.labelName.GetNameByID(idk.NameID) |
| 119 | value, ok2 := l.labelValue.GetValueByID(idk.ValueID) |
| 120 | if ok1 && ok2 { |
| 121 | result[NewLabelKey(name, value)] = id |
| 122 | } |
| 123 | } |
| 124 | return result |
| 125 | } |
| 126 | |
| 127 | func (l *label) GetIDByKey(key LabelKey) (int, bool) { |
| 128 | idk, ok := l.toIDKey(key) |