monitor

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package monitor provides the main controller for the flipper package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Group

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

Group monitors a group of resources and actions on them if necessary.

func NewGroup

func NewGroup(
	cfg cfgmodel.GroupConfig,
	provider resource.Provider,
	logger *slog.Logger,
	notifier notification.Notifier,
) *Group

NewGroup creates a new monitor group from a config and a provider.

func (*Group) Start

func (g *Group) Start(ctx context.Context) error

Start watching the resources and performing health checks. This function blocks until the context is cancelled.

type HealthKeeper

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

HealthKeeper keeps track of the health of the resources in a group and generates actions to keep them healthy. It is responsible for monitoring the health of the resources.

func NewHealthKeeper

func NewHealthKeeper(
	cfg cfgmodel.GroupConfig,
	logger *slog.Logger,
	provider resource.Provider,
	notifier notification.Notifier,
) *HealthKeeper

NewHealthKeeper creates a new healthkeeper for a group.

func (*HealthKeeper) Start

func (h *HealthKeeper) Start(
	ctx context.Context,
	resourceChanges <-chan ResourceUpdate,
	actionChan chan<- HealthKeeperAction,
)

Start monitoring the given resources, stopping anything it was watching before. This function blocks until the context is cancelled. It will send actions to the actionChan when it detects that an action is required to keep the resources healthy. The caller is responsible for closing the actionChan.

type HealthKeeperAction

type HealthKeeperAction struct {
	// ResourcesSequence is the sequence number of the resources when the action was generated.
	ResourcesSequence uint64
	State             plan.State
	Plan              plan.Plan
}

HealthKeeperAction is an action that the healthkeeper requests to be executed.

type Monitor

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

Monitor watches resources. It supports watching multiple groups of resources in parallel.

func New

func New(
	ctx context.Context,
	cfg *cfgmodel.Config,
	logger *slog.Logger,
	notifier notification.Notifier,
) (*Monitor, error)

New creates a new monitor from a config.

func (*Monitor) Watch

func (w *Monitor) Watch(ctx context.Context) error

Watch starts monitoring the resources. To gracefully stop watching, cancel the context.

type ResourceUpdate

type ResourceUpdate struct {
	// Sequence is the sequence number of the update, it can be used to detect stale updates.
	Sequence uint64
	// Resources is the current state of the resources.
	Resources resource.Group
	Changeset resource.GroupChangeset
}

ResourceUpdate contains the current resources and the changeset since the last update.

type ResourcesWatcher

type ResourcesWatcher struct {
	sync.Mutex
	// contains filtered or unexported fields
}

ResourcesWatcher watches for changes of the resources in a resource group itself. It polls the resources from the provider and sends updates over a channel.

func NewResourcesWatcher

func NewResourcesWatcher(cfg cfgmodel.GroupConfig, logger *slog.Logger, provider resource.Provider) *ResourcesWatcher

NewResourcesWatcher creates a new resource watcher for a group.

func (*ResourcesWatcher) Start

func (w *ResourcesWatcher) Start(ctx context.Context, onChange chan<- ResourceUpdate, onError chan<- error)

Start watching the resources and send updates to the onChange channel. If an error occurs, it is sent to the onError channel. The context can be used to stop the watcher. This function blocks until the context is canceled.

func (*ResourcesWatcher) Update

Update the resources by polling the provider. This updates the internal state and returns the resources and changeset from the last call to Update.

Jump to

Keyboard shortcuts

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