mirror of https://github.com/grafana/grafana
playlist: introduce coremodel schema, swap in for backend DTO types (#56048)
* Add simplest possible playlist schema * Add @grafana(decisionNeeded) attributes * playlistid, not playlist_idpull/56086/head
parent
d2601003cf
commit
9ec7b202b6
@ -0,0 +1,69 @@ |
||||
// This file is autogenerated. DO NOT EDIT.
|
||||
//
|
||||
// Generated by pkg/framework/coremodel/gen.go
|
||||
//
|
||||
// Derived from the Thema lineage declared in pkg/coremodel/playlist/coremodel.cue
|
||||
//
|
||||
// Run `make gen-cue` from repository root to regenerate.
|
||||
|
||||
export interface Playlist { |
||||
/** |
||||
* Unique playlist identifier for internal use, set by Grafana. |
||||
*/ |
||||
id: number; |
||||
/** |
||||
* Interval sets the time between switching views in a playlist. |
||||
* FIXME: Is this based on a standardized format or what options are available? Can datemath be used? |
||||
*/ |
||||
interval: string; |
||||
/** |
||||
* The ordered list of items that the playlist will iterate over. |
||||
*/ |
||||
items?: Array<{ |
||||
/** |
||||
* FIXME: The prefixDropper removes playlist from playlist_id, that doesn't work for us since it'll mean we'll have Id twice. |
||||
* ID of the playlist item for internal use by Grafana. Deprecated. |
||||
*/ |
||||
id: number; |
||||
/** |
||||
* PlaylistID for the playlist containing the item. Deprecated. |
||||
*/ |
||||
playlistid: number; |
||||
/** |
||||
* Type of the item. |
||||
*/ |
||||
type: ('dashboard_by_uid' | 'dashboard_by_id' | 'dashboard_by_tag'); |
||||
/** |
||||
* Value depends on type and describes the playlist item. |
||||
*
|
||||
* - dashboard_by_id: The value is an internal numerical identifier set by Grafana. This |
||||
* is not portable as the numerical identifier is non-deterministic between different instances. |
||||
* Will be replaced by dashboard_by_uid in the future. |
||||
* - dashboard_by_tag: The value is a tag which is set on any number of dashboards. All |
||||
* dashboards behind the tag will be added to the playlist. |
||||
*/ |
||||
value: string; |
||||
/** |
||||
* Title is the human-readable identifier for the playlist item. |
||||
*/ |
||||
title: string; |
||||
/** |
||||
* Order is the position in the list for the item. Deprecated. |
||||
*/ |
||||
order: number; |
||||
}>; |
||||
/** |
||||
* Name of the playlist. |
||||
*/ |
||||
name: string; |
||||
/** |
||||
* Unique playlist identifier. Generated on creation, either by the |
||||
* creator of the playlist of by the application. |
||||
*/ |
||||
uid: string; |
||||
} |
||||
|
||||
export const defaultPlaylist: Partial<Playlist> = { |
||||
interval: '5m', |
||||
items: [], |
||||
}; |
||||
@ -0,0 +1,54 @@ |
||||
package playlist |
||||
|
||||
import ( |
||||
"github.com/grafana/thema" |
||||
) |
||||
|
||||
thema.#Lineage |
||||
name: "playlist" |
||||
seqs: [ |
||||
{ |
||||
schemas: [ |
||||
{//0.0 |
||||
// Unique playlist identifier for internal use, set by Grafana. |
||||
id: int64 @grafana(decisionNeeded) |
||||
// Unique playlist identifier. Generated on creation, either by the |
||||
// creator of the playlist of by the application. |
||||
uid: string |
||||
// Name of the playlist. |
||||
name: string |
||||
// Interval sets the time between switching views in a playlist. |
||||
// FIXME: Is this based on a standardized format or what options are available? Can datemath be used? |
||||
interval: string | *"5m" |
||||
// The ordered list of items that the playlist will iterate over. |
||||
items?: [...#PlaylistItem] |
||||
|
||||
/////////////////////////////////////// |
||||
// Definitions (referenced above) are declared below |
||||
|
||||
#PlaylistItem: { |
||||
// FIXME: The prefixDropper removes playlist from playlist_id, that doesn't work for us since it'll mean we'll have Id twice. |
||||
// ID of the playlist item for internal use by Grafana. Deprecated. |
||||
id: int64 @grafana(decisionNeeded) |
||||
// PlaylistID for the playlist containing the item. Deprecated. |
||||
playlistid: int64 @grafana(decisionNeeded) |
||||
|
||||
// Type of the item. |
||||
type: "dashboard_by_uid" | "dashboard_by_id" | "dashboard_by_tag" |
||||
// Value depends on type and describes the playlist item. |
||||
// |
||||
// - dashboard_by_id: The value is an internal numerical identifier set by Grafana. This |
||||
// is not portable as the numerical identifier is non-deterministic between different instances. |
||||
// Will be replaced by dashboard_by_uid in the future. |
||||
// - dashboard_by_tag: The value is a tag which is set on any number of dashboards. All |
||||
// dashboards behind the tag will be added to the playlist. |
||||
value: string |
||||
// Title is the human-readable identifier for the playlist item. |
||||
title: string @grafana(decisionNeeded) |
||||
// Order is the position in the list for the item. Deprecated. |
||||
order: int64 | *0 @grafana(decisionNeeded) |
||||
} |
||||
} |
||||
] |
||||
} |
||||
] |
||||
@ -0,0 +1,147 @@ |
||||
// This file is autogenerated. DO NOT EDIT.
|
||||
//
|
||||
// Generated by pkg/framework/coremodel/gen.go
|
||||
//
|
||||
// Derived from the Thema lineage declared in pkg/coremodel/playlist/coremodel.cue
|
||||
//
|
||||
// Run `make gen-cue` from repository root to regenerate.
|
||||
|
||||
package playlist |
||||
|
||||
import ( |
||||
"embed" |
||||
"path/filepath" |
||||
|
||||
"github.com/grafana/grafana/pkg/cuectx" |
||||
"github.com/grafana/grafana/pkg/framework/coremodel" |
||||
"github.com/grafana/thema" |
||||
) |
||||
|
||||
// Defines values for PlaylistItemType.
|
||||
const ( |
||||
PlaylistItemTypeDashboardById PlaylistItemType = "dashboard_by_id" |
||||
|
||||
PlaylistItemTypeDashboardByTag PlaylistItemType = "dashboard_by_tag" |
||||
|
||||
PlaylistItemTypeDashboardByUid PlaylistItemType = "dashboard_by_uid" |
||||
) |
||||
|
||||
// Model is the Go representation of a playlist.
|
||||
//
|
||||
// THIS TYPE IS INTENDED FOR INTERNAL USE BY THE GRAFANA BACKEND, AND IS SUBJECT TO BREAKING CHANGES.
|
||||
// Equivalent Go types at stable import paths are provided in https://github.com/grafana/grok.
|
||||
type Model struct { |
||||
// Unique playlist identifier for internal use, set by Grafana.
|
||||
Id int64 `json:"id"` |
||||
|
||||
// Interval sets the time between switching views in a playlist.
|
||||
// FIXME: Is this based on a standardized format or what options are available? Can datemath be used?
|
||||
Interval string `json:"interval"` |
||||
|
||||
// The ordered list of items that the playlist will iterate over.
|
||||
Items *[]PlaylistItem `json:"items,omitempty"` |
||||
|
||||
// Name of the playlist.
|
||||
Name string `json:"name"` |
||||
|
||||
// Unique playlist identifier. Generated on creation, either by the
|
||||
// creator of the playlist of by the application.
|
||||
Uid string `json:"uid"` |
||||
} |
||||
|
||||
// PlaylistItem is the Go representation of a playlist.Item.
|
||||
//
|
||||
// THIS TYPE IS INTENDED FOR INTERNAL USE BY THE GRAFANA BACKEND, AND IS SUBJECT TO BREAKING CHANGES.
|
||||
// Equivalent Go types at stable import paths are provided in https://github.com/grafana/grok.
|
||||
type PlaylistItem struct { |
||||
// FIXME: The prefixDropper removes playlist from playlist_id, that doesn't work for us since it'll mean we'll have Id twice.
|
||||
// ID of the playlist item for internal use by Grafana. Deprecated.
|
||||
Id int64 `json:"id"` |
||||
|
||||
// Order is the position in the list for the item. Deprecated.
|
||||
Order int `json:"order"` |
||||
|
||||
// ID for the playlist containing the item. Deprecated.
|
||||
Playlistid int64 `json:"playlistid"` |
||||
|
||||
// Title is the human-readable identifier for the playlist item.
|
||||
Title string `json:"title"` |
||||
|
||||
// Type of the item.
|
||||
Type PlaylistItemType `json:"type"` |
||||
|
||||
// Value depends on type and describes the playlist item.
|
||||
//
|
||||
// - dashboard_by_id: The value is an internal numerical identifier set by Grafana. This
|
||||
// is not portable as the numerical identifier is non-deterministic between different instances.
|
||||
// Will be replaced by dashboard_by_uid in the future.
|
||||
// - dashboard_by_tag: The value is a tag which is set on any number of dashboards. All
|
||||
// dashboards behind the tag will be added to the playlist.
|
||||
Value string `json:"value"` |
||||
} |
||||
|
||||
// Type of the item.
|
||||
//
|
||||
// THIS TYPE IS INTENDED FOR INTERNAL USE BY THE GRAFANA BACKEND, AND IS SUBJECT TO BREAKING CHANGES.
|
||||
// Equivalent Go types at stable import paths are provided in https://github.com/grafana/grok.
|
||||
type PlaylistItemType string |
||||
|
||||
//go:embed coremodel.cue
|
||||
var cueFS embed.FS |
||||
|
||||
// The current version of the coremodel schema, as declared in coremodel.cue.
|
||||
// This version determines what schema version is returned from [Coremodel.CurrentSchema],
|
||||
// and which schema version is used for code generation within the grafana/grafana repository.
|
||||
//
|
||||
// The code generator ensures that this is always the latest Thema schema version.
|
||||
var currentVersion = thema.SV(0, 0) |
||||
|
||||
// Lineage returns the Thema lineage representing a Grafana playlist.
|
||||
//
|
||||
// The lineage is the canonical specification of the current playlist schema,
|
||||
// all prior schema versions, and the mappings that allow migration between
|
||||
// schema versions.
|
||||
func Lineage(lib thema.Library, opts ...thema.BindOption) (thema.Lineage, error) { |
||||
return cuectx.LoadGrafanaInstancesWithThema(filepath.Join("pkg", "coremodel", "playlist"), cueFS, lib, opts...) |
||||
} |
||||
|
||||
var _ thema.LineageFactory = Lineage |
||||
var _ coremodel.Interface = &Coremodel{} |
||||
|
||||
// Coremodel contains the foundational schema declaration for playlists.
|
||||
// It implements coremodel.Interface.
|
||||
type Coremodel struct { |
||||
lin thema.Lineage |
||||
} |
||||
|
||||
// Lineage returns the canonical playlist Lineage.
|
||||
func (c *Coremodel) Lineage() thema.Lineage { |
||||
return c.lin |
||||
} |
||||
|
||||
// CurrentSchema returns the current (latest) playlist Thema schema.
|
||||
func (c *Coremodel) CurrentSchema() thema.Schema { |
||||
return thema.SchemaP(c.lin, currentVersion) |
||||
} |
||||
|
||||
// GoType returns a pointer to an empty Go struct that corresponds to
|
||||
// the current Thema schema.
|
||||
func (c *Coremodel) GoType() interface{} { |
||||
return &Model{} |
||||
} |
||||
|
||||
// New returns a new instance of the playlist coremodel.
|
||||
//
|
||||
// Note that this function does not cache, and initially loading a Thema lineage
|
||||
// can be expensive. As such, the Grafana backend should prefer to access this
|
||||
// coremodel through a registry (pkg/framework/coremodel/registry), which does cache.
|
||||
func New(lib thema.Library) (*Coremodel, error) { |
||||
lin, err := Lineage(lib) |
||||
if err != nil { |
||||
return nil, err |
||||
} |
||||
|
||||
return &Coremodel{ |
||||
lin: lin, |
||||
}, nil |
||||
} |
||||
Loading…
Reference in new issue