model

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package model defines the core types of kee. Probe providers should use this package to interface with the application. It is also used throughout the app to implement its features.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ProbeProvider

type ProbeProvider func(hcl.Body, *hcl.EvalContext) (Prober, error)

A ProbeProvider uses the provided configuration to return an Prober instance.

type Prober

type Prober interface {
	// Probe tests the health of resources. It must return by the time the context is cancelled.
	Probe(context.Context) Statuses
}

A Prober tests the health of zero, one or more resources and reports their state as Status values.

type Registry

type Registry interface {
	// RegisterProvider keeps a ProbeProvider function identified by a unique string.
	// RegisterProvider should be called from init() functions of probe providers packages.
	// It will panic if a provider with the same string identifier already exists.
	RegisterProvider(typeIdentifier string, configurer ProbeProvider)
	// GetProvider returns the ProbeProvider associated with the string identifier or an error if it was not found.
	GetProvider(typeIdentifier string) (ProbeProvider, error)
}

A Registry keeps track of probe providers for the configuration phase.

var DefaultRegistry Registry = make(defaultRegistry)

DefaultRegistry is a Registry to which probe providers should register themselves from their package init() function.

type Severity

type Severity uint

Severity describes how good or bad a system or resource is

const (
	// SeverityOk describes a system or resource as perfectly healthy and able to performe its function.
	SeverityOk Severity = 0
	// SeverityNotice describes a system or resource as healthy but with a abnormal condition that may be the sign of a problem.
	SeverityNotice Severity = 1
	// SeverityWarning describes a system or resource with a condition that partially degrades its ability to perform its function.
	SeverityWarning Severity = 2
	// SeverityCritical describes a system or resource no longer able to perform its function.
	SeverityCritical Severity = 3
)

func SeverityFromInt

func SeverityFromInt(n int) (Severity, error)

SeverityFromInt returns a Severity from an integer, or an error.

func SeverityFromStr

func SeverityFromStr(n string) (Severity, error)

SeverityFromStr parses a string representing a severity and returns a Severity or an error.

func (Severity) IsFailure

func (s Severity) IsFailure() bool

IsFailure is true when the Severity is not OK.

func (Severity) IsSuccess

func (s Severity) IsSuccess() bool

IsSuccess is true when the Severity is OK

func (Severity) IsWorseThan

func (s Severity) IsWorseThan(other Severity) bool

IsWorseThan is true when the other Severity, provided as argument, is less severe than the one this method is called on.

func (Severity) IsWorseThanOrEqualTo

func (s Severity) IsWorseThanOrEqualTo(other Severity) bool

IsWorseThanOrEqualTo is true when the other Severity, provided as argument, is the same Severity or less severe than the one this method is called on.

func (Severity) Max

func (s Severity) Max(other Severity) Severity

Max returns the other Severity provided as argument if this Severity is not OK and the other severity is worse.

func (Severity) String

func (s Severity) String() string

type Status

type Status struct {
	// Id is an idenfitier for the thing whose status is reported. The id must be unique within the Prober instance.
	// Multiple Status can have the same ID if they describe the same system/resource/test/assertion.
	ID string
	// Description contains a short, human readable description of the status, whether successful or not.
	Description string
	// Severity describes how bad the test successed or failed.
	// If the test was sucessfull it should be SeverityOk.
	// If the test failed, the implementation decides on the non-OK level.
	// For non-OK levels, the configuration can limit the displayed value to a subrange of levels.
	Severity Severity
	// Update is the time at which the Probe tested the thing for this Status.
	Update time.Time
	// Change is the last time the Error field of a Status with the same ID field changed.
	// Because this time can be before the start of the kee process (ie cloud provider alarm) the Probe provides
	// its value.
	// If the probe cannot know the last time the "test result" changed before the process started, it should first
	// return the 0 value so it can be displayed as N/A or "unknown" - until the error status changes.
	Change time.Time
	// Label is a user-assigned string that is configured per Prober instance.
	// Prober implementations should not set a value for it, but it will be overwritten anyways.
	Label string
}

