mirror of
https://github.com/grafana/grafana.git
synced 2026-08-18 17:15:08 -05:00
Owensmallwood/pubdash panel blank when target has no datasource (#52115)
Fixes public dashboards bug. When panel targets have no datasource, the datasource on the panel can be a json object or a string and will get added to the targets for pubdash.
This commit is contained in:
@@ -20,6 +20,37 @@ const (
|
||||
"schemaVersion": 35
|
||||
}`
|
||||
|
||||
dashboardWithTargetsWithNoDatasources = `
|
||||
{
|
||||
"panels": [
|
||||
{
|
||||
"id": 2,
|
||||
"datasource": {
|
||||
"type": "postgres",
|
||||
"uid": "abc123"
|
||||
},
|
||||
"targets": [
|
||||
{
|
||||
"expr": "go_goroutines{job=\"$job\"}",
|
||||
"interval": "",
|
||||
"legendFormat": "",
|
||||
"refId": "A"
|
||||
},
|
||||
{
|
||||
"exemplar": true,
|
||||
"expr": "query2",
|
||||
"interval": "",
|
||||
"legendFormat": "",
|
||||
"refId": "B"
|
||||
}
|
||||
],
|
||||
"title": "Panel Title",
|
||||
"type": "timeseries"
|
||||
}
|
||||
],
|
||||
"schemaVersion": 35
|
||||
}`
|
||||
|
||||
dashboardWithQueries = `
|
||||
{
|
||||
"panels": [
|
||||
@@ -256,6 +287,24 @@ func TestGetUniqueDashboardDatasourceUids(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGroupQueriesByPanelId(t *testing.T) {
|
||||
t.Run("can extract queries from dashboard with panel datasource string that has no datasource on panel targets", func(t *testing.T) {
|
||||
json, err := simplejson.NewJson([]byte(oldStyleDashboard))
|
||||
require.NoError(t, err)
|
||||
queries := GroupQueriesByPanelId(json)
|
||||
|
||||
panelId := int64(2)
|
||||
queriesByDatasource := GroupQueriesByDataSource(queries[panelId])
|
||||
require.Len(t, queriesByDatasource[0], 1)
|
||||
})
|
||||
t.Run("can extract queries from dashboard with panel json datasource that has no datasource on panel targets", func(t *testing.T) {
|
||||
json, err := simplejson.NewJson([]byte(dashboardWithTargetsWithNoDatasources))
|
||||
require.NoError(t, err)
|
||||
queries := GroupQueriesByPanelId(json)
|
||||
|
||||
panelId := int64(2)
|
||||
queriesByDatasource := GroupQueriesByDataSource(queries[panelId])
|
||||
require.Len(t, queriesByDatasource[0], 2)
|
||||
})
|
||||
t.Run("can extract no queries from empty dashboard", func(t *testing.T) {
|
||||
json, err := simplejson.NewJson([]byte(`{"panels": {}}`))
|
||||
require.NoError(t, err)
|
||||
@@ -321,7 +370,10 @@ func TestGroupQueriesByPanelId(t *testing.T) {
|
||||
query, err := queries[2][0].MarshalJSON()
|
||||
require.NoError(t, err)
|
||||
require.JSONEq(t, `{
|
||||
"datasource": "_yxMP8Ynk",
|
||||
"datasource": {
|
||||
"uid": "_yxMP8Ynk",
|
||||
"type": "public-ds"
|
||||
},
|
||||
"exemplar": true,
|
||||
"expr": "go_goroutines{job=\"$job\"}",
|
||||
"interval": "",
|
||||
|
||||
Reference in New Issue
Block a user