lifecycle

package
v0.29.4 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2024 License: Apache-2.0 Imports: 15 Imported by: 1

Documentation

Overview

Package lifecycle provides events that services in the Choria eco system emit during startup, shutdown, provisioning and general running.

These events can be used by other tools to react to events or monitor the running of a Chroia network.

A library to view the events received from the network and one to create a running tally of the count and versions of nodes on your network.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EventTypeNames

func EventTypeNames() []string

EventTypeNames produce a list of valid event type names

func PublishEvent

func PublishEvent(e Event, conn inter.RawNATSConnector) error

PublishEvent publishes an event

func ToCloudEventV1

func ToCloudEventV1(e Event) cloudevents.Event

ToCloudEventV1 converts an event to a CloudEvent version 1

func View

func View(ctx context.Context, opt *ViewOptions) error

View connects and stream events to Output

func WriteEvents

func WriteEvents(ctx context.Context, opt *ViewOptions) error

WriteEvents views the event stream to the output

Types

type AliveEvent

type AliveEvent struct {
	Version string `json:"version"`
	// contains filtered or unexported fields
}

AliveEvent is a io.choria.lifecycle.v1.alive event

In addition to the usually required fields it requires a Version() specified when producing this type of event

func (*AliveEvent) Component

func (e *AliveEvent) Component() string

Component is the component that produced the event

func (*AliveEvent) Format

func (e *AliveEvent) Format() Format

Format retrieves the encoding format for the event

func (*AliveEvent) ID

func (e *AliveEvent) ID() string

ID is the v4 uuid of this message

func (*AliveEvent) Identity

func (e *AliveEvent) Identity() string

Identity sets the identity for the event

func (*AliveEvent) Protocol

func (e *AliveEvent) Protocol() string

Protocol retrieves the event protocol

func (*AliveEvent) SetComponent

func (e *AliveEvent) SetComponent(c string)

SetComponent sets the component for the event

func (*AliveEvent) SetFormat

func (e *AliveEvent) SetFormat(f Format)

SetFormat sets the encoding format for the event

func (*AliveEvent) SetIdentity

func (e *AliveEvent) SetIdentity(i string)

SetIdentity sets the identity for the event

func (*AliveEvent) SetVersion

func (e *AliveEvent) SetVersion(v string)

SetVersion sets the version for the event

func (*AliveEvent) String

func (e *AliveEvent) String() string

String is text suitable to display on the console etc

func (*AliveEvent) Target

func (e *AliveEvent) Target() (string, error)

Target is where to publish the event to

func (*AliveEvent) TimeStamp

func (e *AliveEvent) TimeStamp() time.Time

TimeStamp retrieves the event time

func (*AliveEvent) Type

func (e *AliveEvent) Type() Type

Type is the type of event

func (*AliveEvent) TypeString

func (e *AliveEvent) TypeString() string

TypeString the string representation of the event type

type ComponentEvent

type ComponentEvent interface {
	SetComponent(string)
}

ComponentEvent is an event that has a component

type Event

type Event interface {
	Protocol() string
	Target() (string, error)
	String() string
	Type() Type
	TypeString() string
	SetIdentity(string)
	Component() string
	Identity() string
	ID() string
	Format() Format
	SetFormat(Format)
	TimeStamp() time.Time
}

Event is event that can be published to the network

func New

func New(t Type, opts ...Option) (Event, error)

New creates a new event

func NewFromJSON

func NewFromJSON(j []byte) (event Event, err error)

NewFromJSON creates an event from the event JSON

type Format

type Format int

Format is the event format used for transporting events

const (
	// UnknownFormat is an unknown format message
	UnknownFormat Format = iota

	// ChoriaFormat is classical ChoriaFormat lifecycle events in its own package
	ChoriaFormat

	// CloudEventV1Format is a classical Choria lifecycle event carried within a version 1.0 CloudEvent
	CloudEventV1Format
)

func EventFormatFromJSON

func EventFormatFromJSON(j []byte) Format

EventFormatFromJSON inspects the JSON data and tries to determine the format from it's content

func (Format) String added in v0.26.2

func (f Format) String() string

type Framework

type Framework interface {
	NewConnector(ctx context.Context, servers func() (srvcache.Servers, error), name string, logger *logrus.Entry) (conn inter.Connector, err error)
	Certname() string
	Logger(name string) *logrus.Entry
	NewRequestID() (string, error)
	MiddlewareServers() (servers srvcache.Servers, err error)
}

type GovernedEvent added in v0.23.0

