Help us shape the future of Go! Take the 2026 Go Developer Survey

rulefmt

package
v0.313.0 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2026 License: Apache-2.0 Imports: 16 Imported by: 112

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	Group    string
	Rule     int
	RuleName string
	Err      WrappedError
}

Error represents semantic errors on parsing rule groups.

func (*Error) Error

func (err *Error) Error() string

Error prints the error message in a formatted string.

func (*Error) Unwrap added in v0.37.0

func (err *Error) Unwrap() error

Unwrap unpacks wrapped error for use in errors.Is & errors.As.

type Rule

type Rule struct {
	Record        string            `yaml:"record,omitempty"`
	Alert         string            `yaml:"alert,omitempty"`
	Expr          string            `yaml:"expr"`
	For           model.Duration    `yaml:"for,omitempty"`
	KeepFiringFor model.Duration    `yaml:"keep_firing_for,omitempty"`
	Labels        map[string]string `yaml:"labels,omitempty"`
	Annotations   map[string]string `yaml:"annotations,omitempty"`
}

Rule describes an alerting or recording rule.

func (*Rule) Validate added in v0.303.0

func (r *Rule) Validate(node RuleNode, nameValidationScheme model.ValidationScheme, p parser.Parser) (nodes []WrappedError)

Validate the rule and return a list of encountered errors.

type RuleGroup

type RuleGroup struct {
	Name        string            `yaml:"name"`
	Interval    model.Duration    `yaml:"interval,omitempty"`
	QueryOffset *model.Duration   `yaml:"query_offset,omitempty"`
	Limit       int               `yaml:"limit,omitempty"`
	Rules       []Rule            `yaml:"rules"`
	Labels      map[string]string `yaml:"labels,omitempty"`
}

RuleGroup is a list of sequentially evaluated recording and alerting rules.

type RuleGroupNode added in v0.304.0

type RuleGroupNode struct {
	yaml.Node
	Name        string            `yaml:"name"`
	Interval    model.Duration    `yaml:"interval,omitempty"`
	QueryOffset *model.Duration   `yaml:"query_offset,omitempty"`
	Limit       int               `yaml:"limit,omitempty"`
	Rules       []RuleNode        `yaml:"rules"`
	Labels      map[string]string `yaml:"labels,omitempty"`
}

RuleGroupNode adds yaml.v3 layer to support line and columns outputs for invalid rule groups.

type RuleGroups

type RuleGroups struct {
	Groups []RuleGroup `yaml:"groups"`
}

RuleGroups is a set of rule groups that are typically exposed in a file.

func Parse

func Parse(
	content []byte,
	ignoreUnknownFields bool,
	nameValidationScheme model.ValidationScheme,
	p parser.Parser,
	logger *slog.Logger,
) (*RuleGroups, []error)

Parse parses and validates a set of rules.

func ParseFile

func ParseFile(
	file string,
	ignoreUnknownFields bool,
	nameValidationScheme model.ValidationScheme,
	p parser.Parser,
	logger *slog.Logger,
) (*RuleGroups, []error)

ParseFile reads and parses rules from a file.

func (*RuleGroups) Validate

func (g *RuleGroups) Validate(node ruleGroups, nameValidationScheme model.ValidationScheme, p parser.Parser) (errs []error)

Validate validates all rules in the rule groups.

type RuleNode

type RuleNode struct {
	Record        yaml.Node         `yaml:"record,omitempty"`
	Alert         yaml.Node         `yaml:"alert,omitempty"`
	Expr          yaml.Node         `yaml:"expr"`
	For           model.Duration    `yaml:"for,omitempty"`
	KeepFiringFor model.Duration    `yaml:"keep_firing_for,omitempty"`
	Labels        map[string]string `yaml:"labels,omitempty"`
	Annotations   map[string]string `yaml:"annotations,omitempty"`
}

RuleNode adds yaml.v3 layer to support line and column outputs for invalid rules.

type WrappedError

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

WrappedError wraps error with the yaml node which can be used to represent the line and column numbers of the error.

func (*WrappedError) Error

func (we *WrappedError) Error() string

Error prints the error message in a formatted string.

func (*WrappedError) Unwrap added in v0.37.0

func (we *WrappedError) Unwrap() error

Unwrap unpacks wrapped error for use in errors.Is & errors.As.

Jump to

Keyboard shortcuts

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