Skip to content

Commit

Permalink
Dataplane: Enable dataplane for results of LongToWide (#1057)
Browse files Browse the repository at this point in the history
* Dataplane: Enable dataplane for results of LongToWide by setting FrameTypeVersion{0, 1} on the results of LongToWide
* SSE and Recorded Queries will use a different code path for this, but the behavior should be identical.
* If consumers of this function (mainly SQL data sources) find that they need to undo this behavior for some reason, then they can set the frameTypeVersion to {0, 0} on the resulting frame, since this is the only change (e.g. `myWideFrame.Meta.TypeVersion = FrameTypeVersion{0, 0}`)
  • Loading branch information
kylebrandt authored Aug 26, 2024
1 parent 7470982 commit 96b9aa7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 14 deletions.
5 changes: 5 additions & 0 deletions data/time_series.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,11 @@ func LongToWide(longFrame *Frame, fillMissing *FillMissing) (*Frame, error) {
wideFrame.Meta = &FrameMeta{}
}
wideFrame.Meta.Type = FrameTypeTimeSeriesWide

// Setting the TypeVersion to greater than [0, 0] (along with Meta.Type being set) indicates that the produced
// frame follows the dataplane contract (see https://grafana.com/developers/dataplane/ and https://github.com/grafana/dataplane).
// https://grafana.com/developers/dataplane/timeseries#time-series-wide-format-timeserieswide defines TimeSeriesWide in dataplane.
wideFrame.Meta.TypeVersion = FrameTypeVersion{0, 1}
return wideFrame, nil
}

Expand Down
44 changes: 30 additions & 14 deletions data/time_series_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ func TestTimeSeriesSchema(t *testing.T) {
}
}

var FTV01 = data.FrameTypeVersion{0, 1}

func TestLongToWide(t *testing.T) {
tests := []struct {
name string
Expand Down Expand Up @@ -121,7 +123,8 @@ func TestLongToWide(t *testing.T) {
2.0,
4.0,
})).SetMeta(&data.FrameMeta{
Type: data.FrameTypeTimeSeriesWide,
Type: data.FrameTypeTimeSeriesWide,
TypeVersion: FTV01,
}),
Err: require.NoError,
},
Expand Down Expand Up @@ -168,7 +171,8 @@ func TestLongToWide(t *testing.T) {
2.0,
4.0,
})).SetMeta(&data.FrameMeta{
Type: data.FrameTypeTimeSeriesWide,
Type: data.FrameTypeTimeSeriesWide,
TypeVersion: FTV01,
}),
Err: require.NoError,
},
Expand Down Expand Up @@ -221,7 +225,8 @@ func TestLongToWide(t *testing.T) {
2,
4,
})).SetMeta(&data.FrameMeta{
Type: data.FrameTypeTimeSeriesWide,
Type: data.FrameTypeTimeSeriesWide,
TypeVersion: FTV01,
}),
Err: require.NoError,
},
Expand Down Expand Up @@ -280,7 +285,8 @@ func TestLongToWide(t *testing.T) {
2,
4,
})).SetMeta(&data.FrameMeta{
Type: data.FrameTypeTimeSeriesWide,
Type: data.FrameTypeTimeSeriesWide,
TypeVersion: FTV01,
}),
Err: require.NoError,
},
Expand Down Expand Up @@ -319,7 +325,8 @@ func TestLongToWide(t *testing.T) {
float64Ptr(2.0),
float64Ptr(4.0),
})).SetMeta(&data.FrameMeta{
Type: data.FrameTypeTimeSeriesWide,
Type: data.FrameTypeTimeSeriesWide,
TypeVersion: FTV01,
}),
Err: require.NoError,
},
Expand Down Expand Up @@ -385,7 +392,8 @@ func TestLongToWide(t *testing.T) {
0.0,
6.0,
})).SetMeta(&data.FrameMeta{
Type: data.FrameTypeTimeSeriesWide,
Type: data.FrameTypeTimeSeriesWide,
TypeVersion: FTV01,
}),

Err: require.NoError,
Expand Down Expand Up @@ -452,7 +460,8 @@ func TestLongToWide(t *testing.T) {
nil,
float64Ptr(6.0),
})).SetMeta(&data.FrameMeta{
Type: data.FrameTypeTimeSeriesWide,
Type: data.FrameTypeTimeSeriesWide,
TypeVersion: FTV01,
}),
Err: require.NoError,
},
Expand Down Expand Up @@ -548,7 +557,8 @@ func TestLongToWide(t *testing.T) {
6,
}),
).SetMeta(&data.FrameMeta{
Type: data.FrameTypeTimeSeriesWide,
Type: data.FrameTypeTimeSeriesWide,
TypeVersion: FTV01,
}),
Err: require.NoError,
},
Expand Down Expand Up @@ -644,7 +654,8 @@ func TestLongToWide(t *testing.T) {
int64Ptr(6),
}),
).SetMeta(&data.FrameMeta{
Type: data.FrameTypeTimeSeriesWide,
Type: data.FrameTypeTimeSeriesWide,
TypeVersion: FTV01,
}),
Err: require.NoError,
},
Expand Down Expand Up @@ -740,7 +751,8 @@ func TestLongToWide(t *testing.T) {
int64Ptr(6),
}),
).SetMeta(&data.FrameMeta{
Type: data.FrameTypeTimeSeriesWide,
Type: data.FrameTypeTimeSeriesWide,
TypeVersion: FTV01,
}),
Err: require.NoError,
},
Expand Down Expand Up @@ -836,7 +848,8 @@ func TestLongToWide(t *testing.T) {
int64Ptr(6),
}),
).SetMeta(&data.FrameMeta{
Type: data.FrameTypeTimeSeriesWide,
Type: data.FrameTypeTimeSeriesWide,
TypeVersion: FTV01,
}),
Err: require.NoError,
},
Expand Down Expand Up @@ -931,7 +944,8 @@ func TestLongToWide(t *testing.T) {
int64Ptr(6),
}),
).SetMeta(&data.FrameMeta{
Type: data.FrameTypeTimeSeriesWide,
Type: data.FrameTypeTimeSeriesWide,
TypeVersion: FTV01,
}),
Err: require.NoError,
},
Expand Down Expand Up @@ -1026,7 +1040,8 @@ func TestLongToWide(t *testing.T) {
int64Ptr(6.0),
}),
).SetMeta(&data.FrameMeta{
Type: data.FrameTypeTimeSeriesWide,
Type: data.FrameTypeTimeSeriesWide,
TypeVersion: FTV01,
}),
Err: require.NoError,
},
Expand Down Expand Up @@ -1086,7 +1101,8 @@ func TestLongToWideBool(t *testing.T) {
1.0,
3.0,
})).SetMeta(&data.FrameMeta{
Type: data.FrameTypeTimeSeriesWide,
Type: data.FrameTypeTimeSeriesWide,
TypeVersion: FTV01,
}),
Err: require.NoError,
},
Expand Down

0 comments on commit 96b9aa7

Please sign in to comment.