WIP: Spawn backend plugins v2 (#19835)
* WIP: Spawn backend plugins v2 * Add test for plugin version * Fix support for SDK plugins Co-authored-by: Kyle Brandt <kyle@kbrandt.com> Co-authored-by: Marcus Olsson <olsson.e.marcus@gmail.com> Co-authored-by: Marcus Efraimsson <marcus.efraimsson@gmail.com> * WIP: Draft PR for fork of V2 sdk / bi-directional support (#19890) * temporary use export-datasource-plugin branch of grafana-plugin-sdk * fix failing test * remove debug (spew) lines * misc cleanup * add expressions feature toggle * use latest grafana-plugin-sdk-go
This commit is contained in:
committed by
Marcus Efraimsson
co-authored by
Kyle Brandt
Marcus Olsson
Marcus Efraimsson
parent
b0198e7c9c
commit
fc08c26025
@@ -0,0 +1,37 @@
|
||||
package tsdb
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/dataframe"
|
||||
)
|
||||
|
||||
// SeriesToFrame converts a TimeSeries to a sdk Frame
|
||||
func SeriesToFrame(series *TimeSeries) (*dataframe.Frame, error) {
|
||||
timeVec := make([]*time.Time, len(series.Points))
|
||||
floatVec := make([]*float64, len(series.Points))
|
||||
for idx, point := range series.Points {
|
||||
timeVec[idx], floatVec[idx] = convertTSDBTimePoint(point)
|
||||
}
|
||||
frame := dataframe.New(series.Name, dataframe.Labels(series.Tags),
|
||||
dataframe.NewField("time", dataframe.FieldTypeTime, timeVec),
|
||||
dataframe.NewField("value", dataframe.FieldTypeNumber, floatVec),
|
||||
)
|
||||
|
||||
return frame, nil
|
||||
}
|
||||
|
||||
// convertTSDBTimePoint coverts a tsdb.TimePoint into two values appropriate
|
||||
// for Series values.
|
||||
func convertTSDBTimePoint(point TimePoint) (t *time.Time, f *float64) {
|
||||
timeIdx, valueIdx := 1, 0
|
||||
if point[timeIdx].Valid { // Assuming valid is null?
|
||||
tI := int64(point[timeIdx].Float64)
|
||||
uT := time.Unix(tI/int64(1e+3), (tI%int64(1e+3))*int64(1e+6)) // time.Time from millisecond unix ts
|
||||
t = &uT
|
||||
}
|
||||
if point[valueIdx].Valid {
|
||||
f = &point[valueIdx].Float64
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -32,6 +32,7 @@ type QueryResult struct {
|
||||
Meta *simplejson.Json `json:"meta,omitempty"`
|
||||
Series TimeSeriesSlice `json:"series"`
|
||||
Tables []*Table `json:"tables"`
|
||||
Dataframes [][]byte `json:"dataframes"`
|
||||
}
|
||||
|
||||
type TimeSeries struct {
|
||||
|
||||
Reference in New Issue
Block a user