rulefmt

package
v0.54.0-rc.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2024 License: Apache-2.0 Imports: 14 Imported by: 111

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.

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       []RuleNode      `yaml:"rules"`
}

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

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) (*RuleGroups, []error)

Parse parses and validates a set of rules.

func ParseFile

func ParseFile(file string) (*RuleGroups, []error)

ParseFile reads and parses rules from a file.

func (*RuleGroups) Validate

func (g *RuleGroups) Validate(node ruleGroups) (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.

func (*RuleNode) Validate

func (r *RuleNode) Validate() (nodes []WrappedError)

Validate the rule and return a list of encountered errors.

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