mirror of https://github.com/prometheus/prometheus
Replace labelsToKey() with metric Fingerprint (fixes grouping bug).
parent
7fefccd929
commit
42601acfde
|
@ -19,7 +19,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"hash/fnv"
|
"hash/fnv"
|
||||||
"math"
|
"math"
|
||||||
"sort"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
clientmodel "github.com/prometheus/client_golang/model"
|
clientmodel "github.com/prometheus/client_golang/model"
|
||||||
|
@ -382,27 +381,6 @@ func (node *VectorAggregation) labelsToGroupingKey(labels clientmodel.Metric) ui
|
||||||
return summer.Sum64()
|
return summer.Sum64()
|
||||||
}
|
}
|
||||||
|
|
||||||
func labelsToKey(labels clientmodel.Metric) uint64 {
|
|
||||||
pairs := metric.LabelPairs{}
|
|
||||||
|
|
||||||
for label, value := range labels {
|
|
||||||
pairs = append(pairs, &metric.LabelPair{
|
|
||||||
Name: label,
|
|
||||||
Value: value,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
sort.Sort(pairs)
|
|
||||||
|
|
||||||
summer := fnv.New64a()
|
|
||||||
|
|
||||||
for _, pair := range pairs {
|
|
||||||
fmt.Fprint(summer, pair.Name, pair.Value)
|
|
||||||
}
|
|
||||||
|
|
||||||
return summer.Sum64()
|
|
||||||
}
|
|
||||||
|
|
||||||
// EvalVectorInstant evaluates a VectorNode with an instant query.
|
// EvalVectorInstant evaluates a VectorNode with an instant query.
|
||||||
func EvalVectorInstant(node VectorNode, timestamp clientmodel.Timestamp, storage local.Storage, queryStats *stats.TimerGroup) (Vector, error) {
|
func EvalVectorInstant(node VectorNode, timestamp clientmodel.Timestamp, storage local.Storage, queryStats *stats.TimerGroup) (Vector, error) {
|
||||||
totalEvalTimer := queryStats.GetTimer(stats.TotalEvalTime).Start()
|
totalEvalTimer := queryStats.GetTimer(stats.TotalEvalTime).Start()
|
||||||
|
@ -436,7 +414,7 @@ func EvalVectorRange(node VectorNode, start clientmodel.Timestamp, end clientmod
|
||||||
defer closer.Close()
|
defer closer.Close()
|
||||||
|
|
||||||
evalTimer := queryStats.GetTimer(stats.InnerEvalTime).Start()
|
evalTimer := queryStats.GetTimer(stats.InnerEvalTime).Start()
|
||||||
sampleStreams := map[uint64]*SampleStream{}
|
sampleStreams := map[clientmodel.Fingerprint]*SampleStream{}
|
||||||
for t := start; !t.After(end); t = t.Add(interval) {
|
for t := start; !t.After(end); t = t.Add(interval) {
|
||||||
if et := totalEvalTimer.ElapsedTime(); et > *queryTimeout {
|
if et := totalEvalTimer.ElapsedTime(); et > *queryTimeout {
|
||||||
evalTimer.Stop()
|
evalTimer.Stop()
|
||||||
|
@ -448,14 +426,14 @@ func EvalVectorRange(node VectorNode, start clientmodel.Timestamp, end clientmod
|
||||||
Value: sample.Value,
|
Value: sample.Value,
|
||||||
Timestamp: sample.Timestamp,
|
Timestamp: sample.Timestamp,
|
||||||
}
|
}
|
||||||
groupingKey := labelsToKey(sample.Metric.Metric)
|
fp := sample.Metric.Metric.Fingerprint()
|
||||||
if sampleStreams[groupingKey] == nil {
|
if sampleStreams[fp] == nil {
|
||||||
sampleStreams[groupingKey] = &SampleStream{
|
sampleStreams[fp] = &SampleStream{
|
||||||
Metric: sample.Metric,
|
Metric: sample.Metric,
|
||||||
Values: metric.Values{samplePair},
|
Values: metric.Values{samplePair},
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sampleStreams[groupingKey].Values = append(sampleStreams[groupingKey].Values, samplePair)
|
sampleStreams[fp].Values = append(sampleStreams[fp].Values, samplePair)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -860,6 +860,70 @@ func TestRangedEvaluationRegressions(t *testing.T) {
|
||||||
},
|
},
|
||||||
expr: "sum(testmetric) keeping_extra",
|
expr: "sum(testmetric) keeping_extra",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
// Testing metric fingerprint grouping behavior.
|
||||||
|
in: ast.Matrix{
|
||||||
|
{
|
||||||
|
Metric: clientmodel.COWMetric{
|
||||||
|
Metric: clientmodel.Metric{
|
||||||
|
clientmodel.MetricNameLabel: "testmetric",
|
||||||
|
"aa": "bb",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Values: metric.Values{
|
||||||
|
{
|
||||||
|
Timestamp: testStartTime,
|
||||||
|
Value: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Metric: clientmodel.COWMetric{
|
||||||
|
Metric: clientmodel.Metric{
|
||||||
|
clientmodel.MetricNameLabel: "testmetric",
|
||||||
|
"a": "abb",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Values: metric.Values{
|
||||||
|
{
|
||||||
|
Timestamp: testStartTime,
|
||||||
|
Value: 2,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
out: ast.Matrix{
|
||||||
|
{
|
||||||
|
Metric: clientmodel.COWMetric{
|
||||||
|
Metric: clientmodel.Metric{
|
||||||
|
clientmodel.MetricNameLabel: "testmetric",
|
||||||
|
"aa": "bb",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Values: metric.Values{
|
||||||
|
{
|
||||||
|
Timestamp: testStartTime,
|
||||||
|
Value: 1,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Metric: clientmodel.COWMetric{
|
||||||
|
Metric: clientmodel.Metric{
|
||||||
|
clientmodel.MetricNameLabel: "testmetric",
|
||||||
|
"a": "abb",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Values: metric.Values{
|
||||||
|
{
|
||||||
|
Timestamp: testStartTime,
|
||||||
|
Value: 2,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expr: "testmetric",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, s := range scenarios {
|
for i, s := range scenarios {
|
||||||
|
|
Loading…
Reference in New Issue