Browse Source

promql: Support histogram in value string representation

Signed-off-by: beorn7 <beorn@grafana.com>
pull/9759/head
beorn7 3 years ago
parent
commit
9b30ca2598
  1. 5
      promql/engine_test.go
  2. 10
      promql/value.go
  3. 12
      storage/memoized_iterator.go

5
promql/engine_test.go

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

10
promql/value.go

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

12
storage/memoized_iterator.go

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

Loading…
Cancel
Save