mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
postgres: improved tests (#84677)
* postgres: tests: better test aligning time-series results * postgres: add snapshot test for a backward-compat code
This commit is contained in:
parent
28ecd83987
commit
c835022861
@ -83,8 +83,8 @@ func TestIntegrationPostgresSnapshots(t *testing.T) {
|
||||
JSON: queryBytes,
|
||||
RefID: "A",
|
||||
TimeRange: backend.TimeRange{
|
||||
From: time.Date(2023, 12, 24, 14, 15, 0, 0, time.UTC),
|
||||
To: time.Date(2023, 12, 24, 14, 45, 0, 0, time.UTC),
|
||||
From: time.Date(2023, 12, 24, 14, 15, 22, 123456, time.UTC),
|
||||
To: time.Date(2023, 12, 24, 14, 45, 13, 876543, time.UTC),
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -104,6 +104,7 @@ func TestIntegrationPostgresSnapshots(t *testing.T) {
|
||||
{format: "time_series", name: "fill_null"},
|
||||
{format: "time_series", name: "fill_previous"},
|
||||
{format: "time_series", name: "fill_value"},
|
||||
{format: "time_series", name: "fill_value_wide"},
|
||||
{format: "table", name: "simple"},
|
||||
{format: "table", name: "no_rows"},
|
||||
{format: "table", name: "types_numeric"},
|
||||
@ -114,6 +115,8 @@ func TestIntegrationPostgresSnapshots(t *testing.T) {
|
||||
{format: "table", name: "timestamp_convert_integer"},
|
||||
{format: "table", name: "timestamp_convert_real"},
|
||||
{format: "table", name: "timestamp_convert_double"},
|
||||
{format: "table", name: "time_group_compat_case1"},
|
||||
{format: "table", name: "time_group_compat_case2"},
|
||||
}
|
||||
|
||||
for _, test := range tt {
|
||||
|
65
pkg/tsdb/grafana-postgresql-datasource/testdata/table/time_group_compat_case1.golden.jsonc
vendored
Normal file
65
pkg/tsdb/grafana-postgresql-datasource/testdata/table/time_group_compat_case1.golden.jsonc
vendored
Normal file
@ -0,0 +1,65 @@
|
||||
// 🌟 This was machine generated. Do not edit. 🌟
|
||||
//
|
||||
// Frame[0] {
|
||||
// "typeVersion": [
|
||||
// 0,
|
||||
// 0
|
||||
// ],
|
||||
// "executedQueryString": "SELECT floor(extract(epoch from \"t\")/300)*300 AS \"time\",avg(v) FROM tbl GROUP BY 1"
|
||||
// }
|
||||
// Name:
|
||||
// Dimensions: 2 Fields by 1 Rows
|
||||
// +-------------------------------+------------------+
|
||||
// | Name: time | Name: avg |
|
||||
// | Labels: | Labels: |
|
||||
// | Type: []*time.Time | Type: []*float64 |
|
||||
// +-------------------------------+------------------+
|
||||
// | 2023-12-24 14:30:00 +0000 UTC | 42 |
|
||||
// +-------------------------------+------------------+
|
||||
//
|
||||
//
|
||||
// 🌟 This was machine generated. Do not edit. 🌟
|
||||
{
|
||||
"status": 200,
|
||||
"frames": [
|
||||
{
|
||||
"schema": {
|
||||
"meta": {
|
||||
"typeVersion": [
|
||||
0,
|
||||
0
|
||||
],
|
||||
"executedQueryString": "SELECT floor(extract(epoch from \"t\")/300)*300 AS \"time\",avg(v) FROM tbl GROUP BY 1"
|
||||
},
|
||||
"fields": [
|
||||
{
|
||||
"name": "time",
|
||||
"type": "time",
|
||||
"typeInfo": {
|
||||
"frame": "time.Time",
|
||||
"nullable": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "avg",
|
||||
"type": "number",
|
||||
"typeInfo": {
|
||||
"frame": "float64",
|
||||
"nullable": true
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"data": {
|
||||
"values": [
|
||||
[
|
||||
1703428200000
|
||||
],
|
||||
[
|
||||
42
|
||||
]
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
10
pkg/tsdb/grafana-postgresql-datasource/testdata/table/time_group_compat_case1.sql
vendored
Normal file
10
pkg/tsdb/grafana-postgresql-datasource/testdata/table/time_group_compat_case1.sql
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
-- SELECT $__timeGroup("t",5m,NULL),avg(v) FROM tbl GROUP BY 1
|
||||
-- we change behavior based on what follows the timegroup, see:
|
||||
-- https://github.com/grafana/grafana/blob/0b4c81158ea32a671e7788b888b086082343407c/pkg/tsdb/grafana-postgresql-datasource/macros.go#L36
|
||||
CREATE TEMPORARY TABLE tbl (
|
||||
t timestamp with time zone,
|
||||
v double precision
|
||||
);
|
||||
|
||||
INSERT INTO tbl (t, v) VALUES
|
||||
('2023-12-24 14:30:03 UTC', 42);
|
65
pkg/tsdb/grafana-postgresql-datasource/testdata/table/time_group_compat_case2.golden.jsonc
vendored
Normal file
65
pkg/tsdb/grafana-postgresql-datasource/testdata/table/time_group_compat_case2.golden.jsonc
vendored
Normal file
@ -0,0 +1,65 @@
|
||||
// 🌟 This was machine generated. Do not edit. 🌟
|
||||
//
|
||||
// Frame[0] {
|
||||
// "typeVersion": [
|
||||
// 0,
|
||||
// 0
|
||||
// ],
|
||||
// "executedQueryString": "SELECT floor(extract(epoch from \"t\")/300)*300 ,avg(v) FROM tbl GROUP BY 1"
|
||||
// }
|
||||
// Name:
|
||||
// Dimensions: 2 Fields by 1 Rows
|
||||
// +------------------+------------------+
|
||||
// | Name: ?column? | Name: avg |
|
||||
// | Labels: | Labels: |
|
||||
// | Type: []*float64 | Type: []*float64 |
|
||||
// +------------------+------------------+
|
||||
// | 1.7034282e+09 | 42 |
|
||||
// +------------------+------------------+
|
||||
//
|
||||
//
|
||||
// 🌟 This was machine generated. Do not edit. 🌟
|
||||
{
|
||||
"status": 200,
|
||||
"frames": [
|
||||
{
|
||||
"schema": {
|
||||
"meta": {
|
||||
"typeVersion": [
|
||||
0,
|
||||
0
|
||||
],
|
||||
"executedQueryString": "SELECT floor(extract(epoch from \"t\")/300)*300 ,avg(v) FROM tbl GROUP BY 1"
|
||||
},
|
||||
"fields": [
|
||||
{
|
||||
"name": "?column?",
|
||||
"type": "number",
|
||||
"typeInfo": {
|
||||
"frame": "float64",
|
||||
"nullable": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "avg",
|
||||
"type": "number",
|
||||
"typeInfo": {
|
||||
"frame": "float64",
|
||||
"nullable": true
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"data": {
|
||||
"values": [
|
||||
[
|
||||
1703428200
|
||||
],
|
||||
[
|
||||
42
|
||||
]
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
10
pkg/tsdb/grafana-postgresql-datasource/testdata/table/time_group_compat_case2.sql
vendored
Normal file
10
pkg/tsdb/grafana-postgresql-datasource/testdata/table/time_group_compat_case2.sql
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
-- SELECT $__timeGroup("t",5m,NULL) ,avg(v) FROM tbl GROUP BY 1
|
||||
-- we change behavior based on what follows the timegroup, see:
|
||||
-- https://github.com/grafana/grafana/blob/0b4c81158ea32a671e7788b888b086082343407c/pkg/tsdb/grafana-postgresql-datasource/macros.go#L36
|
||||
CREATE TEMPORARY TABLE tbl (
|
||||
t timestamp with time zone,
|
||||
v double precision
|
||||
);
|
||||
|
||||
INSERT INTO tbl (t, v) VALUES
|
||||
('2023-12-24 14:30:03 UTC', 42);
|
100
pkg/tsdb/grafana-postgresql-datasource/testdata/time_series/fill_value_wide.golden.jsonc
vendored
Normal file
100
pkg/tsdb/grafana-postgresql-datasource/testdata/time_series/fill_value_wide.golden.jsonc
vendored
Normal file
@ -0,0 +1,100 @@
|
||||
// 🌟 This was machine generated. Do not edit. 🌟
|
||||
//
|
||||
// Frame[0] {
|
||||
// "typeVersion": [
|
||||
// 0,
|
||||
// 0
|
||||
// ],
|
||||
// "executedQueryString": "SELECT floor(extract(epoch from \"time\")/300)*300 AS \"time\",avg(v1) AS \"v1\", avg(v2) AS \"v2\" FROM tbl GROUP BY 1 ORDER BY 1"
|
||||
// }
|
||||
// Name:
|
||||
// Dimensions: 3 Fields by 7 Rows
|
||||
// +-------------------------------+------------------+------------------+
|
||||
// | Name: Time | Name: v1 | Name: v2 |
|
||||
// | Labels: | Labels: | Labels: |
|
||||
// | Type: []*time.Time | Type: []*float64 | Type: []*float64 |
|
||||
// +-------------------------------+------------------+------------------+
|
||||
// | 2023-12-24 14:15:00 +0000 UTC | 27 | 27 |
|
||||
// | 2023-12-24 14:20:00 +0000 UTC | 15 | 115 |
|
||||
// | 2023-12-24 14:25:00 +0000 UTC | 27 | 27 |
|
||||
// | 2023-12-24 14:30:00 +0000 UTC | 27 | 27 |
|
||||
// | 2023-12-24 14:35:00 +0000 UTC | 50 | 150 |
|
||||
// | 2023-12-24 14:40:00 +0000 UTC | 27 | 27 |
|
||||
// | 2023-12-24 14:45:00 +0000 UTC | 27 | 27 |
|
||||
// +-------------------------------+------------------+------------------+
|
||||
//
|
||||
//
|
||||
// 🌟 This was machine generated. Do not edit. 🌟
|
||||
{
|
||||
"status": 200,
|
||||
"frames": [
|
||||
{
|
||||
"schema": {
|
||||
"meta": {
|
||||
"typeVersion": [
|
||||
0,
|
||||
0
|
||||
],
|
||||
"executedQueryString": "SELECT floor(extract(epoch from \"time\")/300)*300 AS \"time\",avg(v1) AS \"v1\", avg(v2) AS \"v2\" FROM tbl GROUP BY 1 ORDER BY 1"
|
||||
},
|
||||
"fields": [
|
||||
{
|
||||
"name": "Time",
|
||||
"type": "time",
|
||||
"typeInfo": {
|
||||
"frame": "time.Time",
|
||||
"nullable": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "v1",
|
||||
"type": "number",
|
||||
"typeInfo": {
|
||||
"frame": "float64",
|
||||
"nullable": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "v2",
|
||||
"type": "number",
|
||||
"typeInfo": {
|
||||
"frame": "float64",
|
||||
"nullable": true
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"data": {
|
||||
"values": [
|
||||
[
|
||||
1703427300000,
|
||||
1703427600000,
|
||||
1703427900000,
|
||||
1703428200000,
|
||||
1703428500000,
|
||||
1703428800000,
|
||||
1703429100000
|
||||
],
|
||||
[
|
||||
27,
|
||||
15,
|
||||
27,
|
||||
27,
|
||||
50,
|
||||
27,
|
||||
27
|
||||
],
|
||||
[
|
||||
27,
|
||||
115,
|
||||
27,
|
||||
27,
|
||||
150,
|
||||
27,
|
||||
27
|
||||
]
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
12
pkg/tsdb/grafana-postgresql-datasource/testdata/time_series/fill_value_wide.sql
vendored
Normal file
12
pkg/tsdb/grafana-postgresql-datasource/testdata/time_series/fill_value_wide.sql
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
-- SELECT $__timeGroup("time",5m,27),avg(v1) AS "v1", avg(v2) AS "v2" FROM tbl GROUP BY 1 ORDER BY 1
|
||||
-- tests fill-mode=value
|
||||
CREATE TEMPORARY TABLE tbl (
|
||||
"time" timestamp with time zone,
|
||||
v1 double precision,
|
||||
v2 double precision
|
||||
);
|
||||
|
||||
INSERT INTO tbl ("time", v1, v2) VALUES
|
||||
('2023-12-24 14:21:03 UTC', 10, 110),
|
||||
('2023-12-24 14:23:03 UTC', 20, 120),
|
||||
('2023-12-24 14:39:03 UTC', 50, 150);
|
Loading…
Reference in New Issue
Block a user