health

package
v0.3.1-beta.2 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrEventNotFound = errors.New("event not found")
View Source
var ErrStreamNotFound = errors.New("stream not found")

Functions

This section is empty.

Types

type Condition

type Condition struct {
	Type               ConditionType        `json:"type,omitempty"`
	Status             *bool                `json:"status"`
	Frequency          stats.ByWindow       `json:"frequency,omitempty"`
	LastProbeTime      *data.UnixMillisTime `json:"lastProbeTime"`
	LastTransitionTime *data.UnixMillisTime `json:"lastTransitionsTime"`
}

func NewCondition

func NewCondition(condType ConditionType, ts time.Time, status *bool, frequency stats.ByWindow, last *Condition) *Condition

type ConditionType

type ConditionType string

type Core

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

func NewCore

func NewCore(opts CoreOptions, consumer event.StreamConsumer, reducer Reducer) *Core

func (*Core) GetPastEvents added in v0.1.0

func (c *Core) GetPastEvents(manifestID string, from, to *time.Time) ([]data.Event, error)

func (*Core) GetStatus added in v0.1.0

func (c *Core) GetStatus(manifestID string) (*Status, error)

func (*Core) HandleMessage

func (c *Core) HandleMessage(msg event.StreamMessage)

func (*Core) IsHealthy added in v0.1.0

func (c *Core) IsHealthy() bool

func (*Core) Start

func (c *Core) Start(ctx context.Context) error

func (*Core) SubscribeEvents added in v0.1.0

func (c *Core) SubscribeEvents(ctx context.Context, manifestID string, lastEvtID *uuid.UUID, from *time.Time) ([]data.Event, <-chan data.Event, error)

type CoreOptions

type CoreOptions struct {
	Streaming        StreamingOptions
	StartTimeOffset  time.Duration
	MemoryRecordsTtl time.Duration
}

type Measure added in v0.3.0

type Measure struct {
	Timestamp time.Time
	Value     float64
}

func (Measure) MarshalJSON added in v0.3.0

func (m Measure) MarshalJSON() ([]byte, error)

func (*Measure) UnmarshalJSON added in v0.3.0

func (m *Measure) UnmarshalJSON(raw []byte) error

type Metric added in v0.3.0

type Metric struct {
	Name       MetricName        `json:"name"`
	Dimensions map[string]string `json:"dimensions,omitempty"`
	Last       Measure           `json:"last"`
}

func NewMetric added in v0.3.0

func NewMetric(name MetricName, dimensions map[string]string, ts time.Time, value float64) *Metric

func (*Metric) Matches added in v0.3.0

func (m *Metric) Matches(name MetricName, odim map[string]string) bool

type MetricName added in v0.3.0

type MetricName string

type MetricsMap added in v0.3.0

type MetricsMap map[MetricName][]*Metric

func (MetricsMap) Add added in v0.3.0

func (m MetricsMap) Add(metric *Metric) MetricsMap

func (MetricsMap) GetMetric added in v0.3.0

func (m MetricsMap) GetMetric(name MetricName, dimensions map[string]string) *Metric

type MultistreamStatus added in v0.2.0

type MultistreamStatus struct {
	Target    data.MultistreamTargetInfo `json:"target"`
	Connected *Condition                 `json:"connected"`
}

type Record

type Record struct {
	ID         string
	Conditions []ConditionType

	sync.RWMutex

	PastEvents []data.Event
	EventsByID map[uuid.UUID]data.Event
	EventSubs  []chan<- data.Event

	ReducerState interface{}
	LastStatus   *Status
	// contains filtered or unexported fields
}

func NewRecord

func NewRecord(id string, conditions []ConditionType) *Record

func (*Record) SubscribeLocked added in v0.1.0

func (r *Record) SubscribeLocked(ctx context.Context, subs chan data.Event) chan data.Event

type RecordStorage

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

func (*RecordStorage) Get

func (s *RecordStorage) Get(id string) (*Record, bool)

func (*RecordStorage) GetOrCreate

func (s *RecordStorage) GetOrCreate(id string, conditions []ConditionType) *Record

func (*RecordStorage) StartCleanupLoop added in v0.1.0

func (s *RecordStorage) StartCleanupLoop(ctx context.Context, ttl time.Duration)

type Reducer

type Reducer interface {
	Bindings() []event.BindingArgs
	Conditions() []ConditionType
	Reduce(current *Status, state interface{}, evt data.Event) (*Status, interface{})
}

type ReducerFunc

type ReducerFunc func(*Status, interface{}, data.Event) (*Status, interface{})

func (ReducerFunc) Bindings

func (f ReducerFunc) Bindings() []event.BindingArgs

func (ReducerFunc) Conditions

func (f ReducerFunc) Conditions() []ConditionType

func (ReducerFunc) Reduce

func (f ReducerFunc) Reduce(current *Status, state interface{}, evt data.Event) (*Status, interface{})

type Status

type Status struct {
	ID         string       `json:"id"`
	Healthy    *Condition   `json:"healthy"`
	Conditions []*Condition `json:"conditions"`
	Metrics    MetricsMap   `json:"metrics,omitempty"`
	// TODO: Move this `multistream` field somewhere else to make this struct more
	// generic. Maybe condition dimensions/extraArgs?
	Multistream []*MultistreamStatus `json:"multistream,omitempty"`
}

Status is a soft-immutable struct. It should never be modified inline or a lot of things could become inconsistent. Create a new instance/copy for any mutation to be performed and beware of the internal slices and pointers.

Use NewMergedStatus below to facilitate the creation of new status objects with mutated fields. Notice that you still need to clone the internal slices if you want to do any mutations to them.

func NewMergedStatus added in v0.2.0

func NewMergedStatus(base *Status, values Status) *Status

func (Status) ConditionsCopy added in v0.2.0

func (s Status) ConditionsCopy() []*Condition

func (Status) MetricsCopy added in v0.3.0

func (s Status) MetricsCopy() MetricsMap

func (Status) MultistreamCopy added in v0.2.0

func (s Status) MultistreamCopy() []*MultistreamStatus

type StreamingOptions

type StreamingOptions struct {
	Stream, ConsumerName string

	event.RawStreamOptions
}

Purposedly made of built-in types only to bind directly to cli flags.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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