Fix count() for histograms and add test case
Signed-off-by: Ganesh Vernekar <ganeshvern@gmail.com>
This commit is contained in:
parent
f540c1dbd3
commit
71489d0e3d
|
@ -2366,11 +2366,11 @@ func (ev *evaluator) aggregation(op parser.ItemType, grouping []string, without
|
||||||
mean: s.V,
|
mean: s.V,
|
||||||
groupCount: 1,
|
groupCount: 1,
|
||||||
}
|
}
|
||||||
if s.H != nil {
|
if s.H == nil {
|
||||||
|
newAgg.hasFloat = true
|
||||||
|
} else if op == parser.SUM {
|
||||||
newAgg.histogramValue = s.H.Copy()
|
newAgg.histogramValue = s.H.Copy()
|
||||||
newAgg.hasHistogram = true
|
newAgg.hasHistogram = true
|
||||||
} else {
|
|
||||||
newAgg.hasFloat = true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
result[groupingKey] = newAgg
|
result[groupingKey] = newAgg
|
||||||
|
|
|
@ -3886,7 +3886,7 @@ func TestSparseHistogram_HistogramFraction(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSparseHistogram_Sum_AddOperator(t *testing.T) {
|
func TestSparseHistogram_Sum_Count_AddOperator(t *testing.T) {
|
||||||
// TODO(codesome): Integrate histograms into the PromQL testing framework
|
// TODO(codesome): Integrate histograms into the PromQL testing framework
|
||||||
// and write more tests there.
|
// and write more tests there.
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
|
@ -3992,7 +3992,7 @@ func TestSparseHistogram_Sum_AddOperator(t *testing.T) {
|
||||||
}
|
}
|
||||||
require.NoError(t, app.Commit())
|
require.NoError(t, app.Commit())
|
||||||
|
|
||||||
queryAndCheck := func(queryString string) {
|
queryAndCheck := func(queryString string, exp Vector) {
|
||||||
qry, err := engine.NewInstantQuery(test.Queryable(), nil, queryString, timestamp.Time(ts))
|
qry, err := engine.NewInstantQuery(test.Queryable(), nil, queryString, timestamp.Time(ts))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
@ -4002,20 +4002,29 @@ func TestSparseHistogram_Sum_AddOperator(t *testing.T) {
|
||||||
vector, err := res.Vector()
|
vector, err := res.Vector()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
require.Len(t, vector, 1)
|
require.Equal(t, exp, vector)
|
||||||
require.Equal(t, &c.expected, vector[0].H)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// sum().
|
// sum().
|
||||||
queryString := fmt.Sprintf("sum(%s)", seriesName)
|
queryString := fmt.Sprintf("sum(%s)", seriesName)
|
||||||
queryAndCheck(queryString)
|
queryAndCheck(queryString, []Sample{
|
||||||
|
{Point{T: ts, H: &c.expected}, labels.Labels{}},
|
||||||
|
})
|
||||||
|
|
||||||
// + operator.
|
// + operator.
|
||||||
queryString = fmt.Sprintf(`%s{idx="0"}`, seriesName)
|
queryString = fmt.Sprintf(`%s{idx="0"}`, seriesName)
|
||||||
for idx := 1; idx < len(c.histograms); idx++ {
|
for idx := 1; idx < len(c.histograms); idx++ {
|
||||||
queryString += fmt.Sprintf(` + ignoring(idx) %s{idx="%d"}`, seriesName, idx)
|
queryString += fmt.Sprintf(` + ignoring(idx) %s{idx="%d"}`, seriesName, idx)
|
||||||
}
|
}
|
||||||
queryAndCheck(queryString)
|
queryAndCheck(queryString, []Sample{
|
||||||
|
{Point{T: ts, H: &c.expected}, labels.Labels{}},
|
||||||
|
})
|
||||||
|
|
||||||
|
// count().
|
||||||
|
queryString = fmt.Sprintf("count(%s)", seriesName)
|
||||||
|
queryAndCheck(queryString, []Sample{
|
||||||
|
{Point{T: ts, V: 3}, labels.Labels{}},
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue