mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Dataframe/Alerting: to tsdb.TimeSeriesSlice - accept "empty" time series (#26903)
this is in order to trigger no data when used with alerting. fixes #26897. This is perhaps better solved in the SDK but that needs more thought and is tracked in grafana/grafana-plugin-sdk-go#214
This commit is contained in:
@@ -44,6 +44,14 @@ func convertTSDBTimePoint(point TimePoint) (t *time.Time, f *float64) {
|
||||
func FrameToSeriesSlice(frame *data.Frame) (TimeSeriesSlice, error) {
|
||||
tsSchema := frame.TimeSeriesSchema()
|
||||
if tsSchema.Type == data.TimeSeriesTypeNot {
|
||||
// If no fields, or only a time field, create an empty TimeSeriesSlice with a single
|
||||
// time series in order to trigger "no data" in alerting.
|
||||
if len(frame.Fields) == 0 || (len(frame.Fields) == 1 && frame.Fields[0].Type().Time()) {
|
||||
return TimeSeriesSlice{{
|
||||
Name: frame.Name,
|
||||
Points: make(TimeSeriesPoints, 0),
|
||||
}}, nil
|
||||
}
|
||||
return nil, fmt.Errorf("input frame is not recognized as a time series")
|
||||
}
|
||||
// If Long, make wide
|
||||
|
||||
Reference in New Issue
Block a user