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 4 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. 15
      packages/grafana-schema/src/scuemata/dashboard/dashboard.cue
  4. 19
      pkg/coremodel/dashboard/lineage.cue
  5. 9
      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{}) 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",

@ -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.
@ -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

@ -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

@ -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

Loading…
Cancel
Save