prometheus

package
v0.0.0-...-a7bbfa5 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2023 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const MetadataRecordingRulesGenerator = metadataRecordingRulesGenerator(false)

MetadataRecordingRulesGenerator knows how to generate the metadata prometheus recording rules from an SLO.

Variables

View Source
var (
	// ErrNoSLORules will be used when there are no rules to store. The upper layer
	// could ignore or handle the error in cases where there wasn't an output.
	ErrNoSLORules = fmt.Errorf("0 SLO Prometheus rules generated")
)
View Source
var OptimizedSLIRecordingRulesGenerator = sliRecordingRulesGenerator{/* contains filtered or unexported fields */}

OptimizedSLIRecordingRulesGenerator knows how to generate the SLI prometheus recording rules from an SLO optimizing where it can. Normally these rules are used by the SLO alerts.

View Source
var SLIRecordingRulesGenerator = sliRecordingRulesGenerator{/* contains filtered or unexported fields */}

SLIRecordingRulesGenerator knows how to generate the SLI prometheus recording rules form an SLO. Normally these rules are used by the SLO alerts.

View Source
var SLOAlertRulesGenerator = sloAlertRulesGenerator{/* contains filtered or unexported fields */}

SLOAlertRulesGenerator knows how to generate the SLO prometheus alert rules from an SLO.

Functions

This section is empty.

Types

type AlertMeta

type AlertMeta struct {
	Disable     bool
	Name        string            `validate:"required_if_enabled"`
	Labels      map[string]string `validate:"dive,keys,prom_label_key,endkeys,required,prom_label_value"`
	Annotations map[string]string `validate:"dive,keys,prom_annot_key,endkeys,required"`
}

AlertMeta is the metadata of an alert settings.

type FileManager

type FileManager interface {
	FindFiles(ctx context.Context, root string, matcher *regexp.Regexp) (paths []string, err error)
	ReadFile(ctx context.Context, path string) (data []byte, err error)
}

FileManager knows how to manage files.

type FileSLIPluginRepo

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

FileSLIPluginRepo will provide the plugins loaded from files. To be able to provide a simple and safe plugin system to the user we have set some rules/requirements that a plugin must implement:

- The plugin must be in a `plugin.go` file inside a directory. - All the plugin must be in the `plugin.go` file. - The plugin can't import anything apart from the Go standard library. - `reflect` and `unsafe` packages can't be used.

These rules provide multiple things: - Easy discovery of plugins without the need to provide extra data (import paths, path sanitization...). - Safety because we don't allow adding external packages easily. - Force keeping the plugins simple, small and without smart code. - Force avoiding DRY in small plugins and embrace WET to have independent plugins.

func NewFileSLIPluginRepo

func NewFileSLIPluginRepo(config FileSLIPluginRepoConfig) (*FileSLIPluginRepo, error)

func (*FileSLIPluginRepo) GetSLIPlugin

func (f *FileSLIPluginRepo) GetSLIPlugin(ctx context.Context, id string) (*SLIPlugin, error)

func (*FileSLIPluginRepo) ListSLIPlugins

func (f *FileSLIPluginRepo) ListSLIPlugins(ctx context.Context) (map[string]SLIPlugin, error)

func (*FileSLIPluginRepo) Reload

func (f *FileSLIPluginRepo) Reload(ctx context.Context) error

Reload will reload all the plugins again from the paths.

type FileSLIPluginRepoConfig

type FileSLIPluginRepoConfig struct {
	FileManager FileManager
	Paths       []string
	Logger      log.Logger
}

type IOWriterGroupedRulesYAMLRepo

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

IOWriterGroupedRulesYAMLRepo knows to store all the SLO rules (recordings and alerts) grouped in an IOWriter in YAML format, that is compatible with Prometheus.

func NewIOWriterGroupedRulesYAMLRepo

func NewIOWriterGroupedRulesYAMLRepo(writer io.Writer, logger log.Logger) IOWriterGroupedRulesYAMLRepo

func (IOWriterGroupedRulesYAMLRepo) StoreSLOs

func (i IOWriterGroupedRulesYAMLRepo) StoreSLOs(ctx context.Context, slos []StorageSLO) error

StoreSLOs will store the recording and alert prometheus rules, if grouped is false it will split and store as 2 different groups the alerts and the recordings, if true it will be save as a single group.

type SLI

type SLI struct {
	Raw    *SLIRaw
	Events *SLIEvents
}

SLI reprensents an SLI with custom error and total expressions.

type SLIEvents

type SLIEvents struct {
	ErrorQuery string `validate:"required,prom_expr,template_vars"`
	TotalQuery string `validate:"required,prom_expr,template_vars"`
}

type SLIPlugin

type SLIPlugin struct {
	ID   string
	Func plugin.SLIPlugin
}

type SLIPluginRepo

type SLIPluginRepo interface {
	GetSLIPlugin(ctx context.Context, id string) (*SLIPlugin, error)
}

type SLIRaw

type SLIRaw struct {
	ErrorRatioQuery string `validate:"required,prom_expr,template_vars"`
}

type SLO

type SLO struct {
	ID              string `validate:"required,name"`
	Name            string `validate:"required,name"`
	Description     string
	Service         string            `validate:"required,name"`
	SLI             SLI               `validate:"required"`
	TimeWindow      time.Duration     `validate:"required"`
	Objective       float64           `validate:"gt=0,lte=100"`
	Labels          map[string]string `validate:"dive,keys,prom_label_key,endkeys,required,prom_label_value"`
	PageAlertMeta   AlertMeta
	TicketAlertMeta AlertMeta
}

SLO represents a service level objective configuration.

func (SLO) GetSLIErrorMetric

func (s SLO) GetSLIErrorMetric(window time.Duration) string

GetSLIErrorMetric returns the SLI error metric.

func (SLO) GetSLOIDPromLabels

func (s SLO) GetSLOIDPromLabels() map[string]string

GetSLOIDPromLabels returns the ID labels of an SLO, these can be used to identify an SLO recorded metrics and alerts.

type SLOGroup

type SLOGroup struct {
	SLOs []SLO `validate:"required,dive"`
}

func (SLOGroup) Validate

func (s SLOGroup) Validate() error

Validate validates the SLO.

type SLORules

type SLORules struct {
	SLIErrorRecRules []rulefmt.Rule
	MetadataRecRules []rulefmt.Rule
	AlertRules       []rulefmt.Rule
}

SLORules are the prometheus rules required by an SLO.

type StorageSLO

type StorageSLO struct {
	SLO   SLO
	Rules SLORules
}

type YAMLSpecLoader

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

YAMLSpecLoader knows how to load YAML specs and converts them to a model.

func NewYAMLSpecLoader

func NewYAMLSpecLoader(pluginsRepo SLIPluginRepo, windowPeriod time.Duration) YAMLSpecLoader

NewYAMLSpecLoader returns a YAML spec loader.

func (YAMLSpecLoader) IsSpecType

func (y YAMLSpecLoader) IsSpecType(ctx context.Context, data []byte) bool

func (YAMLSpecLoader) LoadSpec

func (y YAMLSpecLoader) LoadSpec(ctx context.Context, data []byte) (*SLOGroup, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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