Skip to content

Instantly share code, notes, and snippets.

@sdboyer
Created July 31, 2023 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sdboyer/10c1f232bd7ef7f316f75d154cacad91 to your computer and use it in GitHub Desktop.
Save sdboyer/10c1f232bd7ef7f316f75d154cacad91 to your computer and use it in GitHub Desktop.
dashboard kind as JSON+JSON Schema
{
"name": "Dashboard",
"maturity": "experimental",
"description": "A Grafana dashboard.",
"lineage": {
"schemas": [
{
"version": [
0,
0
],
"schema": {
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"required": [
"metadata",
"spec",
"status"
],
"properties": {
"metadata": {
"description": "metadata contains embedded CommonMetadata and can be extended with custom string fields\nTODO: use CommonMetadata instead of redefining here; currently needs to be defined here\nwithout external reference as using the CommonMetadata reference breaks thema codegen.",
"type": "object",
"properties": {
"updateTimestamp": {
"type": "string",
"format": "date-time"
},
"createdBy": {
"type": "string"
},
"updatedBy": {
"type": "string"
},
"extraFields": {
"description": "extraFields is reserved for any fields that are pulled from the API server metadata but do not have concrete fields in the CUE metadata",
"type": "object"
}
},
"allOf": [
{
"$ref": "#$defs/_kubeObjectMetadata"
},
{
"required": [
"updateTimestamp",
"createdBy",
"updatedBy",
"extraFields"
]
}
]
},
"spec": {
"type": "object",
"required": [
"style",
"editable",
"graphTooltip",
"schemaVersion"
],
"properties": {
"id": {
"description": "Unique numeric identifier for the dashboard.\n`id` is internal to a specific Grafana instance. `uid` should be used to identify a dashboard across Grafana instances.",
"type": [
"integer",
"null"
],
"format": "int64"
},
"uid": {
"description": "Unique dashboard identifier that can be generated by anyone. string (8-40)",
"type": "string"
},
"title": {
"description": "Title of dashboard.",
"type": "string"
},
"description": {
"description": "Description of dashboard.",
"type": "string"
},
"revision": {
"description": "This property should only be used in dashboards defined by plugins. It is a quick check\nto see if the version has changed since the last time.",
"type": "integer",
"format": "int64"
},
"gnetId": {
"description": "ID of a dashboard imported from the https://grafana.com/grafana/dashboards/ portal",
"type": "string"
},
"tags": {
"description": "Tags associated with dashboard.",
"type": "array",
"items": {
"type": "string"
}
},
"style": {
"description": "Theme of dashboard.\nDefault value: dark.",
"type": "string",
"enum": [
"dark",
"light"
],
"default": "dark"
},
"timezone": {
"description": "Timezone of dashboard. Accepted values are IANA TZDB zone ID or \"browser\" or \"utc\".",
"type": "string",
"default": "browser"
},
"editable": {
"description": "Whether a dashboard is editable or not.",
"type": "boolean",
"default": true
},
"graphTooltip": {
"$ref": "#$defs/DashboardCursorSync"
},
"time": {
"description": "Time range for dashboard.\nAccepted values are relative time strings like {from: 'now-6h', to: 'now'} or absolute time strings like {from: '2020-07-10T08:00:00.000Z', to: '2020-07-10T14:00:00.000Z'}.",
"type": "object",
"required": [
"from",
"to"
],
"properties": {
"from": {
"type": "string",
"default": "now-6h"
},
"to": {
"type": "string",
"default": "now"
}
}
},
"timepicker": {
"description": "Configuration of the time picker shown at the top of a dashboard.",
"type": "object",
"required": [
"hidden",
"refresh_intervals",
"collapse",
"enable",
"time_options"
],
"properties": {
"hidden": {
"description": "Whether timepicker is visible or not.",
"type": "boolean",
"default": false
},
"refresh_intervals": {
"description": "Interval options available in the refresh picker dropdown.",
"type": "array",
"items": {
"type": "string"
},
"default": [
"5s",
"10s",
"30s",
"1m",
"5m",
"15m",
"30m",
"1h",
"2h",
"1d"
]
},
"collapse": {
"description": "Whether timepicker is collapsed or not. Has no effect on provisioned dashboard.",
"type": "boolean",
"default": false
},
"enable": {
"description": "Whether timepicker is enabled or not. Has no effect on provisioned dashboard.",
"type": "boolean",
"default": true
},
"time_options": {
"description": "Selectable options available in the time picker dropdown. Has no effect on provisioned dashboard.",
"type": "array",
"items": {
"type": "string"
},
"default": [
"5m",
"15m",
"1h",
"6h",
"12h",
"24h",
"2d",
"7d",
"30d"
]
}
}
},
"fiscalYearStartMonth": {
"description": "The month that the fiscal year starts on. 0 = January, 11 = December",
"type": "integer",
"minimum": 0,
"maximum": 12,
"exclusiveMaximum": true,
"default": 0
},
"liveNow": {
"description": "When set to true, the dashboard will redraw panels at an interval matching the pixel width.\nThis will keep data \"moving left\" regardless of the query refresh rate. This setting helps\navoid dashboards presenting stale live data",
"type": "boolean"
},
"weekStart": {
"description": "Day when the week starts. Expressed by the name of the day in lowercase, e.g. \"monday\".",
"type": "string"
},
"refresh": {
"description": "Refresh rate of dashboard. Represented via interval string, e.g. \"5s\", \"1m\", \"1h\", \"1d\".",
"oneOf": [
{
"enum": [
false
]
},
{
"type": "string"
}
]
},
"schemaVersion": {
"description": "Version of the JSON schema, incremented each time a Grafana update brings\nchanges to said schema.",
"type": "integer",
"minimum": 0,
"maximum": 65535,
"default": 36
},
"version": {
"description": "Version of the dashboard, incremented each time the dashboard is updated.",
"type": "integer",
"minimum": 0,
"maximum": 4294967295
},
"panels": {
"description": "List of dashboard panels",
"type": "array",
"items": {
"type": "object",
"oneOf": [
{
"$ref": "#$defs/Panel"
},
{
"$ref": "#$defs/RowPanel"
},
{
"$ref": "#$defs/GraphPanel"
},
{
"$ref": "#$defs/HeatmapPanel"
}
]
}
},
"templating": {
"description": "Configured template variables",
"type": "object",
"properties": {
"list": {
"description": "List of configured template variables with their saved values along with some other metadata",
"type": "array",
"items": {
"$ref": "#$defs/VariableModel"
}
}
}
},
"annotations": {
"$ref": "#$defs/AnnotationContainer"
},
"links": {
"description": "Links with references to other dashboards or external websites.",
"type": "array",
"items": {
"$ref": "#$defs/DashboardLink"
}
},
"snapshot": {
"$ref": "#$defs/Snapshot"
}
}
},
"status": {
"type": "object",
"properties": {
"operatorStates": {
"description": "operatorStates is a map of operator ID to operator state evaluations.\nAny operator which consumes this kind SHOULD add its state evaluation information to this field.",
"type": "object",
"additionalProperties": {
"$ref": "#$defs/status.#OperatorState"
}
},
"additionalFields": {
"description": "additionalFields is reserved for future use",
"type": "object"
}
}
}
},
"$defs": {
"schemas": {
"AnnotationContainer": {
"description": "Contains the list of annotations that are associated with the dashboard.\nAnnotations are used to overlay event markers and overlay event tags on graphs.\nGrafana comes with a native annotation store and the ability to add annotation events directly from the graph panel or via the HTTP API.\nSee https://grafana.com/docs/grafana/latest/dashboards/build-dashboards/annotate-visualizations/",
"type": "object",
"properties": {
"list": {
"description": "List of annotations",
"type": "array",
"items": {
"$ref": "#$defs/AnnotationQuery"
}
}
},
"$schema": "http://json-schema.org/draft-04/schema#"
},
"AnnotationPanelFilter": {
"type": "object",
"required": [
"ids"
],
"properties": {
"exclude": {
"description": "Should the specified panels be included or excluded",
"type": "boolean",
"default": false
},
"ids": {
"description": "Panel IDs that should be included or excluded",
"type": "array",
"items": {
"type": "integer",
"minimum": 0,
"maximum": 255
}
}
},
"$schema": "http://json-schema.org/draft-04/schema#"
},
"AnnotationQuery": {
"description": "TODO docs\nFROM: AnnotationQuery in grafana-data/src/types/annotations.ts",
"type": "object",
"required": [
"name",
"datasource",
"enable",
"iconColor"
],
"properties": {
"name": {
"description": "Name of annotation.",
"type": "string"
},
"datasource": {
"$ref": "#$defs/DataSourceRef"
},
"enable": {
"description": "When enabled the annotation query is issued with every dashboard refresh",
"type": "boolean",
"default": true
},
"hide": {
"description": "Annotation queries can be toggled on or off at the top of the dashboard.\nWhen hide is true, the toggle is not shown in the dashboard.",
"type": "boolean",
"default": false
},
"iconColor": {
"description": "Color to use for the annotation event markers",
"type": "string"
},
"filter": {
"$ref": "#$defs/AnnotationPanelFilter"
},
"target": {
"$ref": "#$defs/AnnotationTarget"
},
"type": {
"description": "TODO -- this should not exist here, it is based on the --grafana-- datasource",
"type": "string"
}
},
"$schema": "http://json-schema.org/draft-04/schema#"
},
"AnnotationTarget": {
"description": "TODO: this should be a regular DataQuery that depends on the selected dashboard\nthese match the properties of the \"grafana\" datasouce that is default in most dashboards",
"type": "object",
"required": [
"limit",
"matchAny",
"tags",
"type"
],
"properties": {
"limit": {
"description": "Only required/valid for the grafana datasource...\nbut code+tests is already depending on it so hard to change",
"type": "integer",
"format": "int64"
},
"matchAny": {
"description": "Only required/valid for the grafana datasource...\nbut code+tests is already depending on it so hard to change",
"type": "boolean"
},
"tags": {
"description": "Only required/valid for the grafana datasource...\nbut code+tests is already depending on it so hard to change",
"type": "array",
"items": {
"type": "string"
}
},
"type": {
"description": "Only required/valid for the grafana datasource...\nbut code+tests is already depending on it so hard to change",
"type": "string"
}
},
"$schema": "http://json-schema.org/draft-04/schema#"
},
"DashboardCursorSync": {
"description": "0 for no shared crosshair or tooltip (default).\n1 for shared crosshair.\n2 for shared crosshair AND shared tooltip.",
"type": "integer",
"enum": [
0,
1,
2
],
"default": 0,
"$schema": "http://json-schema.org/draft-04/schema#"
},
"DashboardLink": {
"description": "Links with references to other dashboards or external resources",
"type": "object",
"required": [
"title",
"type",
"icon",
"tooltip",
"url",
"tags",
"asDropdown",
"targetBlank",
"includeVars",
"keepTime"
],
"properties": {
"title": {
"description": "Title to display with the link",
"type": "string"
},
"type": {
"$ref": "#$defs/DashboardLinkType"
},
"icon": {
"description": "Icon name to be displayed with the link",
"type": "string"
},
"tooltip": {
"description": "Tooltip to display when the user hovers their mouse over it",
"type": "string"
},
"url": {
"description": "Link URL. Only required/valid if the type is link",
"type": "string"
},
"tags": {
"description": "List of tags to limit the linked dashboards. If empty, all dashboards will be displayed. Only valid if the type is dashboards",
"type": "array",
"items": {
"type": "string"
}
},
"asDropdown": {
"description": "If true, all dashboards links will be displayed in a dropdown. If false, all dashboards links will be displayed side by side. Only valid if the type is dashboards",
"type": "boolean",
"default": false
},
"targetBlank": {
"description": "If true, the link will be opened in a new tab",
"type": "boolean",
"default": false
},
"includeVars": {
"description": "If true, includes current template variables values in the link as query params",
"type": "boolean",
"default": false
},
"keepTime": {
"description": "If true, includes current time range in the link as query params",
"type": "boolean",
"default": false
}
},
"$schema": "http://json-schema.org/draft-04/schema#"
},
"DashboardLinkType": {
"description": "Dashboard Link type. Accepted values are dashboards (to refer to another dashboard) and link (to refer to an external resource)",
"type": "string",
"enum": [
"link",
"dashboards"
],
"$schema": "http://json-schema.org/draft-04/schema#"
},
"DataSourceRef": {
"description": "Ref to a DataSource instance",
"type": "object",
"properties": {
"type": {
"description": "The plugin type-id",
"type": "string"
},
"uid": {
"description": "Specific datasource instance",
"type": "string"
}
},
"$schema": "http://json-schema.org/draft-04/schema#"
},
"DataTransformerConfig": {
"description": "Transformations allow to manipulate data returned by a query before the system applies a visualization.\nUsing transformations you can: rename fields, join time series data, perform mathematical operations across queries,\nuse the output of one transformation as the input to another transformation, etc.",
"type": "object",
"required": [
"id",
"options"
],
"properties": {
"id": {
"description": "Unique identifier of transformer",
"type": "string"
},
"disabled": {
"description": "Disabled transformations are skipped",
"type": "boolean"
},
"filter": {
"$ref": "#$defs/MatcherConfig"
},
"options": {
"description": "Options to be passed to the transformer\nValid options depend on the transformer id"
}
},
"$schema": "http://json-schema.org/draft-04/schema#"
},
"DynamicConfigValue": {
"type": "object",
"required": [
"id"
],
"properties": {
"id": {
"type": "string",
"default": ""
},
"value": {}
},
"$schema": "http://json-schema.org/draft-04/schema#"
},
"FieldColor": {
"description": "Map a field to a color.",
"type": "object",
"required": [
"mode"
],
"properties": {
"mode": {
"$ref": "#$defs/FieldColorModeId"
},
"fixedColor": {
"description": "The fixed color value for fixed or shades color modes.",
"type": "string"
},
"seriesBy": {
"$ref": "#$defs/FieldColorSeriesByMode"
}
},
"$schema": "http://json-schema.org/draft-04/schema#"
},
"FieldColorModeId": {
"description": "Color mode for a field. You can specify a single color, or select a continuous (gradient) color schemes, based on a value.\nContinuous color interpolates a color using the percentage of a value relative to min and max.\nAccepted values are:\n`thresholds`: From thresholds. Informs Grafana to take the color from the matching threshold\n`palette-classic`: Classic palette. Grafana will assign color by looking up a color in a palette by series index. Useful for Graphs and pie charts and other categorical data visualizations\n`palette-classic-by-name`: Classic palette (by name). Grafana will assign color by looking up a color in a palette by series name. Useful for Graphs and pie charts and other categorical data visualizations\n`continuous-GrYlRd`: ontinuous Green-Yellow-Red palette mode\n`continuous-RdYlGr`: Continuous Red-Yellow-Green palette mode\n`continuous-BlYlRd`: Continuous Blue-Yellow-Red palette mode\n`continuous-YlRd`: Continuous Yellow-Red palette mode\n`continuous-BlPu`: Continuous Blue-Purple palette mode\n`continuous-YlBl`: Continuous Yellow-Blue palette mode\n`continuous-blues`: Continuous Blue palette mode\n`continuous-reds`: Continuous Red palette mode\n`continuous-greens`: Continuous Green palette mode\n`continuous-purples`: Continuous Purple palette mode\n`shades`: Shades of a single color. Specify a single color, useful in an override rule.\n`fixed`: Fixed color mode. Specify a single color, useful in an override rule.",
"type": "string",
"enum": [
"thresholds",
"palette-classic",
"palette-classic-by-name",
"continuous-GrYlRd",
"continuous-RdYlGr",
"continuous-BlYlRd",
"continuous-YlRd",
"continuous-BlPu",
"continuous-YlBl",
"continuous-blues",
"continuous-reds",
"continuous-greens",
"continuous-purples",
"fixed",
"shades"
],
"$schema": "http://json-schema.org/draft-04/schema#"
},
"FieldColorSeriesByMode": {
"description": "Defines how to assign a series color from \"by value\" color schemes. For example for an aggregated data points like a timeseries, the color can be assigned by the min, max or last value.",
"type": "string",
"enum": [
"min",
"max",
"last"
],
"$schema": "http://json-schema.org/draft-04/schema#"
},
"FieldConfig": {
"description": "The data model used in Grafana, namely the data frame, is a columnar-oriented table structure that unifies both time series and table query results.\nEach column within this structure is called a field. A field can represent a single time series or table column.\nField options allow you to change how the data is displayed in your visualizations.",
"type": "object",
"properties": {
"displayName": {
"description": "The display value for this field. This supports template variables blank is auto",
"type": "string"
},
"displayNameFromDS": {
"description": "This can be used by data sources that return and explicit naming structure for values and labels\nWhen this property is configured, this value is used rather than the default naming strategy.",
"type": "string"
},
"description": {
"description": "Human readable field metadata",
"type": "string"
},
"path": {
"description": "An explicit path to the field in the datasource. When the frame meta includes a path,\nThis will default to `${frame.meta.path}/${field.name}\n\nWhen defined, this value can be used as an identifier within the datasource scope, and\nmay be used to update the results",
"type": "string"
},
"writeable": {
"description": "True if data source can write a value to the path. Auth/authz are supported separately",
"type": "boolean"
},
"filterable": {
"description": "True if data source field supports ad-hoc filters",
"type": "boolean"
},
"unit": {
"description": "Unit a field should use. The unit you select is applied to all fields except time.\nYou can use the units ID availables in Grafana or a custom unit.\nAvailable units in Grafana: https://github.com/grafana/grafana/blob/main/packages/grafana-data/src/valueFormats/categories.ts\nAs custom unit, you can use the following formats:\n`suffix:<suffix>` for custom unit that should go after value.\n`prefix:<prefix>` for custom unit that should go before value.\n`time:<format>` For custom date time formats type for example `time:YYYY-MM-DD`.\n`si:<base scale><unit characters>` for custom SI units. For example: `si: mF`. This one is a bit more advanced as you can specify both a unit and the source data scale. So if your source data is represented as milli (thousands of) something prefix the unit with that SI scale character.\n`count:<unit>` for a custom count unit.\n`currency:<unit>` for custom a currency unit.",
"type": "string"
},
"decimals": {
"description": "Specify the number of decimals Grafana includes in the rendered value.\nIf you leave this field blank, Grafana automatically truncates the number of decimals based on the value.\nFor example 1.1234 will display as 1.12 and 100.456 will display as 100.\nTo display all decimals, set the unit to `String`.",
"type": "number"
},
"min": {
"description": "The minimum value used in percentage threshold calculations. Leave blank for auto calculation based on all series and fields.",
"type": "number"
},
"max": {
"description": "The maximum value used in percentage threshold calculations. Leave blank for auto calculation based on all series and fields.",
"type": "number"
},
"mappings": {
"description": "Convert input values into a display string",
"type": "array",
"items": {
"$ref": "#$defs/ValueMapping"
}
},
"thresholds": {
"$ref": "#$defs/ThresholdsConfig"
},
"color": {
"$ref": "#$defs/FieldColor"
},
"links": {
"description": "The behavior when clicking on a result",
"type": "array",
"items": {}
},
"noValue": {
"description": "Alternative to empty string",
"type": "string"
},
"custom": {
"description": "custom is specified by the FieldConfig field\nin panel plugin schemas.",
"type": "object"
}
},
"$schema": "http://json-schema.org/draft-04/schema#"
},
"FieldConfigSource": {
"description": "The data model used in Grafana, namely the data frame, is a columnar-oriented table structure that unifies both time series and table query results.\nEach column within this structure is called a field. A field can represent a single time series or table column.\nField options allow you to change how the data is displayed in your visualizations.",
"type": "object",
"required": [
"defaults",
"overrides"
],
"properties": {
"defaults": {
"$ref": "#$defs/FieldConfig"
},
"overrides": {
"description": "Overrides are the options applied to specific fields overriding the defaults.",
"type": "array",
"items": {
"type": "object",
"required": [
"matcher",
"properties"
],
"properties": {
"matcher": {
"$ref": "#$defs/MatcherConfig"
},
"properties": {
"type": "array",
"items": {
"$ref": "#$defs/DynamicConfigValue"
}
}
}
}
}
},
"$schema": "http://json-schema.org/draft-04/schema#"
},
"GraphPanel": {
"description": "Support for legacy graph panel.\n@deprecated this a deprecated panel type",
"type": "object",
"required": [
"type"
],
"properties": {
"type": {
"type": "string",
"enum": [
"graph"
]
},
"legend": {
"description": "@deprecated this is part of deprecated graph panel",
"type": "object",
"required": [
"show"
],
"properties": {
"show": {
"type": "boolean",
"default": true
},
"sort": {
"type": "string"
},
"sortDesc": {
"type": "boolean"
}
}
}
},
"$schema": "http://json-schema.org/draft-04/schema#"
},
"GridPos": {
"description": "Position and dimensions of a panel in the grid",
"type": "object",
"required": [
"h",
"w",
"x",
"y"
],
"properties": {
"h": {
"description": "Panel height. The height is the number of rows from the top edge of the panel.",
"type": "integer",
"minimum": 0,
"exclusiveMinimum": true,
"maximum": 4294967295,
"default": 9
},
"w": {
"description": "Panel width. The width is the number of columns from the left edge of the panel.",
"type": "integer",
"minimum": 0,
"exclusiveMinimum": true,
"maximum": 24,
"default": 12
},
"x": {
"description": "Panel x. The x coordinate is the number of columns from the left edge of the grid",
"type": "integer",
"minimum": 0,
"maximum": 24,
"exclusiveMaximum": true,
"default": 0
},
"y": {
"description": "Panel y. The y coordinate is the number of rows from the top edge of the grid",
"type": "integer",
"minimum": 0,
"maximum": 4294967295,
"default": 0
},
"static": {
"description": "Whether the panel is fixed within the grid. If true, the panel will not be affected by other panels' interactions",
"type": "boolean"
}
},
"$schema": "http://json-schema.org/draft-04/schema#"
},
"HeatmapPanel": {
"description": "Support for legacy heatmap panel.\n@deprecated this a deprecated panel type",
"type": "object",
"required": [
"type"
],
"properties": {
"type": {
"type": "string",
"enum": [
"heatmap"
]
}
},
"$schema": "http://json-schema.org/draft-04/schema#"
},
"LibraryPanelRef": {
"description": "A library panel is a reusable panel that you can use in any dashboard.\nWhen you make a change to a library panel, that change propagates to all instances of where the panel is used.\nLibrary panels streamline reuse of panels across multiple dashboards.",
"type": "object",
"required": [
"name",
"uid"
],
"properties": {
"name": {
"description": "Library panel name",
"type": "string"
},
"uid": {
"description": "Library panel uid",
"type": "string"
}
},
"$schema": "http://json-schema.org/draft-04/schema#"
},
"LoadingState": {
"description": "Loading status\nAccepted values are `NotStarted` (the request is not started), `Loading` (waiting for response), `Streaming` (pulling continuous data), `Done` (response received successfully) or `Error` (failed request).",
"type": "string",
"enum": [
"NotStarted",
"Loading",
"Streaming",
"Done",
"Error"
],
"$schema": "http://json-schema.org/draft-04/schema#"
},
"MappingType": {
"description": "Supported value mapping types\n`value`: Maps text values to a color or different display text and color. For example, you can configure a value mapping so that all instances of the value 10 appear as Perfection! rather than the number.\n`range`: Maps numerical ranges to a display text and color. For example, if a value is within a certain range, you can configure a range value mapping to display Low or High rather than the number.\n`regex`: Maps regular expressions to replacement text and a color. For example, if a value is www.example.com, you can configure a regex value mapping so that Grafana displays www and truncates the domain.\n`special`: Maps special values like Null, NaN (not a number), and boolean values like true and false to a display text and color. See SpecialValueMatch to see the list of special values. For example, you can configure a special value mapping so that null values appear as N/A.",
"type": "string",
"enum": [
"value",
"range",
"regex",
"special"
],
"$schema": "http://json-schema.org/draft-04/schema#"
},
"MatcherConfig": {
"description": "Matcher is a predicate configuration. Based on the config a set of field(s) or values is filtered in order to apply override / transformation.\nIt comes with in id ( to resolve implementation from registry) and a configuration that’s specific to a particular matcher type.",
"type": "object",
"required": [
"id"
],
"properties": {
"id": {
"description": "The matcher id. This is used to find the matcher implementation from registry.",
"type": "string",
"default": ""
},
"options": {
"description": "The matcher options. This is specific to the matcher implementation."
}
},
"$schema": "http://json-schema.org/draft-04/schema#"
},
"Panel": {
"description": "Dashboard panels are the basic visualization building blocks.",
"type": "object",
"required": [
"type",
"transparent",
"transformations",
"options",
"fieldConfig"
],
"properties": {
"type": {
"description": "The panel plugin type id. This is used to find the plugin to display the panel.",
"type": "string",
"minLength": 1
},
"id": {
"description": "Unique identifier of the panel. Generated by Grafana when creating a new panel. It must be unique within a dashboard, but not globally.",
"type": "integer",
"minimum": 0,
"maximum": 4294967295
},
"pluginVersion": {
"description": "The version of the plugin that is used for this panel. This is used to find the plugin to display the panel and to migrate old panel configs.",
"type": "string"
},
"tags": {
"description": "Tags for the panel.",
"type": "array",
"items": {
"type": "string"
}
},
"targets": {
"description": "Depends on the panel plugin. See the plugin documentation for details.",
"type": "array",
"items": {
"$ref": "#$defs/Target"
}
},
"title": {
"description": "Panel title.",
"type": "string"
},
"description": {
"description": "Panel description.",
"type": "string"
},
"transparent": {
"description": "Whether to display the panel without a background.",
"type": "boolean",
"default": false
},
"datasource": {
"$ref": "#$defs/DataSourceRef"
},
"gridPos": {
"$ref": "#$defs/GridPos"
},
"links": {
"description": "Panel links.",
"type": "array",
"items": {
"$ref": "#$defs/DashboardLink"
}
},
"repeat": {
"description": "Name of template variable to repeat for.",
"type": "string"
},
"repeatDirection": {
"description": "Direction to repeat in if 'repeat' is set.\n`h` for horizontal, `v` for vertical.",
"type": "string",
"enum": [
"h",
"v"
],
"default": "h"
},
"repeatPanelId": {
"description": "Id of the repeating panel.",
"type": "integer",
"format": "int64"
},
"maxDataPoints": {
"description": "The maximum number of data points that the panel queries are retrieving.",
"type": "number"
},
"transformations": {
"description": "List of transformations that are applied to the panel data before rendering.\nWhen there are multiple transformations, Grafana applies them in the order they are listed.\nEach transformation creates a result set that then passes on to the next transformation in the processing pipeline.",
"type": "array",
"items": {
"$ref": "#$defs/DataTransformerConfig"
}
},
"interval": {
"description": "The min time interval setting defines a lower limit for the $__interval and $__interval_ms variables.\nThis value must be formatted as a number followed by a valid time\nidentifier like: \"40s\", \"3d\", etc.\nSee: https://grafana.com/docs/grafana/latest/panels-visualizations/query-transform-data/#query-options",
"type": "string"
},
"timeFrom": {
"description": "Overrides the relative time range for individual panels,\nwhich causes them to be different than what is selected in\nthe dashboard time picker in the top-right corner of the dashboard. You can use this to show metrics from different\ntime periods or days on the same dashboard.\nThe value is formatted as time operation like: `now-5m` (Last 5 minutes), `now/d` (the day so far),\n`now-5d/d`(Last 5 days), `now/w` (This week so far), `now-2y/y` (Last 2 years).\nNote: Panel time overrides have no effect when the dashboard’s time range is absolute.\nSee: https://grafana.com/docs/grafana/latest/panels-visualizations/query-transform-data/#query-options",
"type": "string"
},
"timeShift": {
"description": "Overrides the time range for individual panels by shifting its start and end relative to the time picker.\nFor example, you can shift the time range for the panel to be two hours earlier than the dashboard time picker setting `2h`.\nNote: Panel time overrides have no effect when the dashboard’s time range is absolute.\nSee: https://grafana.com/docs/grafana/latest/panels-visualizations/query-transform-data/#query-options",
"type": "string"
},
"libraryPanel": {
"$ref": "#$defs/LibraryPanelRef"
},
"options": {
"description": "It depends on the panel plugin. They are specified by the Options field in panel plugin schemas.",
"type": "object"
},
"fieldConfig": {
"$ref": "#$defs/FieldConfigSource"
}
},
"$schema": "http://json-schema.org/draft-04/schema#"
},
"RangeMap": {
"description": "Maps numerical ranges to a display text and color.\nFor example, if a value is within a certain range, you can configure a range value mapping to display Low or High rather than the number.",
"type": "object",
"required": [
"type",
"options"
],
"properties": {
"type": {
"type": "string",
"allOf": [
{
"$ref": "#$defs/MappingType"
},
{
"enum": [
"range"
]
}
]
},
"options": {
"description": "Range to match against and the result to apply when the value is within the range",
"type": "object",
"required": [
"from",
"to",
"result"
],
"properties": {
"from": {
"description": "Min value of the range. It can be null which means -Infinity",
"type": [
"number",
"null"
],
"format": "double"
},
"to": {
"description": "Max value of the range. It can be null which means +Infinity",
"type": [
"number",
"null"
],
"format": "double"
},
"result": {
"$ref": "#$defs/ValueMappingResult"
}
}
}
},
"$schema": "http://json-schema.org/draft-04/schema#"
},
"RegexMap": {
"description": "Maps regular expressions to replacement text and a color.\nFor example, if a value is www.example.com, you can configure a regex value mapping so that Grafana displays www and truncates the domain.",
"type": "object",
"required": [
"type",
"options"
],
"properties": {
"type": {
"type": "string",
"allOf": [
{
"$ref": "#$defs/MappingType"
},
{
"enum": [
"regex"
]
}
]
},
"options": {
"description": "Regular expression to match against and the result to apply when the value matches the regex",
"type": "object",
"required": [
"pattern",
"result"
],
"properties": {
"pattern": {
"description": "Regular expression to match against",
"type": "string"
},
"result": {
"$ref": "#$defs/ValueMappingResult"
}
}
}
},
"$schema": "http://json-schema.org/draft-04/schema#"
},
"RowPanel": {
"description": "Row panel",
"type": "object",
"required": [
"type",
"collapsed",
"id",
"panels"
],
"properties": {
"type": {
"description": "The panel type",
"type": "string",
"enum": [
"row"
]
},
"collapsed": {
"description": "Whether this row should be collapsed or not.",
"type": "boolean",
"default": false
},
"title": {
"description": "Row title",
"type": "string"
},
"datasource": {
"$ref": "#$defs/DataSourceRef"
},
"gridPos": {
"$ref": "#$defs/GridPos"
},
"id": {
"description": "Unique identifier of the panel. Generated by Grafana when creating a new panel. It must be unique within a dashboard, but not globally.",
"type": "integer",
"minimum": 0,
"maximum": 4294967295
},
"panels": {
"description": "List of panels in the row",
"type": "array",
"items": {
"type": "object",
"oneOf": [
{
"$ref": "#$defs/Panel"
},
{
"$ref": "#$defs/GraphPanel"
},
{
"$ref": "#$defs/HeatmapPanel"
}
]
}
},
"repeat": {
"description": "Name of template variable to repeat for.",
"type": "string"
}
},
"$schema": "http://json-schema.org/draft-04/schema#"
},
"Snapshot": {
"description": "A dashboard snapshot shares an interactive dashboard publicly.\nIt is a read-only version of a dashboard, and is not editable.\nIt is possible to create a snapshot of a snapshot.\nGrafana strips away all sensitive information from the dashboard.\nSensitive information stripped: queries (metric, template,annotation) and panel links.",
"type": "object",
"required": [
"created",
"expires",
"external",
"externalUrl",
"id",
"key",
"name",
"orgId",
"updated",
"userId"
],
"properties": {
"created": {
"description": "Time when the snapshot was created",
"type": "string",
"format": "date-time"
},
"expires": {
"description": "Time when the snapshot expires, default is never to expire",
"type": "string"
},
"external": {
"description": "Is the snapshot saved in an external grafana instance",
"type": "boolean"
},
"externalUrl": {
"description": "external url, if snapshot was shared in external grafana instance",
"type": "string"
},
"id": {
"description": "Unique identifier of the snapshot",
"type": "integer",
"minimum": 0,
"maximum": 4294967295
},
"key": {
"description": "Optional, defined the unique key of the snapshot, required if external is true",
"type": "string"
},
"name": {
"description": "Optional, name of the snapshot",
"type": "string"
},
"orgId": {
"description": "org id of the snapshot",
"type": "integer",
"minimum": 0,
"maximum": 4294967295
},
"updated": {
"description": "last time when the snapshot was updated",
"type": "string",
"format": "date-time"
},
"url": {
"description": "url of the snapshot, if snapshot was shared internally",
"type": "string"
},
"userId": {
"description": "user id of the snapshot creator",
"type": "integer",
"minimum": 0,
"maximum": 4294967295
}
},
"$schema": "http://json-schema.org/draft-04/schema#"
},
"SpecialValueMap": {
"description": "Maps special values like Null, NaN (not a number), and boolean values like true and false to a display text and color.\nSee SpecialValueMatch to see the list of special values.\nFor example, you can configure a special value mapping so that null values appear as N/A.",
"type": "object",
"required": [
"type",
"options"
],
"properties": {
"type": {
"type": "string",
"allOf": [
{
"$ref": "#$defs/MappingType"
},
{
"enum": [
"special"
]
}
]
},
"options": {
"type": "object",
"required": [
"match",
"result"
],
"properties": {
"match": {
"$ref": "#$defs/SpecialValueMatch"
},
"result": {
"$ref": "#$defs/ValueMappingResult"
}
}
}
},
"$schema": "http://json-schema.org/draft-04/schema#"
},
"SpecialValueMatch": {
"description": "Special value types supported by the `SpecialValueMap`",
"type": "string",
"enum": [
"true",
"false",
"null",
"nan",
"null+nan",
"empty"
],
"$schema": "http://json-schema.org/draft-04/schema#"
},
"Target": {
"description": "Schema for panel targets is specified by datasource\nplugins. We use a placeholder definition, which the Go\nschema loader either left open/as-is with the Base\nvariant of the Dashboard and Panel families, or filled\nwith types derived from plugins in the Instance variant.\nWhen working directly from CUE, importers can extend this\ntype directly to achieve the same effect.",
"type": "object",
"$schema": "http://json-schema.org/draft-04/schema#"
},
"Threshold": {
"description": "User-defined value for a metric that triggers visual changes in a panel when this value is met or exceeded\nThey are used to conditionally style and color visualizations based on query results , and can be applied to most visualizations.",
"type": "object",
"required": [
"value",
"color"
],
"properties": {
"value": {
"description": "Value represents a specified metric for the threshold, which triggers a visual change in the dashboard when this value is met or exceeded.\nNulls currently appear here when serializing -Infinity to JSON.",
"type": [
"number",
"null"
]
},
"color": {
"description": "Color represents the color of the visual change that will occur in the dashboard when the threshold value is met or exceeded.",
"type": "string"
}
},
"$schema": "http://json-schema.org/draft-04/schema#"
},
"ThresholdsConfig": {
"description": "Thresholds configuration for the panel",
"type": "object",
"required": [
"mode",
"steps"
],
"properties": {
"mode": {
"$ref": "#$defs/ThresholdsMode"
},
"steps": {
"description": "Must be sorted by 'value', first value is always -Infinity",
"type": "array",
"items": {
"$ref": "#$defs/Threshold"
}
}
},
"$schema": "http://json-schema.org/draft-04/schema#"
},
"ThresholdsMode": {
"description": "Thresholds can either be `absolute` (specific number) or `percentage` (relative to min or max, it will be values between 0 and 1).",
"type": "string",
"enum": [
"absolute",
"percentage"
],
"$schema": "http://json-schema.org/draft-04/schema#"
},
"ValueMap": {
"description": "Maps text values to a color or different display text and color.\nFor example, you can configure a value mapping so that all instances of the value 10 appear as Perfection! rather than the number.",
"type": "object",
"required": [
"type",
"options"
],
"properties": {
"type": {
"type": "string",
"allOf": [
{
"$ref": "#$defs/MappingType"
},
{
"enum": [
"value"
]
}
]
},
"options": {
"description": "Map with <value_to_match>: ValueMappingResult. For example: { \"10\": { text: \"Perfection!\", color: \"green\" } }",
"type": "object",
"additionalProperties": {
"$ref": "#$defs/ValueMappingResult"
}
}
},
"$schema": "http://json-schema.org/draft-04/schema#"
},
"ValueMapping": {
"description": "Allow to transform the visual representation of specific data values in a visualization, irrespective of their original units",
"type": "object",
"oneOf": [
{
"$ref": "#$defs/ValueMap"
},
{
"$ref": "#$defs/RangeMap"
},
{
"$ref": "#$defs/RegexMap"
},
{
"$ref": "#$defs/SpecialValueMap"
}
],
"$schema": "http://json-schema.org/draft-04/schema#"
},
"ValueMappingResult": {
"description": "Result used as replacement with text and color when the value matches",
"type": "object",
"properties": {
"text": {
"description": "Text to display when the value matches",
"type": "string"
},
"color": {
"description": "Text to use when the value matches",
"type": "string"
},
"icon": {
"description": "Icon to display when the value matches. Only specific visualizations.",
"type": "string"
},
"index": {
"description": "Position in the mapping array. Only used internally.",
"type": "integer",
"format": "int32"
}
},
"$schema": "http://json-schema.org/draft-04/schema#"
},
"VariableHide": {
"description": "Determine if the variable shows on dashboard\nAccepted values are 0 (show label and value), 1 (show value only), 2 (show nothing).",
"type": "integer",
"enum": [
0,
1,
2
],
"$schema": "http://json-schema.org/draft-04/schema#"
},
"VariableModel": {
"description": "A variable is a placeholder for a value. You can use variables in metric queries and in panel titles.",
"type": "object",
"required": [
"id",
"type",
"name",
"hide",
"skipUrlSync"
],
"properties": {
"id": {
"description": "Unique numeric identifier for the variable.",
"type": "string",
"default": "00000000-0000-0000-0000-000000000000"
},
"type": {
"$ref": "#$defs/VariableType"
},
"name": {
"description": "Name of variable",
"type": "string"
},
"label": {
"description": "Optional display name",
"type": "string"
},
"hide": {
"$ref": "#$defs/VariableHide"
},
"skipUrlSync": {
"description": "Whether the variable value should be managed by URL query params or not",
"type": "boolean",
"default": false
},
"description": {
"description": "Description of variable. It can be defined but `null`.",
"type": "string"
},
"query": {
"description": "Query used to fetch values for a variable",
"oneOf": [
{
"type": "string"
},
{
"type": "object"
}
]
},
"datasource": {
"$ref": "#$defs/DataSourceRef"
},
"allFormat": {
"description": "Format to use while fetching all values from data source, eg: wildcard, glob, regex, pipe, etc.",
"type": "string"
},
"current": {
"$ref": "#$defs/VariableOption"
},
"multi": {
"description": "Whether multiple values can be selected or not from variable value list",
"type": "boolean",
"default": false
},
"options": {
"description": "Options that can be selected for a variable.",
"type": "array",
"items": {
"$ref": "#$defs/VariableOption"
}
},
"refresh": {
"$ref": "#$defs/VariableRefresh"
}
},
"$schema": "http://json-schema.org/draft-04/schema#"
},
"VariableOption": {
"description": "Option to be selected in a variable.",
"type": "object",
"required": [
"text",
"value"
],
"properties": {
"selected": {
"description": "Whether the option is selected or not",
"type": "boolean"
},
"text": {
"description": "Text to be displayed for the option",
"oneOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
]
},
"value": {
"description": "Value of the option",
"oneOf": [
{
"type": "string"
},
{
"type": "array",
"items": {
"type": "string"
}
}
]
}
},
"$schema": "http://json-schema.org/draft-04/schema#"
},
"VariableRefresh": {
"description": "Options to config when to refresh a variable\n`0`: Never refresh the variable\n`1`: Queries the data source every time the dashboard loads.\n`2`: Queries the data source when the dashboard time range changes.",
"type": "integer",
"enum": [
0,
1,
2
],
"$schema": "http://json-schema.org/draft-04/schema#"
},
"VariableSort": {
"description": "Sort variable options\nAccepted values are:\n`0`: No sorting\n`1`: Alphabetical ASC\n`2`: Alphabetical DESC\n`3`: Numerical ASC\n`4`: Numerical DESC\n`5`: Alphabetical Case Insensitive ASC\n`6`: Alphabetical Case Insensitive DESC",
"type": "integer",
"enum": [
0,
1,
2,
3,
4,
5,
6
],
"$schema": "http://json-schema.org/draft-04/schema#"
},
"VariableType": {
"description": "Dashboard variable type\n`query`: Query-generated list of values such as metric names, server names, sensor IDs, data centers, and so on.\n`adhoc`: Key/value filters that are automatically added to all metric queries for a data source (Prometheus, Loki, InfluxDB, and Elasticsearch only).\n`constant`: \tDefine a hidden constant.\n`datasource`: Quickly change the data source for an entire dashboard.\n`interval`: Interval variables represent time spans.\n`textbox`: Display a free text input field with an optional default value.\n`custom`: Define the variable options manually using a comma-separated list.\n`system`: Variables defined by Grafana. See: https://grafana.com/docs/grafana/latest/dashboards/variables/add-template-variables/#global-variables",
"type": "string",
"enum": [
"query",
"adhoc",
"constant",
"datasource",
"interval",
"textbox",
"custom",
"system"
],
"$schema": "http://json-schema.org/draft-04/schema#"
},
"_kubeObjectMetadata": {
"description": "_kubeObjectMetadata is metadata found in a kubernetes object's metadata field.\nIt is not exhaustive and only includes fields which may be relevant to a kind's implementation,\nAs it is also intended to be generic enough to function with any API Server.",
"type": "object",
"required": [
"uid",
"creationTimestamp",
"finalizers",
"resourceVersion",
"labels"
],
"properties": {
"uid": {
"type": "string"
},
"creationTimestamp": {
"type": "string",
"format": "date-time"
},
"deletionTimestamp": {
"type": "string",
"format": "date-time"
},
"finalizers": {
"type": "array",
"items": {
"type": "string"
}
},
"resourceVersion": {
"type": "string"
},
"labels": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
},
"$schema": "http://json-schema.org/draft-04/schema#"
},
"status.#OperatorState": {
"type": "object",
"required": [
"lastEvaluation",
"state"
],
"properties": {
"lastEvaluation": {
"description": "lastEvaluation is the ResourceVersion last evaluated",
"type": "string"
},
"state": {
"description": "state describes the state of the lastEvaluation.\nIt is limited to three possible states for machine evaluation.",
"type": "string",
"enum": [
"success",
"in_progress",
"failed"
]
},
"descriptiveState": {
"description": "descriptiveState is an optional more descriptive state field which has no requirements on format",
"type": "string"
},
"details": {
"description": "details contains any extra information that is operator-specific",
"type": "object"
}
},
"$schema": "http://json-schema.org/draft-04/schema#"
}
}
}
}
}
]
}
}
@sdboyer
Copy link
Author

