nflog

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2017 License: Apache-2.0 Imports: 13 Imported by: 0

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 paramters.

Index

Constants

This section is empty.

Variables

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 interface {
	// The Log* methods store a notification log entry for
	// a fully qualified receiver and a given IDs identifying the
	// alert object.
	Log(r *pb.Receiver, key string, firing, resolved []uint64) error

	// Query the log along the given Paramteres.
	//
	// TODO(fabxc):
	// - extend the interface by a `QueryOne` method?
	// - return an iterator rather than a materialized list?
	Query(p ...QueryParam) ([]*pb.Entry, error)

	// Snapshot the current log state and return the number
	// of bytes written.
	Snapshot(w io.Writer) (int, error)
	// GC removes expired entries from the log. It returns
	// the total number of deleted entries.
	GC() (int, error)
}

Log stores and serves information about notifications about byte-slice addressed alert objects to different receivers.

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.

type Option

type Option func(*nlog) error

Option configures a new Log implementation.

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()) 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.

func WithMesh

func WithMesh(create func(g mesh.Gossiper) mesh.Gossip) Option

WithMesh registers the log with a mesh network with which the log state will be shared.

func WithMetrics added in v0.5.1

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

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.

Directories

Path Synopsis
Package nflogpb is a generated protocol buffer package.
Package nflogpb is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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