observability

package
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package observability renders the Grafana dashboards and Prometheus alert rules the framework ships for operators built on it. The templates are embedded, so a render always matches the framework version the binary was built from.

Index

Constants

View Source
const (
	// AlertFormatPrometheusRule wraps each rule file in a
	// monitoring.coreos.com/v1 PrometheusRule object for the Prometheus
	// Operator.
	AlertFormatPrometheusRule AlertFormat = "prometheusrule"
	// AlertFormatRules writes the plain groups: file that Prometheus loads
	// through rule_files.
	AlertFormatRules AlertFormat = "rules"

	// DefaultNamespaceLabel is the label a scrape through a ServiceMonitor or
	// PodMonitor leaves the owner's namespace under: the target's own namespace
	// label collides with the exported one, which Prometheus renames.
	DefaultNamespaceLabel = "exported_namespace"

	// MaxMetricNamespaceLen caps the metric namespace. It prefixes the
	// dashboard uids, which Grafana limits to maxGrafanaUIDLen characters, and
	// the longest dashboard file name, crd_conditions_browser, is 22
	// characters plus the joining underscore. templates_test.go pins that
	// arithmetic to the dashboard file names.
	MaxMetricNamespaceLen = 17
)

Variables

This section is empty.

Functions

func ParseLabels

func ParseLabels(value string) (map[string]string, error)

ParseLabels parses the comma-separated key=value list of --prometheusrule-labels. An empty string yields nil. An entry without a key or without "=" is an error naming the entry.

func Render

func Render(opts Options, outDir string) ([]string, error)

Render writes the dashboards and alert rules for opts into outDir as <outDir>/dashboards/<name>.json and <outDir>/alerts/<name>.yaml, and returns the written paths. Rendered files are regenerated output: every .json in the dashboards directory and every .yaml in the alerts directory is removed first, so a file a framework upgrade renamed or dropped does not linger. opts is validated before anything is written.

Types

type AlertFormat

type AlertFormat string

AlertFormat selects the shape of the rendered alert files.

type Options

type Options struct {
	// MetricNamespace is the argument the operator passed to
	// ocm.NewOperatorConditionsGauge. It names the condition gauge, the
	// dashboard uids and the condition PrometheusRule. Required.
	MetricNamespace string
	// NamespaceLabel is the label carrying the owner's namespace on condition
	// series, substituted into PromQL as a label name. Use
	// DefaultNamespaceLabel unless the scrape keeps the exported label.
	NamespaceLabel string
	// AlertFormat is the shape of the rendered alert files.
	AlertFormat AlertFormat
	// PrometheusRuleNamespace is metadata.namespace of the PrometheusRule
	// objects. Empty leaves it out.
	PrometheusRuleNamespace string
	// PrometheusRuleLabels are written to metadata.labels of the
	// PrometheusRule objects, in key order.
	PrometheusRuleLabels map[string]string
}

Options are the inputs of a render, the values of the "ocf observability render" flags.

func (Options) Validate

func (o Options) Validate() error

Validate reports the first option that cannot render. Messages name the "ocf observability render" flag the value came from.

Jump to

Keyboard shortcuts

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