probes

package
v0.0.0-...-6503209 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2024 License: LGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterProbeType

func RegisterProbeType(ptype string, pfunc probeParserFunc)

Types

type Probe

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

A Probe holds all the runtime information necessary to run a single probe, combining the SpecCommon parameters with a ProbeImpl to actually execute the probe.

func ParseConfig

func ParseConfig(data []byte, resultStore ResultStore) ([]*Probe, error)

ParseConfig parses a JSON-encoded configuration and returns a list of Probe objects that can be executed or sent to the scheduler.

Configuration parsing has a few phases: decoding the configuration itself is a relatively complex task, as we are implementing polymorphysm on probe definitions (via their "params" attribute).This requires a multi-level approach in Go, where JSON parsing is split into generic / specific stages, with the latter delegated to a type-specific parser accessed via a global registry. The result of this process is a "template" probe called a Spec, which has to be an interface type because the actual struct definition is private to the specific probe implementation.

Then, parameterization is applied, potentially generating multiple Probes from each Spec. Variables are expanded, and all necessary information is bound together in the runtime-ready Probe object. The variable expansion process is reflect-heavy but is only performed once at the start of the process. The resulting Probe objects are minimal and lean.

func (*Probe) Interval

func (p *Probe) Interval() time.Duration

Interval satisfies the scheduler.PeriodicEvent interface.

func (*Probe) Name

func (p *Probe) Name() string

Name is a convenience function to return the probe name.

func (*Probe) Tick

func (p *Probe) Tick(ctx context.Context)

Tick satisfies the scheduler.PeriodicEvent interface.

type ProbeImpl

type ProbeImpl interface {
	RunProbe(context.Context, *log.Logger) error
}

ProbeImpl is the probe-specific implementation interface.

type Result

type Result struct {
	ID       string
	Spec     SpecCommon
	Ok       bool
	Error    string
	Start    time.Time
	Duration time.Duration
	Logs     string
}

Result of the execution of a probe.

func (*Result) String

func (r *Result) String() string

Nice displayable string.

type ResultStore

type ResultStore interface {
	Push(*Result)
	Each(func(*Result))
	EachErrs(func(*Result))
	Find(string) *Result
}

ResultStore keeps the most recent probe results in storage, and allows access to them (mostly for debugging purposes, as this part isn't required by the prober functionality). The results buffer has a fixed size, so older results will be dropped as more recent ones come in. Failures are kept in a separate buffer, with the hope of keeping errors around for longer for inspection purposes, even after they've recovered.

func NewInstrumentedResultStore

func NewInstrumentedResultStore(wrap ResultStore) ResultStore

func NewResultStore

func NewResultStore(numOk, numErrs int) ResultStore

type Spec

type Spec interface {
	Build(map[string]interface{}) (ProbeImpl, error)
}

Spec is the generic interface for probe implementation factory functions.

type SpecCommon

type SpecCommon struct {
	Type     string             `json:"type"`
	Name     string             `json:"name"`
	Loop     []string           `json:"loop"`
	Labels   map[string]string  `json:"labels"`
	Interval jsontypes.Duration `json:"interval"`
	Timeout  jsontypes.Duration `json:"timeout"`
}

SpecCommon holds the parameters common to all probe specifications.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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