Documentation
¶
Overview ¶
Package grafanadashboard is the fleet's typed Grafana dashboard model — a dashboard authored as a typed Dashboard of [Panel]s (with [Target]s and [Threshold]s) and rendered, borealis-themed, to Grafana dashboard JSON. So dashboards are types, not hand-edited JSON blobs that drift.
Why ¶
Grafana dashboards live as 1000-line JSON files that nobody hand-edits safely: a copy-pasted panel keeps a stale datasource, thresholds disagree across panels, the colour palette is whatever the last editor clicked. The cure is to author the dashboard as a typed value and render the JSON mechanically with a consistent (borealis/Tundra Aurora) theme.
Shape (Law 1, §3.5) ¶
d, err := grafanadashboard.New("service-red",
grafanadashboard.WithTitle("Service RED"),
grafanadashboard.WithPanel(grafanadashboard.Panel{
Title: "Request rate",
Type: grafanadashboard.TimeSeries,
Targets: []grafanadashboard.Target{{Expr: "rate(http_requests_total[5m])"}},
Thresholds: []grafanadashboard.Threshold{
{Value: 0, Role: grafanadashboard.RoleSuccess},
{Value: 100, Role: grafanadashboard.RoleWarning},
},
}))
jsonBytes, err := d.RenderJSON(grafanadashboard.Tundra())
RenderJSON is a pure function of the Dashboard + Theme: the same input yields byte-identical JSON every time (deterministic field order, panel grid laid out in declaration order, threshold colours resolved from the theme).
Theme (borealis-aligned) ¶
Tundra and Nord return the same Aurora-family palette the borealis design system binds to semantic roles. Thresholds and panel colours reference semantic [Role]s, not raw hex, so every fleet dashboard reads the same.
Weight (Law 6) ¶
Pure standard library (encoding/json) plus errors-go for typed, code-carrying errors. The theme palette is baked in as typed tokens; it does not import the heavy borealis charm stack — a dashboard renderer needs the hex tokens, not a terminal renderer.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Dashboard ¶
type Dashboard struct {
// UID is the stable dashboard UID. Required (seeds the JSON `uid`).
UID string
// Title is the human dashboard title. Defaults to the UID.
Title string
// Tags are dashboard tags, kept in declaration order.
Tags []string
// Datasource is the default datasource name applied to targets that do not
// set their own. Empty leaves Grafana's default.
Datasource string
// Panels are the dashboard's panels, laid out in declaration order.
Panels []Panel
}
Dashboard is the one typed declaration of a Grafana dashboard. Construct with New and functional options; the constructor applies defaults and validates invariants in one place.
func New ¶
New builds and validates a Dashboard. It returns a typed, code-carrying error (code "dashboard_invalid") when an invariant is violated.
func (*Dashboard) RenderJSON ¶
RenderJSON renders the dashboard to Grafana dashboard JSON, themed by t. It is a pure function of (Dashboard, Theme): the same input yields byte-identical JSON every call. Panels are laid out left-to-right, wrapping at the 24-column grid boundary, in declaration order.
type Option ¶
type Option func(*Dashboard)
Option configures a Dashboard during New.
func WithDatasource ¶
WithDatasource sets the default datasource.
type Panel ¶
type Panel struct {
// Title is the panel heading.
Title string
// Type selects the panel renderer. Defaults to [TimeSeries].
Type PanelType
// Unit is the value unit (Grafana unit id, e.g. "reqps", "s", "percent").
Unit string
// Width is the panel grid width in 24-column units (default 12).
Width int
// Height is the panel grid height in row units (default 8).
Height int
// Targets are the panel's queries.
Targets []Target
// Thresholds are the value bands; their colours resolve from the theme Role.
Thresholds []Threshold
}
Panel is one dashboard panel.
type Role ¶
type Role int
Role is a semantic colour intent, mirroring the borealis design system's Role vocabulary. A consumer maps a domain state (a threshold band, a panel emphasis) onto a Role; the Theme decides the actual hex, so every fleet dashboard reads the same and colours are never hand-authored (the ishou / borealis "consume tokens, never hex" rule).
const ( // RoleNeutral is inactive / baseline (Polar Night surface tone). RoleNeutral Role = iota // RolePrimary is the headline / primary-metric colour (Frost). RolePrimary // RoleSuccess is a healthy band (Aurora green). RoleSuccess // RoleInfo is informational (Frost cyan). RoleInfo // RoleWarning is a degraded band (Aurora yellow). RoleWarning // RoleDanger is a breached band (Aurora red). RoleDanger )
type Target ¶
type Target struct {
// Expr is the query expression (e.g. a PromQL string).
Expr string
// Legend is the legend format. Optional.
Legend string
// Datasource overrides the dashboard default for this target. Optional.
Datasource string
}
Target is one panel query.
type Theme ¶
type Theme struct {
// Name identifies the theme in the rendered dashboard metadata.
Name string
// contains filtered or unexported fields
}
Theme is the resolved token bundle: a Role → hex map plus the Grafana base colour names this theme prefers. It is pure data so a dashboard renders the same regardless of where the theme came from.
func Nord ¶
func Nord() Theme
Nord is an alias of Tundra under the upstream palette name — same tokens, provided so a consumer can name the source palette explicitly.
type Threshold ¶
type Threshold struct {
// Value is the band's lower bound. The first threshold conventionally has
// Value 0 and is the base band.
Value float64
// Role is the semantic colour intent for this band.
Role Role
}
Threshold is one value band. The colour is not a hex string but a semantic Role resolved from the Theme at render time — so dashboards never carry hand-authored colours.