pluginmgr

package
v0.0.0-...-1fcb3a4 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ISyncable

type ISyncable interface {
	Name() string
	Description() string
	Enabled() bool
	Checksum() string
}

ISyncable is the type constraint for all plugin types managed by a Manager.

type Notify

type Notify = func(messaging.Message)

Notify is the callback a PluginManager calls when a plugin starts, updates, or stops. Implementations are typically pool.Sync methods that register/deregister plugin handles.

type Plugin

type Plugin interface {
	Start(ctx context.Context) error
}

Plugin is implemented by every plugin Manager - it can be started.

type PluginAdapter

type PluginAdapter[T ISyncable] interface {
	// This is the go-plugin dispense key, e.g. "rule", "enrichment".
	PluginKey() string
	// This is the HandshakeConfig cookie value, e.g. "rule_v1".
	MagicValue() string
	// GRPCPlugin returns the go-plugin.Plugin that constructs the gRPC client stub.
	GRPCPlugin() plugin.Plugin
	// Handshake type-asserts the dispensed raw interface, calls Init (and optionally GetMetadata),
	// and returns the wrapped public T, a PluginLifecycle, the plugin stable ID, the display name, and any error.
	Handshake(ctx context.Context, raw interface{}, binPath string, hash string) (T, PluginLifecycle, string, string, error)
	// IsEnabled reports whether a running handle should continue running.
	IsEnabled(handle *PluginHandle) bool
	// Returns how many subprocess instances to spawn for this binary.
	// Return 1 (or ≤ 0) for the default single-worker behaviour.
	Workers(binPath string) int
}

PluginAdapter[T] encapsulates every piece of type-specific plugin logic. Implement once per plugin type and inject into NewManager.

type PluginHandle

type PluginHandle struct {
	Client    *plugin.Client
	Lifecycle PluginLifecycle
	BinPath   string
	ID        string // stable plugin identifier (e.g. UUID); used for bus messages and pool ops
	Name      string // human-readable display name; used for logging
	Hash      string // SHA-256 of the binary at launch time
	// contains filtered or unexported fields
}

PluginHandle tracks everything the Manager needs for one running plugin subprocess.

type PluginLifecycle

type PluginLifecycle interface {
	Ping(ctx context.Context) error
	Shutdown(ctx context.Context) error
}

PluginLifecycle provides the health-check and graceful-shutdown primitives the Manager uses in ping loops and kill paths.

type PluginManager

type PluginManager[T ISyncable] struct {
	// contains filtered or unexported fields
}

PluginManager[T] is the generic plugin subprocess manager. It watches a directory for executable binaries, manages their subprocess lifecycle, and calls notify for Register/Update/Unregister events so the caller can update pools.

func NewPluginManager

func NewPluginManager[T ISyncable](
	log *logger.Logger,
	notify Notify,
	dir string,
	adapter PluginAdapter[T],
	metrics *PluginManagerMetrics,
) *PluginManager[T]

func (*PluginManager[T]) Start

func (m *PluginManager[T]) Start(ctx context.Context) error

Performs an initial reconcile then watches the plugin directory for changes.

type PluginManagerMetrics

type PluginManagerMetrics struct {
	Starts             prometheus.Counter
	Crashes            prometheus.Counter
	Restarts           prometheus.Counter
	Updates            prometheus.Counter
	StartLatency       prometheus.Histogram
	ActiveSubprocesses *prometheus.GaugeVec
}

Holds the Prometheus metrics shared by all plugin managers.

func NewPluginManagerMetrics

func NewPluginManagerMetrics(subsystem string) *PluginManagerMetrics

Registers and returns a metric set for the given subsystem.

type RegisterMessage

type RegisterMessage[T ISyncable] struct {
	messaging.IsMessage
	Items    []T
	MaxProcs int
}

Delivered when a new plugin subprocess is ready. Items holds all N worker instances for the binary; MaxProcs is the pool capacity hint.

func NewRegisterMessage

func NewRegisterMessage[T ISyncable](items []T, maxProcs int) RegisterMessage[T]

type RemoveMessage

type RemoveMessage[T ISyncable] struct {
	messaging.IsMessage
	ItemID string
}

Delivered when a plugin binary is permanently deleted from disk. The plugin is not expected to return. Pool removes the active entry AND tombstones the plugin ID.

func NewRemoveMessage

func NewRemoveMessage[T ISyncable](itemID string) RemoveMessage[T]

type UnregisterMessage

type UnregisterMessage[T ISyncable] struct {
	messaging.IsMessage
	ItemID string
}

Delivered when a plugin subprocess is stopped transiently aka a crash being restarted, or a plugin disabled via config. The plugin may come back. Pool removes the active entry but does NOT tombstone the plugin ID.

func NewUnregisterMessage

func NewUnregisterMessage[T ISyncable](itemID string) UnregisterMessage[T]

type UpdateMessage

type UpdateMessage[T ISyncable] struct {
	messaging.IsMessage
	Items     []T
	MaxProcs  int
	OnDrained func()
}

Delivered when a plugin binary changes in-place. Items holds all N worker instances for the new binary version. OnDrained is called by ProcessPool.drain once all in-flight calls on the old VersionedPool complete - the PluginManager uses it to kill the old subprocesses only after the pool has finished draining.

func NewUpdateMessage

func NewUpdateMessage[T ISyncable](items []T, maxProcs int, onDrained func()) UpdateMessage[T]

Jump to

Keyboard shortcuts

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