we shouldn't assume we'll receive the labels in sorted order

This commit is contained in:
Callum Styan 2017-12-18 15:32:39 -08:00
parent 8326e410d0
commit bcde61b237
3 changed files with 8 additions and 9 deletions

View file

@ -23,6 +23,7 @@ import (
"path/filepath"
"runtime"
"runtime/pprof"
"sort"
"strings"
"sync"
"text/tabwriter"
@ -317,8 +318,6 @@ func readPrometheusLabels(r io.Reader, n int) ([]labels.Labels, error) {
for scanner.Scan() && i < n {
m := make(labels.Labels, 0, 10)
// Order of the k/v labels matters, so rather than decoding arbitrary json into an
// interface{}, parse the line ourselves and remove unnecessary characters.
r := strings.NewReplacer("\"", "", "{", "", "}", "")
s := r.Replace(scanner.Text())
@ -327,7 +326,8 @@ func readPrometheusLabels(r io.Reader, n int) ([]labels.Labels, error) {
split := strings.Split(labelChunk, ":")
m = append(m, labels.Label{Name: split[0], Value: split[1]})
}
// Order of the k/v labels matters, don't assume we'll always receive them already sorted.
sort.Sort(m)
h := m.Hash()
if _, ok := hashes[h]; ok {
continue

View file

@ -18,6 +18,7 @@ import (
"fmt"
"math/rand"
"os"
"sort"
"strings"
"testing"
@ -61,8 +62,6 @@ func readPrometheusLabels(fn string, n int) ([]labels.Labels, error) {
for scanner.Scan() && i < n {
m := make(labels.Labels, 0, 10)
// Order of the k/v labels matters, so rather than decoding arbitrary json into an
// interface{}, parse the line ourselves and remove unnecessary characters.
r := strings.NewReplacer("\"", "", "{", "", "}", "")
s := r.Replace(scanner.Text())
@ -72,7 +71,8 @@ func readPrometheusLabels(fn string, n int) ([]labels.Labels, error) {
fmt.Println("split: ", split)
m = append(m, labels.Label{Name: split[0], Value: split[1]})
}
// Order of the k/v labels matters, don't assume we'll always receive them already sorted.
sort.Sort(m)
h := m.Hash()
if _, ok := hashes[h]; ok {
continue

View file

@ -135,8 +135,6 @@ func readPrometheusLabels(fn string, n int) ([]Labels, error) {
for scanner.Scan() && i < n {
m := make(Labels, 0, 10)
// Order of the k/v labels matters, so rather than decoding arbitrary json into an
// interface{}, parse the line ourselves and remove unnecessary characters.
r := strings.NewReplacer("\"", "", "{", "", "}", "")
s := r.Replace(scanner.Text())
@ -145,7 +143,8 @@ func readPrometheusLabels(fn string, n int) ([]Labels, error) {
split := strings.Split(labelChunk, ":")
m = append(m, Label{Name: split[0], Value: split[1]})
}
// Order of the k/v labels matters, don't assume we'll always receive them already sorted.
sort.Sort(m)
h := m.Hash()
if _, ok := hashes[h]; ok {
continue