silence

package
v0.0.0-...-9f34937 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2023 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound is returned if a silence was not found.
	ErrNotFound = fmt.Errorf("silence not found")
)
View Source
var ValidateMatcher = func(m *label.Matcher) error {
	if !label.LabelName(m.Name).IsValid() {
		return fmt.Errorf("invalid label name %q", m.Name)
	}
	switch m.Type {
	case label.MatchEqual, label.MatchNotEqual:
		if !utf8.ValidString(m.Value) {
			return fmt.Errorf("invalid label value %q", m.Value)
		}
	case label.MatchRegexp, label.MatchNotRegexp:
		if _, err := regexp.Compile(m.Value); err != nil {
			return fmt.Errorf("invalid regular expression %q: %s", m.Value, err)
		}
	default:
		return fmt.Errorf("unknown matcher type %q", m.Type)
	}
	return nil
}

ValidateMatcher runs validation on the matcher name, type, and pattern.

Functions

This section is empty.

Types

type Entry

type Entry struct {
	ID        int                `json:"id,omitempty"`
	UpdatedAt time.Time          `json:"created_at,omitempty"`
	Matchers  []*label.Matcher   `json:"matchers,omitempty"`
	StartsAt  time.Time          `json:"starts_at,omitempty"`
	EndsAt    time.Time          `json:"ends_at,omitempty"`
	State     alert.SilenceState `json:"state,omitempty"`
}

type EntryQuery

type EntryQuery func(*Entry) (bool, error)

func QIDs

func QIDs(ids []int) EntryQuery

func QMatchers

func QMatchers(set label.LabelSet, mc matcherCache) EntryQuery

QMatchers returns a EntryQuery that matches silences with the given.if not found matcher return true

func QState

func QState(now time.Time, states ...alert.SilenceState) EntryQuery

type MaintenanceFunc

type MaintenanceFunc func() error

MaintenanceFunc represents the function to run as part of the periodic maintenance for silences.

type Option

type Option func(*Options)

func WithDataLoader

func WithDataLoader(fn func(ids ...int) ([]*Entry, error)) Option

WithDataLoader sets the data loader function for the silences. if not set, the silences will use the memory to store silences. in distributed mode, this should be set to use the sync data.

type Options

type Options struct {
	// Retention time for newly created Silences. Silences may be
	// garbage collected after the given duration after they ended.
	Retention time.Duration

	MaintenanceInterval time.Duration
	MaintenanceFunc     MaintenanceFunc

	DataLoader func(ids ...int) ([]*Entry, error)
	Spreader   members.Spreader
}

Options exposes configuration options for creating a new Silences object. Its zero value is a safe default.

type Silencer

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

Silencer binds together a Marker and a Silences to implement the Muter interface.

func NewSilencer

func NewSilencer(s *Silences, m alert.Marker) *Silencer

NewSilencer returns a new Silencer.

func (*Silencer) Mutes

func (s *Silencer) Mutes(lset label.LabelSet) bool

Mutes implements the Muter interface.

type Silences

type Silences struct {
	Options
	// contains filtered or unexported fields
}

Silences holds a silence state that can be modified, queried, and snapshot.

func New

func New(o Options) (*Silences, error)

New returns a new Silences object with the given configuration.

func NewFromConfiguration

func NewFromConfiguration(cfg *conf.Configuration, opts ...Option) (*Silences, error)

NewFromConfiguration returns a new Silences object with the given configuration.

func (*Silences) CountState

func (s *Silences) CountState(states ...alert.SilenceState) (int, error)

CountState counts silences by state.

func (*Silences) Expire

func (s *Silences) Expire(id int) error

Expire the silence with the given ID immediately.

func (*Silences) GC

func (s *Silences) GC() (int, error)

GC runs a garbage collection that removes silences that have ended longer than the configured retention time ago.

func (*Silences) MarshalBinary

func (s *Silences) MarshalBinary() ([]byte, error)

func (*Silences) Merge

func (s *Silences) Merge(b []byte) error

func (*Silences) Name

func (s *Silences) Name() string

func (*Silences) Query

func (s *Silences) Query(qs ...EntryQuery) ([]*Entry, int, error)

Query for silences based on the given query parameters. It returns the resulting silences and the state version the result is based on.

func (*Silences) QueryOne

func (s *Silences) QueryOne(qs ...EntryQuery) (*Entry, error)

QueryOne queries with the given parameters and returns the first result. Returns ErrNotFound if the query result is empty.

func (*Silences) Set

func (s *Silences) Set(sil *Entry) (int, error)

Set the specified silence. If a silence with the ID already exists and the modification modifies history, the old silence gets expired and a new one is created.

func (*Silences) Start

func (s *Silences) Start(ctx context.Context) error

func (*Silences) Stop

func (s *Silences) Stop(ctx context.Context) error

func (*Silences) Version

func (s *Silences) Version() int

Version of the silence state.

Jump to

Keyboard shortcuts

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