mirror of
https://github.com/grafana/grafana.git
synced 2025-08-02 03:12:13 +08:00
schema: Finish converting dashboard schema datasource references to objects (#47806)
* coremodel: finish string -> object datasource ref Seems we missed updating a couple of the datasource references from strings to objects. * cue fmt * Also fix dashboard in scuemata dashboard schema * Update devenv/dev-dashboards/panel-graph/graph-ng-stacking2.json Co-authored-by: Ryan McKinley <ryantxu@gmail.com> Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
This commit is contained in:
@ -68,7 +68,7 @@ func themaTestableDashboards() (map[string][]byte, error) {
|
|||||||
|
|
||||||
jtree := make(map[string]interface{})
|
jtree := make(map[string]interface{})
|
||||||
json.Unmarshal(b, &jtree)
|
json.Unmarshal(b, &jtree)
|
||||||
if oldschemav, has := jtree["schemaVersion"]; !has || !(oldschemav.(float64) > 32) {
|
if oldschemav, has := jtree["schemaVersion"]; !has || !(oldschemav.(float64) > dashboard.HandoffSchemaVersion-1) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,8 +71,7 @@
|
|||||||
"mode": "absolute",
|
"mode": "absolute",
|
||||||
"steps": [
|
"steps": [
|
||||||
{
|
{
|
||||||
"color": "green",
|
"color": "green"
|
||||||
"value": null
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"color": "red",
|
"color": "red",
|
||||||
@ -178,8 +177,7 @@
|
|||||||
"mode": "absolute",
|
"mode": "absolute",
|
||||||
"steps": [
|
"steps": [
|
||||||
{
|
{
|
||||||
"color": "green",
|
"color": "green"
|
||||||
"value": null
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"color": "red",
|
"color": "red",
|
||||||
@ -266,8 +264,7 @@
|
|||||||
"mode": "absolute",
|
"mode": "absolute",
|
||||||
"steps": [
|
"steps": [
|
||||||
{
|
{
|
||||||
"color": "green",
|
"color": "green"
|
||||||
"value": null
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"color": "red",
|
"color": "red",
|
||||||
@ -354,8 +351,7 @@
|
|||||||
"mode": "absolute",
|
"mode": "absolute",
|
||||||
"steps": [
|
"steps": [
|
||||||
{
|
{
|
||||||
"color": "green",
|
"color": "green"
|
||||||
"value": null
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"color": "red",
|
"color": "red",
|
||||||
@ -485,8 +481,7 @@
|
|||||||
"mode": "absolute",
|
"mode": "absolute",
|
||||||
"steps": [
|
"steps": [
|
||||||
{
|
{
|
||||||
"color": "green",
|
"color": "green"
|
||||||
"value": null
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"color": "red",
|
"color": "red",
|
||||||
@ -573,8 +568,7 @@
|
|||||||
"mode": "absolute",
|
"mode": "absolute",
|
||||||
"steps": [
|
"steps": [
|
||||||
{
|
{
|
||||||
"color": "green",
|
"color": "green"
|
||||||
"value": null
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"color": "red",
|
"color": "red",
|
||||||
@ -661,8 +655,7 @@
|
|||||||
"mode": "absolute",
|
"mode": "absolute",
|
||||||
"steps": [
|
"steps": [
|
||||||
{
|
{
|
||||||
"color": "green",
|
"color": "green"
|
||||||
"value": null
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"color": "red",
|
"color": "red",
|
||||||
@ -792,8 +785,7 @@
|
|||||||
"mode": "absolute",
|
"mode": "absolute",
|
||||||
"steps": [
|
"steps": [
|
||||||
{
|
{
|
||||||
"color": "green",
|
"color": "green"
|
||||||
"value": null
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"color": "red",
|
"color": "red",
|
||||||
@ -893,8 +885,7 @@
|
|||||||
"mode": "absolute",
|
"mode": "absolute",
|
||||||
"steps": [
|
"steps": [
|
||||||
{
|
{
|
||||||
"color": "green",
|
"color": "green"
|
||||||
"value": null
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"color": "red",
|
"color": "red",
|
||||||
@ -982,8 +973,7 @@
|
|||||||
"mode": "absolute",
|
"mode": "absolute",
|
||||||
"steps": [
|
"steps": [
|
||||||
{
|
{
|
||||||
"color": "green",
|
"color": "green"
|
||||||
"value": null
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"color": "red",
|
"color": "red",
|
||||||
@ -1069,8 +1059,7 @@
|
|||||||
"mode": "absolute",
|
"mode": "absolute",
|
||||||
"steps": [
|
"steps": [
|
||||||
{
|
{
|
||||||
"color": "green",
|
"color": "green"
|
||||||
"value": null
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"color": "red",
|
"color": "red",
|
||||||
@ -1155,8 +1144,7 @@
|
|||||||
"mode": "absolute",
|
"mode": "absolute",
|
||||||
"steps": [
|
"steps": [
|
||||||
{
|
{
|
||||||
"color": "green",
|
"color": "green"
|
||||||
"value": null
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"color": "red",
|
"color": "red",
|
||||||
@ -1253,8 +1241,7 @@
|
|||||||
"mode": "absolute",
|
"mode": "absolute",
|
||||||
"steps": [
|
"steps": [
|
||||||
{
|
{
|
||||||
"color": "green",
|
"color": "green"
|
||||||
"value": null
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"color": "red",
|
"color": "red",
|
||||||
@ -1354,8 +1341,7 @@
|
|||||||
"mode": "absolute",
|
"mode": "absolute",
|
||||||
"steps": [
|
"steps": [
|
||||||
{
|
{
|
||||||
"color": "green",
|
"color": "green"
|
||||||
"value": null
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"color": "red",
|
"color": "red",
|
||||||
@ -1455,8 +1441,7 @@
|
|||||||
"mode": "absolute",
|
"mode": "absolute",
|
||||||
"steps": [
|
"steps": [
|
||||||
{
|
{
|
||||||
"color": "green",
|
"color": "green"
|
||||||
"value": null
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"color": "red",
|
"color": "red",
|
||||||
@ -1555,8 +1540,7 @@
|
|||||||
"mode": "absolute",
|
"mode": "absolute",
|
||||||
"steps": [
|
"steps": [
|
||||||
{
|
{
|
||||||
"color": "green",
|
"color": "green"
|
||||||
"value": null
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"color": "red",
|
"color": "red",
|
||||||
@ -1692,8 +1676,7 @@
|
|||||||
"mode": "absolute",
|
"mode": "absolute",
|
||||||
"steps": [
|
"steps": [
|
||||||
{
|
{
|
||||||
"color": "green",
|
"color": "green"
|
||||||
"value": null
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"color": "red",
|
"color": "red",
|
||||||
@ -1800,8 +1783,7 @@
|
|||||||
"mode": "absolute",
|
"mode": "absolute",
|
||||||
"steps": [
|
"steps": [
|
||||||
{
|
{
|
||||||
"color": "green",
|
"color": "green"
|
||||||
"value": null
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"color": "red",
|
"color": "red",
|
||||||
@ -1909,8 +1891,7 @@
|
|||||||
"mode": "absolute",
|
"mode": "absolute",
|
||||||
"steps": [
|
"steps": [
|
||||||
{
|
{
|
||||||
"color": "green",
|
"color": "green"
|
||||||
"value": null
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"color": "red",
|
"color": "red",
|
||||||
@ -2040,8 +2021,7 @@
|
|||||||
"mode": "absolute",
|
"mode": "absolute",
|
||||||
"steps": [
|
"steps": [
|
||||||
{
|
{
|
||||||
"color": "green",
|
"color": "green"
|
||||||
"value": null
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"color": "red",
|
"color": "red",
|
||||||
@ -2128,8 +2108,7 @@
|
|||||||
"mode": "absolute",
|
"mode": "absolute",
|
||||||
"steps": [
|
"steps": [
|
||||||
{
|
{
|
||||||
"color": "green",
|
"color": "green"
|
||||||
"value": null
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"color": "red",
|
"color": "red",
|
||||||
@ -2240,8 +2219,7 @@
|
|||||||
"mode": "absolute",
|
"mode": "absolute",
|
||||||
"steps": [
|
"steps": [
|
||||||
{
|
{
|
||||||
"color": "green",
|
"color": "green"
|
||||||
"value": null
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"color": "red",
|
"color": "red",
|
||||||
@ -2356,8 +2334,7 @@
|
|||||||
"mode": "absolute",
|
"mode": "absolute",
|
||||||
"steps": [
|
"steps": [
|
||||||
{
|
{
|
||||||
"color": "green",
|
"color": "green"
|
||||||
"value": null
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"color": "red",
|
"color": "red",
|
||||||
@ -2460,8 +2437,7 @@
|
|||||||
"mode": "absolute",
|
"mode": "absolute",
|
||||||
"steps": [
|
"steps": [
|
||||||
{
|
{
|
||||||
"color": "green",
|
"color": "green"
|
||||||
"value": null
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"color": "red",
|
"color": "red",
|
||||||
@ -2564,8 +2540,7 @@
|
|||||||
"mode": "absolute",
|
"mode": "absolute",
|
||||||
"steps": [
|
"steps": [
|
||||||
{
|
{
|
||||||
"color": "green",
|
"color": "green"
|
||||||
"value": null
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"color": "red",
|
"color": "red",
|
||||||
@ -2701,8 +2676,7 @@
|
|||||||
"mode": "absolute",
|
"mode": "absolute",
|
||||||
"steps": [
|
"steps": [
|
||||||
{
|
{
|
||||||
"color": "green",
|
"color": "green"
|
||||||
"value": null
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"color": "red",
|
"color": "red",
|
||||||
@ -2838,8 +2812,7 @@
|
|||||||
"mode": "absolute",
|
"mode": "absolute",
|
||||||
"steps": [
|
"steps": [
|
||||||
{
|
{
|
||||||
"color": "green",
|
"color": "green"
|
||||||
"value": null
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"color": "red",
|
"color": "red",
|
||||||
@ -2934,7 +2907,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"refresh": false,
|
"refresh": false,
|
||||||
"schemaVersion": 32,
|
"schemaVersion": 36,
|
||||||
"style": "dark",
|
"style": "dark",
|
||||||
"tags": [
|
"tags": [
|
||||||
"gdev",
|
"gdev",
|
||||||
|
@ -9,7 +9,7 @@ import (
|
|||||||
Family: scuemata.#Family & {
|
Family: scuemata.#Family & {
|
||||||
lineages: [
|
lineages: [
|
||||||
[
|
[
|
||||||
{ // 0.0
|
{// 0.0
|
||||||
// Unique numeric identifier for the dashboard.
|
// Unique numeric identifier for the dashboard.
|
||||||
// TODO must isolate or remove identifiers local to a Grafana instance...?
|
// TODO must isolate or remove identifiers local to a Grafana instance...?
|
||||||
id?: number
|
id?: number
|
||||||
@ -55,7 +55,10 @@ Family: scuemata.#Family & {
|
|||||||
annotations?: list: [...{
|
annotations?: list: [...{
|
||||||
builtIn: number | *0
|
builtIn: number | *0
|
||||||
// Datasource to use for annotation.
|
// Datasource to use for annotation.
|
||||||
datasource: string
|
datasource: {
|
||||||
|
type?: string
|
||||||
|
uid?: string
|
||||||
|
}
|
||||||
// Whether annotation is enabled.
|
// Whether annotation is enabled.
|
||||||
enable: bool | *true
|
enable: bool | *true
|
||||||
// Whether to hide annotation.
|
// Whether to hide annotation.
|
||||||
@ -305,7 +308,7 @@ Family: scuemata.#Family & {
|
|||||||
}
|
}
|
||||||
// Embed the disjunction of all injected panel schema, if any were injected.
|
// Embed the disjunction of all injected panel schema, if any were injected.
|
||||||
if len(compose._panelSchemas) > 0 {
|
if len(compose._panelSchemas) > 0 {
|
||||||
or(compose._panelSchemas) // TODO try to stick graph in here
|
or(compose._panelSchemas)// TODO try to stick graph in here
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make the plugin-composed subtrees open if the panel is
|
// Make the plugin-composed subtrees open if the panel is
|
||||||
@ -334,7 +337,10 @@ Family: scuemata.#Family & {
|
|||||||
title?: string
|
title?: string
|
||||||
|
|
||||||
// Name of default datasource.
|
// Name of default datasource.
|
||||||
datasource?: string
|
datasource: {
|
||||||
|
type?: string
|
||||||
|
uid?: string
|
||||||
|
}
|
||||||
|
|
||||||
gridPos?: {
|
gridPos?: {
|
||||||
// Panel
|
// Panel
|
||||||
@ -353,6 +359,7 @@ Family: scuemata.#Family & {
|
|||||||
// Name of template variable to repeat for.
|
// Name of template variable to repeat for.
|
||||||
repeat?: string
|
repeat?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Support for legacy graph panels.
|
// Support for legacy graph panels.
|
||||||
#GraphPanel: {
|
#GraphPanel: {
|
||||||
...
|
...
|
||||||
@ -384,8 +391,8 @@ Family: scuemata.#Family & {
|
|||||||
value_type: *"individual" | "cumulative"
|
value_type: *"individual" | "cumulative"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
]
|
],
|
||||||
]
|
]
|
||||||
compose: {
|
compose: {
|
||||||
// Scuemata families for all panel types that should be composed into the
|
// Scuemata families for all panel types that should be composed into the
|
||||||
@ -393,8 +400,8 @@ Family: scuemata.#Family & {
|
|||||||
Panel: [string]: scuemata.#PanelFamily
|
Panel: [string]: scuemata.#PanelFamily
|
||||||
|
|
||||||
// _panelTypes: [for typ, _ in Panel {typ}]
|
// _panelTypes: [for typ, _ in Panel {typ}]
|
||||||
_panelTypes: [for typ, _ in Panel {typ}, "graph", "row"]
|
_panelTypes: [ for typ, _ in Panel {typ}, "graph", "row"]
|
||||||
_panelSchemas: [for typ, scue in Panel {
|
_panelSchemas: [ for typ, scue in Panel {
|
||||||
for lv, lin in scue.lineages {
|
for lv, lin in scue.lineages {
|
||||||
for sv, sch in lin {
|
for sv, sch in lin {
|
||||||
(_mapPanel & {arg: {
|
(_mapPanel & {arg: {
|
||||||
@ -404,7 +411,7 @@ Family: scuemata.#Family & {
|
|||||||
}}).out
|
}}).out
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, { type: string }]
|
}, {type: string}]
|
||||||
_mapPanel: {
|
_mapPanel: {
|
||||||
arg: {
|
arg: {
|
||||||
type: string & !=""
|
type: string & !=""
|
||||||
|
@ -7,7 +7,7 @@ name: "dashboard"
|
|||||||
seqs: [
|
seqs: [
|
||||||
{
|
{
|
||||||
schemas: [
|
schemas: [
|
||||||
{ // 0.0
|
{// 0.0
|
||||||
// Unique numeric identifier for the dashboard.
|
// Unique numeric identifier for the dashboard.
|
||||||
// TODO must isolate or remove identifiers local to a Grafana instance...?
|
// TODO must isolate or remove identifiers local to a Grafana instance...?
|
||||||
id?: int64
|
id?: int64
|
||||||
@ -53,7 +53,10 @@ seqs: [
|
|||||||
annotations?: list: [...{
|
annotations?: list: [...{
|
||||||
builtIn: uint8 | *0
|
builtIn: uint8 | *0
|
||||||
// Datasource to use for annotation.
|
// Datasource to use for annotation.
|
||||||
datasource: string
|
datasource: {
|
||||||
|
type?: string
|
||||||
|
uid?: string
|
||||||
|
}
|
||||||
// Whether annotation is enabled.
|
// Whether annotation is enabled.
|
||||||
enable: bool | *true
|
enable: bool | *true
|
||||||
// Whether to hide annotation.
|
// Whether to hide annotation.
|
||||||
@ -310,7 +313,10 @@ seqs: [
|
|||||||
title?: string
|
title?: string
|
||||||
|
|
||||||
// Name of default datasource.
|
// Name of default datasource.
|
||||||
datasource?: string
|
datasource?: {
|
||||||
|
type?: string
|
||||||
|
uid?: string
|
||||||
|
}
|
||||||
|
|
||||||
gridPos?: {
|
gridPos?: {
|
||||||
// Panel
|
// Panel
|
||||||
@ -329,16 +335,17 @@ seqs: [
|
|||||||
// Name of template variable to repeat for.
|
// Name of template variable to repeat for.
|
||||||
repeat?: string
|
repeat?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Support for legacy graph and heatmap panels.
|
// Support for legacy graph and heatmap panels.
|
||||||
#GraphPanel: {
|
#GraphPanel: {
|
||||||
...
|
|
||||||
type: "graph"
|
type: "graph"
|
||||||
|
...
|
||||||
}
|
}
|
||||||
#HeatmapPanel: {
|
#HeatmapPanel: {
|
||||||
...
|
|
||||||
type: "heatmap"
|
type: "heatmap"
|
||||||
|
...
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
]
|
]
|
||||||
}
|
},
|
||||||
]
|
]
|
||||||
|
@ -17,6 +17,15 @@ var (
|
|||||||
currentVersion = thema.SV(0, 0)
|
currentVersion = thema.SV(0, 0)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// HandoffSchemaVersion is the minimum schemaVersion for dashboards at which the
|
||||||
|
// Thema-based dashboard schema is known to be valid.
|
||||||
|
//
|
||||||
|
// schemaVersion is the original version numbering system for dashboards. If a
|
||||||
|
// dashboard is below this schemaVersion, it is necessary for the frontend
|
||||||
|
// typescript dashboard migration logic to first run and get it past this
|
||||||
|
// number, after which Thema can take over.
|
||||||
|
const HandoffSchemaVersion = 36
|
||||||
|
|
||||||
// Lineage returns the Thema lineage representing Grafana dashboards. The
|
// Lineage returns the Thema lineage representing Grafana dashboards. The
|
||||||
// lineage is the canonical specification of the current datasource schema, all
|
// lineage is the canonical specification of the current datasource schema, all
|
||||||
// prior schema versions, and the mappings that allow migration between schema
|
// prior schema versions, and the mappings that allow migration between schema
|
||||||
@ -80,7 +89,7 @@ type model struct {
|
|||||||
SchemaVersion int `json:"schemaVersion"`
|
SchemaVersion int `json:"schemaVersion"`
|
||||||
Panels []interface{} `json:"panels"`
|
Panels []interface{} `json:"panels"`
|
||||||
|
|
||||||
////
|
// //
|
||||||
|
|
||||||
Uid string `json:"uid"`
|
Uid string `json:"uid"`
|
||||||
// OrgId int64 `json:"orgId"`
|
// OrgId int64 `json:"orgId"`
|
||||||
|
@ -19,6 +19,7 @@ import (
|
|||||||
"cuelang.org/go/cue/errors"
|
"cuelang.org/go/cue/errors"
|
||||||
"cuelang.org/go/cue/load"
|
"cuelang.org/go/cue/load"
|
||||||
cuejson "cuelang.org/go/pkg/encoding/json"
|
cuejson "cuelang.org/go/pkg/encoding/json"
|
||||||
|
"github.com/grafana/grafana/pkg/coremodel/dashboard"
|
||||||
"github.com/grafana/grafana/pkg/schema"
|
"github.com/grafana/grafana/pkg/schema"
|
||||||
"github.com/laher/mergefs"
|
"github.com/laher/mergefs"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
@ -48,7 +49,6 @@ var doTestAgainstDevenv = func(sch schema.VersionedCueSchema, validdir string, f
|
|||||||
b, err := os.Open(path)
|
b, err := os.Open(path)
|
||||||
require.NoError(t, err, "failed to open dashboard file")
|
require.NoError(t, err, "failed to open dashboard file")
|
||||||
|
|
||||||
// Only try to validate dashboards with schemaVersion >= 30
|
|
||||||
jtree := make(map[string]interface{})
|
jtree := make(map[string]interface{})
|
||||||
byt, err := io.ReadAll(b)
|
byt, err := io.ReadAll(b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -59,9 +59,9 @@ var doTestAgainstDevenv = func(sch schema.VersionedCueSchema, validdir string, f
|
|||||||
t.Logf("no schemaVersion in %s", path)
|
t.Logf("no schemaVersion in %s", path)
|
||||||
return nil
|
return nil
|
||||||
} else {
|
} else {
|
||||||
if !(oldschemav.(float64) > 32) {
|
if !(oldschemav.(float64) > dashboard.HandoffSchemaVersion-1) {
|
||||||
if testing.Verbose() {
|
if testing.Verbose() {
|
||||||
t.Logf("schemaVersion is %v, older than 33, skipping %s", oldschemav, path)
|
t.Logf("schemaVersion is %v, older than %v, skipping %s", oldschemav, dashboard.HandoffSchemaVersion-1, path)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
SED=$(command -v gsed)
|
SED=$(command -v gsed)
|
||||||
SED=${SED:-"sed"}
|
SED=${SED:-"sed"}
|
||||||
|
|
||||||
FILES=$(grep -rl '"schemaVersion": 3[34]' devenv)
|
FILES=$(grep -rl '"schemaVersion": 3[3456]' devenv)
|
||||||
set -e
|
set -e
|
||||||
set -x
|
set -x
|
||||||
for DASH in ${FILES}; do echo "${DASH}"; grep -v 'null,$' "${DASH}" > "${DASH}-nulless"; mv "${DASH}-nulless" "${DASH}"; done
|
for DASH in ${FILES}; do echo "${DASH}"; grep -v 'null,$' "${DASH}" > "${DASH}-nulless"; mv "${DASH}-nulless" "${DASH}"; done
|
||||||
|
Reference in New Issue
Block a user