-
Notifications
You must be signed in to change notification settings - Fork 11.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SQL: Fixes issues with showing value column name prefix in legends #35839
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me
Co-authored-by: Torkel Ödegaard <torkel@grafana.org>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works in the case where you only have two fields, but not when you have more than one value fields with label metric. There's other cases when there's not a value and metric field as can be seen in documentation:
The gdev dashboard has one such example for postgres unittest dashboard:
SELECT
$__timeGroup("time_date_time",'5m'),
min("value_double") as "min_value",
max("value_double") as "max_value"
FROM test_data
WHERE $__timeFilter("time_date_time")
GROUP BY time
ORDER BY time
This gdev dashboard shows that it resolves one panel, but not the other two:
For example below query generates the following frame
SELECT
$__timeGroup("createdAt",'$summarize'),
max(value) as "value",
hostname as "metric"
FROM
grafana_metric
WHERE
$__timeFilter("createdAt") AND
measurement = 'cpu' AND
hostname IN($host)
GROUP BY time, metric
ORDER BY time
{
"response": {
"results": {
"A": {
"frames": [
{
"schema": {
"name": "results",
"meta": {
"executedQueryString": "SELECT\n floor(extract(epoch from \"createdAt\")/60)*60 AS \"time\",\n max(value) as \"value\",\n hostname as \"metric\"\nFROM \n grafana_metric\nWHERE\n \"createdAt\" BETWEEN '2021-06-17T07:47:59.888Z' AND '2021-06-17T07:52:59.888Z' AND\n measurement = 'cpu' AND\n hostname IN('10.1.100.1','10.1.100.10','server1','server2')\nGROUP BY time, metric\nORDER BY time"
},
"fields": [
{
"name": "time",
"type": "time",
"typeInfo": {
"frame": "time.Time"
}
},
{
"name": "value",
"type": "number",
"typeInfo": {
"frame": "float64",
"nullable": true
},
"labels": {
"metric": "server1"
}
},
{
"name": "value",
"type": "number",
"typeInfo": {
"frame": "float64",
"nullable": true
},
"labels": {
"metric": "server2"
}
}
]
},
"data": {
"values": [
[
1623916080000,
1623916140000,
1623916200000,
1623916260000,
1623916320000
],
[
101.94567116740645,
101.32983803008855,
98.24485134174023,
99.11082242003671,
98.20762076760217
],
[
102.17495640876385,
101.49139611423894,
98.5697798472507,
99.34979998130595,
98.5910734483771
]
]
}
}
],
"refId": "A"
}
}
}
}
We need to decide whether wide data frames for SQL is the way forward. To me it is because of unified alerting and multi dimensions plus v8 is a good opportunity to do breaking change as long as we have a good workaround story. Let us know if you need help from backend platform figuring out this.
This solves this issue for me #35599 |
SELECT This query did not work in v7.5 for me, what format have selected time series or table? The query is missing a metric field as well so the above code should not have any effect ? We need to figure out something out really soon as v8 breaks almost all time series queries |
@marefr but good catch that it does not solve all those graphs on that dashboard, a small update should fix that. |
@marefr pushed an update that fixes it so that it works on all panels on that test dashboard, was a wrong condition that made the fix logic only apply to data frames with 2 fields |
The old logic is, if there's no metric column selected, use the names of value columns as metric :) |
@marefr it's working now, the query below works well for me SELECT
$__timeGroup("time_date_time",'5m'),
min("value_double") as "min_value",
max("value_double") as "max_value"
FROM test_data
WHERE $__timeFilter("time_date_time")
GROUP BY time
ORDER BY time |
pushed another update that refines the logic to only be applied when the orignal query returns 3 columns (so if you have more than one value field the fixing logic wont happen). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Works great 🎉
…35839) * rename strategy * Update pkg/tsdb/sqleng/sql_engine.go Co-authored-by: Torkel Ödegaard <torkel@grafana.org> * more strict constraints * Fixed so that it works on multi series results * only apply the logic when original query returns 3 fields * removed part of comment * Update mysql test Co-authored-by: Torkel Ödegaard <torkel@grafana.org> Co-authored-by: Torkel Ödegaard <torkel@grafana.com> (cherry picked from commit 1d6e99b)
…35839) (#35922) * rename strategy * Update pkg/tsdb/sqleng/sql_engine.go Co-authored-by: Torkel Ödegaard <torkel@grafana.org> * more strict constraints * Fixed so that it works on multi series results * only apply the logic when original query returns 3 fields * removed part of comment * Update mysql test Co-authored-by: Torkel Ödegaard <torkel@grafana.org> Co-authored-by: Torkel Ödegaard <torkel@grafana.com> (cherry picked from commit 1d6e99b) Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
…rafana#35839) * rename strategy * Update pkg/tsdb/sqleng/sql_engine.go Co-authored-by: Torkel Ödegaard <torkel@grafana.org> * more strict constraints * Fixed so that it works on multi series results * only apply the logic when original query returns 3 fields * removed part of comment * Update mysql test Co-authored-by: Torkel Ödegaard <torkel@grafana.org> Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
* convert SQLs to use sdk contracts * make draft * postgres * intermedia * get datasourceinfo filled at the beginning of the service * move the interval into package because of cyclict import and fix all postgres tests * fix mysql test * fix mssql * fix the test for pr #35839 * fix some issue about intervalv2 package * update sql test * wire migration for SQLs * add sqls to the background process * make it register instead of register and start * revert formatting * fix tests * fix linter * remove integration test * Postgres test fix Co-authored-by: Marcus Efraimsson <marcus.efraimsson@gmail.com>
Fixes #35390 (partially)
This is a SQL specific and back end only alternative to #35392
http://localhost:3000/d/JYola5qzz/datasource-tests-postgres?orgId=1&editPanel=4