mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-09 23:24:05 -08:00
we shouldn't assume we'll receive the labels in sorted order
This commit is contained in:
parent
8326e410d0
commit
bcde61b237
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue