Browse Source

Fix aggregation grouping key calculation.

pull/546/head
Julius Volz 10 years ago
parent
commit
645cf57bed
  1. 1
      rules/ast/ast.go
  2. 21
      rules/helpers_test.go
  3. 10
      rules/rules_test.go

1
rules/ast/ast.go

@ -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()

21
rules/helpers_test.go

@ -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)

10
rules/rules_test.go

@ -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)

Loading…
Cancel
Save