Status describes the health state of a system or resource. A Prober instance can return zero, one or more Status on each call to Probe().

func (Status) MergeWhenWorse

func (s Status) MergeWhenWorse(other Status) Status

MergeWhenWorse returns an updated copy of the Status when the other Status, provided as argument, has a level more critical than the original Status. Both Status must have the same Id. Updated fields are Description and Severity.

type StatusField

type StatusField int

A StatusField refers to a field of the Status struct.

const (
	// FieldID refers to a Status' ID field.
	FieldID StatusField = 0
	// FieldDescription refers to a Status' Description field.
	FieldDescription StatusField = iota
	// FieldSeverity refers to a Status' Severity field.
	FieldSeverity StatusField = iota
	// FieldUpdate refers to a Status' Update field.
	FieldUpdate StatusField = iota
	// FieldChange refers to a Status' Change field.
	FieldChange StatusField = iota
	// FieldLabel refers to a Status' Label field.
	FieldLabel StatusField = iota
)

func FieldFromInt

func FieldFromInt(n int) (StatusField, error)

FieldFromInt returns a StatusField from an integer, or an error.

type StatusFilter

type StatusFilter func(Status) bool

StatusFilter returns true if the provided Status matches some criteria.

func SeverityWorseThanOrEqualToFilter

func SeverityWorseThanOrEqualToFilter(min Severity) StatusFilter

SeverityWorseThanOrEqualToFilter returns a StatusFilter func that will match Status with a severity worse or equal than the Severity provided as argument.

type StatusMap

type StatusMap map[string]Status

A StatusMap maps Status IDs to Status values.

func (StatusMap) Put

func (sm StatusMap) Put(s Status)

Put stores the provided Status into the map, overwriting any preexisting element with the same ID.

func (StatusMap) PutAll

func (sm StatusMap) PutAll(ss Statuses)

PutAll stores the provided Statuses into the map, overwriting any preexisting element with the same IDs.

func (StatusMap) ToStatuses

func (sm StatusMap) ToStatuses() Statuses

ToStatuses turns a StatusMap back to a Statuses slice.

type StatusReducer

type StatusReducer func(int, Status) int

StatusReducer produces an integer from the provided accumulator and Status.

type StatusTransformer

type StatusTransformer func(Status) Status

StatusTransformer is a function that returns a modified copy of the provided Status.

func MaxSeverity

func MaxSeverity(other Severity) StatusTransformer

MaxSeverity returns a StatusTransformer that applies the Severity.Max to each Status.

func PrependID

func PrependID(prefix string) StatusTransformer

PrependID returns a StatusTransformer that prefixes the Status Id with the string provided in argument.

func SetLabel

func SetLabel(label string) StatusTransformer

SetLabel returns a StatusTransformer that sets the provided Label to each Status.

type Statuses

type Statuses []Status

Statuses is a slice of Status. Each status in the slice should usually have a unique Id.

func (Statuses) Filter

func (ss Statuses) Filter(f StatusFilter) Statuses

Filter returns a modified Statuses with only Status for which the StatusFilter returned true

func (Statuses) ForEach

func (ss Statuses) ForEach(transformer ...StatusTransformer) Statuses

ForEach returns a modified Statuses by applying transformer functions to each Status

func (Statuses) Reduce

func (ss Statuses) Reduce(init int, a StatusReducer) int

Reduce returns an initial integer which has been updated by successive calls to the provided func

func (Statuses) SortBy

func (ss Statuses) SortBy(f StatusField)

SortBy sorts the Statuses by the provided StatusField.

func (Statuses) ToMap

func (ss Statuses) ToMap() (StatusMap, error)

ToMap creates a map with the Status Ids as keys, and Status as value

Directories

Path Synopsis
Package testhelpers provide helpers for writing probe provider tests.
Package testhelpers provide helpers for writing probe provider tests.

Jump to

Keyboard shortcuts

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