cleanup; remove some unused functions

Signed-off-by: Callum Styan <callumstyan@gmail.com>
Signed-off-by: Nicolás Pazos <npazosmendez@gmail.com>
This commit is contained in:
Callum Styan 2023-11-20 16:51:53 -08:00 committed by Nicolás Pazos
parent ba53225efb
commit 766a12fb76
3 changed files with 0 additions and 183 deletions

View file

@ -796,37 +796,6 @@ func labelsToUint32Slice(lbls labels.Labels, symbolTable *rwSymbolTable, buf []u
return result
}
func labelsToUint64Slice(lbls labels.Labels, symbolTable *rwSymbolTable, buf []uint64) []uint64 {
result := buf[:0]
lbls.Range(func(l labels.Label) {
result = append(result, symbolTable.Ref64Packed(l.Name))
result = append(result, symbolTable.Ref64Packed(l.Value))
})
return result
}
func labelsToUint32Packed(lbls labels.Labels, symbolTable *rwSymbolTable, buf []uint32) []uint32 {
result := buf[:0]
lbls.Range(func(l labels.Label) {
result = append(result, symbolTable.Ref32Packed(l.Name))
result = append(result, symbolTable.Ref32Packed(l.Value))
})
return result
}
func labelsToByteSlice(lbls labels.Labels, symbolTable *rwSymbolTable, buf []byte) []byte {
result := buf[:0]
lbls.Range(func(l labels.Label) {
off, leng := symbolTable.Ref(l.Name)
result = binary.AppendUvarint(result, uint64(off))
result = binary.AppendUvarint(result, uint64(leng))
off, leng = symbolTable.Ref(l.Value)
result = binary.AppendUvarint(result, uint64(off))
result = binary.AppendUvarint(result, uint64(leng))
})
return result
}
func labelsToUint32SliceLen(lbls labels.Labels, symbolTable *rwSymbolTable, buf []uint32) []uint32 {
result := buf[:0]
lbls.Range(func(l labels.Label) {
@ -888,103 +857,6 @@ func Uint32RefToLabels(symbols string, minLabels []uint32) labels.Labels {
return ls.Labels()
}
func ByteSliceToLabels(symbols string, minLabels []byte) labels.Labels {
ls := labels.NewScratchBuilder(len(minLabels) / 2)
for len(minLabels) > 0 {
// todo, check for overflow?
offset, n := binary.Uvarint(minLabels)
//fmt.Println(:"offset")
minLabels = minLabels[n:]
length, n := binary.Uvarint(minLabels)
minLabels = minLabels[n:]
name := symbols[offset : offset+length]
// todo, check for overflow?
offset, n = binary.Uvarint(minLabels)
minLabels = minLabels[n:]
length, n = binary.Uvarint(minLabels)
minLabels = minLabels[n:]
value := symbols[offset : offset+length]
ls.Add(name, value)
}
// labelIdx := 0
// for labelIdx < len(minLabels) {
// // todo, check for overflow?
// offset := minLabels[labelIdx]
// labelIdx++
// length := minLabels[labelIdx]
// labelIdx++
// name := symbols[offset : offset+length]
// // todo, check for overflow?
// offset = minLabels[labelIdx]
// labelIdx++
// length = minLabels[labelIdx]
// labelIdx++
// value := symbols[offset : offset+length]
// ls.Add(name, value)
// }
return ls.Labels()
}
func ByteSliceToLabelsSymbolsByte(symbols []byte, minLabels []byte) labels.Labels {
ls := labels.NewScratchBuilder(len(minLabels) / 2)
for len(minLabels) > 0 {
// todo, check for overflow?
offset, n := binary.Uvarint(minLabels)
//fmt.Println(:"offset")
minLabels = minLabels[n:]
length, n := binary.Uvarint(minLabels)
minLabels = minLabels[n:]
name := symbols[offset : offset+length]
// todo, check for overflow?
offset, n = binary.Uvarint(minLabels)
minLabels = minLabels[n:]
length, n = binary.Uvarint(minLabels)
minLabels = minLabels[n:]
value := symbols[offset : offset+length]
ls.Add(string(name), string(value))
}
// labelIdx := 0
// for labelIdx < len(minLabels) {
// // todo, check for overflow?
// offset := minLabels[labelIdx]
// labelIdx++
// length := minLabels[labelIdx]
// labelIdx++
// name := symbols[offset : offset+length]
// // todo, check for overflow?
// offset = minLabels[labelIdx]
// labelIdx++
// length = minLabels[labelIdx]
// labelIdx++
// value := symbols[offset : offset+length]
// ls.Add(name, value)
// }
return ls.Labels()
}
func Uint64RefToLabels(symbols string, minLabels []uint64) labels.Labels {
ls := labels.NewScratchBuilder(len(minLabels) / 2)
labelIdx := 0
for labelIdx < len(minLabels) {
// todo, check for overflow?
offset, length := unpackRef64(minLabels[labelIdx])
name := symbols[offset : offset+length]
// todo, check for overflow?
offset, length = unpackRef64(minLabels[labelIdx+1])
value := symbols[offset : offset+length]
ls.Add(name, value)
labelIdx += 2
}
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.
func metricTypeToMetricTypeProto(t textparse.MetricType) prompb.MetricMetadata_MetricType {
mt := strings.ToUpper(string(t))
@ -1138,21 +1010,3 @@ func MinimizedWriteRequestToWriteRequest(redReq *prompb.MinimizedWriteRequest) (
}
return req, nil
}
// for use with minimized remote write proto format
func packRef(offset, length int) uint32 {
return uint32((offset&0xFFFFF)<<12 | (length & 0xFFF))
}
func unpackRef(ref uint32) (offset, length int) {
return int(ref>>12) & 0xFFFFF, int(ref & 0xFFF)
}
// for use with minimized remote write proto format
func packRef64(offset, length uint32) uint64 {
return (uint64(offset) << 32) | uint64(length)
}
func unpackRef64(ref uint64) (offset, length uint32) {
return uint32(ref >> 32), uint32(ref & 0xFFFFFFFF)
}

View file

@ -887,19 +887,6 @@ func (c *mockChunkIterator) Err() error {
return nil
}
func TestPackRef64(t *testing.T) {
rw := newRwSymbolTable()
name := "__name__"
value := "asdfasd"
nameRef := rw.Ref64Packed(name)
valRef := rw.Ref64Packed(value)
nameOffset, nameLength := unpackRef64(nameRef)
valOffset, valLength := unpackRef64(valRef)
require.Equal(t, name, string(rw.symbols[nameOffset:nameOffset+nameLength]))
require.Equal(t, value, string(rw.symbols[valOffset:valOffset+valLength]))
}
func TestLenFormat(t *testing.T) {
r := rwSymbolTable{}
ls := labels.FromStrings("asdf", "qwer", "zxcv", "1234")

View file

@ -1857,30 +1857,6 @@ func (r *rwSymbolTable) Ref(str string) (off uint32, leng uint32) {
return
}
func (r *rwSymbolTable) Ref64Packed(str string) uint64 {
// todo, check for overflowing the uint32 based on documented format?
if ref, ok := r.symbolsMap64Packed[str]; ok {
return ref
}
if len(r.symbols) > math.MaxUint32 || len(str) > math.MaxUint32 || len(str)+len(r.symbols) > math.MaxUint32 {
panic(1)
}
r.symbolsMap64Packed[str] = packRef64(uint32(len(r.symbols)), uint32(len(str)))
r.symbols = append(r.symbols, str...)
return r.symbolsMap64Packed[str]
}
func (r *rwSymbolTable) Ref32Packed(str string) uint32 {
// todo, check for overflowing the uint32 based on documented format?
if ref, ok := r.symbolsMap32Packed[str]; ok {
return ref
}
r.symbolsMap32Packed[str] = packRef(len(r.symbols), len(str))
r.symbols = append(r.symbols, str...)
return r.symbolsMap32Packed[str]
}
func (r *rwSymbolTable) RefLen(str string) uint32 {
if ref, ok := r.symbolsMapBytes[str]; ok {
return ref