Function
LabelsEqual
(a, b []*Stats_Metric_Label)
Source from the content-addressed store, hash-verified
| 1 | package proto |
| 2 | |
| 3 | func LabelsEqual(a, b []*Stats_Metric_Label) bool { |
| 4 | am := make(map[string]string, len(a)) |
| 5 | for _, lbl := range a { |
| 6 | v := lbl.GetValue() |
| 7 | if v == "" { |
| 8 | // Prometheus considers empty labels as equivalent to being absent |
| 9 | continue |
| 10 | } |
| 11 | am[lbl.GetName()] = lbl.GetValue() |
| 12 | } |
| 13 | lenB := 0 |
| 14 | for _, lbl := range b { |
| 15 | v := lbl.GetValue() |
| 16 | if v == "" { |
| 17 | // Prometheus considers empty labels as equivalent to being absent |
| 18 | continue |
| 19 | } |
| 20 | lenB++ |
| 21 | if am[lbl.GetName()] != v { |
| 22 | return false |
| 23 | } |
| 24 | } |
| 25 | return len(am) == lenB |
| 26 | } |