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>
pull/47902/head
sam boyer 3 years ago committed by GitHub
parent 031a8e140a
commit 5e11af0121
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      devenv/dev-dashboards/dashboards_test.go
  2. 83
      devenv/dev-dashboards/panel-graph/graph-ng-stacking2.json
  3. 25
      packages/grafana-schema/src/scuemata/dashboard/dashboard.cue
  4. 21
      pkg/coremodel/dashboard/lineage.cue
  5. 11
      pkg/coremodel/dashboard/schema.go
  6. 6
      pkg/schema/load/load_test.go
  7. 2
      scripts/stripnulls.sh

@ -68,7 +68,7 @@ func themaTestableDashboards() (map[string][]byte, error) {
jtree := make(map[string]interface{})
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
}

@ -71,8 +71,7 @@
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
"color": "green"
},
{
"color": "red",
@ -178,8 +177,7 @@
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
"color": "green"
},
{
"color": "red",
@ -266,8 +264,7 @@
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
"color": "green"
},
{
"color": "red",
@ -354,8 +351,7 @@
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
"color": "green"
},
{
"color": "red",
@ -485,8 +481,7 @@
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
"color": "green"
},
{
"color": "red",
@ -573,8 +568,7 @@
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
"color": "green"
},
{
"color": "red",
@ -661,8 +655,7 @@
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
"color": "green"
},
{
"color": "red",
@ -792,8 +785,7 @@
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
"color": "green"
},
{
"color": "red",
@ -893,8 +885,7 @@
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
"color": "green"
},
{
"color": "red",
@ -982,8 +973,7 @@
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
"color": "green"
},
{
"color": "red",
@ -1069,8 +1059,7 @@
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
"color": "green"
},
{
"color": "red",
@ -1155,8 +1144,7 @@
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
"color": "green"
},
{
"color": "red",
@ -1253,8 +1241,7 @@
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
"color": "green"
},
{
"color": "red",
@ -1354,8 +1341,7 @@
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
"color": "green"
},
{
"color": "red",
@ -1455,8 +1441,7 @@
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
"color": "green"
},
{
"color": "red",
@ -1555,8 +1540,7 @@
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
"color": "green"
},
{
"color": "red",
@ -1692,8 +1676,7 @@
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
"color": "green"
},
{
"color": "red",
@ -1800,8 +1783,7 @@
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
"color": "green"
},
{
"color": "red",
@ -1909,8 +1891,7 @@
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
"color": "green"
},
{
"color": "red",
@ -2040,8 +2021,7 @@
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
"color": "green"
},
{
"color": "red",
@ -2128,8 +2108,7 @@
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
"color": "green"
},
{
"color": "red",
@ -2240,8 +2219,7 @@
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
"color": "green"
},
{
"color": "red",
@ -2356,8 +2334,7 @@
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
"color": "green"
},
{
"color": "red",
@ -2460,8 +2437,7 @@
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
"color": "green"
},
{
"color": "red",
@ -2564,8 +2540,7 @@
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
"color": "green"
},
{
"color": "red",
@ -2701,8 +2676,7 @@
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
"color": "green"
},
{
"color": "red",
@ -2838,8 +2812,7 @@
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
"color": "green"
},
{
"color": "red",
@ -2934,7 +2907,7 @@
}
],
"refresh": false,
"schemaVersion": 32,
"schemaVersion": 36,
"style": "dark",
"tags": [
"gdev",

@ -9,7 +9,7 @@ import (
Family: scuemata.#Family & {
lineages: [
[
{ // 0.0
{// 0.0
// Unique numeric identifier for the dashboard.
// TODO must isolate or remove identifiers local to a Grafana instance...?
id?: number
@ -55,7 +55,10 @@ Family: scuemata.#Family & {
annotations?: list: [...{
builtIn: number | *0
// Datasource to use for annotation.
datasource: string
datasource: {
type?: string
uid?: string
}
// Whether annotation is enabled.
enable: bool | *true
// Whether to hide annotation.
@ -305,7 +308,7 @@ Family: scuemata.#Family & {
}
// Embed the disjunction of all injected panel schema, if any were injected.
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
@ -334,7 +337,10 @@ Family: scuemata.#Family & {
title?: string
// Name of default datasource.
datasource?: string
datasource: {
type?: string
uid?: string
}
gridPos?: {
// Panel
@ -353,6 +359,7 @@ Family: scuemata.#Family & {
// Name of template variable to repeat for.
repeat?: string
}
// Support for legacy graph panels.
#GraphPanel: {
...
@ -384,8 +391,8 @@ Family: scuemata.#Family & {
value_type: *"individual" | "cumulative"
}
}
}
]
},
],
]
compose: {
// Scuemata families for all panel types that should be composed into the
@ -393,8 +400,8 @@ Family: scuemata.#Family & {
Panel: [string]: scuemata.#PanelFamily
// _panelTypes: [for typ, _ in Panel {typ}]
_panelTypes: [for typ, _ in Panel {typ}, "graph", "row"]
_panelSchemas: [for typ, scue in Panel {
_panelTypes: [ for typ, _ in Panel {typ}, "graph", "row"]
_panelSchemas: [ for typ, scue in Panel {
for lv, lin in scue.lineages {
for sv, sch in lin {
(_mapPanel & {arg: {
@ -404,7 +411,7 @@ Family: scuemata.#Family & {
}}).out
}
}
}, { type: string }]
}, {type: string}]
_mapPanel: {
arg: {
type: string & !=""

@ -7,7 +7,7 @@ name: "dashboard"
seqs: [
{
schemas: [
{ // 0.0
{// 0.0
// Unique numeric identifier for the dashboard.
// TODO must isolate or remove identifiers local to a Grafana instance...?
id?: int64
@ -53,7 +53,10 @@ seqs: [
annotations?: list: [...{
builtIn: uint8 | *0
// Datasource to use for annotation.
datasource: string
datasource: {
type?: string
uid?: string
}
// Whether annotation is enabled.
enable: bool | *true
// Whether to hide annotation.
@ -310,7 +313,10 @@ seqs: [
title?: string
// Name of default datasource.
datasource?: string
datasource?: {
type?: string
uid?: string
}
gridPos?: {
// Panel
@ -329,16 +335,17 @@ seqs: [
// Name of template variable to repeat for.
repeat?: string
}
// Support for legacy graph and heatmap panels.
#GraphPanel: {
...
type: "graph"
...
}
#HeatmapPanel: {
...
type: "heatmap"
...
}
}
},
]
}
},
]

@ -17,6 +17,15 @@ var (
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 is the canonical specification of the current datasource schema, all
// prior schema versions, and the mappings that allow migration between schema
@ -80,7 +89,7 @@ type model struct {
SchemaVersion int `json:"schemaVersion"`
Panels []interface{} `json:"panels"`
////
// //
Uid string `json:"uid"`
// OrgId int64 `json:"orgId"`

@ -19,6 +19,7 @@ import (
"cuelang.org/go/cue/errors"
"cuelang.org/go/cue/load"
cuejson "cuelang.org/go/pkg/encoding/json"
"github.com/grafana/grafana/pkg/coremodel/dashboard"
"github.com/grafana/grafana/pkg/schema"
"github.com/laher/mergefs"
"github.com/stretchr/testify/require"
@ -48,7 +49,6 @@ var doTestAgainstDevenv = func(sch schema.VersionedCueSchema, validdir string, f
b, err := os.Open(path)
require.NoError(t, err, "failed to open dashboard file")
// Only try to validate dashboards with schemaVersion >= 30
jtree := make(map[string]interface{})
byt, err := io.ReadAll(b)
if err != nil {
@ -59,9 +59,9 @@ var doTestAgainstDevenv = func(sch schema.VersionedCueSchema, validdir string, f
t.Logf("no schemaVersion in %s", path)
return nil
} else {
if !(oldschemav.(float64) > 32) {
if !(oldschemav.(float64) > dashboard.HandoffSchemaVersion-1) {
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
}

@ -7,7 +7,7 @@
SED=$(command -v gsed)
SED=${SED:-"sed"}
FILES=$(grep -rl '"schemaVersion": 3[34]' devenv)
FILES=$(grep -rl '"schemaVersion": 3[3456]' devenv)
set -e
set -x
for DASH in ${FILES}; do echo "${DASH}"; grep -v 'null,$' "${DASH}" > "${DASH}-nulless"; mv "${DASH}-nulless" "${DASH}"; done

Loading…
Cancel
Save