Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
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 ¶
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
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 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 ¶
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) Dead ¶
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.