nflog

package
v0.31.0 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 License: Apache-2.0 Imports: 17 Imported by: 110

Documentation

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.

Index

Constants

This section is empty.

Variables

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

ErrInvalidState is returned if the state isn't valid.

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

ErrNotFound is returned for empty query results.

Functions

This section is empty.

Types

type Log

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

Log holds the notification log state for alerts that have been notified.

func New

func New(o Options) (*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 added in v0.6.0

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

func (*Log) Maintenance added in v0.26.0

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

Maintenance garbage collects the notification log 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 (*Log) MarshalBinary added in v0.15.0

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

MarshalBinary serializes all contents of the notification log.

func (*Log) Merge added in v0.15.0

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 added in v0.15.0

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 added in v0.24.0

type MaintenanceFunc func() (int64, error)

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 Options added in v0.26.0

type Options struct {
	SnapshotReader io.Reader
	SnapshotFile   string

	Retention time.Duration

	Logger  *slog.Logger
	Metrics prometheus.Registerer
}

Options configures a new Log implementation.

type QueryParam

type QueryParam func(*query) error

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

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.

type Store added in v0.31.0

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

Store abstracts the NFLog's receiver data storage as a mutable key/value store. A store can be generated from a nflogpb.Entry and then written via the call to Log.

Every key in the Store is associated with either an int, float, or string value.

func NewStore added in v0.31.0

func NewStore(entry *pb.Entry) *Store

NewStore creates a Store from the entry's receiver data. If entry is nil, the resulting Store is empty.

func (*Store) Delete added in v0.31.0

func (s *Store) Delete(key string)

Delete deletes any value associated with the key.

func (*Store) GetFloat added in v0.31.0

func (s *Store) GetFloat(key string) (float64, bool)

GetFloat finds the float value associated with the key, if any, and returns it.

func (*Store) GetInt added in v0.31.0

func (s *Store) GetInt(key string) (int64, bool)

GetInt finds the integer value associated with the key, if any, and returns it.

func (*Store) GetStr added in v0.31.0

func (s *Store) GetStr(key string) (string, bool)

GetFloat finds the string value associated with the key, if any, and returns it.

func (*Store) SetFloat added in v0.31.0

func (s *Store) SetFloat(key string, v float64)

SetFloat associates a float value with the provided key, overwriting any existing value.

func (*Store) SetInt added in v0.31.0

func (s *Store) SetInt(key string, v int64)

SetInt associates an integer value with the provided key, overwriting any existing value.

func (*Store) SetStr added in v0.31.0

func (s *Store) SetStr(key, v string)

SetStr associates a string value with the provided key, overwriting any existing value.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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