Documentation
¶
Overview ¶
Package instancemgmt provides utilities for managing plugin instances.
This package offers several instance manager implementations:
Standard Instance Manager (New): Uses sync.Map for caching instances and disposes them when they need updates.
TTL Instance Manager (NewTTLInstanceManager): Uses TTL-based caching that automatically evicts instances after a configurable time period.
Instance Manager Wrapper (NewInstanceManagerWrapper): Dynamically selects between standard and TTL managers based on feature toggles from the Grafana config in the context.
The context-aware manager checks the "ttlPluginInstanceManager" feature toggle from the Grafana configuration and automatically uses the appropriate underlying implementation. This allows runtime switching without requiring plugin restarts or static configuration. Note: Both the standard and TTL instance managers maintain separate caches. If the feature toggle for TTL instance manager is changed at runtime, instances are not migrated between managers. This can result in duplicate instances for the same plugin context until the old ones are disposed or evicted.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CachedInstance ¶
type CachedInstance struct {
PluginContext backend.PluginContext
// contains filtered or unexported fields
}
CachedInstance a cached Instance.
type InstanceCallbackFunc ¶
type InstanceCallbackFunc interface{}
InstanceCallbackFunc defines the callback function of the InstanceManager.Do method. The argument provided will of type Instance.
type InstanceDisposer ¶
type InstanceDisposer interface {
Dispose()
}
InstanceDisposer is implemented by an Instance that has a Dispose method, which defines that the instance is disposable.
InstanceManager will call the Dispose method before an Instance is replaced with a new Instance. This allows an Instance to clean up resources in use, if any.
type InstanceManager ¶
type InstanceManager interface {
// Get returns an Instance.
//
// If Instance is cached and not updated it's returned. If Instance is not cached or
// updated, a new Instance is created and cached before returned.
Get(ctx context.Context, pluginContext backend.PluginContext) (Instance, error)
// Do provides an Instance as argument to fn.
//
// If Instance is cached and not updated provides as argument to fn. If Instance is not cached or
// updated, a new Instance is created and cached before provided as argument to fn.
Do(ctx context.Context, pluginContext backend.PluginContext, fn InstanceCallbackFunc) error
}
InstanceManager manages the lifecycle of instances.
func NewInstanceManagerWrapper ¶ added in v0.282.0
func NewInstanceManagerWrapper(provider InstanceProvider) InstanceManager
NewInstanceManagerWrapper creates a new instance manager that dynamically selects between standard and TTL instance managers based on feature toggles from the Grafana config.
func NewTTLInstanceManager ¶ added in v0.282.0
func NewTTLInstanceManager(provider InstanceProvider) InstanceManager
NewTTLInstanceManager creates a new instance manager with TTL-based caching. Instances will be automatically evicted from the cache after the specified TTL.
type InstanceProvider ¶
type InstanceProvider interface {
// GetKey returns a cache key to be used for caching an Instance.
GetKey(ctx context.Context, pluginContext backend.PluginContext) (interface{}, error)
// NeedsUpdate returns whether a cached Instance have been updated.
NeedsUpdate(ctx context.Context, pluginContext backend.PluginContext, cachedInstance CachedInstance) bool
// NewInstance creates a new Instance.
NewInstance(ctx context.Context, pluginContext backend.PluginContext) (Instance, error)
}
InstanceProvider defines an instance provider, providing instances.