sdboyer commented Jul 31, 2023

This is the most minimal possible translation of the CUE definition of a dashboard kind into pure JSON. A file like this is one that users/app devs actually directly edit, and therefore think of as the canonical, single source of truth.

At runtime - in an apiserver, in the sdk, whereever - a file like this could be read, dynamically translated into the CUE form that our engine already knows how to work with, and be used to produce an instance of kindsys.Core, ready for use in validation, unmarshaling, and migration. Same basic operations as we do with dashboard_kind.cue today. There would be gotchas, but the basics should work.

@sdboyer
Copy link
Author

sdboyer commented Aug 1, 2023

Notes on the structure we see here:

Everything up to the schema definition itself is essentially unchanged from what's in the CUE definition. Only the schema body itself is transformed, from CUE expressions into the corresponding JSON schema. This is the "DSL wrapped around a schema system" pattern.

OpenAPI follows this pattern. An OpenAPI document is mostly DSL, where the root object is a fixed set of fields. Actual schema definitions appear primarily under components.schemas.

CRDs also follow this pattern. Each CRD describes one type, with schemas for each of the versions (in spec.versions) of that type. (Contrast to OpenAPI documents, which describe a whole API, but have only a single top-level concept of version, with no attached semantics). Within each version, the actual schema body is defined spec.versions.[].schema.openAPIV3Schema.

Don't let that field name fool you, though! Not only is it not a whole OpenAPI document (which was enough to confuse me for a long time), it's not even an OpenAPI 3.0 Schema object - for example, it lacks readOnly, writeOnly and discriminator fields, but includes a dependencies field. There are also subtle, poorly documented rules around references and certain oneOf constructs which have bitten SLO work, and which forced us to introduce the dummySchema field because they caused our (valid!) generated OpenAPI for dashboards to fail, as well.

At the same time, that spec.versions.[].schema.openAPIV3Schema is also not vanilla JSON Schema, as suggested by the docs and the value type name. For example, the x-kubernetes fields, nullable are within bounds of "extending JSON Schema", but the limitations on $ref means the implementation is not compliant with the spec.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment