...

Package nflog

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

Overview ▾

Package nflog implements a garbage-collected and snapshottable append-only log of active/resolved notifications. Each log entry stores the active/resolved state, the notified receiver, and a hash digest of the notification's identifying contents. The log can be queried along different parameters.

Variables

ErrInvalidState is returned if the state isn't valid.

var ErrInvalidState = errors.New("invalid state")

ErrNotFound is returned for empty query results.

var ErrNotFound = errors.New("not found")

type Log

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

func New

func New(opts ...Option) (*Log, error)

New creates a new notification log based on the provided options. The snapshot is loaded into the Log if it is set.

func (*Log) GC

func (l *Log) GC() (int, error)

GC implements the Log interface.

func (*Log) Log

func (l *Log) Log(r *pb.Receiver, gkey string, firingAlerts, resolvedAlerts []uint64, expiry time.Duration) error

func (*Log) MarshalBinary

func (l *Log) MarshalBinary() ([]byte, error)

MarshalBinary serializes all contents of the notification log.

func (*Log) Merge

func (l *Log) Merge(b []byte) error

Merge merges notification log state received from the cluster with the local state.

func (*Log) Query

func (l *Log) Query(params ...QueryParam) ([]*pb.Entry, error)

Query implements the Log interface.

func (*Log) SetBroadcast

func (l *Log) SetBroadcast(f func([]byte))

SetBroadcast sets a broadcast callback that will be invoked with serialized state on updates.

func (*Log) Snapshot

func (l *Log) Snapshot(w io.Writer) (int64, error)

Snapshot implements the Log interface.

type MaintenanceFunc

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

type MaintenanceFunc func() (int64, error)

type Option

Option configures a new Log implementation.

type Option func(*Log) error

func WithLogger

func WithLogger(logger log.Logger) Option

WithLogger configures a logger for the notification log.

func WithMaintenance

func WithMaintenance(d time.Duration, stopc chan struct{}, done func(), maintenanceOverride MaintenanceFunc) Option

WithMaintenance configures the Log to run garbage collection and snapshotting, if configured, at the given interval.

The maintenance terminates on receiving from the provided channel. The done function is called after the final snapshot was completed. If not nil, the last argument is an override for what to do as part of the maintenance - for advanced usage.

func WithMetrics

func WithMetrics(r prometheus.Registerer) Option

WithMetrics registers metrics for the notification log.

func WithNow

func WithNow(f func() time.Time) Option

WithNow overwrites the function used to retrieve a timestamp for the current point in time. This is generally useful for injection during tests.

func WithRetention

func WithRetention(d time.Duration) Option

WithRetention sets the retention time for log st.

func WithSnapshot

func WithSnapshot(sf string) Option

WithSnapshot configures the log to be initialized from a given snapshot file. If maintenance is configured, a snapshot will be saved periodically and on shutdown as well.

type QueryParam

QueryParam is a function that modifies a query to incorporate a set of parameters. Returns an error for invalid or conflicting parameters.

type QueryParam func(*query) error

func QGroupKey

func QGroupKey(gk string) QueryParam

QGroupKey adds a group key as querying argument.

func QReceiver

func QReceiver(r *pb.Receiver) QueryParam

QReceiver adds a receiver parameter to a query.

Subdirectories

Name Synopsis
..
nflogpb