SSE: Threshold expression to use simple functions (#86062)

* replace math expression with predicates
This commit is contained in:
Yuri Tseretyan
2024-04-16 13:35:41 -04:00
committed by GitHub
parent 9c1ef8b16e
commit e9d6135e33
5 changed files with 414 additions and 112 deletions
+43
View File
@@ -2,9 +2,12 @@ package expr
import (
"context"
"time"
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana-plugin-sdk-go/data"
"github.com/grafana/grafana/pkg/expr/mathexp"
"github.com/grafana/grafana/pkg/services/auth/identity"
"github.com/grafana/grafana/pkg/services/datasources"
)
@@ -82,3 +85,43 @@ func (f *recordingCallResourceHandler) CallResource(_ context.Context, req *back
f.recordings = append(f.recordings, req)
return sender.Send(f.response)
}
func newScalar(value *float64) mathexp.Scalar {
n := mathexp.NewScalar("", value)
return n
}
func newNumber(labels data.Labels, value *float64) mathexp.Number {
n := mathexp.NewNumber("", labels)
n.SetValue(value)
return n
}
func newSeries(points ...float64) mathexp.Series {
series := mathexp.NewSeries("", nil, len(points))
for idx, point := range points {
p := point
series.SetPoint(idx, time.Unix(int64(idx), 0), &p)
}
return series
}
func newSeriesPointer(points ...*float64) mathexp.Series {
series := mathexp.NewSeries("", nil, len(points))
for idx, point := range points {
series.SetPoint(idx, time.Unix(int64(idx), 0), point)
}
return series
}
func newSeriesWithLabels(labels data.Labels, values ...*float64) mathexp.Series {
series := mathexp.NewSeries("", labels, len(values))
for idx, value := range values {
series.SetPoint(idx, time.Unix(int64(idx), 0), value)
}
return series
}
func newResults(values ...mathexp.Value) mathexp.Results {
return mathexp.Results{Values: values}
}