promql: Support histogram in value string representation

Signed-off-by: beorn7 <beorn@grafana.com>
This commit is contained in:
beorn7 2021-11-15 20:36:44 +01:00
parent 4c28d9fac7
commit 9b30ca2598
3 changed files with 25 additions and 8 deletions

View file

@ -2455,10 +2455,11 @@ func TestSparseHistogramRate(t *testing.T) {
require.NoError(t, test.Run())
engine := test.QueryEngine()
queryString := fmt.Sprintf("rate(%s[1m])", seriesName)
//queryString := fmt.Sprintf("rate(%s[1m])", seriesName)
queryString := fmt.Sprintf("%s", seriesName)
qry, err := engine.NewInstantQuery(test.Queryable(), queryString, timestamp.Time(int64(5*time.Minute/time.Millisecond)))
require.NoError(t, err)
res := qry.Exec(test.Context())
require.NoError(t, res.Err)
// fmt.Println(res)
fmt.Println(res)
}

View file

@ -87,9 +87,13 @@ type Point struct {
}
func (p Point) String() string {
// TODO(beorn7): Support Histogram.
v := strconv.FormatFloat(p.V, 'f', -1, 64)
return fmt.Sprintf("%v @[%v]", v, p.T)
var s string
if p.H != nil {
s = p.H.String()
} else {
s = strconv.FormatFloat(p.V, 'f', -1, 64)
}
return fmt.Sprintf("%s @[%v]", s, p.T)
}
// MarshalJSON implements json.Marshaler.

View file

@ -80,8 +80,12 @@ func (b *MemoizedSeriesIterator) Seek(t int64) bool {
if !b.ok {
return false
}
if b.it.ChunkEncoding() == chunkenc.EncHistogram {
b.lastTime, _ = b.it.AtHistogram()
} else {
b.lastTime, _ = b.it.At()
}
}
if b.lastTime >= t {
return true
@ -102,12 +106,20 @@ func (b *MemoizedSeriesIterator) Next() bool {
}
// Keep track of the previous element.
if b.it.ChunkEncoding() == chunkenc.EncHistogram {
b.prevTime, b.prev
} else {
b.prevTime, b.prevValue = b.it.At()
}
b.ok = b.it.Next()
if b.ok {
if b.it.ChunkEncoding() == chunkenc.EncHistogram {
b.lastTime, _ = b.it.AtHistogram()
} else {
b.lastTime, _ = b.it.At()
}
}
return b.ok
}