diff --git a/storage/remote/codec.go b/storage/remote/codec.go index e18901900..4ab881bf0 100644 --- a/storage/remote/codec.go +++ b/storage/remote/codec.go @@ -819,11 +819,6 @@ func labelsToLabelRefsProto(lbls labels.Labels, pool *lookupPool, buf []prompb.L func labelsToUint32Slice(lbls labels.Labels, symbolTable *rwSymbolTable, buf []uint32) []uint32 { result := buf[:0] - // ensure slice capacity - if cap(result)-len(result) < len(lbls)*2 { - result = append(make([]uint32, 0, len(lbls)*2), result...) - } - lbls.Range(func(l labels.Label) { result = append(result, symbolTable.Ref(l.Name)) result = append(result, symbolTable.Ref(l.Value)) @@ -832,7 +827,7 @@ func labelsToUint32Slice(lbls labels.Labels, symbolTable *rwSymbolTable, buf []u } func Uint32RefToLabels(symbols string, minLabels []uint32) labels.Labels { - ls := make(labels.Labels, 0, len(minLabels)/2) + ls := labels.NewScratchBuilder(len(minLabels) / 2) labelIdx := 0 for labelIdx < len(minLabels) { @@ -844,11 +839,11 @@ func Uint32RefToLabels(symbols string, minLabels []uint32) labels.Labels { offset, length = unpackRef(minLabels[labelIdx+1]) value := symbols[offset : offset+length] - ls = append(ls, labels.Label{Name: name, Value: value}) + ls.Add(name, value) labelIdx += 2 } - return ls + return ls.Labels() } // metricTypeToMetricTypeProto transforms a Prometheus metricType into prompb metricType. Since the former is a string we need to transform it to an enum.