Skip to content

Commit

Permalink
Merge pull request #98 from fr-ser/frame-name
Browse files Browse the repository at this point in the history
Frame name
  • Loading branch information
fr-ser committed Sep 11, 2022
2 parents 1236941 + c1c19ed commit 1f259be
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 32 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

## [Unreleased]

## [3.1.1] - 2022-09-11

### Changed

- removed the "name" metadata from data frames

## [3.1.0] - 2022-07-09

### Changed
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ This is a list of common questions or problems. For the answers and more details

- [I have a "file not found" error for my database](https://github.com/fr-ser/grafana-sqlite-datasource/blob/master/docs/faq.md#i-have-a-file-not-found-error-for-my-database)
- [I have a "permission denied" error for my database](https://github.com/fr-ser/grafana-sqlite-datasource/blob/master/docs/faq.md#i-have-a-permission-denied-error-for-my-database)
- ...

## Query examples

Expand Down
9 changes: 9 additions & 0 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,12 @@ ProtectHome=false
systemctl daemon-reload
systemctl restart grafana-server
```

## The legend of my time series appears twice / is doubled

Sometimes (especially when displaying multiple lines in a time series chart) the legend (the information below the chart) can show the name of the column twice.
The legend can read "value value" or "temperature temperature".

This can be controlled through the field display name configuration.
There a hardcoded value can be set but the value can also be based on the "labels" of the search.
Some more information about setting the display name via labels can be found in the [Grafana documentation](https://grafana.com/docs/grafana/latest/panels/configure-standard-options/#display-name).
16 changes: 8 additions & 8 deletions pkg/plugin/gap_filling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestEpochGroupSecondsShouldBeReplacedInTheFinalQueryForTables(t *testing.T)
}

expectedFrame := data.NewFrame(
"response",
"",
data.NewField("window", nil, []*int64{intPointer(0), intPointer(10), intPointer(30)}),
data.NewField("value", nil, []*int64{intPointer(1), intPointer(2), intPointer(4)}),
)
Expand Down Expand Up @@ -75,7 +75,7 @@ func TestEpochGroupSecondsShouldFillInNullValuesForTables(t *testing.T) {
}

expectedFrame := data.NewFrame(
"response",
"",
data.NewField(
"window", nil, []*time.Time{
unixTimePointer(0),
Expand Down Expand Up @@ -121,7 +121,7 @@ func TestEpochGroupSecondsShouldFillInNullValuesForTimeSeriesWithDoubleGaps(t *t
}

expectedFrame := data.NewFrame(
"value",
"",
data.NewField(
"window",
nil,
Expand Down Expand Up @@ -178,7 +178,7 @@ func TestEpochGroupSecondsShouldFillInNullValuesWithMultipleTimeColumns(t *testi
}

expectedFrame := data.NewFrame(
"response",
"",
data.NewField("window", nil, []*time.Time{
unixTimePointer(0),
unixTimePointer(10),
Expand Down Expand Up @@ -229,7 +229,7 @@ func TestEpochGroupSecondsShouldBeReplacedInTheFinalQueryForTimeSeries(t *testin
}

expectedFrame := data.NewFrame(
"value",
"",
data.NewField("window", nil, []*time.Time{
timePointer(time.Unix(0, 0)),
timePointer(time.Unix(10, 0)),
Expand Down Expand Up @@ -275,7 +275,7 @@ func TestEpochGroupSecondsWithMultiFrameTimeseriesAndGaps(t *testing.T) {
}

expectedInputFrame := data.NewFrame(
"response",
"",
data.NewField("window", nil, []*time.Time{
unixTimePointer(10), unixTimePointer(20), unixTimePointer(30),
}),
Expand All @@ -300,7 +300,7 @@ func TestEpochGroupSecondsWithMultiFrameTimeseriesAndGaps(t *testing.T) {

expectedOutputFrames := make([]*data.Frame, 2)
expectedOutputFrames[0] = data.NewFrame(
"value one",
"",
data.NewField("window", nil, []time.Time{
time.Unix(10, 0), time.Unix(20, 0), time.Unix(30, 0)},
),
Expand All @@ -314,7 +314,7 @@ func TestEpochGroupSecondsWithMultiFrameTimeseriesAndGaps(t *testing.T) {
expectedOutputFrames[0].Meta = response.Frames[0].Meta

expectedOutputFrames[1] = data.NewFrame(
"value two",
"",
data.NewField("window", nil, []time.Time{
time.Unix(10, 0), time.Unix(20, 0), time.Unix(30, 0)},
),
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugin/json_support_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestJsonSupport(t *testing.T) {
}

expectedFrame := data.NewFrame(
"response",
"",
data.NewField("value", nil, []*int64{intPointer(4)}),
)
expectedFrame.Meta = &data.FrameMeta{ExecutedQueryString: baseQuery}
Expand Down
5 changes: 2 additions & 3 deletions pkg/plugin/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ func query(dataQuery backend.DataQuery, config pluginConfig) (response backend.D
}
log.DefaultLogger.Debug("Fetched data from database")

frame := data.NewFrame("response")
frame := data.NewFrame("")
frame.Meta = &data.FrameMeta{ExecutedQueryString: queryConfig.FinalQuery}

if queryConfig.ShouldFillValues {
Expand Down Expand Up @@ -448,8 +448,7 @@ func query(dataQuery backend.DataQuery, config pluginConfig) (response backend.D
if idx == tsSchema.TimeIndex {
continue
}
partialFrame := data.NewFrame(
strings.Trim(fmt.Sprintf("%s %s", field.Name, field.Labels["name"]), " "),
partialFrame := data.NewFrame("",
frame.Fields[tsSchema.TimeIndex],
field,
)
Expand Down
10 changes: 5 additions & 5 deletions pkg/plugin/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func TestEmptyQuery(t *testing.T) {
)
}

expectedFrame := data.NewFrame("response")
expectedFrame := data.NewFrame("")
expectedFrame.Meta = &data.FrameMeta{ExecutedQueryString: "-- not a query"}

if diff := cmp.Diff(expectedFrame, response.Frames[0], cmpOption...); diff != "" {
Expand Down Expand Up @@ -100,7 +100,7 @@ func TestNoResultsTable(t *testing.T) {
}

expectedFrame := data.NewFrame(
"response",
"",
data.NewField("time", nil, []*int64{}),
data.NewField("value", nil, []*float64{}),
data.NewField("name", nil, []*string{}),
Expand All @@ -116,7 +116,7 @@ func TestNoResultsTimeSeriesWithUnknownColumns(t *testing.T) {
var longToWideCalled bool
mockableLongToWide = func(a *data.Frame, b *data.FillMissing) (*data.Frame, error) {
longToWideCalled = true
return data.NewFrame("response"), nil
return data.NewFrame(""), nil
}

dbPath, cleanup := createTmpDB(`SELECT 1`)
Expand Down Expand Up @@ -144,7 +144,7 @@ func TestNoResultsTimeSeriesWithUnknownColumns(t *testing.T) {
}

expectedFrame := data.NewFrame(
"value",
"",
data.NewField("time", nil, []*time.Time{}),
data.NewField("value", nil, []*float64{}),
)
Expand Down Expand Up @@ -189,7 +189,7 @@ func TestReplaceToAndFromVariables(t *testing.T) {
}

expectedFrame := data.NewFrame(
"response",
"",
data.NewField("a", nil, []*int64{intPointer(123000)}),
data.NewField("b", nil, []*int64{intPointer(456000)}),
)
Expand Down
6 changes: 3 additions & 3 deletions pkg/plugin/query_time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestQueryWithTimeColumn(t *testing.T) {
}

expectedFrame := data.NewFrame(
"response",
"",
data.NewField("time", nil, []*time.Time{
timePointer(time.Unix(21, 0)),
timePointer(time.Unix(22, 300000000)),
Expand Down Expand Up @@ -79,7 +79,7 @@ func TestQueryWithTimeStringColumn(t *testing.T) {
}

expectedFrame := data.NewFrame(
"response",
"",
data.NewField("time", nil, []*time.Time{
timePointer(time.Unix(21, 0)),
timePointer(time.Unix(22, 300000000)),
Expand Down Expand Up @@ -124,7 +124,7 @@ func TestUnixTimestampAsString(t *testing.T) {
}

expectedFrame := data.NewFrame(
"response",
"",
data.NewField("time", nil, []*time.Time{
timePointer(time.Unix(21, 0)),
timePointer(time.Unix(22, 300000000)),
Expand Down
14 changes: 7 additions & 7 deletions pkg/plugin/query_timeseries_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestIgnoreNonTimeSeriesQuery(t *testing.T) {
var longToWideCalled bool
mockableLongToWide = func(a *data.Frame, b *data.FillMissing) (*data.Frame, error) {
longToWideCalled = true
return data.NewFrame("response"), nil
return data.NewFrame(""), nil
}

dbPath, cleanup := createTmpDB(`
Expand Down Expand Up @@ -44,7 +44,7 @@ func TestIgnoreNonTimeSeriesQuery(t *testing.T) {
}

expectedFrame := data.NewFrame(
"response",
"",
data.NewField("time", nil, []*time.Time{
timePointer(time.Unix(21, 0)),
timePointer(time.Unix(22, 0)),
Expand All @@ -68,7 +68,7 @@ func TestIgnoreWideTimeSeriesQuery(t *testing.T) {
var longToWideCalled bool
mockableLongToWide = func(a *data.Frame, b *data.FillMissing) (*data.Frame, error) {
longToWideCalled = true
return data.NewFrame("response"), nil
return data.NewFrame(""), nil
}

dbPath, cleanup := createTmpDB(`
Expand Down Expand Up @@ -99,7 +99,7 @@ func TestIgnoreWideTimeSeriesQuery(t *testing.T) {
}

expectedFrame := data.NewFrame(
"value",
"",
data.NewField("time", nil, []*time.Time{
timePointer(time.Unix(21, 0)),
timePointer(time.Unix(22, 0)),
Expand Down Expand Up @@ -141,7 +141,7 @@ func TestConvertLongTimeSeriesQuery(t *testing.T) {
}

expectedInputFrame := data.NewFrame(
"response",
"",
data.NewField("time", nil, []*time.Time{
timePointer(time.Unix(21, 0)), timePointer(time.Unix(22, 0)),
}),
Expand All @@ -165,7 +165,7 @@ func TestConvertLongTimeSeriesQuery(t *testing.T) {

expectedOutputFrames := make([]*data.Frame, 2)
expectedOutputFrames[0] = data.NewFrame(
"value one",
"",
data.NewField("time", nil, []time.Time{time.Unix(21, 0), time.Unix(22, 0)}),
data.NewField(
"value",
Expand All @@ -176,7 +176,7 @@ func TestConvertLongTimeSeriesQuery(t *testing.T) {
expectedOutputFrames[0].Meta = &data.FrameMeta{ExecutedQueryString: "SELECT * FROM test"}

expectedOutputFrames[1] = data.NewFrame(
"value two",
"",
data.NewField("time", nil, []time.Time{time.Unix(21, 0), time.Unix(22, 0)}),
data.NewField(
"value",
Expand Down
10 changes: 5 additions & 5 deletions pkg/plugin/query_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestCTETableQuery(t *testing.T) {
}

expectedFrame := data.NewFrame(
"response",
"",
data.NewField("time", nil, []*int64{intPointer(1), intPointer(2), intPointer(3)}),
data.NewField("value", nil, []*float64{
floatPointer(1.1), floatPointer(2.2), floatPointer(3.3),
Expand Down Expand Up @@ -72,7 +72,7 @@ func TestMixedTypes(t *testing.T) {
}

expectedFrame := data.NewFrame(
"response",
"",
data.NewField("first", nil, []*float64{floatPointer(1), floatPointer(2.2)}),
data.NewField("second", nil, []*float64{floatPointer(1.1), floatPointer(2)}),
)
Expand Down Expand Up @@ -106,7 +106,7 @@ func TestSimpleTableQuery(t *testing.T) {
}

expectedFrame := data.NewFrame(
"response",
"",
data.NewField("time", nil, []*int64{intPointer(1), intPointer(2), intPointer(3)}),
data.NewField("value", nil, []*float64{
floatPointer(1.1), floatPointer(2.2), floatPointer(3.3),
Expand Down Expand Up @@ -145,7 +145,7 @@ func TestNullValues(t *testing.T) {
}

expectedFrame := data.NewFrame(
"response",
"",
data.NewField("time", nil, []*int64{nil, intPointer(2), intPointer(3)}),
data.NewField("value", nil, []*float64{floatPointer(1.1), nil, floatPointer(3.3)}),
data.NewField("name", nil, []*string{strPointer("one"), strPointer("two"), nil}),
Expand Down Expand Up @@ -182,7 +182,7 @@ func TestNullValuesCTE(t *testing.T) {
}

expectedFrame := data.NewFrame(
"response",
"",
data.NewField("time", nil, []*int64{nil, intPointer(2), intPointer(3)}),
data.NewField("value", nil, []*float64{floatPointer(1.1), nil, floatPointer(3.3)}),
data.NewField("name", nil, []*string{strPointer("one"), strPointer("two"), nil}),
Expand Down

0 comments on commit 1f259be

Please sign in to comment.