...

Package silence

import "github.com/prometheus/alertmanager/silence"
Overview
Index
Subdirectories

Overview ▾

Package silence provides a storage for silences, which can share its state over a mesh network and snapshot it.

Variables

ErrInvalidState is returned if the state isn't valid.

var ErrInvalidState = fmt.Errorf("invalid state")

ErrNotFound is returned if a silence was not found.

var ErrNotFound = fmt.Errorf("silence not found")

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

var ValidateMatcher = func(m *pb.Matcher) error {
    if !model.LabelName(m.Name).IsValid() {
        return fmt.Errorf("invalid label name %q", m.Name)
    }
    switch m.Type {
    case pb.Matcher_EQUAL, pb.Matcher_NOT_EQUAL:
        if !model.LabelValue(m.Pattern).IsValid() {
            return fmt.Errorf("invalid label value %q", m.Pattern)
        }
    case pb.Matcher_REGEXP, pb.Matcher_NOT_REGEXP:
        if _, err := regexp.Compile(m.Pattern); err != nil {
            return fmt.Errorf("invalid regular expression %q: %s", m.Pattern, err)
        }
    default:
        return fmt.Errorf("unknown matcher type %q", m.Type)
    }
    return nil
}

type MaintenanceFunc

MaintenanceFunc represents the function to run as part of the periodic maintenance for silences. It returns the size of the snapshot taken or an error if it failed.

type MaintenanceFunc func() (int64, error)

type Options

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

type Options struct {
    // A snapshot file or reader from which the initial state is loaded.
    // None or only one of them must be set.
    SnapshotFile   string
    SnapshotReader io.Reader

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

    // A logger used by background processing.
    Logger  log.Logger
    Metrics prometheus.Registerer
}

type QueryParam

QueryParam expresses parameters along which silences are queried.

type QueryParam func(*query) error

func QIDs

func QIDs(ids ...string) QueryParam

QIDs configures a query to select the given silence IDs.

func QMatches

func QMatches(set model.LabelSet) QueryParam

QMatches returns silences that match the given label set.

func QState

func QState(states ...types.SilenceState) QueryParam

QState filters queried silences by the given states.

type Silencer

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

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

func NewSilencer

func NewSilencer(s *Silences, m types.Marker, l log.Logger) *Silencer

NewSilencer returns a new Silencer.

func (*Silencer) Mutes

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

Mutes implements the Muter interface.

type Silences

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

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

func New

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

New returns a new Silences object with the given configuration.

func (*Silences) CountState

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

CountState counts silences by state.

func (*Silences) Expire

func (s *Silences) Expire(id string) 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) Maintenance

func (s *Silences) Maintenance(interval time.Duration, snapf string, stopc <-chan struct{}, override MaintenanceFunc)

Maintenance garbage collects the silence state at the given interval. If the snapshot file is set, a snapshot is written to it afterwards. Terminates on receiving from stopc. If not nil, the last argument is an override for what to do as part of the maintenance - for advanced usage.

func (*Silences) MarshalBinary

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

MarshalBinary serializes all silences.

func (*Silences) Merge

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

Merge merges silence state received from the cluster with the local state.

func (*Silences) Query

func (s *Silences) Query(params ...QueryParam) ([]*pb.Silence, 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(params ...QueryParam) (*pb.Silence, 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 *pb.Silence) (string, 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) SetBroadcast

func (s *Silences) SetBroadcast(f func([]byte))

SetBroadcast sets the provided function as the one creating data to be broadcast.

func (*Silences) Snapshot

func (s *Silences) Snapshot(w io.Writer) (int64, error)

Snapshot writes the full internal state into the writer and returns the number of bytes written.

func (*Silences) Version

func (s *Silences) Version() int

Version of the silence state.

Subdirectories

Name Synopsis
..
silencepb