mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
SSE/Alerting: Support prom instant vector responses (#44865)
* SSE/Alerting: (Draft) Support prom instant vector responses fixes #35663 * reduce\classic expressions to handle mathexp.Number * use Notice for warning Co-authored-by: Yuriy Tseretyan <yuriy.tseretyan@grafana.com>
This commit is contained in:
@@ -100,6 +100,11 @@ func GetReduceFunc(rFunc string) (ReducerFunc, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// GetSupportedReduceFuncs returns collection of supported function names
|
||||
func GetSupportedReduceFuncs() []string {
|
||||
return []string{"sum", "mean", "min", "max", "count", "last"}
|
||||
}
|
||||
|
||||
// Reduce turns the Series into a Number based on the given reduction function
|
||||
// if ReduceMapper is defined it applies it to the provided series and performs reduction of the resulting series.
|
||||
// Otherwise, the reduction operation is done against the original series.
|
||||
|
||||
18
pkg/expr/mathexp/testing.go
Normal file
18
pkg/expr/mathexp/testing.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package mathexp
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
|
||||
"github.com/grafana/grafana/pkg/util"
|
||||
)
|
||||
|
||||
func GenerateNumber(value *float64) Number {
|
||||
size := rand.Intn(5)
|
||||
labels := make(map[string]string, size)
|
||||
for i := 0; i < size; i++ {
|
||||
labels[util.GenerateShortUID()] = util.GenerateShortUID()
|
||||
}
|
||||
result := NewNumber(util.GenerateShortUID(), labels)
|
||||
result.SetValue(value)
|
||||
return result
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/data"
|
||||
|
||||
"github.com/grafana/grafana/pkg/expr/mathexp/parse"
|
||||
)
|
||||
|
||||
@@ -154,7 +155,21 @@ func (s Series) GetMeta() interface{} {
|
||||
}
|
||||
|
||||
func (s Series) SetMeta(v interface{}) {
|
||||
s.Frame.SetMeta(&data.FrameMeta{Custom: v})
|
||||
m := s.Frame.Meta
|
||||
if m == nil {
|
||||
m = &data.FrameMeta{}
|
||||
s.Frame.SetMeta(m)
|
||||
}
|
||||
m.Custom = v
|
||||
}
|
||||
|
||||
func (s Series) AddNotice(notice data.Notice) {
|
||||
m := s.Frame.Meta
|
||||
if m == nil {
|
||||
m = &data.FrameMeta{}
|
||||
s.Frame.SetMeta(m)
|
||||
}
|
||||
m.Notices = append(m.Notices, notice)
|
||||
}
|
||||
|
||||
// AsDataFrame returns the underlying *data.Frame.
|
||||
|
||||
@@ -2,6 +2,7 @@ package mathexp
|
||||
|
||||
import (
|
||||
"github.com/grafana/grafana-plugin-sdk-go/data"
|
||||
|
||||
"github.com/grafana/grafana/pkg/expr/mathexp/parse"
|
||||
)
|
||||
|
||||
@@ -33,6 +34,7 @@ type Value interface {
|
||||
GetMeta() interface{}
|
||||
SetMeta(interface{})
|
||||
AsDataFrame() *data.Frame
|
||||
AddNotice(notice data.Notice)
|
||||
}
|
||||
|
||||
// Scalar is the type that holds a single number constant.
|
||||
@@ -55,7 +57,21 @@ func (s Scalar) GetMeta() interface{} {
|
||||
}
|
||||
|
||||
func (s Scalar) SetMeta(v interface{}) {
|
||||
s.Frame.SetMeta(&data.FrameMeta{Custom: v})
|
||||
m := s.Frame.Meta
|
||||
if m == nil {
|
||||
m = &data.FrameMeta{}
|
||||
s.Frame.SetMeta(m)
|
||||
}
|
||||
m.Custom = v
|
||||
}
|
||||
|
||||
func (s Scalar) AddNotice(notice data.Notice) {
|
||||
m := s.Frame.Meta
|
||||
if m == nil {
|
||||
m = &data.FrameMeta{}
|
||||
s.Frame.SetMeta(m)
|
||||
}
|
||||
m.Notices = append(m.Notices, notice)
|
||||
}
|
||||
|
||||
// AsDataFrame returns the underlying *data.Frame.
|
||||
@@ -121,7 +137,21 @@ func (n Number) GetMeta() interface{} {
|
||||
}
|
||||
|
||||
func (n Number) SetMeta(v interface{}) {
|
||||
n.Frame.SetMeta(&data.FrameMeta{Custom: v})
|
||||
m := n.Frame.Meta
|
||||
if m == nil {
|
||||
m = &data.FrameMeta{}
|
||||
n.Frame.SetMeta(m)
|
||||
}
|
||||
m.Custom = v
|
||||
}
|
||||
|
||||
func (n Number) AddNotice(notice data.Notice) {
|
||||
m := n.Frame.Meta
|
||||
if m == nil {
|
||||
m = &data.FrameMeta{}
|
||||
n.Frame.SetMeta(m)
|
||||
}
|
||||
m.Notices = append(m.Notices, notice)
|
||||
}
|
||||
|
||||
// FloatField is a *float64 or a float64 data.Field with methods to always
|
||||
|
||||
Reference in New Issue
Block a user