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()) require.NoError(t, test.Run())
engine := test.QueryEngine() 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))) qry, err := engine.NewInstantQuery(test.Queryable(), queryString, timestamp.Time(int64(5*time.Minute/time.Millisecond)))
require.NoError(t, err) require.NoError(t, err)
res := qry.Exec(test.Context()) res := qry.Exec(test.Context())
require.NoError(t, res.Err) 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 { func (p Point) String() string {
// TODO(beorn7): Support Histogram. var s string
v := strconv.FormatFloat(p.V, 'f', -1, 64) if p.H != nil {
return fmt.Sprintf("%v @[%v]", v, p.T) 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. // MarshalJSON implements json.Marshaler.

View File

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