Skip to content

Commit bba4d9b

Browse files
author
sam boyer
authored
Introduce "scuemata" system for CUE-based specification of Grafana objects (#32527)
1 parent 7351645 commit bba4d9b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+2446
-1136
lines changed

.drone.yml

-64
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,6 @@ steps:
5151
depends_on:
5252
- initialize
5353

54-
- name: check-dashboard-schemas
55-
image: grafana/build-container:1.4.1
56-
commands:
57-
- cue export --out openapi -o - ./dashboard-schemas/...
58-
depends_on:
59-
- initialize
60-
6154
- name: test-backend
6255
image: grafana/build-container:1.4.1
6356
commands:
@@ -114,7 +107,6 @@ steps:
114107
- test-frontend
115108
- codespell
116109
- shellcheck
117-
- check-dashboard-schemas
118110

119111
- name: package
120112
image: grafana/build-container:1.4.1
@@ -305,13 +297,6 @@ steps:
305297
depends_on:
306298
- initialize
307299

308-
- name: check-dashboard-schemas
309-
image: grafana/build-container:1.4.1
310-
commands:
311-
- cue export --out openapi -o - ./dashboard-schemas/...
312-
depends_on:
313-
- initialize
314-
315300
- name: test-backend
316301
image: grafana/build-container:1.4.1
317302
commands:
@@ -382,7 +367,6 @@ steps:
382367
- test-frontend
383368
- codespell
384369
- shellcheck
385-
- check-dashboard-schemas
386370

387371
- name: package
388372
image: grafana/build-container:1.4.1
@@ -761,13 +745,6 @@ steps:
761745
depends_on:
762746
- initialize
763747

764-
- name: check-dashboard-schemas
765-
image: grafana/build-container:1.4.1
766-
commands:
767-
- cue export --out openapi -o - ./dashboard-schemas/...
768-
depends_on:
769-
- initialize
770-
771748
- name: test-backend
772749
image: grafana/build-container:1.4.1
773750
commands:
@@ -830,7 +807,6 @@ steps:
830807
- test-frontend
831808
- codespell
832809
- shellcheck
833-
- check-dashboard-schemas
834810

835811
- name: package
836812
image: grafana/build-container:1.4.1
@@ -1137,13 +1113,6 @@ steps:
11371113
depends_on:
11381114
- initialize
11391115

1140-
- name: check-dashboard-schemas
1141-
image: grafana/build-container:1.4.1
1142-
commands:
1143-
- cue export --out openapi -o - ./dashboard-schemas/...
1144-
depends_on:
1145-
- initialize
1146-
11471116
- name: test-backend
11481117
image: grafana/build-container:1.4.1
11491118
commands:
@@ -1237,7 +1206,6 @@ steps:
12371206
- test-frontend
12381207
- codespell
12391208
- shellcheck
1240-
- check-dashboard-schemas
12411209
- build-backend-enterprise2
12421210
- test-backend-enterprise2
12431211

@@ -1712,13 +1680,6 @@ steps:
17121680
depends_on:
17131681
- initialize
17141682

1715-
- name: check-dashboard-schemas
1716-
image: grafana/build-container:1.4.1
1717-
commands:
1718-
- cue export --out openapi -o - ./dashboard-schemas/...
1719-
depends_on:
1720-
- initialize
1721-
17221683
- name: test-backend
17231684
image: grafana/build-container:1.4.1
17241685
commands:
@@ -1781,7 +1742,6 @@ steps:
17811742
- test-frontend
17821743
- codespell
17831744
- shellcheck
1784-
- check-dashboard-schemas
17851745

17861746
- name: package
17871747
image: grafana/build-container:1.4.1
@@ -2077,13 +2037,6 @@ steps:
20772037
depends_on:
20782038
- initialize
20792039

2080-
- name: check-dashboard-schemas
2081-
image: grafana/build-container:1.4.1
2082-
commands:
2083-
- cue export --out openapi -o - ./dashboard-schemas/...
2084-
depends_on:
2085-
- initialize
2086-
20872040
- name: test-backend
20882041
image: grafana/build-container:1.4.1
20892042
commands:
@@ -2177,7 +2130,6 @@ steps:
21772130
- test-frontend
21782131
- codespell
21792132
- shellcheck
2180-
- check-dashboard-schemas
21812133
- build-backend-enterprise2
21822134
- test-backend-enterprise2
21832135

@@ -2645,13 +2597,6 @@ steps:
26452597
depends_on:
26462598
- initialize
26472599

2648-
- name: check-dashboard-schemas
2649-
image: grafana/build-container:1.4.1
2650-
commands:
2651-
- cue export --out openapi -o - ./dashboard-schemas/...
2652-
depends_on:
2653-
- initialize
2654-
26552600
- name: test-backend
26562601
image: grafana/build-container:1.4.1
26572602
commands:
@@ -2711,7 +2656,6 @@ steps:
27112656
- test-frontend
27122657
- codespell
27132658
- shellcheck
2714-
- check-dashboard-schemas
27152659

27162660
- name: package
27172661
image: grafana/build-container:1.4.1
@@ -2981,13 +2925,6 @@ steps:
29812925
depends_on:
29822926
- initialize
29832927

2984-
- name: check-dashboard-schemas
2985-
image: grafana/build-container:1.4.1
2986-
commands:
2987-
- cue export --out openapi -o - ./dashboard-schemas/...
2988-
depends_on:
2989-
- initialize
2990-
29912928
- name: test-backend
29922929
image: grafana/build-container:1.4.1
29932930
commands:
@@ -3075,7 +3012,6 @@ steps:
30753012
- test-frontend
30763013
- codespell
30773014
- shellcheck
3078-
- check-dashboard-schemas
30793015
- build-backend-enterprise2
30803016
- test-backend-enterprise2
30813017

cue.mod/module.cue

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module: "github.com/grafana/grafana"

cue/data/gen.cue

+213
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
package grafanaschema
2+
3+
import "github.com/grafana/grafana/cue/scuemata"
4+
5+
Family: scuemata.#Family & {
6+
lineages: [
7+
[
8+
{ // 0.0
9+
// Unique numeric identifier for the dashboard.
10+
// TODO must isolate or remove identifiers local to a Grafana instance...?
11+
id?: number
12+
// Unique dashboard identifier that can be generated by anyone. string (8-40)
13+
uid: string
14+
// Title of dashboard.
15+
title?: string
16+
// Description of dashboard.
17+
description?: string
18+
19+
gnetId?: string
20+
// Tags associated with dashboard.
21+
tags?: [...string]
22+
// Theme of dashboard.
23+
style: *"light" | "dark"
24+
// Timezone of dashboard,
25+
timezone?: *"browser" | "utc"
26+
// Whether a dashboard is editable or not.
27+
editable: bool | *true
28+
// 0 for no shared crosshair or tooltip (default).
29+
// 1 for shared crosshair.
30+
// 2 for shared crosshair AND shared tooltip.
31+
graphTooltip: >=0 & <=2 | *0
32+
// Time range for dashboard, e.g. last 6 hours, last 7 days, etc
33+
time?: {
34+
from: string | *"now-6h"
35+
to: string | *"now"
36+
}
37+
// Timepicker metadata.
38+
timepicker?: {
39+
// Whether timepicker is collapsed or not.
40+
collapse: bool | *false
41+
// Whether timepicker is enabled or not.
42+
enable: bool | *true
43+
// Whether timepicker is visible or not.
44+
hidden: bool | *false
45+
// Selectable intervals for auto-refresh.
46+
refresh_intervals: [...string] | *["5s", "10s", "30s", "1m", "5m", "15m", "30m", "1h", "2h", "1d"]
47+
}
48+
// Templating.
49+
templating?: list: [...{...}]
50+
// Annotations.
51+
annotations?: list: [...{
52+
builtIn: number | *0
53+
// Datasource to use for annotation.
54+
datasource: string
55+
// Whether annotation is enabled.
56+
enable?: bool | *true
57+
// Whether to hide annotation.
58+
hide?: bool | *false
59+
// Annotation icon color.
60+
iconColor?: string
61+
// Name of annotation.
62+
name?: string
63+
type: string | *"dashboard"
64+
// Query for annotation data.
65+
rawQuery?: string
66+
showIn: number | *0
67+
}]
68+
// Auto-refresh interval.
69+
refresh?: string
70+
// Version of the JSON schema, incremented each time a Grafana update brings
71+
// changes to said schema.
72+
schemaVersion: number | *25
73+
// Version of the dashboard, incremented each time the dashboard is updated.
74+
version?: number
75+
panels?: [...#Panel]
76+
77+
// Dashboard panels. Panels are canonically defined inline
78+
// because they share a version timeline with the dashboard
79+
// schema; they do not vary independently. We create a separate,
80+
// synthetic Family to represent them in Go, for ease of generating
81+
// e.g. JSON Schema.
82+
#Panel: {
83+
// The panel plugin type id.
84+
type: !=""
85+
86+
// Internal - the exact major and minor versions of the panel plugin
87+
// schema. Hidden and therefore not a part of the data model, but
88+
// expected to be filled with panel plugin schema versions so that it's
89+
// possible to figure out which schema version matched on a successful
90+
// unification.
91+
// _pv: { maj: int, min: int }
92+
// The major and minor versions of the panel plugin for this schema.
93+
// TODO 2-tuple list instead of struct?
94+
panelSchema: { maj: number, min: number }
95+
96+
// Panel title.
97+
title?: string
98+
// Description.
99+
description?: string
100+
// Whether to display the panel without a background.
101+
transparent: bool | *false
102+
// Name of default datasource.
103+
datasource?: string
104+
// Grid position.
105+
gridPos?: {
106+
// Panel
107+
h: number & >0 | *9
108+
// Panel
109+
w: number & >0 & <=24 | *12
110+
// Panel x
111+
x: number & >=0 & <24 | *0
112+
// Panel y
113+
y: number & >=0 | *0
114+
// true if fixed
115+
static?: bool
116+
}
117+
// Panel links.
118+
// links?: [..._panelLink]
119+
// Name of template variable to repeat for.
120+
repeat?: string
121+
// Direction to repeat in if 'repeat' is set.
122+
// "h" for horizontal, "v" for vertical.
123+
repeatDirection: *"h" | "v"
124+
// Schema for panel targets is specified by datasource
125+
// plugins. We use a placeholder definition, which the Go
126+
// schema loader either left open/as-is with the Base
127+
// variant of the Dashboard and Panel families, or filled
128+
// with types derived from plugins in the Instance variant.
129+
// When working directly from CUE, importers can extend this
130+
// type directly to achieve the same effect.
131+
targets?: [...{}]
132+
133+
// The values depend on panel type
134+
options: {...}
135+
136+
fieldConfig: {
137+
defaults: {
138+
// The display value for this field. This supports template variables blank is auto
139+
displayName?: string
140+
141+
// This can be used by data sources that return and explicit naming structure for values and labels
142+
// When this property is configured, this value is used rather than the default naming strategy.
143+
displayNameFromDS?: string
144+
145+
// Human readable field metadata
146+
description?: string
147+
148+
// An explict path to the field in the datasource. When the frame meta includes a path,
149+
// This will default to `${frame.meta.path}/${field.name}
150+
//
151+
// When defined, this value can be used as an identifier within the datasource scope, and
152+
// may be used to update the results
153+
path?: string
154+
155+
// True if data source can write a value to the path. Auth/authz are supported separately
156+
writeable?: bool
157+
158+
// True if data source field supports ad-hoc filters
159+
filterable?: bool
160+
161+
// Numeric Options
162+
unit?: string
163+
164+
// Significant digits (for display)
165+
decimals?: number
166+
167+
min?: number
168+
max?: number
169+
170+
// // Convert input values into a display string
171+
// mappings?: ValueMapping[];
172+
173+
// // Map numeric values to states
174+
// thresholds?: ThresholdsConfig;
175+
176+
// // Map values to a display color
177+
// color?: FieldColor;
178+
179+
// // Used when reducing field values
180+
// nullValueMode?: NullValueMode;
181+
182+
// // The behavior when clicking on a result
183+
// links?: DataLink[];
184+
185+
// Alternative to empty string
186+
noValue?: string
187+
188+
// Can always exist. Valid fields within this are
189+
// defined by the panel plugin - that's the
190+
// PanelFieldConfig that comes from the plugin.
191+
custom?: {...}
192+
}
193+
overrides: [...{
194+
matcher: {
195+
id: string | *""
196+
options?: _
197+
}
198+
properties: [...{
199+
id: string | *""
200+
value?: _
201+
}]
202+
}]
203+
}
204+
}
205+
}
206+
]
207+
]
208+
}
209+
210+
#Latest: {
211+
#Dashboard: Family.latest
212+
#Panel: Family.latest._Panel
213+
}

0 commit comments

Comments
 (0)