Fix aggregation grouping key calculation.

This commit is contained in:
Julius Volz 2015-02-21 14:05:50 +01:00
parent 79834edcb5
commit 645cf57bed
3 changed files with 32 additions and 0 deletions

View file

@ -376,6 +376,7 @@ func (node *VectorAggregation) labelsToGroupingKey(labels clientmodel.Metric) ui
summer := fnv.New64a()
for _, label := range node.groupBy {
fmt.Fprint(summer, labels[label])
fmt.Fprint(summer, []byte{0})
}
return summer.Sum64()

View file

@ -184,6 +184,27 @@ var testMatrix = ast.Matrix{
},
Values: append(getTestValueStream(0, 90, 10, testStartTime), getTestValueStream(0, 0, 10, testStartTime.Add(testSampleInterval*10))...),
},
// For label-key grouping regression test.
{
Metric: clientmodel.COWMetric{
Metric: clientmodel.Metric{
clientmodel.MetricNameLabel: "label_grouping_test",
"a": "aa",
"b": "bb",
},
},
Values: getTestValueStream(0, 100, 10, testStartTime),
},
{
Metric: clientmodel.COWMetric{
Metric: clientmodel.Metric{
clientmodel.MetricNameLabel: "label_grouping_test",
"a": "a",
"b": "abb",
},
},
Values: getTestValueStream(0, 200, 20, testStartTime),
},
}
var testVector = getTestVectorFromTestMatrix(testMatrix)

View file

@ -553,6 +553,8 @@ func TestExpressions(t *testing.T) {
`testcounter_reset_end => 0 @[%v]`,
`testcounter_reset_middle => 50 @[%v]`,
`x{y="testvalue"} => 100 @[%v]`,
`label_grouping_test{a="a", b="abb"} => 200 @[%v]`,
`label_grouping_test{a="aa", b="bb"} => 100 @[%v]`,
},
},
{
@ -641,6 +643,14 @@ func TestExpressions(t *testing.T) {
expr: `sum(http_requests) offset 5m`,
shouldFail: true,
},
// Regression test for missing separator byte in labelsToGroupingKey.
{
expr: `sum(label_grouping_test) by (a, b)`,
output: []string{
`{a="a", b="abb"} => 200 @[%v]`,
`{a="aa", b="bb"} => 100 @[%v]`,
},
},
}
storage, closer := newTestStorage(t)