coremodel

package
v0.0.1-test Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 6, 2022 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllSlots

func AllSlots() map[string]*Slot

func CUEFramework

func CUEFramework() cue.Value

CUEFramework returns a cue.Value representing all the coremodel framework raw CUE files.

For low-level use in constructing other types and APIs, while still letting us declare all the frameworky CUE bits in a single package. Other types and subpackages make the constructs in this value easy to use.

The returned cue.Value is built from Grafana's standard central CUE context, ["github.com/grafana/grafana/pkg/cuectx".ProvideCueContext].

func CUEFrameworkWithContext

func CUEFrameworkWithContext(ctx *cue.Context) cue.Value

CUEFrameworkWithContext is the same as CUEFramework, but allows control over the cue.Context that's used.

Prefer CUEFramework unless you understand cue.Context, and absolutely need this control.

func Mux

func Mux(cm Interface, opts ...MuxOption) kernel.InputKernel

Mux takes a coremodel and returns a Thema version muxer that, given a byte slice containing any version of schema for that coremodel, will translate it to the Interface.CurrentSchema() version, and optionally decode it onto the Interface.GoType().

By default, JSON decoding will be used, and the filename given to any input bytes (shown in errors, which may be user-facing) will be "<name>.<encoding>", e.g. dashboard.json.

Types

type Interface

type Interface interface {
	// Lineage should return the canonical Thema lineage for the coremodel.
	Lineage() thema.Lineage

	// CurrentSchema should return the schema of the version that the Grafana backend
	// is currently written against. (While Grafana can accept data from all
	// older versions of the Thema schema, backend Go code is written against a
	// single version for simplicity)
	CurrentSchema() thema.Schema

	// GoType should return a pointer to the Go struct type that corresponds to
	// the Current() schema.
	GoType() interface{}
}

Interface is the primary coremodel interface that must be implemented by all Grafana coremodels. A coremodel is the foundational, canonical schema for some known-at-compile-time Grafana object.

Currently, all Coremodels are expressed as Thema lineages.

type MuxOption

type MuxOption muxOption

A MuxOption defines options that may be specified only at initial construction of a Lineage via BindLineage.

func Filename

func Filename(name string) MuxOption

Filename specifies the filename that is given to input bytes passing through the mux.

The filename has no impact on mux behavior, but is used in user-facing error output, such as schema validation failures. Thus, it is recommended to pick a name that will make sense in the context a user is expected to see the error.

func YAML

func YAML() MuxOption

YAML indicates that the resulting Mux should look for YAML in input bytes, rather than the default JSON.

type Slot

type Slot struct {
	// contains filtered or unexported fields
}

Slot represents one of Grafana's named Thema composition slot definitions.

func (Slot) ForPluginType

func (s Slot) ForPluginType(plugintype string) (may, must bool)

ForPluginType indicates whether for this Slot, plugins of the given type may provide a slot implementation (first return value), and for those types that may, whether they must produce one (second return value).

Expected values here are those in the set of ["github.com/grafana/grafana/pkg/coremodel/pluginmeta".Type], though passing a string not in that set will harmlessly return {false, false}. That type is not used here to avoid import cycles.

Note that, at least for now, plugins are not required to provide any slot implementations, and do so by simply not containing a models.cue file. Consequently, the "must" return value here is best understood as, "IF a plugin provides a models.cue file, it MUST contain an implementation of this slot."

func (Slot) IsGroup

func (s Slot) IsGroup() bool

IsGroup indicates whether the slot specifies a group lineage - one in which each top-level key represents a distinct schema for objects that are expected to exist in the wild, but objects corresponding to the root of the schema are not expected to exist.

func (Slot) MetaSchema

func (s Slot) MetaSchema() cue.Value

MetaSchema returns the meta-schema that is the contract between coremodels that compose the Slot, and plugins that implement it.

func (Slot) Name

func (s Slot) Name() string

Name returns the name of the Slot. The name is also used as the path at which a Slot lineage is defined in a plugin models.cue file.

Directories

Path Synopsis
Package Slot exposes Grafana's coremodel composition Slot definitions for use in Go.
Package Slot exposes Grafana's coremodel composition Slot definitions for use in Go.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL