liveness

package
v5.10.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2019 License: MIT, MIT, MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SwitchPrefix = "/sensu.io/switchsets"

SwitchPrefix contains the base path for switchset, which are tracked under path.Join(SwitchPrefix, toggleName, key)

Functions

This section is empty.

Types

type EventFunc

type EventFunc func(key string, prev State, leader bool) (bury bool)

EventFunc is a function that can be used by a SwitchSet to handle events. The previous state of the switch will be passed to the function.

For "dead" EventFuncs, the leader flag can be used to determine if the client that flipped the switch is our client. For "alive" EventFuncs, this parameter is always false.

The EventFunc should return whether or not to bury the switch. If bury is true, then the key associated with the EventFunc will be buried and no further events will occur for this key.

type Factory

type Factory func(name string, dead, alive EventFunc, logger logrus.FieldLogger) Interface

Factory is a function that can deliver an Interface

func EtcdFactory

func EtcdFactory(ctx context.Context, client *clientv3.Client) Factory

EtcdFactory returns a Factory that uses an etcd client. The Interface is cached after the first instantiation, and the EventFuncs and logger cannot be changed later.

type Interface

type Interface interface {
	// Alive is an assertion that an entity is alive.
	Alive(ctx context.Context, id string, ttl int64) error

	// Dead is an assertion that an entity is dead. Dead is useful for
	// registering entities that are known to be dead, but not yet tracked.
	Dead(ctx context.Context, id string, ttl int64) error

	// Bury forgets an entity exists
	Bury(ctx context.Context, id string) error
}

Interface specifies the interface for liveness

type State

type State int

State represents a custom int type for the key stae

const (
	// FallbackTTL represents the minimal supported etcd lease TTL,  in case the
	// system encounters a toggle that does not store a TTL
	FallbackTTL = 5

	// Alive state is 0
	Alive State = 0

	// Dead state is 1
	Dead State = 1
)

func (State) String

func (s State) String() string

type SwitchSet

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

SwitchSet is a set of switches that get flipped on life and death events for entities. On life and death events, callback functions that are registered on NewSwitchSet are started as new goroutines.

The SwitchSet uses the Alive method to both register members of the set, and to assert their liveness once registered. After its first call to Alive, if a member does not assert its liveness, then it will be presumed to be dead, and the callback for dead members will be called.

When an entity in a SwitchSet dies, it gains a new life in the underworld. In the underworld, a dead callback is issued for every TTL interval. Entities can go from being dead to alive by calling Alive. When that happens, an entity that lives in the underworld will be reborn.

func NewSwitchSet

func NewSwitchSet(client *clientv3.Client, name string, dead, alive EventFunc, logger logrus.FieldLogger) *SwitchSet

NewSwitchSet creates a new SwitchSet. It will use an etcd prefix of path.Join(SwitchPrefix, name). The dead and live callbacks will be called on all life and death events.

func (*SwitchSet) Alive

func (t *SwitchSet) Alive(ctx context.Context, id string, ttl int64) error

Alive is an assertion that an entity is alive.

If the SwitchSet doesn't know about the entity yet, then it will be registered, and the TTL countdown will start. Unless the entity continually asserts its liveness with calls to Alive, it will be presumed dead.

The ttl parameter is the time-to-live in seconds for the entity. The minimum TTL value is 5. If a smaller value is passed, then an error will be returned and no registration will occur.

func (*SwitchSet) Bury

func (t *SwitchSet) Bury(ctx context.Context, id string) error

Bury buries a live or dead switch. The switch will no longer or callbacks.

func (*SwitchSet) Dead

func (t *SwitchSet) Dead(ctx context.Context, id string, ttl int64) error

Dead is an assertion that an entity is dead. Dead is useful for registering entities that are known to be dead, but not yet tracked by the SwitchSet.

If the SwitchSet doesn't know about the entity yet, then it will be registered, and the TTL countdown will start. Until the entity asserts its liveness, it will be presumed dead, and dead callbacks will be issued.

The ttl parameter is the time-to-live in seconds for the entity. The minimum TTL value is 5. If a smaller value is passed, then an error will be returned and no registration will occur.

Jump to

Keyboard shortcuts

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