type GovernedEvent interface {
	SetGovernor(name string)
	SetSequence(seq uint64)
	SetEventType(stage GovernorEventType) error
}

GovernedEvent is an event that relates to Governors

type GovernorEvent added in v0.23.0

type GovernorEvent struct {
	Governor  string            `json:"governor"`
	Sequence  uint64            `json:"sequence"`
	EventType GovernorEventType `json:"event_type"`
	// contains filtered or unexported fields
}

GovernorEvent is a io.choria.lifecycle.v1.governor event

In addition to the usual required fields it requires a GovernorName(), GovernorSequence() and GovernorType() specified when producing this kind of event

func (*GovernorEvent) Component added in v0.23.0

func (e *GovernorEvent) Component() string

Component is the component that produced the event

func (*GovernorEvent) Format added in v0.23.0

func (e *GovernorEvent) Format() Format

Format retrieves the encoding format for the event

func (*GovernorEvent) ID added in v0.23.0

func (e *GovernorEvent) ID() string

ID is the v4 uuid of this message

func (*GovernorEvent) Identity added in v0.23.0

func (e *GovernorEvent) Identity() string

Identity sets the identity for the event

func (*GovernorEvent) Protocol added in v0.23.0

func (e *GovernorEvent) Protocol() string

Protocol retrieves the event protocol

func (*GovernorEvent) SetComponent added in v0.23.0

func (e *GovernorEvent) SetComponent(c string)

SetComponent sets the component for the event

func (*GovernorEvent) SetEventType added in v0.23.0

func (g *GovernorEvent) SetEventType(stage GovernorEventType) error

func (*GovernorEvent) SetFormat added in v0.23.0

func (e *GovernorEvent) SetFormat(f Format)

SetFormat sets the encoding format for the event

func (*GovernorEvent) SetGovernor added in v0.23.0

func (g *GovernorEvent) SetGovernor(name string)

func (*GovernorEvent) SetIdentity added in v0.23.0

func (e *GovernorEvent) SetIdentity(i string)

SetIdentity sets the identity for the event

func (*GovernorEvent) SetSequence added in v0.23.0

func (g *GovernorEvent) SetSequence(seq uint64)

func (*GovernorEvent) String added in v0.23.0

func (g *GovernorEvent) String() string

func (*GovernorEvent) Target added in v0.23.0

func (e *GovernorEvent) Target() (string, error)

Target is where to publish the event to

func (*GovernorEvent) TimeStamp added in v0.23.0

func (e *GovernorEvent) TimeStamp() time.Time

TimeStamp retrieves the event time

func (*GovernorEvent) Type added in v0.23.0

func (e *GovernorEvent) Type() Type

Type is the type of event

func (*GovernorEvent) TypeString added in v0.23.0

func (e *GovernorEvent) TypeString() string

TypeString the string representation of the event type

type GovernorEventType added in v0.23.0

type GovernorEventType string
const (
	// GovernorEnterEvent is when a Governor slot is obtained through active campaigning
	GovernorEnterEvent GovernorEventType = "enter"
	// GovernorExitEvent is when a slot is left, but not expired or evicted
	GovernorExitEvent GovernorEventType = "exit"
	// GovernorTimeoutEvent is when a slot could not be obtained after some time
	GovernorTimeoutEvent GovernorEventType = "timeouts"
	// GovernorEvictEvent is when a slot is evicted using a admin API
	GovernorEvictEvent GovernorEventType = "eviction"
)

type NewVersionEvent added in v0.27.0

type NewVersionEvent interface {
	VersionEvent
	SetNewVersion(string)
}

NewVersionEvent is an event that has a new and old version

type Option

type Option func(e any) error

Option configures events

func Component

func Component(component string) Option

Component set the component for events

func GovernorName added in v0.23.0

func GovernorName(name string) Option

GovernorName sets the name of the Governor being interacted with

func GovernorSequence added in v0.23.0

func GovernorSequence(seq uint64) Option

GovernorSequence sets the sequence of the event when applicable

func GovernorType added in v0.23.0

func GovernorType(stage GovernorEventType) Option

GovernorType sets the stage this event relates to

func Identity

func Identity(identity string) Option

Identity sets the identity for events

func NewVersion added in v0.27.0

func NewVersion(version string) Option

NewVersion set the version for events

func Version

func Version(version string) Option

Version set the version for events

type ProvisionedEvent

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

ProvisionedEvent is a io.choria.lifecycle.v1.provisioned event

func (*ProvisionedEvent) Component

