diagnostics

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: AGPL-3.0 Imports: 9 Imported by: 2 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package diagnostics lets a plugin publish a small, bounded set of in-process measurements. The host pulls them through the PluginLifecycle GetDiagnostics RPC and merges them into its own diagnostics collector.

The package is deliberately narrow so a plugin cannot leak data or flood the host: attribute keys are a closed enum, attribute values and metric names are pattern-checked, and the number of metrics, series per metric and attributes per series is capped. Observations that break a rule are dropped (never clamped) and flag the next snapshot as truncated. Never record resource names, queries, identifiers, error text or credentials as attribute values.

Index

Constants

View Source
const (
	SchemaVersion = 1
	MaxMetrics    = 24
	MaxPoints     = 16
	MaxAttrs      = 4
	MaxBounds     = 16
)

Wire limits. Hosts enforce the same limits and drop nonconforming data.

Allowed attribute keys.

Variables

View Source
var (
	// ErrInvalidMetric means a name, unit or bucket layout was rejected.
	ErrInvalidMetric = errors.New("invalid diagnostics metric")
	// ErrTooManyMetrics means the registry already holds MaxMetrics metrics.
	ErrTooManyMetrics = errors.New("too many diagnostics metrics")
)

Functions

func ValidKey

func ValidKey(key Key) bool

ValidKey reports whether key is one of the closed attribute keys.

func ValidName

func ValidName(name string) bool

ValidName reports whether name is an allowed metric name.

func ValidUnit

func ValidUnit(unit string) bool

ValidUnit reports whether unit is an allowed unit string.

func ValidValue

func ValidValue(value string) bool

ValidValue reports whether value is an allowed attribute value.

Types

type Attr

type Attr struct {
	Key   Key
	Value string
}

Attr is one attribute of a series. Values must match ^[a-z][a-z0-9_]{0,31}$.

type Counter

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

Counter is a monotonically increasing total. A nil Counter ignores calls.

func (*Counter) Add

func (c *Counter) Add(delta uint64, attrs ...Attr)

Add increases the counter, saturating at the maximum uint64.

type Gauge

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

Gauge is a current value. A nil Gauge ignores calls.

func (*Gauge) Set

func (g *Gauge) Set(value float64, attrs ...Attr)

Set replaces the value. Non-finite values are dropped.

type Histogram

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

Histogram is a cumulative distribution. A nil Histogram ignores calls.

func (*Histogram) Observe

func (h *Histogram) Observe(value float64, attrs ...Attr)

Observe records one value. Non-finite values are dropped.

type Key

type Key = lifecyclepb.DiagKey

Key is a closed set of attribute keys.

type Registry

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

Registry holds a plugin's instruments. Use Default for the process registry.

func Default

func Default() *Registry

Default returns the process-wide registry served by the SDK lifecycle service.

func NewRegistry

func NewRegistry() *Registry

NewRegistry returns an empty registry.

func (*Registry) Counter

func (r *Registry) Counter(name, unit string) (*Counter, error)

Counter registers or returns a counter.

func (*Registry) Gauge

func (r *Registry) Gauge(name, unit string) (*Gauge, error)

Gauge registers or returns a gauge.

func (*Registry) Histogram

func (r *Registry) Histogram(name, unit string, bounds []float64) (*Histogram, error)

Histogram registers or returns a histogram with 1..MaxBounds increasing bounds.

func (*Registry) Snapshot

func (r *Registry) Snapshot() ([]*lifecyclepb.DiagMetric, bool)

Snapshot copies current state. Metrics without points are omitted, so an unobserved instrument is absent rather than reported as zero. It is safe for concurrent use and holds each instrument lock only while copying.

func (*Registry) StartUnixNano

func (r *Registry) StartUnixNano() int64

StartUnixNano is when this registry was created; it changes on restart.

Jump to

Keyboard shortcuts

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