plugin

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultProducerRegistry = map[string]string{}

DefaultProducerRegistry maps a data key to the default producer plugin name (same as type). Populated via RegisterAsDefaultProducer.

View Source
var (
	// ErrNotFound is the not found error message.
	ErrNotFound = errors.New("not found")
)
View Source
var Registry = map[string]FactoryFunc{}

Registry is a mapping from plugin type to Factory function.

Functions

func PluginByType

func PluginByType[P Plugin](handlePlugins HandlePlugins, name string) (P, error)

PluginByType retrieves the specified plugin by name and verifies its type

func ReadPluginStateKey

func ReadPluginStateKey[T StateData](state *PluginState, requestID string, key StateKey) (T, error)

ReadPluginStateKey retrieves data with the given key from PluginState and asserts it to type T. Returns an error if the key is not found or the type assertion fails.

func Register

func Register(pluginType string, factory FactoryFunc)

Register is a static function that can be called to register plugin factory functions.

func RegisterAsDefaultProducer

func RegisterAsDefaultProducer(pluginType string, factory FactoryFunc, key DataKey)

RegisterAsDefaultProducer registers a factory for the given plugin type and records it as the default producer for the given data key. Only one producer may be registered as default per key. Out-of-tree projects that extend the EPP can call this to make their producers eligible for auto-configuration alongside in-tree producers.

func StrictDecoder

func StrictDecoder(raw json.RawMessage) *json.Decoder

StrictDecoder returns a *json.Decoder configured with DisallowUnknownFields over the given raw plugin parameters, or nil when raw is empty. The framework uses this when invoking factories so each plugin gets uniform strict parsing; tests use it to construct factory arguments without duplicating the decoder boilerplate.

Types

type ConsumerPlugin

type ConsumerPlugin interface {
	Plugin
	// Consumes returns the data keys consumed by this plugin, split into Required and Optional.
	// Required keys: the framework errors at init time if no producer exists.
	// Optional keys: the framework logs a warning but does not error; the plugin must handle absence.
	Consumes() DataDependencies
}

ConsumerPlugin defines the interface for a consumer.

type DataDependencies

type DataDependencies struct {
	// Required keys — the framework will error at init time if no producer exists for any of these.
	Required map[DataKey]any
	// Optional keys — the framework logs a warning at init time but does NOT error if no producer exists.
	// The plugin must handle the case where this data is absent at runtime.
	Optional map[DataKey]any
}

DataDependencies holds the data keys a plugin consumes, split by whether they are required (framework errors if no producer exists) or optional (framework logs a warning but continues if no producer exists).

type DataKey

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

DataKey uniquely identifies the data for data producer/consumer.

func NewDataKey

func NewDataKey(dataType, defaultProducerName string) DataKey

NewDataKey creates a new DataKey. The defaultProducerName is passed as the initial producerName.

func (DataKey) String

func (dk DataKey) String() string

String serializes the key to "DataType/ProducerName".

func (DataKey) WithNonEmptyProducerName

func (dk DataKey) WithNonEmptyProducerName(name string) DataKey

WithNonEmptyProducerName returns a copy of the key with the specified producer name if the name is not empty, otherwise returns the key unchanged.

type EvictableStateData

type EvictableStateData interface {
	StateData
	// OnEvicted is called when the data is removed from PluginState,
	// either manually or by the janitor.
	//
	// Implementations MUST be thread-safe and non-blocking, as OnEvicted
	// may be called from background goroutines and can race with other
	// request handlers. It must also tolerate being called concurrently
	// and potentially after partial cleanup.
	OnEvicted(requestID string, key StateKey)
}

EvictableStateData is an optional interface for StateData that needs to perform cleanup logic when it is removed or expires.

type FactoryFunc

type FactoryFunc func(name string, parameters *json.Decoder, handle Handle) (Plugin, error)

Factory is the definition of the factory functions that are used to instantiate plugins specified in a configuration. The framework provides a strict decoder (DisallowUnknownFields) over the plugin's raw parameters, or nil when the plugin was instantiated without parameters (e.g., as a default producer). Factories that ignore parameters can take the decoder as `_ *json.Decoder`.

type Handle

type Handle interface {
	// Context returns a context the plugins can use, if they need one
	Context() context.Context

	HandlePlugins

	// PodList lists pods. Returns nil if no pod source was configured on the handle.
	PodList() []types.NamespacedName

	// Metrics returns a recorder plugins can use to register metrics. It may return
	// nil when no recorder is configured.
	Metrics() MetricsRecorder
}

Handle provides plugins a set of standard data and tools to work with

func NewEppHandle

func NewEppHandle(ctx context.Context, podList PodListFunc, opts ...HandleOption) Handle

type HandleOption

type HandleOption func(*eppHandle)

HandleOption configures an eppHandle constructed via NewEppHandle.

func WithMetricsRecorder

func WithMetricsRecorder(recorder MetricsRecorder) HandleOption

WithMetricsRecorder sets the MetricsRecorder used by the handle. A nil recorder is ignored.

