mirror of
https://github.com/prometheus/prometheus
synced 2024-12-24 23:42:32 +00:00
labels: make sure estimated size is not negative
Deleted labels are remembered, even if they were not in `base` or were removed from `add`, so `base+add-del` could go negative. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
parent
b987afa7ef
commit
e917202766
@ -577,7 +577,11 @@ func (b *Builder) Labels() Labels {
|
||||
return b.base
|
||||
}
|
||||
|
||||
res := make(Labels, 0, len(b.base)-len(b.del)+len(b.add))
|
||||
expectedSize := len(b.base) + len(b.add) - len(b.del)
|
||||
if expectedSize < 1 {
|
||||
expectedSize = 1
|
||||
}
|
||||
res := make(Labels, 0, expectedSize)
|
||||
for _, l := range b.base {
|
||||
if slices.Contains(b.del, l.Name) || contains(b.add, l.Name) {
|
||||
continue
|
||||
|
Loading…
Reference in New Issue
Block a user