rules

package
v0.0.0-...-b873372 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2024 License: AGPL-3.0 Imports: 15 Imported by: 3

Documentation

Index

Constants

View Source
const (
	MimirBackend = "mimir"
)

Variables

This section is empty.

Functions

func CompareGroups

func CompareGroups(groupOne, groupTwo rwrulefmt.RuleGroup) error

CompareGroups differentiates between two rule groups

func ParseFiles

func ParseFiles(backend string, files []string) (map[string]RuleNamespace, error)

ParseFiles returns a formatted set of prometheus rule groups

func PrintComparisonResult

func PrintComparisonResult(results []NamespaceChange, verbose bool) error

PrintComparisonResult prints the differences between the staged namespace and active namespace

func SummarizeChanges

func SummarizeChanges(changes []NamespaceChange) (created, updated, deleted int)

SummarizeChanges returns the number of each type of change in a set of changes

func ValidateRuleGroup

func ValidateRuleGroup(g rwrulefmt.RuleGroup) []error

ValidateRuleGroup validates a rulegroup

Types

type NamespaceChange

type NamespaceChange struct {
	Namespace     string
	State         NamespaceState
	GroupsUpdated []UpdatedRuleGroup
	GroupsCreated []rwrulefmt.RuleGroup
	GroupsDeleted []rwrulefmt.RuleGroup
}

NamespaceChange stores the various changes between a staged set of changes and the active rules configs.

func CompareNamespaces

func CompareNamespaces(original, new RuleNamespace) NamespaceChange

CompareNamespaces returns the differences between the two provided namespaces

func (NamespaceChange) ToOperations

func (c NamespaceChange) ToOperations() []NamespaceChangeOperation

ToOperations returns a list of operations to run to apply the given change. Each operation addresses a single rule group.

type NamespaceChangeOperation

type NamespaceChangeOperation struct {
	Namespace string
	State     NamespaceState
	RuleGroup rwrulefmt.RuleGroup
}

NamespaceChangeOperation holds an operation on a single rule group.

type NamespaceState

type NamespaceState int

NamespaceState is used to denote the difference between the staged namespace and active namespace for the mimir tenant

const (
	// Unchanged denotes the active namespace is identical to the staged namespace
	Unchanged NamespaceState = iota
	// Created denotes there is no active namespace for the staged namespace
	Created
	// Updated denotes the active namespace is different than the staged namespace
	Updated
	// Deleted denotes there is no staged namespace for the active namespace
	Deleted
)

func (NamespaceState) String

func (s NamespaceState) String() string

type RuleNamespace

type RuleNamespace struct {
	// Namespace field only exists for setting namespace in namespace body instead of file name
	Namespace string `yaml:"namespace,omitempty"`
	Filepath  string `yaml:"-"`

	Groups []rwrulefmt.RuleGroup `yaml:"groups"`
}

RuleNamespace is used to parse a slightly modified prometheus rule file format, if no namespace is set, the default namespace is used. Namespace is functionally the same as a file name.

func Parse

func Parse(f string) ([]RuleNamespace, []error)

Parse parses and validates a set of rules.

func ParseBytes

func ParseBytes(content []byte) ([]RuleNamespace, []error)

func (RuleNamespace) AggregateBy

func (r RuleNamespace) AggregateBy(label string, applyTo func(group rwrulefmt.RuleGroup, rule rulefmt.RuleNode) bool) (int, int, error)

AggregateBy modifies the aggregation rules in groups to include a given Label. If the applyTo function is provided, the aggregation is applied only to rules for which the applyTo function returns true.

func (RuleNamespace) CheckRecordingRules

func (r RuleNamespace) CheckRecordingRules(strict bool) int

CheckRecordingRules checks that recording rules have at least one colon in their name, this is based on the recording rules best practices here: https://prometheus.io/docs/practices/rules/ Returns the number of rules that don't match the requirements.

func (RuleNamespace) LintExpressions

func (r RuleNamespace) LintExpressions(backend string) (int, int, error)

LintExpressions runs the `expr` from a rule through the PromQL or LogQL parser and compares its output. If it differs from the parser, it uses the parser's instead.

func (RuleNamespace) Validate

func (r RuleNamespace) Validate() []error

Validate each rule in the rule namespace is valid

type UpdatedRuleGroup

type UpdatedRuleGroup struct {
	New      rwrulefmt.RuleGroup
	Original rwrulefmt.RuleGroup
}

UpdatedRuleGroup is used to store an change between a rule group

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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