func (e *ProvisionedEvent) Component() string

Component is the component that produced the event

func (*ProvisionedEvent) Format

func (e *ProvisionedEvent) Format() Format

Format retrieves the encoding format for the event

func (*ProvisionedEvent) ID

func (e *ProvisionedEvent) ID() string

ID is the v4 uuid of this message

func (*ProvisionedEvent) Identity

func (e *ProvisionedEvent) Identity() string

Identity sets the identity for the event

func (*ProvisionedEvent) Protocol

func (e *ProvisionedEvent) Protocol() string

Protocol retrieves the event protocol

func (*ProvisionedEvent) SetComponent

func (e *ProvisionedEvent) SetComponent(c string)

SetComponent sets the component for the event

func (*ProvisionedEvent) SetFormat

func (e *ProvisionedEvent) SetFormat(f Format)

SetFormat sets the encoding format for the event

func (*ProvisionedEvent) SetIdentity

func (e *ProvisionedEvent) SetIdentity(i string)

SetIdentity sets the identity for the event

func (*ProvisionedEvent) String

func (e *ProvisionedEvent) String() string

String is text suitable to display on the console etc

func (*ProvisionedEvent) Target

func (e *ProvisionedEvent) Target() (string, error)

Target is where to publish the event to

func (*ProvisionedEvent) TimeStamp

func (e *ProvisionedEvent) TimeStamp() time.Time

TimeStamp retrieves the event time

func (*ProvisionedEvent) Type

func (e *ProvisionedEvent) Type() Type

Type is the type of event

func (*ProvisionedEvent) TypeString

func (e *ProvisionedEvent) TypeString() string

TypeString the string representation of the event type

type ShutdownEvent

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

ShutdownEvent is a io.choria.lifecycle.v1.shutdown event

func (*ShutdownEvent) Component

func (e *ShutdownEvent) Component() string

Component is the component that produced the event

func (*ShutdownEvent) Format

func (e *ShutdownEvent) Format() Format

Format retrieves the encoding format for the event

func (*ShutdownEvent) ID

func (e *ShutdownEvent) ID() string

ID is the v4 uuid of this message

func (*ShutdownEvent) Identity

func (e *ShutdownEvent) Identity() string

Identity sets the identity for the event

func (*ShutdownEvent) Protocol

func (e *ShutdownEvent) Protocol() string

Protocol retrieves the event protocol

func (*ShutdownEvent) SetComponent

func (e *ShutdownEvent) SetComponent(c string)

SetComponent sets the component for the event

func (*ShutdownEvent) SetFormat

func (e *ShutdownEvent) SetFormat(f Format)

SetFormat sets the encoding format for the event

func (*ShutdownEvent) SetIdentity

func (e *ShutdownEvent) SetIdentity(i string)

SetIdentity sets the identity for the event

func (*ShutdownEvent) String

func (e *ShutdownEvent) String() string

String is text suitable to display on the console etc

func (*ShutdownEvent) Target

func (e *ShutdownEvent) Target() (string, error)

Target is where to publish the event to

func (*ShutdownEvent) TimeStamp

func (e *ShutdownEvent) TimeStamp() time.Time

TimeStamp retrieves the event time

func (*ShutdownEvent) Type

func (e *ShutdownEvent) Type() Type

Type is the type of event

func (*ShutdownEvent) TypeString

func (e *ShutdownEvent) TypeString() string

TypeString the string representation of the event type

type StartupEvent

type StartupEvent struct {
	Version string `json:"version"`
	// contains filtered or unexported fields
}

StartupEvent is a io.choria.lifecycle.v1.startup event

In addition to the usually required fields it requires a Version() specified when producing this type of event

func (*StartupEvent) Component

func (e *StartupEvent) Component() string

Component is the component that produced the event

func (*StartupEvent) Format

func (e *StartupEvent) Format() Format

Format retrieves the encoding format for the event

func (*StartupEvent) ID

func (e *StartupEvent) ID() string

ID is the v4 uuid of this message

func (*StartupEvent) Identity

func (e *StartupEvent) Identity() string

Identity sets the identity for the event

func (*StartupEvent) Protocol

func (e *StartupEvent) Protocol() string

Protocol retrieves the event protocol

func (*StartupEvent) SetComponent

func (e *StartupEvent) SetComponent(c string)

SetComponent sets the component for the event

func (*StartupEvent) SetFormat

func (e *StartupEvent) SetFormat(f Format)

SetFormat sets the encoding format for the event

