grafana/pkg/models/object.go

120 lines
4.3 KiB
Go
Raw Normal View History

package models
//-----------------------------------------------------------------------------------------------------
// NOTE: the object store is in heavy development, and the locations will likely continue to move
//-----------------------------------------------------------------------------------------------------
import "context"
const (
StandardKindDashboard = "dashboard"
StandardKindPlaylist = "playlist"
StandardKindFolder = "folder"
// StandardKindDataSource: not a real kind yet, but used to define references from dashboards
// Types: influx, prometheus, testdata, ...
StandardKindDataSource = "ds"
// StandardKindPanel: currently used in two ways :( in search it defines a panel within a dashboard
// This is also used to refer to a panel plugin with type: heatmap, timeseries, table, ...
StandardKindPanel = "panel"
// StandardKindTransform: used to show that a dashboard depends on a set of transformations
// NOTE: this should likey be replaced with kind:system/type:transform/uid:joinByField or something like that
StandardKindTransform = "transform"
// StandardKindSVG SVG file support
StandardKindSVG = "svg"
// StandardKindPNG PNG file support
StandardKindPNG = "png"
// StandardKindQuery early development on panel query library
// the kind may need to change to better encapsulate { targets:[], transforms:[] }
StandardKindQuery = "query"
)
// ObjectKindInfo describes information needed from the object store
// All non-raw types will have a schema that can be used to validate
type ObjectKindInfo struct {
// Unique short id for this kind
ID string `json:"id,omitempty"`
// Display name (may be equal to the ID)
Name string `json:"name,omitempty"`
// Kind description
Description string `json:"description,omitempty"`
// The format is not controlled by a schema
IsRaw bool `json:"isRaw,omitempty"`
// The preferred save extension (svg, png, parquet, etc) if one exists
FileExtension string `json:"fileExtension,omitempty"`
// The correct mime-type to return for raw objects
MimeType string `json:"mimeType,omitempty"`
}
// ObjectSummary represents common data derived from a raw object bytes.
// The values should not depend on system state, and are derived from the raw object.
// This summary is used for a unified search and object listing
type ObjectSummary struct {
UID string `json:"uid,omitempty"`
Kind string `json:"kind,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
// Key value pairs. Tags are are represented as keys with empty values
Labels map[string]string `json:"labels,omitempty"`
// URL should only be set if the value is not derived directly from kind+uid
// NOTE: this may go away with a more robust GRN solution /!\
URL string `json:"URL,omitempty"`
// When errors exist
Error *ObjectErrorInfo `json:"error,omitempty"`
// Optional field values. The schema will define and document possible values for a given kind
Fields map[string]interface{} `json:"fields,omitempty"`
// eg: panels within dashboard
Nested []*ObjectSummary `json:"nested,omitempty"`
// Optional references to external things
References []*ObjectExternalReference `json:"references,omitempty"`
// The summary can not be extended
_ interface{}
}
// This will likely get replaced with a more general error framework.
type ObjectErrorInfo struct {
// TODO: Match an error code registry?
Code int64 `json:"code,omitempty"`
// Simple error display
Message string `json:"message,omitempty"`
// Error details
Details interface{} `json:"details,omitempty"`
}
// Reference to another object outside itself
// This message is derived from the object body and can be used to search for references.
// This does not represent a method to declare a reference to another object.
type ObjectExternalReference struct {
// datasource (instance), dashboard (instance),
Kind string `json:"kind,omitempty"`
// prometheus / heatmap, heatamp|prometheus
Type string `json:"type,omitempty"` // flavor
// Unique ID for this object
UID string `json:"UID,omitempty"`
}
// ObjectSummaryBuilder will read an object, validate it, and return a summary, sanitized payload, or an error
// This should not include values that depend on system state, only the raw object
type ObjectSummaryBuilder = func(ctx context.Context, uid string, body []byte) (*ObjectSummary, []byte, error)