type HandlePlugins

type HandlePlugins interface {
	// Plugin returns the named plugin instance
	Plugin(name string) Plugin

	// AddPlugin adds a plugin to the set of known plugin instances
	AddPlugin(name string, plugin Plugin)

	// GetAllPlugins returns all of the known plugins
	GetAllPlugins() []Plugin

	// GetAllPluginsWithNames returns all of the known plugins with their names
	GetAllPluginsWithNames() map[string]Plugin
}

HandlePlugins defines a set of APIs to work with instantiated plugins

type MetricsRecorder

type MetricsRecorder interface {
	prometheus.Registerer
}

MetricsRecorder provides plugins access to metric registration without depending on package-level metric recording functions.

type Plugin

type Plugin interface {
	// TypedName returns the type and name tuple of this plugin instance.
	TypedName() TypedName
}

Plugin defines the interface for a plugin. This interface should be embedded in all plugins across the code.

type PluginState

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

PluginState is per-plugin scratch storage scoped to a single request. A plugin's extension points (e.g. PreRequest, ResponseBody) can write, read, and alter entries here to coordinate within that plugin. Entries are keyed by RequestID and reaped after "stalenessThreshold" of inactivity.

PluginState is not a cross-plugin handoff channel. Data shared between plugins must flow through the Producer/Consumer DAG: write to Endpoint AttributeMap for per-endpoint data, or to the InferenceRequest attribute store for per-request data. The DAG validates type compatibility and execution ordering; PluginState does not.

Note: PluginState uses a sync.Map to back the storage, because it is thread safe. It's aimed to optimize for the "write once and read many times" scenarios.

func NewPluginState

func NewPluginState(ctx context.Context) *PluginState

NewPluginState initializes a new PluginState and returns its pointer.

func (*PluginState) Delete

func (s *PluginState) Delete(requestID string)

Delete deletes data associated with the given requestID from PluginState.

Triggers OnEvicted for every EvictableStateData entry being removed. OnEvicted is invoked at most once per entry: Delete uses LoadAndDelete per key, so it does not fire OnEvicted on entries that were concurrently removed by a racing DeleteKey (or another Delete) on the same requestID.

func (*PluginState) DeleteKey

func (s *PluginState) DeleteKey(requestID string, key StateKey)

DeleteKey deletes the data associated with the given "key" in the context of "requestID" from PluginState.

Note: DeleteKey triggers the OnEvicted callback for the EvictableStateData entry being removed.

func (*PluginState) LastAccessTime

func (s *PluginState) LastAccessTime(requestID string) (time.Time, bool)

LastAccessTime returns the last access time for the given requestID and a boolean indicating if the requestID was found.

func (*PluginState) Read

func (s *PluginState) Read(requestID string, key StateKey) (StateData, error)

Read retrieves data with the given "key" in the context of "requestID" from PluginState. If the key is not present, ErrNotFound is returned.

func (*PluginState) Touch

func (s *PluginState) Touch(requestID string)

Touch updates the last access time for the given requestID, extending its lifetime before being reaped by the janitor.

func (*PluginState) Write

func (s *PluginState) Write(requestID string, key StateKey, val StateData)

Write stores the given "val" in PluginState with the given "key" in the context of the given "requestID". Note: overwriting an existing key does NOT trigger OnEvicted on the displaced value.

type PodListFunc

type PodListFunc func() []types.NamespacedName

PodListFunc is a function type that filters and returns a list of pod metrics

type ProducerPlugin

type ProducerPlugin interface {
	Plugin
	// Produces returns data produced by the producer.
	// This is a map from DataKey produced to
	// the data type of the key (represented as data with default value casted as any field).
	Produces() map[DataKey]any
}

ProducerPlugin defines the interface for a producer.

type StateData

type StateData interface {
	// Clone is an interface to make a copy of StateData.
	Clone() StateData
}

StateData is a generic type for arbitrary data stored in PluginState.

type StateDumper

type StateDumper interface {
	// DumpState returns a JSON-encoded representation of plugin state.
	// Implementations own serialization and must not include request payloads,
	// credentials, or other sensitive values.
	DumpState() (json.RawMessage, error)
}

StateDumper is an optional interface for plugins that can expose sanitized, bounded internal state through operational debug endpoints.

DumpState is intended for on-demand debugging snapshots of dynamic runtime state that is difficult to understand from metrics alone. Prefer metrics for numeric time series, alerting, dashboards, and aggregation over time. Dumped state should stay reasonably small; large or high-cardinality state should be summarized, capped, or omitted.

type StateKey

type StateKey string

StateKey is the type of keys stored in PluginState.

type TypedName

type TypedName struct {
	// Type returns the type of a plugin.
	Type string
	// Name returns the name of a plugin instance.
	Name string
}

TypedName is a utility struct providing a type and a name to plugins.

func (TypedName) String

func (tn TypedName) String() string

String returns the type and name rendered as "<name>/<type>".

Jump to

Keyboard shortcuts

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