alert

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2021 License: MIT Imports: 12 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SecureRule

func SecureRule(restrictQueries bool, matcherName, matcherValue string, rule *rulefmt.Rule) error

SecureRule attaches a label for tenantID to the given alert expression to to ensure that only metrics owned by this tenant can be alerted on

Types

type BulkUpdateResults

type BulkUpdateResults struct {
	Errors   map[string]error
	Statuses map[string]string
}

func NewBulkUpdateResults

func NewBulkUpdateResults() BulkUpdateResults

func (BulkUpdateResults) String

func (r BulkUpdateResults) String() string

type DirectoryClient

type DirectoryClient interface {
	Stat() (os.FileInfo, error)
	Mkdir(perm os.FileMode) error
	ReadDir() ([]os.FileInfo, error)
	Dir() string
}

DirectoryClient provides the necessary functions to read and modify a single directory for the FileLocker to operate

func NewDirectoryClient

func NewDirectoryClient(rulesDir string) DirectoryClient

type File

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

func NewFile

func NewFile(tenantID string) *File

func (*File) AddRule

func (f *File) AddRule(rule rulefmt.Rule)

AddRule appends a new rule to the list of rules in this file

func (*File) DeleteRule

func (f *File) DeleteRule(name string) error

func (*File) GetRule

func (f *File) GetRule(rulename string) *rulefmt.Rule

GetRule returns the specific rule by name. Nil if it isn't found

func (*File) ReplaceRule

func (f *File) ReplaceRule(newRule rulefmt.Rule) error

ReplaceRule replaces an existing rule. Returns error if rule does not exist already

func (*File) Rules

func (f *File) Rules() []rulefmt.Rule

Rules returns the rule configs from this file

type FileLocker

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

func NewFileLocker

func NewFileLocker(fs DirectoryClient) (*FileLocker, error)

func (*FileLocker) Lock

func (f *FileLocker) Lock(filename string)

Lock locks the mutex associated with the given filename for writing. If mutex does not exist in map yet, create one.

func (*FileLocker) RLock

func (f *FileLocker) RLock(filename string)

RLock locks the mutex associated with the given filename for reading. No-op if mutex does not exist in map

func (*FileLocker) RUnlock

func (f *FileLocker) RUnlock(filename string)

RUnlock unlocks the mutex associated with the given filename for reading. No-op if mutex does not exist in map

func (*FileLocker) Unlock

func (f *FileLocker) Unlock(filename string)

Unlock unlocks the mutex associated with the given filename for writing. No-op if mutex does not exist in map

type PrometheusAlertClient

type PrometheusAlertClient interface {
	ValidateRule(rule rulefmt.Rule) error
	RuleExists(filePrefix, rulename string) bool
	WriteRule(filePrefix string, rule rulefmt.Rule) error
	UpdateRule(filePrefix string, rule rulefmt.Rule) error
	ReadRules(filePrefix, ruleName string) ([]rulefmt.Rule, error)
	DeleteRule(filePrefix, ruleName string) error
	BulkUpdateRules(filePrefix string, rules []rulefmt.Rule) (BulkUpdateResults, error)
	ReloadPrometheus() error
	Tenancy() TenancyConfig
}

PrometheusAlertClient provides thread-safe methods for writing, reading, and modifying alert configuration files

func NewClient

func NewClient(fileLocks *FileLocker, prometheusURL string, fsClient fsclient.FSClient, tenancy TenancyConfig) PrometheusAlertClient

type RuleGroup

type RuleGroup struct {
	Name     string         `yaml:"name"`
	Interval model.Duration `yaml:"interval,omitempty"`
	Rules    []rulefmt.Rule `yaml:"rules"`
}

RuleGroup holds the fields in a Prometheus Alert Rule Group

type RuleJSONWrapper

type RuleJSONWrapper struct {
	Record      string            `json:"record,omitempty"`
	Alert       string            `json:"alert,omitempty"`
	Expr        string            `json:"expr"`
	For         string            `json:"for,omitempty"`
	Labels      map[string]string `json:"labels,omitempty"`
	Annotations map[string]string `json:"annotations,omitempty"`
}

RuleJSONWrapper Provides a struct to marshal/unmarshal into a rulefmt.Rule since rulefmt does not support json encoding

func (*RuleJSONWrapper) ToRuleFmt

func (r *RuleJSONWrapper) ToRuleFmt() (rulefmt.Rule, error)

type TenancyConfig

type TenancyConfig struct {
	RestrictorLabel string `json:"restrictor_label"`
	RestrictQueries bool   `json:"restrict_queries"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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