func (*StartupEvent) SetIdentity

func (e *StartupEvent) SetIdentity(i string)

SetIdentity sets the identity for the event

func (*StartupEvent) SetVersion

func (e *StartupEvent) SetVersion(v string)

SetVersion sets the version for the event

func (*StartupEvent) String

func (e *StartupEvent) String() string

String is text suitable to display on the console etc

func (*StartupEvent) Target

func (e *StartupEvent) Target() (string, error)

Target is where to publish the event to

func (*StartupEvent) TimeStamp

func (e *StartupEvent) TimeStamp() time.Time

TimeStamp retrieves the event time

func (*StartupEvent) Type

func (e *StartupEvent) Type() Type

Type is the type of event

func (*StartupEvent) TypeString

func (e *StartupEvent) TypeString() string

TypeString the string representation of the event type

type SubscribeConnector

type SubscribeConnector interface {
	QueueSubscribe(ctx context.Context, name string, subject string, group string, output chan inter.ConnectorMessage) error
	ConnectedServer() string
}

SubscribeConnector is a connection to the middleware

type Type

type Type int

Type is a type of event this system supports

const (
	// Unknown is for when a Type string was passed in that doesn't match what was expected
	Unknown Type = iota - 1

	// Startup is an event components can publish when they start
	Startup

	// Shutdown is an event components can publish when they shutdown
	Shutdown

	// Provisioned is an event components can publish post provisioning
	Provisioned

	// Alive is an event components can publish to indicate they are still alive
	Alive

	// Governor is an event components can publish while interacting with a Governor
	Governor

	// Upgraded is an event that can be fired to indicate a component was upgraded
	Upgraded
)

func (Type) String added in v0.26.2

func (t Type) String() string

type UpgradedEvent added in v0.27.0

type UpgradedEvent struct {
	Version    string `json:"version"`
	NewVersion string `json:"new_version"`
	// contains filtered or unexported fields
}

func (*UpgradedEvent) Component added in v0.27.0

func (e *UpgradedEvent) Component() string

Component is the component that produced the event

func (*UpgradedEvent) Format added in v0.27.0

func (e *UpgradedEvent) Format() Format

Format retrieves the encoding format for the event

func (*UpgradedEvent) ID added in v0.27.0

func (e *UpgradedEvent) ID() string

ID is the v4 uuid of this message

func (*UpgradedEvent) Identity added in v0.27.0

func (e *UpgradedEvent) Identity() string

Identity sets the identity for the event

func (*UpgradedEvent) Protocol added in v0.27.0

func (e *UpgradedEvent) Protocol() string

Protocol retrieves the event protocol

func (*UpgradedEvent) SetComponent added in v0.27.0

func (e *UpgradedEvent) SetComponent(c string)

SetComponent sets the component for the event

func (*UpgradedEvent) SetFormat added in v0.27.0

func (e *UpgradedEvent) SetFormat(f Format)

SetFormat sets the encoding format for the event

func (*UpgradedEvent) SetIdentity added in v0.27.0

func (e *UpgradedEvent) SetIdentity(i string)

SetIdentity sets the identity for the event

func (*UpgradedEvent) SetNewVersion added in v0.27.0

func (e *UpgradedEvent) SetNewVersion(v string)

SetNewVersion sets the version for the event

func (*UpgradedEvent) SetVersion added in v0.27.0

func (e *UpgradedEvent) SetVersion(v string)

SetVersion sets the version for the event

func (*UpgradedEvent) String added in v0.27.0

func (e *UpgradedEvent) String() string

String is text suitable to display on the console etc

func (*UpgradedEvent) Target added in v0.27.0

func (e *UpgradedEvent) Target() (string, error)

Target is where to publish the event to

func (*UpgradedEvent) TimeStamp added in v0.27.0

func (e *UpgradedEvent) TimeStamp() time.Time

TimeStamp retrieves the event time

func (*UpgradedEvent) Type added in v0.27.0

func (e *UpgradedEvent) Type() Type

Type is the type of event

func (*UpgradedEvent) TypeString added in v0.27.0

func (e *UpgradedEvent) TypeString() string

TypeString the string representation of the event type

type VersionEvent

type VersionEvent interface {
	SetVersion(string)
}

VersionEvent is an event that has a version

type ViewOptions

type ViewOptions struct {
	TypeFilter      string
	ComponentFilter string
	Debug           bool
	Output          io.Writer
	Choria          Framework
	Connector       SubscribeConnector
}

ViewOptions configure the view command

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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