From e5752974df060d64835100fbdfb79fb0d23fb7fa Mon Sep 17 00:00:00 2001 From: Sergej Herbert Date: Sun, 11 Sep 2022 15:55:55 +0200 Subject: [PATCH 1/2] refactor: Remove data frame name --- CHANGELOG.md | 6 ++++++ pkg/plugin/gap_filling_test.go | 16 ++++++++-------- pkg/plugin/json_support_test.go | 2 +- pkg/plugin/query.go | 5 ++--- pkg/plugin/query_test.go | 10 +++++----- pkg/plugin/query_time_test.go | 6 +++--- pkg/plugin/query_timeseries_test.go | 14 +++++++------- pkg/plugin/query_types_test.go | 10 +++++----- 8 files changed, 37 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eea5544..b410040 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/pkg/plugin/gap_filling_test.go b/pkg/plugin/gap_filling_test.go index a243654..be50c2f 100644 --- a/pkg/plugin/gap_filling_test.go +++ b/pkg/plugin/gap_filling_test.go @@ -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)}), ) @@ -75,7 +75,7 @@ func TestEpochGroupSecondsShouldFillInNullValuesForTables(t *testing.T) { } expectedFrame := data.NewFrame( - "response", + "", data.NewField( "window", nil, []*time.Time{ unixTimePointer(0), @@ -121,7 +121,7 @@ func TestEpochGroupSecondsShouldFillInNullValuesForTimeSeriesWithDoubleGaps(t *t } expectedFrame := data.NewFrame( - "value", + "", data.NewField( "window", nil, @@ -178,7 +178,7 @@ func TestEpochGroupSecondsShouldFillInNullValuesWithMultipleTimeColumns(t *testi } expectedFrame := data.NewFrame( - "response", + "", data.NewField("window", nil, []*time.Time{ unixTimePointer(0), unixTimePointer(10), @@ -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)), @@ -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), }), @@ -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)}, ), @@ -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)}, ), diff --git a/pkg/plugin/json_support_test.go b/pkg/plugin/json_support_test.go index cf5c939..b232db3 100644 --- a/pkg/plugin/json_support_test.go +++ b/pkg/plugin/json_support_test.go @@ -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} diff --git a/pkg/plugin/query.go b/pkg/plugin/query.go index 5d8bc61..4688b98 100644 --- a/pkg/plugin/query.go +++ b/pkg/plugin/query.go @@ -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 { @@ -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, ) diff --git a/pkg/plugin/query_test.go b/pkg/plugin/query_test.go index 721aeee..2bd66d6 100644 --- a/pkg/plugin/query_test.go +++ b/pkg/plugin/query_test.go @@ -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 != "" { @@ -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{}), @@ -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`) @@ -144,7 +144,7 @@ func TestNoResultsTimeSeriesWithUnknownColumns(t *testing.T) { } expectedFrame := data.NewFrame( - "value", + "", data.NewField("time", nil, []*time.Time{}), data.NewField("value", nil, []*float64{}), ) @@ -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)}), ) diff --git a/pkg/plugin/query_time_test.go b/pkg/plugin/query_time_test.go index b29c19e..cef8277 100644 --- a/pkg/plugin/query_time_test.go +++ b/pkg/plugin/query_time_test.go @@ -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)), @@ -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)), @@ -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)), diff --git a/pkg/plugin/query_timeseries_test.go b/pkg/plugin/query_timeseries_test.go index ea24316..612cf08 100644 --- a/pkg/plugin/query_timeseries_test.go +++ b/pkg/plugin/query_timeseries_test.go @@ -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(` @@ -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)), @@ -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(` @@ -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)), @@ -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)), }), @@ -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", @@ -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", diff --git a/pkg/plugin/query_types_test.go b/pkg/plugin/query_types_test.go index 1fc1f18..8acb87a 100644 --- a/pkg/plugin/query_types_test.go +++ b/pkg/plugin/query_types_test.go @@ -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), @@ -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)}), ) @@ -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), @@ -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}), @@ -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}), From c1c19edbfdce5d7af0d765cc55a3fd92d45f9d8c Mon Sep 17 00:00:00 2001 From: Sergej Herbert Date: Sun, 11 Sep 2022 15:56:06 +0200 Subject: [PATCH 2/2] docs: Add double legend FAQ --- README.md | 1 + docs/faq.md | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/README.md b/README.md index 5b421e0..64dfe0f 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/docs/faq.md b/docs/faq.md index 1488394..d42a958 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -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).