plugins: Introduce generated, static core plugin registry (#54118)

* Refactor towards template/codegen framework

* Add templates for plugin gen

* Add Go codegen for plugins; overhaul framework, too

* Add new codegen output; assorted framework fixes

* Regenerate after merge

* Remove accidental commit file, update templates

* Export the pfs.Tree loader from plugin types

* Print details from cuetsy errors

* Generate loaders for all plugins and list in registry

* Use pfs_gen.go over lineage_gen.go

* Un-un-ignore main file

* Introduce simple List static registry for plugins

* Last tweaks to codegen

* remove unused tvars

* Ensure loop-local instances for both vars

* Generate pfs parsing in-place in registry

* Stop generating pfs_gen.go

* Move Tree into pfs, rename subdir

* Change package name to match dir

* Ignore gocyclo on HTTPServer.getNavTree
This commit is contained in:
sam boyer
2022-09-14 10:15:09 -04:00
committed by GitHub
parent c69a37f8c2
commit ced53a8dc2
36 changed files with 1114 additions and 324 deletions

View File

@@ -1,8 +1,10 @@
// This file is autogenerated. DO NOT EDIT.
//
// Run "make gen-cue" from repository root to regenerate.
// Generated by pkg/framework/coremodel/gen.go
//
// Derived from the Thema lineage at pkg/coremodel/dashboard
// Derived from the Thema lineage declared in pkg/coremodel/dashboard/coremodel.cue
//
// Run `make gen-cue` from repository root to regenerate.
package dashboard
@@ -15,7 +17,7 @@ import (
"github.com/grafana/thema"
)
// Defines values for DashboardGraphTooltip.
// Defines values for GraphTooltip.
const (
GraphTooltipN0 GraphTooltip = 0
@@ -24,14 +26,14 @@ const (
GraphTooltipN2 GraphTooltip = 2
)
// Defines values for DashboardStyle.
// Defines values for Style.
const (
StyleDark Style = "dark"
StyleLight Style = "light"
)
// Defines values for DashboardTimezone.
// Defines values for Timezone.
const (
TimezoneBrowser Timezone = "browser"
@@ -40,7 +42,7 @@ const (
TimezoneUtc Timezone = "utc"
)
// Defines values for DashboardDashboardCursorSync.
// Defines values for DashboardCursorSync.
const (
DashboardCursorSyncN0 DashboardCursorSync = 0
@@ -49,14 +51,14 @@ const (
DashboardCursorSyncN2 DashboardCursorSync = 2
)
// Defines values for DashboardDashboardLinkType.
// Defines values for DashboardLinkType.
const (
DashboardLinkTypeDashboards DashboardLinkType = "dashboards"
DashboardLinkTypeLink DashboardLinkType = "link"
)
// Defines values for DashboardFieldColorModeId.
// Defines values for FieldColorModeId.
const (
FieldColorModeIdContinuousGrYlRd FieldColorModeId = "continuous-GrYlRd"
@@ -69,7 +71,7 @@ const (
FieldColorModeIdThresholds FieldColorModeId = "thresholds"
)
// Defines values for DashboardFieldColorSeriesByMode.
// Defines values for FieldColorSeriesByMode.
const (
FieldColorSeriesByModeLast FieldColorSeriesByMode = "last"
@@ -78,43 +80,43 @@ const (
FieldColorSeriesByModeMin FieldColorSeriesByMode = "min"
)
// Defines values for DashboardGraphPanelType.
// Defines values for GraphPanelType.
const (
GraphPanelTypeGraph GraphPanelType = "graph"
)
// Defines values for DashboardHeatmapPanelType.
// Defines values for HeatmapPanelType.
const (
HeatmapPanelTypeHeatmap HeatmapPanelType = "heatmap"
)
// Defines values for DashboardPanelRepeatDirection.
// Defines values for PanelRepeatDirection.
const (
PanelRepeatDirectionH PanelRepeatDirection = "h"
PanelRepeatDirectionV PanelRepeatDirection = "v"
)
// Defines values for DashboardRowPanelType.
// Defines values for RowPanelType.
const (
RowPanelTypeRow RowPanelType = "row"
)
// Defines values for DashboardThresholdsConfigMode.
// Defines values for ThresholdsConfigMode.
const (
ThresholdsConfigModeAbsolute ThresholdsConfigMode = "absolute"
ThresholdsConfigModePercentage ThresholdsConfigMode = "percentage"
)
// Defines values for DashboardThresholdsMode.
// Defines values for ThresholdsMode.
const (
ThresholdsModeAbsolute ThresholdsMode = "absolute"
ThresholdsModePercentage ThresholdsMode = "percentage"
)
// Defines values for DashboardVariableModelType.
// Defines values for VariableModelType.
const (
VariableModelTypeAdhoc VariableModelType = "adhoc"
@@ -133,7 +135,7 @@ const (
VariableModelTypeTextbox VariableModelType = "textbox"
)
// Defines values for DashboardVariableType.
// Defines values for VariableType.
const (
VariableTypeAdhoc VariableType = "adhoc"
@@ -152,7 +154,7 @@ const (
VariableTypeTextbox VariableType = "textbox"
)
// Dashboard defines model for dashboard.
// Model is the Go representation of a dashboard.
//
// 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.
@@ -243,7 +245,7 @@ type Model struct {
WeekStart *string `json:"weekStart,omitempty"`
}
// DashboardGraphTooltip defines model for Dashboard.GraphTooltip.
// GraphTooltip is the Go representation of a Model.GraphTooltip.
//
// 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.
@@ -294,7 +296,7 @@ type AnnotationQuery struct {
// Schema for panel targets is specified by datasource
// plugins. We use a placeholder definition, which the Go
// schema loader either left open/as-is with the Base
// variant of the Dashboard and Panel families, or filled
// variant of the Model and Panel families, or filled
// with types derived from plugins in the Instance variant.
// When working directly from CUE, importers can extend this
// type directly to achieve the same effect.
@@ -310,7 +312,7 @@ type AnnotationQuery struct {
// Equivalent Go types at stable import paths are provided in https://github.com/grafana/grok.
type DashboardCursorSync int
// FROM public/app/features/dashboard/state/DashboardModels.ts - ish
// FROM public/app/features/dashboard/state/Models.ts - ish
// TODO docs
//
// THIS TYPE IS INTENDED FOR INTERNAL USE BY THE GRAFANA BACKEND, AND IS SUBJECT TO BREAKING CHANGES.
@@ -328,7 +330,7 @@ type DashboardLink struct {
Url *string `json:"url,omitempty"`
}
// DashboardDashboardLinkType defines model for DashboardDashboardLink.Type.
// DashboardLinkType is the Go representation of a DashboardLink.Type.
//
// 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.
@@ -361,7 +363,7 @@ type FieldColorModeId string
// Equivalent Go types at stable import paths are provided in https://github.com/grafana/grok.
type FieldColorSeriesByMode string
// DashboardGraphPanel defines model for dashboard.GraphPanel.
// GraphPanel is the Go representation of a dashboard.GraphPanel.
//
// 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.
@@ -376,7 +378,7 @@ type GraphPanel struct {
// Equivalent Go types at stable import paths are provided in https://github.com/grafana/grok.
type GraphPanelType string
// DashboardGridPos defines model for dashboard.GridPos.
// GridPos is the Go representation of a dashboard.GridPos.
//
// 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.
@@ -397,7 +399,7 @@ type GridPos struct {
Y int `json:"y"`
}
// DashboardHeatmapPanel defines model for dashboard.HeatmapPanel.
// HeatmapPanel is the Go representation of a dashboard.HeatmapPanel.
//
// 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.
@@ -405,13 +407,13 @@ type HeatmapPanel struct {
Type HeatmapPanelType `json:"type"`
}
// DashboardHeatmapPanelType defines model for DashboardHeatmapPanel.Type.
// HeatmapPanelType is the Go representation of a HeatmapPanel.Type.
//
// 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 HeatmapPanelType string
// Dashboard panels. Panels are canonically defined inline
// Model panels. Panels are canonically defined inline
// because they share a version timeline with the dashboard
// schema; they do not evolve independently.
//
@@ -588,7 +590,7 @@ type RowPanel struct {
Type RowPanelType `json:"type"`
}
// DashboardRowPanelType defines model for DashboardRowPanel.Type.
// RowPanelType is the Go representation of a RowPanel.Type.
//
// 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.
@@ -597,7 +599,7 @@ type RowPanelType string
// Schema for panel targets is specified by datasource
// plugins. We use a placeholder definition, which the Go
// schema loader either left open/as-is with the Base
// variant of the Dashboard and Panel families, or filled
// variant of the Model and Panel families, or filled
// with types derived from plugins in the Instance variant.
// When working directly from CUE, importers can extend this
// type directly to achieve the same effect.
@@ -624,7 +626,7 @@ type Threshold struct {
Value *float32 `json:"value,omitempty"`
}
// DashboardThresholdsConfig defines model for dashboard.ThresholdsConfig.
// ThresholdsConfig is the Go representation of a dashboard.ThresholdsConfig.
//
// 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.
@@ -647,13 +649,13 @@ type ThresholdsConfig struct {
} `json:"steps"`
}
// DashboardThresholdsConfigMode defines model for DashboardThresholdsConfig.Mode.
// ThresholdsConfigMode is the Go representation of a ThresholdsConfig.Mode.
//
// 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 ThresholdsConfigMode string
// DashboardThresholdsMode defines model for dashboard.ThresholdsMode.
// ThresholdsMode is the Go representation of a dashboard.ThresholdsMode.
//
// 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.
@@ -682,7 +684,7 @@ type VariableModel struct {
Type VariableModelType `json:"type"`
}
// DashboardVariableModelType defines model for DashboardVariableModel.Type.
// VariableModelType is the Go representation of a VariableModel.Type.
//
// 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.
@@ -699,7 +701,11 @@ type VariableType string
//go:embed coremodel.cue
var cueFS embed.FS
// codegen ensures that this is always the latest Thema schema version
// 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 dashboard.

View File

@@ -1,8 +1,10 @@
// This file is autogenerated. DO NOT EDIT.
//
// Run "make gen-cue" from repository root to regenerate.
// Generated by pkg/framework/coremodel/gen.go
//
// Derived from the Thema lineage at pkg/coremodel/pluginmeta
// Derived from the Thema lineage declared in pkg/coremodel/pluginmeta/coremodel.cue
//
// Run `make gen-cue` from repository root to regenerate.
package pluginmeta
@@ -15,7 +17,7 @@ import (
"github.com/grafana/thema"
)
// Defines values for PluginmetaCategory.
// Defines values for Category.
const (
CategoryCloud Category = "cloud"
@@ -32,7 +34,7 @@ const (
CategoryTsdb Category = "tsdb"
)
// Defines values for PluginmetaType.
// Defines values for Type.
const (
TypeApp Type = "app"
@@ -45,7 +47,7 @@ const (
TypeSecretsmanager Type = "secretsmanager"
)
// Defines values for PluginmetaDependencyType.
// Defines values for DependencyType.
const (
DependencyTypeApp DependencyType = "app"
@@ -54,7 +56,7 @@ const (
DependencyTypePanel DependencyType = "panel"
)
// Defines values for PluginmetaIncludeRole.
// Defines values for IncludeRole.
const (
IncludeRoleAdmin IncludeRole = "Admin"
@@ -63,7 +65,7 @@ const (
IncludeRoleViewer IncludeRole = "Viewer"
)
// Defines values for PluginmetaIncludeType.
// Defines values for IncludeType.
const (
IncludeTypeApp IncludeType = "app"
@@ -80,7 +82,7 @@ const (
IncludeTypeSecretsmanager IncludeType = "secretsmanager"
)
// Defines values for PluginmetaReleaseState.
// Defines values for ReleaseState.
const (
ReleaseStateAlpha ReleaseState = "alpha"
@@ -91,7 +93,7 @@ const (
ReleaseStateStable ReleaseState = "stable"
)
// Pluginmeta defines model for pluginmeta.
// Model is the Go representation of a pluginmeta.
//
// 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.
@@ -287,7 +289,7 @@ type Category string
// Equivalent Go types at stable import paths are provided in https://github.com/grafana/grok.
type Type string
// PluginmetaBuildInfo defines model for pluginmeta.BuildInfo.
// BuildInfo is the Go representation of a pluginmeta.BuildInfo.
//
// 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.
@@ -307,7 +309,7 @@ type BuildInfo struct {
Time *int64 `json:"time,omitempty"`
}
// PluginmetaDependencies defines model for pluginmeta.Dependencies.
// Dependencies is the Go representation of a pluginmeta.Dependencies.
//
// 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.
@@ -338,7 +340,7 @@ type Dependency struct {
Version string `json:"version"`
}
// PluginmetaDependencyType defines model for PluginmetaDependency.Type.
// DependencyType is the Go representation of a Dependency.Type.
//
// 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.
@@ -383,13 +385,13 @@ type Include struct {
Uid *string `json:"uid,omitempty"`
}
// PluginmetaIncludeRole defines model for PluginmetaInclude.Role.
// IncludeRole is the Go representation of a Include.Role.
//
// 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 IncludeRole string
// PluginmetaIncludeType defines model for PluginmetaInclude.Type.
// IncludeType is the Go representation of a Include.Type.
//
// 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.
@@ -546,7 +548,11 @@ type URLParam struct {
//go:embed coremodel.cue
var cueFS embed.FS
// codegen ensures that this is always the latest Thema schema version
// 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 pluginmeta.