eval

package
v0.0.0-...-efb87f3 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Evaluation

type Evaluation struct {
	ID          int64                `json:"id" storm:"id,increment"`
	CheckHostID string               `json:"check_host_id" storm:"index"`
	CheckID     string               `json:"check_id" storm:"index"`
	HostID      string               `json:"host_id"`
	History     States               `json:"history"`
	State       State                `json:"state"`
	Start       time.Time            `json:"start"`
	End         time.Time            `json:"end"`
	Hosts       map[string]State     `json:"hosts"`
	Results     []checks.CheckResult `json:"-"`
}

Evaluation describes the current state of a check.

func LatestEvaluation

func LatestEvaluation(db database.Reader, result *checks.CheckResult) (*Evaluation, error)

LatestEvaluation retrieves the latest evaluation if any.

func NewEvaluation

func NewEvaluation(clock time.Time, result *checks.CheckResult) *Evaluation

NewEvaluation returns a new evaluation.

func (*Evaluation) Final

func (e *Evaluation) Final() bool

Final returns true if the evaluation is for a check and not for a host-part of a check.

func (*Evaluation) Save

func (e *Evaluation) Save(db database.Writer) error

Save will save e to the supplied db and cache.

type Evaluator

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

Evaluator will evaluate check results from all nodes on the leader node.

func NewEvaluator

func NewEvaluator(db database.ReadWriter) *Evaluator

NewEvaluator will instantiate a new Evaluator listening to cluster changes, and evaluating results as they arrive.

func (*Evaluator) Evaluate

func (e *Evaluator) Evaluate(checkResult *checks.CheckResult) (*Evaluation, error)

Evaluate will evaluate a CheckResult and return an Evaluation including current state.

type State

type State int

State denotes the current state of a Check.

const (
	// StateUnknown is an initial state for checks which are not yet down or up.
	StateUnknown State = iota

	// StateUp is a Check that is OK or "green".
	StateUp State = iota

	// StateDown is a Check with failed conditions.
	StateDown State = iota
)

func (State) ColorString

func (s State) ColorString() string

ColorString will return a colorized string representing the state. It will be suitable for printing in an ANSI terminal.

func (State) MarshalJSON

func (s State) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

func (State) MarshalText

func (s State) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (State) String

func (s State) String() string

String implements GoStringer.

func (*State) UnmarshalJSON

func (s *State) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

func (*State) UnmarshalText

func (s *State) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

func (State) Valid

func (s State) Valid() bool

Valid returns true if s is a valid state.

type States

type States []State

States can hold multiple states.

func (*States) Add

func (s *States) Add(state State, clamp int)

Add a new state to a States object. The newest state will always be available at position 0. This type is not meant to be read directly thou.

func (*States) Clamp

func (s *States) Clamp(size int)

Clamp removes elements older than size.

func (*States) ColorString

func (s *States) ColorString() string

ColorString will return a nicely colored array.

func (*States) Histogram

func (s *States) Histogram() map[State]int

Histogram generates a map of count of the content.

func (*States) Last

func (s *States) Last(n int) *States

Last returns a new States object containing the latest n states.

func (*States) Reduce

func (s *States) Reduce() State

Reduce reduces the slice of states to a single state according to a very simple algorithm:

  1. If there's no states stored, return StateUnknown.
  2. If any state is StateUnknown, return StateUnknown.
  3. If no state is StateUnknown, and there is a majority that majority is returned.
  4. If none of 1-3 is satisfied, StateUnknown will we returned.

type Summary

type Summary struct {
	sync.RWMutex
	ID string `storm:"id"`

	Checks int           `json:"checks"`
	States map[State]int `json:"states"`
	// contains filtered or unexported fields
}

Summary is a summary of all checks.

func NewSummary

func NewSummary(db database.Writer) *Summary

NewSummary will return a new Summary.

func (*Summary) AddCheck

func (s *Summary) AddCheck(id string)

AddCheck adds a check to the internal list of check IDs.

func (*Summary) AddEvaluation

func (s *Summary) AddEvaluation(eval *Evaluation) error

AddEvaluation will add a new evaluation to the summary.

func (*Summary) PostApply

func (s *Summary) PostApply(leader bool, command database.Command, data interface{})

PostApply implements database.Listener. We listen for added and deleted checks.

func (*Summary) RemoveCheck

func (s *Summary) RemoveCheck(id string)

RemoveCheck will remove the check identifier by id from summary.

Jump to

Keyboard shortcuts

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